1 /***************************************************************************
2 * Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.com> *
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. *
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. *
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
25 #include <QStringList>
28 #include <solid/solidnamespace.h>
35 class QStandardItemModel
;
57 * @short The panel used to display devices in a popup
60 class NotifierDialog
: public QObject
67 ///Specific role for the data-model
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
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
83 NotifierDialog(DeviceNotifier
* notifier
,QObject
*parent
= 0);
88 virtual ~NotifierDialog();
91 * Returns the related QWidget.
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
147 * get the udi of a device displayed in the dialog
148 * @param index the index of the device
150 QString
getDeviceUdi(int index
);
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
191 * @internal build the dialog depending where it is
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
206 ///The tree view used to display the content
207 NotifierView
*m_notifierView
;
209 ///QLabel which represent the title
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
);