GUI tools for setting up indexing schedule, initial implementation done

This commit is contained in:
Jean-Francois Dockes 2011-12-07 13:41:05 +01:00
parent b9c64e8591
commit 07226fa306
17 changed files with 438 additions and 29 deletions

View File

@ -100,6 +100,14 @@ void RclConfig::zeroMe() {
m_rmtstate.init(this, 0, "indexedmimetypes");
}
bool RclConfig::isDefaultConfig()
{
string defaultconf = path_cat(path_canon(path_home()), ".recoll/");
string specifiedconf = path_canon(m_confdir);
path_catslash(specifiedconf);
return !defaultconf.compare(specifiedconf);
}
RclConfig::RclConfig(const string *argcnf)
{
zeroMe();
@ -130,18 +138,18 @@ RclConfig::RclConfig(const string *argcnf)
m_confdir = cp;
} else {
autoconfdir = true;
m_confdir = path_home();
m_confdir += ".recoll/";
m_confdir = path_cat(path_home(), ".recoll/");
}
}
if (!autoconfdir) {
// We want a recoll.conf file to exist in this case to avoid
// creating indexes all over the place
string conffile = path_cat(m_confdir, "recoll.conf");
if (access(conffile.c_str(), 0) < 0) {
m_reason = "Explicitly specified configuration directory must exist"
" (won't be automatically created)";
// Note: autoconfdir and isDefaultConfig() are normally the same. We just
// want to avoid the imperfect test in isDefaultConfig() if we actually know
// this is the default conf
if (!autoconfdir && !isDefaultConfig()) {
if (access(m_confdir.c_str(), 0) < 0) {
m_reason = "Explicitly specified configuration "
"directory must exist"
" (won't be automatically created). Use mkdir first";
return;
}
}

View File

@ -83,8 +83,13 @@ class RclConfig {
bool ok() {return m_ok;}
const string &getReason() {return m_reason;}
/** Return the directory where this configuration is stored */
/** Return the directory where this configuration is stored.
* This was possibly silently created by the rclconfig
* constructor it it is the default one (~/.recoll) and it did
* not exist yet. */
string getConfDir() {return m_confdir;}
/** Returns true if this is ~/.recoll */
bool isDefaultConfig();
/** Get the local value for /usr/local/share/recoll/ */
const string& getDatadir() {return m_datadir;}

View File

@ -72,7 +72,7 @@ void CronToolW::changeCron(bool enable)
return;
string id = idstring(theconfig->getConfDir());
string cmd("recollindex -m -w 60");
string cmd("recollindex");
string reason;
@ -88,7 +88,7 @@ void CronToolW::changeCron(bool enable)
accept();
} else {
QMessageBox::warning(0, "Recoll",
tr("Error installing cron entry. Bad syntax in fields ? "));
tr("Error installing cron entry. Bad syntax in fields ?"));
}
}
}

View File

@ -14,8 +14,8 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _CRONTAB_W_H_INCLUDED_
#define _CRONTAB_W_H_INCLUDED_
#ifndef _CRONTOOL_W_H_INCLUDED_
#define _CRONTOOL_W_H_INCLUDED_
#include "ui_crontool.h"
@ -45,4 +45,4 @@ private:
};
#endif /* _CRONTAB_W_H_INCLUDED_ */
#endif /* _CRONTOOL_W_H_INCLUDED_ */

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>465</width>
<height>365</height>
<height>367</height>
</rect>
</property>
<property name="windowTitle">
@ -18,6 +18,12 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;

View File

@ -43,6 +43,9 @@ p, li { white-space: pre-wrap; }
<property name="checkable">
<bool>false</bool>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="description">
<string>This will let you adjust the directories you want to index, and other parameters like excluded file paths or names, default character sets, etc.</string>
</property>
@ -53,6 +56,9 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Indexing schedule</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="description">
<string>This will let you chose between batch and real-time indexing, and set up an automatic schedule for batch indexing (using cron).</string>
</property>

View File

@ -18,6 +18,7 @@
#define _IDXSCHED_H_INCLUDED_
#include "ui_idxsched.h"
#include "rclhelp.h"
class IdxSchedW : public QDialog, public Ui::IdxSchedW {
Q_OBJECT
@ -26,6 +27,9 @@ class IdxSchedW : public QDialog, public Ui::IdxSchedW {
: QDialog(parent)
{
setupUi(this);
(void)new HelpClient(this);
HelpClient::installMap((const char *)this->objectName().toUtf8(),
"RCL.INDEXING");
}
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>352</height>
</rect>
</property>
<property name="windowTitle">
@ -24,8 +24,9 @@
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Recoll&lt;/span&gt; indexing can run permanently, indexing files as they change, or run at discrete intervals. &lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Reading the manual may help you to decide between these approaches. Hopefuly, F1 should get you there.&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;This tool can help you set up a schedule to automate batch indexing runs, or start real time indexing when you log in (or both actually, which may make sense in some situations). &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Reading the manual may help you to decide between these approaches (press F1). &lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;This tool can help you set up a schedule to automate batch indexing runs, or start real time indexing when you log in (or both, which rarely makes sense). &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
@ -38,7 +39,10 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QCommandLinkButton" name="cronCLB">
<property name="text">
<string>Start cron scheduling tool</string>
<string>Cron scheduling</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="description">
<string>The tool will let you decide at what time indexing should run and will install a crontab entry.</string>
@ -48,10 +52,13 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QCommandLinkButton" name="rtidxCLB">
<property name="text">
<string>Real time indexing start up options</string>
<string>Real time indexing start up</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="description">
<string>Decide if real time indexing will be started when you log in</string>
<string>Decide if real time indexing will be started when you log in (only for the default index).</string>
</property>
</widget>
</item>

View File

@ -160,6 +160,7 @@
<string>&amp;Preferences</string>
</property>
<addaction name="indexConfigAction"/>
<addaction name="indexScheduleAction"/>
<addaction name="separator"/>
<addaction name="queryPrefsAction"/>
<addaction name="extIdxAction"/>
@ -375,6 +376,14 @@
<cstring>indexConfigAction</cstring>
</property>
</action>
<action name="indexScheduleAction">
<property name="text">
<string>&amp;Indexing schedule</string>
</property>
<property name="name" stdset="0">
<cstring>indexScheduleAction</cstring>
</property>
</action>
<action name="queryPrefsAction">
<property name="text">
<string>&amp;Query configuration</string>

View File

@ -72,6 +72,7 @@ using std::pair;
#include "firstidx.h"
#include "idxsched.h"
#include "crontool.h"
#include "rtitool.h"
using namespace confgui;
@ -235,6 +236,8 @@ void RclMain::init()
this, SLOT(showSpellDialog()));
connect(indexConfigAction, SIGNAL(activated()),
this, SLOT(showIndexConfig()));
connect(indexScheduleAction, SIGNAL(activated()),
this, SLOT(showIndexSched()));
connect(queryPrefsAction, SIGNAL(activated()),
this, SLOT(showUIPrefs()));
connect(extIdxAction, SIGNAL(activated()),
@ -713,9 +716,12 @@ void RclMain::showIndexSched(bool modal)
this, SLOT (fileExit()));
connect(indexSched->cronCLB, SIGNAL(clicked()),
this, SLOT(execCronTool()));
connect(indexSched->rtidxCLB, SIGNAL(clicked()),
this, SLOT(execRTITool()));
if (theconfig && theconfig->isDefaultConfig()) {
connect(indexSched->rtidxCLB, SIGNAL(clicked()),
this, SLOT(execRTITool()));
} else {
indexSched->rtidxCLB->setEnabled(false);
}
} else {
// Close and reopen, in hope that makes us visible...
indexSched->close();
@ -755,6 +761,33 @@ void RclMain::showCronTool(bool modal)
}
}
void RclMain::showRTITool()
{
showRTITool(false);
}
void RclMain::execRTITool()
{
showRTITool(true);
}
void RclMain::showRTITool(bool modal)
{
LOGDEB(("showRTITool()\n"));
if (rtiTool == 0) {
rtiTool = new RTIToolW(0);
connect(new QShortcut(quitKeySeq, rtiTool), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
// Close and reopen, in hope that makes us visible...
rtiTool->close();
}
if (modal) {
rtiTool->exec();
rtiTool->setModal(false);
} else {
rtiTool->show();
}
}
void RclMain::showUIPrefs()
{
if (uiprefs == 0) {

View File

@ -36,6 +36,7 @@ class ExecCmd;
class Preview;
class ResTable;
class CronToolW;
class RTIToolW;
#include "ui_rclmain.h"
@ -58,6 +59,7 @@ public:
indexConfig(0),
indexSched(0),
cronTool(0),
rtiTool(0),
spellform(0),
periodictimer(0),
restable(0),
@ -96,6 +98,8 @@ public slots:
virtual void execIndexConfig();
virtual void showCronTool();
virtual void execCronTool();
virtual void showRTITool();
virtual void execRTITool();
virtual void showIndexSched();
virtual void execIndexSched();
virtual void setUIPrefs();
@ -144,6 +148,7 @@ private:
ConfIndexW *indexConfig;
IdxSchedW *indexSched;
CronToolW *cronTool;
RTIToolW *rtiTool;
SpellW *spellform;
QTimer *periodictimer;
ResTable *restable;
@ -169,6 +174,7 @@ private:
virtual void showIndexConfig(bool modal);
virtual void showIndexSched(bool modal);
virtual void showCronTool(bool modal);
virtual void showRTITool(bool modal);
};
#endif // RCLMAIN_W_H

View File

@ -16,6 +16,7 @@ HEADERS += \
rclmain_w.h \
reslist.h \
restable.h \
rtitool.h \
searchclause_w.h \
spell_w.h \
ssearch_w.h \
@ -36,6 +37,7 @@ SOURCES += \
rclmain_w.cpp \
reslist.cpp \
restable.cpp \
rtitool.cpp \
searchclause_w.cpp \
spell_w.cpp \
ssearch_w.cpp \
@ -52,6 +54,7 @@ FORMS = \
listdialog.ui \
rclmain.ui \
restable.ui \
rtitool.ui \
spell.ui \
ssearchb.ui \
uiprefs.ui \

172
src/qtgui/rtitool.cpp Normal file
View File

@ -0,0 +1,172 @@
/* Copyright (C) 2005 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.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <string>
using std::string;
#include <QCheckBox>
#include <QMessageBox>
#include "recoll.h"
#include "rtitool.h"
#include "smallut.h"
#include "pathut.h"
#include "copyfile.h"
#include "readfile.h"
#include "execmd.h"
static const char *rautostartfile = ".config/autostart/recollindex.desktop";
// Just in case we don't find the file in the shared dir, have a
// default text ready
static const char *desktopfiletext =
"[Desktop Entry]\n"
"Name=Recoll real time indexer\n"
"Comment=Runs in background to extract and index text from modified "
"documents\n"
"Icon=system-run\n"
"Exec=recollindex -w 60 -m\n"
"Terminal=false\n"
"TerminalOptions=\n"
"Type=Application\n"
"Categories=Utility;Filesystem;Database;\n"
"NoDisplay=true\n"
"X-GNOME-Autostart-enabled=true\n"
"X-KDE-autostart-after=panel\n"
"X-KDE-UniqueApplet=true\n"
;
void RTIToolW::init()
{
connect(this->sesCB, SIGNAL(clicked(bool)),
this, SLOT(sesclicked(bool)));
string autostartfile = path_cat(path_home(), rautostartfile);
if (access(autostartfile.c_str(), 0) == 0) {
sesCB->setChecked(true);
}
}
void RTIToolW::sesclicked(bool on)
{
nowCB->setEnabled(on);
if (!on)
nowCB->setChecked(false);
}
void RTIToolW::accept()
{
bool exitdial = false;
string autostartfile = path_cat(path_home(), rautostartfile);
if (sesCB->isChecked()) {
// Setting up daemon indexing autostart
if (::access(autostartfile.c_str(), 0) == 0) {
QString msg = tr("Replacing: ") +
QString::fromLocal8Bit(autostartfile.c_str());
QMessageBox::Button rep =
QMessageBox::question(this, tr("Replacing file"), msg,
QMessageBox::Ok | QMessageBox::Cancel);
if (rep != QMessageBox::Ok) {
goto out;
}
}
string text;
if (theconfig) {
string sourcefile = path_cat(theconfig->getDatadir(), "examples");
sourcefile = path_cat(sourcefile, "recollindex.desktop");
if (::access(sourcefile.c_str(), 0) == 0) {
file_to_string(sourcefile, text);
}
}
if (text.empty())
text = desktopfiletext;
int fd = ::open(autostartfile.c_str(), O_WRONLY|O_CREAT, 0644);
if (fd < 0 || ::write(fd, text.c_str(), size_t(text.size()))
!= ssize_t(text.size()) || ::close(fd) != 0) {
if (fd >=0)
::close(fd);
QString msg = tr("Can't create: ") +
QString::fromLocal8Bit(autostartfile.c_str());
QMessageBox::warning(0, tr("Warning"), msg, QMessageBox::Ok);
return;
}
::close(fd);
if (nowCB->isChecked()) {
ExecCmd cmd;
list<string> args;
int status;
args.push_back("-m");
args.push_back("-w");
args.push_back("0");
status = cmd.doexec("recollindex", args, 0, 0);
if (status) {
QMessageBox::warning(0, tr("Warning"),
tr("Could not execute recollindex"),
QMessageBox::Ok);
goto out;
}
}
exitdial = true;
} else {
// Turning autostart off
if (::access(autostartfile.c_str(), 0) == 0) {
QString msg = tr("Deleting: ") +
QString::fromLocal8Bit(autostartfile.c_str());
QMessageBox::Button rep =
QMessageBox::question(this, tr("Deleting file"), msg,
QMessageBox::Ok | QMessageBox::Cancel);
if (rep == QMessageBox::Ok) {
exitdial = true;
unlink(autostartfile.c_str());
if (theconfig) {
Pidfile pidfile(theconfig->getPidfile());
pid_t pid;
if ((pid = pidfile.open()) != 0) {
QMessageBox::Button rep =
QMessageBox::question(this,
tr("Removing autostart"),
tr("Autostart file deleted. Kill current process too ?"),
QMessageBox::Yes | QMessageBox::No);
if (rep == QMessageBox::Yes) {
kill(pid, SIGTERM);
}
}
}
}
} else {
exitdial = true;
}
}
out:
if (exitdial)
QDialog::accept();
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005 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
@ -14,4 +14,28 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#ifndef _RTITOOL_W_H_INCLUDED_
#define _RTITOOL_W_H_INCLUDED_
#include "ui_rtitool.h"
class QPushButton;
class RTIToolW : public QDialog, public Ui::RTIToolW {
Q_OBJECT
public:
RTIToolW(QWidget * parent = 0)
: QDialog(parent)
{
setupUi(this);
init();
}
public slots:
void sesclicked(bool);
void accept();
private:
void init();
};
#endif /* _RTITOOL_W_H_INCLUDED_ */

123
src/qtgui/rtitool.ui Normal file
View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RTIToolW</class>
<widget class="QDialog" name="RTIToolW">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>409</width>
<height>182</height>
</rect>
</property>
<property name="windowTitle">
<string>Real time indexing automatic start</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Recoll&lt;/span&gt; indexing can be set up to run as a daemon, updating the index as files change, in real time. You gain an always up to date index, but system resources are used permanently.&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="sesCB">
<property name="text">
<string>Start indexing daemon with my desktop session.</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="nowCB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Also start indexing daemon right now.</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RTIToolW</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>204</x>
<y>159</y>
</hint>
<hint type="destinationlabel">
<x>204</x>
<y>90</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RTIToolW</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>204</x>
<y>159</y>
</hint>
<hint type="destinationlabel">
<x>204</x>
<y>90</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -111,6 +111,7 @@ ${INSTALL} -m 0755 desktop/hotrecoll.py \
${datadir}/recoll/filters/ || exit 1
${INSTALL} -m 0444 \
desktop/recollindex.desktop \
sampleconf/mimeconf \
sampleconf/mimeview \
sampleconf/recoll.conf \

View File

@ -17,6 +17,8 @@
#ifndef TEST_ECRONTAB
#include "autoconfig.h"
#include <stdio.h>
#include "ecrontab.h"
#include "execmd.h"
#include "smallut.h"
@ -126,8 +128,8 @@ bool checkCrontabUnmanaged(const string& marker, const string& data)
bool getCrontabSched(const string& marker, const string& id,
vector<string>& sched)
{
fprintf(stderr, "getCrontabSched: marker[%s], id[%s]\n",
marker.c_str(), id.c_str());
LOGDEB0(("getCrontabSched: marker[%s], id[%s]\n",
marker.c_str(), id.c_str()));
vector<string> lines;
if (!eCrontabGetLines(lines)) {
// No crontab, answer is no