Gui: help for cron etc. 1st checkpoint

This commit is contained in:
Jean-Francois Dockes 2011-12-02 19:15:24 +01:00
parent 4e2266495f
commit b9c64e8591
15 changed files with 868 additions and 81 deletions

View File

@ -140,7 +140,7 @@ RclConfig::RclConfig(const string *argcnf)
// 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 must exist"
m_reason = "Explicitly specified configuration directory must exist"
" (won't be automatically created)";
return;
}

View File

@ -0,0 +1,13 @@
[Desktop Entry]
Name=Recoll real time indexer
Comment=Runs in background to extract and index text from modified documents
Icon=system-run
Exec=recollindex -w 60 -m
Terminal=false
TerminalOptions=
Type=Application
Categories=Utility;Filesystem;Database;
NoDisplay=true
X-GNOME-Autostart-enabled=true
X-KDE-autostart-after=panel
X-KDE-UniqueApplet=true

94
src/qtgui/crontool.cpp Normal file
View File

@ -0,0 +1,94 @@
/* 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 <QPushButton>
#include <QMessageBox>
#include "recoll.h"
#include "crontool.h"
#include "ecrontab.h"
#include "smallut.h"
static string marker;
static string idstring(const string& confdir)
{
// Quote conf dir, there may be spaces and whatelse in there
return string("RECOLL_CONFDIR=") + escapeShell(confdir);
}
void CronToolW::init()
{
marker = "RCLCRON_RCLINDEX=";
enableButton = new QPushButton(tr("Enable"));
disableButton = new QPushButton(tr("Disable"));
buttonBox->addButton(enableButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(disableButton, QDialogButtonBox::ActionRole);
connect(enableButton, SIGNAL(clicked()), this, SLOT(enableCron()));
connect(disableButton, SIGNAL(clicked()), this, SLOT(disableCron()));
// Try to read the current values
if (!theconfig)
return;
string id = idstring(theconfig->getConfDir());
vector<string> sched;
if (getCrontabSched(marker, id, sched)) {
minsLE->setText(QString::fromAscii(sched[0].c_str()));
hoursLE->setText(QString::fromAscii(sched[1].c_str()));
daysLE->setText(QString::fromAscii(sched[4].c_str()));
}
}
void CronToolW::enableCron()
{
changeCron(true);
}
void CronToolW::disableCron()
{
changeCron(false);
}
void CronToolW::changeCron(bool enable)
{
if (!theconfig)
return;
string id = idstring(theconfig->getConfDir());
string cmd("recollindex -m -w 60");
string reason;
if (!enable) {
editCrontab(marker, id, "", "", reason);
accept();
} else {
string mins((const char *)minsLE->text().toAscii());
string hours((const char *)hoursLE->text().toAscii());
string days((const char *)daysLE->text().toAscii());
string sched = mins + " " + hours + " * * " + days;
if (editCrontab(marker, id, sched, cmd, reason)) {
accept();
} else {
QMessageBox::warning(0, "Recoll",
tr("Error installing cron entry. Bad syntax in fields ? "));
}
}
}

48
src/qtgui/crontool.h Normal file
View File

@ -0,0 +1,48 @@
/*
* 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.
*/
#ifndef _CRONTAB_W_H_INCLUDED_
#define _CRONTAB_W_H_INCLUDED_
#include "ui_crontool.h"
class QPushButton;
class CronToolW : public QDialog, public Ui::CronToolW {
Q_OBJECT
public:
CronToolW(QWidget * parent = 0)
: QDialog(parent),
enableButton(0),
disableButton(0)
{
setupUi(this);
init();
}
QPushButton *enableButton;
QPushButton *disableButton;
private slots:
void enableCron();
void disableCron();
private:
void init();
void changeCron(bool enable);
};
#endif /* _CRONTAB_W_H_INCLUDED_ */

150
src/qtgui/crontool.ui Normal file
View File

