[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/runtime/knotify
From: Jacopo De Simoi <wilderkde () gmail ! com>
Date: 2010-11-10 22:42:58
Message-ID: 20101110224258.53FA6AC89E () svn ! kde ! org
[Download RAW message or body]
SVN commit 1195371 by jacopods:
Notify when it's safe to disconnect a device.
Notice that this feature is disabled by default
FEATURE: 246842
M +20 -1 hardwarenotifications.notifyrc
M +40 -24 ksolidnotify.cpp
M +2 -0 ksolidnotify.h
--- trunk/KDE/kdebase/runtime/knotify/hardwarenotifications.notifyrc #1195370:1195371
@@ -56,7 +56,7 @@
Name[zh_CN]=硬件通知
Name[zh_TW]=硬體通知
IconName=emblem-mounted
-Comment=Notifications triggered by solid
+Comment=Notifications triggered by hardware devices
Comment[ar]=تنبيهات أطلقها سوليد
Comment[ast]=Notificaciones activaes por solid
Comment[ca]=Notificacions provocades pel Solid
@@ -107,8 +107,14 @@
Comment[x-test]=xxNotifications triggered by solidxx
Comment[zh_CN]=Solid 触发的通知
Comment[zh_TW]=solid 觸發的通知
+Contexts=devnotifier
Version=1
+[Context/devnotifier]
+Name=Device Notifier
+Comment=The Plasma device notifier is present
+Icon=highlight
+
[Event/mounterror]
Name=Mount or unmount error
Name[ar]=خطأ وصل أو فصل
@@ -218,3 +224,16 @@
Comment[zh_CN]=挂载或卸载设备时出现问题
Comment[zh_TW]=掛載或卸載裝置時發生錯誤
Action=Popup
+Contexts=devnotifier
+
+[Event/mounterror/devnotifier/present]
+Action=-Popup
+
+[Event/safetoremove]
+Name=The device can be safely removed
+Comment=The device which has been just unmounted is now safe to remove.
+Action=Popup
+Contexts=devnotifier
+
+[Event/safetoremove/devnotifier/present]
+Action=-Popup
--- trunk/KDE/kdebase/runtime/knotify/ksolidnotify.cpp #1195370:1195371
@@ -18,6 +18,7 @@
*/
#include "ksolidnotify.h"
+#include "knotify.h"
//solid specific includes
#include <Solid/DeviceNotifier>
@@ -93,6 +94,18 @@
m_devices.remove(udi);
}
+bool KSolidNotify::isSafelyRemovable(const QString &udi)
+{
+ Solid::Device parent = m_devices[udi].parent();
+ if (parent.is<Solid::StorageDrive>())
+ {
+ Solid::StorageDrive *drive = parent.as<Solid::StorageDrive>();
+ return (!drive->isInUse() && (drive->isHotpluggable() || drive->isRemovable()));
+ }
+
+ return !m_devices[udi].as<Solid::StorageAccess>()->isAccessible();
+}
+
void KSolidNotify::connectSignals(Solid::Device* device)
{
if (device->is<Solid::StorageVolume>())
@@ -114,41 +127,48 @@
}
}
-void KSolidNotify::storageSetupDone(Solid::ErrorType error, QVariant errorData, \
const QString &udi) +void KSolidNotify::notifySolidEvent(QString event, \
Solid::ErrorType error, QVariant errorData, const QString & udi, const QString & \
errorMessage) {
- if (error)
+ ContextList context;
+ if (m_dbusServiceExists)
{
- Solid::Device device(udi);
- QString errorMessage = i18n("Could not mount the following device: %1", \
device.description());
- if (!m_dbusServiceExists)
+ KNotifyConfig mountConfig("hardwarenotifications", ContextList(), event);
+ if (mountConfig.readEntry("Action").split('|').contains("Popup"))
{
- m_kNotify->event("mounterror", "hardwarenotifications", ContextList(), \
i18n("Device error"), errorMessage, KNotifyImage(), QStringList(), \
-1);
- } else
- {
QDBusMessage m = QDBusMessage::createMethodCall( dbusDeviceNotificationsName, \
dbusDeviceNotificationsPath, dbusDeviceNotificationsName, "notify" ); m << error << \
errorMessage << errorData.toString().simplified() << udi; \
QDBusConnection::sessionBus().call(m); }
+ context << QPair<QString, QString>("devnotifier", "present");
}
+
+ m_kNotify->event(event, "hardwarenotifications", context, i18n("Devices \
notification"), errorMessage, KNotifyImage(), QStringList(), -1); +
}
+void KSolidNotify::storageSetupDone(Solid::ErrorType error, QVariant errorData, \
const QString &udi) +{
+ if (error)
+ {
+ Solid::Device device(udi);
+ QString errorMessage = i18n("Could not mount the following device: %1", \
device.description()); + notifySolidEvent("mounterror", error, errorData, udi, \
errorMessage); + }
+}
+
void KSolidNotify::storageTeardownDone(Solid::ErrorType error, QVariant errorData, \
const QString &udi) {
if (error)
{
Solid::Device device(udi);
QString errorMessage = i18n("Could not unmount the following device: %1\nOne or \
more files on this device are open within an application ", \
device.description());
- if (!m_dbusServiceExists)
+ notifySolidEvent("mounterror", error, errorData, udi, errorMessage);
+ } else if (isSafelyRemovable(udi))
{
- m_kNotify->event("mounterror", "hardwarenotifications", ContextList(), \
i18n("Device error"), errorMessage, KNotifyImage(), QStringList(), \
-1);
- } else
- {
- QDBusMessage m = QDBusMessage::createMethodCall( dbusDeviceNotificationsName, \
dbusDeviceNotificationsPath, dbusDeviceNotificationsName, "notify" );
- m << error << errorMessage << errorData.toString().simplified() << udi;
- QDBusConnection::sessionBus().call(m);
+ Solid::Device device(udi);
+ notifySolidEvent("safetoremove", error, errorData, udi, i18nc("The term \"remove\" \
here means \"physically disconnect the device from the computer\", whereas \"safely\" \
means \"without risk of data loss\"", "The following device can now be safely \
removed: %1", device.description())); }
}
-}
void KSolidNotify::storageEjectDone(Solid::ErrorType error, QVariant errorData, \
const QString &udi) {
@@ -168,17 +188,13 @@
Solid::Device discDevice(discUdi);
QString errorMessage = i18n("Could not eject the following device: %1\nOne or more \
files on this device are open within an application ", \
discDevice.description());
- if (!m_dbusServiceExists)
+ notifySolidEvent("mounterror", error, errorData, udi, errorMessage);
+ } else if (isSafelyRemovable(udi))
{
- m_kNotify->event("mounterror", "hardwarenotifications", ContextList(), \
i18n("Device error"), errorMessage, KNotifyImage(), QStringList(), \
-1);
- } else
- {
- QDBusMessage m = QDBusMessage::createMethodCall( dbusDeviceNotificationsName, \
dbusDeviceNotificationsPath, dbusDeviceNotificationsName, "notify" );
- m << error << errorMessage << errorData.toString().simplified() << udi;
- QDBusConnection::sessionBus().call(m);
+ Solid::Device device(udi);
+ notifySolidEvent("safetoremove", error, errorData, udi, i18n("The following device \
can now be safely removed: %1", device.description())); }
}
-}
void KSolidNotify::slotServiceOwnerChanged( const QString & serviceName, const \
QString & oldOwner, const QString & newOwner ) {
--- trunk/KDE/kdebase/runtime/knotify/ksolidnotify.h #1195370:1195371
@@ -60,6 +60,8 @@
private:
void connectSignals(Solid::Device* device);
+ bool isSafelyRemovable(const QString &udi);
+ void notifySolidEvent(QString event, Solid::ErrorType error, QVariant errorData, \
const QString & udi, const QString & errorMessage);
KNotify* m_kNotify;
QHash<QString, Solid::Device> m_devices;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic