The device %1 (%2) named '%3' and currently mounted at %4 can not be unmounted at this time.%5
Would you like to forcibly terminate these processes?
All unsaved data would be lost").arg("system:/media/" + medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL()).arg(processesUsingDev)) == KMessageBox::Yes) {
+ killUsingProcesses(medium);
+ if (!sdevice->unmountDevice(&unmountMessages, &unmountRetcode)) {
+ // Unmount failed!
+ qerror = "" + i18n("Unfortunately, the device %1 (%2) named '%3' and currently mounted at %4 could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
+ if (!unmountMessages.isNull()) {
+ qerror.append(i18n("Technical details:
").append(unmountMessages));
+ }
+ qerror.append("
");
+ }
+ else {
+ qerror = "";
+ }
+ }
+ }
+ }
+
+ if (qerror != "") {
+ return qerror;
+ }
+
+ ResetProperties(sdevice);
+
+ return TQString();
+}
+
+TQString TDEBackend::isInFstab(const Medium *medium)
+{
+ KMountPoint::List fstab = KMountPoint::possibleMountPoints(KMountPoint::NeedMountOptions|KMountPoint::NeedRealDeviceName);
+
+ KMountPoint::List::iterator it = fstab.begin();
+ KMountPoint::List::iterator end = fstab.end();
+
+ for (; it!=end; ++it)
+ {
+ TQString reald = (*it)->realDeviceName();
+ if ( reald.endsWith( "/" ) ) {
+ reald = reald.left( reald.length() - 1 );
+ }
+ if ((*it)->mountedFrom() == medium->deviceNode() || ( !medium->deviceNode().isEmpty() && reald == medium->deviceNode() ) )
+ {
+ TQStringList opts = (*it)->mountOptions();
+ if (opts.contains("user") || opts.contains("users")) {
+ return (*it)->mountPoint();
+ }
+ }
+ }
+
+ return TQString::null;
+}
+
+TQString TDEBackend::listUsingProcesses(const Medium* medium)
+{
+ TQString proclist, fullmsg;
+ TQString cmdline = TQString("/usr/bin/env fuser -vm %1 2>&1").arg(KProcess::quote(medium->mountPoint()));
+ FILE *fuser = popen(cmdline.latin1(), "r");
+
+ uint counter = 0;
+ if (fuser) {
+ proclist += "
";
+ TQTextIStream is(fuser);
+ TQString tmp;
+ while (!is.atEnd()) {
+ tmp = is.readLine();
+ tmp = TQStyleSheet::escape(tmp) + "\n";
+
+ proclist += tmp;
+ if (counter++ > 10) {
+ proclist += "...";
+ break;
+ }
+ }
+ proclist += "
";
+ (void)pclose( fuser );
+ }
+ if (counter) {
+ fullmsg = i18n("Programs still using the device "
+ "have been detected. They are listed below. You have to "
+ "close them or change their working directory before "
+ "attempting to unmount the device again.");
+ fullmsg += "
" + proclist;
+ return fullmsg;
+ }
+ else {
+ return TQString::null;
+ }
+}
+
+TQString TDEBackend::killUsingProcesses(const Medium* medium)
+{
+ TQString proclist, fullmsg;
+ TQString cmdline = TQString("/usr/bin/env fuser -vmk %1 2>&1").arg(KProcess::quote(medium->mountPoint()));
+ FILE *fuser = popen(cmdline.latin1(), "r");
+
+ uint counter = 0;
+ if (fuser) {
+ proclist += "";
+ TQTextIStream is(fuser);
+ TQString tmp;
+ while (!is.atEnd()) {
+ tmp = is.readLine();
+ tmp = TQStyleSheet::escape(tmp) + "\n";
+
+ proclist += tmp;
+ if (counter++ > 10) {
+ proclist += "...";
+ break;
+ }
+ }
+ proclist += "
";
+ (void)pclose( fuser );
+ }
+ if (counter) {
+ fullmsg = i18n("Programs that were still using the device "
+ "have been forcibly terminated. They are listed below.");
+ fullmsg += "
" + proclist;
+ return fullmsg;
+ }
+ else {
+ return TQString::null;
+ }
+}
+
+TQString TDEBackend::generateName(const TQString &devNode)
+{
+ return KURL(devNode).fileName();
+}
+#include "tdehardwarebackend.moc"
\ No newline at end of file
diff --git a/kioslave/media/mediamanager/tdehardwarebackend.h b/kioslave/media/mediamanager/tdehardwarebackend.h
index e69de29bb..40181b062 100644
--- a/kioslave/media/mediamanager/tdehardwarebackend.h
+++ b/kioslave/media/mediamanager/tdehardwarebackend.h
@@ -0,0 +1,165 @@
+/* This file is part of the TDE Project
+ Copyright (c) 2012 Timothy Pearson
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/**
+* This is a media:/ backend for the builtin TDE hardware library
+*
+* @author Timothy Pearson
+* @short media:/ backend for the TDE hardware library
+*/
+
+#ifndef _TDEBACKEND_H_
+#define _TDEBACKEND_H_
+
+#include "backendbase.h"
+
+#include
+#include
+#include
+
+#include
+
+#include
+
+namespace KIO {
+ class Job;
+}
+
+class Dialog;
+
+class TDEBackend : public TQObject, public BackendBase
+{
+Q_OBJECT
+
+public:
+ /**
+ * Constructor
+ */
+ TDEBackend(MediaList &list, TQObject* parent);
+
+ /**
+ * Destructor
+ */
+ ~TDEBackend();
+
+ /**
+ * List all devices and append them to the media device list (called only once, at startup).
+ *
+ * @return true if succeded, false otherwise
+ */
+ bool ListDevices();
+
+ TQStringList mountoptions(const TQString &id);
+
+ bool setMountoptions(const TQString &id, const TQStringList &options);
+
+ TQString mount(const TQString &id);
+ TQString mount(const Medium *medium);
+ TQString unmount(const TQString &id);
+// TQString decrypt(const TQString &id, const TQString &password);
+// TQString undecrypt(const TQString &id);
+
+private:
+ /**
+ * Append a device in the media list. This function will check if the device
+ * is worth listing.
+ *
+ * @param sdevice A pointer to a TDEStorageDevice object
+ * @param allowNotification Indicates if this event will be notified to the user
+ */
+ void AddDevice(TDEStorageDevice * sdevice, bool allowNotification=true);
+
+ /**
+ * Remove a device from the device list
+ *
+ * @param sdevice A pointer to a TDEStorageDevice object
+ */
+ void RemoveDevice(TDEStorageDevice * sdevice);
+
+ /**
+ * A device has changed, update it
+ *
+ * @param sdevice A pointer to a TDEStorageDevice object
+ */
+ void ModifyDevice(TDEStorageDevice * sdevice);
+
+private slots:
+ void AddDeviceHandler(TDEGenericDevice* device);
+ void RemoveDeviceHandler(TDEGenericDevice* device);
+ void ModifyDeviceHandler(TDEGenericDevice* device);
+
+ void slotPasswordReady();
+ void slotPasswordCancel();
+
+signals:
+ void signalDecryptionPasswordError(TQString);
+
+/* Set media properties */
+private:
+ /**
+ * Reset properties for the given medium
+ *
+ * @param sdevice A pointer to a TDEStorageDevice objec
+ */
+ void ResetProperties(TDEStorageDevice * sdevice, bool allowNotification=false);
+
+ /**
+ * Find the medium that is concerned with device udi
+ */
+// const char* findMediumUdiFromUdi(const char* udi);
+
+ void setVolumeProperties(Medium* medium);
+ bool setFloppyProperties(Medium* medium);
+// void setFloppyMountState( Medium* medium );
+// bool setFstabProperties(Medium* medium);
+ void setCameraProperties(Medium* medium);
+ TQString generateName(const TQString &devNode);
+ static TQString isInFstab(const Medium *medium);
+ static TQString listUsingProcesses(const Medium *medium);
+ static TQString killUsingProcesses(const Medium *medium);
+
+ // Decryption
+ Dialog* m_decryptDialog;
+ TQString m_decryptionPassword;
+ bool m_decryptPasswordValid;
+
+/* TDE structures */
+private:
+ /**
+ * Object for the kded module
+ */
+ TQObject* m_parent;
+
+ /**
+ * Data structure for fstab mount/unmount jobs
+ */
+ struct mount_job_data {
+ // [in] Medium, which is being mounted/unmounted by the job
+ const Medium* medium;
+ // [in,out] Should be set to true when the job completes
+ bool completed;
+ // [out] KIO::Error if an error occured during operation. Otherwise, 0
+ int error;
+ // [out] Error message to be displayed to the user
+ TQString errorMessage;
+ };
+
+ TQMap mount_jobs;
+};
+
+#endif /* _TDEBACKEND_H_ */