~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/applets/devicenotifier/devicenotifier.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>               *
 
5
 *                                                                         *
 
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.                                   *
 
10
 *                                                                         *
 
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.                          *
 
15
 *                                                                         *
 
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
 ***************************************************************************/
 
21
 
 
22
#ifndef DEVICENOTIFIER_H
 
23
#define DEVICENOTIFIER_H
 
24
 
 
25
//Solid
 
26
#include <Solid/Device>
 
27
 
 
28
//Plasma
 
29
#include <Plasma/PopupApplet>
 
30
#include <Plasma/DataEngine>
 
31
 
 
32
///Ui includes
 
33
#include "ui_configurationpage.h"
 
34
 
 
35
class KCModuleProxy;
 
36
 
 
37
namespace Notifier
 
38
{
 
39
 
 
40
class NotifierDialog;
 
41
 
 
42
class HotplugDataConsumer : public QObject
 
43
{
 
44
    Q_OBJECT
 
45
public:
 
46
    HotplugDataConsumer(NotifierDialog *parent);
 
47
 
 
48
protected Q_SLOTS:
 
49
        /**
 
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
 
53
     **/
 
54
    void dataUpdated(const QString &udi, Plasma::DataEngine::Data data);
 
55
 
 
56
private:
 
57
    NotifierDialog * const m_dialog;
 
58
};
 
59
 
 
60
class DeviceDataConsumer : public QObject
 
61
{
 
62
    Q_OBJECT
 
63
public:
 
64
    DeviceDataConsumer(NotifierDialog *parent);
 
65
 
 
66
protected Q_SLOTS:
 
67
        /**
 
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
 
71
     **/
 
72
    void dataUpdated(const QString &udi, Plasma::DataEngine::Data data);
 
73
 
 
74
private:
 
75
    NotifierDialog * const m_dialog;
 
76
};
 
77
 
 
78
/**
 
79
 * @short Applet used to display devices
 
80
 *
 
81
 */
 
82
class DeviceNotifier : public Plasma::PopupApplet
 
83
{
 
84
    Q_OBJECT
 
85
 
 
86
    public:
 
87
        enum {
 
88
            RemovableOnly = 0,
 
89
            NonRemovableOnly = 1,
 
90
            AllDevices = 2
 
91
        };
 
92
 
 
93
        /**
 
94
         * Constructor of the applet
 
95
         * @param parent the parent of this object
 
96
         **/
 
97
        DeviceNotifier(QObject *parent, const QVariantList &args);
 
98
 
 
99
        /**
 
100
         * Default destructor
 
101
         **/
 
102
        ~DeviceNotifier();
 
103
 
 
104
        /**
 
105
         * initialize the applet (called by plasma automatically)
 
106
         **/
 
107
        void init();
 
108
 
 
109
        /**
 
110
         * Used to know it there are hidden devices
 
111
         * @return true if there are hidden device
 
112
         **/
 
113
        bool areThereHiddenDevices();
 
114
 
 
115
        /**
 
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)
 
119
         **/
 
120
        void changeNotifierIcon(const QString &name = QString(), uint timeout = 0);
 
121
 
 
122
        /**
 
123
         * The graphics widget that displays the list of devices.
 
124
         */
 
125
        QGraphicsWidget *graphicsWidget();
 
126
 
 
127
        /**
 
128
         * Return true if the applet has been opened for internal reasons (i.e. has been shown
 
129
         * with no user interaction);
 
130
         **/
 
131
        bool poppedUpInternally();
 
132
 
 
133
        /**
 
134
         * Force to keep the applet open until the user closes it manually
 
135
         */
 
136
        void keepPopupOpen();
 
137
 
 
138
        QList<QAction *> contextualActions();
 
139
 
 
140
        static const int LONG_NOTIFICATION_TIMEOUT = 7500;
 
141
        static const int SHORT_NOTIFICATION_TIMEOUT = 2500;
 
142
 
 
143
    protected:
 
144
        /**
 
145
         * Reimplemented from Plasma::Applet
 
146
         **/
 
147
        void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
 
148
 
 
149
        /**
 
150
         * Reimplemented from Plasma::Applet
 
151
         **/
 
152
        void createConfigurationInterface(KConfigDialog *parent);
 
153
 
 
154
        /**
 
155
        * Reimplemented from Plasma::PopupApplet
 
156
        **/
 
157
        void popupEvent(bool show);
 
158
 
 
159
    public slots:
 
160
        /**
 
161
        * Reimplemented from Plasma::Applet
 
162
        **/
 
163
        void configChanged();
 
164
 
 
165
        /**
 
166
        * @internal Sets the tooltip content properly before showing.
 
167
        */
 
168
        void toolTipAboutToShow();
 
169
 
 
170
        /**
 
171
        * @internal Clears memory when needed.
 
172
        */
 
173
        void toolTipHidden();
 
174
 
 
175
        /**
 
176
        * Sets the visibility of a device
 
177
        * @param udi the udi of the device
 
178
        * @param visibility true if it is visible
 
179
        **/
 
180
        void setDeviceVisibility(const QString &udi, bool visibility);
 
181
 
 
182
        /**
 
183
        * Define if the devices that would be hidden will be showed anyway
 
184
        * @param visibility true if they have to be visible
 
185
        **/
 
186
        void setGlobalVisibility(bool visibility);
 
187
 
 
188
        /**
 
189
        * Shows a message
 
190
        * @param message the text of the message
 
191
        * @param details details of the notification
 
192
        * @param udi the udi of the device
 
193
        **/
 
194
        void showNotification(const QString &message, const QString &details, const QString &udi);
 
195
 
 
196
    protected slots:
 
197
        /**
 
198
        * slot called when a source/device is added in the hotplug engine
 
199
        * @param udi the udi of the new source
 
200
        **/
 
201
        void onSourceAdded(const QString &udi);
 
202
 
 
203
        /**
 
204
        * @internal slot called when a source/device is removed in the hotplug engine
 
205
        * @param udi the udi of the removed source
 
206
        **/
 
207
        void onSourceRemoved(const QString &udi);
 
208
 
 
209
        /**
 
210
        * Reimplemented from Plasma::Applet
 
211
        **/
 
212
        void configAccepted();
 
213
 
 
214
        void newNotification(const QString &source);
 
215
 
 
216
    private slots:
 
217
        /**
 
218
        * @internal Used to recreate the devices in the menu.
 
219
        */
 
220
        void resetDevices();
 
221
 
 
222
        /**
 
223
        * @internal slot called to restore to the notifier his icon
 
224
        **/
 
225
        void resetNotifierIcon();
 
226
 
 
227
    private:
 
228
        /**
 
229
         * @internal used to register a new device that has appeared to us
 
230
         */
 
231
        void deviceAdded(const Solid::Device &device, bool hotplugged = true);
 
232
 
 
233
        /**
 
234
        * @internal Used to fill the notifier from previous plugged devices
 
235
        **/
 
236
        void fillPreviousDevices();
 
237
 
 
238
        /**
 
239
         * @internal Used to popup the device view.
 
240
         */
 
241
        void notifyDevice(const QString &udi);
 
242
 
 
243
        /**
 
244
         * @internal Used to remove the last device notification.
 
245
         */
 
246
        void removeLastDeviceNotification(const QString &udi);
 
247
 
 
248
        // Data consumers that relay information to the main applet
 
249
        HotplugDataConsumer *m_hotplugDataConsumer;
 
250
        DeviceDataConsumer *m_deviceDataConsumer;
 
251
 
 
252
        ///the engine used to get hot plug devices
 
253
        Plasma::DataEngine *m_hotplugEngine;
 
254
 
 
255
        ///The engine used to manage devices in the applet (unmount,...)
 
256
        Plasma::DataEngine *m_solidDeviceEngine;
 
257
 
 
258
        ///The engine used to retrieve device notifications
 
259
        Plasma::DataEngine *m_deviceNotificationsEngine;
 
260
 
 
261
        ///The dialog where devices are displayed
 
262
        Notifier::NotifierDialog * m_dialog;
 
263
 
 
264
        ///the time durin when the dialog will be show
 
265
        int m_displayTime;
 
266
 
 
267
        ///the number of items displayed in the dialog
 
268
        int m_numberItems;
 
269
 
 
270
        ///the time during when the item will be displayed
 
271
        int m_itemsValidity;
 
272
 
 
273
        ///the timer for different use cases
 
274
        QTimer *m_timer;
 
275
 
 
276
        //Timer to reset the icon
 
277
        QTimer *m_iconTimer;
 
278
 
 
279
        QList<QString> m_lastPlugged;
 
280
 
 
281
        ///list of the hidden devices
 
282
        QList<QString> m_hiddenDevices;
 
283
 
 
284
        ///configuration page
 
285
        Ui::configurationPage m_configurationUi;
 
286
 
 
287
        ///tells which devices to show
 
288
        int m_showDevices;
 
289
 
 
290
        ///bool to know if notifications are enabled
 
291
        bool isNotificationEnabled : 1;
 
292
 
 
293
        ///list of the devices
 
294
        ///true if fillPreviousDevices is running
 
295
        bool m_fillingPreviousDevices : 1;
 
296
 
 
297
        ///if true all the devices will be shown anyway
 
298
        bool m_globalVisibility : 1;
 
299
 
 
300
        ///if true the applet will check if the removed devices were hidded
 
301
        bool m_checkHiddenDevices : 1;
 
302
 
 
303
        ///if true we are triggering the popup internally
 
304
        bool m_triggeringPopupInternally : 1;
 
305
 
 
306
        ///if true the applet popped up without user interaction (e.g. new device inserted)
 
307
        bool m_poppedUpInternally : 1;
 
308
 
 
309
        ///embedded KCM modules in the configuration dialog
 
310
        KCModuleProxy *m_autoMountingWidget;
 
311
        KCModuleProxy *m_deviceActionsWidget;
 
312
};
 
313
 
 
314
}
 
315
#endif