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.
develop
tastytea 2018-11-02 11:54:40 +01:00
parent 27ccc954a1
commit f6ff77571d
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
6 changed files with 131 additions and 81 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6)
project (whyblocked
VERSION 0.10.11
VERSION 0.11.0
LANGUAGES CXX
)

View File

@ -15,10 +15,12 @@
*/
#include <regex>
#include <array>
#include <QMessageBox>
#include <QDebug>
#include <QTranslator>
#include <QLibraryInfo>
#include <QtCore/qmimedata.h>
#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, "<a href=\"$1\">$1</a>");
}
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<const std::regex, 4> 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<MainWindow*>(parent))

View File

@ -21,6 +21,7 @@
#include <QMainWindow>
#include <QStandardItemModel>
#include <QDialog>
#include <QtGui/qevent.h>
#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<string> receipts;
string user = "";
bool blocked = true;
string reason = "";
std::vector<string> 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;

View File

@ -10,6 +10,9 @@
<height>600</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>Whyblocked</string>
</property>
@ -24,6 +27,9 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="tableview">
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Click or press enter to view receipts</string>
</property>

View File

@ -64,12 +64,12 @@
<translation>Ent&amp;fernen</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="221"/>
<location filename="../src/interface_qt.cpp" line="262"/>
<source>Insert receipt here.</source>
<translation>Beleg hier einfügen.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="256"/>
<location filename="../src/interface_qt.cpp" line="297"/>
<source>Added %1 to database.</source>
<translation>%1 zur Datenbank hinzugefügt.</translation>
</message>
@ -77,178 +77,178 @@
<context>
<name>MainWindow</name>
<message>
<location filename="../src/whyblocked.ui" line="14"/>
<location filename="../src/whyblocked.ui" line="17"/>
<source>Whyblocked</source>
<translation></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="28"/>
<location filename="../src/whyblocked.ui" line="34"/>
<source>Click or press enter to view receipts</source>
<translation>Klicken oder Eingabe drücken, um Belege zu anzuzeigen</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="71"/>
<location filename="../src/whyblocked.ui" line="77"/>
<source>Memory aids, proof</source>
<translation>Gedächtnisstützen, Beweise</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="95"/>
<location filename="../src/whyblocked.ui" line="101"/>
<source>Toolbar</source>
<translation>Werkzeugleiste</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="122"/>
<location filename="../src/whyblocked.ui" line="128"/>
<source>&amp;Database</source>
<translation>&amp;Datenbank</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="132"/>
<location filename="../src/whyblocked.ui" line="138"/>
<source>&amp;Help</source>
<translation>&amp;Hilfe</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="145"/>
<location filename="../src/whyblocked.ui" line="151"/>
<source>&amp;Add</source>
<translation>&amp;Hinzufügen</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="148"/>
<location filename="../src/whyblocked.ui" line="154"/>
<source>Add user or instance</source>
<translation>Benutzer oder Instanz hinzufügen</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="151"/>
<location filename="../src/whyblocked.ui" line="157"/>
<source>Ctrl+N</source>
<translation></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="160"/>
<location filename="../src/whyblocked.ui" line="166"/>
<source>Re&amp;move</source>
<translation>Ent&amp;fernen</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="163"/>
<location filename="../src/whyblocked.ui" line="169"/>
<source>Remove user or instance</source>
<translation>Benutzer oder Instanz entfernen</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="166"/>
<location filename="../src/whyblocked.ui" line="172"/>
<source>Del</source>
<translation></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="175"/>
<location filename="../src/whyblocked.ui" line="181"/>
<source>&amp;About</source>
<translation>&amp;Über</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="178"/>
<location filename="../src/whyblocked.ui" line="184"/>
<source>About this application</source>
<translation>Über dieses Programm</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="187"/>
<location filename="../src/whyblocked.ui" line="193"/>
<source>&amp;Reload</source>
<translation>Neu &amp;laden</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="190"/>
<location filename="../src/whyblocked.ui" line="196"/>
<source>Reload database</source>
<translation>Datenbank neu laden</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="193"/>
<location filename="../src/whyblocked.ui" line="199"/>
<source>Ctrl+R</source>
<translation></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="202"/>
<location filename="../src/whyblocked.ui" line="208"/>
<source>&amp;Quit</source>
<translation>&amp;Beenden</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="205"/>
<location filename="../src/whyblocked.ui" line="211"/>
<source>Quit application</source>
<translation>Programm beenden</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="208"/>
<location filename="../src/whyblocked.ui" line="214"/>
<source>Ctrl+Q</source>
<translation></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="217"/>
<location filename="../src/whyblocked.ui" line="223"/>
<source>&amp;Edit</source>
<translation>B&amp;earbeiten</translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="220"/>
<location filename="../src/interface_qt.cpp" line="93"/>
<location filename="../src/whyblocked.ui" line="226"/>
<location filename="../src/interface_qt.cpp" line="95"/>
<source>Edit entry</source>
<translation>Eintrag bearbeiten</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="40"/>
<location filename="../src/interface_qt.cpp" line="42"/>
<source>User/Instance</source>
<translation>Benutzer/Instanz</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="41"/>
<location filename="../src/interface_qt.cpp" line="43"/>
<source>Blocked/Silenced</source>
<translation>Blockiert/Gedämpft</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="42"/>
<location filename="../src/interface_qt.cpp" line="44"/>
<source>Reason</source>
<translation>Begründung</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="57"/>
<location filename="../src/interface_qt.cpp" line="59"/>
<source>Database loaded.</source>
<translation>Datenbank geladen.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="67"/>
<location filename="../src/interface_qt.cpp" line="69"/>
<source>blocked</source>
<translation>blockiert</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="71"/>
<location filename="../src/interface_qt.cpp" line="73"/>
<source>silenced</source>
<translation>gedämpft</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="87"/>
<location filename="../src/interface_qt.cpp" line="89"/>
<source>Invalid selection</source>
<translation>Ungültige Auswahl</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="88"/>
<location filename="../src/interface_qt.cpp" line="90"/>
<source>Please select only 1 entry to edit.</source>
<translation>Bitte nur 1 Eintrag zum bearbeiten auswählen.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="125"/>
<location filename="../src/interface_qt.cpp" line="127"/>
<source>Removed %1 from database.</source>
<translation>%1 aus der Datenbank gelöscht.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="133"/>
<location filename="../src/interface_qt.cpp" line="135"/>
<source>Select data to remove.</source>
<translation>Wähle Daten zum löschen aus.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="139"/>
<location filename="../src/interface_qt.cpp" line="141"/>
<source>About Whyblocked</source>
<translation>Über Whyblocked</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="140"/>
<location filename="../src/interface_qt.cpp" line="142"/>
<source>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Reminds you why you blocked someone.&lt;/p&gt;&lt;p&gt;Sourcecode: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Licence GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.&lt;/small&gt;&lt;/p&gt;</source>
<translation>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Erinnert dich, warum du jemanden blockiertest.&lt;/p&gt;&lt;p&gt;Quelltext: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Lizenz GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;Für dieses Programm besteht KEINERLEI GARANTIE. Dies ist freie Software, die Sie unter bestimmten Bedingungen weitergeben dürfen.&lt;/small&gt;&lt;/p&gt;</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="163"/>
<location filename="../src/interface_qt.cpp" line="165"/>
<source>Receipts:</source>
<translation>Belege:</translation>
</message>

