From c8029a36924fdad89b2455746bfd771da723287f Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 21 Aug 2015 04:05:55 +0300 Subject: client-qt: correct network thread termination downloads model skeleton filters model skeleton empty download info tabwindow main window layout initial server data requests (settings, modules, downloads) protocol: renamed most of ui_* messages to download_ui* as it more precise reworked ui related proto part added download related messages (should be sufficient for now) some work on event subscription part bit of work on module related messages added more top level messages (most of defined messages may be used now) --- client-qt/udm-client-qt/udm_main.cpp | 89 +++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 'client-qt/udm-client-qt/udm_main.cpp') diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp index 0089a45..17744aa 100644 --- a/client-qt/udm-client-qt/udm_main.cpp +++ b/client-qt/udm-client-qt/udm_main.cpp @@ -25,14 +25,25 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "connect_widget.h" #include "client_session.h" +#include "downloads_model.h" +#include "filters_model.h" udm_main::udm_main(QWidget *parent) : QMainWindow(parent) { + io_service_ = nullptr; + thread_client_session = nullptr; + //session = nullptr; auto menu_main = this->menuBar()->addMenu(tr("Main")); auto action_connect = menu_main->addAction(tr("Connect")); connect(action_connect, SIGNAL(triggered()), this, SLOT(show_connect_widget())); @@ -41,10 +52,55 @@ udm_main::udm_main(QWidget *parent) lbl_state = new QLabel; lbl_state->setText(tr("State") + ": " + tr("Offline")); this->statusBar()->addPermanentWidget(lbl_state); + + tbl_downloads = new QTableView; + tbl_downloads->setShowGrid(false); + mdl_downloads = new downloads_model; + tbl_downloads->setModel(mdl_downloads); + 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); + + tree_filters = new QTreeView; + mdl_filters = new filters_model; + tree_filters->setModel(mdl_filters); + tree_filters->header()->hide(); + tree_filters->setSelectionMode(QAbstractItemView::ExtendedSelection); + tree_filters->setSelectionBehavior(QAbstractItemView::SelectRows); + tree_filters->setIndentation(10); + + spl_hor = new QSplitter(Qt::Horizontal); + spl_hor->addWidget(tree_filters); + spl_hor->addWidget(tbl_downloads); + + spl_hor->setStretchFactor(0, 2); + spl_hor->setStretchFactor(1, 10); + + tabs_info = new QTabWidget; + + + + + spl_vert = new QSplitter(Qt::Vertical); + spl_vert->addWidget(spl_hor); + spl_vert->addWidget(tabs_info); + + spl_vert->setStretchFactor(0, 3); + spl_vert->setStretchFactor(1, 1); + setCentralWidget(spl_vert); + } udm_main::~udm_main() { + if(thread_client_session) + { + thread_client_session->quit(); + delete thread_client_session; + } //TODO: clear all remaining data } @@ -59,15 +115,30 @@ void udm_main::show_connect_widget() void udm_main::client_pre_connect_init() { + if(thread_client_session) + { + delete thread_client_session; + thread_client_session = nullptr; + } thread_client_session = new QThread(this); + if(io_service_) + { + delete io_service_; + io_service_ = nullptr; + } io_service_ = new boost::asio::io_service; +/* if(session) //crashing + { + delete session; + session = nullptr; + } */ session = new client_session(0, io_service_); //parent must be 0 here connect(session, SIGNAL(server_message_received(server_msg)), this, SLOT(server_message_received(server_msg))); connect(session, SIGNAL(client_connected(bool,QString)), this, SLOT(client_connected(bool,QString))); } void udm_main::client_connect_finalize() { - //connect(session, SIGNAL(terminate_thread()), thread_client_session, SLOT(terminate())); + connect(session, SIGNAL(terminate_thread()), thread_client_session, SLOT(quit())); session->moveToThread(thread_client_session); thread_client_session->start(); } @@ -99,6 +170,22 @@ void udm_main::server_message_received(server_msg msg) auth_token = msg.auth_reply().auth_token().c_str(); //TODO: update client status lbl_state->setText(tr("State") + ": " + tr("Connected") + ", " + tr("Authenticated")); + //request modules and settings here + { + client_msg msg; + msg.set_type(CLIENT_MSG_TYPE::CLIENT_CORE_SETTINGS_REQUEST); + session->send_message(msg); + } + { + client_msg msg; + msg.set_type(CLIENT_MSG_TYPE::CLIENT_MODULES_REQUEST); + session->send_message(msg); + } + { + client_msg msg; + msg.set_type(CLIENT_MSG_TYPE::CLIENT_DOWNLOADS_LIST_REQUEST); + session->send_message(msg); + } } else { -- cgit v1.2.3