diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d543633 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "xdgcfg"] + path = xdgcfg + url = https://schlomp.space/tastytea/xdgcfg.git diff --git a/CMakeLists.txt b/CMakeLists.txt index e7ec49f..ca91e6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.6) project (whyblocked - VERSION 0.11.1 + VERSION 0.12.0 LANGUAGES CXX ) @@ -15,6 +15,7 @@ pkg_check_modules(SQLITE3 sqlite3) find_package(Qt5Core CONFIG REQUIRED) if(NOT WITHOUT_GUI) find_package(Qt5Widgets CONFIG REQUIRED) + pkg_check_modules(LIBCONFIG REQUIRED libconfig++) endif() set(CMAKE_CXX_STANDARD 14) @@ -29,9 +30,11 @@ set(CMAKE_AUTOUIC ON) include_directories(${PROJECT_BINARY_DIR}) include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS}) include_directories(${SQLITE3_INCLUDE_DIRS}) +include_directories(${LIBCONFIG_INCLUDE_DIRS}) link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS}) link_directories(${SQLITE3_LIBRARY_DIRS}) +link_directories(${LIBCONFIG_LIBRARY_DIRS}) # Write version in header configure_file ( @@ -42,13 +45,17 @@ configure_file ( set(COMMON_LIBRARIES ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs) -add_executable(whyblocked src/interface_text.cpp src/whyblocked.cpp) +add_executable(whyblocked + src/interface_text.cpp src/whyblocked.cpp) target_link_libraries(whyblocked ${COMMON_LIBRARIES} Qt5::Core) install(TARGETS whyblocked DESTINATION ${CMAKE_INSTALL_BINDIR}) if(NOT WITHOUT_GUI) - add_executable(whyblocked-gui src/interface_qt.cpp src/whyblocked.cpp) - target_link_libraries(whyblocked-gui ${COMMON_LIBRARIES} Qt5::Widgets) + add_executable(whyblocked-gui + src/interface_qt.cpp src/whyblocked.cpp src/xdgcfg.cpp) + target_link_libraries(whyblocked-gui + ${COMMON_LIBRARIES} Qt5::Widgets + ${LIBCONFIG_LIBRARIES} stdc++fs) install(TARGETS whyblocked-gui DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES de.tastytea.Whyblocked.desktop DESTINATION diff --git a/src/interface_qt.cpp b/src/interface_qt.cpp index c99a8d3..b75d894 100644 --- a/src/interface_qt.cpp +++ b/src/interface_qt.cpp @@ -18,22 +18,136 @@ #include #include #include +#include #include #include #include +#include #include "version.hpp" #include "whyblocked.hpp" #include "interface_qt.hpp" -MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent) +MainWindow::MainWindow(QMainWindow *parent) +: QMainWindow(parent) +, _config("whyblocked.cfg") +, _headersize({ 250, 125, 125 }) { setupUi(this); _model = new QStandardItemModel; tableview->setModel(_model); + + if (_config.read() == 0) + { + libconfig::Setting &root = _config.get_cfg().getRoot(); + string key; + + key = "size"; + if (root.exists(key) && root[key.c_str()].isArray()) + { + this->resize(root[key.c_str()][0], root[key.c_str()][1]); + } + + key = "toolbar_position"; + if (root.exists(key)) + { + const string value = root[key.c_str()].c_str(); + if (value == "top") + { + this->removeToolBar(toolbar); + this->addToolBar(Qt::TopToolBarArea, toolbar); + } + else if (value == "right") + { + this->removeToolBar(toolbar); + this->addToolBar(Qt::RightToolBarArea, toolbar); + } + else if (value == "bottom") + { + this->removeToolBar(toolbar); + this->addToolBar(Qt::BottomToolBarArea, toolbar); + } + else if (value == "left") + { + this->removeToolBar(toolbar); + this->addToolBar(Qt::LeftToolBarArea, toolbar); + } + } + + key = "toolbar_visible"; + if (root.exists(key)) + { + toolbar->setVisible(root[key.c_str()]); + } + + key = "table_headers"; + if (root.exists(key) && root[key.c_str()].isArray()) + { + const libconfig::Setting &value = root[key.c_str()]; + _headersize = { value[0], value[1], value[2] }; + } + } + populate_tableview(); } +MainWindow::~MainWindow() +{ + libconfig::Setting &root = _config.get_cfg().getRoot(); + // We can't add an element that already exists, so we delete it beforehand. + for (const string &key : + { "size", "toolbar_position", "toolbar_visible", "table_headers" }) + { + if (root.exists(key)) + { + root.remove(key); + } + } + + libconfig::Setting &size = root.add("size", libconfig::Setting::TypeArray); + size.add(libconfig::Setting::TypeInt) = this->width(); + size.add(libconfig::Setting::TypeInt) = this->height(); + + libconfig::Setting &pos = root.add("toolbar_position", + libconfig::Setting::TypeString); + if (toolbar->orientation() == Qt::Orientation::Horizontal) + { + if (toolbar-> geometry().top() < 100) + { + pos = "top"; + } + else + { + pos = "bottom"; + } + } + else + { + if (toolbar->geometry().left() == 0) + { + pos = "left"; + } + else + { + pos = "right"; + } + } + + root.add("toolbar_visible", libconfig::Setting::TypeBoolean) + = !toolbar->isHidden(); + + libconfig::Setting &headers = root.add("table_headers", + libconfig::Setting::TypeArray); + headers.add(libconfig::Setting::TypeInt) = + tableview->horizontalHeader()->sectionSize(0); + headers.add(libconfig::Setting::TypeInt) = + tableview->horizontalHeader()->sectionSize(1); + headers.add(libconfig::Setting::TypeInt) = + tableview->horizontalHeader()->sectionSize(2); + + _config.write(); +} + void MainWindow::populate_tableview() { _model->clear(); @@ -43,7 +157,9 @@ void MainWindow::populate_tableview() tr("Blocked/Silenced"), tr("Reason") }); - tableview->horizontalHeader()->resizeSection(0, 250); + tableview->horizontalHeader()->resizeSection(0, _headersize[0]); + tableview->horizontalHeader()->resizeSection(1, _headersize[1]); + tableview->horizontalHeader()->resizeSection(2, _headersize[2]); result_view result; if (database::view(result)) diff --git a/src/interface_qt.hpp b/src/interface_qt.hpp index 9dd69ca..2852856 100644 --- a/src/interface_qt.hpp +++ b/src/interface_qt.hpp @@ -18,10 +18,13 @@ #define INTERFACE_QT_HPP #include +#include +#include #include #include #include #include +#include "xdgcfg.hpp" #include "ui_whyblocked.h" #include "ui_whyblocked_add.h" @@ -41,6 +44,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow public: explicit MainWindow(QMainWindow *parent = nullptr); + ~MainWindow(); void add_row(const QString &user, const int &blocked, const QString &reason); @@ -53,6 +57,8 @@ private: void dropEvent(QDropEvent *event); QStandardItemModel *_model; + xdgcfg _config; + std::array _headersize; private slots: void add(); diff --git a/src/whyblocked.ui b/src/whyblocked.ui index c6e545c..dc94a4d 100644 --- a/src/whyblocked.ui +++ b/src/whyblocked.ui @@ -100,6 +100,9 @@ Toolbar + + false + TopToolBarArea diff --git a/src/xdgcfg.cpp b/src/xdgcfg.cpp new file mode 120000 index 0000000..0f27a45 --- /dev/null +++ b/src/xdgcfg.cpp @@ -0,0 +1 @@ +../xdgcfg/src/xdgcfg.cpp \ No newline at end of file diff --git a/src/xdgcfg.hpp b/src/xdgcfg.hpp new file mode 120000 index 0000000..f1851a8 --- /dev/null +++ b/src/xdgcfg.hpp @@ -0,0 +1 @@ +../xdgcfg/src/xdgcfg.hpp \ No newline at end of file diff --git a/translations/whyblocked_de.ts b/translations/whyblocked_de.ts index 1b5faee..c74b43a 100644 --- a/translations/whyblocked_de.ts +++ b/translations/whyblocked_de.ts @@ -69,12 +69,12 @@ - + Insert receipt here. Beleg hier einfügen. - + Added %1 to database. %1 zur Datenbank hinzugefügt. @@ -102,158 +102,158 @@ Werkzeugleiste - + &Database &Datenbank - + &Help &Hilfe - + &Add &Hinzufügen - + Add user or instance Benutzer oder Instanz hinzufügen - + Ctrl+N - + Re&move Ent&fernen - + Remove user or instance Benutzer oder Instanz entfernen - + Del - + &About &Über - + About this application Über dieses Programm - + &Reload Neu &laden - + Reload database Datenbank neu laden - + Ctrl+R - + &Quit &Beenden - + Quit application Programm beenden - + Ctrl+Q - + &Edit B&earbeiten - - + + Edit entry Eintrag bearbeiten - + User/Instance Benutzer/Instanz - + Blocked/Silenced Blockiert/Gedämpft - + Reason Begründung - + Database loaded. Datenbank geladen. - + blocked blockiert - + silenced gedämpft - + Invalid selection Ungültige Auswahl - + Please select only 1 entry to edit. Bitte nur 1 Eintrag zum bearbeiten auswählen. - + Removed %1 from database. %1 aus der Datenbank gelöscht. - + Select data to remove. Wähle Daten zum löschen aus. - + About Whyblocked Über Whyblocked - + <p><b>Whyblocked</b> %1</p><p>Reminds you why you blocked someone.</p><p>Sourcecode: <a href="https://schlomp.space/tastytea/whyblocked">https://schlomp.space/tastytea/whyblocked</a></p><p><small>Copyright © 2018 <a href="mailto:tastytea@tastytea.de">tastytea</a>.<br>Licence GPLv3: <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPL version 3</a>.<br>This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.</small></p> <p><b>Whyblocked</b> %1</p><p>Erinnert dich, warum du jemanden blockiertest.</p><p>Quelltext: <a href="https://schlomp.space/tastytea/whyblocked">https://schlomp.space/tastytea/whyblocked</a></p><p><small>Copyright © 2018 <a href="mailto:tastytea@tastytea.de">tastytea</a>.<br>Lizenz GPLv3: <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPL version 3</a>.<br>Für dieses Programm besteht KEINERLEI GARANTIE. Dies ist freie Software, die Sie unter bestimmten Bedingungen weitergeben dürfen.</small></p> - + Receipts: Belege: diff --git a/translations/whyblocked_en.ts b/translations/whyblocked_en.ts index fab4e38..9ef61b2 100644 --- a/translations/whyblocked_en.ts +++ b/translations/whyblocked_en.ts @@ -69,12 +69,12 @@ - + Insert receipt here. - + Added %1 to database. @@ -102,158 +102,158 @@ - + &Database - + &Help - + &Add - + Add user or instance - + Ctrl+N - + Re&move - + Remove user or instance - + Del - + &About - + About this application - + &Reload - + Reload database - + Ctrl+R - + &Quit - + Quit application - + Ctrl+Q - + &Edit - - + + Edit entry - + User/Instance - + Blocked/Silenced - + Reason - + Database loaded. - + blocked - + silenced - + Invalid selection - + Please select only 1 entry to edit. - + Removed %1 from database. - + Select data to remove. - + About Whyblocked - + <p><b>Whyblocked</b> %1</p><p>Reminds you why you blocked someone.</p><p>Sourcecode: <a href="https://schlomp.space/tastytea/whyblocked">https://schlomp.space/tastytea/whyblocked</a></p><p><small>Copyright © 2018 <a href="mailto:tastytea@tastytea.de">tastytea</a>.<br>Licence GPLv3: <a href="https://www.gnu.org/licenses/gpl-3.0.html">GNU GPL version 3</a>.<br>This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.</small></p> - + Receipts: diff --git a/xdgcfg b/xdgcfg new file mode 160000 index 0000000..6c0976b --- /dev/null +++ b/xdgcfg @@ -0,0 +1 @@ +Subproject commit 6c0976baa74f959ed3218af56e56ff58202a5a05