Change mount API to allow for mount backends other than pmount

Add static convenience method for determining X11 VT mapping to TDEApplication
pull/16/head
Timothy Pearson 11 years ago
parent c8d64e3c7b
commit 1f3ee12a9a

@ -175,6 +175,14 @@ typedef void* IceIOErrorHandler;
#include <tqimage.h> #include <tqimage.h>
#endif #endif
#if defined Q_WS_X11
#include <sys/ioctl.h>
#include <linux/vt.h>
extern "C" {
extern int getfd(const char *fnam);
}
#endif
#include "kappdcopiface.h" #include "kappdcopiface.h"
// exported for tdm kfrontend // exported for tdm kfrontend
@ -242,6 +250,67 @@ void TDEApplication_init_windows(bool GUIenabled);
class QAssistantClient; class QAssistantClient;
#endif #endif
#ifdef Q_WS_X11
// --------------------------------------------------------------------------------------
// Get the VT number X is running on
// (code taken from GDM, daemon/getvt.c, GPLv2+)
// --------------------------------------------------------------------------------------
int get_x_vtnum(Display *dpy)
{
Atom prop;
Atom actualtype;
int actualformat;
unsigned long nitems;
unsigned long bytes_after;
unsigned char *buf;
int num;
prop = XInternAtom (dpy, "XFree86_VT", False);
if (prop == None)
return -1;
if (XGetWindowProperty (dpy, DefaultRootWindow (dpy), prop, 0, 1,
False, AnyPropertyType, &actualtype, &actualformat,
&nitems, &bytes_after, &buf)) {
return -1;
}
if (nitems != 1) {
XFree (buf);
return -1;
}
switch (actualtype) {
case XA_CARDINAL:
case XA_INTEGER:
case XA_WINDOW:
switch (actualformat) {
case 8:
num = (*(uint8_t *)(void *)buf);
break;
case 16:
num = (*(uint16_t *)(void *)buf);
break;
case 32:
num = (*(uint32_t *)(void *)buf);
break;
default:
XFree (buf);
return -1;
}
break;
default:
XFree (buf);
return -1;
}
XFree (buf);
return num;
}
// --------------------------------------------------------------------------------------
#endif // Q_WS_X11
/* /*
Private data to make keeping binary compatibility easier Private data to make keeping binary compatibility easier
*/ */
@ -3632,6 +3701,18 @@ TQ_ButtonState TDEApplication::keyboardMouseState()
return static_cast< ButtonState >( ret ); return static_cast< ButtonState >( ret );
} }
#if defined Q_WS_X11
int TDEApplication::currentX11VT()
{
return get_x_vtnum(TQPaintDevice::x11AppDisplay());
}
#else // Q_WS_X11
int TDEApplication::currentX11VT()
{
return -1;
}
#endif // Q_WS_X11
void TDEApplication::installSigpipeHandler() void TDEApplication::installSigpipeHandler()
{ {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX

@ -1220,6 +1220,13 @@ public:
*/ */
static uint mouseState() KDE_DEPRECATED; static uint mouseState() KDE_DEPRECATED;
/**
* Returns the VT that the current X server is running on, or -1 if this information is unavailable.
*
* @since 14.0.0
*/
static int currentX11VT();
public slots: public slots:
/** /**

@ -937,7 +937,7 @@ TQString TDEStorageDevice::mountPath() {
file.close(); file.close();
} }
// While this device is not directly mounted, it could concievably be mounted via the Device Mapper // While this device is not directly mounted, it could conceivably be mounted via the Device Mapper
// If so, try to retrieve the mount path... // If so, try to retrieve the mount path...
TQStringList slaveDeviceList = holdingDevices(); TQStringList slaveDeviceList = holdingDevices();
for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) { for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
@ -953,7 +953,7 @@ TQString TDEStorageDevice::mountPath() {
return TQString::null; return TQString::null;
} }
TQString TDEStorageDevice::mountDevice(TQString mediaName, TQString mountOptions, TQString* errRet, int* retcode) { TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
int internal_retcode; int internal_retcode;
if (!retcode) { if (!retcode) {
retcode = &internal_retcode; retcode = &internal_retcode;
@ -969,12 +969,37 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TQString mountOptions
KTempFile passwordFile(TQString::null, "tmp", 0600); KTempFile passwordFile(TQString::null, "tmp", 0600);
passwordFile.setAutoDelete(true); passwordFile.setAutoDelete(true);
TQString optionString;
if (mountOptions["ro"] == "true") {
optionString.append(" -r");
}
if (mountOptions["atime"] != "true") {
optionString.append(" -A");
}
if (mountOptions["utf8"] == "true") {
optionString.append(" -c utf8");
}
if (mountOptions["sync"] == "true") {
optionString.append(" -s");
}
if (mountOptions.contains("filesystem")) {
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
}
if (mountOptions.contains("locale")) {
optionString.append(TQString(" -c %1").arg(mountOptions["locale"]));
}
TQString passFileName = passwordFile.name(); TQString passFileName = passwordFile.name();
TQString devNode = deviceNode(); TQString devNode = deviceNode();
passFileName.replace("'", "'\\''"); passFileName.replace("'", "'\\''");
devNode.replace("'", "'\\''"); devNode.replace("'", "'\\''");
mediaName.replace("'", "'\\''"); mediaName.replace("'", "'\\''");
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(mountOptions).arg(devNode).arg(mediaName); TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
FILE *exepipe = popen(command.ascii(), "r"); FILE *exepipe = popen(command.ascii(), "r");
if (exepipe) { if (exepipe) {
@ -995,7 +1020,7 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TQString mountOptions
return ret; return ret;
} }
TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TQString mountOptions, TQString* errRet, int* retcode) { TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) {
int internal_retcode; int internal_retcode;
if (!retcode) { if (!retcode) {
retcode = &internal_retcode; retcode = &internal_retcode;
@ -1018,12 +1043,37 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
pwFile->writeBlock(passphrase.ascii(), passphrase.length()); pwFile->writeBlock(passphrase.ascii(), passphrase.length());
pwFile->flush(); pwFile->flush();
TQString optionString;
if (mountOptions["ro"] == "true") {
optionString.append(" -r");
}
if (mountOptions["atime"] != "true") {
optionString.append(" -A");
}
if (mountOptions["utf8"] == "true") {
optionString.append(" -c utf8");
}
if (mountOptions["sync"] == "true") {
optionString.append(" -s");
}
if (mountOptions.contains("filesystem")) {
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
}
if (mountOptions.contains("locale")) {
optionString.append(TQString(" -c %1").arg(mountOptions["locale"]));
}
TQString passFileName = passwordFile.name(); TQString passFileName = passwordFile.name();
TQString devNode = deviceNode(); TQString devNode = deviceNode();
passFileName.replace("'", "'\\''"); passFileName.replace("'", "'\\''");
devNode.replace("'", "'\\''"); devNode.replace("'", "'\\''");
mediaName.replace("'", "'\\''"); mediaName.replace("'", "'\\''");
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(mountOptions).arg(devNode).arg(mediaName); TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
FILE *exepipe = popen(command.ascii(), "r"); FILE *exepipe = popen(command.ascii(), "r");
if (exepipe) { if (exepipe) {

@ -513,6 +513,8 @@ class TDECORE_EXPORT TDEGenericDevice : public TQObject
friend class TDEHardwareDevices; friend class TDEHardwareDevices;
}; };
typedef TQMap<TQString,TQString> TDEStorageMountOptions;
class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
{ {
public: public:
@ -582,7 +584,7 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
* *
* @return a TQString with the mount path, if successful * @return a TQString with the mount path, if successful
*/ */
TQString mountDevice(TQString mediaName=TQString::null, TQString mountOptions=TQString::null, TQString* errRet=0, int* retcode=0); TQString mountDevice(TQString mediaName=TQString::null, TDEStorageMountOptions mountOptions=TDEStorageMountOptions(), TQString* errRet=0, int* retcode=0);
/** /**
* Mounts the encrypted device if the correct passphrase is given * Mounts the encrypted device if the correct passphrase is given
@ -595,7 +597,7 @@ class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice
* *
* @return a TQString with the mount path, if successful * @return a TQString with the mount path, if successful
*/ */
TQString mountEncryptedDevice(TQString passphrase, TQString mediaName=TQString::null, TQString mountOptions=TQString::null, TQString* errRet=0, int* retcode=0); TQString mountEncryptedDevice(TQString passphrase, TQString mediaName=TQString::null, TDEStorageMountOptions mountOptions=TDEStorageMountOptions(), TQString* errRet=0, int* retcode=0);
/** /**
* Unmounts the device * Unmounts the device

Loading…
Cancel
Save