diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 1647a89..6b4486c 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -215,6 +215,7 @@ 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); } void MainWindow::startIndexSync() @@ -236,6 +237,7 @@ void MainWindow::startIndexSync() emit beginIndexSync(); } + void MainWindow::spinPreviewPageValueChanged(int val) { makePreviews(val); @@ -351,6 +353,45 @@ 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(';'); + 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); +} + +void MainWindow::saveSettings() +{ + QSettings settings; + + QString pdfViewerCmd = ui->txtSettingPdfPreviewerCmd->text(); + QStringList excludedPaths = ui->txtSettingIgnoredPaths->text().split(';'); + QStringList mountPaths = ui->txtSettingMountPaths->text().split(';'); + + 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.sync(); + + QProcess::startDetached(qApp->arguments()[0], qApp->arguments().mid(1)); + qApp->quit(); } void MainWindow::previewReceived(QSharedPointer preview, unsigned int previewGeneration) @@ -389,7 +430,7 @@ void MainWindow::lineEditReturnPressed() ui->lblSearchResults->setText("Invalid paranthesis"); return; } - if(indexerTabActive()) + if(ui->tabWidget->currentIndex() > 1) { ui->tabWidget->setCurrentIndex(0); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index d5ee7c8..df65d13 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -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,7 @@ class MainWindow : public QMainWindow void finishIndexing(); void addPathToIndex(); void startIndexSync(); + void saveSettings(); signals: void startIpcPreviews(RenderConfig config, const QVector &targets); diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 7c9eae0..ca819c1 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1221 - 709 + 1280 + 736 @@ -27,7 +27,7 @@ QTabWidget::South - 0 + 3 @@ -81,8 +81,8 @@ 0 0 - 1185 - 419 + 1244 + 446 @@ -344,6 +344,126 @@ + + + Settings + + + + + + PDF Viewer + + + + + + Command to open PDF pages in (%f = file path; %p = page number) + + + + + + + + + + + + + Mount paths + + + + + + 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 ; + + + + + + + + + + + + + Ignored paths + + + + + + Path prefixes that should always be ignored during indexing (will be applied before the ignore patterns). Separated by ; + + + + + + + + + + + + + Misc + + + + + + + + Max number of previews per 'page' in 'Previews' tab: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Save settings and restart + + + + + @@ -368,7 +488,7 @@ 0 0 - 1221 + 1280 35 diff --git a/shared/common.cpp b/shared/common.cpp index 7944b89..78f6d89 100644 --- a/shared/common.cpp +++ b/shared/common.cpp @@ -14,13 +14,6 @@ #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); @@ -176,19 +169,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() diff --git a/shared/common.h b/shared/common.h index 14968b0..68ebe4b 100644 --- a/shared/common.h +++ b/shared/common.h @@ -2,6 +2,15 @@ #define COMMON_H #include #include + +#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" +#define SETTINGS_KEY_PREVIEWSPERPAGE "previewsPerPage" + namespace Common { void setupAppInfo();