@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CronToolW</class>
<widget class="QDialog" name="CronToolW">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>465</width>
<height>365</height>
</rect>
</property>
<property name="windowTitle">
<string>Cron Dialog</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; batch indexing schedule (cron) &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;Each field can contain a wildcard (*), a single numeric value, comma-separated lists (1,3,5) and ranges (1-7). More generally, the fields will be used &lt;span style=&quot; font-style:italic;&quot;&gt;as is&lt;/span&gt; inside the crontab file, and the full crontab syntax can be used, see crontab(5).&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;&lt;br /&gt;For example, entering &lt;span style=&quot; font-family:'Courier New,courier';&quot;&gt;*&lt;/span&gt; in &lt;span style=&quot; font-style:italic;&quot;&gt;Days, &lt;/span&gt;&lt;span style=&quot; font-family:'Courier New,courier';&quot;&gt;12,19&lt;/span&gt; in &lt;span style=&quot; font-style:italic;&quot;&gt;Hours&lt;/span&gt; and &lt;span style=&quot; font-family:'Courier New,courier';&quot;&gt;15&lt;/span&gt; in &lt;span style=&quot; font-style:italic;&quot;&gt;Minutes&lt;/span&gt; would start recollindex every day at 12:15 AM and 7:15 PM&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;A schedule with very frequent activations is probably less efficient than real time indexing.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Days of week (* or 0-7, 0 or 7 is Sunday)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="daysLE"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Hours (* or 0-23)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="hoursLE"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Minutes (0-59)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="minsLE"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_5">
<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;Click &lt;span style=&quot; font-style:italic;&quot;&gt;Disable&lt;/span&gt; to stop automatic batch indexing, &lt;span style=&quot; font-style:italic;&quot;&gt;Enable&lt;/span&gt; to activate it, &lt;span style=&quot; font-style:italic;&quot;&gt;Cancel&lt;/span&gt; to change nothing.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CronToolW</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CronToolW</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

17
src/qtgui/firstidx.cpp Normal file
View File

@ -0,0 +1,17 @@
/* 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"

32
src/qtgui/firstidx.h Normal file
View File

@ -0,0 +1,32 @@
/*
* 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.
*/
#ifndef _FIRSTIDX_H_INCLUDED_
#define _FIRSTIDX_H_INCLUDED_
#include "ui_firstidx.h"
class FirstIdxDialog : public QDialog, public Ui::FirstIdxDialog {
Q_OBJECT
public:
FirstIdxDialog(QWidget * parent = 0)
: QDialog(parent)
{
setupUi(this);
}
};
#endif /* _FIRSTIDX_H_INCLUDED_ */

133
src/qtgui/firstidx.ui Normal file
View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FirstIdxDialog</class>
<widget class="QDialog" name="FirstIdxDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>457</height>
</rect>
</property>
<property name="windowTitle">
<string>First indexing setup</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;It appears that the index for this configuration does not exist.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you just want to index your home directory with a set of reasonable defaults, press the &lt;span style=&quot; font-style:italic;&quot;&gt;Start indexing now&lt;/span&gt; button. You will be able to adjust the details later. &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;If you want more control, use the following links to adjust the indexing configuration and schedule.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="idxconfCLB">
<property name="text">
<string>Indexing configuration</string>
</property>
<property name="checkable">
<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>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="idxschedCLB">
<property name="text">
<string>Indexing schedule</string>
</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>
</widget>
</item>
<item>
<widget class="QPushButton" name="runidxPB">
<property name="text">
<string>Start indexing now</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FirstIdxDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FirstIdxDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>runidxPB</sender>
<signal>clicked()</signal>
<receiver>FirstIdxDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>215</x>
<y>400</y>
</hint>
<hint type="destinationlabel">
<x>215</x>
<y>228</y>
</hint>
</hints>
</connection>
</connections>
</ui>

33
src/qtgui/idxsched.h Normal file
View File

