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.
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.
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.
17
#include "autoconfig.h"
28
#include <QMessageBox>
38
static const char *rautostartfile = ".config/autostart/recollindex.desktop";
40
// Just in case we don't find the file in the shared dir, have a
42
static const char *desktopfiletext =
44
"Name=Recoll real time indexer\n"
45
"Comment=Runs in background to extract and index text from modified "
48
"Exec=recollindex -w 60 -m\n"
52
"Categories=Utility;Filesystem;Database;\n"
54
"X-GNOME-Autostart-enabled=true\n"
55
"X-KDE-autostart-after=panel\n"
56
"X-KDE-UniqueApplet=true\n"
61
connect(this->sesCB, SIGNAL(clicked(bool)),
62
this, SLOT(sesclicked(bool)));
63
string autostartfile = path_cat(path_home(), rautostartfile);
64
if (access(autostartfile.c_str(), 0) == 0) {
65
sesCB->setChecked(true);
69
void RTIToolW::sesclicked(bool on)
71
nowCB->setEnabled(on);
73
nowCB->setChecked(false);
76
void RTIToolW::accept()
78
bool exitdial = false;
79
string autostartfile = path_cat(path_home(), rautostartfile);
81
if (sesCB->isChecked()) {
82
// Setting up daemon indexing autostart
84
if (::access(autostartfile.c_str(), 0) == 0) {
85
QString msg = tr("Replacing: ") +
86
QString::fromLocal8Bit(autostartfile.c_str());
88
QMessageBox::Button rep =
89
QMessageBox::question(this, tr("Replacing file"), msg,
90
QMessageBox::Ok | QMessageBox::Cancel);
91
if (rep != QMessageBox::Ok) {
98
string sourcefile = path_cat(theconfig->getDatadir(), "examples");
99
sourcefile = path_cat(sourcefile, "recollindex.desktop");
100
if (::access(sourcefile.c_str(), 0) == 0) {
101
file_to_string(sourcefile, text);
105
text = desktopfiletext;
107
// Try to create .config and autostart anyway. If they exists this will
108
// do nothing. An error will be detected when we try to create the file
109
string dir = path_cat(path_home(), ".config");
110
mkdir(dir.c_str(), 0700);
111
dir = path_cat(dir, "autostart");
112
mkdir(dir.c_str(), 0700);
114
int fd = ::open(autostartfile.c_str(), O_WRONLY|O_CREAT, 0644);
115
if (fd < 0 || ::write(fd, text.c_str(), size_t(text.size()))
116
!= ssize_t(text.size()) || ::close(fd) != 0) {
119
QString msg = tr("Can't create: ") +
120
QString::fromLocal8Bit(autostartfile.c_str());
121
QMessageBox::warning(0, tr("Warning"), msg, QMessageBox::Ok);
126
if (nowCB->isChecked()) {
131
args.push_back("-m");
132
args.push_back("-w");
134
status = cmd.doexec("recollindex", args, 0, 0);
136
QMessageBox::warning(0, tr("Warning"),
137
tr("Could not execute recollindex"),
145
// Turning autostart off
146
if (::access(autostartfile.c_str(), 0) == 0) {
147
QString msg = tr("Deleting: ") +
148
QString::fromLocal8Bit(autostartfile.c_str());
150
QMessageBox::Button rep =
151
QMessageBox::question(this, tr("Deleting file"), msg,
152
QMessageBox::Ok | QMessageBox::Cancel);
153
if (rep == QMessageBox::Ok) {
155
unlink(autostartfile.c_str());
157
Pidfile pidfile(theconfig->getPidfile());
159
if ((pid = pidfile.open()) != 0) {
160
QMessageBox::Button rep =
161
QMessageBox::question(this,
162
tr("Removing autostart"),
163
tr("Autostart file deleted. Kill current process too ?"),
164
QMessageBox::Yes | QMessageBox::No);
165
if (rep == QMessageBox::Yes) {