1
/***************************************************************************
2
* Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com> *
3
* Copyright 2009 by Giulio Camuffo <giuliocamuffo@gmail.com> *
4
* Copyright 2009 by Jacopo De Simoi <wilderkde@gmail.com> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20
***************************************************************************/
22
#ifndef DEVICENOTIFIER_H
23
#define DEVICENOTIFIER_H
26
#include <Solid/Device>
29
#include <Plasma/PopupApplet>
30
#include <Plasma/DataEngine>
33
#include "ui_configurationpage.h"
42
class HotplugDataConsumer : public QObject
46
HotplugDataConsumer(NotifierDialog *parent);
50
* slot called when a source of the hotplug engine is updated
51
* @param udi the udi of the source
52
* @param data the data of the source
54
void dataUpdated(const QString &udi, Plasma::DataEngine::Data data);
57
NotifierDialog * const m_dialog;
60
class DeviceDataConsumer : public QObject
64
DeviceDataConsumer(NotifierDialog *parent);
68
* slot called when a source of the hotplug engine is updated
69
* @param udi the udi of the source
70
* @param data the data of the source
72
void dataUpdated(const QString &udi, Plasma::DataEngine::Data data);
75
NotifierDialog * const m_dialog;
79
* @short Applet used to display devices
82
class DeviceNotifier : public Plasma::PopupApplet
94
* Constructor of the applet
95
* @param parent the parent of this object
97
DeviceNotifier(QObject *parent, const QVariantList &args);
105
* initialize the applet (called by plasma automatically)
110
* Used to know it there are hidden devices
111
* @return true if there are hidden device
113
bool areThereHiddenDevices();
116
* allow to change the icon of the notifier if this applet is in icon mode
117
* @param name icon name
118
* @param timeout if not 0, time to wait before resetting the icon (in msecs)
120
void changeNotifierIcon(const QString &name = QString(), uint timeout = 0);
123
* The graphics widget that displays the list of devices.
125
QGraphicsWidget *graphicsWidget();
128
* Return true if the applet has been opened for internal reasons (i.e. has been shown
129
* with no user interaction);
131
bool poppedUpInternally();
134
* Force to keep the applet open until the user closes it manually
136
void keepPopupOpen();
138
QList<QAction *> contextualActions();
140
static const int LONG_NOTIFICATION_TIMEOUT = 7500;
141
static const int SHORT_NOTIFICATION_TIMEOUT = 2500;
145
* Reimplemented from Plasma::Applet
147
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
150
* Reimplemented from Plasma::Applet
152
void createConfigurationInterface(KConfigDialog *parent);
155
* Reimplemented from Plasma::PopupApplet
157
void popupEvent(bool show);
161
* Reimplemented from Plasma::Applet
163
void configChanged();
166
* @internal Sets the tooltip content properly before showing.
168
void toolTipAboutToShow();
171
* @internal Clears memory when needed.
173
void toolTipHidden();
176
* Sets the visibility of a device
177
* @param udi the udi of the device
178
* @param visibility true if it is visible
180
void setDeviceVisibility(const QString &udi, bool visibility);
183
* Define if the devices that would be hidden will be showed anyway
184
* @param visibility true if they have to be visible
186
void setGlobalVisibility(bool visibility);
190
* @param message the text of the message
191
* @param details details of the notification
192
* @param udi the udi of the device
194
void showNotification(const QString &message, const QString &details, const QString &udi);
198
* slot called when a source/device is added in the hotplug engine
199
* @param udi the udi of the new source
201
void onSourceAdded(const QString &udi);
204
* @internal slot called when a source/device is removed in the hotplug engine
205
* @param udi the udi of the removed source
207
void onSourceRemoved(const QString &udi);
210
* Reimplemented from Plasma::Applet
212
void configAccepted();
214
void newNotification(const QString &source);
218
* @internal Used to recreate the devices in the menu.
223
* @internal slot called to restore to the notifier his icon
225
void resetNotifierIcon();
229
* @internal used to register a new device that has appeared to us
231
void deviceAdded(const Solid::Device &device, bool hotplugged = true);
234
* @internal Used to fill the notifier from previous plugged devices
236
void fillPreviousDevices();
239
* @internal Used to popup the device view.
241
void notifyDevice(const QString &udi);
244
* @internal Used to remove the last device notification.
246
void removeLastDeviceNotification(const QString &udi);
248
// Data consumers that relay information to the main applet
249
HotplugDataConsumer *m_hotplugDataConsumer;
250
DeviceDataConsumer *m_deviceDataConsumer;
252
///the engine used to get hot plug devices
253
Plasma::DataEngine *m_hotplugEngine;
255
///The engine used to manage devices in the applet (unmount,...)
256
Plasma::DataEngine *m_solidDeviceEngine;
258
///The engine used to retrieve device notifications
259
Plasma::DataEngine *m_deviceNotificationsEngine;
261
///The dialog where devices are displayed
262
Notifier::NotifierDialog * m_dialog;
264
///the time durin when the dialog will be show
267
///the number of items displayed in the dialog
270
///the time during when the item will be displayed
273
///the timer for different use cases
276
//Timer to reset the icon
279
QList<QString> m_lastPlugged;
281
///list of the hidden devices
282
QList<QString> m_hiddenDevices;
284
///configuration page
285
Ui::configurationPage m_configurationUi;
287
///tells which devices to show
290
///bool to know if notifications are enabled
291
bool isNotificationEnabled : 1;
293
///list of the devices
294
///true if fillPreviousDevices is running
295
bool m_fillingPreviousDevices : 1;
297
///if true all the devices will be shown anyway
298
bool m_globalVisibility : 1;
300
///if true the applet will check if the removed devices were hidded
301
bool m_checkHiddenDevices : 1;
303
///if true we are triggering the popup internally
304
bool m_triggeringPopupInternally : 1;
306
///if true the applet popped up without user interaction (e.g. new device inserted)
307
bool m_poppedUpInternally : 1;
309
///embedded KCM modules in the configuration dialog
310
KCModuleProxy *m_autoMountingWidget;
311
KCModuleProxy *m_deviceActionsWidget;