Only reload database on start and when the reload button is clicked.
parent
0f13bc8d9b
commit
0fdaad70ee
|
@ -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 (!data.receipts.empty())
|
||||
{
|
||||
if (!dbdata.front().receipts.empty())
|
||||
text += string("<b>") + tr("Receipts:").toStdString() + "</b>";
|
||||
for (const string &url : data.receipts)
|
||||
{
|
||||
text += string("<b>") + tr("Receipts:").toStdString() + "</b>";
|
||||
for (const string &url : dbdata.front().receipts)
|
||||
{
|
||||
text += "<br>" + url;
|
||||
}
|
||||
text = urls_to_hyperlinks(text);
|
||||
text += "<br>" + url;
|
||||
}
|
||||
label_receipts->setText(QString::fromStdString((text)));
|
||||
text = urls_to_hyperlinks(text);
|
||||
}
|
||||
label_receipts->setText(QString::fromStdString((text)));
|
||||
}
|
||||
|
||||
const string MainWindow::urls_to_hyperlinks(const string &text)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
using std::cerr;
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
Database::Database() {};
|
||||
|
||||
Database::data::operator bool() const
|
||||
{
|
||||
return !user.empty();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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><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></source>
|
||||
<translation><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></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>
|
||||
|
|
|
@ -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><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></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>
|
||||
|
|
Loading…
Reference in New Issue