@ -0,0 +1,33 @@
/*
* 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.
*/
#ifndef _IDXSCHED_H_INCLUDED_
#define _IDXSCHED_H_INCLUDED_
#include "ui_idxsched.h"
class IdxSchedW : public QDialog, public Ui::IdxSchedW {
Q_OBJECT
public:
IdxSchedW(QWidget * parent = 0)
: QDialog(parent)
{
setupUi(this);
}
};
#endif /* _IDXSCHED_H_INCLUDED_ */

107
src/qtgui/idxsched.ui Normal file
View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IdxSchedW</class>
<widget class="QDialog" name="IdxSchedW">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Index scheduling setup</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 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>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="cronCLB">
<property name="text">
<string>Start cron scheduling tool</string>
</property>
<property name="description">
<string>The tool will let you decide at what time indexing should run and will install a crontab entry.</string>
</property>
</widget>
</item>
<item>
<widget class="QCommandLinkButton" name="rtidxCLB">
<property name="text">
<string>Real time indexing start up options</string>
</property>
<property name="description">
<string>Decide if real time indexing will be started when you log in</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>IdxSchedW</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>IdxSchedW</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -69,6 +69,9 @@ using std::pair;
#include "confguiindex.h"
#include "restable.h"
#include "listdialog.h"
#include "firstidx.h"
#include "idxsched.h"
#include "crontool.h"
using namespace confgui;
@ -91,14 +94,8 @@ void RclMain::init()
};
DocSequence::set_translations((const char *)tr("sorted").toUtf8(),
(const char *)tr("filtered").toUtf8());
curPreview = 0;
asearchform = 0;
uiprefs = 0;
indexConfig = 0;
spellform = 0;
m_idxStatusAck = false;
periodictimer = new QTimer(this);
m_periodicToggle = 0;
// At least some versions of qt4 don't display the status bar if
// it's not created here.
@ -340,48 +337,34 @@ void RclMain::resultCount(int n)
// the database and talk to the user if we can't
void RclMain::initDbOpen()
{
bool needindexconfig = false;
bool nodb = false;
string reason;
bool maindberror;
if (!maybeOpenDb(reason, true, &maindberror)) {
nodb = true;
if (maindberror) {
switch (QMessageBox::
question
(this, "Recoll",
qApp->translate("Main", "Could not open database in ") +
QString::fromLocal8Bit(theconfig->getDbDir().c_str()) +
qApp->translate("Main",
".\n"
"Click Cancel if you want to edit the configuration file before indexing starts, or Ok to let it proceed."),
"Ok", "Cancel", 0, 0)) {
case 0: // Ok: indexing is going to start.
start_indexing(true);
break;
case 1: // Cancel
needindexconfig = true;
break;
}
FirstIdxDialog fidia(this);
connect(fidia.idxconfCLB, SIGNAL(clicked()),
this, SLOT(execIndexConfig()));
connect(fidia.idxschedCLB, SIGNAL(clicked()),
this, SLOT(execIndexSched()));
connect(fidia.runidxPB, SIGNAL(clicked()),
this, SLOT(toggleIndexing()));
fidia.exec();
// Don't open adv search or run cmd line search in this case.
return;
} else {
QMessageBox::warning(0, "Recoll",
tr("Could not open external index. Db not open. Check external indexes list."));
}
}
if (needindexconfig) {
startIndexingAfterConfig = 1;
showIndexConfig();
} else {
if (prefs.startWithAdvSearchOpen)
showAdvSearchDialog();
// If we have something in the search entry, it comes from a
// command line argument
if (!nodb && sSearch->hasSearchString())
QTimer::singleShot(0, sSearch, SLOT(startSimpleSearch()));
}
if (prefs.startWithAdvSearchOpen)
showAdvSearchDialog();
// If we have something in the search entry, it comes from a
// command line argument
if (!nodb && sSearch->hasSearchString())
QTimer::singleShot(0, sSearch, SLOT(startSimpleSearch()));
}
void RclMain::focusToSearch()
@ -686,6 +669,14 @@ void RclMain::showSpellDialog()
}
void RclMain::showIndexConfig()
{
showIndexConfig(false);
}
void RclMain::execIndexConfig()
{
showIndexConfig(true);
}
void RclMain::showIndexConfig(bool modal)
{
LOGDEB(("showIndexConfig()\n"));
if (indexConfig == 0) {
@ -697,7 +688,71 @@ void RclMain::showIndexConfig()
indexConfig->close();
indexConfig->reloadPanels();
}
indexConfig->show();
if (modal) {
indexConfig->exec();
indexConfig->setModal(false);
} else {
indexConfig->show();
}
}
void RclMain::showIndexSched()
{
showIndexSched(false);
}
void RclMain::execIndexSched()
{
showIndexSched(true);
}
void RclMain::showIndexSched(bool modal)
{
LOGDEB(("showIndexSched()\n"));
if (indexSched == 0) {
indexSched = new IdxSchedW(this);
connect(new QShortcut(quitKeySeq, indexSched), SIGNAL (activated()),
this, SLOT (fileExit()));
connect(indexSched->cronCLB, SIGNAL(clicked()),
this, SLOT(execCronTool()));
connect(indexSched->rtidxCLB, SIGNAL(clicked()),
this, SLOT(execRTITool()));
} else {
// Close and reopen, in hope that makes us visible...
indexSched->close();
}
if (modal) {
indexSched->exec();
indexSched->setModal(false);
} else {
indexSched->show();
}
}
void RclMain::showCronTool()
{
showCronTool(false);
}
void RclMain::execCronTool()
{
showCronTool(true);
}
void RclMain::showCronTool(bool modal)
{
LOGDEB(("showCronTool()\n"));
if (cronTool == 0) {
cronTool = new CronToolW(0);
connect(new QShortcut(quitKeySeq, cronTool), SIGNAL (activated()),
this, SLOT (fileExit()));
} else {
// Close and reopen, in hope that makes us visible...
cronTool->close();
}
if (modal) {
cronTool->exec();
cronTool->setModal(false);
} else {
cronTool->show();
}
}
void RclMain::showUIPrefs()

