Rudimentary Qt interface

develop
tastytea 2018-10-06 21:33:02 +02:00
parent 08ff4d628b
commit ad308f3dd5
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
8 changed files with 413 additions and 21 deletions

View File

@ -7,6 +7,7 @@ project (whyblocked
include(GNUInstallDirs) include(GNUInstallDirs)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir) pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
find_package(Qt5Widgets CONFIG REQUIRED)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) 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_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_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR}) include_directories(${PROJECT_BINARY_DIR})
@ -27,12 +31,16 @@ configure_file (
"${PROJECT_BINARY_DIR}/version.hpp" "${PROJECT_BINARY_DIR}/version.hpp"
) )
file(GLOB sources src/*.cpp) add_executable(whyblocked src/interface_text.cpp src/whyblocked.cpp)
add_executable(whyblocked ${sources})
target_link_libraries(whyblocked target_link_libraries(whyblocked
${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs) ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs)
install(TARGETS whyblocked DESTINATION ${CMAKE_INSTALL_BINDIR}) 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 # Packages
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME}) set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})

105
src/interface_qt.cpp Normal file
View File

@ -0,0 +1,105 @@
/* This file is part of whyblocked.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <QMessageBox>
#include <QDebug>
#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<string, int, string> &line : result)
{
QList<QStandardItem*> 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("<b>whyblocked</b> reminds you why you blocked someone.<br><br>"
"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,\n"
"and you are welcome to redistribute it under certain conditions.<br><br>"
"Sourcecode: <a href=\"https://schlomp.space/tastytea/whyblocked\">"
"https://schlomp.space/tastytea/whyblocked</a>"));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::setApplicationName("whyblocked");
MainWindow win;
win.show();
return app.exec();
}

41
src/interface_qt.hpp Normal file
View File

@ -0,0 +1,41 @@
/* This file is part of whyblocked.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef INTERFACE_QT_HPP
#define INTERFACE_QT_HPP
#include <QMainWindow>
#include <QStandardItemModel>
#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

View File

@ -22,13 +22,13 @@ using std::cout;
using std::cerr; using std::cerr;
using std::cin; 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 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"; 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; bool keeprunning = true;
@ -180,5 +180,5 @@ const bool whyblocked_text::start()
} }
} }
return true; return 0;
} }

View File

@ -175,13 +175,3 @@ const bool details(const string &user, result_details &result)
return true; return true;
} }
int main(int argc, char *argv[])
{
if (!whyblocked_text::start())
{
return 1;
}
return 0;
}

View File

@ -32,10 +32,4 @@ const bool remove(const string &user);
const bool view(result_view &result); const bool view(result_view &result);
const bool details(const string &user, result_details &result); const bool details(const string &user, result_details &result);
namespace whyblocked_text
{
const void print_help();
const bool start();
}
#endif // WHYBLOCKED_HPP #endif // WHYBLOCKED_HPP

106
src/whyblocked.ui Normal file
View File

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="locale">
<locale language="English" country="UnitedKingdom"/>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="tableview">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>100</number>
</attribute>
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="label_receipts">
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolbar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_add"/>
<addaction name="action_remove"/>
<addaction name="action_about"/>
</widget>
<action name="action_add">
<property name="icon">
<iconset theme="add"/>
</property>
<property name="text">
<string>add</string>
</property>
<property name="toolTip">
<string>Add user or instance</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="action_remove">
<property name="icon">
<iconset theme="remove"/>
</property>
<property name="text">
<string>remove</string>
</property>
<property name="toolTip">
<string>Remove user or instance</string>
</property>
<property name="shortcut">
<string>Ctrl+Del</string>
</property>
</action>
<action name="action_about">
<property name="icon">
<iconset theme="info"/>
</property>
<property name="text">
<string>about</string>
</property>
<property name="toolTip">
<string>About this application</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

148
src/whyblocked_add.ui Normal file
View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogAdd</class>
<widget class="QDialog" name="DialogAdd">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>170</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_user">
<property name="text">
<string>User/Instance</string>
</property>
<property name="buddy">
<cstring>text_user</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="radio_blocked">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Blocked</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="text_user"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_blocked">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Blocked/Silenced</string>
</property>
<property name="buddy">
<cstring>radio_blocked</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="radio_silcenced">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Silenced</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_reason">
<property name="text">
<string>Reason</string>
</property>
<property name="buddy">
<cstring>text_reason</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="text_reason"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>text_user</tabstop>
<tabstop>radio_blocked</tabstop>
<tabstop>radio_silcenced</tabstop>
<tabstop>text_reason</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogAdd</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>227</x>
<y>147</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>169</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogAdd</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>290</x>
<y>153</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>169</y>
</hint>
</hints>
</connection>
</connections>
</ui>