Added build script of Debian
[qtrapids] / src / client / DownloadView.cpp
index 94bcaf4..cf04e51 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        *
@@ -30,7 +28,8 @@ namespace qtrapids
 
 DownloadView::DownloadView(QWidget* parent) :
                QTreeWidget(parent),
-               items_()
+               items_(),
+               settings_()
 {
        setRootIsDecorated(false); // Hide branch lines, making one-level treeview (similar to list)
        setHeaderItem(DownloadViewItem::getHeaderItem());
@@ -100,8 +99,8 @@ void DownloadView::addItem_(TorrentState const& info, ParamsMap_t)
          << formatSize(info.total_size)
          << GetStatusString((TorrentStatus::Id)info.state)
          << formatProgress(info.progress)
-         << QString::number(info.down_rate, 'f', 2)
-         << QString::number(info.up_rate, 'f', 2)
+         << formatSize(info.down_rate)
+         << formatSize(info.up_rate)
          << QString::number(info.seeds) + "/" + QString::number(info.leeches)
          << QString::number(info.ratio)
          << "ETA" );
@@ -122,12 +121,22 @@ void DownloadView::updateItem_(DownloadViewItem *item
        item->setData(3, Qt::DisplayRole,
                      QVariant(formatProgress(info.progress)));
        item->setData(4, Qt::DisplayRole,
-                     QVariant(QString::number(info.down_rate)));
+                     QVariant(formatSize(info.down_rate)));
        item->setData(5, Qt::DisplayRole,
-                     QVariant(QString::number(info.up_rate)));
+                     QVariant(formatSize(info.up_rate)));
        item->setData(6, Qt::DisplayRole,
                      QString::number(info.seeds) + "/" + QString::number(info.leeches));
-
+       item->setData(7, Qt::DisplayRole, QString::number(info.ratio));
+       
+       // Calculate ETA
+       if (info.down_rate > 0) {
+               qulonglong eta = (info.total_size - info.total_done) / info.down_rate;
+               item->setData(8, Qt::DisplayRole, formatElapsedTime(eta));
+       }       else {
+               item->setData(8, Qt::DisplayRole, "N/A");
+       }
+       
+       // Set color for status text
        QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state));
        item->setForeground(2, brushTmp);
 }
@@ -161,27 +170,52 @@ void DownloadView::on_itemClicked(QTreeWidgetItem * , int)
 }
 
 
+void DownloadView::saveView()
+{
+               QTreeWidgetItem *item = headerItem();
+               QList<QVariant> columns;
+               
+               for (int i = 0; i < item->columnCount(); ++i) {
+                       isColumnHidden(i) ? columns.push_back(QVariant(false)) : columns.push_back(QVariant(true));
+               }
+               
+       settings_.setValue("downloadview_columns", QVariant(columns));
+}
+
+
+void DownloadView::restoreView()
+{
+       QTreeWidgetItem *item = headerItem();
+       QVariant columns(settings_.value("downloadview_columns"));
+       QList<QVariant> columnList = columns.toList();
+       
+       for (int i = 0; i < columnList.size(); ++i) {
+               columnList.at(i).toBool() ? setColumnHidden(i, false) : setColumnHidden(i, true);
+       }
+}
+
+
 QString DownloadView::GetStatusString(TorrentStatus::Id status)
 {
        switch (status) {
-       case TorrentStatus::QUEUED_FOR_CHECKING :
-               return tr("Queued");
-       case TorrentStatus::CHECKING_FILES :
-               return tr("Checking");
-       case TorrentStatus::DOWNLOADING_METADATA :
-               return tr("DL meta");
-       case TorrentStatus::DOWNLOADING :
-               return tr("Downloading");
-       case TorrentStatus::FINISHED :
-               return tr("Finished");
-       case TorrentStatus::SEEDING :
-               return tr("Seeding");
-       case TorrentStatus::ALLOCATING :
-               return tr("Allocating");
-       case TorrentStatus::CHECKING_RESUME_DATA :
-               return tr("Checking resume");
-       default:
-               return tr("N/A");
+               case TorrentStatus::QUEUED_FOR_CHECKING :
+                       return tr("Queued");
+               case TorrentStatus::CHECKING_FILES :
+                       return tr("Checking");
+               case TorrentStatus::DOWNLOADING_METADATA :
+                       return tr("DL meta");
+               case TorrentStatus::DOWNLOADING :
+                       return tr("Downloading");
+               case TorrentStatus::FINISHED :
+                       return tr("Finished");
+               case TorrentStatus::SEEDING :
+                       return tr("Seeding");
+               case TorrentStatus::ALLOCATING :
+                       return tr("Allocating");
+               case TorrentStatus::CHECKING_RESUME_DATA :
+                       return tr("Checking resume");
+               default:
+                       return tr("N/A");
        }
 }
 
@@ -192,18 +226,18 @@ QColor DownloadView::GetStatusColor(TorrentStatus::Id status)
        QColor yellow(255,174,0);
 
        switch (status) {
-       case TorrentStatus::QUEUED_FOR_CHECKING :
-       case TorrentStatus::CHECKING_FILES :
-       case TorrentStatus::DOWNLOADING_METADATA :
-       case TorrentStatus::ALLOCATING :
-       case TorrentStatus::CHECKING_RESUME_DATA:
-               return yellow;
-       case TorrentStatus::DOWNLOADING :
-       case TorrentStatus::FINISHED :
-       case TorrentStatus::SEEDING :
-               return green;
-       default:
-               return QColor();
+               case TorrentStatus::QUEUED_FOR_CHECKING :
+               case TorrentStatus::CHECKING_FILES :
+               case TorrentStatus::DOWNLOADING_METADATA :
+               case TorrentStatus::ALLOCATING :
+               case TorrentStatus::CHECKING_RESUME_DATA:
+                       return yellow;
+               case TorrentStatus::DOWNLOADING :
+               case TorrentStatus::FINISHED :
+               case TorrentStatus::SEEDING :
+                       return green;
+               default:
+                       return QColor();
        }
 }