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

« back to all changes in this revision

Viewing changes to plasma/generic/applets/notifications/core/completedjobnotification.cpp

  • 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
 *   completedjobnotification.h                                                          *
 
3
 *   Copyright (C) 2010 Marco Martin <notmart@gmail.com>                   *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "completedjobnotification.h"
 
22
#include "job.h"
 
23
 
 
24
#include <QProcess>
 
25
 
 
26
#include <KIcon>
 
27
#include <KLocale>
 
28
#include <KDebug>
 
29
 
 
30
 
 
31
static const int completedJobExpireDelay = 60 * 1000;
 
32
static const int completedShortJobExpireDelay = 8 * 1000;
 
33
static const uint shortJobsLength = 30 * 1000;
 
34
 
 
35
CompletedJobNotification::CompletedJobNotification(QObject *parent)
 
36
    : Notification(parent)
 
37
{
 
38
}
 
39
 
 
40
CompletedJobNotification::~CompletedJobNotification()
 
41
{
 
42
}
 
43
 
 
44
void CompletedJobNotification::setJob(Job *job)
 
45
{
 
46
    setApplicationName(job->applicationName());
 
47
    setApplicationIcon(KIcon(job->applicationIconName()));
 
48
    setSummary(i18n("%1 [Finished]", job->message()));
 
49
 
 
50
    if (job->error().isEmpty()) {
 
51
        setMessage(job->completedMessage());
 
52
    } else {
 
53
        setMessage(job->error());
 
54
    }
 
55
 
 
56
    if (job->elapsed() < shortJobsLength) {
 
57
        setTimeout(completedShortJobExpireDelay);
 
58
    } else {
 
59
        setTimeout(completedJobExpireDelay);
 
60
    }
 
61
 
 
62
    if (job->destination().isValid()) {
 
63
        QHash<QString, QString> actions;
 
64
        actions.insert("open", i18n("Open"));
 
65
        setActions(actions);
 
66
        setActionOrder(QStringList()<<"open");
 
67
        m_destinationPrettyUrl = job->destination().prettyUrl();
 
68
    }
 
69
 
 
70
    m_job = job;
 
71
}
 
72
 
 
73
void CompletedJobNotification::linkActivated(const QString &url)
 
74
{
 
75
    kDebug() << "open " << url;
 
76
    QProcess::startDetached("kde-open", QStringList() << url);
 
77
}
 
78
 
 
79
Job *CompletedJobNotification::job() const
 
80
{
 
81
    return m_job;
 
82
}
 
83
 
 
84
void CompletedJobNotification::triggerAction(const QString &actionId)
 
85
{
 
86
    if (actionId == "open" && !m_destinationPrettyUrl.isNull()) {
 
87
        linkActivated(m_destinationPrettyUrl);
 
88
    }
 
89
}
 
90
 
 
91
 
 
92
#include "completedjobnotification.moc"