diff --git a/CMakeLists.txt b/CMakeLists.txt index 310550e..10b857a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,13 @@ cmake_minimum_required (VERSION 3.6) project (whyblocked - VERSION 0.9.0 + VERSION 0.10.0 LANGUAGES CXX ) include(GNUInstallDirs) find_package(PkgConfig REQUIRED) pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir) +find_package(Qt5Core CONFIG REQUIRED) if(NOT WITHOUT_GUI) find_package(Qt5Widgets CONFIG REQUIRED) endif() @@ -37,13 +38,14 @@ configure_file ( if(Qt5_LRELEASE_EXECUTABLE) file(GLOB TS_FILES "translations/*.ts") file(GLOB TS_SRC_FILES "src/*") - qt5_create_translation(QM_FILES ${TS_SRC_FILES} ${TS_FILES} OPTIONS -no-obsolete) + qt5_create_translation(QM_FILES ${TS_SRC_FILES} ${TS_FILES} + OPTIONS -no-obsolete) qt5_add_translation(QM_FILES ${TS_FILES}) endif() add_executable(whyblocked src/interface_text.cpp src/whyblocked.cpp) target_link_libraries(whyblocked - ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs) + ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs Qt5::Core) install(TARGETS whyblocked DESTINATION ${CMAKE_INSTALL_BINDIR}) if(NOT WITHOUT_GUI) diff --git a/README.md b/README.md index 3f4d211..1db6172 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Gentoo ebuilds are available via my * [cmake](https://cmake.org/) (at least 3.6) * [vsqlite++](http://vsqlite.virtuosic-bytes.com/) (tested: 0.3.13) * [libxdg-basedir](http://repo.or.cz/w/libxdg-basedir.git) (tested: 1.2) +* [qtcore](https://www.qt.io/) (tested: 5.11/5.7) * [qtwidgets](https://www.qt.io/) (tested: 5.11/5.7) #### Get sourcecode diff --git a/src/interface_text.cpp b/src/interface_text.cpp index c738cf2..bc868d2 100644 --- a/src/interface_text.cpp +++ b/src/interface_text.cpp @@ -15,14 +15,26 @@ */ #include +#include +#include +#include +#include #include "version.hpp" #include "whyblocked.hpp" +#include "interface_text.hpp" using std::cout; using std::cerr; using std::cin; -const string get_answer(const string &question) +// 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; @@ -32,37 +44,37 @@ const string get_answer(const string &question) return answer; } -const bool askblocked() +const bool Text::askblocked() { while (true) { - const string blocked = get_answer("Blocked(b) or silenced(s)"); - if (blocked[0] == 'b' || blocked[0] == 'B') + const string blocked = get_answer(tr("Blocked(b) or silenced(s)")); + if (blocked[0] == tr("b")[0] || blocked[0] == tr("B")) { return true; } - else if (blocked[0] == 's' || blocked[0] == 'S') + else if (blocked[0] == tr("s")[0] || blocked[0] == tr("S")[0]) { return false; } } } -const void askrecipes(const string &user) +const void Text::askrecipes(const string &user) { while (true) { - const string receipt_yn = get_answer("Add receipt? [y/n]"); - if (receipt_yn[0] == 'y' || receipt_yn[0] == 'Y') + 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("Receipt"); + const string receipt = get_answer(tr("Receipt")); if (database::add_receipt(user, receipt)) { - cout << "Receipt added.\n"; + cout << tr("Receipt added.") << '\n'; } } - else if (receipt_yn[0] == 'n' || receipt_yn[0] == 'N') + else if (receipt_yn[0] == tr("n")[0] || receipt_yn[0] == tr("N")[0]) { break; } @@ -73,9 +85,9 @@ const void askrecipes(const string &user) } } -const void add() +const void Text::add() { - const string user = get_answer("User or instance"); + const string user = get_answer(tr("User or instance")); int blocked; if (askblocked()) @@ -86,24 +98,24 @@ const void add() { blocked = 0; } - const string reason = get_answer("Reason"); + const string reason = get_answer(tr("Reason")); if (database::add_block(user, blocked, reason)) { - cout << user << " added.\n"; + cout << user << " " << tr("added.") << '\n'; } askrecipes(user); } -const void edit() +const void Text::edit() { result_details olddata; - const string olduser = get_answer("User or instance"); + const string olduser = get_answer(tr("User or instance")); if (database::details(olduser, olddata)) { - cout << "A blank line keeps the former value.\n"; - string newuser = get_answer("Change user or instance to"); + 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; @@ -119,8 +131,8 @@ const void edit() blocked = 0; } - cout << "Old reason was: " << std::get<1>(olddata) << '\n'; - string newreason = get_answer("Change reason to"); + 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); @@ -129,8 +141,8 @@ const void edit() std::vector newreceipts; for (const string &oldreceipt : std::get<2>(olddata)) { - cout << "Old receipt was: " << oldreceipt << '\n'; - string newreceipt = get_answer("Change receipt to"); + cout << tr("Old receipt was:") << " " << oldreceipt << '\n'; + string newreceipt = get_answer(tr("Change receipt to")); if (newreceipt.empty()) { newreceipt = oldreceipt; @@ -152,22 +164,22 @@ const void edit() } else { - cerr << "Could not remove " << olduser << ".\n"; + cerr << tr("Could not remove") << " " << olduser << ".\n"; } } } -const void remove() +const void Text::remove() { - const string user = get_answer("User or instance"); + const string user = get_answer(tr("User or instance")); if (database::remove(user)) { - cout << user << " removed.\n"; + cout << user << " " << tr("removed.") << '\n'; } } -const void view() +const void Text::view() { result_view result; if (database::view(result)) @@ -176,39 +188,39 @@ const void view() { if (std::get<1>(line) == 1) { - cout << " Blocked: "; + cout << tr(" Blocked:") << " "; } else { - cout << "Silenced: "; + cout << tr("Silenced:") << " "; } - cout << std::get<0>(line) << " because: "; + cout << std::get<0>(line) << " " << tr("because:") << " "; cout << std::get<2>(line) << '\n'; } } } -const void details() +const void Text::details() { - const string user = get_answer("User or instance"); + const string user = get_answer(tr("User or instance")); { result_details result; if (database::details(user, result)) { - cout << user << " is "; + cout << user << " " << tr("is") << " "; if (std::get<0>(result) == 1) { - cout << "blocked, because: "; + cout << tr("blocked, because:") << " "; } else if (std::get<0>(result) == 0) { - cout << "silenced, because: "; + cout << tr("silenced, because:") << " "; } cout << std::get<1>(result) << '\n'; if (!std::get<2>(result).empty()) { - cout << "Receipts:\n"; + cout << tr("Receipts:") << '\n'; for (const string &url : std::get<2>(result)) { cout << " " << url << '\n'; @@ -218,69 +230,75 @@ const void details() } } -const void help() +const void Text::help() { - cout << "Type add, edit, 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 << 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'; } -int main(int argc, char *argv[]) +Text::Text(QObject *parent) : QObject(parent) { bool keeprunning = true; - - cout << "This is whyblocked " << global::version << ".\n"; + + cout << tr("This is Whyblocked") << " " << global::version << ".\n"; help(); while (keeprunning) { string answer = get_answer(""); - switch (answer[0]) + if (answer[0] == tr("a")[0] || answer[0] == tr("A")[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 << "Response not understood.\n"; + add(); + } + else if (answer[0] == tr("e")[0] || answer[0] == tr("E")[0]) + { + edit(); + } + else if (answer[0] == tr("r")[0] || answer[0] == tr("R")[0]) + { + remove(); + } + else if (answer[0] == tr("v")[0] || answer[0] == tr("V")[0]) + { + view(); + } + else if (answer[0] == tr("d")[0] || answer[0] == tr("D")[0]) + { + details(); + } + else if (answer[0] == tr("h")[0] || answer[0] == tr("H")[0]) + { + help(); + } + else if (answer[0] == tr("q")[0] || answer[0] == tr("Q")[0]) + { + keeprunning = false; + } + else + { + 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; } diff --git a/src/interface_text.hpp b/src/interface_text.hpp new file mode 100644 index 0000000..4b83bbb --- /dev/null +++ b/src/interface_text.hpp @@ -0,0 +1,44 @@ +/* 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_TEXT_HPP +#define INTERFACE_TEXT_HPP + +#include +#include + +using std::string; + +class Text : public QObject +{ + Q_OBJECT + +public: + explicit Text(QObject *parent = nullptr); + +private: + const string get_answer(const QString &question); + const bool askblocked(); + const void askrecipes(const string &user); + const void add(); + const void edit(); + const void remove(); + const void view(); + const void details(); + const void help(); +}; + +#endif // INTERFACE_TEXT_HPP diff --git a/translations/whyblocked_de.ts b/translations/whyblocked_de.ts index 67d1e0e..a0814cc 100644 --- a/translations/whyblocked_de.ts +++ b/translations/whyblocked_de.ts @@ -248,4 +248,250 @@ <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> + + Text + + + Blocked(b) or silenced(s) + Blockiert(b) oder Gedämpft(g) + + + + b + b + + + + B + B + + + + s + g + + + + S + G + + + + Add receipt? [y/n] + Beleg hinzufügen? [j/n] + + + + y + j + + + + Y + J + + + + Receipt + Beleg + + + + Receipt added. + Beleg hinzugefügt. + + + + n + n + + + + N + N + + + + + + + User or instance + Benutzer oder Instanz + + + + Reason + Begründung + + + + added. + hinzugefügt. + + + + A blank line keeps the former value. + Leere Zeile um den alten Wert zu erhalten. + + + + Change user or instance to + Ändere Benutzer oder Instanz zu + + + + Old reason was: + Alte Begründung war: + + + + Change reason to + Ändere Begründung zu + + + + Old receipt was: + Alter Beleg war: + + + + Change receipt to + Ändere beleg zu + + + + Could not remove + Konnte nicht entfernen: + + + + removed. + entfernt. + + + + Blocked: + Blockiert: + + + + Silenced: + Gedämpft: + + + + because: + weil: + + + + is + ist + + + + blocked, because: + blockiert, weil: + + + + silenced, because: + gedämpft, weil: + + + + Receipts: + Belege: + + + + Type add, edit, remove, view or details. Or just the first letter. + Schreibe zufügen, ändern, entfernen, anschauen oder details. Oder nur den Anfangsbuchstaben. + + + + Type help or h to show this help. Type quit or q to quit the program. + Schreibe hilfe oder h, um die Hilfe anzuzeigen. Schreibe beenden oder b um das Programm zu beenden. + + + + This is Whyblocked + Dies ist Whyblocked + + + + a + z + + + + A + Z + + + + e + ä + + + + E + Ä + + + + r + e + + + + R + E + + + + v + a + + + + V + A + + + + d + d + + + + D + D + + + + h + h + + + + H + H + + + + q + b + + + + Q + B + + + + Response not understood. + Antwort nicht verstanden. + + diff --git a/translations/whyblocked_en.ts b/translations/whyblocked_en.ts index ca48de6..2b9d80b 100644 --- a/translations/whyblocked_en.ts +++ b/translations/whyblocked_en.ts @@ -248,4 +248,250 @@ + + Text + + + Blocked(b) or silenced(s) + + + + + b + + + + + B + + + + + s + + + + + S + + + + + Add receipt? [y/n] + + + + + y + + + + + Y + + + + + Receipt + + + + + Receipt added. + + + + + n + + + + + N + + + + + + + + User or instance + + + + + Reason + + + + + added. + + + + + A blank line keeps the former value. + + + + + Change user or instance to + + + + + Old reason was: + + + + + Change reason to + + + + + Old receipt was: + + + + + Change receipt to + + + + + Could not remove + + + + + removed. + + + + + Blocked: + + + + + Silenced: + + + + + because: + + + + + is + + + + + blocked, because: + + + + + silenced, because: + + + + + Receipts: + + + + + Type add, edit, remove, view or details. Or just the first letter. + + + + + Type help or h to show this help. Type quit or q to quit the program. + + + + + This is Whyblocked + + + + + a + + + + + A + + + + + e + + + + + E + + + + + r + + + + + R + + + + + v + + + + + V + + + + + d + + + + + D + + + + + h + + + + + H + + + + + q + + + + + Q + + + + + Response not understood. + + +