From ad308f3dd53857c9c29fb426a135601af3f8a6f4 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 6 Oct 2018 21:33:02 +0200 Subject: [PATCH] Rudimentary Qt interface --- CMakeLists.txt | 12 +++- src/interface_qt.cpp | 105 +++++++++++++++++++++++++++++ src/interface_qt.hpp | 41 ++++++++++++ src/interface_text.cpp | 6 +- src/whyblocked.cpp | 10 --- src/whyblocked.hpp | 6 -- src/whyblocked.ui | 106 +++++++++++++++++++++++++++++ src/whyblocked_add.ui | 148 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 413 insertions(+), 21 deletions(-) create mode 100644 src/interface_qt.cpp create mode 100644 src/interface_qt.hpp create mode 100644 src/whyblocked.ui create mode 100644 src/whyblocked_add.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index bbb2455..04a95a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ project (whyblocked include(GNUInstallDirs) find_package(PkgConfig REQUIRED) pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir) +find_package(Qt5Widgets CONFIG REQUIRED) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -14,6 +15,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -g -Og") +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(${PROJECT_BINARY_DIR}) @@ -27,12 +31,16 @@ configure_file ( "${PROJECT_BINARY_DIR}/version.hpp" ) -file(GLOB sources src/*.cpp) -add_executable(whyblocked ${sources}) +add_executable(whyblocked src/interface_text.cpp src/whyblocked.cpp) target_link_libraries(whyblocked ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs) install(TARGETS whyblocked DESTINATION ${CMAKE_INSTALL_BINDIR}) +add_executable(whyblocked-gui src/interface_qt.cpp src/whyblocked.cpp) +target_link_libraries(whyblocked-gui + ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs Qt5::Widgets) +install(TARGETS whyblocked-gui DESTINATION ${CMAKE_INSTALL_BINDIR}) + # Packages set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME}) diff --git a/src/interface_qt.cpp b/src/interface_qt.cpp new file mode 100644 index 0000000..257e975 --- /dev/null +++ b/src/interface_qt.cpp @@ -0,0 +1,105 @@ +/* This file is part of whyblocked. + * Copyright © 2018 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "whyblocked.hpp" +#include "interface_qt.hpp" + +MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent) +{ + setupUi(this); + statusBar()->showMessage(tr("Ready")); + + QStandardItemModel *model = new QStandardItemModel; + tableview->setModel(model); + populate_tableview(*model); + model->setHeaderData(0, Qt::Horizontal, tr("User/Instance")); + model->setHeaderData(1, Qt::Horizontal, tr("Blocked/Silenced?")); + model->setHeaderData(2, Qt::Horizontal, tr("Reason")); + tableview->horizontalHeader()->resizeSection(0, 300); + tableview->setSelectionBehavior(QAbstractItemView::SelectRows); + + + connect(action_add, &QAction::triggered, this, &MainWindow::add); + connect(action_remove, &QAction::triggered, this, &MainWindow::remove); + connect(action_about, &QAction::triggered, this, &MainWindow::about); +} + +void MainWindow::populate_tableview(QStandardItemModel &model) +{ + model.clear(); + result_view result; + if (view(result)) + { + for (const std::tuple &line : result) + { + QList items; + items.append(new QStandardItem(QString::fromStdString((std::get<0>(line))))); + if (std::get<1>(line) == 1) + { + items.append(new QStandardItem(QString(tr("blocked")))); + } + else + { + items.append(new QStandardItem(QString(tr("silenced")))); + } + items.append(new QStandardItem(QString::fromStdString((std::get<2>(line))))); + model.appendRow(items); + } + } +} + +void MainWindow::add() +{ + QDialog *dialog_add = new QDialog; + Ui::DialogAdd ui; + ui.setupUi(dialog_add); + + if (dialog_add->exec() == 1) + { + statusBar()->showMessage(tr("Added nothing. :-P")); + } +} + +void MainWindow::remove() +{ + statusBar()->showMessage(tr("Removed nothing. :-P")); +} + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About whyblocked"), + tr("whyblocked reminds you why you blocked someone.

" + "Copyright © 2018 tastytea.
" + "Licence GPLv3: " + "GNU GPL version 3.
" + "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" + "and you are welcome to redistribute it under certain conditions.

" + "Sourcecode: " + "https://schlomp.space/tastytea/whyblocked")); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QCoreApplication::setApplicationName("whyblocked"); + + MainWindow win; + win.show(); + + return app.exec(); +} diff --git a/src/interface_qt.hpp b/src/interface_qt.hpp new file mode 100644 index 0000000..b29849a --- /dev/null +++ b/src/interface_qt.hpp @@ -0,0 +1,41 @@ +/* This file is part of whyblocked. + * Copyright © 2018 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef INTERFACE_QT_HPP +#define INTERFACE_QT_HPP + +#include +#include +#include "ui_whyblocked.h" +#include "ui_whyblocked_add.h" + +class MainWindow : public QMainWindow, private Ui::MainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QMainWindow *parent = nullptr); + +private slots: + void add(); + void remove(); + void about(); + +private: + void populate_tableview(QStandardItemModel &model); +}; + +#endif // INTERFACE_QT_HPP diff --git a/src/interface_text.cpp b/src/interface_text.cpp index f295879..86c8907 100644 --- a/src/interface_text.cpp +++ b/src/interface_text.cpp @@ -22,13 +22,13 @@ using std::cout; using std::cerr; using std::cin; -const void whyblocked_text::print_help() +const void print_help() { cout << "Type add, remove, view or details. Or just the first letter.\n"; cout << "Type help or h to show this help. Type quit or q to quit the program.\n"; } -const bool whyblocked_text::start() +int main(int argc, char *argv[]) { bool keeprunning = true; @@ -180,5 +180,5 @@ const bool whyblocked_text::start() } } - return true; + return 0; } diff --git a/src/whyblocked.cpp b/src/whyblocked.cpp index f78ed17..f2d489d 100644 --- a/src/whyblocked.cpp +++ b/src/whyblocked.cpp @@ -175,13 +175,3 @@ const bool details(const string &user, result_details &result) return true; } - -int main(int argc, char *argv[]) -{ - if (!whyblocked_text::start()) - { - return 1; - } - - return 0; -} diff --git a/src/whyblocked.hpp b/src/whyblocked.hpp index c677b9b..2bdefd2 100644 --- a/src/whyblocked.hpp +++ b/src/whyblocked.hpp @@ -32,10 +32,4 @@ const bool remove(const string &user); const bool view(result_view &result); const bool details(const string &user, result_details &result); -namespace whyblocked_text -{ - const void print_help(); - const bool start(); -} - #endif // WHYBLOCKED_HPP diff --git a/src/whyblocked.ui b/src/whyblocked.ui new file mode 100644 index 0000000..0fccb9f --- /dev/null +++ b/src/whyblocked.ui @@ -0,0 +1,106 @@ + + + MainWindow + + + + 0 + 0 + 600 + 600 + + + + MainWindow + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + 100 + + + true + + + true + + + + + + + + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + + + + + add + + + Add user or instance + + + Ctrl+N + + + + + + + + remove + + + Remove user or instance + + + Ctrl+Del + + + + + + + + about + + + About this application + + + + + + diff --git a/src/whyblocked_add.ui b/src/whyblocked_add.ui new file mode 100644 index 0000000..192b521 --- /dev/null +++ b/src/whyblocked_add.ui @@ -0,0 +1,148 @@ + + + DialogAdd + + + + 0 + 0 + 300 + 170 + + + + Dialog + + + + + + + + User/Instance + + + text_user + + + + + + + true + + + + 0 + 0 + + + + Blocked + + + true + + + + + + + + + + + 0 + 0 + + + + Blocked/Silenced + + + radio_blocked + + + + + + + + 0 + 0 + + + + Silenced + + + + + + + Reason + + + text_reason + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + text_user + radio_blocked + radio_silcenced + text_reason + + + + + buttonBox + accepted() + DialogAdd + accept() + + + 227 + 147 + + + 157 + 169 + + + + + buttonBox + rejected() + DialogAdd + reject() + + + 290 + 153 + + + 286 + 169 + + + + +