goldendict-ng/config.hh

879 lines
24 KiB
C++
Raw Normal View History

2012-02-20 21:47:14 +00:00
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#ifndef __CONFIG_HH_INCLUDED__
#define __CONFIG_HH_INCLUDED__
2014-12-12 14:04:27 +00:00
#include <QObject>
2012-12-10 12:49:45 +00:00
#include <QVector>
#include <QString>
#include <QSize>
#include <QDateTime>
#include <QKeySequence>
#include <QSet>
#include <QMetaType>
#include "ex.hh"
#include <QLocale>
#ifdef Q_OS_WIN
#include <QRect>
#endif
/// GoldenDict's configuration
namespace Config {
/// Dictionaries which are temporarily disabled via the dictionary bar.
typedef QSet< QString > MutedDictionaries;
2012-12-07 11:59:29 +00:00
#ifdef Q_OS_WIN
#pragma pack(push,4)
#endif
/// A path where to search for the dictionaries
struct Path
{
QString path;
bool recursive;
Path(): recursive( false ) {}
Path( QString const & path_, bool recursive_ ):
path( path_ ), recursive( recursive_ ) {}
bool operator == ( Path const & other ) const
{ return path == other.path && recursive == other.recursive; }
};
/// A list of paths where to search for the dictionaries
2012-12-10 12:49:45 +00:00
typedef QVector< Path > Paths;
/// A directory holding bunches of audiofiles, which is indexed into a separate
/// dictionary.
struct SoundDir
{
QString path, name;
QString iconFilename;
SoundDir()
{}
SoundDir( QString const & path_, QString const & name_, QString iconFilename_ = "" ):
path( path_ ), name( name_ ), iconFilename( iconFilename_ )
{}
bool operator == ( SoundDir const & other ) const
{ return path == other.path && name == other.name && iconFilename == other.iconFilename; }
};
/// A list of SoundDirs
2012-12-10 12:49:45 +00:00
typedef QVector< SoundDir > SoundDirs;
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_ ) {}
bool operator == ( DictionaryRef const & other ) const
{ return id == other.id && name == other.name; }
};
/// A dictionary group
struct Group
{
unsigned id;
QString name, icon;
QByteArray iconData;
QKeySequence shortcut;
2017-05-05 14:39:51 +00:00
QString favoritesFolder;
2012-12-10 12:49:45 +00:00
QVector< DictionaryRef > dictionaries;
Config::MutedDictionaries mutedDictionaries; // Disabled via dictionary bar
Config::MutedDictionaries popupMutedDictionaries; // Disabled via dictionary bar in popup
Group(): id( 0 ) {}
bool operator == ( Group const & other ) const
{ return id == other.id && name == other.name && icon == other.icon &&
2017-05-05 14:39:51 +00:00
favoritesFolder == other.favoritesFolder &&
dictionaries == other.dictionaries && shortcut == other.shortcut &&
mutedDictionaries == other.mutedDictionaries &&
popupMutedDictionaries == other.popupMutedDictionaries &&
2012-10-31 13:58:35 +00:00
iconData == other.iconData; }
bool operator != ( Group const & other ) const
{ return ! operator == ( other ); }
};
/// All the groups
2012-12-10 12:49:45 +00:00
struct Groups: public QVector< Group >
{
unsigned nextId; // Id to use to create the group next time
Groups(): nextId( 1 )
{}
};
/// Proxy server configuration
struct ProxyServer
{
bool enabled;
2014-04-01 17:00:13 +00:00
bool useSystemProxy;
enum Type
{
Socks5 = 0,
HttpConnect,
HttpGet
} type;
QString host;
unsigned port;
QString user, password;
2014-04-03 14:21:02 +00:00
QString systemProxyUser, systemProxyPassword;
ProxyServer();
};
struct AnkiConnectServer
{
bool enabled;
QString host;
unsigned port;
QString deck;
QString model;
QString word;
QString text;
QString sentence;
AnkiConnectServer();
};
// A hotkey -- currently qt modifiers plus one or two keys
struct HotKey
{
Qt::KeyboardModifiers modifiers;
int key1, key2;
HotKey();
/// Hotkey's constructor, take a QKeySequence's first two keys
/// 1st key's modifier will be the `modifiers` above
/// 1st key without modifier will becomes `key1`
/// 2nd key without modifier will becomes `key2`
/// The relation between the int and qt's KeyCode should consult qt's doc
HotKey( QKeySequence const & );
QKeySequence toKeySequence() const;
};
struct FullTextSearch
{
int searchMode;
bool matchCase;
int maxArticlesPerDictionary;
int maxDistanceBetweenWords;
bool useMaxDistanceBetweenWords;
bool useMaxArticlesPerDictionary;
bool enabled;
bool ignoreWordsOrder;
bool ignoreDiacritics;
quint32 maxDictionarySize;
QByteArray dialogGeometry;
QString disabledTypes;
FullTextSearch() :
searchMode( 0 ), matchCase( false ),
maxArticlesPerDictionary( 100 ),
maxDistanceBetweenWords( 2 ),
useMaxDistanceBetweenWords( true ),
useMaxArticlesPerDictionary( false ),
enabled( true ),
ignoreWordsOrder( false ),
ignoreDiacritics( false ),
maxDictionarySize( 0 )
{}
};
/// This class encapsulates supported backend preprocessor logic,
/// discourages duplicating backend names in code, which is error-prone.
class InternalPlayerBackend
{
public:
/// Returns true if at least one backend is available.
static bool anyAvailable();
/// Returns the default backend or null backend if none is available.
static InternalPlayerBackend defaultBackend();
/// Returns the name list of supported backends.
static QStringList nameList();
/// Returns true if built with FFmpeg player support and the name matches.
bool isFfmpeg() const;
/// Returns true if built with Qt Multimedia player support and the name matches.
bool isQtmultimedia() const;
QString const & uiName() const
{ return name; }
void setUiName( QString const & name_ )
{ name = name_; }
bool operator == ( InternalPlayerBackend const & other ) const
{ return name == other.name; }
bool operator != ( InternalPlayerBackend const & other ) const
{ return ! operator == ( other ); }
private:
#ifdef MAKE_FFMPEG_PLAYER
static InternalPlayerBackend ffmpeg()
{ return InternalPlayerBackend( "FFmpeg" ); }
#endif
#ifdef MAKE_QTMULTIMEDIA_PLAYER
static InternalPlayerBackend qtmultimedia()
{ return InternalPlayerBackend( "Qt Multimedia" ); }
#endif
explicit InternalPlayerBackend( QString const & name_ ) : name( name_ )
{}
QString name;
};
#if defined( HAVE_X11 )
Allow customizing unpinned scan popup window flags on X11 with Qt5 My tests in many desktop environments and window managers indicate that no single configuration works perfectly in all environments. There are also behavior differences between Qt::Popup and Qt::Tool flags, which are not exactly bugs, so I suppose users might subjectively prefer different options. Customizing the flags allows the user to prevent unpinned scan popup window flickering with Qt5 on Linux. In a way adding these options fixes issue #645, which is: the scan popup window blinks rapidly, barely noticeably in some applications, such as Calibre ebook-viewer and Chromium. In this case the scan popup window usually ends up hidden when selection ends, unless it was finished with a jerk. I have tested the new options in 9 desktop environments and window managers: at least one configuration for each eliminates #645 and makes the scan popup window work the same as with Qt4 in this regard: the popup window remains visible, text in the popup's translation line keeps up with the text selection in the external application, and the selected text is being translated on the fly. Moreover, for each tested DE/WM, at least one configuration makes the scan popup window work perfectly as far as I am concerned. This issue was partially worked around with a 200ms scan popup delay timer in the recent commit 58e41fe3ceb769cab37608e36637044e597ba1f8 for the duplicate issue #854. However the timer solution is incomplete because it requires the user to select text quickly and without delays. If global mouse selection does not change for 200ms while the left mouse button is held down, the user will likely not see the scan popup when (s)he finishes selection, and will have to try selecting again - hopefully faster this time. The 200ms delay is no longer critically important after this commit, but it is still beneficial: the lookup query changes less often, which in turn reduces article definition update frequency. So the delay improves the UI (perhaps subjectively) and performance.
2018-04-09 17:50:23 +00:00
// The ScanPopup window flags customization code has been tested
// only in X11 desktop environments and window managers.
// None of the window flags configurations I have tried works perfectly well
// in XFCE with Qt4. Let us enable customization code for Qt5 exclusively to
// avoid regressions with Qt4.
#define ENABLE_SPWF_CUSTOMIZATION
#endif
enum ScanPopupWindowFlags
{
SPWF_default = 0,
SPWF_Popup,
SPWF_Tool
};
ScanPopupWindowFlags spwfFromInt( int id );
struct InputPhrase
{
2021-06-18 18:33:24 +00:00
InputPhrase()
{}
InputPhrase( QString const & _phrase, QString const & _suffix ) :
phrase( _phrase ),
punctuationSuffix( _suffix )
{}
static InputPhrase fromPhrase( QString const & phrase )
{
2021-06-18 18:33:24 +00:00
return InputPhrase( phrase, QString() );
}
bool isValid() const { return !phrase.isEmpty(); }
QString phraseWithSuffix() const { return phrase + punctuationSuffix; }
QString phrase;
QString punctuationSuffix;
};
inline bool operator == ( InputPhrase const & a, InputPhrase const & b )
{
return a.phrase == b.phrase && a.punctuationSuffix == b.punctuationSuffix;
}
inline bool operator != ( InputPhrase const & a, InputPhrase const & b )
{
return !( a == b );
}
/// Various user preferences
struct Preferences
{
QString interfaceLanguage; // Empty value corresponds to system default
2014-06-25 14:01:11 +00:00
QString helpLanguage; // Empty value corresponds to interface language
QString displayStyle; // Empty value corresponds to the default one
QString webFontFamily; // Empty value corresponds to the default one
bool newTabsOpenAfterCurrentOne;
bool newTabsOpenInBackground;
bool hideSingleTab;
2011-11-02 23:37:50 +00:00
bool mruTabOrder;
bool hideMenubar;
bool enableTrayIcon;
bool startToTray;
bool closeToTray;
bool autoStart;
bool doubleClickTranslates;
bool selectWordBySingleClick;
Add "Automatically scroll to target article" option When a user clicks on a link in a dictionary or requests translation of a word by double-clicking or translates selection via the context menu, at first the article from the highest-priority dictionary is at the top. Then, after approximately one second, the article from the dictionary, out of which the translation was requested, becomes current and the view scrolls down to this article placing it on top, hiding articles from the dictionaries above it. Such application behavior is inconvenient in some workflows so that the user manually navigates to the top dictionary translation when this automatic scrolling happens. For example: a user has English->Russian dictionaries and English->English dictionaries. The English->Russian dictionaries are higher up in the dictionary order because they provide easier/faster to understand translations. Some rare words and phrases are missing from the English->Russian dictionaries however. Thus the user occasionally reads the English explanation of a word/phrase. When the user double-clicks on a word or follows a link in the English->English dictionary article, she would rather see translations from the preferable English->Russian dictionaries. The new option allows to disable automatic scrolling and ensure that articles from higher-priority dictionaries are visible. The option doesn't affect backward/forward navigation via arrow buttons or Alt+Arrow shortcuts: these still scroll to the stored vertical position among articles. This remaining automatic scrolling happens much faster, is not a problem for the described use case and hopefully for other use cases.
2019-01-11 13:50:40 +00:00
bool autoScrollToTargetArticle;
bool escKeyHidesMainWindow;
2022-12-11 01:22:54 +00:00
bool darkMode;
bool darkReaderMode;
bool alwaysOnTop;
/// An old UI mode when tranlateLine and wordList
/// are in the dockable side panel, not on the toolbar.
bool searchInDock;
bool enableMainWindowHotkey;
QKeySequence mainWindowHotkey;
bool enableClipboardHotkey;
QKeySequence clipboardHotkey;
bool startWithScanPopupOn;
bool enableScanPopupModifiers;
unsigned long scanPopupModifiers; // Combination of KeyboardState::Modifier
bool ignoreOwnClipboardChanges;
bool scanToMainWindow;
bool ignoreDiacritics;
2022-04-23 08:15:23 +00:00
bool ignorePunctuation;
#ifdef HAVE_X11
bool trackClipboardScan;
bool trackSelectionScan;
bool showScanFlag;
#endif
// Whether the word should be pronounced on page load, in main window/popup
bool pronounceOnLoadMain, pronounceOnLoadPopup;
bool useInternalPlayer;
InternalPlayerBackend internalPlayerBackend;
QString audioPlaybackProgram;
ProxyServer proxyServer;
AnkiConnectServer ankiConnectServer;
bool checkForNewReleases;
bool disallowContentFromOtherSites;
bool enableWebPlugins;
bool hideGoldenDictHeader;
int maxNetworkCacheSize;
bool clearNetworkCacheOnExit;
2009-04-30 19:57:25 +00:00
qreal zoomFactor;
2014-06-23 15:11:15 +00:00
qreal helpZoomFactor;
int wordsZoomLevel;
2009-04-30 19:57:25 +00:00
2012-02-16 14:56:25 +00:00
unsigned maxStringsInHistory;
unsigned storeHistory;
bool alwaysExpandOptionalParts;
2012-02-16 14:56:25 +00:00
unsigned historyStoreInterval;
unsigned favoritesStoreInterval;
bool confirmFavoritesDeletion;
bool collapseBigArticles;
int articleSizeLimit;
Add options to limit input phrase length When a long text is accidentally selected or copied while the scan popup is on, Goldendict spends a lot of CPU time to gradually create a "No translation..." article. When translation of huge (e.g. 15 MB) text from the clipboard is (accidentally) requested, Goldendict freezes for a while. Turning the added input phrase limit option on eliminates this waste of the CPU time. I have implemented these options primarily for selection and clipboard, but they also affect mouse-over translation on Windows and command line translation requests. This is mostly because I did not bother to limit the options' scope. I guess hovering over an extremely long text without spaces (e.g. Base64-encoded) could cause the same performance issue on Windows. The command-line translation could be requested from a script that integrates Goldendict with some other application, from which long text could be sent for translation by accident. I hope that the default value of 200 characters will be sufficient for just about any real-world user input in any language. The option is on by default, because the default length limit is generous and any longer text is unlikely to be sent for translation intentionally. My personal preference for the input phrase length limit is 100 symbols. ArticleView::pasteTriggered() didn't call QString::simplified() on the text retrieved from the clipboard. I assumed this was an oversight, so now it *is* called - indirectly, via Preferences::sanitizeInputPhrase().
2020-11-06 19:51:30 +00:00
bool limitInputPhraseLength;
int inputPhraseLengthLimit;
InputPhrase sanitizeInputPhrase( QString const & inputPhrase ) const;
Add options to limit input phrase length When a long text is accidentally selected or copied while the scan popup is on, Goldendict spends a lot of CPU time to gradually create a "No translation..." article. When translation of huge (e.g. 15 MB) text from the clipboard is (accidentally) requested, Goldendict freezes for a while. Turning the added input phrase limit option on eliminates this waste of the CPU time. I have implemented these options primarily for selection and clipboard, but they also affect mouse-over translation on Windows and command line translation requests. This is mostly because I did not bother to limit the options' scope. I guess hovering over an extremely long text without spaces (e.g. Base64-encoded) could cause the same performance issue on Windows. The command-line translation could be requested from a script that integrates Goldendict with some other application, from which long text could be sent for translation by accident. I hope that the default value of 200 characters will be sufficient for just about any real-world user input in any language. The option is on by default, because the default length limit is generous and any longer text is unlikely to be sent for translation intentionally. My personal preference for the input phrase length limit is 100 symbols. ArticleView::pasteTriggered() didn't call QString::simplified() on the text retrieved from the clipboard. I assumed this was an oversight, so now it *is* called - indirectly, via Preferences::sanitizeInputPhrase().
2020-11-06 19:51:30 +00:00
unsigned short maxDictionaryRefsInContextMenu;
bool synonymSearchEnabled;
bool stripClipboard;
bool raiseWindowOnSearch;
2012-12-10 14:14:13 +00:00
QString addonStyle;
FullTextSearch fts;
Preferences();
};
/// A MediaWiki network dictionary definition
struct MediaWiki
{
2012-11-17 17:03:58 +00:00
QString id, name, url;
bool enabled;
2012-11-17 17:03:58 +00:00
QString icon;
MediaWiki(): enabled( false )
{}
MediaWiki( QString const & id_, QString const & name_, QString const & url_,
2012-11-17 17:03:58 +00:00
bool enabled_, QString const & icon_ ):
id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ), icon( icon_ ) {}
bool operator == ( MediaWiki const & other ) const
{ return id == other.id && name == other.name && url == other.url &&
enabled == other.enabled && icon == other.icon ; }
};
/// Any website which can be queried though a simple template substitution
struct WebSite
{
QString id, name, url;
bool enabled;
2012-12-03 12:48:31 +00:00
QString iconFilename;
bool inside_iframe;
WebSite(): enabled( false )
{}
WebSite( QString const & id_, QString const & name_, QString const & url_,
bool enabled_, QString const & iconFilename_, bool inside_iframe_ ):
id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ), iconFilename( iconFilename_ ),
inside_iframe( inside_iframe_ ) {}
bool operator == ( WebSite const & other ) const
{ return id == other.id && name == other.name && url == other.url &&
enabled == other.enabled && iconFilename == other.iconFilename &&
inside_iframe == other.inside_iframe; }
};
/// All the WebSites
2012-12-10 12:49:45 +00:00
typedef QVector< WebSite > WebSites;
2014-04-30 12:55:53 +00:00
/// Any DICT server
struct DictServer
{
QString id, name, url;
bool enabled;
QString databases;
QString strategies;
2014-04-30 12:55:53 +00:00
QString iconFilename;
DictServer(): enabled( false )
{}
DictServer( QString const & id_, QString const & name_, QString const & url_,
bool enabled_, QString const & databases_, QString const & strategies_,
QString const & iconFilename_ ):
2014-04-30 12:55:53 +00:00
id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ), databases( databases_ ),
strategies( strategies_ ), iconFilename( iconFilename_ ) {}
2014-04-30 12:55:53 +00:00
bool operator == ( DictServer const & other ) const
{ return id == other.id && name == other.name && url == other.url
&& enabled == other.enabled && databases == other.databases
&& strategies == other.strategies
2014-04-30 12:55:53 +00:00
&& iconFilename == other.iconFilename; }
};
/// All the DictServers
typedef QVector< DictServer > DictServers;
2009-04-09 14:15:01 +00:00
/// Hunspell configuration
struct Hunspell
{
QString dictionariesPath;
2012-12-10 12:49:45 +00:00
typedef QVector< QString > Dictionaries;
2009-04-09 14:15:01 +00:00
Dictionaries enabledDictionaries;
bool operator == ( Hunspell const & other ) const
{ return dictionariesPath == other.dictionariesPath &&
enabledDictionaries == other.enabledDictionaries; }
bool operator != ( Hunspell const & other ) const
{ return ! operator == ( other ); }
2009-04-09 14:15:01 +00:00
};
/// All the MediaWikis
2012-12-10 12:49:45 +00:00
typedef QVector< MediaWiki > MediaWikis;
/// Chinese transliteration configuration
struct Chinese
{
bool enable;
bool enableSCToTWConversion;
bool enableSCToHKConversion;
bool enableTCToSCConversion;
Chinese();
bool operator == ( Chinese const & other ) const
{ return enable == other.enable &&
enableSCToTWConversion == other.enableSCToTWConversion &&
enableSCToHKConversion == other.enableSCToHKConversion &&
enableTCToSCConversion == other.enableTCToSCConversion; }
bool operator != ( Chinese const & other ) const
{ return ! operator == ( other ); }
};
/// Romaji transliteration configuration
struct Romaji
{
bool enable;
bool enableHepburn;
bool enableNihonShiki;
bool enableKunreiShiki;
bool enableHiragana;
bool enableKatakana;
Romaji();
bool operator == ( Romaji const & other ) const
{ return enable == other.enable &&
enableHepburn == other.enableHepburn &&
enableNihonShiki == other.enableNihonShiki &&
enableKunreiShiki == other.enableKunreiShiki &&
enableHiragana == other.enableHiragana &&
enableKatakana == other.enableKatakana; }
bool operator != ( Romaji const & other ) const
{ return ! operator == ( other ); }
2009-05-11 23:37:18 +00:00
};
struct Transliteration
{
bool enableRussianTransliteration;
2009-05-11 23:37:18 +00:00
bool enableGermanTransliteration;
bool enableGreekTransliteration;
2013-01-18 19:21:56 +00:00
bool enableBelarusianTransliteration;
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
Chinese chinese;
#endif
Romaji romaji;
bool operator == ( Transliteration const & other ) const
{ return enableRussianTransliteration == other.enableRussianTransliteration &&
enableGermanTransliteration == other.enableGermanTransliteration &&
2013-01-18 19:21:56 +00:00
enableGreekTransliteration == other.enableGreekTransliteration &&
enableBelarusianTransliteration == other.enableBelarusianTransliteration &&
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
chinese == other.chinese &&
#endif
romaji == other.romaji;
2009-05-11 23:37:18 +00:00
}
bool operator != ( Transliteration const & other ) const
{ return ! operator == ( other ); }
2009-05-11 23:37:18 +00:00
Transliteration():
enableRussianTransliteration( false ),
enableGermanTransliteration( false ),
2013-01-18 19:21:56 +00:00
enableGreekTransliteration( false ),
enableBelarusianTransliteration( false )
{}
};
struct Lingua
{
bool enable;
QString languageCodes;
bool operator == ( Lingua const & other ) const
{ return enable == other.enable &&
languageCodes == other.languageCodes;
}
bool operator != ( Lingua const & other ) const
{ return ! operator == ( other ); }
};
struct Forvo
{
bool enable;
QString apiKey;
QString languageCodes;
Forvo(): enable( false )
{}
bool operator == ( Forvo const & other ) const
{ return enable == other.enable &&
apiKey == other.apiKey &&
languageCodes == other.languageCodes;
}
bool operator != ( Forvo const & other ) const
{ return ! operator == ( other ); }
};
struct Program
{
bool enabled;
enum Type
{
Audio,
PlainText,
Html,
PrefixMatch,
MaxTypeValue
} type;
QString id, name, commandLine;
2012-12-07 11:59:59 +00:00
QString iconFilename;
Program(): enabled( false )
{}
Program( bool enabled_, Type type_, QString const & id_,
2012-12-09 17:29:27 +00:00
QString const & name_, QString const & commandLine_, QString const & iconFilename_ ):
enabled( enabled_ ), type( type_ ), id( id_ ), name( name_ ),
2012-12-07 11:59:59 +00:00
commandLine( commandLine_ ), iconFilename( iconFilename_ ) {}
bool operator == ( Program const & other ) const
{ return enabled == other.enabled &&
type == other.type &&
name == other.name &&
2012-12-07 11:59:59 +00:00
commandLine == other.commandLine &&
iconFilename == other.iconFilename;
}
bool operator != ( Program const & other ) const
{ return ! operator == ( other ); }
};
2012-12-10 12:49:45 +00:00
typedef QVector< Program > Programs;
struct VoiceEngine
{
bool enabled;
//engine name.
QString engine_name;
QString name;
//voice name.
QString voice_name;
QString iconFilename;
QLocale locale;
int volume; // 0~1 allowed
int rate; // -1 ~ 1 allowed
VoiceEngine():
enabled( false ),
volume( 50 ),
rate( 0 )
{
}
VoiceEngine( QString engine_nane_, QString name_, QString voice_name_, QLocale locale_, int volume_, int rate_ ):
enabled( false ),
engine_name( engine_nane_ ),
name( name_ ),
voice_name( voice_name_ ),
locale( locale_ ),
volume( volume_ ),
rate( rate_ )
{}
bool operator == ( VoiceEngine const & other ) const
{
return enabled == other.enabled && engine_name == other.engine_name && name == other.name
&& voice_name == other.voice_name && locale == other.locale && iconFilename == other.iconFilename
&& volume == other.volume && rate == other.rate;
}
bool operator != ( VoiceEngine const & other ) const
{ return ! operator == ( other ); }
};
typedef QVector< VoiceEngine> VoiceEngines;
struct HeadwordsDialog
{
int searchMode;
bool matchCase;
bool autoApply;
QString headwordsExportPath;
QByteArray headwordsDialogGeometry;
HeadwordsDialog() :
searchMode( 0 ), matchCase( false )
, autoApply( false )
{}
};
struct Class
{
Paths paths;
SoundDirs soundDirs;
Group dictionaryOrder;
Group inactiveDictionaries;
Groups groups;
Preferences preferences;
MediaWikis mediawikis;
WebSites webSites;
2014-04-30 12:55:53 +00:00
DictServers dictServers;
2009-04-09 14:15:01 +00:00
Hunspell hunspell;
Transliteration transliteration;
Lingua lingua;
Forvo forvo;
Programs programs;
VoiceEngines voiceEngines;
unsigned lastMainGroupId; // Last used group in main window
unsigned lastPopupGroupId; // Last used group in popup window
2012-12-07 11:59:59 +00:00
QByteArray popupWindowState; // Binary state saved by QMainWindow
QByteArray popupWindowGeometry; // Geometry saved by QMainWindow
QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window
QByteArray inspectorGeometry; // Geometry of WebKit inspector window
QByteArray dictionariesDialogGeometry; // Geometry of Dictionaries dialog
2014-06-23 15:11:15 +00:00
QByteArray helpWindowGeometry; // Geometry of help window
QByteArray helpSplitterState; // Geometry of help splitter
QString historyExportPath; // Path for export/import history
QString resourceSavePath; // Path to save images/audio
QString articleSavePath; // Path to save articles
bool pinPopupWindow; // Last pin status
bool popupWindowAlwaysOnTop; // Last status of pinned popup window
QByteArray mainWindowState; // Binary state saved by QMainWindow
QByteArray mainWindowGeometry; // Geometry saved by QMainWindow
MutedDictionaries mutedDictionaries; // Disabled via dictionary bar
MutedDictionaries popupMutedDictionaries; // Disabled via dictionary bar in popup
QDateTime timeForNewReleaseCheck; // Only effective if
// preferences.checkForNewReleases is set
QString skippedRelease; // Empty by default
bool showingDictBarNames;
bool usingSmallIconsInToolbars;
2012-12-07 11:59:29 +00:00
int maxPictureWidth; // Maximum picture width
/// Maximum size for the headwords.
/// Bigger headwords won't be indexed. For now, only in DSL.
unsigned int maxHeadwordSize;
unsigned int maxHeadwordsToExpand;
HeadwordsDialog headwordsDialog;
2012-11-28 19:32:37 +00:00
QString editDictionaryCommandLine; // Command line to call external editor for dictionary
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),
pinPopupWindow( false ), showingDictBarNames( false ),
usingSmallIconsInToolbars( false ),
maxPictureWidth( 0 ), maxHeadwordSize ( 256U ),
maxHeadwordsToExpand( 0 )
{}
Group * getGroup( unsigned id );
Group const * getGroup( unsigned id ) const;
};
2012-12-07 11:59:29 +00:00
#ifdef Q_OS_WIN
#pragma pack(pop)
#endif
/// Configuration-specific events. Some parts of the program need to react
/// to specific changes in configuration. The object of this class is used
/// to emit signals when such events happen -- and the listeners connect to
/// them to be notified of them.
/// This class is separate from the main Class since QObjects can't be copied.
class Events: public QObject
{
Q_OBJECT
public:
/// Signals that the value of the mutedDictionaries has changed.
/// This emits mutedDictionariesChanged() signal, so the subscribers will
/// be notified.
void signalMutedDictionariesChanged();
signals:
/// THe value of the mutedDictionaries has changed.
void mutedDictionariesChanged();
private:
};
DEF_EX( exError, "Error with the program's configuration", std::exception )
DEF_EX( exCantUseDataDir, "Can't use XDG_DATA_HOME directory to store GoldenDict data", exError )
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
2022-01-09 08:35:07 +00:00
Class load() ;
/// Saves the configuration
2022-01-09 08:35:07 +00:00
void save( Class const & ) ;
/// Returns the configuration file name.
QString getConfigFileName();
/// Returns the main configuration directory.
2022-01-09 08:35:07 +00:00
QString getConfigDir() ;
/// Returns the index directory, where the indices are to be stored.
2022-01-09 08:35:07 +00:00
QString getIndexDir() ;
/// Returns the filename of a .pid file which should store current pid of
/// the process.
2022-01-09 08:35:07 +00:00
QString getPidFileName() ;
/// Returns the filename of a history file which stores search history.
2022-01-09 08:35:07 +00:00
QString getHistoryFileName() ;
2017-05-05 14:39:51 +00:00
/// Returns the filename of a favorities file.
2022-01-09 08:35:07 +00:00
QString getFavoritiesFileName() ;
2017-05-05 14:39:51 +00:00
/// Returns the user .css file name.
2022-01-09 08:35:07 +00:00
QString getUserCssFileName() ;
2009-05-01 12:20:33 +00:00
/// Returns the user .css file name used for printing only.
2022-01-09 08:35:07 +00:00
QString getUserCssPrintFileName() ;
2009-05-01 12:20:33 +00:00
/// Returns the user .css file name for the Qt interface customization.
2022-01-09 08:35:07 +00:00
QString getUserQtCssFileName() ;
/// 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() noexcept;
/// Returns the directory storing program localizized files (.qm).
QString getLocDir() noexcept;
2014-06-24 13:55:06 +00:00
/// Returns the directory storing program help files (.qch).
QString getHelpDir() noexcept;
2014-06-24 13:55:06 +00:00
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
/// Returns the directory storing OpenCC configuration and dictionary files (.json and .ocd).
QString getOpenCCDir() noexcept;
#endif
/// Returns true if the program is configured as a portable version. In that
/// mode, all the settings and indices are kept in the program's directory.
bool isPortableVersion() noexcept;
/// Returns directory with dictionaries for portable version. It is content/
/// in the application's directory.
QString getPortableVersionDictionaryDir() noexcept;
/// Returns directory with morpgologies for portable version. It is
/// content/morphology in the application's directory.
QString getPortableVersionMorphoDir() noexcept;
2012-12-10 14:14:13 +00:00
/// Returns the add-on styles directory.
2022-02-13 06:26:45 +00:00
QString getStylesDir();
2012-12-10 14:14:13 +00:00
/// Returns the directory where user-specific non-essential (cached) data should be written.
QString getCacheDir() noexcept;
/// Returns the article network disk cache directory.
QString getNetworkCacheDir() noexcept;
}
Q_DECLARE_METATYPE( Config::InputPhrase )
#endif