~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/applicationjobs/kuiserverengine.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright © 2008 Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License version 2 as
 
6
 *   published by the Free Software Foundation
 
7
 *
 
8
 *   This program is distributed in the hope that it will be useful,
 
9
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *   GNU General Public License for more details
 
12
 *
 
13
 *   You should have received a copy of the GNU Library General Public
 
14
 *   License along with this program; if not, write to the
 
15
 *   Free Software Foundation, Inc.,
 
16
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
 */
 
18
 
 
19
#ifndef KUISERVERENGINE_H
 
20
#define KUISERVERENGINE_H
 
21
 
 
22
#include <QDBusObjectPath>
 
23
#include <QBasicTimer>
 
24
#include <QTimer>
 
25
 
 
26
#include <Plasma/DataContainer>
 
27
#include <Plasma/DataEngine>
 
28
 
 
29
class JobView;
 
30
 
 
31
namespace Plasma
 
32
{
 
33
    class Service;
 
34
} // namespace Plasma
 
35
 
 
36
class KuiserverEngine : public Plasma::DataEngine
 
37
{
 
38
    Q_OBJECT
 
39
    Q_CLASSINFO("D-Bus Interface", "org.kde.JobViewServer")
 
40
 
 
41
public:
 
42
    KuiserverEngine(QObject* parent, const QVariantList& args);
 
43
    ~KuiserverEngine();
 
44
 
 
45
    void init();
 
46
 
 
47
    QDBusObjectPath requestView(const QString &appName, const QString &appIconName,
 
48
                                int capabilities);
 
49
    Plasma::Service* serviceForSource(const QString& source);
 
50
 
 
51
private Q_SLOTS:
 
52
    void processPendingJobs();
 
53
 
 
54
private:
 
55
    QTimer m_pendingJobsTimer;
 
56
    QList<JobView *> m_pendingJobs;
 
57
};
 
58
 
 
59
class JobView : public Plasma::DataContainer
 
60
{
 
61
    Q_OBJECT
 
62
    Q_CLASSINFO("D-Bus Interface", "org.kde.JobViewV2")
 
63
 
 
64
public:
 
65
    enum State {
 
66
                 UnknownState = -1,
 
67
                 Running = 0,
 
68
                 Suspended = 1,
 
69
                 Stopped = 2
 
70
               };
 
71
 
 
72
    JobView(QObject *parent = 0);
 
73
    ~JobView();
 
74
 
 
75
    uint jobId() const;
 
76
    JobView::State state();
 
77
 
 
78
    void setTotalAmount(qlonglong amount, const QString &unit);
 
79
    QString totalAmountSize() const;
 
80
    QString totalAmountFiles() const;
 
81
 
 
82
    void setProcessedAmount(qlonglong amount, const QString &unit);
 
83
 
 
84
    void setSpeed(qlonglong bytesPerSecond);
 
85
    QString speedString() const;
 
86
 
 
87
    void setInfoMessage(const QString &infoMessage);
 
88
    QString infoMessage() const;
 
89
 
 
90
    bool setDescriptionField(uint number, const QString &name, const QString &value);
 
91
    void clearDescriptionField(uint number);
 
92
 
 
93
    void setAppName(const QString &appName);
 
94
    void setAppIconName(const QString &appIconName);
 
95
    void setCapabilities(int capabilities);
 
96
    void setPercent(uint percent);
 
97
    void setSuspended(bool suspended);
 
98
 
 
99
    //vestigal, required to implement this dbus interface
 
100
    void setDestUrl(const QDBusVariant &destUrl);
 
101
 
 
102
    void terminate(const QString &errorMessage);
 
103
 
 
104
    QDBusObjectPath objectPath() const;
 
105
 
 
106
    void requestStateChange(State state);
 
107
 
 
108
public Q_SLOTS:
 
109
    void finished();
 
110
 
 
111
Q_SIGNALS:
 
112
    void suspendRequested();
 
113
    void resumeRequested();
 
114
    void cancelRequested();
 
115
 
 
116
protected:
 
117
    void timerEvent(QTimerEvent *event);
 
118
 
 
119
private:
 
120
    void scheduleUpdate();
 
121
    void updateEta();
 
122
    int unitId(const QString &unit);
 
123
 
 
124
    QDBusObjectPath m_objectPath;
 
125
    QBasicTimer m_updateTimer;
 
126
 
 
127
    uint m_capabilities;
 
128
    uint m_percent;
 
129
    uint m_jobId;
 
130
 
 
131
    // for ETA calculation we cache these values
 
132
    qlonglong m_speed;
 
133
    qlonglong m_totalBytes;
 
134
    qlonglong m_processedBytes;
 
135
 
 
136
    State m_state;
 
137
 
 
138
    QMap<QString, int> m_unitMap;
 
139
    int m_bytesUnitId;
 
140
    int m_unitId;
 
141
 
 
142
    static uint s_jobId;
 
143
};
 
144
 
 
145
#endif