Deleted text interface.

develop
tastytea 2019-01-12 21:28:29 +01:00
parent d9065280ea
commit fd951ed502
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
5 changed files with 17 additions and 394 deletions

View File

@ -13,10 +13,8 @@ pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
# because the sqlite3 in Debian jessie doesn't come with a pkg-config module. # because the sqlite3 in Debian jessie doesn't come with a pkg-config module.
pkg_check_modules(SQLITE3 sqlite3) pkg_check_modules(SQLITE3 sqlite3)
find_package(Qt5Core CONFIG REQUIRED) find_package(Qt5Core CONFIG REQUIRED)
if(NOT WITHOUT_GUI) find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED) pkg_check_modules(LIBCONFIG REQUIRED libconfig++)
pkg_check_modules(LIBCONFIG REQUIRED libconfig++)
endif()
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
@ -44,28 +42,21 @@ configure_file (
) )
set(COMMON_LIBRARIES set(COMMON_LIBRARIES
${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs) )
# add_executable(whyblocked add_executable(whyblocked-gui
# src/interface_text.cpp src/whyblocked.cpp) src/interface_qt.cpp src/whyblocked.cpp src/xdgcfg.cpp)
# target_link_libraries(whyblocked ${COMMON_LIBRARIES} Qt5::Core) target_link_libraries(whyblocked-gui
# install(TARGETS whyblocked DESTINATION ${CMAKE_INSTALL_BINDIR}) ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp Qt5::Widgets
${LIBCONFIG_LIBRARIES} stdc++fs)
if(NOT WITHOUT_GUI) install(TARGETS whyblocked-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(whyblocked-gui install(FILES de.tastytea.Whyblocked.desktop DESTINATION
src/interface_qt.cpp src/whyblocked.cpp src/xdgcfg.cpp) ${CMAKE_INSTALL_DATAROOTDIR}/applications)
target_link_libraries(whyblocked-gui install(FILES de.tastytea.Whyblocked.appdata.xml DESTINATION
${COMMON_LIBRARIES} Qt5::Widgets ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
${LIBCONFIG_LIBRARIES} stdc++fs) install(FILES de.tastytea.Whyblocked.svg DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
install(TARGETS whyblocked-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES de.tastytea.Whyblocked.desktop DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/applications)
install(FILES de.tastytea.Whyblocked.appdata.xml DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
install(FILES de.tastytea.Whyblocked.svg DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
endif()
if(NOT WITHOUT_TRANSLATIONS) if(NOT WITHOUT_TRANSLATIONS)
add_subdirectory(translations) add_subdirectory(translations)

View File

@ -35,9 +35,9 @@ Gentoo ebuilds are available via my
* [vsqlite++](http://vsqlite.virtuosic-bytes.com/) (tested: 0.3) * [vsqlite++](http://vsqlite.virtuosic-bytes.com/) (tested: 0.3)
* [libxdg-basedir](http://repo.or.cz/w/libxdg-basedir.git) (tested: 1.2) * [libxdg-basedir](http://repo.or.cz/w/libxdg-basedir.git) (tested: 1.2)
* [qtcore](https://www.qt.io/) (tested: 5.11/5.5) * [qtcore](https://www.qt.io/) (tested: 5.11/5.5)
* [qtwidgets](https://www.qt.io/) (tested: 5.11/5.5)
* [libconfig++](https://github.com/hyperrealm/libconfig) (tested: 1.5)
* Optional * Optional
* GUI: [qtwidgets](https://www.qt.io/) (tested: 5.11/5.5)
* GUI: [libconfig++](https://github.com/hyperrealm/libconfig) (tested: 1.5)
* Translations: [lupdate & lrelease](http://doc.qt.io/qt-5/linguist-manager.html) (tested: 5.11/5.5) * Translations: [lupdate & lrelease](http://doc.qt.io/qt-5/linguist-manager.html) (tested: 5.11/5.5)
#### Get sourcecode #### Get sourcecode
@ -63,7 +63,6 @@ make install
cmake options: cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build * `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITHOUT_GUI=YES` to not build GUI
* `-DWITHOUT_TRANSLATIONS=YES` to not compile translations * `-DWITHOUT_TRANSLATIONS=YES` to not compile translations
* One of: * One of:
* `-DWITH_DEB=YES` if you want to be able to generate a deb-package * `-DWITH_DEB=YES` if you want to be able to generate a deb-package

View File

@ -1,322 +0,0 @@
/* 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 <iostream>
#include <QCoreApplication>
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include "version.hpp"
#include "whyblocked.hpp"
#include "interface_text.hpp"
using std::cout;
using std::cerr;
using std::cin;
// Allow cout to output QStrings
std::ostream &operator <<(std::ostream &stream, const QString &str)
{
stream << str.toStdString();
return stream;
}
const string Text::get_answer(const QString &question)
{
string answer;
cout << question << ": ";
std::getline(cin, answer, '\n');
return answer;
}
bool Text::askblocked()
{
while (true)
{
const string blocked = get_answer(tr("Blocked or silenced?") +
" [b/s]");
if (blocked[0] == 'b' || blocked[0] == 'B')
{
return true;
}
else if (blocked[0] == 's' || blocked[0] == 'S')
{
return false;
}
}
}
void Text::askrecipes(const string &user)
{
while (true)
{
const string receipt_yn = get_answer(tr("Add receipt? [y/n]"));
if (receipt_yn[0] == tr("y")[0] || receipt_yn[0] == tr("Y")[0])
{
const string receipt = get_answer(tr("Receipt"));
if (database::add_receipt(user, receipt))
{
cout << tr("Receipt added.") << '\n';
}
}
else if (receipt_yn[0] == tr("n")[0] || receipt_yn[0] == tr("N")[0])
{
break;
}
else
{
continue;
}
}
}
void Text::add()
{
const string user = get_answer(tr("User or instance"));
int blocked;
if (askblocked())
{
blocked = 1;
}
else
{
blocked = 0;
}
const string reason = get_answer(tr("Reason"));
if (database::add_block(user, blocked, reason))
{
cout << user << " " << tr("added.") << '\n';
}
askrecipes(user);
}
void Text::edit()
{
result_details olddata;
const string olduser = get_answer(tr("User or instance"));
if (database::details(olduser, olddata))
{
cout << tr("A blank line keeps the former value.") << '\n';
string newuser = get_answer(tr("Change user or instance to"));
if (newuser.empty())
{
newuser = olduser;
}
int blocked;
if (askblocked())
{
blocked = 1;
}
else
{
blocked = 0;
}
cout << tr("Old reason was:") << " " << std::get<1>(olddata) << '\n';
string newreason = get_answer(tr("Change reason to"));
if (newreason.empty())
{
newreason = std::get<1>(olddata);
}
std::vector<string> newreceipts;
for (const string &oldreceipt : std::get<2>(olddata))
{
cout << tr("Old receipt was:") << " " << oldreceipt << '\n';
string newreceipt = get_answer(tr("Change receipt to"));
if (newreceipt.empty())
{
newreceipt = oldreceipt;
}
newreceipts.push_back(newreceipt);
}
if (database::remove(olduser))
{
database::add_block(newuser, blocked, newreason);
if (!newreceipts.empty())
{
for (const string &newreceipt : newreceipts)
{
database::add_receipt(newuser, newreceipt);
}
}
askrecipes(newuser);
}
else
{
cerr << tr("Could not remove") << " " << olduser << ".\n";
}
}
}
void Text::remove()
{
const string user = get_answer(tr("User or instance"));
if (database::remove(user))
{
cout << user << " " << tr("removed.") << '\n';
}
}
void Text::view()
{
result_view result;
if (database::view(result))
{
for (const std::tuple<string, int, string> &line : result)
{
if (std::get<1>(line) == 1)
{
cout << tr(" Blocked:") << " ";
}
else
{
cout << tr("Silenced:") << " ";
}
cout << std::get<0>(line) << " " << tr("because:") << " ";
cout << std::get<2>(line) << '\n';
}
}
}
void Text::details()
{
const string user = get_answer(tr("User or instance"));
{
result_details result;
if (database::details(user, result))
{
cout << user << " " << tr("is") << " ";
if (std::get<0>(result) == 1)
{
cout << tr("blocked, because:") << " ";
}
else if (std::get<0>(result) == 0)
{
cout << tr("silenced, because:") << " ";
}
cout << std::get<1>(result) << '\n';
if (!std::get<2>(result).empty())
{
cout << tr("Receipts:") << '\n';
for (const string &url : std::get<2>(result))
{
cout << " " << url << '\n';
}
}
}
}
}
void Text::help()
{
cout << tr(
"Type add, edit, remove, view or details. Or just the first letter.")
<< '\n';
cout << tr(
"Type help or h to show this help. Type quit or q to quit the program.")
<< '\n';
}
Text::Text(QObject *parent) : QObject(parent)
{
bool keeprunning = true;
cout << tr("This is Whyblocked") << " " << global::version << ".\n";
help();
while (keeprunning)
{
string answer = get_answer("");
switch (answer[0])
{
case 'a':
case 'A':
{
add();
break;
}
case 'e':
case 'E':
{
edit();
break;
}
case 'r':
case 'R':
{
remove();
break;
}
case 'v':
case 'V':
{
view();
break;
}
case 'd':
case 'D':
{
details();
break;
}
case 'h':
case 'H':
{
help();
break;
}
case 'q':
case 'Q':
{
keeprunning = false;
break;
}
default:
{
cout << tr("Response not understood.") << '\n';
}
}
}
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("Whyblocked");
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator appTranslator;
appTranslator.load("whyblocked_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&appTranslator);
Text t(&app);
return 0;
}

View File

@ -1,44 +0,0 @@
/* 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_TEXT_HPP
#define INTERFACE_TEXT_HPP
#include <string>
#include <QtCore>
using std::string;
class Text : public QObject
{
Q_OBJECT
public:
explicit Text(QObject *parent = nullptr);
private:
const string get_answer(const QString &question);
bool askblocked();
void askrecipes(const string &user);
void add();
void edit();
void remove();
void view();
void details();
void help();
};
#endif // INTERFACE_TEXT_HPP

View File

@ -7,7 +7,6 @@ qt5_create_translation(QM_FILES ${TS_SRC_FILES} ${TS_FILES}
OPTIONS -no-obsolete) OPTIONS -no-obsolete)
# qt5_add_translation(QM_FILES ${TS_FILES}) # qt5_add_translation(QM_FILES ${TS_FILES})
add_custom_target(translations ALL DEPENDS ${QM_FILES}) add_custom_target(translations ALL DEPENDS ${QM_FILES})
# add_dependencies(${CMAKE_PROJECT_NAME} translations)
add_dependencies(${CMAKE_PROJECT_NAME}-gui translations) add_dependencies(${CMAKE_PROJECT_NAME}-gui translations)
install(FILES ${QM_FILES} DESTINATION install(FILES ${QM_FILES} DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/qt5/translations) ${CMAKE_INSTALL_DATAROOTDIR}/qt5/translations)