Only reload database on start and when the reload button is clicked.

develop
tastytea 2019-01-12 20:37:43 +01:00
parent 0f13bc8d9b
commit 0fdaad70ee
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
6 changed files with 61 additions and 65 deletions

View File

@ -33,7 +33,6 @@ MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent) : QMainWindow(parent)
, _config("whyblocked.cfg") , _config("whyblocked.cfg")
, _headersize({ 250, 125, 125 }) , _headersize({ 250, 125, 125 })
, _database()
{ {
std::locale::global(std::locale("")); std::locale::global(std::locale(""));
@ -199,9 +198,8 @@ void MainWindow::populate_tableview(const vector<Database::data> &entries)
void MainWindow::reload() void MainWindow::reload()
{ {
vector<Database::data> entries; _dbdata = Database::query();
entries = _database.query(); populate_tableview(_dbdata);
populate_tableview(entries);
} }
void MainWindow::add_row(const QString &user, const int &blocked, void MainWindow::add_row(const QString &user, const int &blocked,
@ -243,13 +241,17 @@ void MainWindow::edit()
const string user = index.sibling(index.row(), 0).data() const string user = index.sibling(index.row(), 0).data()
.toString().toStdString(); .toString().toStdString();
Database::data dbdata = Database::data data;
_database.query("SELECT * FROM blocks WHERE user = '" + for (const Database::data &entry : _dbdata)
user + "';").front(); {
dbdata.reason = dbdata.reason; if (entry.user == user)
dbdata.receipts = dbdata.receipts; {
data = entry;
break;
}
}
dialog->set_data(dbdata); dialog->set_data(data);
dialog->setProperty("edit", true); dialog->setProperty("edit", true);
dialog->show(); dialog->show();
} }
@ -262,7 +264,7 @@ void MainWindow::remove()
for (auto &row : selection->selectedRows()) for (auto &row : selection->selectedRows())
{ {
const string user = row.data().toString().toStdString(); const string user = row.data().toString().toStdString();
_database.remove(user); Database::remove(user);
_model->removeRow(row.row()); _model->removeRow(row.row());
} }
label_receipts->clear(); label_receipts->clear();
@ -292,17 +294,10 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
if (obj == text_find && if (obj == text_find &&
(event->type() == QEvent::KeyRelease || event->type() == QEvent::Enter)) (event->type() == QEvent::KeyRelease || event->type() == QEvent::Enter))
{ {
string columns;
if (check_user->isChecked())
{
columns = "user";
}
vector<Database::data> entries = _database.query();
vector<Database::data> filtered_entries; vector<Database::data> filtered_entries;
if (!entries.empty()) if (!_dbdata.empty())
{ {
for (const Database::data &entry : entries) for (const Database::data &entry : _dbdata)
{ {
wstring searchstring; wstring searchstring;
@ -352,16 +347,21 @@ void MainWindow::show_details(QModelIndex index)
{ {
const string user = index.sibling(index.row(), 0).data() const string user = index.sibling(index.row(), 0).data()
.toString().toStdString(); .toString().toStdString();
vector<Database::data> dbdata = Database::data data;
_database.query("SELECT * FROM blocks WHERE user = '" + user + "';"); for (const Database::data &entry : _dbdata)
{
if (entry.user == user)
{
data = entry;
break;
}
}
string text = ""; string text = "";
if (!dbdata.empty()) if (!data.receipts.empty())
{
if (!dbdata.front().receipts.empty())
{ {
text += string("<b>") + tr("Receipts:").toStdString() + "</b>"; text += string("<b>") + tr("Receipts:").toStdString() + "</b>";
for (const string &url : dbdata.front().receipts) for (const string &url : data.receipts)
{ {
text += "<br>" + url; text += "<br>" + url;
} }
@ -369,7 +369,6 @@ void MainWindow::show_details(QModelIndex index)
} }
label_receipts->setText(QString::fromStdString((text))); label_receipts->setText(QString::fromStdString((text)));
} }
}
const string MainWindow::urls_to_hyperlinks(const string &text) const string MainWindow::urls_to_hyperlinks(const string &text)
{ {

View File

@ -63,7 +63,7 @@ private:
QStandardItemModel *_model; QStandardItemModel *_model;
xdgcfg _config; xdgcfg _config;
std::array<int, 3> _headersize; std::array<int, 3> _headersize;
Database _database; std::vector<Database::data> _dbdata;
private slots: private slots:
void add(); void add();

View File

@ -28,8 +28,6 @@
using std::cerr; using std::cerr;
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
Database::Database() {};
Database::data::operator bool() const Database::data::operator bool() const
{ {
return !user.empty(); return !user.empty();

View File

@ -37,7 +37,6 @@ public:
explicit operator bool() const; explicit operator bool() const;
}; };
Database();
static bool add_user(const string &user, const bool blocked, static bool add_user(const string &user, const bool blocked,
const string &reason); const string &reason);
static bool add_receipt(const string &user, const string &receipt); static bool add_receipt(const string &user, const string &receipt);

View File

@ -74,7 +74,7 @@
<translation>Du kannst URLs hier hineinziehen</translation> <translation>Du kannst URLs hier hineinziehen</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="460"/> <location filename="../src/interface_qt.cpp" line="465"/>
<source>Insert receipt here.</source> <source>Insert receipt here.</source>
<translation>Beleg hier einfügen.</translation> <translation>Beleg hier einfügen.</translation>
</message> </message>
@ -198,7 +198,7 @@
</message> </message>
<message> <message>
<location filename="../src/whyblocked.ui" line="285"/> <location filename="../src/whyblocked.ui" line="285"/>
<location filename="../src/interface_qt.cpp" line="240"/> <location filename="../src/interface_qt.cpp" line="238"/>
<source>Edit entry</source> <source>Edit entry</source>
<translation>Eintrag bearbeiten</translation> <translation>Eintrag bearbeiten</translation>
</message> </message>
@ -219,68 +219,68 @@
</message> </message>
<message> <message>
<location filename="../src/whyblocked.ui" line="59"/> <location filename="../src/whyblocked.ui" line="59"/>
<location filename="../src/interface_qt.cpp" line="184"/> <location filename="../src/interface_qt.cpp" line="183"/>
<source>User/Instance</source> <source>User/Instance</source>
<translation>Benutzer/Instanz</translation> <translation>Benutzer/Instanz</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="185"/> <location filename="../src/interface_qt.cpp" line="184"/>
<source>Blocked/Silenced</source> <source>Blocked/Silenced</source>
<translation>Blockiert/Gedämpft</translation> <translation>Blockiert/Gedämpft</translation>
</message> </message>
<message> <message>
<location filename="../src/whyblocked.ui" line="72"/> <location filename="../src/whyblocked.ui" line="72"/>
<location filename="../src/interface_qt.cpp" line="186"/> <location filename="../src/interface_qt.cpp" line="185"/>
<source>Reason</source> <source>Reason</source>
<translation>Begründung</translation> <translation>Begründung</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="110"/> <location filename="../src/interface_qt.cpp" line="109"/>
<source>Try dragging an account from your webbrowser into this window.</source> <source>Try dragging an account from your webbrowser into this window.</source>
<translation>Versuche, einen account von deinem webbrowser in dieses fenster zu ziehen.</translation> <translation>Versuche, einen account von deinem webbrowser in dieses fenster zu ziehen.</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="214"/> <location filename="../src/interface_qt.cpp" line="212"/>
<source>blocked</source> <source>blocked</source>
<translation>blockiert</translation> <translation>blockiert</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="218"/> <location filename="../src/interface_qt.cpp" line="216"/>
<source>silenced</source> <source>silenced</source>
<translation>gedämpft</translation> <translation>gedämpft</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="234"/> <location filename="../src/interface_qt.cpp" line="232"/>
<source>Invalid selection</source> <source>Invalid selection</source>
<translation>Ungültige Auswahl</translation> <translation>Ungültige Auswahl</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="235"/> <location filename="../src/interface_qt.cpp" line="233"/>
<source>Please select only 1 entry to edit.</source> <source>Please select only 1 entry to edit.</source>
<translation>Bitte nur 1 Eintrag zum bearbeiten auswählen.</translation> <translation>Bitte nur 1 Eintrag zum bearbeiten auswählen.</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="272"/> <location filename="../src/interface_qt.cpp" line="274"/>
<source>Nothing selected</source> <source>Nothing selected</source>
<translation>Nichts ausgewählt</translation> <translation>Nichts ausgewählt</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="273"/> <location filename="../src/interface_qt.cpp" line="275"/>
<source>Please select entries to remove.</source> <source>Please select entries to remove.</source>
<translation>Bitte wähle einträge aus, die gelöscht werden sollen.</translation> <translation>Bitte wähle einträge aus, die gelöscht werden sollen.</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="338"/> <location filename="../src/interface_qt.cpp" line="339"/>
<source>About Whyblocked</source> <source>About Whyblocked</source>
<translation>Über Whyblocked</translation> <translation>Über Whyblocked</translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="339"/> <location filename="../src/interface_qt.cpp" line="340"/>
<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> <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> <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>
<message> <message>
<location filename="../src/interface_qt.cpp" line="363"/> <location filename="../src/interface_qt.cpp" line="369"/>
<source>Receipts:</source> <source>Receipts:</source>
<translation>Belege:</translation> <translation>Belege:</translation>
</message> </message>

View File

@ -74,7 +74,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="460"/> <location filename="../src/interface_qt.cpp" line="465"/>
<source>Insert receipt here.</source> <source>Insert receipt here.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -198,7 +198,7 @@
</message> </message>
<message> <message>
<location filename="../src/whyblocked.ui" line="285"/> <location filename="../src/whyblocked.ui" line="285"/>
<location filename="../src/interface_qt.cpp" line="240"/> <location filename="../src/interface_qt.cpp" line="238"/>
<source>Edit entry</source> <source>Edit entry</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -219,68 +219,68 @@
</message> </message>
<message> <message>
<location filename="../src/whyblocked.ui" line="59"/> <location filename="../src/whyblocked.ui" line="59"/>
<location filename="../src/interface_qt.cpp" line="184"/> <location filename="../src/interface_qt.cpp" line="183"/>
<source>User/Instance</source> <source>User/Instance</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="185"/> <location filename="../src/interface_qt.cpp" line="184"/>
<source>Blocked/Silenced</source> <source>Blocked/Silenced</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/whyblocked.ui" line="72"/> <location filename="../src/whyblocked.ui" line="72"/>
<location filename="../src/interface_qt.cpp" line="186"/> <location filename="../src/interface_qt.cpp" line="185"/>
<source>Reason</source> <source>Reason</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="110"/> <location filename="../src/interface_qt.cpp" line="109"/>
<source>Try dragging an account from your webbrowser into this window.</source> <source>Try dragging an account from your webbrowser into this window.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="214"/> <location filename="../src/interface_qt.cpp" line="212"/>
<source>blocked</source> <source>blocked</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="218"/> <location filename="../src/interface_qt.cpp" line="216"/>
<source>silenced</source> <source>silenced</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="234"/> <location filename="../src/interface_qt.cpp" line="232"/>
<source>Invalid selection</source> <source>Invalid selection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="235"/> <location filename="../src/interface_qt.cpp" line="233"/>
<source>Please select only 1 entry to edit.</source> <source>Please select only 1 entry to edit.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="272"/> <location filename="../src/interface_qt.cpp" line="274"/>
<source>Nothing selected</source> <source>Nothing selected</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="273"/> <location filename="../src/interface_qt.cpp" line="275"/>
<source>Please select entries to remove.</source> <source>Please select entries to remove.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="338"/> <location filename="../src/interface_qt.cpp" line="339"/>
<source>About Whyblocked</source> <source>About Whyblocked</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="339"/> <location filename="../src/interface_qt.cpp" line="340"/>
<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> <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> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/interface_qt.cpp" line="363"/> <location filename="../src/interface_qt.cpp" line="369"/>
<source>Receipts:</source> <source>Receipts:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>