Added find function
parent
89eef7247a
commit
dd83e11338
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.2)
|
||||
project (whyblocked
|
||||
VERSION 0.12.2
|
||||
VERSION 0.13.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -16,20 +16,26 @@
|
|||
|
||||
#include <regex>
|
||||
#include <array>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <algorithm>
|
||||
#include <QMessageBox>
|
||||
#include <QTranslator>
|
||||
#include <QLibraryInfo>
|
||||
#include <QtCore/qmimedata.h>
|
||||
#include <libconfig.h++>
|
||||
#include "version.hpp"
|
||||
#include "whyblocked.hpp"
|
||||
#include "interface_qt.hpp"
|
||||
|
||||
using std::wstring;
|
||||
|
||||
MainWindow::MainWindow(QMainWindow *parent)
|
||||
: QMainWindow(parent)
|
||||
, _config("whyblocked.cfg")
|
||||
, _headersize({ 250, 125, 125 })
|
||||
{
|
||||
std::locale::global(std::locale(""));
|
||||
|
||||
setupUi(this);
|
||||
|
||||
_model = new QStandardItemModel;
|
||||
|
@ -90,7 +96,8 @@ MainWindow::MainWindow(QMainWindow *parent)
|
|||
widget_find->hide();
|
||||
text_find->installEventFilter(this);
|
||||
|
||||
populate_tableview();
|
||||
reload();
|
||||
|
||||
statusBar()->showMessage(tr("Try dragging an account from your webbrowser "
|
||||
"into this window."));
|
||||
}
|
||||
|
@ -152,7 +159,7 @@ MainWindow::~MainWindow()
|
|||
_config.write();
|
||||
}
|
||||
|
||||
void MainWindow::populate_tableview()
|
||||
void MainWindow::populate_tableview(const result_view &entries)
|
||||
{
|
||||
_model->clear();
|
||||
_model->setHorizontalHeaderLabels(
|
||||
|
@ -165,18 +172,21 @@ void MainWindow::populate_tableview()
|
|||
tableview->horizontalHeader()->resizeSection(1, _headersize[1]);
|
||||
tableview->horizontalHeader()->resizeSection(2, _headersize[2]);
|
||||
|
||||
result_view result;
|
||||
if (database::view(result))
|
||||
for (const std::tuple<string, int, string> &line : entries)
|
||||
{
|
||||
for (const std::tuple<string, int, string> &line : result)
|
||||
{
|
||||
add_row(QString::fromStdString(std::get<0>(line)),
|
||||
std::get<1>(line),
|
||||
QString::fromStdString(std::get<2>(line)));
|
||||
}
|
||||
add_row(QString::fromStdString(std::get<0>(line)),
|
||||
std::get<1>(line),
|
||||
QString::fromStdString(std::get<2>(line)));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::reload()
|
||||
{
|
||||
result_view entries;
|
||||
database::view(entries);
|
||||
populate_tableview(entries);
|
||||
}
|
||||
|
||||
void MainWindow::add_row(const QString &user, const int &blocked,
|
||||
const QString &reason)
|
||||
{
|
||||
|
@ -268,9 +278,47 @@ void MainWindow::find()
|
|||
|
||||
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (obj == text_find && event->type() == QEvent::KeyPress)
|
||||
if (obj == text_find && event->type() == QEvent::KeyRelease)
|
||||
{
|
||||
//
|
||||
string columns;
|
||||
if (check_user->isChecked())
|
||||
{
|
||||
columns = "user";
|
||||
}
|
||||
|
||||
result_view entries;
|
||||
result_view filtered_entries;
|
||||
if (database::view(entries))
|
||||
{
|
||||
for (const std::tuple<string, int, string> &line : entries)
|
||||
{
|
||||
const string user = std::get<0>(line);
|
||||
const string reason = std::get<2>(line);
|
||||
wstring searchstring;
|
||||
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
|
||||
|
||||
if (check_user->isChecked())
|
||||
{
|
||||
searchstring += convert.from_bytes(user);
|
||||
}
|
||||
if (check_reason->isChecked())
|
||||
{
|
||||
searchstring += convert.from_bytes(reason);
|
||||
}
|
||||
std::transform(searchstring.begin(), searchstring.end(),
|
||||
searchstring.begin(), ::towlower);
|
||||
if (searchstring.find(
|
||||
text_find->text().toLower().toStdWString())
|
||||
!= std::string::npos)
|
||||
{
|
||||
filtered_entries.push_back({
|
||||
user, std::get<1>(line), reason });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
populate_tableview(filtered_entries);
|
||||
}
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QDialog>
|
||||
#include <QtGui/qevent.h>
|
||||
#include "xdgcfg.hpp"
|
||||
#include "whyblocked.hpp"
|
||||
#include "ui_whyblocked.h"
|
||||
#include "ui_whyblocked_add.h"
|
||||
|
||||
|
@ -66,7 +67,8 @@ private slots:
|
|||
void edit();
|
||||
void about();
|
||||
void show_details(QModelIndex index);
|
||||
void populate_tableview();
|
||||
void populate_tableview(const result_view &entries);
|
||||
void reload();
|
||||
void find();
|
||||
|
||||
};
|
||||
|
|
|
@ -111,12 +111,21 @@ const bool database::remove(const string &user)
|
|||
return true;
|
||||
}
|
||||
|
||||
const bool database::view(result_view &result)
|
||||
const bool database::view(result_view &result, const string &sql_query)
|
||||
{
|
||||
try
|
||||
{
|
||||
string query;
|
||||
if (sql_query.empty())
|
||||
{
|
||||
query = "SELECT * FROM blocks;";
|
||||
}
|
||||
else
|
||||
{
|
||||
query = sql_query;
|
||||
}
|
||||
sqlite::connection con(get_filepath());
|
||||
sqlite::query q(con, "SELECT * FROM blocks;");
|
||||
sqlite::query q(con, query);
|
||||
sqlite::result_type res = q.get_result();
|
||||
while(res->next_row())
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace database
|
|||
const string &reason);
|
||||
const bool add_receipt(const string &user, const string &receipt);
|
||||
const bool remove(const string &user);
|
||||
const bool view(result_view &result);
|
||||
const bool view(result_view &result, const string &sql_query = "");
|
||||
const bool details(const string &user, result_details &result);
|
||||
}
|
||||
|
||||
|
|
|
@ -293,7 +293,8 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-find"/>
|
||||
<iconset theme="edit-find">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Find</string>
|
||||
|
@ -360,7 +361,7 @@
|
|||
<sender>action_reload</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>populate_tableview()</slot>
|
||||
<slot>reload()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
|
@ -461,5 +462,6 @@
|
|||
<slot>show_details(QModelIndex)</slot>
|
||||
<slot>edit()</slot>
|
||||
<slot>find()</slot>
|
||||
<slot>reload()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<translation>Du kannst URLs hier hineinziehen</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="403"/>
|
||||
<location filename="../src/interface_qt.cpp" line="449"/>
|
||||
<source>Insert receipt here.</source>
|
||||
<translation>Beleg hier einfügen.</translation>
|
||||
</message>
|
||||
|
@ -198,89 +198,89 @@
|
|||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="285"/>
|
||||
<location filename="../src/interface_qt.cpp" line="213"/>
|
||||
<location filename="../src/interface_qt.cpp" line="223"/>
|
||||
<source>Edit entry</source>
|
||||
<translation>Eintrag bearbeiten</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="299"/>
|
||||
<location filename="../src/whyblocked.ui" line="300"/>
|
||||
<source>&Find</source>
|
||||
<translation>&Finden</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="302"/>
|
||||
<location filename="../src/whyblocked.ui" line="303"/>
|
||||
<source>Find entries</source>
|
||||
<translation>Dinde Einträge</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="305"/>
|
||||
<location filename="../src/whyblocked.ui" line="306"/>
|
||||
<source>Ctrl+F</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="59"/>
|
||||
<location filename="../src/interface_qt.cpp" line="160"/>
|
||||
<location filename="../src/interface_qt.cpp" line="167"/>
|
||||
<source>User/Instance</source>
|
||||
<translation>Benutzer/Instanz</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="161"/>
|
||||
<location filename="../src/interface_qt.cpp" line="168"/>
|
||||
<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="162"/>
|
||||
<location filename="../src/interface_qt.cpp" line="169"/>
|
||||
<source>Reason</source>
|
||||
<translation>Begründung</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="94"/>
|
||||
<location filename="../src/interface_qt.cpp" line="101"/>
|
||||
<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="187"/>
|
||||
<location filename="../src/interface_qt.cpp" line="197"/>
|
||||
<source>blocked</source>
|
||||
<translation>blockiert</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="191"/>
|
||||
<location filename="../src/interface_qt.cpp" line="201"/>
|
||||
<source>silenced</source>
|
||||
<translation>gedämpft</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="207"/>
|
||||
<location filename="../src/interface_qt.cpp" line="217"/>
|
||||
<source>Invalid selection</source>
|
||||
<translation>Ungültige Auswahl</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="208"/>
|
||||
<location filename="../src/interface_qt.cpp" line="218"/>
|
||||
<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="251"/>
|
||||
<location filename="../src/interface_qt.cpp" line="261"/>
|
||||
<source>Nothing selected</source>
|
||||
<translation>Nichts ausgewählt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="252"/>
|
||||
<location filename="../src/interface_qt.cpp" line="262"/>
|
||||
<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="282"/>
|
||||
<location filename="../src/interface_qt.cpp" line="328"/>
|
||||
<source>About Whyblocked</source>
|
||||
<translation>Über Whyblocked</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="283"/>
|
||||
<location filename="../src/interface_qt.cpp" line="329"/>
|
||||
<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="306"/>
|
||||
<location filename="../src/interface_qt.cpp" line="352"/>
|
||||
<source>Receipts:</source>
|
||||
<translation>Belege:</translation>
|
||||
</message>
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="401"/>
|
||||
<location filename="../src/interface_qt.cpp" line="449"/>
|
||||
<source>Insert receipt here.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -198,89 +198,89 @@
|
|||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="285"/>
|
||||
<location filename="../src/interface_qt.cpp" line="213"/>
|
||||
<location filename="../src/interface_qt.cpp" line="223"/>
|
||||
<source>Edit entry</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="299"/>
|
||||
<location filename="../src/whyblocked.ui" line="300"/>
|
||||
<source>&Find</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="302"/>
|
||||
<location filename="../src/whyblocked.ui" line="303"/>
|
||||
<source>Find entries</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="305"/>
|
||||
<location filename="../src/whyblocked.ui" line="306"/>
|
||||
<source>Ctrl+F</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="59"/>
|
||||
<location filename="../src/interface_qt.cpp" line="160"/>
|
||||
<location filename="../src/interface_qt.cpp" line="167"/>
|
||||
<source>User/Instance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="161"/>
|
||||
<location filename="../src/interface_qt.cpp" line="168"/>
|
||||
<source>Blocked/Silenced</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/whyblocked.ui" line="72"/>
|
||||
<location filename="../src/interface_qt.cpp" line="162"/>
|
||||
<location filename="../src/interface_qt.cpp" line="169"/>
|
||||
<source>Reason</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="94"/>
|
||||
<location filename="../src/interface_qt.cpp" line="101"/>
|
||||
<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="187"/>
|
||||
<location filename="../src/interface_qt.cpp" line="197"/>
|
||||
<source>blocked</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="191"/>
|
||||
<location filename="../src/interface_qt.cpp" line="201"/>
|
||||
<source>silenced</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="207"/>
|
||||
<location filename="../src/interface_qt.cpp" line="217"/>
|
||||
<source>Invalid selection</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="208"/>
|
||||
<location filename="../src/interface_qt.cpp" line="218"/>
|
||||
<source>Please select only 1 entry to edit.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="251"/>
|
||||
<location filename="../src/interface_qt.cpp" line="261"/>
|
||||
<source>Nothing selected</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="252"/>
|
||||
<location filename="../src/interface_qt.cpp" line="262"/>
|
||||
<source>Please select entries to remove.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="280"/>
|
||||
<location filename="../src/interface_qt.cpp" line="328"/>
|
||||
<source>About Whyblocked</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/interface_qt.cpp" line="281"/>
|
||||
<location filename="../src/interface_qt.cpp" line="329"/>
|
||||
<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="304"/>
|
||||
<location filename="../src/interface_qt.cpp" line="352"/>
|
||||
<source>Receipts:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
2
xdgcfg
2
xdgcfg
|
@ -1 +1 @@
|
|||
Subproject commit 6c0976baa74f959ed3218af56e56ff58202a5a05
|
||||
Subproject commit e22f82fc6f1c40cda3d3ce5e671299f26f622528
|
Loading…
Reference in New Issue