2009-02-05 14:21:47 +00:00
|
|
|
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __CONFIG_HH_INCLUDED__
|
|
|
|
#define __CONFIG_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <QString>
|
2009-02-06 17:16:33 +00:00
|
|
|
#include <QSize>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "ex.hh"
|
|
|
|
|
|
|
|
/// GoldenDict's configuration
|
|
|
|
namespace Config {
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
/// A path where to search for the dictionaries
|
2009-03-28 22:37:03 +00:00
|
|
|
struct Path
|
|
|
|
{
|
|
|
|
QString path;
|
|
|
|
bool recursive;
|
|
|
|
|
|
|
|
Path(): recursive( false ) {}
|
|
|
|
Path( QString const & path_, bool recursive_ ):
|
|
|
|
path( path_ ), recursive( recursive_ ) {}
|
|
|
|
};
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// A list of paths where to search for the dictionaries
|
2009-03-28 22:37:03 +00:00
|
|
|
typedef vector< Path > Paths;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
/// A directory holding bunches of audiofiles, which is indexed into a separate
|
|
|
|
/// dictionary.
|
|
|
|
struct SoundDir
|
|
|
|
{
|
|
|
|
QString path, name;
|
|
|
|
|
|
|
|
SoundDir()
|
|
|
|
{}
|
|
|
|
|
|
|
|
SoundDir( QString const & path_, QString const & name_ ):
|
|
|
|
path( path_ ), name( name_ )
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A list of SoundDirs
|
|
|
|
typedef vector< SoundDir > SoundDirs;
|
|
|
|
|
2009-04-01 12:00:28 +00:00
|
|
|
struct DictionaryRef
|
|
|
|
{
|
|
|
|
QString id; // Dictionrary id, which is usually an md5 hash
|
|
|
|
QString name; // Dictionary name, used to recover when its id changes
|
|
|
|
|
|
|
|
DictionaryRef()
|
|
|
|
{}
|
|
|
|
|
|
|
|
DictionaryRef( QString const & id_, QString const & name_ ):
|
|
|
|
id( id_ ), name( name_ ) {}
|
|
|
|
};
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// A dictionary group
|
|
|
|
struct Group
|
|
|
|
{
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned id;
|
2009-01-28 20:55:45 +00:00
|
|
|
QString name, icon;
|
2009-04-01 12:00:28 +00:00
|
|
|
vector< DictionaryRef > dictionaries;
|
2009-04-10 12:48:40 +00:00
|
|
|
|
|
|
|
Group(): id( 0 ) {}
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// All the groups
|
2009-04-10 12:48:40 +00:00
|
|
|
struct Groups: public vector< Group >
|
|
|
|
{
|
|
|
|
unsigned nextId; // Id to use to create the group next time
|
|
|
|
|
|
|
|
Groups(): nextId( 1 )
|
|
|
|
{}
|
|
|
|
};
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
/// Proxy server configuration
|
|
|
|
struct ProxyServer
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
Socks5 = 0,
|
|
|
|
HttpConnect,
|
|
|
|
HttpGet
|
|
|
|
} type;
|
|
|
|
|
|
|
|
QString host;
|
|
|
|
unsigned port;
|
|
|
|
QString user, password;
|
|
|
|
|
|
|
|
ProxyServer();
|
|
|
|
};
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
/// Various user preferences
|
|
|
|
struct Preferences
|
|
|
|
{
|
2009-04-12 20:46:25 +00:00
|
|
|
QString interfaceLanguage; // Empty value corresponds to system default
|
2009-04-13 12:51:25 +00:00
|
|
|
bool newTabsOpenAfterCurrentOne;
|
|
|
|
bool newTabsOpenInBackground;
|
2009-02-05 20:55:00 +00:00
|
|
|
bool enableTrayIcon;
|
|
|
|
bool startToTray;
|
|
|
|
bool closeToTray;
|
|
|
|
bool enableScanPopup;
|
2009-02-08 20:20:02 +00:00
|
|
|
bool startWithScanPopupOn;
|
2009-02-05 20:55:00 +00:00
|
|
|
bool enableScanPopupModifiers;
|
|
|
|
unsigned long scanPopupModifiers; // Combination of KeyboardState::Modifier
|
2009-04-11 16:44:14 +00:00
|
|
|
bool scanPopupAltMode; // When you press modifier shortly after the selection
|
|
|
|
unsigned scanPopupAltModeSecs;
|
2009-02-05 20:55:00 +00:00
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
// Whether the word should be pronounced on page load, in main window/popup
|
|
|
|
bool pronounceOnLoadMain, pronounceOnLoadPopup;
|
|
|
|
QString audioPlaybackProgram;
|
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
ProxyServer proxyServer;
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
Preferences();
|
|
|
|
};
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// A MediaWiki network dictionary definition
|
|
|
|
struct MediaWiki
|
|
|
|
{
|
|
|
|
QString id, name, url;
|
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
MediaWiki(): enabled( false )
|
|
|
|
{}
|
|
|
|
|
|
|
|
MediaWiki( QString const & id_, QString const & name_, QString const & url_,
|
|
|
|
bool enabled_ ):
|
|
|
|
id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ) {}
|
|
|
|
};
|
|
|
|
|
2009-04-09 14:15:01 +00:00
|
|
|
/// Hunspell configuration
|
|
|
|
struct Hunspell
|
|
|
|
{
|
|
|
|
QString dictionariesPath;
|
|
|
|
|
|
|
|
typedef vector< QString > Dictionaries;
|
|
|
|
|
|
|
|
Dictionaries enabledDictionaries;
|
|
|
|
};
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// All the MediaWikis
|
|
|
|
typedef vector< MediaWiki > MediaWikis;
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
struct Class
|
|
|
|
{
|
|
|
|
Paths paths;
|
2009-04-04 16:06:06 +00:00
|
|
|
SoundDirs soundDirs;
|
2009-01-28 20:55:45 +00:00
|
|
|
Groups groups;
|
2009-02-05 20:55:00 +00:00
|
|
|
Preferences preferences;
|
2009-03-26 19:00:08 +00:00
|
|
|
MediaWikis mediawikis;
|
2009-04-09 14:15:01 +00:00
|
|
|
Hunspell hunspell;
|
2009-02-06 17:04:11 +00:00
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned lastMainGroupId; // Last used group in main window
|
|
|
|
unsigned lastPopupGroupId; // Last used group in popup window
|
2009-02-06 17:16:33 +00:00
|
|
|
QSize lastPopupSize;
|
2009-04-03 21:24:07 +00:00
|
|
|
|
|
|
|
QByteArray mainWindowState; // Binary state saved by QMainWindow
|
|
|
|
QByteArray mainWindowGeometry; // Geometry saved by QMainWindow
|
2009-04-10 12:48:40 +00:00
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 )
|
|
|
|
{}
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_EX( exError, "Error with the program's configuration", std::exception )
|
|
|
|
DEF_EX( exCantUseHomeDir, "Can't use home directory to store GoldenDict preferences", exError )
|
|
|
|
DEF_EX( exCantUseIndexDir, "Can't use index directory to store GoldenDict index files", exError )
|
|
|
|
DEF_EX( exCantReadConfigFile, "Can't read the configuration file", exError )
|
|
|
|
DEF_EX( exCantWriteConfigFile, "Can't write the configuration file", exError )
|
|
|
|
DEF_EX( exMalformedConfigFile, "The configuration file is malformed", exError )
|
|
|
|
|
|
|
|
/// Loads the configuration, or creates the default one if none is present
|
|
|
|
Class load() throw( exError );
|
|
|
|
|
|
|
|
/// Saves the configuration
|
|
|
|
void save( Class const & ) throw( exError );
|
|
|
|
|
|
|
|
/// Returns the index directory, where the indices are to be stored.
|
|
|
|
QString getIndexDir() throw( exError );
|
|
|
|
|
|
|
|
/// Returns the user .css file name.
|
|
|
|
QString getUserCssFileName() throw( exError );
|
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
/// Returns the user .css file name for the Qt interface customization.
|
|
|
|
QString getUserQtCssFileName() throw( exError );
|
|
|
|
|
2009-04-12 19:41:58 +00:00
|
|
|
/// Returns the program's data dir. Under Linux that would be something like
|
|
|
|
/// /usr/share/apps/goldendict, under Windows C:/Program Files/GoldenDict.
|
|
|
|
QString getProgramDataDir() throw();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|