not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / devicenotifier / notifierdialog.h
blob7ea28a6136594aae4bb9daf4d6ecc9a141c3264e
1 /***************************************************************************
2 * Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
20 #ifndef NOTIFIERDIALOG_H
21 #define NOTIFIERDIALOG_H
23 //Qt
24 #include <QWidget>
25 #include <QStringList>
27 //solid
28 #include <solid/solidnamespace.h>
31 //to remove
32 #include <QTreeView>
34 class QModelIndex;
35 class QStandardItemModel;
36 class QStandardItem;
37 class QLabel;
39 //own
40 class DeviceNotifier;
42 //desktop view
43 namespace Plasma
45 class Icon;
46 class Dialog;
48 namespace Solid
50 class Device;
52 namespace Notifier
54 class NotifierView;
56 /**
57 * @short The panel used to display devices in a popup
60 class NotifierDialog : public QObject
62 Q_OBJECT
64 public:
67 ///Specific role for the data-model
68 enum SpecificRoles {
69 SolidUdiRole = Qt::UserRole + 1,
70 PredicateFilesRole = Qt::UserRole + 2,
71 ActionRole = Qt::UserRole + 3,
72 IconNameRole = Qt::UserRole + 4,
73 ScopeRole = Qt::UserRole + 5,
74 SubTitleMandatoryRole = Qt::UserRole + 6
77 /**
78 * Constructor of the dialog
79 * @param notifier the notifier attached to this dialog
80 * @param area where the dialog is displayed
81 * @param parent the parent of this object
82 **/
83 NotifierDialog(DeviceNotifier * notifier,QObject *parent = 0);
85 /**
86 * Default destructor
87 **/
88 virtual ~NotifierDialog();
90 /**
91 * Returns the related QWidget.
92 **/
93 QWidget * dialog();
95 /**
96 * Hide the dialog
97 **/
98 void hide();
101 * Show the dialog
103 void show();
106 * insert a device in the data-model of the dialog
107 * @param name the name of the device
109 void insertDevice(const QString &name);
111 void setUnMount(bool unmount,const QString &name);
114 * Allow to set data which will be displayed by the view
115 * @param name the name of the device
116 * @param data the data
117 * @param role the role in the data-model
119 void setDeviceData(const QString &name, QVariant data, int role);
122 * Allow to get a data display by the view
123 * @param name the name of the device
124 * @param role the role where is the data
126 QVariant getDeviceData(const QString &name, int role);
129 * Remove a device in the dialog
130 * @param name the name of the device
132 void removeDevice(const QString &name);
135 * Remove a device in the view (provided by convenience)
136 * @param index the index where the data will be delete
138 void removeDevice(int index);
141 * Return the number of items displayed
144 int countDevices();
147 * get the udi of a device displayed in the dialog
148 * @param index the index of the device
150 QString getDeviceUdi(int index);
152 signals :
154 void itemSelected();
156 private slots:
158 * @internal slot called when user has click on a item in the dialog
159 * @param index the model index which is clicked
161 void slotOnItemClicked(const QModelIndex & index);
164 * @internal slot called when an eject is finished
165 * @param errorData the error if problem
166 * @param error type of error given by solid
168 void storageEjectDone(Solid::ErrorType error, QVariant errorData);
171 * @internal slot called when a storage tear is finished
172 * @param errorData the error if problem
173 * @param error type of error given by solid
175 void storageTeardownDone(Solid::ErrorType error, QVariant errorData);
178 * @internal slot called to restore to the notifier his icon
180 void resetNotifierIcon();
183 * @internal update the color of the label to follow plasma theme
186 void updateColors();
189 private :
191 * @internal build the dialog depending where it is
193 void buildDialog();
196 * @internal get the model index in the data-model by using the udi in parameter
197 * @param udi the udi used to find the model index
199 QModelIndex indexForUdi(const QString &udi) const;
201 ///The data-model used to store devices
202 QStandardItemModel *m_hotplugModel;
204 // The widget which display the panel
205 QWidget *m_widget;
206 ///The tree view used to display the content
207 NotifierView *m_notifierView;
209 ///QLabel which represent the title
210 QLabel * m_label;
212 ///The applet attached to this item
213 DeviceNotifier * m_notifier;
215 ///Root item in treeview
216 QStandardItem *m_rootItem;
219 * @internal Search a category with same name. If not find, create a new category in top of treeview
220 * @param categoryName the name of the category for device
222 QStandardItem* searchOrCreateDeviceCategory(const QString &categoryName);
225 * @internal get The category name of a device plugged
226 * @param device the solid device plugged in hardware
228 QString getCategoryNameOfDevice(const Solid::Device& device);
233 #endif