From f6ff77571dfdd7bbd4b2d74afd042360d426eb37 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 2 Nov 2018 11:54:40 +0100 Subject: [PATCH] Added drop-support to main window (issue #8) If text is dropped on the main window, the add dialog pops up with the user/instance field pre-filled. --- CMakeLists.txt | 2 +- src/interface_qt.cpp | 41 +++++++++++++++++++ src/interface_qt.hpp | 11 +++-- src/whyblocked.ui | 6 +++ translations/whyblocked_de.ts | 76 +++++++++++++++++------------------ translations/whyblocked_en.ts | 76 +++++++++++++++++------------------ 6 files changed, 131 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10e896a..50c32f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.6) project (whyblocked - VERSION 0.10.11 + VERSION 0.11.0 LANGUAGES CXX ) diff --git a/src/interface_qt.cpp b/src/interface_qt.cpp index bcc73a9..b5066e7 100644 --- a/src/interface_qt.cpp +++ b/src/interface_qt.cpp @@ -15,10 +15,12 @@ */ #include +#include #include #include #include #include +#include #include "version.hpp" #include "whyblocked.hpp" #include "interface_qt.hpp" @@ -177,6 +179,45 @@ const string MainWindow::urls_to_hyperlinks(const string &text) return std::regex_replace(text, re_url, "$1"); } +void MainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("text/plain")) + { + event->acceptProposedAction(); + } +} + +void MainWindow::dropEvent(QDropEvent *event) +{ + string text = event->mimeData()->text().toStdString(); + const std::array fediverse = + { + std::regex("https://([^/]+)/@([^/]+)"), // Mastodon + std::regex("https://([^/]+)/profile/([^/]+)"), // Friendica + std::regex("https://([^/]+)/users/([^/]+)"), // Pleroma + std::regex("https://([^/]+)/([^/]+)") // Gnusocial + }; + std::smatch match; + + for (const std::regex &re : fediverse) + { + std::regex_match(text, match, re); + const string instance = match[1]; + const string user = match[2]; + if (!instance.empty() && !user.empty()) + { + text = '@' + user + '@' + instance; + break; + } + } + + DialogAdd *dialog = new DialogAdd(this); + Dialogdata data; + data.user = text; + dialog->set_data(data); + dialog->show(); +} + DialogAdd::DialogAdd(QMainWindow *parent) : QDialog(parent) , _parent(static_cast(parent)) diff --git a/src/interface_qt.hpp b/src/interface_qt.hpp index 9ef2485..011afde 100644 --- a/src/interface_qt.hpp +++ b/src/interface_qt.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "ui_whyblocked.h" #include "ui_whyblocked_add.h" @@ -28,10 +29,10 @@ using std::string; struct Dialogdata { - string user; - bool blocked; - string reason; - std::vector receipts; + string user = ""; + bool blocked = true; + string reason = ""; + std::vector receipts = {}; }; class MainWindow : public QMainWindow, private Ui::MainWindow @@ -48,6 +49,8 @@ public slots: private: const string urls_to_hyperlinks(const string &text); + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); QStandardItemModel *_model; diff --git a/src/whyblocked.ui b/src/whyblocked.ui index 95ffae7..c6e545c 100644 --- a/src/whyblocked.ui +++ b/src/whyblocked.ui @@ -10,6 +10,9 @@ 600 + + true + Whyblocked @@ -24,6 +27,9 @@ + + false + Click or press enter to view receipts diff --git a/translations/whyblocked_de.ts b/translations/whyblocked_de.ts index fcab1bb..27809f9 100644 --- a/translations/whyblocked_de.ts +++ b/translations/whyblocked_de.ts @@ -64,12 +64,12 @@ Ent&fernen - + Insert receipt here. Beleg hier einfügen. - + Added %1 to database. %1 zur Datenbank hinzugefügt. @@ -77,178 +77,178 @@ MainWindow - + Whyblocked - + Click or press enter to view receipts Klicken oder Eingabe drücken, um Belege zu anzuzeigen - + Memory aids, proof Gedächtnisstützen, Beweise - + Toolbar 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 03e628f..a52ce8c 100644 --- a/translations/whyblocked_en.ts +++ b/translations/whyblocked_en.ts @@ -64,12 +64,12 @@ - + Insert receipt here. - + Added %1 to database. @@ -77,178 +77,178 @@ MainWindow - + Whyblocked - + Click or press enter to view receipts - + Memory aids, proof - + Toolbar - + &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: