~ubuntu-branches/ubuntu/karmic/kdebase-workspace/karmic-updates

« back to all changes in this revision

Viewing changes to plasma/applets/systemtray/ui/jobwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Richard Johnson, Scott Kitterman, Jonathan Thomas
  • Date: 2009-10-03 00:05:53 UTC
  • mfrom: (1.1.29 upstream)
  • Revision ID: james.westby@ubuntu.com-20091003000553-aurbf1n21soayz72
Tags: 4:4.3.2-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Update kubuntu_80_fix_includes.diff
  - Bump version of KDE build-deps to 4.3.2
  - Update kdebase-workspace-data.install

[ Richard Johnson ]
* updating kdm upstart script - removing a lot of cruft

[ Scott Kitterman ]
* Drop debian/patches/powerdevil-suspend-dialogue/
  0001-Turn-low-battery-notifications-into-a-countdown-dialo.diff to return
  to the upstream behavior of using a notification for low power shutdown
  warnings (LP: #438445)
  - Keep 0002-Increase-WaitBeforeSuspendingTime-from-10-to-30-secon.diff so
    people have more time to react (change already upstream for KDE 4.4)
  - This is also not ideal, but work is planned to make this better for the
    next development cycle

[ Jonathan Thomas ]
* Make kdebase-workspace-bin depend on policykit. Otherwise anything that wants to
  use PolicyKit will crash (LP: #436748)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <Plasma/Meter>
37
37
#include <Plasma/PushButton>
38
38
 
 
39
static const int UPDATE_INTERVAL = 200;
 
40
 
39
41
JobWidget::JobWidget(SystemTray::Job *job, Plasma::ExtenderItem *parent)
40
42
    : QGraphicsWidget(parent),
41
 
    m_extenderItem(parent),
42
 
    m_job(job),
43
 
    m_extenderItemDestroyed(false)
 
43
      m_extenderItem(parent),
 
44
      m_job(job),
 
45
      m_updateTimerId(0),
 
46
      m_extenderItemDestroyed(false)
44
47
{
45
48
    Q_ASSERT(m_extenderItem);
46
49
 
95
98
    if (m_job) {
96
99
        m_details->setText(i18n("More"));
97
100
 
98
 
        connect(m_job, SIGNAL(changed(SystemTray::Job*)), this, SLOT(updateJob()));
 
101
        connect(m_job, SIGNAL(changed(SystemTray::Job*)), this, SLOT(scheduleUpdateJob()));
 
102
        connect(m_job, SIGNAL(stateChanged(SystemTray::Job*)), this, SLOT(updateJobState()));
99
103
        connect(m_job, SIGNAL(destroyed(SystemTray::Job*)), this, SLOT(destroyExtenderItem()));
100
104
        connect(m_details, SIGNAL(clicked()),
101
105
                this, SLOT(detailsClicked()));
153
157
    m_extenderItemDestroyed = true;
154
158
}
155
159
 
 
160
void JobWidget::scheduleUpdateJob()
 
161
{
 
162
    if (m_extenderItemDestroyed) {
 
163
        return;
 
164
    }
 
165
 
 
166
    if (!m_updateTimerId) {
 
167
        m_updateTimerId = startTimer(UPDATE_INTERVAL);
 
168
    }
 
169
}
 
170
 
 
171
void JobWidget::updateJobState()
 
172
{
 
173
    if (m_extenderItemDestroyed) {
 
174
        return;
 
175
    }
 
176
 
 
177
    //show the current status in the title.
 
178
    if (!m_job->error().isEmpty()) {
 
179
        m_extenderItem->setTitle(m_job->error());
 
180
    } else if (m_job->state() == SystemTray::Job::Running) {
 
181
        m_extenderItem->setTitle(m_job->message());
 
182
        if (m_job->eta()) {
 
183
            m_eta->setText(i18n("%1 (%2 remaining)", m_job->speed(),
 
184
                                 KGlobal::locale()->prettyFormatDuration(m_job->eta())));
 
185
        } else {
 
186
            m_eta->setText(QString());
 
187
        }
 
188
    } else if (m_job->state() == SystemTray::Job::Suspended) {
 
189
        m_extenderItem->setTitle(
 
190
            i18nc("%1 is the name of the job, can be things like Copying, deleting, moving",
 
191
                  "%1 [Paused]", m_job->message()));
 
192
        m_eta->setText(i18n("Paused"));
 
193
    } else {
 
194
        m_extenderItem->setTitle(
 
195
            i18nc("%1 is the name of the job, can be things like Copying, deleting, moving",
 
196
                  "%1 [Finished]", m_job->message()));
 
197
        m_extenderItem->showCloseButton();
 
198
        m_details->hide();
 
199
    }
 
200
}
 
201
 
156
202
void JobWidget::updateJob()
157
203
{
158
204
    if (m_extenderItemDestroyed) {
161
207
 
162
208
    m_meter->setValue(m_job->percentage());
163
209
 
164
 
    Plasma::ExtenderItem *item = m_extenderItem;
165
 
 
166
210
    if (m_job) {
167
211
        if (m_job->labels().count() > 0) {
168
212
            labelName0 = m_job->labels().value(0).first;
181
225
 
182
226
    updateLabels();
183
227
 
184
 
    //show the current status in the title.
185
 
    if (!m_job->error().isEmpty()) {
186
 
        item->setTitle(m_job->error());
187
 
    } else if (m_job->state() == SystemTray::Job::Running) {
188
 
        item->setTitle(m_job->message());
189
 
        if (m_job->eta()) {
190
 
            m_eta->setText(i18n("%1 (%2 remaining)", m_job->speed(),
191
 
                                 KGlobal::locale()->prettyFormatDuration(m_job->eta())));
192
 
        } else {
193
 
            m_eta->setText(QString());
194
 
        }
195
 
    } else if (m_job->state() == SystemTray::Job::Suspended) {
196
 
        item->setTitle(
197
 
            i18nc("%1 is the name of the job, can be things like Copying, deleting, moving",
198
 
                  "%1 [Paused]", m_job->message()));
199
 
        m_eta->setText(i18n("Paused"));
200
 
    } else {
201
 
        item->setTitle(
202
 
            i18nc("%1 is the name of the job, can be things like Copying, deleting, moving",
203
 
                  "%1 [Finished]", m_job->message()));
204
 
        item->showCloseButton();
205
 
        m_details->hide();
206
 
    }
207
 
 
208
228
    //set the correct actions to visible.
209
 
    if (item->action("suspend")) {
210
 
        item->action("suspend")->setVisible(m_job->isSuspendable() &&
 
229
    if (m_extenderItem->action("suspend")) {
 
230
        m_extenderItem->action("suspend")->setVisible(m_job->isSuspendable() &&
211
231
                                            m_job->state() == SystemTray::Job::Running);
212
232
    }
213
233
 
214
 
    if (item->action("resume")) {
215
 
        item->action("resume")->setVisible(m_job->isSuspendable() &&
 
234
    if (m_extenderItem->action("resume")) {
 
235
        m_extenderItem->action("resume")->setVisible(m_job->isSuspendable() &&
216
236
                                           m_job->state() == SystemTray::Job::Suspended);
217
237
    }
218
238
 
219
 
    if (item->action("stop")) {
220
 
        item->action("stop")->setVisible(m_job->isKillable() &&
 
239
    if (m_extenderItem->action("stop")) {
 
240
        m_extenderItem->action("stop")->setVisible(m_job->isKillable() &&
221
241
                                         m_job->state() != SystemTray::Job::Stopped);
222
242
    }
223
243
 
234
254
        m_fileCountLabel->setText(i18np("%2 / 1 file", "%2 / %1 files", files, processed["files"]));
235
255
    }
236
256
 
237
 
    QString processedString = KGlobal::locale()->formatByteSize(processed["bytes"]);
238
 
    QString totalsString = KGlobal::locale()->formatByteSize(totals["bytes"]);
239
 
    m_totalBytesLabel->setText(QString("%1 / %2").arg(processedString, totalsString));
 
257
    qlonglong done = processed["bytes"];
 
258
    qlonglong total = totals["bytes"];
 
259
    if (total > 0) {
 
260
        QString processedString = KGlobal::locale()->formatByteSize(processed["bytes"]);
 
261
        QString totalsString = KGlobal::locale()->formatByteSize(totals["bytes"]);
 
262
        m_totalBytesLabel->setText(QString("%1 / %2").arg(processedString, totalsString));
 
263
    } else {
 
264
        m_details->hide();
 
265
        m_totalBytesLabel->hide();
 
266
    }
240
267
 
241
 
    item->setIcon(m_job->applicationIconName());
 
268
    m_extenderItem->setIcon(m_job->applicationIconName());
242
269
}
243
270
 
244
271
void JobWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
247
274
    updateLabels();
248
275
}
249
276
 
 
277
void JobWidget::timerEvent(QTimerEvent *event)
 
278
{
 
279
    if (event->timerId() == m_updateTimerId) {
 
280
        killTimer(m_updateTimerId);
 
281
        m_updateTimerId = 0;
 
282
        updateJob();
 
283
    }
 
284
}
 
285
 
250
286
void JobWidget::updateLabels()
251
287
{
252
288
    QFontMetricsF fm = m_fromLabel->nativeWidget()->fontMetrics();
272
308
void JobWidget::detailsClicked()
273
309
{
274
310
    if (!m_totalBytesLabel->isVisible()) {
275
 
        m_details->setText(i18n("less"));
 
311
        m_details->setText(i18n("Less"));
276
312
        m_totalBytesLabel->setVisible(true);
277
313
        m_dirCountLabel->setVisible(true);
278
314
        m_fileCountLabel->setVisible(true);
281
317
        m_layout->addItem(m_dirCountLabel, 6, 1);
282
318
        m_extenderItem->setCollapsed(m_extenderItem->isCollapsed());
283
319
    } else {
284
 
        m_details->setText(i18n("more"));
 
320
        m_details->setText(i18n("More"));
285
321
        m_totalBytesLabel->setVisible(false);
286
322
        m_dirCountLabel->setVisible(false);
287
323
        m_fileCountLabel->setVisible(false);