1 | /* |
2 | * This file is part of the KDE project |
3 | * Copyright (C) 2009 Shaun Reich <shaun.reich@kdemail.net> |
4 | * Copyright (C) 2006-2008 Rafael Fernández López <ereslibre@kde.org> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License version 2 as published by the Free Software Foundation. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef PROGRESSLISTMODEL_H |
22 | #define PROGRESSLISTMODEL_H |
23 | |
24 | #include "uiserver.h" |
25 | #include "jobview.h" |
26 | |
27 | #include <QDBusContext> |
28 | |
29 | |
30 | class QDBusAbstractInterface; |
31 | class QDBusServiceWatcher; |
32 | |
33 | class ProgressListModel: public QAbstractItemModel, protected QDBusContext |
34 | { |
35 | Q_OBJECT |
36 | Q_CLASSINFO("D-Bus Interface" , "org.kde.JobViewServer" ) |
37 | |
38 | |
39 | public: |
40 | |
41 | explicit ProgressListModel(QObject *parent = 0); |
42 | ~ProgressListModel(); |
43 | |
44 | QModelIndex parent(const QModelIndex&) const; |
45 | |
46 | |
47 | /** |
48 | * Returns what operations the model/delegate support on the given @p index |
49 | * |
50 | * @param index the index in which you want to know the allowed operations |
51 | * @return the allowed operations on the model/delegate |
52 | */ |
53 | Qt::ItemFlags flags(const QModelIndex &index) const; |
54 | |
55 | |
56 | /** |
57 | * Returns the data on @p index that @p role contains. The result is |
58 | * a QVariant, so you may need to cast it to the type you want |
59 | * |
60 | * @param index the index in which you are accessing |
61 | * @param role the role you want to retrieve |
62 | * @return the data in a QVariant class |
63 | */ |
64 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
65 | |
66 | |
67 | /** |
68 | * Returns the index for the given @p row. Since it is a list, @p column should |
69 | * be 0, but it will be ignored. @p parent will be ignored as well. |
70 | * |
71 | * @param row the row you want to get the index |
72 | * @param column will be ignored |
73 | * @param parent will be ignored |
74 | * @return the index for the given @p row as a QModelIndex |
75 | */ |
76 | QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; |
77 | |
78 | QModelIndex indexForJob(JobView *jobView) const; |
79 | |
80 | |
81 | /** |
82 | * Returns the number of columns |
83 | * |
84 | * @param parent will be ignored |
85 | * @return the number of columns. In this case is always 1 |
86 | */ |
87 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
88 | |
89 | |
90 | /** |
91 | * Returns the number of rows |
92 | * |
93 | * @param parent will be ignored |
94 | * @return the number of rows in the model |
95 | */ |
96 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
97 | |
98 | |
99 | /** |
100 | * Called by a KJob's DBus connection to this ("JobViewServer"). |
101 | * Indicates that the KJob is now in existence (and is a just-created job). |
102 | * Returns a QDBusObjectPath that represents a unique dbus path that is a subset |
103 | * of the current "org.kde.JobView" address(so there can be multiple jobs, and KJob |
104 | * can keep track of them. |
105 | */ |
106 | QDBusObjectPath requestView(const QString &appName, const QString &appIconName, int capabilities); |
107 | |
108 | public Q_SLOTS: |
109 | /** |
110 | * Calling this(within "org.kde.kuiserver") results in all of the |
111 | * information that pertains to any KJobs and status updates for |
112 | * them, being sent to this DBus address, at the given |
113 | * @p objectPath |
114 | * Note that you will also receive jobs that existed before this was |
115 | * called |
116 | */ |
117 | void registerService(const QString &service, const QString &objectPath); |
118 | |
119 | /** |
120 | * Forces emission of jobUrlsChanged() signal...exposed to D-BUS (because they need it). |
121 | * @see jobUrlsChanged |
122 | */ |
123 | void emitJobUrlsChanged(); |
124 | |
125 | /** |
126 | * Whether or not a JobTracker will be needed. This will occur if there are no useful registered |
127 | * services. For example, this would occur if Plasma has "Show application jobs/file transfers" disabled. |
128 | * In which case, returning true here would be expected. This way KDynamicJobTracker can create a |
129 | * KWidgetJobTracker for each job (shows a dialog for each job). |
130 | * @return if a proper job tracker needs to be created by something. |
131 | */ |
132 | bool requiresJobTracker(); |
133 | |
134 | /** |
135 | * Only used over D-BUS merely for debugging purposes. |
136 | * Lets us know which services and at which paths kuiserver |
137 | * thinks should be informed. e.g. Plasma |
138 | * (the applicationjobs dataengine), Dolphin, etc. |
139 | * @return list of currently registered services |
140 | */ |
141 | QStringList registeredJobContacts(); |
142 | |
143 | private Q_SLOTS: |
144 | |
145 | void jobFinished(JobView *jobView); |
146 | void jobChanged(uint jobId); |
147 | |
148 | |
149 | /** |
150 | * Implemented to handle the case when a client drops out. |
151 | */ |
152 | void serviceUnregistered(const QString &name); |
153 | |
154 | Q_SIGNALS: |
155 | void serviceDropped(const QString&); |
156 | |
157 | /** |
158 | * Emits a list of destination URL's that have |
159 | * jobs pertaining to them(when it changes). |
160 | */ |
161 | void jobUrlsChanged(QStringList); |
162 | |
163 | private: |
164 | |
165 | QDBusObjectPath newJob(const QString &appName, const QString &appIcon, int capabilities); |
166 | |
167 | ///< desturls |
168 | QStringList gatherJobUrls(); |
169 | |
170 | /** |
171 | * The next available(unused) unique jobId, we can use this one directly, |
172 | * just remember to increment it after you construct a job from it. |
173 | */ |
174 | uint m_jobId; |
175 | |
176 | QList<JobView*> m_jobViews; |
177 | /** |
178 | * Stores a relationship between the process that requested the job and |
179 | * the job itself by using the dbus service and he jobview. |
180 | */ |
181 | QHash<QString, JobView*> m_jobViewsOwners; |
182 | |
183 | /** |
184 | * Contains the list of registered services. In other words, the clients |
185 | * who have "subscribed" to our D-Bus interface so they can get informed |
186 | * about changes to all the jobs. |
187 | */ |
188 | QHash<QString, QDBusAbstractInterface*> m_registeredServices; |
189 | |
190 | UiServer *m_uiServer; |
191 | QDBusServiceWatcher *m_serviceWatcher; |
192 | }; |
193 | |
194 | Q_DECLARE_METATYPE(JobView*) |
195 | |
196 | #endif // PROGRESSLISTMODEL_H |
197 | |