Switch to unified view

a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.7 2006-04-05 13:39:07 dockes Exp $ (C) 2005 Jean-Francois Dockes";
2
static char rcsid[] = "@(#$Id: guiutils.cpp,v 1.8 2006-04-07 13:08:08 dockes Exp $ (C) 2005 Jean-Francois Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
23
#include "smallut.h"
23
#include "smallut.h"
24
#include "recoll.h"
24
#include "recoll.h"
25
#include "guiutils.h"
25
#include "guiutils.h"
26
#include "pathut.h"
26
#include "pathut.h"
27
#include "base64.h"
27
#include "base64.h"
28
#include "rcldb.h"
28
29
29
#include <qsettings.h>
30
#include <qsettings.h>
30
#include <qstringlist.h>
31
#include <qstringlist.h>
31
32
32
const static char *htmlbrowserlist = 
33
const static char *htmlbrowserlist = 
33
    "opera konqueror firefox mozilla netscape";
34
    "opera konqueror firefox mozilla netscape";
34
35
36
/** 
35
// Search for and launch an html browser for the documentation. If the
37
 * Search for and launch an html browser for the documentation. If the
36
// user has set a preference, we use it directly instead of guessing.
38
 * user has set a preference, we use it directly instead of guessing.
39
 */
37
bool startHelpBrowser(const string &iurl)
40
bool startHelpBrowser(const string &iurl)
38
{
41
{
39
    string url;
42
    string url;
40
    if (iurl.empty()) {
43
    if (iurl.empty()) {
41
    url = path_cat(recoll_datadir, "doc");
44
    url = path_cat(recoll_datadir, "doc");
42
    url = path_cat(url, "usermanual.html");
45
    url = path_cat(url, "usermanual.html");
43
    url = string("file://") + url;
46
    url = string("file://") + url;
44
    } else
47
    } else
45
    url = iurl;
48
    url = iurl;
46
47
49
48
    // If the user set a preference with an absolute path then things are
50
    // If the user set a preference with an absolute path then things are
49
    // simple
51
    // simple
50
    if (!prefs.htmlBrowser.isEmpty() && prefs.htmlBrowser.find('/') != -1) {
52
    if (!prefs.htmlBrowser.isEmpty() && prefs.htmlBrowser.find('/') != -1) {
51
    if (access(prefs.htmlBrowser.ascii(), X_OK) != 0) {
53
    if (access(prefs.htmlBrowser.ascii(), X_OK) != 0) {
...
...
95
        searched.c_str()));
97
        searched.c_str()));
96
    return false;
98
    return false;
97
}
99
}
98
100
99
101
100
///////////////////////// 
102
// The global preferences structure
101
// Global variables for user preferences. These are set in the user preference
102
// dialog and saved restored to the appropriate place in the qt settings
103
PrefsPack prefs;
103
PrefsPack prefs;
104
104
105
// Using the same macro to read/write a setting. insurance against typing 
106
// mistakes
105
#define SETTING_RW(var, nm, tp, def)            \
107
#define SETTING_RW(var, nm, tp, def)            \
106
    if (writing) {                  \
108
    if (writing) {                  \
107
    settings.writeEntry(nm , var);          \
109
    settings.writeEntry(nm , var);          \
108
    } else {                        \
110
    } else {                        \
109
    var = settings.read##tp##Entry(nm, def);    \
111
    var = settings.read##tp##Entry(nm, def);    \
110
    }                       
112
    }                       
111
113
114
/** 
115
 * Saving and restoring user preferences. These are stored in a global
116
 * structure during program execution and saved to disk using the QT
117
 * settings mechanism
118
 */
112
void rwSettings(bool writing)
119
void rwSettings(bool writing)
113
{
120
{
114
    QSettings settings;
121
    QSettings settings;
115
    settings.setPath("Recoll.org", "Recoll");
122
    settings.setPath("Recoll.org", "Recoll");
116
123
...
...
130
    SETTING_RW(prefs.queryBuildAbstract, 
137
    SETTING_RW(prefs.queryBuildAbstract, 
131
           "/Recoll/prefs/query/buildAbstract", Bool, true);
138
           "/Recoll/prefs/query/buildAbstract", Bool, true);
132
    SETTING_RW(prefs.queryReplaceAbstract, 
139
    SETTING_RW(prefs.queryReplaceAbstract, 
133
           "/Recoll/prefs/query/replaceAbstract", Bool, false);
140
           "/Recoll/prefs/query/replaceAbstract", Bool, false);
134
141
142
    // The extra databases settings. These are stored as a list of
143
    // xapian directory names, encoded in base64 to avoid any
144
    // binary/charset conversion issues. There are 2 lists for all
145
    // known dbs and active (searched) ones.
146
    // When starting up, we also add from the RECOLL_EXTRA_DBS environment
147
    // variable.
135
    QStringList qsl;
148
    QStringList qsl;
136
    if (writing) {
149
    if (writing) {
137
    for (list<string>::const_iterator it = prefs.allExtraDbs.begin();
150
    for (list<string>::const_iterator it = prefs.allExtraDbs.begin();
138
         it != prefs.allExtraDbs.end(); it++) {
151
         it != prefs.allExtraDbs.end(); it++) {
139
        string b64;
152
        string b64;
...
...
156
    for (QStringList::iterator it = qsl.begin(); it != qsl.end(); it++) {
169
    for (QStringList::iterator it = qsl.begin(); it != qsl.end(); it++) {
157
        string dec;
170
        string dec;
158
        base64_decode((*it).ascii(), dec);
171
        base64_decode((*it).ascii(), dec);
159
        prefs.allExtraDbs.push_back(dec);
172
        prefs.allExtraDbs.push_back(dec);
160
    }
173
    }
161
174
  const char *cp;
175
  if ((cp = getenv("RECOLL_EXTRA_DBS")) != 0) {
176
      list<string> dbl;
177
      stringToTokens(cp, dbl, ":");
178
      for (list<string>::iterator dit = dbl.begin(); dit != dbl.end();
179
       dit++) {
180
      string dbdir = path_canon(*dit);
181
      path_catslash(dbdir);
182
      if (find(prefs.allExtraDbs.begin(), prefs.allExtraDbs.end(),
183
           dbdir) != prefs.allExtraDbs.end())
184
          continue;
185
      if (!Rcl::Db::testDbDir(dbdir)) {
186
          LOGERR(("Not a xapian database: [%s]\n", dbdir.c_str()));
187
          continue;
188
      }
189
      prefs.allExtraDbs.push_back(dbdir);
190
      }
191
  }
162
    qsl = settings.readListEntry("/Recoll/prefs/query/activeExtraDbs");
192
    qsl = settings.readListEntry("/Recoll/prefs/query/activeExtraDbs");
163
    prefs.activeExtraDbs.clear();
193
    prefs.activeExtraDbs.clear();
164
    for (QStringList::iterator it = qsl.begin(); it != qsl.end(); it++) {
194
    for (QStringList::iterator it = qsl.begin(); it != qsl.end(); it++) {
165
        string dec;
195
        string dec;
166
        base64_decode((*it).ascii(), dec);
196
        base64_decode((*it).ascii(), dec);