summaryrefslogtreecommitdiff
path: root/client-qt/udm-client-qt/downloads_model.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-09-10 00:15:07 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-09-10 00:15:07 +0300
commitccffc685c412183b56f822438da5cc8a575d757e (patch)
tree4ff9b3abb4ac1d94941ff5aa5aee9ee4cbe74a3e /client-qt/udm-client-qt/downloads_model.cpp
parentb5af51e358073145cdf66470cc890d98547a6dac (diff)
client-qt:
handle disconnect basic downloads model (still draft with unimplemented basic features like dynamic columns count, dynamic columns will be implemented next) basic handler for download list (in theory it's already working now, but untested) basic modules info handler (just store data in memory for now, all basic features still unimplemented, download info ui templates generation will be implemented next here) basic core info handler (just store data in memory for now, core settings and core info ui will be implemented next here.) server: api: added client metadata manipulation api for downloader modules added metadata map to download structure in downloader modules curl_downloader: implemented new api's
Diffstat (limited to 'client-qt/udm-client-qt/downloads_model.cpp')
-rw-r--r--client-qt/udm-client-qt/downloads_model.cpp90
1 files changed, 82 insertions, 8 deletions
diff --git a/client-qt/udm-client-qt/downloads_model.cpp b/client-qt/udm-client-qt/downloads_model.cpp
index 2dadc0f..567b5e5 100644
--- a/client-qt/udm-client-qt/downloads_model.cpp
+++ b/client-qt/udm-client-qt/downloads_model.cpp
@@ -21,47 +21,121 @@
#include "downloads_model.h"
-downloads_model::downloads_model(QObject *parent)
+downloads_model::downloads_model(std::vector<download> &downloads_, QObject */*parent*/) : downloads(downloads_)
{
}
-int downloads_model::rowCount(const QModelIndex &parent) const
+int downloads_model::rowCount(const QModelIndex &/*parent*/) const
{
- return 0;
+ return downloads.size();
}
QVariant downloads_model::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
+ if((unsigned)index.row() >= downloads.size())
+ return QVariant();
+
+
+ //TODO: support for dynamic columnt count
+
+ if(role == Qt::DisplayRole)
+ {
+ switch(index.column())
+ {
+ case 0:
+ return QString(" ") + QString::fromUtf8(downloads[index.row()].name().c_str());
+ break;
+ //TODO: human readable size
+ case 1:
+ return (qint64) downloads[index.row()].size();
+ break;
+ case 2:
+ return (qint64)downloads[index.row()].downloaded();
+ break;
+ //
+ case 3:
+ return (qint64)((double)downloads[index.row()].downloaded() / (double)downloads[index.row()].size()) * 100.0;
+ break;
+ case 4:
+ return downloads[index.row()].module_name().c_str();
+ break;
+ case 5: //TODO:
+ return QVariant();
+ break;
+ case 6: //TODO:
+ return QVariant();
+ break;
+
+
+
+ }
+ }
+ return QVariant();
+
}
QVariant downloads_model::headerData(int section, Qt::Orientation orientation, int role) const
{
+ //TODO: support for dynamic columnt count
+ if(role == Qt::DisplayRole)
+ {
+ if(orientation == Qt::Horizontal)
+ {
+ switch(section)
+ {
+ case 0:
+ return QString(tr("Name"));
+ break;
+ case 1:
+ return QString(tr("Size"));
+ break;
+ case 2:
+ return QString(tr("Downloaded"));
+ break;
+ case 3:
+ return QString(tr("Progress"));
+ break;
+ case 4:
+ return QString(tr("Module name"));
+ break;
+ case 5:
+ return QString(tr("Down Speed"));
+ break;
+ case 6:
+ return QString(tr("ETA"));
+ break;
+ }
+ }
+ }
+
return QVariant();
}
-int downloads_model::columnCount ( const QModelIndex & parent) const
+int downloads_model::columnCount ( const QModelIndex & /*parent*/) const
{
- return 1;
+ //TODO: support for dynamic columnt count
+ return 7;
}
-bool downloads_model::insertRows(int position, int rows, const QModelIndex &index)
+bool downloads_model::insertRows(int position, int rows, const QModelIndex &/*index*/)
{
beginInsertRows(QModelIndex(), position, position+rows-1);
endInsertRows();
return true;
}
-bool downloads_model::removeRows(int position, int rows, const QModelIndex &index)
+bool downloads_model::removeRows(int position, int rows, const QModelIndex &/*index*/)
{
beginRemoveRows(QModelIndex(), position, position+rows-1);
endRemoveRows();
return true;
}
-void downloads_model::sort ( int column, Qt::SortOrder order)
+void downloads_model::sort ( int /*column*/, Qt::SortOrder /*order*/)
{
+ //TODO:
}