diff --git a/pglab/ASyncDBConnection.cpp b/pglab/ASyncDBConnection.cpp index 29366e4..7166502 100644 --- a/pglab/ASyncDBConnection.cpp +++ b/pglab/ASyncDBConnection.cpp @@ -130,7 +130,11 @@ bool ASyncDBConnection::Thread::makeConnection() auto keywords = m_config.getKeywords(); auto values = m_config.getValues(); #if true - return m_connection.connect(keywords, values, 0); + bool result = m_connection.connect(keywords, values, 0); + if (result) { + doStateCallback(State::Connected); + } + return result; #else while (!terminateRequested) { @@ -234,11 +238,12 @@ void ASyncDBConnection::Thread::doStateCallback(State state) void ASyncDBConnection::Thread::waitForAndSendCommand() { + using namespace std::chrono_literals; // lock the data std::unique_lock lk(m_commandQueue.m_mutex); if (m_commandQueue.m_queue.empty()) { // no data wait till there is data - m_commandQueue.m_newEvent.wait(lk); + m_commandQueue.m_newEvent.wait_for(lk, 1000ms); // can we use the predicate to reimplement the stop function???, []{return ready;}); } @@ -266,30 +271,26 @@ void ASyncDBConnection::Thread::waitForAndSendCommand() void ASyncDBConnection::Thread::doNewCommand() { - // todo: send command // get command from top of queue (but leave it in the queue, we need the callback) - { - std::lock_guard lg(m_commandQueue.m_mutex); - if (! m_commandQueue.m_queue.empty()) { - const Command &command = m_commandQueue.m_queue.front(); - if (!command.command.empty()) { - bool query_send = false; - if (command.params.empty()) - query_send = m_connection.sendQuery(command.command.c_str()); - else - query_send = m_connection.sendQueryParams(command.command.c_str(), command.params); + if (! m_commandQueue.m_queue.empty()) { + const Command &command = m_commandQueue.m_queue.front(); + if (!command.command.empty()) { + bool query_send = false; + if (command.params.empty()) + query_send = m_connection.sendQuery(command.command.c_str()); + else + query_send = m_connection.sendQueryParams(command.command.c_str(), command.params); - if (query_send) { - m_timer.start(); - doStateCallback(State::QuerySend); - } - else { - std::string error = m_connection.getErrorMessage(); - // todo: need to report the error - } - } - } - } + if (query_send) { + m_timer.start(); + doStateCallback(State::QuerySend); + } + else { + std::string error = m_connection.getErrorMessage(); + // todo: need to report the error + } + } + } } @@ -336,7 +337,7 @@ void ASyncDBConnection::Thread::waitForResult() timeout.tv_sec = 5; timeout.tv_usec = 0; - int select_result = select(1, &readfds, nullptr, nullptr, &timeout); + int select_result = select(sock + 1, &readfds, nullptr, nullptr, &timeout); if (select_result > 0) { if (FD_ISSET(sock, &readfds)) { if (consumeResultInput()) { diff --git a/pglab/ConnectionManagerWindow.ui b/pglab/ConnectionManagerWindow.ui index c98eafd..225e2af 100644 --- a/pglab/ConnectionManagerWindow.ui +++ b/pglab/ConnectionManagerWindow.ui @@ -201,12 +201,12 @@ 0 0 800 - 23 + 24 - File + Fi&le @@ -240,7 +240,7 @@ - :/icons/server_add.png:/icons/server_add.png + :/icons/add_connection.png:/icons/add_connection.png Add Connection @@ -248,9 +248,9 @@ - - :/icons/server_delete.png - + + :/icons/delete_connection.png + :/icons/delete_connection.png:/icons/delete_connection.png Delete connection @@ -261,8 +261,9 @@ - - :/icons/server_go.png:/icons/server_go.png + + :/icons/open_query_window.png + Connect @@ -270,14 +271,14 @@ - Quit application + &Quit application - - :/icons/backups.png - + + :/icons/backup_database.png + :/icons/backups.png:/icons/backup_database.png Backup database @@ -286,7 +287,7 @@ - :/icons/server_edit.png + :/icons/manage_server.png diff --git a/pglab/MainWindow.cpp b/pglab/MainWindow.cpp index f830664..aa4f038 100644 --- a/pglab/MainWindow.cpp +++ b/pglab/MainWindow.cpp @@ -131,6 +131,9 @@ void MainWindow::on_actionAbout_triggered() "\n" "Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons " "attribution 3.0 license\n" + "\n" + "More icons by https://icons8.com/ under Creative Commons Attribution-NoDerivs 3.0 Unported " + "license." )); } diff --git a/pglab/MainWindow.ui b/pglab/MainWindow.ui index 7a19461..d3e2cf3 100644 --- a/pglab/MainWindow.ui +++ b/pglab/MainWindow.ui @@ -45,12 +45,12 @@ 0 0 993 - 22 + 24 - File + Fi&le @@ -69,7 +69,7 @@ - Query + &Query @@ -79,7 +79,7 @@ - Window + Wi&ndow @@ -126,7 +126,7 @@ :/icons/folder.png:/icons/folder.png - Load SQL + &Load SQL Ctrl+O @@ -138,7 +138,7 @@ :/icons/script_save.png:/icons/script_save.png - Save SQL + &Save SQL Ctrl+S @@ -150,7 +150,7 @@ :/icons/table_save.png:/icons/table_save.png - Export data + &Export data @@ -160,7 +160,7 @@ - Close + &Close Ctrl+F4 @@ -168,12 +168,12 @@ - - :/icons/information.png - + + :/icons/about.png + :/icons/information.png:/icons/about.png - About + &About @@ -183,7 +183,7 @@ - Execute queries + &Execute queries Execute the (selected) queries @@ -199,7 +199,7 @@ - Cancel + &Cancel Alt+Pause @@ -211,7 +211,7 @@ :/icons/lightbulb.png:/icons/lightbulb.png - Explain Analyze + Ex&plain Analyze Shift+F7 @@ -219,22 +219,22 @@ - Save SQL as + Sa&ve SQL as - Save copy of SQL as + Save copy &of SQL as - - :/icons/page_white_add.png - + + :/icons/new_query_tab.png + :/icons/page_white_add.png:/icons/new_query_tab.png - New SQL + &New SQL Ctrl+N @@ -247,7 +247,7 @@ - Explain + E&xplain Explain the (selected) query @@ -258,7 +258,7 @@ - Show connection manager + &Show connection manager @@ -268,7 +268,7 @@ - Copy + &Copy Ctrl+C @@ -281,7 +281,7 @@ - Copy as C-string + Copy as C-&string Ctrl+Alt+C diff --git a/pglab/icons/about.png b/pglab/icons/about.png new file mode 100644 index 0000000..1a02d2b Binary files /dev/null and b/pglab/icons/about.png differ diff --git a/pglab/icons/add_connection.png b/pglab/icons/add_connection.png new file mode 100644 index 0000000..8ff7512 Binary files /dev/null and b/pglab/icons/add_connection.png differ diff --git a/pglab/icons/backup_database.png b/pglab/icons/backup_database.png new file mode 100644 index 0000000..64e9423 Binary files /dev/null and b/pglab/icons/backup_database.png differ diff --git a/pglab/icons/backups.png b/pglab/icons/backups.png deleted file mode 100644 index 41b14aa..0000000 Binary files a/pglab/icons/backups.png and /dev/null differ diff --git a/pglab/icons/delete_connection.png b/pglab/icons/delete_connection.png new file mode 100644 index 0000000..5563984 Binary files /dev/null and b/pglab/icons/delete_connection.png differ diff --git a/pglab/icons/information.png b/pglab/icons/information.png deleted file mode 100644 index 93c67f2..0000000 Binary files a/pglab/icons/information.png and /dev/null differ diff --git a/pglab/icons/manage_server.png b/pglab/icons/manage_server.png new file mode 100644 index 0000000..7331756 Binary files /dev/null and b/pglab/icons/manage_server.png differ diff --git a/pglab/icons/new_query_tab.png b/pglab/icons/new_query_tab.png new file mode 100644 index 0000000..40f546e Binary files /dev/null and b/pglab/icons/new_query_tab.png differ diff --git a/pglab/icons/open_query_window.png b/pglab/icons/open_query_window.png new file mode 100644 index 0000000..46cd65a Binary files /dev/null and b/pglab/icons/open_query_window.png differ diff --git a/pglab/icons/server_add.png b/pglab/icons/server_add.png deleted file mode 100644 index 210979f..0000000 Binary files a/pglab/icons/server_add.png and /dev/null differ diff --git a/pglab/resources.qrc b/pglab/resources.qrc index 657d688..8b00d1b 100644 --- a/pglab/resources.qrc +++ b/pglab/resources.qrc @@ -1,6 +1,5 @@  - icons/server_add.png icons/server_delete.png icons/server_go.png icons/script_delete.png @@ -12,13 +11,18 @@ icons/page_white_add.png icons/page_white_delete.png icons/lightbulb_off.png - icons/information.png icons/16x16/document_green.png icons/16x16/document_red.png icons/16x16/document_yellow.png - icons/backups.png icons/page_white_copy.png icons/token_shortland_character.png icons/server_edit.png + icons/new_query_tab.png + icons/about.png + icons/backup_database.png + icons/add_connection.png + icons/delete_connection.png + icons/open_query_window.png + icons/manage_server.png diff --git a/pglab/tsqueue.h b/pglab/tsqueue.h index 8b93d34..12a915e 100644 --- a/pglab/tsqueue.h +++ b/pglab/tsqueue.h @@ -15,7 +15,7 @@ public: bool empty(); t_Callable pop(); - //HANDLE getNewDataEventHandle(); + //HANDLE getNewDataEventHandle(); Looks like this wasn't use at all so we can leave the event out. private: using t_CallableQueue = std::deque;