~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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*****************************************************************************
*   Copyright (C) 2009 by Shaun Reich <shaun.reich@kdemail.net>              *
*   Copyright (C) 2006-2008 Rafael Fernández López <ereslibre@kde.org>       *
*   Copyright (C) 2000 Matej Koss <koss@miesto.sk>                           *
*   Copyright (C) 2000 David Faure <faure@kde.org>                           *
*                                                                            *
*   This program is free software; you can redistribute it and/or            *
*   modify it under the terms of the GNU General Public License as           *
*   published by the Free Software Foundation; either version 2 of           *
*   the License, or (at your option) any later version.                      *
*                                                                            *
*   This program 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 General Public License for more details.                             *
*                                                                            *
*   You should have received a copy of the GNU General Public License        *
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
*****************************************************************************/


#ifndef JOBVIEW_H
#define JOBVIEW_H

#include <QtGui/QListView>
#include <QtDBus/QDBusObjectPath>

#include <kio/global.h>

#include <kuiserversettings.h>

class QDBusAbstractInterface;
class RequestViewCallWatcher;

class JobView : public QObject
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.JobViewV2")

public:

    enum DataType {
        Capabilities = 33,
        ApplicationName,
        Icon,
        SizeTotal,
        SizeProcessed,
        TimeTotal,
        TimeElapsed,
        Speed,
        Percent,
        InfoMessage,
        DescFields,
        State,
        JobViewRole
    };

    enum JobState {
        Running = 0,
        Suspended = 1,
        Stopped = 2
    };

    JobView(uint jobId, QObject *parent = 0);
    ~JobView();

    void terminate(const QString &errorMessage);

    void setSuspended(bool suspended);

    void setTotalAmount(qulonglong amount, const QString &unit);
    QString sizeTotal() const;

    void setProcessedAmount(qulonglong amount, const QString &unit);
    QString sizeProcessed() const;

    void setPercent(uint percent);
    uint percent() const;

    void setSpeed(qulonglong bytesPerSecond);
    QString speed() const;

    void setInfoMessage(const QString &infoMessage);
    QString infoMessage() const;

    bool setDescriptionField(uint number, const QString &name, const QString &value);
    void clearDescriptionField(uint number);

    void setAppName(const QString &appName);
    QString appName() const;

    void setAppIconName(const QString &appIconName);
    QString appIconName() const;

    void setCapabilities(int capabilities);
    int capabilities() const;

    QString error() const;

    uint state() const;

    uint jobId() const;

    QDBusObjectPath objectPath() const;



     /**
     * Set the dest Url of the job...
     * sent from the jobtracker (once upon construction)
     * @param destUrl will be a QVariant, likely to have 1
     * dest Url...OR it can be non-existent (only srcUrl would
     * be there), in that case it is a delete a directory job
     * etc..
     */
    void setDestUrl(const QDBusVariant& destUrl);

    QVariant destUrl() const;

    /**
     *  The below methods force an emission of the respective signal.
     *  Only use case is kuiserver's delegate, where we need to control
     *  the state of a job, but can't emit them because they are signals
     * 
     *  Note: it isn't used for job's propagating their children jobs
     *  all the way up to KJob, use the other signals in here for that.
     *  (although it does the same thing).
     */
    void requestSuspend();
    void requestResume();
    void requestCancel();


    /**
     * Called by the model.
     * Lets us know that a job at @p objectPath is
     * open for business. @p address is only for data-keeping of our
     * hash, later on. We will remove it when that address drops,
     * due to some signal magic from the model.
     */
    void addJobContact(const QString& objectPath, const QString& address);

    void pendingCallStarted();

public Q_SLOTS:
    void pendingCallFinished(RequestViewCallWatcher *watcher);

Q_SIGNALS:
    void suspendRequested();
    void resumeRequested();
    void cancelRequested();

    void finished(JobView*);

    /**
     * Triggered when an internal data type changes. It is triggered
     * once for each data type of this JobView, that has changed.
     *
     * @param uint unique job identifier
     */
    void changed(uint);

    void destUrlSet();

private Q_SLOTS:

    /**
     * Called when the model finds out that the client that was
     * registered, has just died. Meaning notifications to the
     * given path, are no longer required(remove them from the list).
     */
    void serviceDropped(const QString &address);

private:

    int m_capabilities;        ///< The capabilities of the job

    QString m_applicationName; ///< The application name

    QString m_appIconName;     ///< The icon name

    QString m_sizeTotal;       ///< The total size of the operation

    QString m_sizeProcessed;   ///< The processed size at the moment(amount completed)

    QString m_speed;           ///< The current speed of the operation (human readable, example, "3Mb/s")

    int m_percent;             ///< The current percent completed of the job

    QString m_infoMessage;     ///< The information message to be shown

    QString m_error;           ///< The error message of the job, set when it's terminated

    QString m_totalUnit;       ///< The unit used in setTotalAmount

    qulonglong m_totalAmount;  ///< The amount used in setTotalAmount

    QString m_processUnit;     ///< The unit used in setProcessedAmount

    qulonglong m_processAmount; ///< The processed amount (setProcessedAmount)

    QHash<uint, QPair<QString, QString> > m_descFields;

    QVariant m_destUrl;

    QDBusObjectPath m_objectPath;

    /**
     * All for the client:
     *   <address name,  <objectPath, interface> >
     */
    QHash<QString, QPair<QString, QDBusAbstractInterface*> > m_objectPaths;

    const uint m_jobId;
    JobState m_state;          ///< Current state of this job

    // if the job has been terminated (but it could still be awaiting a pendingReply)
    bool m_isTerminated;

    // number of pending async calls to "requestView" that progresslistmodel has made.
    // 0 means that this job can be deleted and all is well. Else it has to kind of wait until it comes back.
    int m_currentPendingCalls;
};

#endif //JOBVIEW_H