From c849f96cc3771f52c0466eb772f91bfb2e8e5d86 Mon Sep 17 00:00:00 2001
From: Jean-Francois Dockes
Date: Tue, 8 Oct 2019 11:41:46 +0200
Subject: [PATCH] Windows: implement GUI to start the windows task scheduler
for batch indexing
---
src/qtgui/idxsched.ui | 2 +-
src/qtgui/rclm_wins.cpp | 27 ++++++++---
src/qtgui/rclmain_w.h | 5 ++
src/qtgui/recoll-win.pro | 9 ++--
src/qtgui/winschedtool.cpp | 89 ++++++++++++++++++++++++++++++++++++
src/qtgui/winschedtool.h | 42 +++++++++++++++++
src/qtgui/winschedtool.ui | 94 ++++++++++++++++++++++++++++++++++++++
src/utils/rclutil.cpp | 2 +-
src/utils/rclutil.h | 4 ++
9 files changed, 259 insertions(+), 15 deletions(-)
create mode 100644 src/qtgui/winschedtool.cpp
create mode 100644 src/qtgui/winschedtool.h
create mode 100644 src/qtgui/winschedtool.ui
diff --git a/src/qtgui/idxsched.ui b/src/qtgui/idxsched.ui
index 26d17d6d..93f0823a 100644
--- a/src/qtgui/idxsched.ui
+++ b/src/qtgui/idxsched.ui
@@ -17,7 +17,7 @@
-
-
-
+
0
diff --git a/src/qtgui/rclm_wins.cpp b/src/qtgui/rclm_wins.cpp
index fc3147c2..69cf2c3d 100644
--- a/src/qtgui/rclm_wins.cpp
+++ b/src/qtgui/rclm_wins.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 J.F.Dockes
+/* Copyright (C) 2005-2019 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -24,8 +24,12 @@
#include "listdialog.h"
#include "confgui/confguiindex.h"
#include "idxsched.h"
+#ifdef _WIN32
+#include "winschedtool.h"
+#else
#include "crontool.h"
#include "rtitool.h"
+#endif
#include "snippets_w.h"
#include "fragbuts.h"
#include "specialindex.h"
@@ -197,17 +201,19 @@ void RclMain::execIndexSched()
}
void RclMain::showIndexSched(bool modal)
{
-#ifdef _WIN32
- QMessageBox::information(this, tr("Index scheduling"),
- tr("Sorry, not available under Windows for now, use the File menu entries "
- "to update the index"));
- return;
-#endif
LOGDEB("showIndexSched()\n" );
if (indexSched == 0) {
indexSched = new IdxSchedW(this);
connect(new QShortcut(quitKeySeq, indexSched), SIGNAL (activated()),
this, SLOT (fileExit()));
+#ifdef _WIN32
+ indexSched->cronCLB->setText(tr("Batch scheduling"));
+ indexSched->cronCLB->setDescription(
+ tr("The tool will let you decide at what time indexing should run. "
+ " It uses the Windows task scheduler."));
+ indexSched->mainExplainLBL->hide();
+ indexSched->rtidxCLB->hide();
+#endif
connect(indexSched->cronCLB, SIGNAL(clicked()),
this, SLOT(execCronTool()));
if (theconfig && theconfig->isDefaultConfig()) {
@@ -242,11 +248,16 @@ void RclMain::execCronTool()
{
showCronTool(true);
}
+
void RclMain::showCronTool(bool modal)
{
LOGDEB("showCronTool()\n" );
if (cronTool == 0) {
+#ifdef _WIN32
+ cronTool = new WinSchedToolW(0);
+#else
cronTool = new CronToolW(0);
+#endif
connect(new QShortcut(quitKeySeq, cronTool), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
@@ -271,6 +282,7 @@ void RclMain::execRTITool()
}
void RclMain::showRTITool(bool modal)
{
+#ifndef _WIN32
LOGDEB("showRTITool()\n" );
if (rtiTool == 0) {
rtiTool = new RTIToolW(0);
@@ -286,6 +298,7 @@ void RclMain::showRTITool(bool modal)
} else {
rtiTool->show();
}
+#endif
}
void RclMain::showUIPrefs()
diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h
index f33abc0e..3b163583 100644
--- a/src/qtgui/rclmain_w.h
+++ b/src/qtgui/rclmain_w.h
@@ -41,6 +41,7 @@ class ExecCmd;
class Preview;
class ResTable;
class CronToolW;
+class WinSchedToolW;
class RTIToolW;
class FragButs;
class SpecIdxW;
@@ -179,7 +180,11 @@ private:
UIPrefsDialog *uiprefs{0};
ConfIndexW *indexConfig{0};
IdxSchedW *indexSched{0};
+#ifdef _WIN32
+ WinSchedToolW *cronTool{0};
+#else
CronToolW *cronTool{0};
+#endif
RTIToolW *rtiTool{0};
SpellW *spellform{0};
FragButs *fragbuts{0};
diff --git a/src/qtgui/recoll-win.pro b/src/qtgui/recoll-win.pro
index cd5de1c2..8ff08cd1 100644
--- a/src/qtgui/recoll-win.pro
+++ b/src/qtgui/recoll-win.pro
@@ -21,7 +21,7 @@ HEADERS += \
advshist.h \
confgui/confgui.h \
confgui/confguiindex.h \
- crontool.h \
+ winschedtool.h \
widgets/editdialog.h \
firstidx.h \
fragbuts.h \
@@ -36,7 +36,6 @@ HEADERS += \
rclmain_w.h \
reslist.h \
restable.h \
- rtitool.h \
searchclause_w.h \
snippets_w.h \
specialindex.h \
@@ -52,7 +51,7 @@ SOURCES += \
advshist.cpp \
confgui/confgui.cpp \
confgui/confguiindex.cpp \
- crontool.cpp \
+ winschedtool.cpp \
fragbuts.cpp \
guiutils.cpp \
main.cpp \
@@ -72,7 +71,6 @@ SOURCES += \
respopup.cpp \
reslist.cpp \
restable.cpp \
- rtitool.cpp \
searchclause_w.cpp \
snippets_w.cpp \
spell_w.cpp \
@@ -86,7 +84,7 @@ SOURCES += \
FORMS = \
advsearch.ui \
- crontool.ui \
+ winschedtool.ui \
widgets/editdialog.ui \
firstidx.ui \
idxsched.ui \
@@ -95,7 +93,6 @@ FORMS = \
ptrans.ui \
rclmain.ui \
restable.ui \
- rtitool.ui \
specialindex.ui \
spell.ui \
snippets.ui \
diff --git a/src/qtgui/winschedtool.cpp b/src/qtgui/winschedtool.cpp
new file mode 100644
index 00000000..f7a31394
--- /dev/null
+++ b/src/qtgui/winschedtool.cpp
@@ -0,0 +1,89 @@
+/* Copyright (C) 2019 J.F.Dockes
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include "autoconfig.h"
+#include "winschedtool.h"
+
+#include
+#include
+
+#include
+#include
+
+#include "recoll.h"
+#include "smallut.h"
+#include "rclutil.h"
+#include "log.h"
+#include "execmd.h"
+
+using namespace std;
+
+void WinSchedToolW::init()
+{
+ if (!theconfig) {
+ QMessageBox::warning(0, tr("Error"),
+ tr("Configuration not initialized"));
+ return;
+ }
+
+ connect(startPB, SIGNAL(clicked()), this, SLOT(startWinScheduler()));
+
+ // thisexecpath returns the directory
+ string recollindex = path_cat(path_thisexecpath(), "recollindex.exe");
+ LOGDEB("WinSchedTool: recollindex: " << recollindex << endl);
+
+ string batchfile = path_cat(theconfig->getConfDir(), "winsched.bat");
+ LOGDEB("WinSchedTool: batch file " << batchfile << endl);
+
+ if (!path_exists(batchfile)) {
+ FILE *fp = fopen(batchfile.c_str(), "w");
+ fprintf(fp, "%s -c %s\n", recollindex.c_str(),
+ theconfig->getConfDir().c_str());
+ fclose(fp);
+ }
+ QString blurb = tr(
+ "
Recoll indexing batch scheduling
"
+ "We use the standard Windows task scheduler for this. The program "
+ "will be started when you click the button below.
"
+ "You can use either the full interface "
+ "(Create task in the menu on the right), or the simplified "
+ "Create Basic task wizard. In both cases Copy/Paste the "
+ "batch file path listed below as the Action to be performed."
+ "Once created, you will find your task in the WPD section "
+ "of the task library.
"
+ );
+
+ blurb.append("
").append(u8s2qs(batchfile)).append("
");
+ explainLBL->setText(blurb);
+ explainLBL->setTextInteractionFlags(Qt::TextSelectableByMouse);
+}
+
+void WinSchedToolW::startWinScheduler()
+{
+ if (m_cmd) {
+ int status;
+ if (m_cmd->maybereap(&status)) {
+ delete m_cmd;
+ } else {
+ QMessageBox::warning(0, "Recoll",
+ tr("Command already started"));
+ return;
+ }
+ }
+ m_cmd = new ExecCmd();
+ vector lcmd{"c:/windows/system32/taskschd.msc"};
+ m_cmd->startExec("rclstartw", lcmd, false, false);
+}
diff --git a/src/qtgui/winschedtool.h b/src/qtgui/winschedtool.h
new file mode 100644
index 00000000..fc0a77c2
--- /dev/null
+++ b/src/qtgui/winschedtool.h
@@ -0,0 +1,42 @@
+/* Copyright (C) 2019 J.F.Dockes
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef _WINSCHEDTOOL_W_H_INCLUDED_
+#define _WINSCHEDTOOL_W_H_INCLUDED_
+
+#include "ui_winschedtool.h"
+
+class QPushButton;
+class ExecCmd;
+
+class WinSchedToolW : public QDialog, public Ui::WinSchedToolW {
+ Q_OBJECT;
+public:
+ WinSchedToolW(QWidget * parent = 0)
+ : QDialog(parent) {
+ setupUi(this);
+ init();
+ }
+ QPushButton *startButton{nullptr};
+
+private slots:
+ void startWinScheduler();
+private:
+ void init();
+ ExecCmd *m_cmd{nullptr};
+};
+
+#endif /* _WINSCHEDTOOL_W_H_INCLUDED_ */
diff --git a/src/qtgui/winschedtool.ui b/src/qtgui/winschedtool.ui
new file mode 100644
index 00000000..792b80cd
--- /dev/null
+++ b/src/qtgui/winschedtool.ui
@@ -0,0 +1,94 @@
+
+
+ WinSchedToolW
+
+
+
+ 0
+ 0
+ 508
+ 416
+
+
+
+ Recoll Batch indexing
+
+
+ -
+
+
-
+
+
+
+ 0
+ 1
+
+
+
+
+
+
+ Qt::RichText
+
+
+ true
+
+
+
+ -
+
+
+ Start Windows Task Scheduler tool
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Close
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ WinSchedToolW
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ WinSchedToolW
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp
index 8ae7f4bf..08a474e0 100644
--- a/src/utils/rclutil.cpp
+++ b/src/utils/rclutil.cpp
@@ -83,7 +83,7 @@ static bool path_isdriveabs(const string& s)
#include
#pragma comment(lib, "shlwapi.lib")
-static string path_thisexecpath()
+string path_thisexecpath()
{
wchar_t text[MAX_PATH];
GetModuleFileNameW(NULL, text, MAX_PATH);
diff --git a/src/utils/rclutil.h b/src/utils/rclutil.h
index 2db003d5..4d2f3910 100644
--- a/src/utils/rclutil.h
+++ b/src/utils/rclutil.h
@@ -36,6 +36,10 @@ extern bool path_empty(const std::string& path);
/// e.g. /usr/share/recoll. Depends on OS and config
extern const std::string& path_pkgdatadir();
+#ifdef _WIN32
+extern std::string path_thisexecpath();
+#endif
+
/// Transcode to utf-8 if possible or url encoding, for display.
extern bool printableUrl(const std::string& fcharset,
const std::string& in, std::string& out);