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

View File

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

View File

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

View File

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

View File

@ -74,7 +74,7 @@
<translation>Du kannst URLs hier hineinziehen</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="460"/>
<location filename="../src/interface_qt.cpp" line="465"/>
<source>Insert receipt here.</source>
<translation>Beleg hier einfügen.</translation>
</message>
@ -198,7 +198,7 @@
</message>
<message>
<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>
<translation>Eintrag bearbeiten</translation>
</message>
@ -219,68 +219,68 @@
</message>
<message>
<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>
<translation>Benutzer/Instanz</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="185"/>
<location filename="../src/interface_qt.cpp" line="184"/>
<source>Blocked/Silenced</source>
<translation>Blockiert/Gedämpft</translation>
</message>
<message>
<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>
<translation>Begründung</translation>
</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>
<translation>Versuche, einen account von deinem webbrowser in dieses fenster zu ziehen.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="214"/>
<location filename="../src/interface_qt.cpp" line="212"/>
<source>blocked</source>
<translation>blockiert</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="218"/>
<location filename="../src/interface_qt.cpp" line="216"/>
<source>silenced</source>
<translation>gedämpft</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="234"/>
<location filename="../src/interface_qt.cpp" line="232"/>
<source>Invalid selection</source>
<translation>Ungültige Auswahl</translation>
</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>
<translation>Bitte nur 1 Eintrag zum bearbeiten auswählen.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="272"/>
<location filename="../src/interface_qt.cpp" line="274"/>
<source>Nothing selected</source>
<translation>Nichts ausgewählt</translation>
</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>
<translation>Bitte wähle einträge aus, die gelöscht werden sollen.</translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="338"/>
<location filename="../src/interface_qt.cpp" line="339"/>
<source>About Whyblocked</source>
<translation>Über Whyblocked</translation>
</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>
<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="363"/>
<location filename="../src/interface_qt.cpp" line="369"/>
<source>Receipts:</source>
<translation>Belege:</translation>
</message>

View File

@ -74,7 +74,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="460"/>
<location filename="../src/interface_qt.cpp" line="465"/>
<source>Insert receipt here.</source>
<translation type="unfinished"></translation>
</message>
@ -198,7 +198,7 @@
</message>
<message>
<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>
<translation type="unfinished"></translation>
</message>
@ -219,68 +219,68 @@
</message>
<message>
<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>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="185"/>
<location filename="../src/interface_qt.cpp" line="184"/>
<source>Blocked/Silenced</source>
<translation type="unfinished"></translation>
</message>
<message>
<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>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="214"/>
<location filename="../src/interface_qt.cpp" line="212"/>
<source>blocked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="218"/>
<location filename="../src/interface_qt.cpp" line="216"/>
<source>silenced</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="234"/>
<location filename="../src/interface_qt.cpp" line="232"/>
<source>Invalid selection</source>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="272"/>
<location filename="../src/interface_qt.cpp" line="274"/>
<source>Nothing selected</source>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="338"/>
<location filename="../src/interface_qt.cpp" line="339"/>
<source>About Whyblocked</source>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/interface_qt.cpp" line="363"/>
<location filename="../src/interface_qt.cpp" line="369"/>
<source>Receipts:</source>
<translation type="unfinished"></translation>
</message>