1
/**************************************************************************
2
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.com> *
3
* This program is free software; you can redistribute it and/or modify *
4
* it under the terms of the GNU General Public License as published by *
5
* the Free Software Foundation; either version 2 of the License, or *
6
* (at your option) any later version. *
8
* This program is distributed in the hope that it will be useful, *
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11
* GNU General Public License for more details. *
13
* You should have received a copy of the GNU General Public License *
14
* along with this program; if not, write to the *
15
* Free Software Foundation, Inc., *
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
17
***************************************************************************/
20
#include "devicewrapper.h"
25
#include <QtDBus/QDBusInterface>
26
#include <QtDBus/QDBusReply>
29
#include <Solid/Device>
30
#include <Solid/StorageVolume>
31
#include <Solid/StorageAccess>
32
#include <Solid/OpticalDrive>
33
#include <Solid/OpticalDisc>
37
#include <KMessageBox>
38
#include <KStandardDirs>
39
#include <kdesktopfileactions.h>
42
#include <Plasma/DataEngine>
44
DeviceWrapper::DeviceWrapper(const QString& udi)
46
m_isStorageAccess(false),
47
m_isAccessible(false),
48
m_isEncryptedContainer(false)
50
m_udi = m_device.udi();
53
DeviceWrapper::~DeviceWrapper()
57
void DeviceWrapper::dataUpdated(const QString &source, Plasma::DataEngine::Data data)
64
if (data["text"].isValid()) {
66
foreach (const QString &desktop, data["predicateFiles"].toStringList()) {
67
QString filePath = KStandardDirs::locate("data", "solid/actions/" + desktop);
68
QList<KServiceAction> services = KDesktopFileActions::userDefinedServices(filePath, true);
70
foreach (KServiceAction serviceAction, services) {
71
QString actionId = id()+'_'+desktop+'_'+serviceAction.name();
72
m_actionIds << actionId;
73
emit registerAction(actionId, serviceAction.icon(), serviceAction.text(), desktop);
76
m_isEncryptedContainer = data["isEncryptedContainer"].toBool();
78
if (data["Device Types"].toStringList().contains("Storage Access")) {
79
m_isStorageAccess = true;
80
if (data["Accessible"].toBool() == true) {
81
m_isAccessible = true;
83
m_isAccessible = false;
86
m_isStorageAccess = false;
88
if (data["Device Types"].toStringList().contains("OpticalDisc")) {
89
m_isOpticalDisc = true;
91
m_isOpticalDisc = false;
95
m_emblems = m_device.emblems();
97
emit refreshMatch(m_udi);
101
QString DeviceWrapper::id() const {
105
Solid::Device DeviceWrapper::device() const {
109
KIcon DeviceWrapper::icon() const {
110
return KIcon(m_device.icon(), NULL, m_emblems);
113
bool DeviceWrapper::isStorageAccess() const {
114
return m_isStorageAccess;
117
bool DeviceWrapper::isAccessible() const {
118
return m_isAccessible;
121
bool DeviceWrapper::isEncryptedContainer() const {
122
return m_isEncryptedContainer;
125
bool DeviceWrapper::isOpticalDisc() const {
126
return m_isOpticalDisc;
129
QString DeviceWrapper::description() const {
130
return m_device.description();
133
void DeviceWrapper::setForceEject(bool force)
135
m_forceEject = force;
138
QString DeviceWrapper::defaultAction() const {
140
QString actionString;
142
if (m_isOpticalDisc && m_forceEject) {
143
actionString = i18n("Eject medium");
144
} else if (m_isStorageAccess) {
145
if (!m_isEncryptedContainer) {
146
if (!m_isAccessible) {
147
actionString = i18n("Mount the device");
149
actionString = i18n("Unmount the device");
152
if (!m_isAccessible) {
153
actionString = i18nc("Unlock the encrypted container; will ask for a password; partitions inside will appear as they had been plugged in","Unlock the container");
155
actionString = i18nc("Close the encrypted container; partitions inside will disappear as they had been unplugged", "Lock the container");
159
actionString = i18n("Eject medium");
164
void DeviceWrapper::runAction(QAction * action)
167
QString desktopAction = action->data().toString();
168
if (!desktopAction.isEmpty()) {
169
QStringList desktopFiles;
170
desktopFiles.append(desktopAction);
171
QDBusInterface soliduiserver("org.kde.kded", "/modules/soliduiserver", "org.kde.SolidUiServer");
172
soliduiserver.asyncCall("showActionsDialog", id(), desktopFiles);
175
if (isOpticalDisc() && m_forceEject) {
176
Solid::OpticalDrive *drive = m_device.parent().as<Solid::OpticalDrive>();
183
if (m_device.is<Solid::StorageVolume>()) {
184
Solid::StorageAccess *access = m_device.as<Solid::StorageAccess>();
186
if (access->isAccessible()) {
195
if (isOpticalDisc()) {
196
Solid::OpticalDrive *drive = m_device.parent().as<Solid::OpticalDrive>();
204
QStringList DeviceWrapper::actionIds() const
209
#include "devicewrapper.moc"