Browse Source

Added find function

tags/0.13.0
tastytea 11 months ago
parent
commit
dd83e11338
Signed by: tastytea <tastytea@tastytea.de> GPG Key ID: CFC39497F1B26E07
9 changed files with 118 additions and 57 deletions
  1. +1
    -1
      CMakeLists.txt
  2. +61
    -13
      src/interface_qt.cpp
  3. +3
    -1
      src/interface_qt.hpp
  4. +11
    -2
      src/whyblocked.cpp
  5. +1
    -1
      src/whyblocked.hpp
  6. +4
    -2
      src/whyblocked.ui
  7. +18
    -18
      translations/whyblocked_de.ts
  8. +18
    -18
      translations/whyblocked_en.ts
  9. +1
    -1
      xdgcfg

+ 1
- 1
CMakeLists.txt View File

@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2)
project (whyblocked
VERSION 0.12.2
VERSION 0.13.0
LANGUAGES CXX
)


+ 61
- 13
src/interface_qt.cpp View File

@@ -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);
}

+ 3
- 1
src/interface_qt.hpp View File

@@ -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();

};

+ 11
- 2
src/whyblocked.cpp View File

@@ -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())
{

+ 1
- 1
src/whyblocked.hpp View File

@@ -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);
}


+ 4
- 2
src/whyblocked.ui View File

@@ -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>&amp;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>

+ 18
- 18
translations/whyblocked_de.ts View File

@@ -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>&amp;Find</source>
<translation>&amp;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>&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="306"/>
<location filename="../src/interface_qt.cpp" line="352"/>
<source>Receipts:</source>
<translation>Belege:</translation>
</message>

+ 18
- 18
translations/whyblocked_en.ts View File

@@ -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>&amp;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>&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="304"/>
<location filename="../src/interface_qt.cpp" line="352"/>
<source>Receipts:</source>
<translation type="unfinished"></translation>
</message>

+ 1
- 1
xdgcfg

@@ -1 +1 @@
Subproject commit 6c0976baa74f959ed3218af56e56ff58202a5a05
Subproject commit e22f82fc6f1c40cda3d3ce5e671299f26f622528

Loading…
Cancel
Save