mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
solid: move mount/unmount code to SolidUiServer KDED module
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
cb96859d28
commit
ce08557009
4 changed files with 41 additions and 54 deletions
|
@ -181,7 +181,7 @@ if(UDEV_FOUND)
|
|||
Support for m-p-i is included even if not found during build"
|
||||
)
|
||||
|
||||
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${KDE4_KDECORE_LIBS} ${UDEV_LIBRARIES})
|
||||
set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${KDE4_KDECORE_LIBS} ${QT_QTDBUS_LIBRARY} ${UDEV_LIBRARIES})
|
||||
endif(UDEV_FOUND)
|
||||
|
||||
set_source_files_properties(
|
||||
|
|
|
@ -19,12 +19,10 @@
|
|||
*/
|
||||
|
||||
#include "udevstorageaccess.h"
|
||||
#include "kstandarddirs.h"
|
||||
#include "kmountpoint.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Solid::Backends::UDev;
|
||||
|
@ -88,39 +86,20 @@ bool StorageAccess::setup()
|
|||
return true;
|
||||
}
|
||||
|
||||
// permission denied on /run/mount so.. using base directory that is writable
|
||||
const QString mountbase = KGlobal::dirs()->saveLocation("tmp");
|
||||
const QString idfsuuid(m_device->deviceProperty("ID_FS_UUID"));
|
||||
mountpoint = mountbase + QLatin1Char('/') + idfsuuid;
|
||||
QDir mountdir(mountbase);
|
||||
if (!mountdir.exists(idfsuuid) && !mountdir.mkdir(idfsuuid)) {
|
||||
qWarning() << "could not create" << mountpoint;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->broadcastActionRequested("setup");
|
||||
|
||||
const QStringList mountargs = QStringList() << "mount" << m_device->deviceProperty("DEVNAME") << mountpoint;
|
||||
QProcess mountproc;
|
||||
mountproc.start("kdesudo", mountargs);
|
||||
mountproc.waitForStarted();
|
||||
while (mountproc.state() == QProcess::Running) {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
QDBusInterface soliduiserver("org.kde.kded", "/modules/soliduiserver", "org.kde.SolidUiServer");
|
||||
QDBusReply<int> reply = soliduiserver.call("mountDevice", m_device->udi());
|
||||
|
||||
if (mountproc.exitCode() == 0) {
|
||||
const Solid::ErrorType replyvalue = static_cast<Solid::ErrorType>(reply.value());
|
||||
if (replyvalue == Solid::NoError) {
|
||||
m_device->broadcastActionDone("setup", Solid::NoError, QString());
|
||||
emit accessibilityChanged(true, m_device->udi());
|
||||
} else {
|
||||
QString mounterror = mountproc.readAllStandardError();
|
||||
if (mounterror.isEmpty()) {
|
||||
mounterror = mountproc.readAllStandardOutput();
|
||||
}
|
||||
qWarning() << "mount error" << mounterror;
|
||||
m_device->broadcastActionDone("setup", Solid::UnauthorizedOperation, mounterror);
|
||||
return true;
|
||||
}
|
||||
|
||||
return (mountproc.exitCode() == 0);
|
||||
m_device->broadcastActionDone("setup", replyvalue, Solid::errorString(replyvalue));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageAccess::teardown()
|
||||
|
@ -132,27 +111,18 @@ bool StorageAccess::teardown()
|
|||
|
||||
m_device->broadcastActionRequested("teardown");
|
||||
|
||||
const QStringList umountargs = QStringList() << "umount" << mountpoint;
|
||||
QProcess umountproc;
|
||||
umountproc.start("kdesudo", umountargs);
|
||||
umountproc.waitForStarted();
|
||||
while (umountproc.state() == QProcess::Running) {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
QDBusInterface soliduiserver("org.kde.kded", "/modules/soliduiserver", "org.kde.SolidUiServer");
|
||||
QDBusReply<int> reply = soliduiserver.call("unmountDevice", m_device->udi());
|
||||
|
||||
if (umountproc.exitCode() == 0) {
|
||||
const Solid::ErrorType replyvalue = static_cast<Solid::ErrorType>(reply.value());
|
||||
if (replyvalue == Solid::NoError) {
|
||||
m_device->broadcastActionDone("teardown", Solid::NoError, QString());
|
||||
emit accessibilityChanged(false, m_device->udi());
|
||||
} else {
|
||||
QString umounterror = umountproc.readAllStandardError();
|
||||
if (umounterror.isEmpty()) {
|
||||
umounterror = umountproc.readAllStandardOutput();
|
||||
}
|
||||
qWarning() << "unmount error" << umounterror;
|
||||
m_device->broadcastActionDone("teardown", Solid::UnauthorizedOperation, umounterror);
|
||||
return true;
|
||||
}
|
||||
|
||||
return (umountproc.exitCode() == 0);
|
||||
m_device->broadcastActionDone("teardown", replyvalue, Solid::errorString(replyvalue));
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccess::slotSetupRequested()
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "solidnamespace.h"
|
||||
#include "klocale.h"
|
||||
|
||||
static int registerSolidMetaTypes()
|
||||
{
|
||||
|
@ -26,9 +27,23 @@ static int registerSolidMetaTypes()
|
|||
|
||||
return 0; // something
|
||||
}
|
||||
|
||||
#ifdef Q_CONSTRUCTOR_FUNCTION
|
||||
Q_CONSTRUCTOR_FUNCTION(registerSolidMetaTypes)
|
||||
#else
|
||||
static const int _Solid_registerMetaTypes = registerSolidMetaTypes();
|
||||
#endif
|
||||
|
||||
QString Solid::errorString(const ErrorType error)
|
||||
{
|
||||
switch (error) {
|
||||
case Solid::UnauthorizedOperation:
|
||||
return i18n("Unauthorized operation");
|
||||
case Solid::DeviceBusy:
|
||||
return i18n("Device is busy");
|
||||
case Solid::OperationFailed:
|
||||
return i18n("Operation failed");
|
||||
case Solid::UserCanceled:
|
||||
return i18n("Canceled by user");
|
||||
case Solid::InvalidOption:
|
||||
return i18n("Invalid option");
|
||||
case Solid::MissingDriver:
|
||||
return i18n("Missing driver");
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef SOLID_SOLIDNAMESPACE_H
|
||||
#define SOLID_SOLIDNAMESPACE_H
|
||||
|
||||
#include <QtCore/QMetaType>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
enum ErrorType {
|
||||
|
@ -33,9 +35,9 @@ namespace Solid
|
|||
InvalidOption,
|
||||
MissingDriver
|
||||
};
|
||||
}
|
||||
|
||||
#include <QtCore/QMetaType>
|
||||
QString errorString(const ErrorType error);
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Solid::ErrorType)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue