Porównaj commity
52 Commity
Autor | SHA1 | Data | |
---|---|---|---|
5f19328679 | |||
5ffd7ae97e | |||
9ed28df09c | |||
69e028daf5 | |||
d4b0c1feae | |||
990888efc1 | |||
3f8c147182 | |||
ba030169aa | |||
1636e39c5b | |||
bda23670e3 | |||
d0fe51c666 | |||
a561032668 | |||
b8006bde7b | |||
614238edda | |||
83ed935790 | |||
69837ed60f | |||
2ad99699bf | |||
b6b3e2f3c0 | |||
cf0c940b15 | |||
9c41d531b0 | |||
780318db6d | |||
9fd48d4664 | |||
e99b2ba091 | |||
0867ab294d | |||
01a6a499c5 | |||
b3c6ce3899 | |||
72dae1f7be | |||
e01f5d6490 | |||
759d2a7924 | |||
a820183477 | |||
8c5825439a | |||
399c27a452 | |||
7a2e4aaec1 | |||
11decb757f | |||
b71c234fb4 | |||
bc908a1038 | |||
8ba4ee5847 | |||
451c79088a | |||
1a39118470 | |||
0d2e518000 | |||
b108cb7151 | |||
c82cf03814 | |||
8a82da95bd | |||
a408173064 | |||
dd479fa668 | |||
e76988ee77 | |||
f29f997289 | |||
afa9d33f3d | |||
fc92b963d4 | |||
9acbd5dccf | |||
87ebc137d5 | |||
67189f34c6 |
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
.user
|
||||
.o
|
||||
*.user
|
||||
*.o
|
||||
*.a
|
||||
moc_*.cpp
|
||||
moc_*.h
|
||||
Makefile
|
||||
cli/looqs
|
||||
gui/looqs-gui
|
||||
qrc_*
|
32
CHANGELOG.md
32
CHANGELOG.md
@ -1,5 +1,37 @@
|
||||
# looqs: Release notes
|
||||
|
||||
## 2022-06-29 - v0.4
|
||||
This release makes several minor improvements and begins prebuilt binaries of looqs that (should) run
|
||||
on any recent Linux distribution.
|
||||
|
||||
- General: Begin new, experimental distro-agnostic tarball containing prebuilt binaries and libs. See the README for more information.
|
||||
- GUI: In the "Previews" tab, allow filtering by file, to only show previews for a specific file.
|
||||
- GUI: Add "Show previews" context menu option to files in result (if available)
|
||||
- General: Fix build with libquazip 1.X
|
||||
- General: Properly report access errors as a failure during indexing
|
||||
- GUI: Add button to export a list of all paths that failed
|
||||
- General: Improve dir scan threading
|
||||
- CLI: Improve helptext
|
||||
- General: Add voidlinux build instructions
|
||||
|
||||
## 2022-06-14 - v0.3
|
||||
CHANGES:
|
||||
- GUI: Add settings tab to configure various settings
|
||||
- GUI: Don't render previews for results that do not originate from a content search. This was confusing.
|
||||
- GUI: Remove 'open config file' menu action
|
||||
- GUI: Highlight "words" that are actually numbers in preview texts
|
||||
- search: Search for "words" that are a number, e. g. 23. Previously, those were ignored due to a regression.
|
||||
- CLI: Minor cleanups.
|
||||
- sandbox: Improve preview generation sandbox further by restricting it more
|
||||
- sandbox: Fix case where activiation would fail during indexing in some cases on kernels without landlock.
|
||||
- Remove 'firstrun' setting
|
||||
|
||||
|
||||
## 2022-06-07 - v0.2
|
||||
CHANGES:
|
||||
- Sandboxing: Add environment variable `LOOQS_DISABLE_SANDBOXING` to disable sandboxing. This is intended for troubleshooting
|
||||
- Sandboxing: Fix issue where activation failed on kernels without landlock
|
||||
|
||||
## 2022-06-06 - v0.1
|
||||
The first release comes with basic functionality. It's a start that can be considered useful to some degree.
|
||||
|
||||
|
20
HACKING.md
20
HACKING.md
@ -3,29 +3,31 @@
|
||||
## Introduction
|
||||
Without elaborating here, I hacked looqs because I was not satisfied with the state of desktop search on Linux.
|
||||
|
||||
Originally a set of CLI python scripts, it is now written in C++ and offers a GUI made using Qt. While a "web app" would have been an option, I prefer a desktop application for something like looqs. I chose Qt because I am more familiar with it than with any other GUI framework. To my knowledge, potential alternatives like GTK do not include as many "batteries" as Qt anyway, so the job presumably would have been harder there.
|
||||
Originally a set of CLI python scripts, it is now written in C++ and offers a GUI made using Qt. While a "web app" would have been an option, I prefer a desktop application for something like looqs. I chose Qt because I am more familiar with it than with any other GUI framework. To my knowledge, potential alternatives like GTK do not include as many "batteries" as Qt anyway, so the job presumably would have been harder there,
|
||||
at least for me.
|
||||
|
||||
[CONTRIBUTING.md](CONTRIBUTING.md) contains the instructions on how to submit patches etc.
|
||||
If you are interested in how to contribute, please see the file [CONTRIBUTING.md](CONTRIBUTING.md) which contains the instructions on how to submit patches etc.
|
||||
|
||||
## Security
|
||||
The architecture ensures that the parsing of documents and the preview generation is sandboxed by [exile.h](https://github.com/quitesimpleorg/exile.h). looqs uses a multi-process architecture to achieve this.
|
||||
The architecture ensures that the parsing of documents and the preview generation is sandboxed by [exile.h](https://github.com/quitesimpleorg/exile.h). looqs uses a multi-process architecture to achieve this.
|
||||
|
||||
Qt code is considered trusted in this model. While one may critize this, it was the only practical solution. looqs uses its serialization mechanism and other classes to communicate between the non-sandboxed GUI process and the sandboxed processes.
|
||||
Qt code is considered trusted in this model. While one may critize this, it was the only practical solution. looqs uses Qt's serialization mechanism and other classes to communicate between the non-sandboxed GUI process and the sandboxed processes.
|
||||
|
||||
Set the enviornment variable `LOOQS_DISABLE_SANDBOX=1` to disable sandboxing. It's intended for troublehshooting.
|
||||
|
||||
## Database
|
||||
The heart is sqlite, with the FTS5 extensions behind the full-text search. I definitly did not
|
||||
want to run some heavy Java based solutions. I explored other options like Postgresql, I've discard them due to some limitations back then.
|
||||
The heart is sqlite, with the FTS5 extensions behind the full-text search. While FTS may not be sqlite's strong suit, I definitly did not want to run one of those oftenly recommended heavy (Java based) solutions. I explored other options like Postgresql, I've discard them due to some limitations back then.
|
||||
|
||||
Down the road, alternatives will be explored of course if sqlite should not suffice anymore.
|
||||
|
||||
## File format support
|
||||
The pdf library is libpoppler. Files such as .odt or .docx documents are opened with libquazip. The XML files in there are not parsed,
|
||||
looqs simply strips the tags and that seems to work fine so far. Naturally, this is not the "proper way", so there is room for improvement maybehere. However, those file formats are not a huge priortiy for me personally. libuchardet does encoding detection and conversion.
|
||||
looqs simply strips the tags and that seems to work fine so far. Naturally, this is not the "proper way", so there is room for improvement maybe here. However, those file formats are not a huge priortiy for me personally. libuchardet does encoding detection and conversion.
|
||||
|
||||
Naturally looqs won't be able to index and render previews for everything. Such approach would create a huge bloated binary. In the future, there will be some plugin system of some sorts, either we will load .so objects or use subprocesses.
|
||||
Naturally, looqs won't be able to index and render previews for everything. Such approach would create a huge bloated binary. In the future, there will be some plugin system of some sorts, either we will load .so objects or use subprocesses.
|
||||
|
||||
## Name
|
||||
looqs looks for files. You as the user can also look inside them. The 'k' was replaced by a 'q'. Originally wanted my projects to have "qs" (for quitesimple) in their name. While abandoned now, this got us to looqs.
|
||||
looqs looks for files. You as the user can also look inside them. The 'k' in "looks" was replaced by a 'q'. Originally, I wanted my projects to have "qs" (for quitesimple) in their name. While abandoned now, this got us to looqs.
|
||||
|
||||
|
||||
|
||||
|
1119
LICENSE-3RD-PARTY
Normal file
1119
LICENSE-3RD-PARTY
Normal file
Plik diff jest za duży
Load Diff
48
README.md
48
README.md
@ -3,8 +3,6 @@ looqs is a tool that creates a full-text search index for your files. It allows
|
||||
search terms have been found, as shown in the screenshots below.
|
||||
|
||||
## Screenshots
|
||||
The screenshots in this section may occasionally be slightly outdated, but they are usually recent enough to get an overall impression of the current state of the GUI.
|
||||
|
||||
### Preview
|
||||
looqs allow you to look inside files. It marks what you have searched for.
|
||||
|
||||
@ -28,9 +26,10 @@ There is no need to write the long form of filters. There are also booleans avai
|
||||
|
||||

|
||||
|
||||
The screenshots in this section may occasionally be slightly outdated, but they are usually recent enough to get an overall impression of the current state of the GUI.
|
||||
|
||||
## Current status
|
||||
Last version: 2022-06-06, v0.1
|
||||
Latest version: 2022-06-29, v0.4
|
||||
|
||||
Please see [Changelog](CHANGELOG.md) for a human readable list of changes.
|
||||
|
||||
@ -58,6 +57,8 @@ Linux (on amd64) is currently the main focus. Currently, I don't plan on support
|
||||
### Licence
|
||||
GPLv3.
|
||||
|
||||
For the dependencies/third-party libraries, see: LICENSE-3RD-PARTY
|
||||
|
||||
### Contributing
|
||||
Please see the [Contribution guidelines](CONTRIBUTING.md) file.
|
||||
|
||||
@ -78,6 +79,17 @@ qmake
|
||||
make
|
||||
```
|
||||
|
||||
### Void
|
||||
```
|
||||
# as root
|
||||
xbps-install qt5-devel poppler-qt5-devel quazip-qt5-devel uchardet-devel gcc make
|
||||
# as user
|
||||
git submodule init
|
||||
git submodule update
|
||||
qmake
|
||||
make
|
||||
```
|
||||
|
||||
The GUI is located in `gui/looqs-gui`, the binary for the CLI is in `cli/looqs`
|
||||
|
||||
## Packages
|
||||
@ -95,7 +107,35 @@ sudo apt-get update
|
||||
sudo apt-get install looqs
|
||||
```
|
||||
|
||||
### Prebuilt tarball (distro-agnostic) (EXPERIMENTAL)
|
||||
looqs is also distributed as a tarball containing prebuilt binaries and its library dependencies. The tarball is
|
||||
built using the Gentoo Hardened toolchain and the Qt version is smaller than what distributions usually
|
||||
include. It does not include libraries that should mess with fontrendering or the graphics stack. The binaries should run on any recent Linux distribution (requires glibc 2.34 or newer at least) and expects
|
||||
dependencies such as libGL to be provided by your distribution already (should be the case).
|
||||
|
||||
It's considered experimental for two reasons. Firstly, looqs has no updater (yet). You will have to manually check for updates. Secondly, I can't guarantee that I'll be quick with updates of the tarball specifically if the library versions become outdated between looqs updates.
|
||||
|
||||
You are therefore encouraged to use distro-native packages or to build it yourself if possible.
|
||||
|
||||
The tarball can be obtained here: https://repo.quitesimple.org/tarball/looqs
|
||||
|
||||
Quick start:
|
||||
|
||||
```
|
||||
# Verify sig, see the end of this document: gpg --verify looqs-v0.4.tar.xz.sig
|
||||
tar xf looqs-v0.4.tar.xz # Replace with the actual version you have obtained
|
||||
cd looqs-v0.4
|
||||
./looqs-gui # or ./looqs for the CLI
|
||||
```
|
||||
|
||||
An AppImage may accompany the tarball in the future.
|
||||
|
||||
|
||||
### Other distros
|
||||
I'll probably add a package for voidlinux at some point and maybe will provide a Gentoo ebuild. However, I would appreciate help for others distros. If you create a package, let me know!
|
||||
|
||||
As for distro-agnostic packages, I will also take a look into appimage / flatpak etc. and/or maybe just provide a self-contained archive.
|
||||
|
||||
### Signature verification
|
||||
Release tags can be verified with [my PGP public key](https://quitesimple.org/share/pubkey). For what little it's worth, its fingerprint is: `C342 CA02 D2EC 2E14 F3C3 D5FF 7F7B 4C08 02CD 02F2`
|
||||
|
||||
Packages can be verified with the [repo-specific public key](https://repo.quitesimple.org/repo.quitesimple.org.asc). For what little it's worth, its fingerprint is: `1B49 45B3 16B2 468A 3DAC C1E0 75EF 3FE8 D753 C8F9`
|
||||
|
10
USAGE.md
10
USAGE.md
@ -20,15 +20,12 @@ To give you some idea: At the time this section was written, 167874 files were i
|
||||
has changed.
|
||||
|
||||
## Config
|
||||
The config file is in `$HOME/.config/quitesimple.org/looqs.conf`. It will be created on first execution of the CLI or GUI
|
||||
interface. The GUI has a menu entry to quickly open this config file. This is to be considered temporary and will be removed once the GUI itself can edit all settings.
|
||||
The config file is in `$HOME/.config/quitesimple.org/looqs.conf`. It will be created on first execution of the CLI or GUI interface. Generally, you should not edit this file directly. Instead, use the "Settings" tab in the GUI.
|
||||
|
||||
Database default path: `$HOME/.local/share/quitesimple.org/looqs/looqs.sqlite`. If this does not work for
|
||||
you, move it and adjust adjust the path in the config file.
|
||||
Database default path: `$HOME/.local/share/quitesimple.org/looqs/looqs.sqlite`. If you prefer a different path, move it and adjust the path.
|
||||
|
||||
|
||||
## GUI
|
||||
The GUI is minimal at this point. Depending on what you want to do, you may need to open the config file and change the settings there. Chances are that you may not need to do that.
|
||||
|
||||
### First run
|
||||
You will be presented with an empty list. Go to the **"Index"** tab, add some directories and click **"Start indexing"**.
|
||||
@ -47,8 +44,7 @@ see this document at the end. By default, both the full path and the content are
|
||||
### Configuring PDF viewer
|
||||
It's most convenient if, when you click on a preview, the PDF reader opens the page you clicked. For that, looqs needs to know which viewer you want to launch.
|
||||
|
||||
It tries to auto detect some common viewers. You must set the value of the ```pdfviewer=``` config entry yourself if it doesn't do something you
|
||||
like, such as not opening your favorite viewer. In the command line options, "%f" represents the filepath, "%p" the page number.
|
||||
It tries to auto detect some common viewers. You must set the value in the "Settings" tab yourself if it doesn't do something you like, such as not opening your favorite viewer. In the command line options, "%f" represents the filepath, "%p" the page number.
|
||||
|
||||
### Preview tab
|
||||
The preview tab shows previews. It marks your search keywords too. Click on a preview to open the file.
|
||||
|
@ -37,6 +37,12 @@ else:unix: LIBS += -L$$OUT_PWD/../shared/ -lshared
|
||||
|
||||
LIBS += -luchardet -lpoppler-qt5 -lquazip5
|
||||
|
||||
packagesExist(quazip1-qt5) {
|
||||
PKGCONFIG += quazip1-qt5
|
||||
CONFIG += link_pkgconfig
|
||||
LIBS -= -lquazip5
|
||||
}
|
||||
|
||||
INCLUDEPATH += $$PWD/../shared
|
||||
DEPENDPATH += $$PWD/../shared
|
||||
|
||||
|
@ -47,7 +47,8 @@ int CommandAdd::handle(QStringList arguments)
|
||||
{{"t", "threads"}, "Number of threads to use.", "threads"}});
|
||||
|
||||
parser.addHelpOption();
|
||||
parser.addPositionalArgument("add", "Add paths to the index", "add [paths...]");
|
||||
parser.addPositionalArgument("add", "Add paths to the index",
|
||||
"add [paths...]. If no path is given, read from stdin, one path per line.");
|
||||
|
||||
parser.process(arguments);
|
||||
this->keepGoing = parser.isSet("continue");
|
||||
|
@ -30,6 +30,7 @@
|
||||
void printUsage(QString argv0)
|
||||
{
|
||||
qInfo() << "Usage:" << argv0 << "command";
|
||||
qInfo() << "Valid commands: add, update, delete, search, list. Each command has a --help option.";
|
||||
}
|
||||
|
||||
Command *commandFromName(QString name, SqliteDbService &dbService)
|
||||
@ -97,7 +98,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
QString file = args.at(1);
|
||||
SandboxedProcessor processor(file);
|
||||
return processor.process();
|
||||
return static_cast<int>(processor.process());
|
||||
}
|
||||
Command *cmd = commandFromName(commandName, dbService);
|
||||
if(cmd != nullptr)
|
||||
@ -116,7 +117,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::error() << "Unknown command:" << commandName << Qt::endl;
|
||||
printUsage(argv0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
74
gui/aboutdialog.cpp
Normal file
74
gui/aboutdialog.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QTextBrowser>
|
||||
#include <QPushButton>
|
||||
#include "aboutdialog.h"
|
||||
#include "common.h"
|
||||
|
||||
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QTabWidget *tabWidget = new QTabWidget(this);
|
||||
|
||||
this->setWindowTitle("About looqs");
|
||||
|
||||
QHBoxLayout *closeLayout = new QHBoxLayout();
|
||||
QPushButton *closeButton = new QPushButton(this);
|
||||
closeButton->setText("Close");
|
||||
closeButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
connect(closeButton, &QPushButton::clicked, this, &QDialog::close);
|
||||
|
||||
closeLayout->setMargin(10);
|
||||
closeLayout->addStretch(10);
|
||||
closeLayout->addWidget(closeButton);
|
||||
|
||||
layout->addWidget(tabWidget);
|
||||
layout->addLayout(closeLayout);
|
||||
QFrame *frame = new QFrame(this);
|
||||
QVBoxLayout *aboutLayout = new QVBoxLayout(frame);
|
||||
frame->setLayout(aboutLayout);
|
||||
|
||||
QLabel *aboutLooqs = new QLabel(this);
|
||||
QString html = "<h2>looqs</h2>";
|
||||
html += "Full-text search with previews for your files<br><br>";
|
||||
html += "Copyright (c) 2018-2022: Albert Schwarzkopf<br><br>";
|
||||
html += QString("Version: %1<br><br>").arg(Common::versionText());
|
||||
html += "Contact: looqs at quitesimple dot org<br><br>";
|
||||
html += "Website: <a href=\"https://quitesimple.org\">https://quitesimple.org</a><br><br>";
|
||||
html += "Source code: <a "
|
||||
"href=\"https://github.com/quitesimpleorg/looqs\">https://github.com/quitesimpleorg/looqs</a><br><br>";
|
||||
html += "License: GPLv3<br><br>";
|
||||
html += "looqs is open source and free of charge in the hope it will be useful. The author(s) do not "
|
||||
"give any warranty. In the unlikely event of any damage, the author(s) cannot be held responsible. "
|
||||
"You are using looqs at your own risk<br><br>";
|
||||
html += "looqs uses third-party libraries, please see the corresponding tab.";
|
||||
aboutLooqs->setText(html);
|
||||
aboutLooqs->setTextFormat(Qt::RichText);
|
||||
|
||||
QLabel *logo = new QLabel(this);
|
||||
QImage image(QString(":/looqs.svg"));
|
||||
logo->setPixmap(QPixmap::fromImage(image));
|
||||
|
||||
aboutLayout->addWidget(logo);
|
||||
aboutLayout->addWidget(aboutLooqs);
|
||||
|
||||
tabWidget->addTab(frame, "About");
|
||||
|
||||
QFile license(QString(":/LICENSE"));
|
||||
license.open(QIODevice::ReadOnly);
|
||||
QString licenseText = license.readAll();
|
||||
|
||||
QFile thirdPartyLicense(QString(":./LICENSE-3RD-PARTY"));
|
||||
thirdPartyLicense.open(QIODevice::ReadOnly);
|
||||
QString thirdPartyLicenseInfo = thirdPartyLicense.readAll();
|
||||
|
||||
QTextBrowser *licenseTextBrowser = new QTextBrowser(this);
|
||||
licenseTextBrowser->setText(licenseText);
|
||||
|
||||
QTextBrowser *thirdPartyLicenceTextBrowser = new QTextBrowser(this);
|
||||
thirdPartyLicenceTextBrowser->setText(thirdPartyLicenseInfo);
|
||||
|
||||
tabWidget->addTab(licenseTextBrowser, "License");
|
||||
tabWidget->addTab(thirdPartyLicenceTextBrowser, "Third-party libraries");
|
||||
}
|
12
gui/aboutdialog.h
Normal file
12
gui/aboutdialog.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef ABOUTDIALOG_H
|
||||
#define ABOUTDIALOG_H
|
||||
#include <QDialog>
|
||||
|
||||
class AboutDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AboutDialog(QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // ABOUTDIALOG_H
|
12
gui/gui.pro
12
gui/gui.pro
@ -7,7 +7,11 @@
|
||||
QT += core concurrent gui network
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++17
|
||||
|
||||
|
||||
|
||||
TARGET = looqs-gui
|
||||
TEMPLATE = app
|
||||
|
||||
@ -23,6 +27,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
aboutdialog.cpp \
|
||||
ipcpreviewclient.cpp \
|
||||
ipcpreviewworker.cpp \
|
||||
ipcserver.cpp \
|
||||
@ -40,6 +45,7 @@ SOURCES += \
|
||||
rendertarget.cpp
|
||||
|
||||
HEADERS += \
|
||||
aboutdialog.h \
|
||||
ipc.h \
|
||||
ipcpreviewclient.h \
|
||||
ipcpreviewworker.h \
|
||||
@ -69,6 +75,12 @@ else:unix: LIBS += -L$$OUT_PWD/../shared/ -lshared
|
||||
|
||||
LIBS += -luchardet -lpoppler-qt5 -lquazip5
|
||||
|
||||
packagesExist(quazip1-qt5) {
|
||||
PKGCONFIG += quazip1-qt5
|
||||
CONFIG += link_pkgconfig
|
||||
LIBS -= -lquazip5
|
||||
}
|
||||
|
||||
INCLUDEPATH += $$PWD/../shared
|
||||
DEPENDPATH += $$PWD/../shared
|
||||
|
||||
|
56
gui/main.cpp
56
gui/main.cpp
@ -23,25 +23,51 @@ void enableIpcSandbox()
|
||||
qCritical() << "Failed to init policy for sandbox";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
policy->namespace_options = EXILE_UNSHARE_NETWORK | EXILE_UNSHARE_USER;
|
||||
policy->namespace_options = EXILE_UNSHARE_USER | EXILE_UNSHARE_MOUNT | EXILE_UNSHARE_NETWORK;
|
||||
policy->no_new_privs = 1;
|
||||
policy->drop_caps = 1;
|
||||
policy->vow_promises =
|
||||
exile_vows_from_str("thread cpath wpath rpath unix stdio prot_exec proc shm fsnotify ioctl error");
|
||||
policy->vow_promises = exile_vows_from_str("thread cpath rpath unix stdio proc error");
|
||||
policy->mount_path_policies_to_chroot = 1;
|
||||
|
||||
QString ipcSocketPath = Common::ipcSocketPath();
|
||||
QFileInfo info{ipcSocketPath};
|
||||
QString ipcSocketPathDir = info.absolutePath();
|
||||
std::string stdIpcSocketPath = ipcSocketPathDir.toStdString();
|
||||
|
||||
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ, "/");
|
||||
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, stdIpcSocketPath.c_str());
|
||||
/* we only need the 'server' side of the 'unix' vow (for unix sockets)'. The process
|
||||
* has no business to connect anywhere.
|
||||
*
|
||||
* Maybe this case should be handled by exile at some point, but for now deal with it here */
|
||||
exile_append_syscall_policy(policy, EXILE_SYS(connect), EXILE_SYSCALL_DENY_RET_ERROR, NULL, 0);
|
||||
|
||||
/* ALLOW_EXEC is needed for fallback, not in landlock mode. It does not allow executing anything though here
|
||||
* due to the vows */
|
||||
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_EXEC, "/");
|
||||
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE | EXILE_FS_ALLOW_EXEC,
|
||||
stdIpcSocketPath.c_str());
|
||||
int ret = exile_enable_policy(policy);
|
||||
if(ret != 0)
|
||||
{
|
||||
qDebug() << "Failed to establish sandbox";
|
||||
qDebug() << "Failed to establish sandbox" << Qt::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Arguments are irrelevant for sandbox test, just want to silence analyzer/compiler warnings */
|
||||
ret = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(ret != -1 || errno != EACCES)
|
||||
{
|
||||
qCritical() << "Sandbox sanity check failed" << Qt::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const struct sockaddr *addr = {};
|
||||
ret = connect(3, addr, sizeof(*addr));
|
||||
if(ret != -1 || errno != EACCES)
|
||||
{
|
||||
qCritical() << "Sandbox sanity check failed" << Qt::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
exile_free_policy(policy);
|
||||
}
|
||||
|
||||
@ -54,14 +80,21 @@ int main(int argc, char *argv[])
|
||||
if(arg == "ipc")
|
||||
{
|
||||
Common::setupAppInfo();
|
||||
enableIpcSandbox();
|
||||
QApplication a(argc, argv);
|
||||
if(Common::noSandboxModeRequested())
|
||||
{
|
||||
qInfo() << "Launching with no sandbox!" << Qt::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
enableIpcSandbox();
|
||||
}
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
IpcServer *ipcserver = new IpcServer();
|
||||
qDebug() << "Launching IPC Server";
|
||||
if(!ipcserver->startSpawner(socketPath))
|
||||
{
|
||||
qCritical() << "Error failed to spawn";
|
||||
qCritical() << "Error failed to spawn" << Qt::endl;
|
||||
return 1;
|
||||
}
|
||||
qDebug() << "Launched IPC Server";
|
||||
@ -81,7 +114,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
QString file = args.at(2);
|
||||
SandboxedProcessor processor(file);
|
||||
return processor.process();
|
||||
return static_cast<int>(processor.process());
|
||||
}
|
||||
}
|
||||
QString ipcSocketPath = Common::ipcSocketPath();
|
||||
@ -109,7 +142,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
Common::setupAppInfo();
|
||||
QCommandLineParser parser;
|
||||
parser.addOption({{"s", "no-sandbox"}, "Disable sandboxing"});
|
||||
QStringList appArgs;
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
@ -117,6 +149,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
parser.parse(appArgs);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
try
|
||||
{
|
||||
Common::ensureConfigured();
|
||||
@ -127,7 +160,6 @@ int main(int argc, char *argv[])
|
||||
QMessageBox::critical(nullptr, "Error", e.message);
|
||||
return 1;
|
||||
}
|
||||
QApplication a(argc, argv);
|
||||
a.setWindowIcon(QIcon(":/looqs.svg"));
|
||||
QObject::connect(&a, &QApplication::aboutToQuit, &process, &QProcess::kill);
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "../shared/common.h"
|
||||
#include "ipcpreviewclient.h"
|
||||
#include "previewgenerator.h"
|
||||
#include "aboutdialog.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent, QString socketPath)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow), progressDialog(this)
|
||||
@ -40,6 +41,7 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath)
|
||||
{
|
||||
this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->maximum());
|
||||
this->ui->spinPreviewPage->setEnabled(true);
|
||||
this->ui->comboPreviewFiles->setEnabled(true);
|
||||
});
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::error, this,
|
||||
[this](QString msg)
|
||||
@ -82,6 +84,13 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath)
|
||||
|
||||
ui->spinPreviewPage->setValue(1);
|
||||
ui->spinPreviewPage->setMinimum(1);
|
||||
|
||||
ui->btnOpenFailed->setVisible(false);
|
||||
ui->comboPreviewFiles->setVisible(false);
|
||||
|
||||
auto policy = ui->btnOpenFailed->sizePolicy();
|
||||
policy.setRetainSizeWhenHidden(true);
|
||||
ui->btnOpenFailed->setSizePolicy(policy);
|
||||
}
|
||||
|
||||
void MainWindow::addPathToIndex()
|
||||
@ -172,31 +181,12 @@ void MainWindow::connectSignals()
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(
|
||||
ui->menuAboutAction, &QAction::triggered, this,
|
||||
[this](bool checked)
|
||||
{
|
||||
QString html = "<h2>looqs</h2>";
|
||||
html += "Full-text search with previews for your files<br><br>";
|
||||
html += "Copyright (c) 2018-2022: Albert Schwarzkopf<br><br>";
|
||||
html += QString("Version: %1<br><br>").arg(Common::versionText());
|
||||
html += "Contact: looqs at quitesimple dot org<br><br>";
|
||||
html += "Website: <a href=\"https://quitesimple.org\">https://quitesimple.org</a><br><br>";
|
||||
html +=
|
||||
"Source code: <a "
|
||||
"href=\"https://github.com/quitesimpleorg/looqs\">https://github.com/quitesimpleorg/looqs</a><br><br>";
|
||||
html += "License: GPLv3<br><br><br>";
|
||||
html += "looqs is open source and free of charge in the hope it will be useful. The author(s) do not "
|
||||
"give any warranty. In the unlikely event of any damage, the author(s) cannot be held responsible. "
|
||||
"You are using looqs at your own risk";
|
||||
|
||||
QMessageBox::about(this, "About looqs", html);
|
||||
});
|
||||
connect(ui->menuOpenConfigInTextEditorAction, &QAction::triggered, this,
|
||||
connect(ui->menuAboutAction, &QAction::triggered, this,
|
||||
[this](bool checked)
|
||||
{
|
||||
QSettings setting;
|
||||
QDesktopServices::openUrl(setting.fileName());
|
||||
AboutDialog aboutDialog(this);
|
||||
|
||||
aboutDialog.exec();
|
||||
});
|
||||
connect(ui->menuAboutQtAction, &QAction::triggered, this,
|
||||
[this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); });
|
||||
@ -215,6 +205,36 @@ void MainWindow::connectSignals()
|
||||
});
|
||||
connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync);
|
||||
connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel);
|
||||
connect(ui->btnSaveSettings, &QPushButton::clicked, this, &MainWindow::saveSettings);
|
||||
connect(ui->btnOpenFailed, &QPushButton::clicked, this, &MainWindow::exportFailedPaths);
|
||||
connect(
|
||||
ui->comboPreviewFiles, qOverload<int>(&QComboBox::currentIndexChanged), this, [&]() { makePreviews(1); },
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void MainWindow::exportFailedPaths()
|
||||
{
|
||||
|
||||
QString filename =
|
||||
QString("/tmp/looqs_indexresult_failed_%1").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss"));
|
||||
QFile outFile(filename);
|
||||
if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
QMessageBox::critical(this, "Failed to write log file", "An error occured while trying to create log file");
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream stream(&outFile);
|
||||
|
||||
IndexResult result = this->indexer->getResult();
|
||||
|
||||
stream << "Failed to index the following paths:\n";
|
||||
for(FileScanResult &fsr : result.failedResults())
|
||||
{
|
||||
stream << fsr.first << " " << SaveFileResultToString(fsr.second) << '\n';
|
||||
}
|
||||
|
||||
QDesktopServices::openUrl(filename);
|
||||
}
|
||||
|
||||
void MainWindow::startIndexSync()
|
||||
@ -236,6 +256,7 @@ void MainWindow::startIndexSync()
|
||||
|
||||
emit beginIndexSync();
|
||||
}
|
||||
|
||||
void MainWindow::spinPreviewPageValueChanged(int val)
|
||||
{
|
||||
makePreviews(val);
|
||||
@ -253,10 +274,12 @@ void MainWindow::startIndexing()
|
||||
|
||||
ui->previewsTab->setEnabled(false);
|
||||
ui->resultsTab->setEnabled(false);
|
||||
ui->settingsTab->setEnabled(false);
|
||||
ui->txtPathScanAdd->setEnabled(false);
|
||||
ui->txtSearch->setEnabled(false);
|
||||
ui->previewProcessBar->setValue(0);
|
||||
ui->previewProcessBar->setVisible(true);
|
||||
ui->btnOpenFailed->setVisible(false);
|
||||
|
||||
QVector<QString> paths;
|
||||
QStringList pathSettingsValue;
|
||||
@ -289,8 +312,13 @@ void MainWindow::finishIndexing()
|
||||
ui->btnStartIndexing->setText("Start indexing");
|
||||
ui->previewsTab->setEnabled(true);
|
||||
ui->resultsTab->setEnabled(true);
|
||||
ui->settingsTab->setEnabled(true);
|
||||
ui->txtPathScanAdd->setEnabled(true);
|
||||
ui->txtSearch->setEnabled(true);
|
||||
if(result.erroredPaths > 0)
|
||||
{
|
||||
ui->btnOpenFailed->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::comboScaleChanged(int i)
|
||||
@ -351,6 +379,49 @@ void MainWindow::tabChanged()
|
||||
makePreviews(ui->spinPreviewPage->value());
|
||||
}
|
||||
}
|
||||
/* Settings tab active */
|
||||
if(ui->tabWidget->currentIndex() == 3)
|
||||
{
|
||||
initSettingsTabs();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::initSettingsTabs()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QString pdfViewerCmd = settings.value(SETTINGS_KEY_PDFVIEWER).toString();
|
||||
QString excludedPaths = Common::excludedPaths().join(';');
|
||||
QString mountPaths = Common::mountPaths().join(';');
|
||||
QString databasePath = Common::databasePath();
|
||||
int numPagesPerPreview = settings.value(SETTINGS_KEY_PREVIEWSPERPAGE, 20).toInt();
|
||||
|
||||
ui->txtSettingPdfPreviewerCmd->setText(pdfViewerCmd);
|
||||
ui->txtSettingIgnoredPaths->setText(excludedPaths);
|
||||
ui->txtSettingMountPaths->setText(mountPaths);
|
||||
ui->spinSettingNumerPerPages->setValue(numPagesPerPreview);
|
||||
ui->txtSettingDatabasePath->setText(databasePath);
|
||||
}
|
||||
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QString pdfViewerCmd = ui->txtSettingPdfPreviewerCmd->text();
|
||||
QStringList excludedPaths = ui->txtSettingIgnoredPaths->text().split(';');
|
||||
QStringList mountPaths = ui->txtSettingMountPaths->text().split(';');
|
||||
QString databasePath = ui->txtSettingDatabasePath->text();
|
||||
|
||||
settings.setValue(SETTINGS_KEY_PDFVIEWER, pdfViewerCmd);
|
||||
settings.setValue(SETTINGS_KEY_EXCLUDEDPATHS, excludedPaths);
|
||||
settings.setValue(SETTINGS_KEY_MOUNTPATHS, mountPaths);
|
||||
settings.setValue(SETTINGS_KEY_PREVIEWSPERPAGE, ui->spinSettingNumerPerPages->value());
|
||||
settings.setValue(SETTINGS_KEY_DBPATH, databasePath);
|
||||
|
||||
settings.sync();
|
||||
|
||||
QProcess::startDetached(qApp->arguments()[0], qApp->arguments().mid(1));
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview, unsigned int previewGeneration)
|
||||
@ -389,7 +460,7 @@ void MainWindow::lineEditReturnPressed()
|
||||
ui->lblSearchResults->setText("Invalid paranthesis");
|
||||
return;
|
||||
}
|
||||
if(indexerTabActive())
|
||||
if(ui->tabWidget->currentIndex() > 1)
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
}
|
||||
@ -436,6 +507,9 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
||||
{
|
||||
this->previewableSearchResults.clear();
|
||||
ui->treeResultsList->clear();
|
||||
ui->comboPreviewFiles->clear();
|
||||
ui->comboPreviewFiles->addItem("All previews");
|
||||
ui->comboPreviewFiles->setVisible(true);
|
||||
|
||||
bool hasDeleted = false;
|
||||
for(const SearchResult &result : results)
|
||||
@ -454,11 +528,17 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
||||
bool exists = pathInfo.exists();
|
||||
if(exists)
|
||||
{
|
||||
if(!result.wasContentSearch)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!pathInfo.suffix().contains("htm")) // hack until we can preview them properly...
|
||||
{
|
||||
if(PreviewGenerator::get(pathInfo) != nullptr)
|
||||
{
|
||||
this->previewableSearchResults.append(result);
|
||||
ui->comboPreviewFiles->addItem(result.fileData.absPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,7 +582,7 @@ void MainWindow::makePreviews(int page)
|
||||
scaleText.chop(1);
|
||||
|
||||
QVector<QString> wordsToHighlight;
|
||||
QRegularExpression extractor(R"#("([^"]*)"|(\p{L}+))#");
|
||||
QRegularExpression extractor(R"#("([^"]*)"|((\p{L}|\p{N})+))#");
|
||||
for(const Token &token : this->contentSearchQuery.getTokens())
|
||||
{
|
||||
if(token.type == FILTER_CONTENT_CONTAINS)
|
||||
@ -536,6 +616,13 @@ void MainWindow::makePreviews(int page)
|
||||
QVector<RenderTarget> targets;
|
||||
for(SearchResult &sr : this->previewableSearchResults)
|
||||
{
|
||||
if(ui->comboPreviewFiles->currentIndex() != 0)
|
||||
{
|
||||
if(sr.fileData.absPath != ui->comboPreviewFiles->currentText())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
RenderTarget renderTarget;
|
||||
renderTarget.path = sr.fileData.absPath;
|
||||
|
||||
@ -556,6 +643,7 @@ void MainWindow::makePreviews(int page)
|
||||
ui->previewProcessBar->setVisible(this->previewableSearchResults.size() > 0);
|
||||
++this->currentPreviewGeneration;
|
||||
this->ui->spinPreviewPage->setEnabled(false);
|
||||
this->ui->comboPreviewFiles->setEnabled(false);
|
||||
emit startIpcPreviews(renderConfig, targets);
|
||||
}
|
||||
|
||||
@ -571,6 +659,20 @@ void MainWindow::createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo)
|
||||
menu.addAction("Copy full path to clipboard",
|
||||
[&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.absoluteFilePath()); });
|
||||
menu.addAction("Open containing folder", [this, &fileInfo] { this->openFile(fileInfo.absolutePath()); });
|
||||
|
||||
auto result =
|
||||
std::find_if(this->previewableSearchResults.begin(), this->previewableSearchResults.end(),
|
||||
[this, &fileInfo](SearchResult &a) { return fileInfo.absoluteFilePath() == a.fileData.absPath; });
|
||||
|
||||
if(result != this->previewableSearchResults.end())
|
||||
{
|
||||
menu.addAction("Show previews for this file",
|
||||
[this, &fileInfo]
|
||||
{
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
this->ui->comboPreviewFiles->setCurrentText(fileInfo.absoluteFilePath());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openDocument(QString path, int num)
|
||||
|
@ -61,6 +61,7 @@ class MainWindow : public QMainWindow
|
||||
void openDocument(QString path, int num);
|
||||
void openFile(QString path);
|
||||
unsigned int currentPreviewGeneration = 1;
|
||||
void initSettingsTabs();
|
||||
private slots:
|
||||
void lineEditReturnPressed();
|
||||
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
||||
@ -73,6 +74,8 @@ class MainWindow : public QMainWindow
|
||||
void finishIndexing();
|
||||
void addPathToIndex();
|
||||
void startIndexSync();
|
||||
void saveSettings();
|
||||
void exportFailedPaths();
|
||||
|
||||
signals:
|
||||
void startIpcPreviews(RenderConfig config, const QVector<RenderTarget> &targets);
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1221</width>
|
||||
<height>709</height>
|
||||
<width>1280</width>
|
||||
<height>855</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -27,7 +27,7 @@
|
||||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="resultsTab">
|
||||
<attribute name="title">
|
||||
@ -81,8 +81,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1185</width>
|
||||
<height>419</height>
|
||||
<width>1244</width>
|
||||
<height>565</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||
@ -162,6 +162,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboPreviewFiles">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
@ -184,6 +194,16 @@
|
||||
<string>Index</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="6" column="0">
|
||||
<widget class="QLineEdit" name="txtIgnorePatterns"/>
|
||||
</item>
|
||||
<item row="11" column="0">
|
||||
<widget class="QPushButton" name="btnStartIndexing">
|
||||
<property name="text">
|
||||
<string>Start indexing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBoxPaths">
|
||||
<property name="title">
|
||||
@ -243,6 +263,12 @@
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblPathsFound">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Paths found:</string>
|
||||
</property>
|
||||
@ -250,17 +276,42 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblPathsFoundValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblAdded">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
@ -274,17 +325,42 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblAddedValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSkipped">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
@ -298,17 +374,42 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSkippedValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblFailed">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
@ -322,23 +423,171 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblFailedValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnOpenFailed">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open log of failed paths</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLineEdit" name="txtIgnorePatterns"/>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="settingsTab">
|
||||
<attribute name="title">
|
||||
<string>Settings</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupPdfSettings">
|
||||
<property name="title">
|
||||
<string>PDF Viewer</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Command to open PDF pages in (%f = file path; %p = page number)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtSettingPdfPreviewerCmd"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<widget class="QPushButton" name="btnStartIndexing">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupMountPaths">
|
||||
<property name="title">
|
||||
<string>Mount paths</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblMountPaths">
|
||||
<property name="text">
|
||||
<string>Path prefixes of files that should not be removed during sync, even if they cannot be accessed (e . g. files indexed on external disks) . Separated by ;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtSettingMountPaths"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Ignored paths</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Path prefixes that should always be ignored during indexing (will be applied before the ignore patterns). Separated by ;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtSettingIgnoredPaths"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupSettingDatabasePath">
|
||||
<property name="title">
|
||||
<string>Database path</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_10">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSettingDatabasePath">
|
||||
<property name="text">
|
||||
<string>Path of the database. Note: Changing it here will create an empty, new database. The old will not be moved. </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtSettingDatabasePath"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="Misc">
|
||||
<property name="title">
|
||||
<string>Misc</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Max number of previews per 'page' in 'Previews' tab: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinSettingNumerPerPages"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSaveSettings">
|
||||
<property name="text">
|
||||
<string>Start indexing</string>
|
||||
<string>Save settings and restart</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -368,7 +617,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1221</width>
|
||||
<width>1280</width>
|
||||
<height>35</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -376,7 +625,6 @@
|
||||
<property name="title">
|
||||
<string>looqs</string>
|
||||
</property>
|
||||
<addaction name="menuOpenConfigInTextEditorAction"/>
|
||||
<addaction name="menuSyncIndexAction"/>
|
||||
<addaction name="menuAboutAction"/>
|
||||
<addaction name="menuAboutQtAction"/>
|
||||
@ -389,11 +637,6 @@
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menuOpenConfigInTextEditorAction">
|
||||
<property name="text">
|
||||
<string>Open config in text editor</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menuAboutQtAction">
|
||||
<property name="text">
|
||||
<string>About Qt</string>
|
||||
|
@ -14,16 +14,10 @@
|
||||
#include "databasefactory.h"
|
||||
#include "logger.h"
|
||||
|
||||
#define SETTINGS_KEY_DBPATH "dbpath"
|
||||
#define SETTINGS_KEY_FIRSTRUN "firstrun"
|
||||
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
||||
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
||||
#define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths"
|
||||
#define SETTINGS_KEY_MOUNTPATHS "mountpaths"
|
||||
|
||||
inline void initResources()
|
||||
{
|
||||
Q_INIT_RESOURCE(migrations);
|
||||
Q_INIT_RESOURCE(plaintexts);
|
||||
}
|
||||
|
||||
bool Common::initSqliteDatabase(QString path)
|
||||
@ -75,11 +69,11 @@ void Common::setPdfViewer()
|
||||
}
|
||||
else if(evincePath != "")
|
||||
{
|
||||
value = evincePath + "-i %p %f";
|
||||
value = evincePath + " -i %p %f";
|
||||
}
|
||||
else if(qpdfviewPath != "")
|
||||
{
|
||||
value = qpdfviewPath + "%f#%p";
|
||||
value = qpdfviewPath + " %f#%p";
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
@ -91,10 +85,10 @@ void Common::setPdfViewer()
|
||||
void Common::ensureConfigured()
|
||||
{
|
||||
QSettings settings;
|
||||
QVariant firstRun = settings.value(SETTINGS_KEY_FIRSTRUN);
|
||||
if(!firstRun.isValid())
|
||||
QString dbpath = databasePath();
|
||||
if(dbpath == "")
|
||||
{
|
||||
QString dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
||||
dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
||||
QDir dir;
|
||||
if(!dir.exists(dbpath))
|
||||
{
|
||||
@ -104,38 +98,34 @@ void Common::ensureConfigured()
|
||||
}
|
||||
}
|
||||
dbpath += "/looqs.sqlite";
|
||||
}
|
||||
if(!QFile::exists(dbpath))
|
||||
{
|
||||
if(!initSqliteDatabase(dbpath))
|
||||
{
|
||||
throw LooqsGeneralException("Failed to initialize sqlite database");
|
||||
}
|
||||
|
||||
settings.setValue(SETTINGS_KEY_FIRSTRUN, false);
|
||||
settings.setValue(SETTINGS_KEY_DBPATH, dbpath);
|
||||
setPdfViewer();
|
||||
}
|
||||
else
|
||||
DatabaseFactory factory{dbpath};
|
||||
auto db = factory.forCurrentThread();
|
||||
DBMigrator migrator{db};
|
||||
if(migrator.migrationNeeded())
|
||||
{
|
||||
|
||||
QString dbpath = databasePath();
|
||||
if(!QFile::exists(dbpath))
|
||||
{
|
||||
throw LooqsGeneralException("Database " + dbpath + " was not found");
|
||||
}
|
||||
DatabaseFactory factory{dbpath};
|
||||
auto db = factory.forCurrentThread();
|
||||
DBMigrator migrator{db};
|
||||
if(migrator.migrationNeeded())
|
||||
{
|
||||
QFile out;
|
||||
out.open(stderr, QIODevice::WriteOnly);
|
||||
Logger migrationLogger{&out};
|
||||
migrationLogger << "Database is being upgraded, please be patient..." << Qt::endl;
|
||||
QObject::connect(&migrator, &DBMigrator::migrationDone,
|
||||
[&migrationLogger](uint32_t migration)
|
||||
{ migrationLogger << "Progress: Successfully migrated to: " << migration << Qt::endl; });
|
||||
migrator.performMigrations();
|
||||
migrationLogger << "Database upgraded successfully" << Qt::endl;
|
||||
}
|
||||
QFile out;
|
||||
out.open(stderr, QIODevice::WriteOnly);
|
||||
Logger migrationLogger{&out};
|
||||
migrationLogger << "Database is being upgraded, please be patient..." << Qt::endl;
|
||||
QObject::connect(&migrator, &DBMigrator::migrationDone,
|
||||
[&migrationLogger](uint32_t migration)
|
||||
{ migrationLogger << "Progress: Successfully migrated to: " << migration << Qt::endl; });
|
||||
migrator.performMigrations();
|
||||
migrationLogger << "Database upgraded successfully" << Qt::endl;
|
||||
}
|
||||
QVariant pdfViewer = settings.value(SETTINGS_KEY_PDFVIEWER);
|
||||
if(!pdfViewer.isValid())
|
||||
{
|
||||
setPdfViewer();
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,6 +147,16 @@ QString Common::databasePath()
|
||||
return env;
|
||||
}
|
||||
|
||||
bool Common::noSandboxModeRequested()
|
||||
{
|
||||
QString env = getenv("LOOQS_DISABLE_SANDBOX");
|
||||
if(env == "1")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString Common::ipcSocketPath()
|
||||
{
|
||||
return "/tmp/.looqs/looqs-ipc-socket";
|
||||
@ -166,19 +166,18 @@ QString Common::ipcSocketPath()
|
||||
// return settings.value(SETTINGS_KEY_IPCSOCKETPATH, "/tmp/.looqs/looqs-ipc-socket").toString();
|
||||
}
|
||||
|
||||
static QStringList excludedPaths = {"/proc", "/sys", "/dev", "/tmp", "/var/run", "/run"};
|
||||
|
||||
QStringList Common::excludedPaths()
|
||||
{
|
||||
static int ran = false;
|
||||
static QStringList excludedPaths;
|
||||
if(!ran)
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList userExcludedPaths = settings.value(SETTINGS_KEY_EXCLUDEDPATHS).toStringList();
|
||||
QStringList defaults{"/proc", "/sys", "/dev", "/tmp", "/var/run", "/run"};
|
||||
excludedPaths = settings.value(SETTINGS_KEY_EXCLUDEDPATHS, defaults).toStringList();
|
||||
ran = true;
|
||||
::excludedPaths.append(userExcludedPaths);
|
||||
}
|
||||
return ::excludedPaths;
|
||||
return excludedPaths;
|
||||
}
|
||||
|
||||
QStringList Common::mountPaths()
|
||||
|
@ -2,6 +2,14 @@
|
||||
#define COMMON_H
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
|
||||
#define SETTINGS_KEY_DBPATH "dbpath"
|
||||
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
||||
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
||||
#define SETTINGS_KEY_EXCLUDEDPATHS "excludedpaths"
|
||||
#define SETTINGS_KEY_MOUNTPATHS "mountpaths"
|
||||
#define SETTINGS_KEY_PREVIEWSPERPAGE "previewsPerPage"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
void setupAppInfo();
|
||||
@ -15,6 +23,7 @@ QStringList excludedPaths();
|
||||
QStringList mountPaths();
|
||||
bool isTextFile(QFileInfo fileInfo);
|
||||
bool isMountPath(QString path);
|
||||
bool noSandboxModeRequested();
|
||||
QString versionText();
|
||||
} // namespace Common
|
||||
#endif
|
||||
|
@ -19,9 +19,12 @@ void DirScanWorker::run()
|
||||
QString path;
|
||||
/* TODO: if we have e. g. only one path, then only one thread will scan this path.
|
||||
*
|
||||
* Thus, we must resubmit to the queue directories so other threads can help
|
||||
the current one (requires a new logic for threads in ParallelDirScanner). Alterantively,
|
||||
start new DirScanWorkers ourselves here... */
|
||||
* Thus, we must submit new directory paths to the queue so other threads can help
|
||||
the current one.
|
||||
|
||||
It also may not be guaranteed enqueuing new paths is faster than just scanning them,
|
||||
at least not for dirs with a small number of files
|
||||
*/
|
||||
while(queue->dequeue(path))
|
||||
{
|
||||
if(wildcardMatcher.match(path))
|
||||
|
@ -87,6 +87,10 @@ int FileSaver::processFiles(const QVector<QString> paths, std::function<SaveFile
|
||||
{
|
||||
Logger::info() << "Saved" << path << Qt::endl;
|
||||
}
|
||||
else if(result == OK_WASEMPTY)
|
||||
{
|
||||
Logger::info() << "Saved (but content was empty)" << path << Qt::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -98,7 +102,12 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
||||
QVector<PageData> pageData;
|
||||
QString canonicalPath = fileInfo.canonicalFilePath();
|
||||
|
||||
int status = -1;
|
||||
int processorReturnCode = -1;
|
||||
|
||||
if(!fileInfo.isReadable())
|
||||
{
|
||||
return NOACCESS;
|
||||
}
|
||||
|
||||
if(!fileInfo.exists())
|
||||
{
|
||||
@ -115,44 +124,45 @@ SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
QProcess process;
|
||||
QStringList args;
|
||||
args << "process" << canonicalPath;
|
||||
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||
process.start("/proc/self/exe", args);
|
||||
process.waitForStarted();
|
||||
process.waitForFinished();
|
||||
|
||||
/* TODO: This is suboptimal as it eats lots of mem
|
||||
* but avoids a weird QDataStream/QProcess behaviour
|
||||
* where it thinks the process has ended when it has not...
|
||||
*
|
||||
* Also, there seem to be issues with reads not being blocked, so
|
||||
* the only reliable way appears to be waiting until the process
|
||||
* finishes.
|
||||
*/
|
||||
QDataStream in(process.readAllStandardOutput());
|
||||
while(!in.atEnd())
|
||||
if(fileInfo.size() > 0)
|
||||
{
|
||||
PageData pd;
|
||||
in >> pd;
|
||||
pageData.append(pd);
|
||||
}
|
||||
status = process.exitCode();
|
||||
if(status != 0 && status != NOTHING_PROCESSED)
|
||||
{
|
||||
Logger::error() << "FileSaver::saveFile(): Error while processing" << canonicalPath << ":"
|
||||
<< "Exit code " << status << Qt::endl;
|
||||
QProcess process;
|
||||
QStringList args;
|
||||
args << "process" << canonicalPath;
|
||||
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||
process.start("/proc/self/exe", args);
|
||||
process.waitForStarted();
|
||||
process.waitForFinished();
|
||||
|
||||
return PROCESSFAIL;
|
||||
/* TODO: This is suboptimal as it eats lots of mem
|
||||
* but avoids a weird QDataStream/QProcess behaviour
|
||||
* where it thinks the process has ended when it has not...
|
||||
*
|
||||
* Also, there seem to be issues with reads not being blocked, so
|
||||
* the only reliable way appears to be waiting until the process
|
||||
* finishes.
|
||||
*/
|
||||
QDataStream in(process.readAllStandardOutput());
|
||||
while(!in.atEnd())
|
||||
{
|
||||
PageData pd;
|
||||
in >> pd;
|
||||
pageData.append(pd);
|
||||
}
|
||||
processorReturnCode = process.exitCode();
|
||||
if(processorReturnCode != OK && processorReturnCode != OK_WASEMPTY)
|
||||
{
|
||||
Logger::error() << "FileSaver::saveFile(): Error while processing" << canonicalPath << ":"
|
||||
<< "Exit code " << processorReturnCode << Qt::endl;
|
||||
|
||||
return static_cast<SaveFileResult>(processorReturnCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Could happen if a file corrupted for example
|
||||
if(pageData.isEmpty() && status != NOTHING_PROCESSED)
|
||||
SaveFileResult result = this->dbService->saveFile(fileInfo, pageData);
|
||||
if(result == OK && processorReturnCode == OK_WASEMPTY)
|
||||
{
|
||||
Logger::error() << "Could not get any content for " << canonicalPath << Qt::endl;
|
||||
return OK_WASEMPTY;
|
||||
}
|
||||
|
||||
return this->dbService->saveFile(fileInfo, pageData);
|
||||
return result;
|
||||
}
|
||||
|
@ -19,7 +19,21 @@ void Indexer::beginIndexing()
|
||||
QVector<QString> dirs;
|
||||
|
||||
WildcardMatcher wildcardMatcher;
|
||||
wildcardMatcher.setPatterns(this->ignorePattern);
|
||||
|
||||
QStringList ignoreList = this->ignorePattern;
|
||||
|
||||
for(QString &excludedPath : Common::excludedPaths())
|
||||
{
|
||||
QString pattern = excludedPath;
|
||||
if(!pattern.endsWith("/"))
|
||||
{
|
||||
pattern += "/";
|
||||
}
|
||||
pattern += "*";
|
||||
ignoreList.append(excludedPath);
|
||||
}
|
||||
ignoreList.append(this->ignorePattern);
|
||||
wildcardMatcher.setPatterns(ignoreList);
|
||||
for(QString &path : this->pathsToScan)
|
||||
{
|
||||
if(wildcardMatcher.match(path))
|
||||
@ -40,7 +54,7 @@ void Indexer::beginIndexing()
|
||||
if(!dirs.empty())
|
||||
{
|
||||
this->dirScanner->setPaths(dirs);
|
||||
this->dirScanner->setIgnorePatterns(this->ignorePattern);
|
||||
this->dirScanner->setIgnorePatterns(ignoreList);
|
||||
|
||||
this->dirScanner->scan();
|
||||
}
|
||||
@ -106,7 +120,7 @@ void Indexer::dirScanProgress(int current, int total)
|
||||
|
||||
void Indexer::processFileScanResult(FileScanResult result)
|
||||
{
|
||||
if(result.second == DBFAIL || result.second == PROCESSFAIL || result.second == NOTFOUND)
|
||||
if(result.second != OK || result.second != OK_WASEMPTY || result.second != SKIPPED)
|
||||
{
|
||||
this->currentIndexResult.results.append(result);
|
||||
if(!keepGoing)
|
||||
@ -124,7 +138,8 @@ void Indexer::processFileScanResult(FileScanResult result)
|
||||
}
|
||||
}
|
||||
|
||||
if(result.second == OK)
|
||||
/* TODO: OK_WASEMPTY might need a special list */
|
||||
if(result.second == OK || result.second == OK_WASEMPTY)
|
||||
{
|
||||
++this->currentIndexResult.addedPaths;
|
||||
}
|
||||
|
@ -22,19 +22,30 @@ class IndexResult
|
||||
return addedPaths + skippedPaths + erroredPaths;
|
||||
}
|
||||
|
||||
QVector<QString> failedPaths() const
|
||||
QVector<FileScanResult> failedResults() const
|
||||
{
|
||||
QVector<QString> result;
|
||||
QVector<FileScanResult> result;
|
||||
std::for_each(results.begin(), results.end(),
|
||||
[&result](FileScanResult res)
|
||||
{
|
||||
if(res.second == DBFAIL || res.second == PROCESSFAIL || res.second == NOTFOUND)
|
||||
if(res.second == DBFAIL || res.second == PROCESSFAIL || res.second == NOTFOUND ||
|
||||
res.second == NOACCESS)
|
||||
{
|
||||
result.append(res.first);
|
||||
result.append(res);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
QVector<QString> failedPaths() const
|
||||
{
|
||||
QVector<QString> result;
|
||||
|
||||
QVector<FileScanResult> results = failedResults();
|
||||
|
||||
std::for_each(results.begin(), results.end(), [&result](FileScanResult res) { result.append(res.first); });
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
class Indexer : public QObject
|
||||
|
@ -23,12 +23,12 @@ QueryType LooqsQuery::getQueryType()
|
||||
return static_cast<QueryType>(tokensMask & COMBINED);
|
||||
}
|
||||
|
||||
bool LooqsQuery::hasContentSearch()
|
||||
bool LooqsQuery::hasContentSearch() const
|
||||
{
|
||||
return (this->getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
|
||||
}
|
||||
|
||||
bool LooqsQuery::hasPathSearch()
|
||||
bool LooqsQuery::hasPathSearch() const
|
||||
{
|
||||
return (this->getTokensMask() & FILTER_PATH) == FILTER_PATH;
|
||||
}
|
||||
@ -181,8 +181,8 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
|
||||
QStringList loneWords;
|
||||
LooqsQuery result;
|
||||
QRegularExpression rx(
|
||||
"((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([\\p{L},])+)|(?<boolean>AND|OR)"
|
||||
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>[\"\\p{L}]+))");
|
||||
"((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([\\p{L}\\p{N},])+)|(?<boolean>AND|OR)"
|
||||
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>[\"\\p{L}\\p{N}]+))");
|
||||
QRegularExpressionMatchIterator i = rx.globalMatch(expression);
|
||||
auto previousWasBool = [&result] { return !result.tokens.empty() && ((result.tokens.last().type & BOOL) == BOOL); };
|
||||
auto previousWas = [&result](TokenType t) { return !result.tokens.empty() && (result.tokens.last().type == t); };
|
||||
|
@ -61,8 +61,8 @@ class LooqsQuery
|
||||
{
|
||||
this->limit = limit;
|
||||
}
|
||||
bool hasContentSearch();
|
||||
bool hasPathSearch();
|
||||
bool hasContentSearch() const;
|
||||
bool hasPathSearch() const;
|
||||
|
||||
void addSortCondition(SortCondition sc);
|
||||
static bool checkParanthesis(QString query);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <quazip5/quazip.h>
|
||||
#include <quazip5/quazipfile.h>
|
||||
#include <quazip.h>
|
||||
#include <quazipfile.h>
|
||||
#include "odtprocessor.h"
|
||||
#include "tagstripperprocessor.h"
|
||||
|
||||
|
@ -71,7 +71,35 @@ void ParallelDirScanner::scan()
|
||||
this->targetPathsQueue.clear();
|
||||
this->resultPathsQueue.clear();
|
||||
|
||||
this->targetPathsQueue.enqueue(this->paths);
|
||||
/* First scan without subdirs. This way we collect paths for the threads */
|
||||
WildcardMatcher matcher;
|
||||
matcher.setPatterns(this->ignorePatterns);
|
||||
for(QString &path : this->paths)
|
||||
{
|
||||
QDirIterator iterator(path, QStringList{}, QDir::Dirs | QDir::QDir::Files | QDir::NoDotAndDotDot);
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
QString path = iterator.next();
|
||||
if(matcher.match(path))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QFileInfo info = iterator.fileInfo();
|
||||
if(!info.isSymLink())
|
||||
{
|
||||
if(info.isDir())
|
||||
{
|
||||
this->targetPathsQueue.enqueue(info.absoluteFilePath());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->resultPathsQueue.enqueue(info.absoluteFilePath());
|
||||
this->processedPaths += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
emit this->progress(this->processedPaths, this->processedPaths);
|
||||
int threadsNum = getThreadsNum();
|
||||
if(threadsNum == 0)
|
||||
{
|
||||
|
6
shared/plaintexts.qrc
Normal file
6
shared/plaintexts.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource>
|
||||
<file>../LICENSE</file>
|
||||
<file>../LICENSE-3RD-PARTY</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -10,8 +10,6 @@ enum DataSource
|
||||
ARRAY
|
||||
};
|
||||
|
||||
#define NOTHING_PROCESSED 4
|
||||
|
||||
class Processor
|
||||
{
|
||||
public:
|
||||
|
@ -27,10 +27,15 @@ static QMap<QString, Processor *> processors{
|
||||
|
||||
void SandboxedProcessor::enableSandbox(QString readablePath)
|
||||
{
|
||||
if(Common::noSandboxModeRequested())
|
||||
{
|
||||
qInfo() << "Sandbox is disabled!" << Qt::endl;
|
||||
return;
|
||||
}
|
||||
struct exile_policy *policy = exile_init_policy();
|
||||
if(policy == NULL)
|
||||
{
|
||||
qCritical() << "Could not init exile";
|
||||
qCritical() << "Could not init exile" << Qt::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
policy->namespace_options = EXILE_UNSHARE_NETWORK | EXILE_UNSHARE_USER;
|
||||
@ -38,6 +43,8 @@ void SandboxedProcessor::enableSandbox(QString readablePath)
|
||||
std::string readablePathLocation;
|
||||
if(!readablePath.isEmpty())
|
||||
{
|
||||
policy->namespace_options |= EXILE_UNSHARE_MOUNT;
|
||||
policy->mount_path_policies_to_chroot = 1;
|
||||
readablePathLocation = readablePath.toStdString();
|
||||
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ, readablePathLocation.c_str()) != 0)
|
||||
{
|
||||
@ -73,7 +80,7 @@ void SandboxedProcessor::printResults(const QVector<PageData> &pageData)
|
||||
fsstdout.close();
|
||||
}
|
||||
|
||||
int SandboxedProcessor::process()
|
||||
SaveFileResult SandboxedProcessor::process()
|
||||
{
|
||||
QFileInfo fileInfo(this->filePath);
|
||||
Processor *processor = processors.value(fileInfo.suffix(), nullptr);
|
||||
@ -85,10 +92,14 @@ int SandboxedProcessor::process()
|
||||
processor = defaultTextProcessor;
|
||||
}
|
||||
}
|
||||
if(!fileInfo.isReadable())
|
||||
{
|
||||
return NOACCESS;
|
||||
}
|
||||
if(processor == nullptr || processor == nothingProcessor)
|
||||
{
|
||||
/* Nothing to do */
|
||||
return NOTHING_PROCESSED;
|
||||
return OK;
|
||||
}
|
||||
|
||||
QVector<PageData> pageData;
|
||||
@ -112,9 +123,9 @@ int SandboxedProcessor::process()
|
||||
catch(LooqsGeneralException &e)
|
||||
{
|
||||
Logger::error() << "SandboxedProcessor: Error while processing" << absPath << ":" << e.message << Qt::endl;
|
||||
return 3 /* PROCESSFAIL */;
|
||||
return PROCESSFAIL;
|
||||
}
|
||||
|
||||
printResults(pageData);
|
||||
return 0;
|
||||
return pageData.isEmpty() ? OK_WASEMPTY : OK;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QString>
|
||||
#include <QMimeDatabase>
|
||||
#include "pagedata.h"
|
||||
#include "savefileresult.h"
|
||||
|
||||
class SandboxedProcessor
|
||||
{
|
||||
@ -19,7 +20,7 @@ class SandboxedProcessor
|
||||
this->filePath = filepath;
|
||||
}
|
||||
|
||||
int process();
|
||||
SaveFileResult process();
|
||||
};
|
||||
|
||||
#endif // SANDBOXEDPROCESSOR_H
|
||||
|
33
shared/savefileresult.h
Normal file
33
shared/savefileresult.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef SAVEFILERESULT_H
|
||||
#define SAVEFILERESULT_H
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
enum SaveFileResult
|
||||
{
|
||||
OK,
|
||||
OK_WASEMPTY, /* The file was successfully read but no content could be extracted. Might be just an empty document or
|
||||
so*/
|
||||
SKIPPED, /* The file was not processed/saved, because it has not changed */
|
||||
DBFAIL, /* A database error occured */
|
||||
PROCESSFAIL, /* General processor failure */
|
||||
NOTFOUND, /* The file was not found */
|
||||
NOACCESS /* The process can't read the file */
|
||||
};
|
||||
|
||||
static inline QString SaveFileResultToString(SaveFileResult sfr)
|
||||
{
|
||||
QStringList SaveFileResultStr;
|
||||
|
||||
SaveFileResultStr << "OK"
|
||||
<< "OK_WASEMPTY"
|
||||
<< "SKIPPED"
|
||||
<< "DBFAIL"
|
||||
<< "PROCESSFAIL"
|
||||
<< "NOTFOUND"
|
||||
<< "NOACCESS";
|
||||
|
||||
return SaveFileResultStr[(int)sfr];
|
||||
}
|
||||
|
||||
#endif // SAVEFILERESULT_H
|
@ -7,6 +7,7 @@ class SearchResult
|
||||
public:
|
||||
FileData fileData;
|
||||
QVector<unsigned int> pages;
|
||||
bool wasContentSearch = false;
|
||||
};
|
||||
|
||||
#endif // SEARCHRESULT_H
|
||||
|
@ -16,7 +16,11 @@ CONFIG += c++17
|
||||
INCLUDEPATH += $$PWD/../sandbox/exile.h/
|
||||
INCLUDEPATH += /usr/include/poppler/qt5/ /usr/include/quazip5
|
||||
|
||||
|
||||
# Dirty, we only need the includes here but well this magic works, so...
|
||||
packagesExist(quazip1-qt5) {
|
||||
PKGCONFIG += quazip1-qt5
|
||||
CONFIG += link_pkgconfig
|
||||
}
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
@ -84,6 +88,7 @@ HEADERS += sqlitesearch.h \
|
||||
pdfprocessor.h \
|
||||
processor.h \
|
||||
sandboxedprocessor.h \
|
||||
savefileresult.h \
|
||||
searchresult.h \
|
||||
sqlitedbservice.h \
|
||||
tagstripperprocessor.h \
|
||||
@ -96,3 +101,4 @@ unix {
|
||||
INSTALLS += target
|
||||
}
|
||||
RESOURCES = migrations/migrations.qrc
|
||||
RESOURCES += plaintexts.qrc
|
||||
|
@ -7,14 +7,7 @@
|
||||
#include "filedata.h"
|
||||
#include "../shared/sqlitesearch.h"
|
||||
#include "../shared/token.h"
|
||||
enum SaveFileResult
|
||||
{
|
||||
OK,
|
||||
SKIPPED,
|
||||
DBFAIL,
|
||||
PROCESSFAIL,
|
||||
NOTFOUND
|
||||
};
|
||||
#include "savefileresult.h"
|
||||
|
||||
class SqliteDbService
|
||||
{
|
||||
|
@ -213,6 +213,7 @@ QVector<SearchResult> SqliteSearch::search(const LooqsQuery &query)
|
||||
throw LooqsGeneralException("SQL Error: " + dbQuery.lastError().text());
|
||||
}
|
||||
|
||||
bool contentSearch = query.hasContentSearch();
|
||||
while(dbQuery.next())
|
||||
{
|
||||
SearchResult result;
|
||||
@ -229,6 +230,7 @@ QVector<SearchResult> SqliteSearch::search(const LooqsQuery &query)
|
||||
result.pages.append(page.toUInt());
|
||||
}
|
||||
}
|
||||
result.wasContentSearch = contentSearch;
|
||||
results.append(result);
|
||||
}
|
||||
return results;
|
||||
|
Submodule submodules/exile.h updated: 42d44b0cc1...8f38dc4480
Reference in New Issue
Block a user