summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client-qt/udm-client-qt/udm_main.cpp87
-rw-r--r--client-qt/udm-client-qt/udm_main.h12
-rw-r--r--protocol/udm.proto10
-rw-r--r--server/include/server_session.h2
-rw-r--r--server/src/server_session.cpp140
5 files changed, 214 insertions, 37 deletions
diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp
index b822163..62b8195 100644
--- a/client-qt/udm-client-qt/udm_main.cpp
+++ b/client-qt/udm-client-qt/udm_main.cpp
@@ -33,6 +33,7 @@
#include <QStackedLayout>
#include <QPushButton>
#include <QToolBar>
+#include <QMenu>
#include "connect_widget.h"
#include "client_session.h"
@@ -61,12 +62,17 @@ udm_main::udm_main(QWidget *parent)
tbl_downloads->setUpdatesEnabled(true);
mdl_downloads = new downloads_model(downloads);
tbl_downloads->setModel(mdl_downloads);
+ tbl_downloads->setContextMenuPolicy(Qt::CustomContextMenu);
tbl_downloads->setSelectionBehavior(QAbstractItemView::SelectRows);
tbl_downloads->setSortingEnabled(true);
tbl_downloads->horizontalHeader()->setHighlightSections(false);
tbl_downloads->horizontalHeader()->setMovable(true);
tbl_downloads->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
tbl_downloads->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+ connect(tbl_downloads, SIGNAL(customContextMenuRequested(QPoint)), SLOT(downloads_menu(QPoint)));
+ connect(tbl_downloads->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(downloads_selection_changed(QItemSelection,QItemSelection)));
+
+ create_menu();
tree_filters = new QTreeView;
mdl_filters = new filters_model;
@@ -98,6 +104,81 @@ udm_main::udm_main(QWidget *parent)
create_buttons();
}
+void udm_main::create_menu()
+{
+ download_menu = new QMenu;
+ QAction *a = download_menu->addAction(tr("Start"));
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(download_start()));
+ a = download_menu->addAction(tr("Stop"));
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(download_stop()));
+ a = download_menu->addAction(tr("Delete"));
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(download_delete()));
+ //TODO: dynamic menu
+}
+
+void udm_main::downloads_menu(const QPoint &/*pos*/)
+{
+ download_menu->popup(QCursor::pos());
+}
+
+
+void udm_main::download_start()
+{
+ client_msg msg;
+ msg.set_auth_token(auth_token);
+ for(auto i : tbl_downloads->selectionModel()->selectedRows())
+ {
+ msg.set_type(CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_START);
+ client_download_start_request *r = msg.add_download_start_request();
+ r->set_download_id(downloads[i.row()].id());
+ }
+ session->send_message(msg);
+}
+
+void udm_main::download_stop()
+{
+ client_msg msg;
+ msg.set_auth_token(auth_token);
+ for(auto i : tbl_downloads->selectionModel()->selectedRows())
+ {
+ msg.set_type(CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_STOP);
+ client_download_stop_request *r = msg.add_download_stop_request();
+ r->set_download_id(downloads[i.row()].id());
+ }
+ session->send_message(msg);
+}
+
+void udm_main::download_delete()
+{
+ client_msg msg;
+ msg.set_auth_token(auth_token);
+ for(auto i : tbl_downloads->selectionModel()->selectedRows())
+ {
+ msg.set_type(CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_DELETE);
+ client_download_delete_request *r = msg.add_download_delete_request();
+ r->set_download_id(downloads[i.row()].id());
+ }
+ session->send_message(msg);
+}
+
+void udm_main::downloads_selection_changed(QItemSelection s, QItemSelection)
+{
+ if(s.size())
+ {
+ btn_start->setEnabled(true);
+ btn_stop->setEnabled(true);
+ btn_del->setEnabled(true);
+ }
+ else
+ {
+ btn_start->setEnabled(false);
+ btn_stop->setEnabled(false);
+ btn_del->setEnabled(false);
+ }
+
+}
+
+
udm_main::~udm_main()
{
if(thread_client_session)
@@ -296,12 +377,12 @@ void udm_main::create_buttons()
void udm_main::btn_start_clicked()
{
-
+ download_start();
}
void udm_main::btn_stop_clicked()
{
-
+ download_stop();
}
void udm_main::btn_add_clicked()
@@ -332,7 +413,7 @@ void udm_main::got_download_settings(std::string module_name, std::map<int, std:
void udm_main::btn_del_clicked()
{
-
+ download_delete();
}
diff --git a/client-qt/udm-client-qt/udm_main.h b/client-qt/udm-client-qt/udm_main.h
index d3e07be..284c4e5 100644
--- a/client-qt/udm-client-qt/udm_main.h
+++ b/client-qt/udm-client-qt/udm_main.h
@@ -25,6 +25,7 @@
#include <QMainWindow>
+#include <QItemSelection>
#include "../../protocol/udm.pb.h"
class client_session;
@@ -37,6 +38,8 @@ class filters_model;
class QSplitter;
class QToolBar;
class QPushButton;
+class QMenu;
+class QAction;
namespace boost {
namespace asio {
@@ -70,6 +73,12 @@ protected slots:
void btn_add_clicked();
void btn_del_clicked();
+ void download_start();
+ void download_stop();
+ void download_delete();
+ void downloads_menu(const QPoint&);
+ void downloads_selection_changed(QItemSelection, QItemSelection);
+
signals:
void connect_signal(QString host, QString password, int port);
void connect_signal_ssl(QString host, QString password, int port, QString ssl_ca, QString ssl_crt, QString ssl_key);
@@ -78,6 +87,7 @@ private:
void client_pre_connect_init();
void client_connect_finalize();
void create_buttons();
+ void create_menu();
QThread *thread_client_session;
client_session *session;
boost::asio::io_service *io_service_;
@@ -88,6 +98,8 @@ private:
QTabWidget *tabs_info;
QToolBar *button_bar;
QPushButton *btn_start, *btn_stop, *btn_del, *btn_add;
+ QMenu *download_menu;
+ std::list<QAction*> download_menu_actions;
downloads_model *mdl_downloads;
filters_model *mdl_filters;
QSplitter *spl_hor, *spl_vert;
diff --git a/protocol/udm.proto b/protocol/udm.proto
index 38af4f4..dd23368 100644
--- a/protocol/udm.proto
+++ b/protocol/udm.proto
@@ -334,12 +334,12 @@ message client_msg {
repeated client_download_ui_data_request download_ui_data_request = 4;
repeated client_event_subscription_request subscription_request = 5;
repeated client_event_unsubscription_request unsubscription_request = 6;
- repeated client_download_request downloads_request = 7;
+ optional client_download_request download_info_request = 7;
optional client_download_add_request download_add_request = 8;
- optional client_download_start_request download_start_request = 9;
- optional client_download_stop_request download_stop_request = 10;
- optional client_download_delete_request download_delete_request = 11;
- optional client_download_action_request download_action_request = 12;
+ repeated client_download_start_request download_start_request = 9;
+ repeated client_download_stop_request download_stop_request = 10;
+ repeated client_download_delete_request download_delete_request = 11;
+ repeated client_download_action_request download_action_request = 12;
optional client_downloads_request download_list_request = 13;
}
diff --git a/server/include/server_session.h b/server/include/server_session.h
index 436c4ee..a4c570b 100644
--- a/server/include/server_session.h
+++ b/server/include/server_session.h
@@ -53,6 +53,8 @@ private:
void handle_write_no_read(const boost::system::error_code& error);
void handle_handshake(const boost::system::error_code& error);
bool handle_command(client_msg* msg);
+
+ void send_download_list();
char* recv_data_ = nullptr;
socket_wraper* socket_ = nullptr;
diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp
index 868370a..43d8837 100644
--- a/server/src/server_session.cpp
+++ b/server/src/server_session.cpp
@@ -421,40 +421,28 @@ bool server_session::handle_command(client_msg *msg)
}
break;
case CLIENT_MSG_TYPE::CLIENT_DOWNLOADS_LIST_REQUEST:
+ send_download_list();
+ break;
+ case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_INFO_REQUEST:
{
- //TODO: thread safety
- //draft implementation, need a lot of optimizations
- server_msg m;
- m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOADS_LIST_REPLY);
- for(auto i : downloads)
+ for(auto i : modules->get_downloader_modules())
{
- 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(i->get_module_info().name == downloads[msg->download_info_request().download_id()].module_name)
{
- //downloader module not found, this should be a fatal error
- continue;
+ auto dm = static_cast<module_downloader *>(i);
+ server_msg m;
+ m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_INFO_REPLY);
+ download *d = m.mutable_download()->mutable_download();
+ d->set_id(msg->download_info_request().download_id());
+ auto dl = dm->get_download(downloads[msg->download_info_request().download_id()].module_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);
}
- 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:
@@ -482,6 +470,64 @@ bool server_session::handle_command(client_msg *msg)
d->set_module_name(msg->download_add_request().module_name());
d->set_downloaded(dl.downloaded);
send_message(&m);
+ break;
+ }
+ }
+ }
+ break;
+ case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_START:
+ {
+ for(auto i : msg->download_start_request())
+ {
+ for(auto m : modules->get_downloader_modules())
+ {
+ if(m->get_module_info().name == downloads[i.download_id()].module_name)
+ {
+ auto dm = static_cast<module_downloader *>(m);
+ if(!dm->start_download(i.download_id()))
+ {
+ //TODO: handle error
+ }
+ break;
+ }
+ }
+ }
+ }
+ break;
+ case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_STOP:
+ {
+ for(auto i : msg->download_stop_request())
+ {
+ for(auto m : modules->get_downloader_modules())
+ {
+ if(m->get_module_info().name == downloads[i.download_id()].module_name)
+ {
+ auto dm = static_cast<module_downloader *>(m);
+ if(!dm->stop_download(i.download_id()))
+ {
+ //TODO: handle error
+ }
+ break;
+ }
+ }
+ }
+ }
+ break;
+ case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_DELETE:
+ {
+ for(auto i : msg->download_delete_request())
+ {
+ for(auto m : modules->get_downloader_modules())
+ {
+ if(m->get_module_info().name == downloads[i.download_id()].module_name)
+ {
+ auto dm = static_cast<module_downloader *>(m);
+ if(!dm->delete_download(i.download_id(), i.with_data()));
+ {
+ //TODO: handle error
+ }
+ break;
+ }
}
}
}
@@ -493,6 +539,42 @@ bool server_session::handle_command(client_msg *msg)
return true;
}
+void server_session::send_download_list()
+{
+ //TODO: thread safety
+ //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())
+ {
+ if(dm->get_module_info().name == i.second.module_name)
+ {
+ module = dm;
+ break;
+ }
+ }
+ 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);
+ d->set_state(ds.state);
+ }
+ send_message(&m);
+}
+
void server_session::send_message(server_msg *msg)
{
int size = 0;