1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
/*
* Copyright 2005-2009 Fabrice Colin
*
* 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 _PINOTSETTINGS_HH
#define _PINOTSETTINGS_HH
#include <sys/types.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <vector>
#include <glibmm/ustring.h>
#include <libxml++/nodes/element.h>
#include "IndexInterface.h"
#include "ModuleProperties.h"
#include "QueryProperties.h"
class PinotSettings
{
public:
~PinotSettings();
typedef enum { LOAD_ALL = 0, LOAD_GLOBAL, LOAD_LOCAL } LoadWhat;
typedef enum { SAVE_PREFS = 0, SAVE_CONFIG } SaveWhat;
class IndexProperties
{
public:
IndexProperties();
IndexProperties(const Glib::ustring &name,
const std::string &location,
unsigned int id, bool isInternal);
IndexProperties(const IndexProperties &other);
virtual ~IndexProperties();
IndexProperties& operator=(const IndexProperties &other);
bool operator<(const IndexProperties &other) const;
bool operator==(const IndexProperties &other) const;
Glib::ustring m_name;
std::string m_location;
unsigned int m_id;
bool m_internal;
};
static PinotSettings &getInstance(void);
static bool enableClientMode(bool enable);
static std::string getHomeDirectory(void);
static std::string getConfigurationDirectory(void);
static std::string getFileName(bool prefsOrUI);
static std::string getCurrentUserName(void);
static void checkHistoryDatabase(void);
static std::string getHistoryDatabaseName(bool needToQueryDaemonHistory = false);
bool isFirstRun(void) const;
void clear(void);
bool load(LoadWhat what);
bool save(SaveWhat what);
/// Returns the indexes set.
const std::set<IndexProperties> &getIndexes(void) const;
/// Adds a new index.
bool addIndex(const Glib::ustring &name, const std::string &location,
bool isInternal = false);
/// Removes an index.
bool removeIndex(const IndexProperties &indexProps);
/// Clears the indexes map.
void clearIndexes(void);
/// Returns properties of the given index.
IndexProperties getIndexPropertiesByName(const std::string &name) const;
/// Returns properties of the given index.
IndexProperties getIndexPropertiesByLocation(const std::string &location) const;
/// Returns the name(s) for the given ID.
void getIndexNames(unsigned int id, std::set<std::string> &names);
/// Returns an IndexInterface for the given index location.
IndexInterface *getIndex(const std::string &location);
/// Returns the search engines set.
bool getSearchEngines(std::set<ModuleProperties> &engines, const std::string &channelName = "") const;
/// Returns an ID that identifies the given engine name.
unsigned int getEngineId(const std::string &name);
/// Returns the name(s) for the given ID.
void getEngineNames(unsigned int id, std::set<std::string> &names);
/// Returns the search engines channels.
std::map<std::string, bool> &getSearchEnginesChannels(void);
/// Returns the queries map, keyed by name.
const std::map<std::string, QueryProperties> &getQueries(void) const;
/// Adds a new query.
bool addQuery(const QueryProperties &properties);
/// Removes a query.
bool removeQuery(const std::string &name);
/// Clears the queries map.
void clearQueries(void);
/// Gets default patterns.
bool getDefaultPatterns(std::set<Glib::ustring> &defaultPatterns);
/// Determines if a file matches the blacklist.
bool isBlackListed(const std::string &fileName);
class IndexableLocation
{
public:
IndexableLocation();
IndexableLocation(const IndexableLocation &other);
~IndexableLocation();
IndexableLocation &operator=(const IndexableLocation &other);
bool operator<(const IndexableLocation &other) const;
bool operator==(const IndexableLocation &other) const;
bool m_monitor;
Glib::ustring m_name;
bool m_isSource;
};
class CacheProvider
{
public:
CacheProvider();
CacheProvider(const CacheProvider &other);
~CacheProvider();
CacheProvider &operator=(const CacheProvider &other);
bool operator<(const CacheProvider &other) const;
bool operator==(const CacheProvider &other) const;
Glib::ustring m_name;
Glib::ustring m_location;
std::set<Glib::ustring> m_protocols;
};
Glib::ustring m_version;
bool m_warnAboutVersion;
Glib::ustring m_defaultBackend;
Glib::ustring m_googleAPIKey;
Glib::ustring m_docsIndexLocation;
Glib::ustring m_daemonIndexLocation;
double m_minimumDiskSpace;
int m_xPos;
int m_yPos;
int m_width;
int m_height;
int m_panePos;
bool m_showEngines;
bool m_expandQueries;
bool m_ignoreRobotsDirectives;
bool m_suggestQueryTerms;
unsigned short m_newResultsColourRed;
unsigned short m_newResultsColourGreen;
unsigned short m_newResultsColourBlue;
Glib::ustring m_proxyAddress;
unsigned int m_proxyPort;
Glib::ustring m_proxyType;
bool m_proxyEnabled;
std::set<std::string> m_labels;
std::set<IndexableLocation> m_indexableLocations;
std::set<Glib::ustring> m_filePatternsList;
bool m_isBlackList;
std::map<std::string, std::string> m_editablePluginValues;
std::vector<CacheProvider> m_cacheProviders;
std::set<Glib::ustring> m_cacheProtocols;
protected:
static PinotSettings m_instance;
static bool m_clientMode;
bool m_firstRun;
std::set<IndexProperties> m_indexes;
unsigned int m_indexCount;
std::set<ModuleProperties> m_engines;
std::map<unsigned int, std::string> m_engineIds;
std::map<std::string, bool> m_engineChannels;
std::map<std::string, QueryProperties> m_queries;
PinotSettings();
bool loadSearchEngines(const std::string &directoryName);
bool loadConfiguration(const std::string &fileName, bool isGlobal);
bool loadUi(const xmlpp::Element *pElem);
bool loadIndexes(const xmlpp::Element *pElem);
bool loadEngineChannels(const xmlpp::Element *pElem);
bool loadQueries(const xmlpp::Element *pElem);
bool loadLabels(const xmlpp::Element *pElem);
bool loadColour(const xmlpp::Element *pElem);
bool loadProxy(const xmlpp::Element *pElem);
bool loadIndexableLocations(const xmlpp::Element *pElem);
bool loadFilePatterns(const xmlpp::Element *pElem);
bool loadPluginParameters(const xmlpp::Element *pElem);
bool loadCacheProviders(const xmlpp::Element *pElem);
private:
PinotSettings(const PinotSettings &other);
PinotSettings &operator=(const PinotSettings &other);
};
#endif // _PINOTSETTINGS_HH
|