Added build script of Debian
[qtrapids] / src / gui / DownloadView.cpp
index d6c9183..252f5a9 100644 (file)
@@ -1,11 +1,9 @@
 /***************************************************************************
- *   Copyright (C) 2009 by Lassi Väätämöinen   *
- *   lassi.vaatamoinen@ixonos.com   *
+ *   Copyright (C) 2010 by Ixonos Plc   *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
+ *   the Free Software Foundation; version 2 of the License.               *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
@@ -29,11 +27,11 @@ DownloadView::DownloadView(QWidget* parent) :
                items_(),
                timer_(NULL)
 {
-  setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
-  setHeaderItem(DownloadViewItem::getHeaderItem());
+       setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
+       setHeaderItem(DownloadViewItem::getHeaderItem());
 
-  connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
-          this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
+       connect(this, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
+               this, SLOT(on_itemClicked(QTreeWidgetItem*, int)));
 
        timer_ = new QTimer(this);
        connect(timer_, SIGNAL(timeout()), this, SLOT(on_timeout()));
@@ -54,21 +52,21 @@ void DownloadView::newItem(qtrapids::QTorrentHandle handle)
 #endif
 
        DownloadViewItem *item = new DownloadViewItem(QStringList()
-                       << handle.name()
-                       << QString::number(handle.getTotalSize())
-                       << GetStatusString(handle.state())
-                       << QString::number(100*handle.progress() + '%')
-                       << QString::number(handle.downloadRate(), 'f', 2) 
-                       << QString::number(handle.uploadRate(),  'f', 2) 
-                       << QString::number(handle.numSeeds()) + "/"
-                                       + QString::number(handle.numLeeches())
-                       << QString::number(handle.ratio())
-                       << "ETA" );
-       
+               << handle.name()
+               << QString::number(handle.getTotalSize())
+               << GetStatusString(handle.state())
+               << QString::number(100*handle.progress())
+               << QString::number(handle.downloadRate(), 'f', 2)
+               << QString::number(handle.uploadRate(),  'f', 2)
+               << QString::number(handle.numSeeds()) + "/"
+               + QString::number(handle.numLeeches())
+               << QString::number(handle.ratio())
+               << "ETA" );
+
        // Set text color for status:
        QBrush brushTmp(GetStatusColor(handle.state()));
        item->setForeground(2, brushTmp);
-                       
+
        addTopLevelItem(item);
        items_[handle] = item;
 }
@@ -77,35 +75,35 @@ void DownloadView::newItem(qtrapids::QTorrentHandle handle)
 void DownloadView::updateItem(qtrapids::QTorrentHandle handle)
 {
        //qDebug() << "DownloadView::updateItem() "  << items_.count(handle);
-               
+
        static float lastProg = 0;
-       
+
        // If there are items currently downloading, update:
        if (items_.count(handle) > 0) {
-               
+
                DownloadViewItem *item = items_[handle];
-               
+
                // Only the changing fields are being updated:
                item->setData(2, Qt::DisplayRole,
-                                                                       QVariant(GetStatusString(handle.state())));
+                             QVariant(GetStatusString(handle.state())));
                item->setData(4, Qt::DisplayRole,
-                                                                       QVariant(QString::number(handle.downloadRate(), 'f', 2)));
+                             QVariant(QString::number(handle.downloadRate(), 'f', 2)));
                item->setData(5, Qt::DisplayRole,
-                                                                       QVariant(QString::number(handle.uploadRate(), 'f', 2)));
-               item->setData(6, Qt::DisplayRole, 
-                                                                       QString::number(handle.numSeeds()) + "/" 
-                                                                               + QString::number(handle.numLeeches()));
-                                                                               
-               // Set progress if increment is 1 percent.                      
+                             QVariant(QString::number(handle.uploadRate(), 'f', 2)));
+               item->setData(6, Qt::DisplayRole,
+                             QString::number(handle.numSeeds()) + "/"
+                             + QString::number(handle.numLeeches()));
+
+               // Set progress if increment is 1 percent.
                float prog = handle.progress();
                if ((prog-lastProg) >= 0.01 || prog >= 1.0) {
                        item->setData(3, Qt::DisplayRole,
-                                                                               QVariant(QString::number(100*prog) + '%'));
+                                     QVariant(QString::number(100*prog)));
                        lastProg = prog;
                }
-               
+
                /// @TODO: ETA-counter adjusting,if ETA is to be implemented
-                                                                               
+
                // Adjust color
                QBrush brushTmp(GetStatusColor(handle.state()));
                item->setForeground(2, brushTmp);
@@ -121,23 +119,23 @@ qtrapids::QTorrentHandle DownloadView::removeSelected()
 #endif
 
        DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
-       
+
        std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listIter
-                       = items_.begin();
+       = items_.begin();
        std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listEnd
-                       = items_.end();
-       
+       = items_.end();
+
        while (listIter != listEnd) {
                if (listIter->second == item) {
                        break;
                }
                ++listIter;
        }
-       
+
        qtrapids::QTorrentHandle handle = listIter->first;
        items_.erase(listIter);
 
-       
+
        int index = indexOfTopLevelItem(currentItem());
        if (index >= 0) {
                takeTopLevelItem(index);
@@ -167,14 +165,15 @@ void DownloadView::on_itemClicked(QTreeWidgetItem * item, int column)
        /*
        qDebug() << "DownloadView::on_itemClicked(()" << item << "," << column;
        qDebug() << "current item" << currentItem();
-       
+
        if (item == currentItem() && item->isSelected()) {
                item->setSelected(false);
        }
        */
 }
 