View File

@ -31,9 +31,11 @@
#include "refcntr.h"
#include "pathut.h"
class IdxSchedW;
class ExecCmd;
class Preview;
class ResTable;
class CronToolW;
#include "ui_rclmain.h"
@ -49,7 +51,22 @@ class RclMain : public QMainWindow, public Ui::RclMainBase
public:
RclMain(QWidget * parent = 0)
: QMainWindow(parent), m_sortspecnochange(false)
: QMainWindow(parent),
curPreview(0),
asearchform(0),
uiprefs(0),
indexConfig(0),
indexSched(0),
cronTool(0),
spellform(0),
periodictimer(0),
restable(0),
displayingTable(0),
m_idNoStem(0),
m_idAllStem(0),
m_idxStatusAck(false),
m_sortspecnochange(false),
m_periodicToggle(0)
{
setupUi(this);
init();
@ -76,6 +93,11 @@ public slots:
virtual void showExtIdxDialog();
virtual void showUIPrefs();
virtual void showIndexConfig();
virtual void execIndexConfig();
virtual void showCronTool();
virtual void execCronTool();
virtual void showIndexSched();
virtual void execIndexSched();
virtual void setUIPrefs();
virtual void enableNextPage(bool);
virtual void enablePrevPage(bool);
@ -120,16 +142,18 @@ private:
AdvSearch *asearchform;
UIPrefsDialog *uiprefs;
ConfIndexW *indexConfig;
IdxSchedW *indexSched;
CronToolW *cronTool;
SpellW *spellform;
QTimer *periodictimer;
ResTable *restable;
bool displayingTable;
QAction *m_idNoStem;
QAction *m_idAllStem;
vector<ExecCmd*> m_viewers;
map<QString, QAction*> m_stemLangToId;
vector<string> m_catgbutvec;
QAction * m_idNoStem;
QAction * m_idAllStem;
bool m_idxStatusAck; // Did we act on last status?
DocSeqFiltSpec m_filtspec;
bool m_sortspecnochange;
@ -142,6 +166,9 @@ private:
bool next);
virtual void setStemLang(const QString& lang);
virtual void onSortCtlChanged();
virtual void showIndexConfig(bool modal);
virtual void showIndexSched(bool modal);
virtual void showCronTool(bool modal);
};
#endif // RCLMAIN_W_H

View File

@ -7,6 +7,9 @@ HEADERS += \
advsearch_w.h \
confgui/confgui.h \
confgui/confguiindex.h \
crontool.h \
firstidx.h \
idxsched.h \
listdialog.h \
preview_w.h \
rclhelp.h \
@ -24,6 +27,7 @@ SOURCES += \
advsearch_w.cpp \
confgui/confgui.cpp \
confgui/confguiindex.cpp \
crontool.cpp \
guiutils.cpp \
idxthread.cpp \
main.cpp \
@ -42,10 +46,13 @@ SOURCES += \
FORMS = \
advsearch.ui \
crontool.ui \
firstidx.ui \
idxsched.ui \
listdialog.ui \
rclmain.ui \
restable.ui \
spell.ui \
spell.ui \
ssearchb.ui \
uiprefs.ui \
viewaction.ui \

View File

@ -20,9 +20,10 @@
#include "ecrontab.h"
#include "execmd.h"
#include "smallut.h"
#include "debuglog.h"
bool editCrontab(const string& marker, const string& id,
const string& sched, const string& cmd, string& reason)
// Read crontab file and split it into lines.
static bool eCrontabGetLines(vector<string>& lines)
{
string crontab;
ExecCmd croncmd;
@ -30,21 +31,61 @@ bool editCrontab(const string& marker, const string& id,
int status;
// Retrieve current crontab contents. An error here means that no
// crontab exists, and is not fatal (just use empty string)
// crontab exists, and is not fatal, but we return a different
// status than for an empty one
args.push_back("-l");
if ((status = croncmd.doexec("crontab", args, 0, &crontab))) {
lines.clear();
return false;
}
// Split crontab into lines
stringToTokens(crontab, lines, "\n");
return true;
}
// Concatenate lines and write crontab
static bool eCrontabWriteFile(const vector<string>& lines, string& reason)
{
string crontab;
ExecCmd croncmd;
list<string> args;
int status;
for (vector<string>::const_iterator it = lines.begin();
it != lines.end(); it++) {
crontab += *it + "\n";
}
args.push_back("-");
if ((status = croncmd.doexec("crontab", args, &crontab, 0))) {
char nbuf[30];
sprintf(nbuf, "0x%x", status);
reason = string("Exec crontab -l failed: status: ") + nbuf;
return false;
}
return true;
}
// Add / change / delete entry identified by marker and id
bool editCrontab(const string& marker, const string& id,
const string& sched, const string& cmd, string& reason)
{
vector<string> lines;
if (!eCrontabGetLines(lines)) {
// Special case: cmd is empty, no crontab, don't create one
if (cmd.empty())
return true;
}
// Split crontab into lines
vector<string> lines;
stringToTokens(crontab, lines, "\n");
// Remove old copy if any
for (vector<string>::iterator it = lines.begin();
it != lines.end(); it++) {
// Skip comment
if (it->find_first_of("#") == it->find_first_not_of(" \t"))
continue;
if (it->find(marker) != string::npos &&
it->find(id) != string::npos) {
lines.erase(it);
@ -57,42 +98,19 @@ bool editCrontab(const string& marker, const string& id,
lines.push_back(nline);
}
// Rebuild new crontab and install it
crontab.clear();
for (vector<string>::iterator it = lines.begin();
it != lines.end(); it++) {
crontab += *it + "\n";
}
args.clear();
args.push_back("-");
if ((status = croncmd.doexec("crontab", args, &crontab, 0))) {
char nbuf[30];
sprintf(nbuf, "0x%x", status);
reason = string("Exec crontab -l failed: status: ") + nbuf;
}
if (!eCrontabWriteFile(lines, reason))
return false;
return true;
}
bool checkCrontabUnmanaged(const string& marker, const string& data)
{
string crontab;
ExecCmd croncmd;
list<string> args;
int status;
// Retrieve current crontab contents. An error here means that no
// crontab exists.
args.push_back("-l");
if ((status = croncmd.doexec("crontab", args, 0, &crontab))) {
vector<string> lines;
if (!eCrontabGetLines(lines)) {
// No crontab, answer is no
return false;
}
// Split crontab into lines
vector<string> lines;
stringToTokens(crontab, lines, "\n");
// Scan crontab
for (vector<string>::iterator it = lines.begin();
it != lines.end(); it++) {
@ -104,6 +122,38 @@ bool checkCrontabUnmanaged(const string& marker, const string& data)
return false;
}
/** Retrieve the scheduling for a crontab entry */
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());
vector<string> lines;
if (!eCrontabGetLines(lines)) {
// No crontab, answer is no
sched.clear();
return false;
}
string line;
for (vector<string>::iterator it = lines.begin();
it != lines.end(); it++) {
// Skip comment
if (it->find_first_of("#") == it->find_first_not_of(" \t"))
continue;
if (it->find(marker) != string::npos &&
it->find(id) != string::npos) {
line = *it;
break;
}
}
stringToTokens(line, sched);
sched.resize(5);
return true;
}
#else // TEST ->
#include <stdio.h>
@ -124,7 +174,8 @@ static char *thisprog;
static char usage [] =
" -a add or replace crontab line \n"
" -a delete crontab line \n"
" -d delete crontab line \n"
" -s get scheduling \n"
" -c <string> check for unmanaged lines for string\n"
;
static void
@ -140,12 +191,13 @@ static int op_flags;
#define OPT_d 0x4
#define OPT_w 0x8
#define OPT_c 0x10
#define OPT_s 0x20
const string& marker("RCLCRON_RCLINDEX=");
// Note of course the -w does not make sense for a cron entry
const string& cmd0("recollindex -w ");
const string& id("RECOLL_CONFDIR=/home/dockes/.recoll");
const string& sched("30 8 * * *");
const string& id("RECOLL_CONFDIR=\"/home/dockes/.recoll/\"");
const string& sched("30 8 * 1 *");
int main(int argc, char **argv)
{
@ -167,6 +219,7 @@ int main(int argc, char **argv)
cmd = *(++argv); argc--;
goto b1;
case 'd': op_flags |= OPT_d; break;
case 's': op_flags |= OPT_s; break;
case 'w': op_flags |= OPT_w; if (argc < 2) Usage();
wt = *(++argv); argc--;
goto b1;
@ -187,6 +240,18 @@ int main(int argc, char **argv)
status = editCrontab(marker, id, sched, cmd, reason);
} else if (op_flags & OPT_d) {
status = editCrontab(marker, id, sched, "", reason);
} else if (op_flags & OPT_s) {
vector<string> sched;
if (!(status = getCrontabSched(marker, id, sched))) {
cerr << "getCrontabSched failed: " << reason << endl;
exit(1);
}
cout << "sched vec size " << sched.size() << endl;
cout << "mins " << sched[0] << " hours " << sched[1] <<
" days of month " << sched[2] << " months " << sched[3] <<
" days of week " << sched[4] << endl;
exit(0);
} else if (op_flags & OPT_c) {
if ((status = checkCrontabUnmanaged(marker, cmd))) {
cerr << "crontab has unmanaged lines for " << cmd << endl;

View File

@ -33,7 +33,9 @@
*/
#include <string>
#include <vector>
using std::string;
using std::vector;
/** Add, replace or delete a command inside a crontab file
*
@ -62,4 +64,8 @@ bool editCrontab(const string& marker, const string& id,
*/
bool checkCrontabUnmanaged(const string& marker, const string& data);
/** Retrieve the scheduling for a crontab entry */
bool getCrontabSched(const string& marker, const string& id,
vector<string>& sched);
#endif /* _ECRONTAB_H_INCLUDED_ */