1
/***************************************************************************
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. *
8
* Copyright (C) 2007 by Javier Goday <jgoday@gmail.com> *
9
* Copyright (C) 2009 by Matthias Fuchs <mat69@gmx.net> *
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. *
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
***************************************************************************/
22
#include "kgetappletutils.h"
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>
30
#include <QtDBus/QDBusConnectionInterface>
31
#include <QGraphicsLinearLayout>
34
#include <QVBoxLayout>
37
#include <QPushButton>
42
#include <KPushButton>
44
const int KGetAppletUtils::SPACING = 4;
47
void KGetAppletUtils::paintTitle(QPainter *p, Plasma::Svg *svg, const QRect &rect)
51
p->setRenderHint(QPainter::SmoothPixmapTransform);
52
QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
54
font.setPointSize(15);
55
QFontMetrics metrics(font);
57
p->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
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");
74
QGraphicsWidget *KGetAppletUtils::createErrorWidget(const QString &message, QGraphicsWidget *parent)
76
return new ErrorWidget(message, parent);
82
ErrorWidget::ErrorWidget(const QString &message, QGraphicsWidget *parent)
83
: QGraphicsProxyWidget(parent)
85
m_interface = QDBusConnection::sessionBus().interface();
87
m_layout = new QGraphicsLinearLayout(this);
88
m_layout->setOrientation(Qt::Vertical);
90
m_errorLabel = new Plasma::Label(this);
91
m_errorLabel->setText(message);
92
m_errorLabel->nativeWidget()->setAlignment(Qt::AlignCenter);
94
m_icon = new Plasma::IconWidget(KIcon("dialog-warning"),"", this);
96
m_launchButton = new Plasma::PushButton(this);
97
m_launchButton->setText(i18n("Launch KGet"));
98
m_launchButton->nativeWidget()->setIcon(KIcon("kget"));
100
m_layout->addItem(m_errorLabel);
101
m_layout->addItem(m_icon);
102
m_layout->addItem(m_launchButton);
106
connect(m_launchButton, SIGNAL(clicked()), SLOT(launchKGet()));
109
ErrorWidget::~ErrorWidget()
113
delete m_launchButton;
116
void ErrorWidget::launchKGet()
118
QProcess kgetProcess;
119
kgetProcess.startDetached("kget");
123
void ErrorWidget::checkKGetStatus()
125
if (m_interface->isServiceRegistered("org.kde.kget")) {
128
QTimer::singleShot(1000, this, SLOT(checkKGetStatus()));
132
#include "kgetappletutils.moc"