diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-09-22 13:59:38 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-09-22 13:59:38 +0300 |
commit | bd7207d8bf82c58c60399c05c29c2312a8c0f258 (patch) | |
tree | bd8674bdf03e23d6797ab9e69ece4523307607ff | |
parent | acfde068698184249e50e0781a22bb38ba87cf3f (diff) |
protocol:
added download state field to "download"
added module defined download state names to "module_info"
few fields description
server:
added download state to downloader api structures
setting download states in outgoing downloads
client-qt:
basic implementation of download state in downloads table (withoud module defined states)
fixed downloads table model update (working)
-rw-r--r-- | client-qt/udm-client-qt/downloads_model.cpp | 47 | ||||
-rw-r--r-- | client-qt/udm-client-qt/downloads_model.h | 11 | ||||
-rw-r--r-- | client-qt/udm-client-qt/udm_main.cpp | 9 | ||||
-rw-r--r-- | protocol/udm.proto | 10 | ||||
-rw-r--r-- | server/include/api_module_downloader.h | 18 | ||||
-rw-r--r-- | server/src/server_session.cpp | 77 | ||||
-rw-r--r-- | server/udm-server.project | 10 |
7 files changed, 120 insertions, 62 deletions
diff --git a/client-qt/udm-client-qt/downloads_model.cpp b/client-qt/udm-client-qt/downloads_model.cpp index 1883a6c..f5d8817 100644 --- a/client-qt/udm-client-qt/downloads_model.cpp +++ b/client-qt/udm-client-qt/downloads_model.cpp @@ -57,15 +57,36 @@ QVariant downloads_model::data(const QModelIndex &index, int role) const break; // case 3: - return (qint64)((double)downloads[index.row()].downloaded() / (double)downloads[index.row()].size()) * 100.0; + if(downloads[index.row()].size()) + return (qint64)((double)downloads[index.row()].downloaded() / (double)downloads[index.row()].size()) * 100.0; + else + return QVariant(); break; - case 4: + case 4: //TODO: + { + switch(downloads[index.row()].state()) + { + case 0: + return tr("Stopped"); + break; + case 1: + return tr("Stopped"); + break; + //TODO: handle module defined states + default: + return QVariant(); + break; + } + return QVariant(); + } + break; + case 5: return downloads[index.row()].module_name().c_str(); break; - case 5: //TODO: + case 6: //TODO: return QVariant(); break; - case 6: //TODO: + case 7: //TODO: return QVariant(); break; @@ -99,12 +120,15 @@ QVariant downloads_model::headerData(int section, Qt::Orientation orientation, i return QString(tr("Progress")); break; case 4: - return QString(tr("Module name")); + return QString(tr("State")); break; case 5: - return QString(tr("Down Speed")); + return QString(tr("Module name")); break; case 6: + return QString(tr("Down Speed")); + break; + case 7: return QString(tr("ETA")); break; } @@ -134,9 +158,18 @@ bool downloads_model::removeRows(int position, int rows, const QModelIndex &/*in return true; } +QModelIndex downloads_model::index ( int row, int column, const QModelIndex & /*parent */) const +{ + return createIndex(row, column); +} +QModelIndex downloads_model::parent ( const QModelIndex & /*index*/) const +{ + return QModelIndex(); +} + void downloads_model::refresh() { - QModelIndex topLeft = createIndex(0,0), bottomRight = createIndex(downloads.size()-1, 5); + QModelIndex topLeft = createIndex(0,0), bottomRight = createIndex(downloads.size() - 1, 6); emit dataChanged(topLeft, bottomRight); } diff --git a/client-qt/udm-client-qt/downloads_model.h b/client-qt/udm-client-qt/downloads_model.h index 08172d5..519d8ba 100644 --- a/client-qt/udm-client-qt/downloads_model.h +++ b/client-qt/udm-client-qt/downloads_model.h @@ -31,12 +31,21 @@ class downloads_model : public QAbstractTableModel Q_OBJECT public: downloads_model(std::vector<download> &downloads, QObject *parent = 0); + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount ( const QModelIndex & parent = QModelIndex() ) const; + QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - int columnCount ( const QModelIndex & parent = QModelIndex() ) const; + + QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const; + QModelIndex parent ( const QModelIndex & index ) const; + + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); + + void sort ( int column, Qt::SortOrder order = Qt::AscendingOrder ); diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp index ee58834..b822163 100644 --- a/client-qt/udm-client-qt/udm_main.cpp +++ b/client-qt/udm-client-qt/udm_main.cpp @@ -220,9 +220,14 @@ void udm_main::server_message_received(server_msg msg) break; case SERVER_MSG_TYPE::SERVER_DOWNLOADS_LIST_REPLY: { - downloads.clear(); //TODO: something better + if(!downloads.empty()) + { + mdl_downloads->removeRows(0, downloads.size()); + downloads.clear(); //TODO: something better + } for(auto i : msg.downloads()) downloads.push_back(i.download()); + mdl_downloads->insertRows(0, downloads.size()); mdl_downloads->refresh(); } break; @@ -233,6 +238,7 @@ void udm_main::server_message_received(server_msg msg) { if(i.id() == msg.download().download().id()) { + //TODO: merge download, not replace i = msg.download().download(); found = true; break; @@ -240,6 +246,7 @@ void udm_main::server_message_received(server_msg msg) } if(!found) downloads.push_back(msg.download().download()); + mdl_downloads->insertRows(downloads.size(), 1); mdl_downloads->refresh(); } break; diff --git a/protocol/udm.proto b/protocol/udm.proto index c1f1909..38af4f4 100644 --- a/protocol/udm.proto +++ b/protocol/udm.proto @@ -154,6 +154,7 @@ message download { optional download_content_entry content = 4; required int64 size = 5; required int64 downloaded = 6; + required int32 state = 7; //download state as defined in api_module_downloader.h, or module defined state } message server_download_reply { @@ -247,11 +248,12 @@ message module_info //general module info for client including settings, downloa required string version = 3; optional string description = 4 [default = "no description specified"]; repeated setting settings = 5; - repeated module_download_ui_element_info download_info_ui = 6; //always complete here - repeated module_download_ui_element_info download_creation_ui = 7; - repeated module_download_menu_element_info download_menu = 8; + repeated module_download_ui_element_info download_info_ui = 6; //module defined download info ui, always complete here + repeated module_download_ui_element_info download_creation_ui = 7; //module defined download creation ui, always complete here + repeated module_download_menu_element_info download_menu = 8; //module defined download menu info, may not present repeated module_download_menu_element_info download_content_menu = 9; //menu for files and folders inside download root, may not present - repeated string_pair get_downloads_parameters_info = 10; + repeated string_pair get_downloads_parameters_info = 10; //info about additional parameters which may be passed to api_module_downloader::get_download, api_module_downloader::get_downloads + repeated int_string_pair download_state_name = 11; //module defined download states description, we have a few hardcoded states necessary for every downloader: 0 = stopped, 1 = running, ... } //module related messages end diff --git a/server/include/api_module_downloader.h b/server/include/api_module_downloader.h index ba6cb6a..6445772 100644 --- a/server/include/api_module_downloader.h +++ b/server/include/api_module_downloader.h @@ -57,7 +57,8 @@ struct downloader_module_info : public module_info_base //downloader_module_info { std::list<module_download_menu_element_info_s> download_root_menu, download_content_menu; //downloader module can add additional menu entries for download root and download content if content management supported by protocol std::list<module_download_ui_element_info_s> download_info_ui, download_creation_ui; //downloader module should set all data fields required for download creation, also may set data fields for info in ui in client - std::map<std::string, std::string> get_downloads_parameters_info; //any supported parameters of get_downloads(), get_download_info() must be described here + std::map<std::string, std::string> get_downloads_parameters_info; //module defined parameters of get_downloads(), get_download_info() must be described here + std::map<int, std::string> download_state_names; //module defined download states }; enum DOWNLOAD_CONTENT_ENTRY_TYPE_s { @@ -75,15 +76,20 @@ struct download_content_entry_s { //here is basic content entry description, thi std::map<std::string, std::string> info_map; //any additional info }; +enum download_state_e { + stoppped = 0, + running = 1 +}; struct download_s { int id = -1; //id generated via download_add or via session restore and it's unique for current session and current dowloader - std::string name; - int64_t size = 0, downloaded = 0, download_speed = 0; //download size and size of downloaded data, also download speed all vars in bytes - std::map<int, std::string> info_map; //any additional info provided by downloader module can be stored here - std::list<download_content_entry_s> content; //download content can be set for download, structure described above - std::map<std::string, std::string> metadata; //client defined metadata map + std::string name; + int64_t size = 0, downloaded = 0, download_speed = 0; //download size and size of downloaded data, also download speed all vars in bytes + download_state_e state = download_state_e::stoppped; //download state can be module defined + std::map<int, std::string> info_map; //any additional info provided by downloader module can be stored here + std::list<download_content_entry_s> content; //download content can be set for download, structure described above + std::map<std::string, std::string> metadata; //client defined metadata map }; class module_downloader : public module_base diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp index ff49408..2c8687d 100644 --- a/server/src/server_session.cpp +++ b/server/src/server_session.cpp @@ -420,34 +420,35 @@ bool server_session::handle_command(client_msg *msg) //draft implementation, need a lot of optimizations server_msg m; m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOADS_LIST_REPLY); - for(auto i : downloads) - { - server_download_reply *r = m.add_downloads(); - download *d = r->mutable_download(); - d->set_id(i.first); //set core_id for later access - d->set_module_name(i.second.module_name); - module_base *module = nullptr; - for(auto dm : modules->get_downloader_modules()) - { + for(auto i : downloads) + { + server_download_reply *r = m.add_downloads(); + download *d = r->mutable_download(); + d->set_id(i.first); //set core_id for later access + d->set_module_name(i.second.module_name); + module_base *module = nullptr; + for(auto dm : modules->get_downloader_modules()) + { if(dm->get_module_info().name == i.second.module_name) { module = dm; break; } - } - if(!module) - { + } + if(!module) + { //downloader module not found, this should be a fatal error continue; - } - module_downloader *dm = static_cast<module_downloader*>(module); - download_s ds = dm->get_download(i.second.module_id); - d->set_downloaded(ds.downloaded); - d->set_size(ds.size); - d->set_name(ds.name); - } - send_message(&m); - return true; + } + module_downloader *dm = static_cast<module_downloader*>(module); + download_s ds = dm->get_download(i.second.module_id); + d->set_downloaded(ds.downloaded); + d->set_size(ds.size); + d->set_name(ds.name); + d->set_state(ds.state); + } + send_message(&m); + return true; } break; case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_ADD: @@ -459,24 +460,24 @@ bool server_session::handle_command(client_msg *msg) std::map<int, std::string> params; for(auto p : msg->download_add_request().params()) params[p.id()] = p.value(); - auto dm = static_cast<module_downloader *>(i); - int download_id = dm->add_download(params); - int core_id = downloads.size(); - downloads[core_id].module_id = download_id; - downloads[core_id].module_name = msg->download_add_request().module_name(); - server_msg m; - m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_INFO_REPLY); - download *d = m.mutable_download()->mutable_download(); - d->set_id(core_id); - auto dl = dm->get_download(download_id); - d->set_name(dl.name); - d->set_size(dl.size); - d->set_module_name(msg->download_add_request().module_name()); - d->set_downloaded(dl.downloaded); - send_message(&m); - + auto dm = static_cast<module_downloader *>(i); + int download_id = dm->add_download(params); + int core_id = downloads.size(); + downloads[core_id].module_id = download_id; + downloads[core_id].module_name = msg->download_add_request().module_name(); + server_msg m; + m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_INFO_REPLY); + download *d = m.mutable_download()->mutable_download(); + d->set_id(core_id); + auto dl = dm->get_download(download_id); + d->set_name(dl.name); + d->set_size(dl.size); + d->set_state(dl.state); + d->set_module_name(msg->download_add_request().module_name()); + d->set_downloaded(dl.downloaded); + send_message(&m); } - } + } } break; default: diff --git a/server/udm-server.project b/server/udm-server.project index 9a2b1b2..39a75cc 100644 --- a/server/udm-server.project +++ b/server/udm-server.project @@ -1,6 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <CodeLite_Project Name="udm-server"> <Plugins> + <Plugin Name="qmake"> + <![CDATA[00010001N0005Debug000000000000]]> + </Plugin> <Plugin Name="CMakePlugin"> <![CDATA[[{ "name": "Debug", @@ -13,9 +16,6 @@ "parentProject": "" }]]]> </Plugin> - <Plugin Name="qmake"> - <![CDATA[00010001N0005Debug000000000000]]> - </Plugin> </Plugins> <Description/> <Dependencies/> @@ -89,8 +89,8 @@ <StartupCommands/> </Debugger> <PreBuild> - <Command Enabled="no">#[ -d ../protocol ] || mkdir ../protocol</Command> - <Command Enabled="no">#protoc --cpp_out=../protocol --proto_path=../protocol ../protocol/udm.proto</Command> + <Command Enabled="yes">[ -d ../protocol ] || mkdir ../protocol</Command> + <Command Enabled="yes">protoc --cpp_out=../protocol --proto_path=../protocol ../protocol/udm.proto</Command> </PreBuild> <PostBuild/> <CustomBuild Enabled="no"> |