diff --git a/src/main.cpp b/src/main.cpp index 134abddf..370485ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,6 +127,18 @@ int main(int argc, char *argv[]) { settings->setValue("Settings/remoteType", "main"); }; + // during first run the queueScript key might not exist + if (!(settings->contains("Settings/queueScript"))) { + // if queueScript does not exist create new key + settings->setValue("Settings/queueScript", ""); + }; + + // during first run the queueScriptRun key might not exist + if (!(settings->contains("Settings/queueScriptRun"))) { + // if queueScriptRun does not exist create new key + settings->setValue("Settings/queueScriptRun", "false"); + }; + // set application font size int fontsize = 0; diff --git a/src/main_window.cpp b/src/main_window.cpp index b863b42a..373bf063 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -22,6 +22,8 @@ MainWindow::MainWindow() { } auto settings = GetSettings(); + ui.queueScriptRun->setChecked( + (settings->value("Settings/queueScriptRun").toBool())); #if defined(Q_OS_WIN) // disable "?" WindowContextHelpButton @@ -404,6 +406,8 @@ MainWindow::MainWindow() { dialog.getDefaultUploadOptions().trimmed()); settings->setValue("Settings/defaultRcloneOptions", dialog.getDefaultRcloneOptions().trimmed()); + settings->setValue("Settings/queueScript", + dialog.getQueueScript().trimmed()); settings->setValue("Settings/checkRcloneBrowserUpdates", dialog.getCheckRcloneBrowserUpdates()); @@ -441,6 +445,16 @@ MainWindow::MainWindow() { dialog.getHttpsProxy().trimmed()); settings->setValue("Settings/no_proxy", dialog.getNoProxy().trimmed()); + // set queueScriptRun tooltip + QString queueScriptRunToolTip = + QString("Run script defined in preferences after all queue " + "processing finishes.\n\n" + "Can be used for example to hibernate your computer.\n\n") + + QString("Script set in preferences: ") + QString("\"") + + QString(settings->value("Settings/queueScript", false).toString()) + + QString("\""); + ui.queueScriptRun->setToolTip(queueScriptRunToolTip); + SetRclone(dialog.getRclone()); SetRcloneConf(dialog.getRcloneConf()); mFirstTime = true; @@ -454,6 +468,13 @@ MainWindow::MainWindow() { } }); + QObject::connect(ui.actionQueueScriptRun, &QAction::triggered, this, [=]() { + // remember in settings queueScriptRun checkbox state + auto settings = GetSettings(); + settings->setValue("Settings/queueScriptRun", + ui.queueScriptRun->isChecked()); + }); + // intercept tab closure MainWindow::connect(ui.tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseTab(int))); @@ -2195,6 +2216,17 @@ void MainWindow::addTasksToQueue() { ui.queueListWidget->clear(); + // set queueScriptRun tooltip + auto settings = GetSettings(); + QString queueScriptRunToolTip = + QString("Run script defined in preferences after all queue processing " + "finishes.\n\n" + "Can be used for example to hibernate your computer.\n\n") + + QString("Script set in preferences: ") + QString("\"") + + QString(settings->value("Settings/queueScript", false).toString()) + + QString("\""); + ui.queueScriptRun->setToolTip(queueScriptRunToolTip); + auto items = ui.tasksListWidget->selectedItems(); ListOfJobOptions *ljo = ListOfJobOptions::getInstance(); @@ -2560,6 +2592,19 @@ void MainWindow::addTransfer(const QString &message, const QString &source, if (mQueueCount == 0) { ui.tabs->setTabText(3, QString("Queue (%1)>>(0)").arg(mQueueCount)); + // run queueScript + auto settings = GetSettings(); + bool queueScriptRun = + settings->value("Settings/queueScriptRun", false).toBool(); + + if (queueScriptRun) { + QString queueScript = + settings->value("Settings/queueScript", false).toString(); + if (!queueScript.isEmpty()) { + runQueueScript(queueScript); + } + } + } else { ui.tabs->setTabText( 3, QString("Queue (%1)>>(1)").arg(mQueueCount - 1)); @@ -2635,6 +2680,23 @@ void MainWindow::addTransfer(const QString &message, const QString &source, transfer->start(GetRclone(), GetRcloneConf() + args, QIODevice::ReadOnly); } +// runs queueScript +void MainWindow::runQueueScript(const QString &script) { + + QProcess *p = new QProcess(); + + QObject::connect(p, + static_cast( + &QProcess::finished), + this, [=](int code, QProcess::ExitStatus) { + if (code == 0) { + } + p->deleteLater(); + }); + + p->start(script); +} + void MainWindow::addMount(const QString &remote, const QString &folder, const QString &remoteType) { QProcess *mount = new QProcess(this); diff --git a/src/main_window.h b/src/main_window.h index db8473db..d58ab2f0 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -28,6 +28,8 @@ private slots: void addStream(const QString &remote, const QString &stream, const QString &remoteType); + void runQueueScript(const QString &script); + void slotCloseTab(int index); void saveQueueFile(void); diff --git a/src/main_window.ui b/src/main_window.ui index 3cecd9fa..29d17a7e 100644 --- a/src/main_window.ui +++ b/src/main_window.ui @@ -557,6 +557,13 @@ + + + + Run script when finished + + + @@ -811,6 +818,11 @@ Move task down in the queue + + + queueScriptRun + + tabs @@ -835,5 +847,21 @@ + + queueScriptRun + toggled(bool) + actionQueueScriptRun + trigger() + + + 567 + 73 + + + -1 + -1 + + + diff --git a/src/preferences_dialog.cpp b/src/preferences_dialog.cpp index 2c33ac57..5a607979 100644 --- a/src/preferences_dialog.cpp +++ b/src/preferences_dialog.cpp @@ -91,6 +91,29 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) { ui.defaultUploadDir->setText(defaultUploadDir); }); + QObject::connect(ui.queueScriptBrowse, &QPushButton::clicked, this, [=]() { + QString queueScript = QFileDialog::getOpenFileName(this, "Select script", + ui.queueScript->text()); + if (queueScript.isEmpty()) { + return; + } + + if (!QFileInfo(queueScript).isExecutable()) { + QMessageBox::critical( + this, "Error", QString("File %1 is not executable").arg(queueScript)); + return; + } + + if (QFileInfo(queueScript) == QFileInfo(qApp->applicationFilePath())) { + QMessageBox::critical(this, "Error", + "You selected RcloneBrowser executable!\nPlease " + "select your script executable instead."); + return; + } + + ui.queueScript->setText(queueScript); + }); + auto settings = GetSettings(); ui.rclone->setText( QDir::toNativeSeparators(settings->value("Settings/rclone").toString())); @@ -119,6 +142,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) { settings->value("Settings/defaultUploadOptions").toString()); ui.defaultRcloneOptions->setText( settings->value("Settings/defaultRcloneOptions").toString()); + ui.queueScript->setText(QDir::toNativeSeparators( + settings->value("Settings/queueScript").toString())); ui.checkRcloneBrowserUpdates->setChecked( settings->value("Settings/checkRcloneBrowserUpdates", true).toBool()); @@ -305,6 +330,10 @@ QString PreferencesDialog::getDefaultRcloneOptions() const { return ui.defaultRcloneOptions->text(); } +QString PreferencesDialog::getQueueScript() const { + return ui.queueScript->text(); +} + bool PreferencesDialog::getCheckRcloneBrowserUpdates() const { return ui.checkRcloneBrowserUpdates->isChecked(); } diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h index 197c0616..6c0f4cb6 100644 --- a/src/preferences_dialog.h +++ b/src/preferences_dialog.h @@ -19,6 +19,7 @@ class PreferencesDialog : public QDialog { QString getDefaultDownloadOptions() const; QString getDefaultUploadOptions() const; QString getDefaultRcloneOptions() const; + QString getQueueScript() const; bool getCheckRcloneBrowserUpdates() const; bool getCheckRcloneUpdates() const; diff --git a/src/preferences_dialog.ui b/src/preferences_dialog.ui index e9ece2c9..f2d082a6 100755 --- a/src/preferences_dialog.ui +++ b/src/preferences_dialog.ui @@ -54,42 +54,8 @@ 6 - - - - ... - - - - - - - rclone.conf location: - - - rcloneConf - - - - - - - Default rclone options: - - - defaultRcloneOptions - - - - - - - ... - - - - - + + 0 @@ -97,7 +63,7 @@ - <html><head/><body><p>rclone executable file location</p></body></html> + <html><head/><body><p>default upload folder used for transfers</p></body></html> @@ -111,8 +77,15 @@ - - + + + + ... + + + + + 0 @@ -120,7 +93,7 @@ - <html><head/><body><p>extra rclone options used for downloads e.g.:</p><p>--include *.jpg</p></body></html> + <html><head/><body><p>rclone executable file location</p></body></html> @@ -137,25 +110,32 @@ - - + + - rclone location: + ... + + + + + + + rclone.conf location: - rclone + rcloneConf - - + + ... - - + + 0 @@ -163,17 +143,24 @@ - <html><head/><body><p>rclone configuration file locaction. if empty default location defined by rclone is used</p></body></html> + <html><head/><body><p>extra rclone options used for downloads e.g.:</p><p>--include *.jpg</p></body></html> - - + + - Default upload options: + ... + + + + + + + rclone location: - defaultUploadOptions + rclone @@ -187,15 +174,21 @@ - - - - ... + + + + + 0 + 0 + + + + <html><head/><body><p>extra rclone options used for uploads e.g:</p><p>--exclude .DS_Store</p></body></html> - - + + 0 @@ -203,12 +196,12 @@ - <html><head/><body><p>options used by rclone for remotes mounting e.g:</p><p>--vfs-cache-mode writes</p></body></html> + <html><head/><body><p>location of audio/video player used for streaming e.g.</p><p>/Applications/VLC.app -<br/>/usr/local/bin/vlc -<br/>&quot;c:\Program Files\VideoLAN\VLC\vlc.exe&quot; -</p></body></html> - - + + 0 @@ -216,12 +209,12 @@ - <html><head/><body><p>extra rclone options used for uploads e.g:</p><p>--exclude .DS_Store</p></body></html> + <html><head/><body><p>options used by rclone for remotes mounting e.g:</p><p>--vfs-cache-mode writes</p></body></html> - - + + 0 @@ -229,17 +222,14 @@ - <html><head/><body><p>default upload folder used for transfers</p></body></html> + <html><head/><body><p>rclone configuration file locaction. if empty default location defined by rclone is used</p></body></html> - - + + - Default download folder: - - - defaultDownloadDir + ... @@ -253,13 +243,6 @@ - - - - ... - - - @@ -283,16 +266,54 @@ - - - - - 0 - 0 - + + + + Default download folder: + + + defaultDownloadDir + + + + + + + Default rclone options: + + + defaultRcloneOptions + + + + + + + Default upload options: + + + defaultUploadOptions + + + + + + Finished queue script: + + + + + - <html><head/><body><p>location of audio/video player used for streaming e.g.</p><p>/Applications/VLC.app -<br/>/usr/local/bin/vlc -<br/>&quot;c:\Program Files\VideoLAN\VLC\vlc.exe&quot; -</p></body></html> + <html><head/><body><p>Script executed when queue processing is finished.</p></body></html> + + + + + + + ... @@ -320,6 +341,9 @@ rcloneBrowse rcloneConfBrowse defaultDownloadDir + label_7 + queueScript + queueScriptBrowse