View File

@ -64,12 +64,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="221"/>
<location filename="../src/interface_qt.cpp" line="262"/>
<source>Insert receipt here.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="256"/>
<location filename="../src/interface_qt.cpp" line="297"/>
<source>Added %1 to database.</source>
<translation type="unfinished"></translation>
</message>
@ -77,178 +77,178 @@
<context>
<name>MainWindow</name>
<message>
<location filename="../src/whyblocked.ui" line="14"/>
<location filename="../src/whyblocked.ui" line="17"/>
<source>Whyblocked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="28"/>
<location filename="../src/whyblocked.ui" line="34"/>
<source>Click or press enter to view receipts</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="71"/>
<location filename="../src/whyblocked.ui" line="77"/>
<source>Memory aids, proof</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="95"/>
<location filename="../src/whyblocked.ui" line="101"/>
<source>Toolbar</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="122"/>
<location filename="../src/whyblocked.ui" line="128"/>
<source>&amp;Database</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="132"/>
<location filename="../src/whyblocked.ui" line="138"/>
<source>&amp;Help</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="145"/>
<location filename="../src/whyblocked.ui" line="151"/>
<source>&amp;Add</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="148"/>
<location filename="../src/whyblocked.ui" line="154"/>
<source>Add user or instance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="151"/>
<location filename="../src/whyblocked.ui" line="157"/>
<source>Ctrl+N</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="160"/>
<location filename="../src/whyblocked.ui" line="166"/>
<source>Re&amp;move</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="163"/>
<location filename="../src/whyblocked.ui" line="169"/>
<source>Remove user or instance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="166"/>
<location filename="../src/whyblocked.ui" line="172"/>
<source>Del</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="175"/>
<location filename="../src/whyblocked.ui" line="181"/>
<source>&amp;About</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="178"/>
<location filename="../src/whyblocked.ui" line="184"/>
<source>About this application</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="187"/>
<location filename="../src/whyblocked.ui" line="193"/>
<source>&amp;Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="190"/>
<location filename="../src/whyblocked.ui" line="196"/>
<source>Reload database</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="193"/>
<location filename="../src/whyblocked.ui" line="199"/>
<source>Ctrl+R</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="202"/>
<location filename="../src/whyblocked.ui" line="208"/>
<source>&amp;Quit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="205"/>
<location filename="../src/whyblocked.ui" line="211"/>
<source>Quit application</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="208"/>
<location filename="../src/whyblocked.ui" line="214"/>
<source>Ctrl+Q</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="217"/>
<location filename="../src/whyblocked.ui" line="223"/>
<source>&amp;Edit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/whyblocked.ui" line="220"/>
<location filename="../src/interface_qt.cpp" line="93"/>
<location filename="../src/whyblocked.ui" line="226"/>
<location filename="../src/interface_qt.cpp" line="95"/>
<source>Edit entry</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="40"/>
<location filename="../src/interface_qt.cpp" line="42"/>
<source>User/Instance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="41"/>
<location filename="../src/interface_qt.cpp" line="43"/>
<source>Blocked/Silenced</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="42"/>
<location filename="../src/interface_qt.cpp" line="44"/>
<source>Reason</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="57"/>
<location filename="../src/interface_qt.cpp" line="59"/>
<source>Database loaded.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="67"/>
<location filename="../src/interface_qt.cpp" line="69"/>
<source>blocked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="71"/>
<location filename="../src/interface_qt.cpp" line="73"/>
<source>silenced</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="87"/>
<location filename="../src/interface_qt.cpp" line="89"/>
<source>Invalid selection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="88"/>
<location filename="../src/interface_qt.cpp" line="90"/>
<source>Please select only 1 entry to edit.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="125"/>
<location filename="../src/interface_qt.cpp" line="127"/>
<source>Removed %1 from database.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="133"/>
<location filename="../src/interface_qt.cpp" line="135"/>
<source>Select data to remove.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="139"/>
<location filename="../src/interface_qt.cpp" line="141"/>
<source>About Whyblocked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="140"/>
<location filename="../src/interface_qt.cpp" line="142"/>
<source>&lt;p&gt;&lt;b&gt;Whyblocked&lt;/b&gt; %1&lt;/p&gt;&lt;p&gt;Reminds you why you blocked someone.&lt;/p&gt;&lt;p&gt;Sourcecode: &lt;a href=&quot;https://schlomp.space/tastytea/whyblocked&quot;&gt;https://schlomp.space/tastytea/whyblocked&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;small&gt;Copyright © 2018 &lt;a href=&quot;mailto:tastytea@tastytea.de&quot;&gt;tastytea&lt;/a&gt;.&lt;br&gt;Licence GPLv3: &lt;a href=&quot;https://www.gnu.org/licenses/gpl-3.0.html&quot;&gt;GNU GPL version 3&lt;/a&gt;.&lt;br&gt;This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.&lt;/small&gt;&lt;/p&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="163"/>
<location filename="../src/interface_qt.cpp" line="165"/>
<source>Receipts:</source>
<translation type="unfinished"></translation>
</message>