~neon/kdenetwork/trunk

« back to all changes in this revision

Viewing changes to kget/plasma/applet/common/kgetappletutils.cpp

  • Committer: uwolfer
  • Date: 2013-06-08 10:12:41 UTC
  • Revision ID: svn-v4:283d02a7-25f6-0310-bc7c-ecb5cbfe19da:trunk/KDE/kdenetwork:1357331
kdenetwork has moved to Git

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *                                                                         *
3
 
 *   This program is free software; you can redistribute it and/or modify  *
4
 
 *   it under the terms of the GNU General Public License as published by  *
5
 
 *   the Free Software Foundation; either version 2 of the License, or     *
6
 
 *   (at your option) any later version.                                   *
7
 
 *                                                                         *
8
 
 *   Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>                 *
9
 
 *   Copyright (C) 2009 by Matthias Fuchs <mat69@gmx.net>                  *
10
 
 *                                                                         *
11
 
 *   This program is distributed in the hope that it will be useful,       *
12
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 
 *   GNU General Public License for more details.                          *
15
 
 *                                                                         *
16
 
 *   You should have received a copy of the GNU General Public License     *
17
 
 *   along with this program; if not, write to the                         *
18
 
 *   Free Software Foundation, Inc.,                                       *
19
 
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
20
 
 ***************************************************************************/
21
 
 
22
 
#include "kgetappletutils.h"
23
 
 
24
 
#include <plasma/svg.h>
25
 
#include <plasma/theme.h>
26
 
#include <plasma/widgets/label.h>
27
 
#include <plasma/widgets/iconwidget.h>
28
 
#include <plasma/widgets/pushbutton.h>
29
 
 
30
 
#include <QtDBus/QDBusConnectionInterface>
31
 
#include <QGraphicsLinearLayout>
32
 
#include <QPainter>
33
 
#include <QRect>
34
 
#include <QVBoxLayout>
35
 
#include <QLabel>
36
 
#include <QProcess>
37
 
#include <QPushButton>
38
 
#include <QTimer>
39
 
 
40
 
#include <KIcon>
41
 
#include <KLocale>
42
 
#include <KPushButton>
43
 
 
44
 
const int KGetAppletUtils::SPACING = 4;
45
 
 
46
 
 
47
 
void KGetAppletUtils::paintTitle(QPainter *p, Plasma::Svg *svg, const QRect &rect)
48
 
{
49
 
    Q_UNUSED(svg)
50
 
 
51
 
    p->setRenderHint(QPainter::SmoothPixmapTransform);
52
 
    QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
53
 
    font.setBold(true);
54
 
    font.setPointSize(15);
55
 
    QFontMetrics metrics(font);
56
 
    p->setFont(font);
57
 
    p->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
58
 
 
59
 
    QRect iconRect(QPoint(rect.x() + SPACING + 10, rect.y() + SPACING + 10), QSize(metrics.height(), metrics.height()));
60
 
    KIcon("kget").paint(p, iconRect);
61
 
    //p->drawPixmap(QPointF(rect.x() + SPACING + 10, rect.y() + SPACING + 10), KIcon("kget").pixmap(iconRect.width(), iconRect.height()), iconRect);
62
 
    //svg->paint(p, QRect(rect.x() + SPACING + 10,
63
 
    //                    rect.y() + SPACING + 10, 111, 35), "title");
64
 
    //p->setPen(Qt::black);
65
 
    p->drawText(QRectF(rect.x() + SPACING * 2 + 10 + iconRect.width(), rect.y() + SPACING + 10, 
66
 
                       metrics.width(i18n("KGet")), metrics.height()), i18n("KGet"));
67
 
    p->drawLine(QPointF(rect.x() + SPACING + 10, rect.y() + SPACING * 2 + 10 + metrics.height()), 
68
 
                QPointF(rect.width() - SPACING - 10, rect.y() + SPACING * 2 + 10 + metrics.height()));
69
 
    //svg->paint(p, QRect(rect.x() + SPACING + 10,
70
 
    //                    rect.y() + SPACING + 45,
71
 
    //                    rect.width() - (SPACING + 10) * 2, 1), "line");
72
 
}
73
 
 
74
 
QGraphicsWidget *KGetAppletUtils::createErrorWidget(const QString &message, QGraphicsWidget *parent)
75
 
{
76
 
    return new ErrorWidget(message, parent);
77
 
}
78
 
 
79
 
 
80
 
/** Error widget **/
81
 
 
82
 
ErrorWidget::ErrorWidget(const QString &message, QGraphicsWidget *parent)
83
 
    : QGraphicsProxyWidget(parent)
84
 
{
85
 
    m_interface = QDBusConnection::sessionBus().interface();
86
 
 
87
 
    m_layout = new QGraphicsLinearLayout(this);
88
 
    m_layout->setOrientation(Qt::Vertical);
89
 
 
90
 
    m_errorLabel = new Plasma::Label(this);
91
 
    m_errorLabel->setText(message);
92
 
    m_errorLabel->nativeWidget()->setAlignment(Qt::AlignCenter);
93
 
 
94
 
    m_icon = new Plasma::IconWidget(KIcon("dialog-warning"),"", this);
95
 
 
96
 
    m_launchButton = new Plasma::PushButton(this);
97
 
    m_launchButton->setText(i18n("Launch KGet"));
98
 
    m_launchButton->nativeWidget()->setIcon(KIcon("kget"));
99
 
 
100
 
    m_layout->addItem(m_errorLabel);
101
 
    m_layout->addItem(m_icon);
102
 
    m_layout->addItem(m_launchButton);
103
 
 
104
 
    setLayout(m_layout);
105
 
 
106
 
    connect(m_launchButton, SIGNAL(clicked()), SLOT(launchKGet()));
107
 
}
108
 
 
109
 
ErrorWidget::~ErrorWidget()
110
 
{
111
 
    delete m_errorLabel;
112
 
    delete m_icon;
113
 
    delete m_launchButton;
114
 
}
115
 
 
116
 
void ErrorWidget::launchKGet()
117
 
{
118
 
    QProcess kgetProcess;
119
 
    kgetProcess.startDetached("kget");
120
 
    checkKGetStatus();
121
 
}
122
 
 
123
 
void ErrorWidget::checkKGetStatus()
124
 
{
125
 
    if (m_interface->isServiceRegistered("org.kde.kget")) {
126
 
        emit kgetStarted();
127
 
    } else {
128
 
        QTimer::singleShot(1000, this, SLOT(checkKGetStatus()));
129
 
    }
130
 
}
131
 
 
132
 
#include "kgetappletutils.moc"