From 23df384c55469156e3c365dadd3dd75c19cf544c Mon Sep 17 00:00:00 2001 From: pholat Date: Wed, 27 May 2020 13:49:50 +0200 Subject: [PATCH] EGD-3087 SMS Search implemented (#374) * EGD-3087 WIP adding SMS Querry * EGD-3087 Added query virtual interface on Service top layer Service shouldn't implement query logic and should be proxying that. additionally: - small fixes in includes - shared service db name same way as apps and event manager * EGD-3087 Query - want to work on interface not on db * EGD-3087 Query gluecode works fine. Our query in SMS search calls getBySMSQuery Changes cut off before any potential orm interface layer * EGD-3087 WIP Interface in use * EGD-3087 Query for SMS search works as designed * EGD-3087 Query results should be on screen * EGD-3087 BUG workaround - need to deep refresh display to show data * EGD-3087 Searching for text from input works fine * EGD-3087 Showing results / or empty results depending on query * EGD-3087 Pre PR fixups * EGD-3087 Empty search - getting back to prewious window ignore current * EGD-3087 PR applied * EGD-3087 PR - style fixed * EGD-3087 Review - DB ListView handling moved to separate function * EGD-3087 Workaround: crash on use after free fix * EGD-3087 PR stylistic changes * EGD-3087 PR cleanup applied * EGD-3087 Added test for Query interface * EGD-3087 renamed getByQuery to getQuery & finished tests * EGD-3087 Post rebase fixup * EGD-3087 PR - moved ListView request part to separate function * EGD-3087 PR Fixups * EGD-3087 Post rebase style fix * EGD-3087 Added variable for DB service stack & const to getter function --- image/assets/lang/lang_de.json | 4 +- image/assets/lang/lang_en.json | 4 +- image/assets/lang/lang_pl.json | 4 +- image/assets/lang/lang_sp.json | 4 +- .../ApplicationDesktop.cpp | 4 +- .../ApplicationDesktop.hpp | 2 +- .../ApplicationMessages.cpp | 15 ++- .../ApplicationMessages.hpp | 2 +- .../application-messages/CMakeLists.txt | 47 ++++----- .../data/SMSTextToSearch.cpp | 9 ++ .../data/SMSTextToSearch.hpp | 12 +++ .../models/SearchResultsModel.cpp | 26 ++++- .../models/SearchResultsModel.hpp | 18 ++++ .../windows/SearchResults.cpp | 63 +++++++++--- .../windows/SearchResults.hpp | 5 + .../windows/SearchStart.cpp | 9 +- .../windows/PhonebookErrors.cpp | 4 +- .../windows/PhonebookSearch.cpp | 2 +- module-db/CMakeLists.txt | 71 ++++++------- module-db/Common/Query.hpp | 22 +++++ module-db/Interface/BaseInterface.hpp | 54 ++++++++++ module-db/Interface/Record.cpp | 22 +++-- module-db/Interface/Record.hpp | 17 +--- module-db/Interface/ThreadRecord.cpp | 15 +++ module-db/Interface/ThreadRecord.hpp | 8 ++ module-db/Tables/README.md | 6 ++ module-db/Tables/ThreadsTable.cpp | 69 ++++++++----- module-db/Tables/ThreadsTable.hpp | 3 + module-db/queries/README.md | 8 ++ module-db/queries/sms/QuerySMSSearch.cpp | 32 ++++++ module-db/queries/sms/QuerySMSSearch.hpp | 33 +++++++ module-db/tests/CMakeLists.txt | 1 + module-db/tests/ContactsNameTable_tests.cpp | 2 +- module-db/tests/QueryInterface.cpp | 54 ++++++++++ module-gui/gui/core/BoundingBox.cpp | 1 + module-gui/gui/core/Font.hpp | 1 + module-gui/gui/widgets/BoxLayout.cpp | 6 +- module-gui/gui/widgets/Style.hpp | 31 +++--- .../service-cellular/ServiceCellular.cpp | 6 +- .../api/CellularServiceAPI.hpp | 14 +-- module-services/service-db/CMakeLists.txt | 2 + module-services/service-db/ServiceDB.cpp | 85 ++++++++++------ module-services/service-db/ServiceDB.hpp | 10 +- .../service-db/api/DBServiceAPI.cpp | 99 ++++++++++--------- .../service-db/api/DBServiceAPI.hpp | 2 + .../api/DBServiceAPI_GetByQuery.cpp | 9 ++ .../service-db/includes/DBServiceName.hpp | 5 + .../messages/DBNotificationMessage.cpp | 15 ++- .../messages/DBNotificationMessage.hpp | 50 ++++------ .../service-db/messages/QueryMessage.cpp | 27 +++++ .../service-db/messages/QueryMessage.hpp | 30 ++++++ .../service-evtmgr/EventManager.cpp | 5 +- source/MessageType.hpp | 1 + 53 files changed, 748 insertions(+), 302 deletions(-) create mode 100644 module-apps/application-messages/data/SMSTextToSearch.cpp create mode 100644 module-apps/application-messages/data/SMSTextToSearch.hpp create mode 100644 module-db/Common/Query.hpp create mode 100644 module-db/Interface/BaseInterface.hpp create mode 100644 module-db/Tables/README.md create mode 100644 module-db/queries/README.md create mode 100644 module-db/queries/sms/QuerySMSSearch.cpp create mode 100644 module-db/queries/sms/QuerySMSSearch.hpp create mode 100644 module-db/tests/QueryInterface.cpp create mode 100644 module-services/service-db/api/DBServiceAPI_GetByQuery.cpp create mode 100644 module-services/service-db/includes/DBServiceName.hpp create mode 100644 module-services/service-db/messages/QueryMessage.cpp create mode 100644 module-services/service-db/messages/QueryMessage.hpp diff --git a/image/assets/lang/lang_de.json b/image/assets/lang/lang_de.json index 1ca754ed9..ffa2a4eef 100644 --- a/image/assets/lang/lang_de.json +++ b/image/assets/lang/lang_de.json @@ -138,9 +138,9 @@ "app_phonebook_back": "BACK", "app_phonebook_select": "SELECT", "app_phonebook_search_win_contacts": "Contacts", - "app_phonebook_search_win_search": "Search", + "common_search_uc": "Search", "app_phonebook_search_win_info": "Type what do you need and click SEARCH", - "app_phonebook_search_results": "Results", + "common_search_results": "Results", "app_phonebook_list_favourites": "Favourites", "app_phonebook_contact_title": "Add Contact", "app_phonebook_contact_address": "Address", diff --git a/image/assets/lang/lang_en.json b/image/assets/lang/lang_en.json index 5c6c2cdc4..510fc2338 100644 --- a/image/assets/lang/lang_en.json +++ b/image/assets/lang/lang_en.json @@ -163,9 +163,9 @@ "app_phonebook_confirm": "CONFIRM", "app_phonebook_select": "SELECT", "app_phonebook_search_win_contacts": "Contacts", - "app_phonebook_search_win_search": "Search", + "common_search_uc": "Search", "app_phonebook_search_win_info": "Type what do you need\nand click SEARCH", - "app_phonebook_search_results": "Search results", + "common_search_results": "Search results", "app_phonebook_search_no_results": "There are no results", "app_phonebook_list_favourites": "Favourites", "app_phonebook_contact_title": "Add Contact", diff --git a/image/assets/lang/lang_pl.json b/image/assets/lang/lang_pl.json index 27c52bd7b..ba80a681b 100644 --- a/image/assets/lang/lang_pl.json +++ b/image/assets/lang/lang_pl.json @@ -139,9 +139,9 @@ "app_phonebook_back": "WRÓĆ", "app_phonebook_select": "WYBIERZ", "app_phonebook_search_win_contacts": "Kontakty", - "app_phonebook_search_win_search": "Szukaj", + "common_search_uc": "Szukaj", "app_phonebook_search_win_info": "wpisz czego szukasz i naciśnij SZUKAJ", - "app_phonebook_search_results": "Rezultaty", + "common_search_results": "Rezultaty", "app_phonebook_list_favourites": "Ulubione", "app_phonebook_contact_title": "Dodaj Kontakt", "app_phonebook_contact_no_name": "brak nazwy", diff --git a/image/assets/lang/lang_sp.json b/image/assets/lang/lang_sp.json index 19a20b2b7..4dc75d50b 100644 --- a/image/assets/lang/lang_sp.json +++ b/image/assets/lang/lang_sp.json @@ -138,9 +138,9 @@ "app_phonebook_back": "BACK", "app_phonebook_select": "SELECT", "app_phonebook_search_win_contacts": "Contacts", - "app_phonebook_search_win_search": "Search", + "common_search_uc": "Search", "app_phonebook_search_win_info": "Type what do you need and click SEARCH", - "app_phonebook_search_results": "Results", + "common_search_results": "Results", "app_phonebook_list_favourites": "Favourites", "app_phonebook_contact_title": "Add Contact", "app_phonebook_contact_no_name": "no name", diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 77ef3c2a1..b0b15bd5e 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -48,7 +48,7 @@ namespace app } bool handled = false; - if (auto msg = dynamic_cast(msgl)) { + if (auto msg = dynamic_cast(msgl)) { handled = handle(msg); } else if (auto msg = dynamic_cast(msgl)) { @@ -63,7 +63,7 @@ namespace app } } - auto ApplicationDesktop::handle(DBNotificationMessage *msg) -> bool + auto ApplicationDesktop::handle(db::NotificationMessage *msg) -> bool { LOG_DEBUG("DB notification handler"); assert(msg); diff --git a/module-apps/application-desktop/ApplicationDesktop.hpp b/module-apps/application-desktop/ApplicationDesktop.hpp index 4e3c9dbb4..0a58df28c 100644 --- a/module-apps/application-desktop/ApplicationDesktop.hpp +++ b/module-apps/application-desktop/ApplicationDesktop.hpp @@ -53,7 +53,7 @@ namespace app bool getPinLocked(); // if there is modem notification and there is no default SIM selected, then we need to select if when unlock is // done - bool handle(DBNotificationMessage *msg); + bool handle(db::NotificationMessage *msg); bool handle(cellular::StateChange *msg); /** * This static method will be used to lock the phone diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index 269081d8c..232d1b7ef 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -1,5 +1,6 @@ #include "ApplicationMessages.hpp" +#include "application-messages/data/SMSTextToSearch.hpp" #include "windows/MessagesMainWindow.hpp" #include "windows/NewMessage.hpp" #include "windows/OptionsMessages.hpp" @@ -39,9 +40,10 @@ namespace app } if (msgl->messageType == MessageType::DBServiceNotification) { - DBNotificationMessage *msg = dynamic_cast(msgl); + auto msg = dynamic_cast(msgl); LOG_DEBUG("Received multicast"); - if ((msg != nullptr) && (msg->baseType == DB::BaseType::SmsDB)) { + if ((msg != nullptr) && + ((msg->interface == db::Interface::Name::SMS) || (msg->interface == db::Interface::Name::SMSThread))) { this->windows[gui::name::window::thread_view]->rebuild(); this->windows[gui::name::window::main_window]->rebuild(); return std::make_shared(); @@ -55,6 +57,7 @@ namespace app handled = true; switch (resp->responseTo) { case MessageType::DBThreadGetLimitOffset: + case MessageType::DBQuery: case MessageType::DBSMSTemplateGetLimitOffset: { if (getCurrentWindow()->onDatabaseMessage(resp)) refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); @@ -190,15 +193,17 @@ namespace app meta.text = utils::localize.get("app_messages_thread_no_result"); meta.title = utils::localize.get("common_results_prefix") + query; dialog->update(meta); - switchWindow(gui::name::window::thread_search_none, nullptr); + auto data = std::make_unique(); + data->ignoreCurrentWindowOnStack = true; + switchWindow(gui::name::window::thread_search_none, std::move(data)); return true; } - bool ApplicationMessages::showSearchResults(const UTF8 &title) + bool ApplicationMessages::showSearchResults(const UTF8 &title, const UTF8 &search_text) { auto name = gui::name::window::search_results; windows[name]->setTitle(title); - switchWindow(name, nullptr); + switchWindow(name, std::make_unique(search_text)); return true; } diff --git a/module-apps/application-messages/ApplicationMessages.hpp b/module-apps/application-messages/ApplicationMessages.hpp index 341fb4203..d9a188b5c 100644 --- a/module-apps/application-messages/ApplicationMessages.hpp +++ b/module-apps/application-messages/ApplicationMessages.hpp @@ -54,7 +54,7 @@ namespace app bool removeSMS_thread(const ThreadRecord *record); /// show dialog with big search icon and text which was used for query bool searchEmpty(const std::string &query = ""); - bool showSearchResults(const UTF8 &title); + bool showSearchResults(const UTF8 &title, const UTF8 &search_text); bool sendSms(const UTF8 &number, const UTF8 &body); bool newMessageOptions(const std::string &requestingWindow, gui::Text *text); diff --git a/module-apps/application-messages/CMakeLists.txt b/module-apps/application-messages/CMakeLists.txt index 7301a8dc7..4df64ebf7 100644 --- a/module-apps/application-messages/CMakeLists.txt +++ b/module-apps/application-messages/CMakeLists.txt @@ -13,32 +13,33 @@ include_directories( ${PROJECT_NAME} target_sources( ${PROJECT_NAME} PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/ApplicationMessages.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/ThreadItem.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/SMSTemplateModel.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/SMSTemplateItem.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/Icon.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/SearchResultsItem.cpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/BaseThreadItem.cpp" + "ApplicationMessages.cpp" + "widgets/ThreadItem.cpp" + "widgets/SMSTemplateModel.cpp" + "widgets/SMSTemplateItem.cpp" + "widgets/Icon.cpp" + "widgets/SearchResultsItem.cpp" + "widgets/BaseThreadItem.cpp" - "${CMAKE_CURRENT_LIST_DIR}/models/BaseThreadRecordModel.cpp" - "${CMAKE_CURRENT_LIST_DIR}/models/ThreadModel.cpp" - "${CMAKE_CURRENT_LIST_DIR}/models/SearchResultsModel.cpp" + "models/BaseThreadRecordModel.cpp" + "models/ThreadModel.cpp" + "models/SearchResultsModel.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/MessagesMainWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/ThreadViewWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/NewMessage.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/OptionsWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/OptionsMessages.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/SearchStart.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/SMSTemplatesWindow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/windows/SearchResults.cpp" + "windows/MessagesMainWindow.cpp" + "windows/ThreadViewWindow.cpp" + "windows/NewMessage.cpp" + "windows/OptionsWindow.cpp" + "windows/OptionsMessages.cpp" + "windows/SearchStart.cpp" + "windows/SMSTemplatesWindow.cpp" + "windows/SearchResults.cpp" + + "data/SMSTextToSearch.cpp" PUBLIC - "${CMAKE_CURRENT_LIST_DIR}/ApplicationMessages.hpp" - "${CMAKE_CURRENT_LIST_DIR}/MessagesStyle.hpp" - "${CMAKE_CURRENT_LIST_DIR}/models/ThreadModel.hpp" - "${CMAKE_CURRENT_LIST_DIR}/widgets/ThreadItem.hpp" - + "ApplicationMessages.hpp" + "MessagesStyle.hpp" + "models/ThreadModel.hpp" + "widgets/ThreadItem.hpp" ) diff --git a/module-apps/application-messages/data/SMSTextToSearch.cpp b/module-apps/application-messages/data/SMSTextToSearch.cpp new file mode 100644 index 000000000..b840c152f --- /dev/null +++ b/module-apps/application-messages/data/SMSTextToSearch.cpp @@ -0,0 +1,9 @@ +#include "SMSTextToSearch.hpp" + +SMSTextToSearch::SMSTextToSearch(const std::string text_to_search) : text_to_search(text_to_search) +{} + +auto SMSTextToSearch::getTextToSearch() const -> std::string +{ + return text_to_search; +} diff --git a/module-apps/application-messages/data/SMSTextToSearch.hpp b/module-apps/application-messages/data/SMSTextToSearch.hpp new file mode 100644 index 000000000..07181b0d0 --- /dev/null +++ b/module-apps/application-messages/data/SMSTextToSearch.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +class SMSTextToSearch : public gui::SwitchData +{ + std::string text_to_search; + + public: + SMSTextToSearch(const std::string text_to_search); + [[nodiscard]] auto getTextToSearch() const -> std::string; +}; diff --git a/module-apps/application-messages/models/SearchResultsModel.cpp b/module-apps/application-messages/models/SearchResultsModel.cpp index b0cbc57f4..a77a6098a 100644 --- a/module-apps/application-messages/models/SearchResultsModel.cpp +++ b/module-apps/application-messages/models/SearchResultsModel.cpp @@ -3,6 +3,7 @@ #include "../widgets/SearchResultsItem.hpp" #include "service-db/api/DBServiceAPI.hpp" +#include namespace gui::model { @@ -26,10 +27,33 @@ namespace gui::model ret->setTimestamp(utils::time::DateTime(thread->date)); { // The only thing that differs with ThreadModel actually - here show what was found - ret->setPreview("this is preview text"); + ret->setPreview(thread->snippet); } ret->setID(index); return ret; } + void SearchResultsModel::requestRecordsCount() + {} + + void SearchResultsModel::requestRecords(uint32_t offset, uint32_t limit) + { + if (std::string(search_value).compare("") != 0) { + DBServiceAPI::GetQuery( + getApplication(), + db::Interface::Name::SMSThread, + std::make_unique(search_value, offset, max_search_items_on_screen)); + } + } + + void SearchResultsModel::setRecordsCount(uint32_t count) + { + recordsCount = count; + } + + void SearchResultsModel::setSearchValue(const UTF8 &search_value) + { + this->search_value = search_value; + } + }; // namespace gui::model diff --git a/module-apps/application-messages/models/SearchResultsModel.hpp b/module-apps/application-messages/models/SearchResultsModel.hpp index b060fe1c5..5f6792877 100644 --- a/module-apps/application-messages/models/SearchResultsModel.hpp +++ b/module-apps/application-messages/models/SearchResultsModel.hpp @@ -1,14 +1,32 @@ #pragma once #include "BaseThreadRecordModel.hpp" +#include "Style.hpp" namespace gui::model { class SearchResultsModel : public BaseThreadRecordModel { + UTF8 search_value; + /// definition of how many items we shall request from db per page : as many will fit + 1 + const unsigned int max_search_items_on_screen = + (style::window_height / style::window::messages::sms_thread_item_h) + 1; + public: SearchResultsModel(app::Application *app); gui::ListItem *getItem(int index) override; + /// resquest data for model - not needed + void requestRecordsCount() override; + /// empty, size get in requestRecords + void requestRecords(uint32_t offset, uint32_t limit) override; + /// set count in top model class - used for scroll bar + void setRecordsCount(uint32_t count); + /// set what we need to search + void setSearchValue(const UTF8 &search_value); + auto getMaxItemsOnScreen() const -> unsigned int + { + return max_search_items_on_screen; + } }; }; // namespace gui::model diff --git a/module-apps/application-messages/windows/SearchResults.cpp b/module-apps/application-messages/windows/SearchResults.cpp index f9b7411e1..a0479c62e 100644 --- a/module-apps/application-messages/windows/SearchResults.cpp +++ b/module-apps/application-messages/windows/SearchResults.cpp @@ -1,5 +1,10 @@ #include "SearchResults.hpp" -#include +#include "ThreadRecord.hpp" +#include +#include +#include "messages/DBThreadMessage.hpp" +#include "messages/QueryMessage.hpp" +#include "queries/sms/QuerySMSSearch.hpp" #include "service-db/messages/DBMessage.hpp" #include @@ -24,27 +29,59 @@ namespace gui 8, body->area().w - 2 * style::window::list_offset_default, body->area().h); - list->setProvider(model.get()); - setFocusItem(list); } void SearchResults::onBeforeShow(ShowMode mode, SwitchData *data) { - if (mode == ShowMode::GUI_SHOW_INIT || data == nullptr) { - model->clear(); - model->requestRecordsCount(); - list->clear(); - list->setElementsCount(model->getItemCount()); - setFocusItem(list); + if (mode == ShowMode::GUI_SHOW_INIT && data != nullptr) { + if (auto search_data = dynamic_cast(data)) { + if (listViewRequest(search_data->getTextToSearch()) == false) { + showEmptyResults(); + } + } } } + bool SearchResults::listViewRequest(const std::string &text) + { + if (text.length() != 0u) { + model->setSearchValue(text); + model->requestRecords(0, model->getMaxItemsOnScreen()); + list->setElementsCount(model->getItemCount()); + list->setProvider(model.get()); + setFocusItem(list); + return true; + } + return false; + } + bool SearchResults::onDatabaseMessage(sys::Message *msgl) { - auto msg = reinterpret_cast(msgl); - if (model->updateRecords(std::move(msg->records), msg->offset, msg->limit, msg->count)) - return true; - + if (auto msg = dynamic_cast(msgl)) { + if (auto response = dynamic_cast(msg->getResult())) { + return listViewUpdate(response); + } + } return false; } + + auto SearchResults::listViewUpdate(db::query::SMSSearchResult *response) -> bool + { + int count = response->getResults().size(); + auto records_data = response->getResults(); + auto records = std::make_unique>(records_data.begin(), records_data.end()); + model->updateRecords(std::move(records), 0, 3, count); + model->setRecordsCount(response->getMax()); + if (response->getMax() == 0) { + return showEmptyResults(); + } + return true; + } + + bool SearchResults::showEmptyResults() + { + auto app = dynamic_cast(application); + assert(app); + return app->searchEmpty(); + } }; // namespace gui diff --git a/module-apps/application-messages/windows/SearchResults.hpp b/module-apps/application-messages/windows/SearchResults.hpp index e09a8a521..1ed939922 100644 --- a/module-apps/application-messages/windows/SearchResults.hpp +++ b/module-apps/application-messages/windows/SearchResults.hpp @@ -3,6 +3,7 @@ #include "AppWindow.hpp" #include #include "../models/SearchResultsModel.hpp" +#include "messages/QueryMessage.hpp" namespace gui { @@ -16,6 +17,7 @@ namespace gui gui::Item *body = nullptr; gui::ListView *list = nullptr; std::unique_ptr model; + auto listViewRequest(const std::string &text) -> bool; public: SearchResults(app::Application *app); @@ -23,6 +25,9 @@ namespace gui void onBeforeShow(ShowMode mode, SwitchData *data) override; /// needed to populate db responses auto onDatabaseMessage(sys::Message *msgl) -> bool override; + auto showEmptyResults() -> bool; + /// listView update on DB notification + auto listViewUpdate(db::query::SMSSearchResult *) -> bool; }; } // namespace gui diff --git a/module-apps/application-messages/windows/SearchStart.cpp b/module-apps/application-messages/windows/SearchStart.cpp index 576fde26f..328fa6b13 100644 --- a/module-apps/application-messages/windows/SearchStart.cpp +++ b/module-apps/application-messages/windows/SearchStart.cpp @@ -18,19 +18,22 @@ namespace gui body = new gui::Item(); body->setBoundingBox(bodySize()); addWidget(body); - inputCallback = [&](Item &, const InputEvent &inputEvent) -> bool { + auto text = searchBox(this, utils::localize.get("common_search_uc"), "search"); + + inputCallback = [=](Item &, const InputEvent &inputEvent) -> bool { auto app = dynamic_cast(application); assert(app); if (inputEvent.state != InputEvent::State::keyReleasedShort) { return false; } if (inputEvent.keyCode == KeyCode::KEY_ENTER) { - app->showSearchResults(utils::localize.get("app_phonebook_search_results")); + auto search_text = text->getText(); + app->showSearchResults(utils::localize.get("common_search_results") + ": " + std::string(search_text), + search_text); } return false; }; - auto text = searchBox(this, utils::localize.get("app_phonebook_search_win_search"), "search"); setFocusItem(text); } diff --git a/module-apps/application-phonebook/windows/PhonebookErrors.cpp b/module-apps/application-phonebook/windows/PhonebookErrors.cpp index 81fa15c79..5ee896cfb 100644 --- a/module-apps/application-phonebook/windows/PhonebookErrors.cpp +++ b/module-apps/application-phonebook/windows/PhonebookErrors.cpp @@ -92,7 +92,7 @@ bool NoResults::handleSwitchData(SwitchData *data) void NoResults::setContactData() { - setTitle(utils::localize.get("app_phonebook_search_results").c_str() + std::string(":\"") + searchQuery.c_str() + + setTitle(utils::localize.get(style::strings::common::search_results) + std::string(":\"") + searchQuery + std::string("\"")); } @@ -170,7 +170,7 @@ bool ContactBlocked::handleSwitchData(SwitchData *data) void ContactBlocked::setContactData() { - setTitle(utils::localize.get("app_phonebook_search_results").c_str() + std::string(":\"") + searchQuery.c_str() + + setTitle(utils::localize.get(style::strings::common::search_results) + std::string(":\"") + searchQuery + std::string("\"")); } diff --git a/module-apps/application-phonebook/windows/PhonebookSearch.cpp b/module-apps/application-phonebook/windows/PhonebookSearch.cpp index d93545417..890b9214c 100644 --- a/module-apps/application-phonebook/windows/PhonebookSearch.cpp +++ b/module-apps/application-phonebook/windows/PhonebookSearch.cpp @@ -19,7 +19,7 @@ namespace gui setTitle(utils::localize.get("app_phonebook_title_main")); - inputField = searchBox(this, utils::localize.get("app_phonebook_search_win_search"), "search"); + inputField = searchBox(this, utils::localize.get("common_search_uc"), "search"); bottomBar->setActive(BottomBar::Side::LEFT, false); bottomBar->setActive(BottomBar::Side::CENTER, true); bottomBar->setActive(BottomBar::Side::RIGHT, true); diff --git a/module-db/CMakeLists.txt b/module-db/CMakeLists.txt index b02e8fa72..34993facc 100644 --- a/module-db/CMakeLists.txt +++ b/module-db/CMakeLists.txt @@ -5,45 +5,46 @@ project(module-db VERSION 1.0 set(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/Database/Field.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Database/QueryResult.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Database/Database.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Database/sqlite3.c - ${CMAKE_CURRENT_SOURCE_DIR}/Database/sqlite3vfs.cpp + Database/Field.cpp + Database/QueryResult.cpp + Database/Database.cpp + Database/sqlite3.c + Database/sqlite3vfs.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/ContactsDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/SmsDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/SettingsDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/AlarmsDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/NotesDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/CalllogDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Databases/CountryCodesDB.cpp + Databases/ContactsDB.cpp + Databases/SmsDB.cpp + Databases/SettingsDB.cpp + Databases/AlarmsDB.cpp + Databases/NotesDB.cpp + Databases/CalllogDB.cpp + Databases/CountryCodesDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/Table.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/SMSTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/ThreadsTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/ContactsTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/ContactsNameTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/ContactsNumberTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/ContactsRingtonesTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/ContactsAddressTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/SettingsTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/AlarmsTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/NotesTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/CalllogTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/CountryCodesTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Tables/SMSTemplateTable.cpp + Tables/Table.cpp + Tables/SMSTable.cpp + Tables/ThreadsTable.cpp + Tables/ContactsTable.cpp + Tables/ContactsNameTable.cpp + Tables/ContactsNumberTable.cpp + Tables/ContactsRingtonesTable.cpp + Tables/ContactsAddressTable.cpp + Tables/SettingsTable.cpp + Tables/AlarmsTable.cpp + Tables/NotesTable.cpp + Tables/CalllogTable.cpp + Tables/CountryCodesTable.cpp + Tables/SMSTemplateTable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/Record.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/SMSRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/ContactRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/ThreadRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/SettingsRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/AlarmsRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/NotesRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/CalllogRecord.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Interface/SMSTemplateRecord.cpp + Interface/Record.cpp + Interface/SMSRecord.cpp + Interface/ContactRecord.cpp + Interface/ThreadRecord.cpp + Interface/SettingsRecord.cpp + Interface/AlarmsRecord.cpp + Interface/NotesRecord.cpp + Interface/CalllogRecord.cpp + Interface/SMSTemplateRecord.cpp + queries/sms/QuerySMSSearch.cpp ) if(NOT ${PROJECT_TARGET} STREQUAL "TARGET_Linux") diff --git a/module-db/Common/Query.hpp b/module-db/Common/Query.hpp new file mode 100644 index 000000000..3d259068b --- /dev/null +++ b/module-db/Common/Query.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace db +{ + /// virtual query input interface + class Query + { + public: + virtual ~Query() = default; + [[nodiscard]] virtual auto debugInfo() const -> std::string = 0; + }; + + /// virtual query output (result) interface + class QueryResult + { + public: + virtual ~QueryResult() = default; + [[nodiscard]] virtual auto debugInfo() const -> std::string = 0; + }; +} // namespace db diff --git a/module-db/Interface/BaseInterface.hpp b/module-db/Interface/BaseInterface.hpp new file mode 100644 index 000000000..0ce7d83d8 --- /dev/null +++ b/module-db/Interface/BaseInterface.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include + +namespace db +{ + + class Query; + class QueryResult; + + class Interface + { + public: + virtual std::unique_ptr runQuery(const db::Query *query); + + enum class Name + { + Settings, + SMS, + SMSThread, + SMSTemplate, + Contact, + Alarms, + Notes, + Calllog, + CountryCodes + }; + }; +}; // namespace db + +constexpr const char *c_str(enum db::Interface::Name db) +{ + switch (db) { + case db::Interface::Name::Settings: + return "Settings"; + case db::Interface::Name::SMS: + return "SMS"; + case db::Interface::Name::SMSThread: + return "SMSThread"; + case db::Interface::Name::SMSTemplate: + return "SMSTemplate"; + case db::Interface::Name::Contact: + return "Contact"; + case db::Interface::Name::Alarms: + return "Alarms"; + case db::Interface::Name::Notes: + return "Notes"; + case db::Interface::Name::Calllog: + return "Callog"; + case db::Interface::Name::CountryCodes: + return "CountryCodes"; + }; + return ""; +} diff --git a/module-db/Interface/Record.cpp b/module-db/Interface/Record.cpp index e5aeb5e3b..0f701a47e 100644 --- a/module-db/Interface/Record.cpp +++ b/module-db/Interface/Record.cpp @@ -1,11 +1,13 @@ - -/* - * @file Record.cpp - * @author Mateusz Piesta (mateusz.piesta@mudita.com) - * @date 29.05.19 - * @brief - * @copyright Copyright (C) 2019 mudita.com - * @details - */ - #include "Record.hpp" +#include +#include + +namespace db +{ + + std::unique_ptr Interface::runQuery(const Query *query) + { + LOG_DEBUG("Query not handled! debugInfo: %s", query ? query->debugInfo().c_str() : "empty"); + return nullptr; + } +} // namespace db diff --git a/module-db/Interface/Record.hpp b/module-db/Interface/Record.hpp index 907481f3d..15e09948c 100644 --- a/module-db/Interface/Record.hpp +++ b/module-db/Interface/Record.hpp @@ -1,23 +1,14 @@ - -/* - * @file Record.hpp - * @author Mateusz Piesta (mateusz.piesta@mudita.com) - * @date 29.05.19 - * @brief - * @copyright Copyright (C) 2019 mudita.com - * @details - */ #pragma once -#include #include "../Database/Database.hpp" +#include "BaseInterface.hpp" -template class RecordInterface +template class RecordInterface : public db::Interface { public: - RecordInterface(){}; + RecordInterface() = default; - virtual ~RecordInterface(){}; + virtual ~RecordInterface() = default; virtual bool Add(const T &) { diff --git a/module-db/Interface/ThreadRecord.cpp b/module-db/Interface/ThreadRecord.cpp index c8398b4a2..7d925f6bb 100644 --- a/module-db/Interface/ThreadRecord.cpp +++ b/module-db/Interface/ThreadRecord.cpp @@ -10,6 +10,7 @@ #include "ThreadRecord.hpp" #include "SMSRecord.hpp" +#include "queries/sms/QuerySMSSearch.hpp" #include #include @@ -127,3 +128,17 @@ ThreadRecord ThreadRecordInterface::GetByContact(uint32_t contact_id) ThreadRecord a = ret[0]; return a; } + +std::unique_ptr ThreadRecordInterface::runQuery(const db::Query *query) +{ + if (const auto local_query = dynamic_cast(query)) { + return runQueryImpl(local_query); + } + return nullptr; +} + +std::unique_ptr ThreadRecordInterface::runQueryImpl(const db::query::SMSSearch *query) +{ + auto db_result = smsDB->threads.getBySMSQuery(query->text, query->starting_postion, query->depth); + return std::make_unique(db_result.first, db_result.second); +} diff --git a/module-db/Interface/ThreadRecord.hpp b/module-db/Interface/ThreadRecord.hpp index 1194aece1..8bee5d192 100644 --- a/module-db/Interface/ThreadRecord.hpp +++ b/module-db/Interface/ThreadRecord.hpp @@ -15,6 +15,7 @@ #include "../Databases/SmsDB.hpp" #include "../Databases/ContactsDB.hpp" #include "../Common/Common.hpp" +#include "../queries/sms/QuerySMSSearch.hpp" struct ThreadRecord { @@ -65,7 +66,14 @@ class ThreadRecordInterface : public RecordInterface runQuery(const db::Query *query) override; + private: SmsDB *smsDB; ContactsDB *contactsDB; + + /// for now implementation between Interface <-> Database + /// it would only make sense to pass Query from Inteface to multiple databases to get all data we are interested in + /// or better split it to smaller entities... this could be done with any db high level interface - left as it is + std::unique_ptr runQueryImpl(const db::query::SMSSearch *query); }; diff --git a/module-db/Tables/README.md b/module-db/Tables/README.md new file mode 100644 index 000000000..369d8b860 --- /dev/null +++ b/module-db/Tables/README.md @@ -0,0 +1,6 @@ +clunky DB abstraction layer - this could and should be replaced with any ready to go db interface library (ORM) + +please note that ORM might/would/should solve other issues with our DB usage such as: +1. migrations +2. possibly sanitization +3. request lazy evaluation diff --git a/module-db/Tables/ThreadsTable.cpp b/module-db/Tables/ThreadsTable.cpp index 31660927b..2b5544b01 100644 --- a/module-db/Tables/ThreadsTable.cpp +++ b/module-db/Tables/ThreadsTable.cpp @@ -9,6 +9,7 @@ */ #include "ThreadsTable.hpp" +#include "log/log.hpp" ThreadsTable::ThreadsTable(Database *db) : Table(db) {} @@ -81,17 +82,8 @@ ThreadsTableRow ThreadsTable::GetByID(uint32_t id) }; } -std::vector ThreadsTable::GetLimitOffset(uint32_t offset, uint32_t limit) +void fillRetQuery(std::vector &ret, const std::unique_ptr &retQuery) { - - auto retQuery = db->Query("SELECT * from threads ORDER BY date DESC LIMIT %lu OFFSET %lu;", limit, offset); - - if ((retQuery == nullptr) || (retQuery->GetRowCount() == 0)) { - return std::vector(); - } - - std::vector ret; - do { ret.push_back(ThreadsTableRow{ (*retQuery)[0].GetUInt32(), // ID @@ -103,7 +95,19 @@ std::vector ThreadsTable::GetLimitOffset(uint32_t offset, uint3 static_cast((*retQuery)[6].GetUInt32()), // type/last-dir }); } while (retQuery->NextRow()); +} +std::vector ThreadsTable::GetLimitOffset(uint32_t offset, uint32_t limit) +{ + + auto retQuery = db->Query("SELECT * from threads ORDER BY date DESC LIMIT %lu OFFSET %lu;", limit, offset); + + if ((retQuery == nullptr) || (retQuery->GetRowCount() == 0)) { + return std::vector(); + } + + std::vector ret; + fillRetQuery(ret, retQuery); return ret; } @@ -144,19 +148,7 @@ std::vector ThreadsTable::GetLimitOffsetByField(uint32_t offset } std::vector ret; - - do { - ret.push_back(ThreadsTableRow{ - (*retQuery)[0].GetUInt32(), // ID - (*retQuery)[1].GetUInt32(), // date - (*retQuery)[2].GetUInt32(), // msgCount - (*retQuery)[3].GetUInt32(), // msgRead - (*retQuery)[4].GetUInt32(), // contactID - (*retQuery)[5].GetString(), // snippet - static_cast((*retQuery)[6].GetUInt32()), // type/last-dir - }); - } while (retQuery->NextRow()); - + fillRetQuery(ret, retQuery); return ret; } @@ -181,3 +173,34 @@ uint32_t ThreadsTable::GetCountByFieldID(const char *field, uint32_t id) return uint32_t{(*queryRet)[0].GetUInt32()}; } + +std::pair> ThreadsTable::getBySMSQuery(std::string text, + uint32_t offset, + uint32_t limit) +{ + auto ret = std::pair>{0, {}}; + auto count_ret = db->Query("SELECT COUNT (*) from sms WHERE sms.body like \"%%%q%%\"", text.c_str()); + ret.first = count_ret == nullptr ? 0 : (*count_ret)[0].GetUInt32(); + if (ret.first != 0) { + auto retQuery = + db->Query("SELECT * from sms WHERE sms.body like \"%%%q%%\" ORDER BY date DESC LIMIT %lu OFFSET %lu;", + text.c_str(), + limit, + offset); + do { + ret.second.push_back(ThreadsTableRow{ + .ID = (*retQuery)[0].GetUInt32(), + .date = (*retQuery)[3].GetUInt32(), + .msgCount = 0, + .msgRead = (*retQuery)[7].GetBool(), + .contactID = (*retQuery)[2].GetUInt32(), + .snippet = (*retQuery)[6].GetString(), + .type = static_cast((*retQuery)[8].GetUInt32()), + }); + } while (retQuery->NextRow()); + } + else { + ret.second = {}; + } + return ret; +} diff --git a/module-db/Tables/ThreadsTable.hpp b/module-db/Tables/ThreadsTable.hpp index 037f7bf60..ca1101552 100644 --- a/module-db/Tables/ThreadsTable.hpp +++ b/module-db/Tables/ThreadsTable.hpp @@ -56,6 +56,9 @@ class ThreadsTable : public Table uint32_t GetCountByFieldID(const char *field, uint32_t id) override final; ThreadsTableRow getByContact(uint32_t contact_id); + /// returns: { maximum_query_depth, vector {requested amount of data which match} } + std::pair> getBySMSQuery(std::string text, uint32_t offset, uint32_t limit); + private: const char *createTableQuery = "CREATE TABLE IF NOT EXISTS threads(" "_id INTEGER PRIMARY KEY," diff --git a/module-db/queries/README.md b/module-db/queries/README.md new file mode 100644 index 000000000..1ac8b9358 --- /dev/null +++ b/module-db/queries/README.md @@ -0,0 +1,8 @@ +Virtual database query interface. + +Instead manually creating switch cases for each possible query logic, create one +virtual `query` interface and push `querying` logic to db (where it's implemented) + +* db::service accepts `GetByQuery(service, database, query)` +* it routes it to proper database on request (instead manually copying interfaces) +* db implements querying logics and returns response diff --git a/module-db/queries/sms/QuerySMSSearch.cpp b/module-db/queries/sms/QuerySMSSearch.cpp new file mode 100644 index 000000000..ecb09545f --- /dev/null +++ b/module-db/queries/sms/QuerySMSSearch.cpp @@ -0,0 +1,32 @@ +#include "QuerySMSSearch.hpp" + +namespace db::query +{ + SMSSearch::SMSSearch(std::string text_to_search, unsigned int starting_position, unsigned int depth) + : text(text_to_search), starting_postion(starting_position), depth(depth) + {} + + auto SMSSearch::debugInfo() const -> std::string + { + return "SMSSearch"; + } + + SMSSearchResult::SMSSearchResult(unsigned int results_max_depth, std::vector result_rows) + : results_max_depth(results_max_depth), results(result_rows) + {} + + auto SMSSearchResult::getMax() const -> unsigned int + { + return results_max_depth; + } + + auto SMSSearchResult::getResults() const -> std::vector + { + return results; + } + + [[nodiscard]] auto SMSSearchResult::debugInfo() const -> std::string + { + return "SMSSearchResult"; + } +} // namespace db::query diff --git a/module-db/queries/sms/QuerySMSSearch.hpp b/module-db/queries/sms/QuerySMSSearch.hpp new file mode 100644 index 000000000..2fadb5447 --- /dev/null +++ b/module-db/queries/sms/QuerySMSSearch.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include + +namespace db::query +{ + /// implements search for SMS by text + class SMSSearch : public Query + { + public: + std::string text; + unsigned int starting_postion; + unsigned int depth; + SMSSearch(std::string text_to_search, unsigned int starting_position, unsigned int depth); + + [[nodiscard]] auto debugInfo() const -> std::string override; + }; + + class SMSSearchResult : public QueryResult + { + unsigned int results_max_depth = 0; + std::vector results; + + public: + SMSSearchResult(unsigned int results_max_depth, std::vector result_rows); + [[nodiscard]] auto getMax() const -> unsigned int; + [[nodiscard]] auto getResults() const -> std::vector; + [[nodiscard]] auto debugInfo() const -> std::string override; + }; + +}; // namespace db::query diff --git a/module-db/tests/CMakeLists.txt b/module-db/tests/CMakeLists.txt index af1c60df1..f79ae296e 100644 --- a/module-db/tests/CMakeLists.txt +++ b/module-db/tests/CMakeLists.txt @@ -23,6 +23,7 @@ add_executable( ${PROJECT_NAME} EXCLUDE_FROM_ALL "${CMAKE_CURRENT_SOURCE_DIR}/SettingsRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/AlarmsRecord_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/SMSTemplateRecord_tests.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/QueryInterface.cpp" ) target_link_libraries( ${PROJECT_NAME} PRIVATE module-db ) diff --git a/module-db/tests/ContactsNameTable_tests.cpp b/module-db/tests/ContactsNameTable_tests.cpp index b15b2fa35..de1b84468 100644 --- a/module-db/tests/ContactsNameTable_tests.cpp +++ b/module-db/tests/ContactsNameTable_tests.cpp @@ -93,4 +93,4 @@ TEST_CASE("Contacts Name Table tests") REQUIRE(contactsdb.name.GetCount() == 0); Database::Deinitialize(); -} \ No newline at end of file +} diff --git a/module-db/tests/QueryInterface.cpp b/module-db/tests/QueryInterface.cpp new file mode 100644 index 000000000..7f8c73ac4 --- /dev/null +++ b/module-db/tests/QueryInterface.cpp @@ -0,0 +1,54 @@ +#include "Common/Query.hpp" +#include "Databases/ContactsDB.hpp" +#include "Databases/SmsDB.hpp" +#include "SMSRecord.hpp" +#include "ThreadRecord.hpp" +#include "catch.hpp" +#include "../Database/Database.hpp" +#include "queries/sms/QuerySMSSearch.hpp" +#include + +namespace db +{ + + class TestQuery : public Query + { + public: + [[nodiscard]] auto debugInfo() const -> std::string override + { + return "Test!"; + } + }; +} // namespace db + +TEST_CASE("Query interface") +{ + Database::Initialize(); + auto contactsDB = std::make_unique(); + auto smsDB = std::make_unique(); + auto smsInterface = std::make_unique(smsDB.get(), contactsDB.get()); + auto threadInterface = std::make_unique(smsDB.get(), contactsDB.get()); + + REQUIRE(contactsDB); + REQUIRE(smsDB); + REQUIRE(smsInterface); + + SECTION("unknown query -> no results") + { + REQUIRE(smsInterface->runQuery(std::make_unique().get()) == nullptr); + } + + auto query = std::make_unique("a", 0, 10); + + SECTION("known query, wrong interface") + { + auto result = smsInterface->runQuery(query.get()); + REQUIRE(result == nullptr); + } + + SECTION("proper result returned") + { + auto result = threadInterface->runQuery(query.get()); + REQUIRE(dynamic_cast(result.get())); + } +} diff --git a/module-gui/gui/core/BoundingBox.cpp b/module-gui/gui/core/BoundingBox.cpp index f1aef5a69..a1437861c 100644 --- a/module-gui/gui/core/BoundingBox.cpp +++ b/module-gui/gui/core/BoundingBox.cpp @@ -1,4 +1,5 @@ #include "BoundingBox.hpp" +#include #include #include diff --git a/module-gui/gui/core/Font.hpp b/module-gui/gui/core/Font.hpp index 60a7bdeaa..f96aec4d0 100644 --- a/module-gui/gui/core/Font.hpp +++ b/module-gui/gui/core/Font.hpp @@ -12,6 +12,7 @@ #include "utf8/UTF8.hpp" #include #include +#include #include #include #include diff --git a/module-gui/gui/widgets/BoxLayout.cpp b/module-gui/gui/widgets/BoxLayout.cpp index fa22f64df..e9cdd09c4 100644 --- a/module-gui/gui/widgets/BoxLayout.cpp +++ b/module-gui/gui/widgets/BoxLayout.cpp @@ -63,8 +63,10 @@ namespace gui { Rect::setSize(w, h); - for (auto it : outOfDrawAreaItems) { - it->setVisible(true); + if (children.size() != 0u) { + for (auto it : outOfDrawAreaItems) { + it->setVisible(true); + } } outOfDrawAreaItems.clear(); diff --git a/module-gui/gui/widgets/Style.hpp b/module-gui/gui/widgets/Style.hpp index 9a29811f4..f0082d35c 100644 --- a/module-gui/gui/widgets/Style.hpp +++ b/module-gui/gui/widgets/Style.hpp @@ -112,21 +112,22 @@ namespace style { namespace common { - const inline std::string open = "common_open"; - const inline std::string call = "common_call"; - const inline std::string send = "common_send"; - const inline std::string confirm = "common_confirm"; - const inline std::string select = "common_select"; - const inline std::string use = "common_use"; - const inline std::string ok = "common_ok"; - const inline std::string back = "common_back"; - const inline std::string set = "common_set"; - const inline std::string yes = "common_yes"; - const inline std::string no = "common_no"; - const inline std::string Switch = "common_switch"; - const inline std::string options = "common_options"; - const inline std::string information = "common_information"; - const inline std::string search = "common_search"; + const inline std::string open = "common_open"; + const inline std::string call = "common_call"; + const inline std::string send = "common_send"; + const inline std::string confirm = "common_confirm"; + const inline std::string select = "common_select"; + const inline std::string use = "common_use"; + const inline std::string ok = "common_ok"; + const inline std::string back = "common_back"; + const inline std::string set = "common_set"; + const inline std::string yes = "common_yes"; + const inline std::string no = "common_no"; + const inline std::string Switch = "common_switch"; + const inline std::string options = "common_options"; + const inline std::string information = "common_information"; + const inline std::string search = "common_search"; + const inline std::string search_results = "common_search_results"; // days const inline std::string Monday = "common_monday"; const inline std::string Tuesday = "common_tuesday"; diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index b7fea9ed1..1159ff366 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -577,14 +577,14 @@ sys::Message_t ServiceCellular::DataReceivedHandler(sys::DataMessage *msgl, sys: responseMsg = std::make_shared(false); } break; case MessageType::DBServiceNotification: { - DBNotificationMessage *msg = dynamic_cast(msgl); + auto msg = dynamic_cast(msgl); if (msg == nullptr) { responseMsg = std::make_shared(false); break; } LOG_DEBUG("Received multicast"); - if ((msg->baseType == DB::BaseType::SmsDB) && ((msg->notificationType == DB::NotificationType::Updated) || - (msg->notificationType == DB::NotificationType::Added))) { + if (msg->interface == db::Interface::Name::SMS && (msg->type == db::NotificationMessage::Type::Create || + msg->type == db::NotificationMessage::Type::Update)) { sendSMS(); return std::make_shared(); } diff --git a/module-services/service-cellular/api/CellularServiceAPI.hpp b/module-services/service-cellular/api/CellularServiceAPI.hpp index 160be87a1..5fd237941 100644 --- a/module-services/service-cellular/api/CellularServiceAPI.hpp +++ b/module-services/service-cellular/api/CellularServiceAPI.hpp @@ -1,14 +1,4 @@ -/* - * @file CellularServiceAPI.hpp - * @author Mateusz Piesta (mateusz.piesta@mudita.com) - * @date 09.07.19 - * @brief - * @copyright Copyright (C) 2019 mudita.com - * @details - */ - -#ifndef PUREPHONE_CELLULARSERVICEAPI_HPP -#define PUREPHONE_CELLULARSERVICEAPI_HPP +#pragma once #include "../messages/CellularMessage.hpp" #include "utf8/UTF8.hpp" @@ -57,5 +47,3 @@ namespace CellularServiceAPI bool GetScanMode(sys::Service *serv); bool GetFirmwareVersion(sys::Service *serv, std::string &response); }; // namespace CellularServiceAPI - -#endif // PUREPHONE_CELLULARSERVICEAPI_HPP diff --git a/module-services/service-db/CMakeLists.txt b/module-services/service-db/CMakeLists.txt index 78287c168..d5c6b05c0 100644 --- a/module-services/service-db/CMakeLists.txt +++ b/module-services/service-db/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources( ${PROJECT_NAME} PRIVATE "ServiceDB.cpp" "api/DBServiceAPI.cpp" + "api/DBServiceAPI_GetByQuery.cpp" "messages/DBAlarmMessage.cpp" "messages/DBCalllogMessage.cpp" @@ -18,4 +19,5 @@ target_sources( ${PROJECT_NAME} "messages/DBSMSMessage.cpp" "messages/DBSMSTemplateMessage.cpp" "messages/DBThreadMessage.cpp" + "messages/QueryMessage.cpp" ) diff --git a/module-services/service-db/ServiceDB.cpp b/module-services/service-db/ServiceDB.cpp index 8d6630bab..f37648224 100644 --- a/module-services/service-db/ServiceDB.cpp +++ b/module-services/service-db/ServiceDB.cpp @@ -28,10 +28,12 @@ #include #include