~ubuntu-branches/ubuntu/precise/kde-runtime/precise-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
  * This file is part of the KDE project
  * Copyright (C) 2009 Shaun Reich <shaun.reich@kdemail.net>
  * Copyright (C) 2006-2008 Rafael Fernández López <ereslibre@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License version 2 as published by the Free Software Foundation.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
*/

#ifndef PROGRESSLISTMODEL_H
#define PROGRESSLISTMODEL_H

#include "uiserver.h"
#include "jobview.h"


class QDBusAbstractInterface;
class QDBusServiceWatcher;

class ProgressListModel: public QAbstractItemModel
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.JobViewServer")


public:

    explicit ProgressListModel(QObject *parent = 0);
    ~ProgressListModel();

    QModelIndex parent(const QModelIndex&) const;


    /**
    * Returns what operations the model/delegate support on the given @p index
    *
    * @param index    the index in which you want to know the allowed operations
    * @return         the allowed operations on the model/delegate
    */
    Qt::ItemFlags flags(const QModelIndex &index) const;


    /**
    * Returns the data on @p index that @p role contains. The result is
    * a QVariant, so you may need to cast it to the type you want
    *
    * @param index    the index in which you are accessing
    * @param role     the role you want to retrieve
    * @return         the data in a QVariant class
    */
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;


    /**
    * Returns the index for the given @p row. Since it is a list, @p column should
    * be 0, but it will be ignored. @p parent will be ignored as well.
    *
    * @param row      the row you want to get the index
    * @param column   will be ignored
    * @param parent   will be ignored
    * @return         the index for the given @p row as a QModelIndex
    */
    QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;

    QModelIndex indexForJob(JobView *jobView) const;


    /**
    * Returns the number of columns
    *
    * @param parent   will be ignored
    * @return         the number of columns. In this case is always 1
    */
    int columnCount(const QModelIndex &parent = QModelIndex()) const;


    /**
    * Returns the number of rows
    *
    * @param parent   will be ignored
    * @return         the number of rows in the model
    */
    int rowCount(const QModelIndex &parent = QModelIndex()) const;


    /**
    * Called by a KJob's DBus connection to this ("JobViewServer").
    * Indicates that the KJob is now in existence (and is a just-created job).
    * Returns a QDBusObjectPath that represents a unique dbus path that is a subset
    * of the current "org.kde.JobView" address(so there can be multiple jobs, and KJob
    * can keep track of them.
    */
    QDBusObjectPath requestView(const QString &appName, const QString &appIconName, int capabilities);

public Q_SLOTS:
    /**
    * Calling this(within "org.kde.kuiserver") results in all of the
    * information that pertains to any KJobs and status updates for
    * them, being sent to this DBus address, at the given
    * @p objectPath
    * Note that you will also receive jobs that existed before this was
    * called
    */
    void registerService(const QString &service, const QString &objectPath);

    /**
    * Forces emission of jobUrlsChanged() signal...exposed to D-BUS (because they need it).
    * @see jobUrlsChanged
    */
    void emitJobUrlsChanged();

    /**
    * Whether or not a JobTracker will be needed. This will occur if there are no useful registered
    * services. For example, this would occur if Plasma has "Show application jobs/file transfers" disabled.
    * In which case, returning true here would be expected. This way KDynamicJobTracker can create a
    * KWidgetJobTracker for each job (shows a dialog for each job).
    * @return if a proper job tracker needs to be created by something.
    */
    bool requiresJobTracker();

private Q_SLOTS:

    void jobFinished(JobView *jobView);
    void jobChanged(uint jobId);


    /**
    * Implemented to handle the case when a client drops out.
    */
    void serviceUnregistered(const QString &name);

Q_SIGNALS:
    void serviceDropped(const QString&);

    /**
    * Emits a list of destination URL's that have
    * jobs pertaining to them(when it changes).
    */
    void jobUrlsChanged(QStringList);

private:

    QDBusObjectPath newJob(const QString &appName, const QString &appIcon, int capabilities);

    ///< desturls
    QStringList gatherJobUrls();

    /**
    * The next available(unused) unique jobId, we can use this one directly,
    * just remember to increment it after you construct a job from it.
    */
    uint m_jobId;

    QList<JobView*> m_jobViews;

    /**
     * Contains the list of registered services. In other words, the clients
     * who have "subscribed" to our D-Bus interface so they can get informed
     * about changes to all the jobs.
     */
    QHash<QString, QDBusAbstractInterface*> m_registeredServices;

    UiServer *m_uiServer;
    QDBusServiceWatcher *m_serviceWatcher;
};

Q_DECLARE_METATYPE(JobView*)

#endif // PROGRESSLISTMODEL_H