add more spacing
[personal-kdebase.git] / runtime / kuiserver / progresslistmodel.h
blob8ef62d9a0ebc0c2c49576e0fa51d41f4764da93b
1 /**
2 * This file is part of the KDE project
3 * Copyright (C) 2006-2008 Rafael Fernández López <ereslibre@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef PROGRESSLISTMODEL_H
21 #define PROGRESSLISTMODEL_H
23 #include "uiserver.h"
25 #include <QAbstractListModel>
26 #include <QTimer>
28 #include <kio/global.h>
29 #include <kio/jobclasses.h>
31 class KWidgetJobTracker;
33 struct JobInfo
35 enum State {
36 InvalidState = 0,
37 Running,
38 Suspended,
39 Cancelled
42 int capabilities; ///< The capabilities of the job
43 UIServer::JobView *jobView; ///< The D-Bus object associated to this job
44 QString applicationName; ///< The application name
45 QString icon; ///< The icon name
46 QString sizeTotals; ///< The total size of the operation
47 QString sizeProcessed; ///< The processed size at the moment
48 qlonglong timeElapsed; ///< The elapsed time
49 qlonglong timeTotals; ///< The total time of the operation
50 QString speed; ///< The current speed of the operation (human readable, example, "3Mb/s")
51 int percent; ///< The current percent of the progress
52 QString message; ///< The information message to be shown
53 QHash<uint, QPair<QString, QString> > descFields; ///< Description fields
54 State state; ///< The state of the job
57 class ProgressListModel
58 : public QAbstractItemModel
60 Q_OBJECT
62 public:
63 enum ExtraModelRole
65 Capabilities = 33,
66 ApplicationName,
67 Icon,
68 SizeTotals,
69 SizeProcessed,
70 TimeTotals,
71 TimeElapsed,
72 Speed,
73 Percent,
74 Message,
75 DescFields,
76 State,
77 JobViewRole
80 ProgressListModel(QObject *parent = 0);
81 ~ProgressListModel();
83 QModelIndex parent(const QModelIndex&) const;
85 /**
86 * Returns the data on @p index that @p role contains. The result is
87 * a QVariant, so you may need to cast it to the type you want
89 * @param index the index in which you are accessing
90 * @param role the role you want to retrieve
91 * @return the data in a QVariant class
93 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
95 /**
96 * Returns what operations the model/delegate support on the given @p index
98 * @param index the index in which you want to know the allowed operations
99 * @return the allowed operations on the model/delegate
101 Qt::ItemFlags flags(const QModelIndex &index) const;
104 * Returns the index for the given @p row. Since it is a list, @p column should
105 * be 0, but it will be ignored. @p parent will be ignored as well.
107 * @param row the row you want to get the index
108 * @param column will be ignored
109 * @param parent will be ignored
110 * @return the index for the given @p row as a QModelIndex
112 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
114 QModelIndex indexForJob(UIServer::JobView *jobView) const;
117 * Returns the number of columns
119 * @param parent will be ignored
120 * @return the number of columns. In this case is always 1
122 int columnCount(const QModelIndex &parent = QModelIndex()) const;
125 * Returns the number of rows
127 * @param parent will be ignored
128 * @return the number of rows in the model
130 int rowCount(const QModelIndex &parent = QModelIndex()) const;
133 * Sets the data contained on @p value to the given @p index and @p role
135 * @param index the index where the data contained on @p value will be stored
136 * @param value the data that is going to be stored
137 * @param role in what role we want to store the data at the given @p index
138 * @return whether the data was successfully stored or not
140 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
142 UIServer::JobView* newJob(const QString &appName, const QString &appIcon, int capabilities);
144 void finishJob(UIServer::JobView *jobView);
146 QPair<QString, QString> getDescriptionField(const QModelIndex &index, uint id);
148 bool setDescriptionField(const QModelIndex &index, uint id, const QString &name, const QString &value);
150 void clearDescriptionField(const QModelIndex &index, uint id);
152 JobInfo::State state(const QModelIndex &index) const;
154 private:
156 * @internal
158 bool setData(int row, const QVariant &value, int role = Qt::EditRole);
160 QMap<UIServer::JobView*, JobInfo> jobInfoMap; /// @internal
163 Q_DECLARE_METATYPE(UIServer::JobView*)
165 #endif // PROGRESSLISTMODEL_H