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

kget

barchart.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *
00008  *   Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00019  ***************************************************************************/
00020 
00021 #include "barchart.h"
00022 #include "transfergraph.h"
00023 
00024 #include <plasma/widgets/label.h>
00025 #include <plasma/layouts/boxlayout.h>
00026 #include <plasma/widgets/pushbutton.h>
00027 #include <plasma/widgets/progressbar.h>
00028 //#include <plasma/widgets/layoutanimator.h>
00029 
00030 #include <KLocale>
00031 //#include <QTimeLine>
00032 
00033 BarChart::BarChart(Plasma::Applet *parent, Plasma::BoxLayout *mainlayout)
00034     : TransferGraph(parent),
00035     m_actualPage(0)
00036 {
00037     m_totalSizeLabel = 0;
00038     m_layout = mainlayout;
00039 
00040 /*
00041     // Layout animator
00042     Plasma::LayoutAnimator *animator = new Plasma::LayoutAnimator();
00043     QTimeLine * timeLine = new QTimeLine();
00044 
00045     animator->setTimeLine(timeLine);
00046     animator->setEffect(Plasma::LayoutAnimator::InsertedState, Plasma::LayoutAnimator::FadeInMoveEffect);
00047     animator->setEffect(Plasma::LayoutAnimator::StandardState, Plasma::LayoutAnimator::MoveEffect);
00048     animator->setEffect(Plasma::LayoutAnimator::RemovedState, Plasma::LayoutAnimator::FadeOutMoveEffect);
00049     m_layout->setAnimator(animator);
00050 */
00051     // the progress bars layout
00052     m_progressBarsLayout = new Plasma::VBoxLayout(m_layout);
00053     m_progressBarsLayout->setMargin(0);
00054     m_layout->addItem(m_progressBarsLayout);
00055 
00056     // Pager layout and next, previous buttons
00057     m_pagerLayout = new Plasma::HBoxLayout(m_layout);
00058     m_pagerLayout->setMargin(0);
00059     m_pageLabel = new Plasma::Label(m_applet);
00060     m_pageLabel->setPen(QPen(Qt::gray));
00061     m_pageLabel->setAlignment(Qt::AlignRight);
00062     m_previousPageButton = new Plasma::PushButton(KIcon("go-previous"), "", m_applet);
00063     m_nextPageButton = new Plasma::PushButton(KIcon("go-next"), "", m_applet);
00064     m_previousPageButton->setEnabled(false);
00065     m_nextPageButton->setEnabled(false);
00066 
00067     m_pagerLayout->addItem(m_pageLabel);
00068     m_pagerLayout->addItem(m_previousPageButton);
00069     m_pagerLayout->addItem(m_nextPageButton);
00070 
00071     m_layout->addItem(m_pagerLayout);
00072 
00073     // Total size
00074     m_totalSizeLabel = new Plasma::Label(m_applet);
00075     m_totalSizeLabel->setPen(QPen(Qt::white));
00076     m_totalSizeLabel->setAlignment(Qt::AlignRight);
00077     m_layout->addItem(m_totalSizeLabel);
00078 
00079     // connect the clicked signal of the next and previous buttons
00080     QObject::connect(m_previousPageButton, SIGNAL(clicked()), SLOT(previousPage()));
00081     QObject::connect(m_nextPageButton, SIGNAL(clicked()), SLOT(nextPage()));
00082 }
00083 
00084 BarChart::~BarChart()
00085 {
00086     delete m_pageLabel;
00087     delete m_totalSizeLabel;
00088     delete m_nextPageButton;
00089     delete m_previousPageButton;
00090 
00091     foreach(const QString &key, m_progressBars.keys()) {
00092         delete m_progressBars[key];
00093     }
00094 
00095     delete m_pagerLayout;
00096     delete m_progressBarsLayout;
00097 }
00098 
00099 void BarChart::setTransfers(const QVariantMap &transfers)
00100 {
00101     if(transfers.keys() != m_transfers.keys()) {
00102         clear();
00103     }
00104 
00105     TransferGraph::setTransfers(transfers);
00106     populate();
00107 }
00108 
00109 void BarChart::nextPage()
00110 {
00111     if(m_transfers.size() >= ((m_actualPage + 1)* MAX_DOWNLOADS_PER_PAGE)) {
00112         m_actualPage ++;
00113 
00114         clear();
00115         populate();
00116     }
00117 }
00118 
00119 void BarChart::previousPage()
00120 {
00121     if(m_actualPage > 0) {
00122         m_actualPage --;
00123 
00124         clear();
00125         populate();
00126     }
00127 }
00128 
00129 void BarChart::populate()
00130 {
00131     int totalSize = 0;
00132     int limit = m_transfers.size() < ((m_actualPage + 1)* MAX_DOWNLOADS_PER_PAGE) ? 
00133             m_transfers.size() :
00134             ((m_actualPage + 1)* MAX_DOWNLOADS_PER_PAGE);
00135 
00136     for(int i = (m_actualPage * MAX_DOWNLOADS_PER_PAGE); i < limit; i++) {
00137         QString key = m_transfers.keys().at(i);
00138 
00139         if(m_progressBars.count(key) <= 0) {
00140             Plasma::ProgressBar *bar = new Plasma::ProgressBar(m_applet);
00141             bar->setFormat(m_transfers[key].toList().at(0).toString() + " %v%");
00142             bar->setMinimumSize(QSizeF(100, 20));
00143             m_progressBars [key] = bar;
00144 
00145             m_progressBarsLayout->addItem(bar);
00146         }
00147         // set the progress bar opacity to 1 if the transfer is active
00148         qreal opacity = (m_transfers [key].toList().at(3).toUInt() == 1) ? 1.0 : 0.6;
00149 
00150         m_progressBars [key]->setOpacity(opacity);
00151         m_progressBars [key]->setValue(m_transfers[key].toList().at(1).toString().toInt());
00152         totalSize += m_transfers[key].toList().at(2).toInt();
00153     }
00154 
00155     m_totalSizeLabel->setText(i18n("Total size: %1", KGlobal::locale()->formatByteSize(totalSize)));
00156     m_pageLabel->setText(i18n("Showing %1-%2 of %3 transfers",
00157         m_actualPage * MAX_DOWNLOADS_PER_PAGE, limit, m_transfers.size()));
00158 
00159     // remove the progressbars for the deleted transfers
00160     foreach(QString key, m_progressBars.keys()) {
00161         if(!m_transfers.keys().contains(key)) {
00162             Plasma::ProgressBar *bar = m_progressBars [key];
00163             m_progressBars.remove(key);
00164             m_progressBarsLayout->removeItem(bar);
00165             delete bar;
00166         }
00167     }
00168 
00169     // activate or deactivate the navigation buttons
00170     if(m_transfers.size() > ((m_actualPage + 1)* MAX_DOWNLOADS_PER_PAGE))
00171         m_nextPageButton->setEnabled(true);
00172     else
00173         m_nextPageButton->setEnabled(false);
00174 
00175     if(m_actualPage > 0)
00176         m_previousPageButton->setEnabled(true);
00177     else
00178         m_previousPageButton->setEnabled(false);
00179 
00180     m_applet->updateGeometry();
00181 }
00182 
00183 void BarChart::clear()
00184 {
00185     foreach(QString key, m_progressBars.keys()) {
00186         Plasma::ProgressBar *bar = m_progressBars [key];
00187         m_progressBarsLayout->removeItem(bar);
00188         m_progressBars.remove(key);
00189         delete bar;
00190     }
00191 }

kget

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal