• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • plasma
  • applet
  • panelbar
kgetpanelbar.cpp
Go to the documentation of this file.
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  * *
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 "panelbar/kgetpanelbar.h"
22 #include "panelbar/kgetpanelbar_p.h"
23 #include "common/kgetappletutils.h"
24 
25 #include <QGridLayout>
26 #include <QGraphicsProxyWidget>
27 #include <QGraphicsLinearLayout>
28 #include <QLabel>
29 #include <QPainter>
30 #include <QProgressBar>
31 
32 #include <KDebug>
33 #include <KIcon>
34 #include <KIconLoader>
35 #include <KLocale>
36 #include <KTitleWidget>
37 #include <KWindowSystem>
38 #include <kio/global.h>
39 
40 #include <plasma/applet.h>
41 #include <plasma/dataengine.h>
42 #include <plasma/dialog.h>
43 #include <plasma/svg.h>
44 #include <plasma/theme.h>
45 #include <plasma/widgets/iconwidget.h>
46 
47 const static int TOP_MARGIN = 60;
48 const static int SPACING = 4;
49 const static int MARGIN = 20;
50 const static int MAX_DOWNLOADS_PER_PAGE = 5;
51 
52 KGetPanelBar::Private::Private(QWidget *parent) : Plasma::Dialog(parent),
53  m_transfers()
54 {
55  m_dialogLayout = new QGridLayout(this);
56  m_dialogLayout->setColumnStretch(0, 0);
57  m_dialogLayout->setColumnStretch(1, 0);
58  m_dialogLayout->setColumnStretch(2, 1);
59  setLayout(m_dialogLayout);
60 
61  KTitleWidget *title = new KTitleWidget(this);
62  title->setText(i18n("KGet transfers"));
63  title->setPixmap(KIcon("kget").pixmap(22, 22), KTitleWidget::ImageRight);
64  m_dialogLayout->addWidget(title, 0, 0, 1, 3);
65 }
66 
67 KGetPanelBar::Private::~Private()
68 {
69 }
70 
71 void KGetPanelBar::Private::transfersAdded(const QList<OrgKdeKgetTransferInterface*> &transfers)
72 {
73  foreach (OrgKdeKgetTransferInterface* transfer, transfers) {
74  QLabel *icon = new QLabel(this);
75  QLabel *name = new QLabel(this);
76  QProgressBar *progressBar = new QProgressBar(this);
77 
78  QString fileName = KUrl(transfer->source().value()).fileName();
79  icon->setPixmap(KIO::pixmapForUrl(fileName, 0, KIconLoader::Desktop, 16));
80  name->setText(fileName);
81  name->setStyleSheet(QString("color: %1;").
82  arg(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor).name()));
83  progressBar->setValue(transfer->percent().value());
84 
85  int row = m_dialogLayout->rowCount();
86 
87  m_dialogLayout->addWidget(icon, row, 0);
88  m_dialogLayout->addWidget(name, row, 1);
89  m_dialogLayout->addWidget(progressBar, row, 2);
90 
91  m_transfers.insert(transfer, progressBar);
92  }
93 }
94 
95 void KGetPanelBar::Private::transfersRemoved(const QList<OrgKdeKgetTransferInterface*> &transfers)
96 {
97  foreach (OrgKdeKgetTransferInterface* transfer, transfers) {
98  int index = m_dialogLayout->indexOf(m_transfers[transfer]);
99  int row, column, rowSpan, columnSpan;
100  m_dialogLayout->getItemPosition(index, &row, &column, &rowSpan, &columnSpan);
101  kDebug() << row;
102 
103  QList<QLayoutItem*> items;
104  for (int i = 0; i != 3; i++) {
105  QLayoutItem * item = m_dialogLayout->itemAtPosition(row, i);
106  items << item;
107  m_dialogLayout->removeItem(item);
108  delete item->widget();
109  delete item;
110  }
111 
112  m_transfers.remove(transfer);
113  }
114 }
115 
116 void KGetPanelBar::Private::update()
117 {
118  int totalSize = 0;
119  int completedSize = 0;
120  QMap<OrgKdeKgetTransferInterface*, QProgressBar*>::const_iterator it;
121  QMap<OrgKdeKgetTransferInterface*, QProgressBar*>::const_iterator itEnd = m_transfers.constEnd();
122  for (it = m_transfers.constBegin(); it != itEnd; ++it) {
123  OrgKdeKgetTransferInterface *transfer = it.key();
124  (*it)->setValue(transfer->percent().value());
125  totalSize += transfer->totalSize().value();
126  completedSize += transfer->downloadedSize().value();
127  }
128  if (totalSize > 0) {
129  emit progressBarChanged((int) ((completedSize * 100) / totalSize));
130  }
131  else {
132  emit progressBarChanged(0);
133  }
134 }
135 
136 void KGetPanelBar::Private::clear()
137 {
138  // TODO : Find another way to remove all layout widgets except the title one
139  for (int row = 1; row < m_dialogLayout->rowCount(); ++row) {
140  delete m_dialogLayout->itemAtPosition(row, 0);
141  delete m_dialogLayout->itemAtPosition(row, 1);
142  delete m_dialogLayout->itemAtPosition(row, 2);
143 
144  m_dialogLayout->removeItem(m_dialogLayout->itemAtPosition(row, 0));
145  m_dialogLayout->removeItem(m_dialogLayout->itemAtPosition(row, 1));
146  m_dialogLayout->removeItem(m_dialogLayout->itemAtPosition(row, 2));
147  }
148  m_transfers.clear();
149 }
150 
151 
152 KGetPanelBar::KGetPanelBar(QObject *parent, const QVariantList &args)
153  : KGetApplet(parent, args),
154  m_icon(0),
155  d(new KGetPanelBar::Private())
156 {
157  d->setFocusPolicy(Qt::NoFocus);
158  connect(this, SIGNAL(transfersAdded(QList<OrgKdeKgetTransferInterface*>)), d, SLOT(transfersAdded(QList<OrgKdeKgetTransferInterface*>)));
159  connect(this, SIGNAL(transfersRemoved(QList<OrgKdeKgetTransferInterface*>)), d, SLOT(transfersRemoved(QList<OrgKdeKgetTransferInterface*>)));
160  setBackgroundHints(Applet::NoBackground);
161 }
162 
163 KGetPanelBar::~KGetPanelBar()
164 {
165  delete d;
166  delete m_bar;
167 }
168 
169 void KGetPanelBar::init()
170 {
171  KGlobal::locale()->insertCatalog("plasma_applet_kget");
172 
173  m_icon = new Plasma::IconWidget(KIcon("go-down"), QString(), this);
174 
175  m_layout = new QGraphicsLinearLayout(Qt::Horizontal, this);
176  m_layout->addItem(m_icon);
177 
178  QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
179 
180  m_bar = new QProgressBar();
181 
182  connect(d, SIGNAL(progressBarChanged(int)), m_bar, SLOT(setValue(int)));
183 
184  proxy->setWidget(m_bar);
185 
186  m_bar->setValue(0);
187  m_bar->setStyleSheet("background-color: transparent");
188 
189  m_layout->addItem(proxy);
190 
191  setLayout(m_layout);
192 
193  connect(m_icon, SIGNAL(clicked()), SLOT(showDialog()));
194 
195  KGetApplet::init();
196 }
197 
198 void KGetPanelBar::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
199 {
200  Q_UNUSED(p)
201  Q_UNUSED(option)
202  Q_UNUSED(contentsRect)
203 }
204 
205 void KGetPanelBar::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
206 {
207  Q_UNUSED(source)
208 
209  if(data["error"].toBool()) {
210  kDebug() << "Error : " << data["errorMessage"].toString();
211  d->clear();
212  }
213  else if(!data["error"].toBool()) {
214  setTransfers(data["transfers"].toMap());
215  d->update();
216  }
217 }
218 
219 void KGetPanelBar::showDialog()
220 {
221  if (d->isVisible()) {
222  d->hide();
223  }
224  else {
225  d->show();
226  KWindowSystem::setState(d->winId(), NET::SkipTaskbar);
227  d->move(popupPosition(d->sizeHint()));
228  }
229 }
230 
231 #include "kgetpanelbar.moc"
232 #include "kgetpanelbar_p.moc"
KGetPanelBar
Definition: kgetpanelbar.h:35
KGetApplet::transfersAdded
void transfersAdded(const QList< OrgKdeKgetTransferInterface * > &transfers)
TOP_MARGIN
static const int TOP_MARGIN
Definition: kgetpanelbar.cpp:47
KGetPanelBar::Private::clear
void clear()
Definition: kgetpanelbar.cpp:136
kgetpanelbar.h
QWidget
SPACING
static const int SPACING
Definition: kgetpanelbar.cpp:48
kgetappletutils.h
QObject
KGetPanelBar::init
void init()
Definition: kgetpanelbar.cpp:169
KGetPanelBar::~KGetPanelBar
~KGetPanelBar()
Definition: kgetpanelbar.cpp:163
kgetpanelbar_p.h
KGetPanelBar::Private::~Private
~Private()
Definition: kgetpanelbar.cpp:67
KGetPanelBar::paintInterface
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
Definition: kgetpanelbar.cpp:198
KGetPanelBar::KGetPanelBar
KGetPanelBar(QObject *parent, const QVariantList &args)
Definition: kgetpanelbar.cpp:152
KGetPanelBar::Private
Definition: kgetpanelbar_p.h:31
KGetApplet::init
void init()
Definition: kgetapplet.cpp:139
KGetApplet::transfersRemoved
void transfersRemoved(const QList< OrgKdeKgetTransferInterface * > &transfers)
QGraphicsProxyWidget
KGetApplet::m_transfers
QHash< OrgKdeKgetTransferInterface *, Data > m_transfers
Definition: kgetapplet.h:115
KGetPanelBar::Private::transfersRemoved
void transfersRemoved(const QList< OrgKdeKgetTransferInterface * > &transfers)
Definition: kgetpanelbar.cpp:95
KGetPanelBar::Private::transfersAdded
void transfersAdded(const QList< OrgKdeKgetTransferInterface * > &transfers)
Definition: kgetpanelbar.cpp:71
MAX_DOWNLOADS_PER_PAGE
static const int MAX_DOWNLOADS_PER_PAGE
Definition: kgetpanelbar.cpp:50
MARGIN
static const int MARGIN
Definition: kgetpanelbar.cpp:49
KGetApplet
Definition: kgetapplet.h:68
KGetPanelBar::Private::Private
Private(QWidget *parent=0)
Definition: kgetpanelbar.cpp:52
KGetPanelBar::Private::update
void update()
Definition: kgetpanelbar.cpp:116
KGetPanelBar::dataUpdated
void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data)
Definition: kgetpanelbar.cpp:205
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal