~ubuntu-branches/ubuntu/quantal/recoll/quantal

« back to all changes in this revision

Viewing changes to qtgui/crontool.cpp

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2012-03-27 12:15:51 UTC
  • mfrom: (1.3.8)
  • Revision ID: package-import@ubuntu.com-20120327121551-nmntidzpehudushy
Tags: 1.17.1-1
* New upstream release.
* Enable Python module resulting into new binary: python-recoll.
* debian/control:
  + Updated Build-Deps: libqtwebkit-dev, python-all-dev.
  + Added python-recoll binary.
  + Updated Standards-Version to 3.9.3
* debian/rules:
  + Build Python module by default.
* debian/recoll.menu, debian/python-recoll.install, debian/recoll.install:
  + Changes for new binary package.
* debian/copyright:
  + Updated to copyright-format 1.0
  + Updated upstream and Debian copyright.
  + Fixed unicode.org/copyright.html URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2005 J.F.Dockes
 
2
 *   This program is free software; you can redistribute it and/or modify
 
3
 *   it under the terms of the GNU General Public License as published by
 
4
 *   the Free Software Foundation; either version 2 of the License, or
 
5
 *   (at your option) any later version.
 
6
 *
 
7
 *   This program is distributed in the hope that it will be useful,
 
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *   GNU General Public License for more details.
 
11
 *
 
12
 *   You should have received a copy of the GNU General Public License
 
13
 *   along with this program; if not, write to the
 
14
 *   Free Software Foundation, Inc.,
 
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
16
 */
 
17
#include "autoconfig.h"
 
18
 
 
19
#include <stdio.h>
 
20
 
 
21
#include <QPushButton>
 
22
#include <QMessageBox>
 
23
#include <QTimer>
 
24
 
 
25
#include "recoll.h"
 
26
#include "crontool.h"
 
27
#include "ecrontab.h"
 
28
#include "smallut.h"
 
29
 
 
30
static string marker;
 
31
 
 
32
static string idstring(const string& confdir)
 
33
{
 
34
    // Quote conf dir, there may be spaces and whatelse in there
 
35
    return string("RECOLL_CONFDIR=") + escapeShell(confdir);
 
36
}
 
37
 
 
38
void CronToolW::init()
 
39
{
 
40
    marker = "RCLCRON_RCLINDEX=";
 
41
 
 
42
    enableButton = new QPushButton(tr("Enable"));
 
43
    disableButton = new QPushButton(tr("Disable"));
 
44
    buttonBox->addButton(enableButton, QDialogButtonBox::ActionRole);
 
45
    buttonBox->addButton(disableButton, QDialogButtonBox::ActionRole);
 
46
    connect(enableButton, SIGNAL(clicked()), this, SLOT(enableCron()));
 
47
    connect(disableButton, SIGNAL(clicked()), this, SLOT(disableCron()));
 
48
 
 
49
    // Try to read the current values
 
50
    if (!theconfig)
 
51
        return;
 
52
 
 
53
    if (checkCrontabUnmanaged(marker, "recollindex")) {
 
54
        QMessageBox::warning(0, "Recoll", 
 
55
                             tr("It seems that manually edited entries exist for recollindex, cannot edit crontab"));
 
56
        QTimer::singleShot(0, this, SLOT(close()));
 
57
    }
 
58
    
 
59
    string id = idstring(theconfig->getConfDir());
 
60
    vector<string> sched;
 
61
    if (getCrontabSched(marker, id, sched)) {
 
62
        minsLE->setText(QString::fromAscii(sched[0].c_str()));
 
63
        hoursLE->setText(QString::fromAscii(sched[1].c_str()));
 
64
        daysLE->setText(QString::fromAscii(sched[4].c_str()));
 
65
    }
 
66
}
 
67
 
 
68
void CronToolW::enableCron()
 
69
{
 
70
    changeCron(true);
 
71
}
 
72
void CronToolW::disableCron()
 
73
{
 
74
    changeCron(false);
 
75
}
 
76
 
 
77
void CronToolW::changeCron(bool enable)
 
78
{
 
79
    if (!theconfig)
 
80
        return;
 
81
 
 
82
    string id = idstring(theconfig->getConfDir());
 
83
    string cmd("recollindex");
 
84
 
 
85
    string reason;
 
86
 
 
87
    if (!enable) {
 
88
        editCrontab(marker, id, "", "", reason);
 
89
        accept();
 
90
    } else {
 
91
        string mins((const char *)minsLE->text().toAscii());
 
92
        string hours((const char *)hoursLE->text().toAscii());
 
93
        string days((const char *)daysLE->text().toAscii());
 
94
        string sched = mins + " " + hours + "  * * " + days;
 
95
        if (editCrontab(marker, id, sched, cmd, reason)) {
 
96
            accept();
 
97
        }  else {
 
98
            QMessageBox::warning(0, "Recoll", 
 
99
                     tr("Error installing cron entry. Bad syntax in fields ?"));
 
100
        }           
 
101
    }
 
102
}