-void DownloadView::on_timeout() {
+void DownloadView::on_timeout()
+{
 #ifdef QTRAPIDS_DEBUG
        qDebug() << "DownloadView::on_timeout()";
 #endif
@@ -186,22 +185,22 @@ void DownloadView::on_timeout() {
 QString DownloadView::GetStatusString(qtrapids::QTorrentHandle::State const& status) const
 {
        switch (status) {
-               case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
-                       return tr("Queued");
-               case qtrapids::QTorrentHandle::CHECKING_FILES :
-                       return tr("Checking");
-               case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
-                       return tr("DL meta");
-               case qtrapids::QTorrentHandle::DOWNLOADING :
-                       return tr("Downloading");
-               case qtrapids::QTorrentHandle::FINISHED :
-                       return tr("Finished");
-               case qtrapids::QTorrentHandle::SEEDING :
-                       return tr("Seeding"); 
-               case qtrapids::QTorrentHandle::ALLOCATING :
-                       return tr("Allocating");
-               default:
-                       return tr("N/A");
+       case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
+               return tr("Queued");
+       case qtrapids::QTorrentHandle::CHECKING_FILES :
+               return tr("Checking");
+       case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
+               return tr("DL meta");
+       case qtrapids::QTorrentHandle::DOWNLOADING :
+               return tr("Downloading");
+       case qtrapids::QTorrentHandle::FINISHED :
+               return tr("Finished");
+       case qtrapids::QTorrentHandle::SEEDING :
+               return tr("Seeding");
+       case qtrapids::QTorrentHandle::ALLOCATING :
+               return tr("Allocating");
+       default:
+               return tr("N/A");
        }
 }
 
@@ -212,29 +211,29 @@ QColor DownloadView::GetStatusColor(qtrapids::QTorrentHandle::State const& statu
        QColor yellow(255,174,0);
 
        switch (status) {
-               case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
-               case qtrapids::QTorrentHandle::CHECKING_FILES :
-               case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
-               case qtrapids::QTorrentHandle::ALLOCATING :
-                       return yellow;
-               case qtrapids::QTorrentHandle::DOWNLOADING :
-               case qtrapids::QTorrentHandle::FINISHED :
-               case qtrapids::QTorrentHandle::SEEDING :
-                               return green;
-               default:
-                       return QColor();
+       case qtrapids::QTorrentHandle::QUEUED_FOR_CHECKING :
+       case qtrapids::QTorrentHandle::CHECKING_FILES :
+       case qtrapids::QTorrentHandle::DOWNLOADING_METADATA :
+       case qtrapids::QTorrentHandle::ALLOCATING :
+               return yellow;
+       case qtrapids::QTorrentHandle::DOWNLOADING :
+       case qtrapids::QTorrentHandle::FINISHED :
+       case qtrapids::QTorrentHandle::SEEDING :
+               return green;
+       default:
+               return QColor();
        }
 }
 
 void DownloadView::UpdateView()
 {
        DownloadViewItem *item = dynamic_cast<DownloadViewItem*> (currentItem());
-       
+
        std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listIter
-                       = items_.begin();
+       = items_.begin();
        std::map<qtrapids::QTorrentHandle, DownloadViewItem*>::iterator listEnd
-                       = items_.end();
-       
+       = items_.end();
+
        while (listIter != listEnd) {
                updateItem(listIter->first);
                ++listIter;