mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Support for portable version mode.
To enable portable version mode, simply create the portable/ directory in the same directory where the executable itself lives. In portable version all dictionaries live in content/, morphologies in content/morphology. Sound dirs aren't supported in portable version.
This commit is contained in:
parent
68b1e5f262
commit
d59fb9e568
37
config.cc
37
config.cc
|
@ -24,6 +24,9 @@ namespace
|
|||
{
|
||||
QDir getHomeDir()
|
||||
{
|
||||
if ( isPortableVersion() )
|
||||
return QDir( QCoreApplication::applicationDirPath() + "/portable" );
|
||||
|
||||
QDir result = QDir::home();
|
||||
|
||||
char const * pathInHome =
|
||||
|
@ -1062,6 +1065,9 @@ QString getUserQtCssFileName() throw( exError )
|
|||
|
||||
QString getProgramDataDir() throw()
|
||||
{
|
||||
if ( isPortableVersion() )
|
||||
return QCoreApplication::applicationDirPath();
|
||||
|
||||
#ifdef PROGRAM_DATA_DIR
|
||||
return PROGRAM_DATA_DIR;
|
||||
#else
|
||||
|
@ -1077,4 +1083,35 @@ QString getLocDir() throw()
|
|||
return QCoreApplication::applicationDirPath() + "/locale";
|
||||
}
|
||||
|
||||
bool isPortableVersion() throw()
|
||||
{
|
||||
struct IsPortable
|
||||
{
|
||||
bool isPortable;
|
||||
|
||||
IsPortable(): isPortable( QFileInfo( QCoreApplication::applicationDirPath() + "/portable" ).isDir() )
|
||||
{}
|
||||
};
|
||||
|
||||
static IsPortable p;
|
||||
|
||||
return p.isPortable;
|
||||
}
|
||||
|
||||
QString getPortableVersionDictionaryDir() throw()
|
||||
{
|
||||
if ( isPortableVersion() )
|
||||
return getProgramDataDir() + "/content";
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString getPortableVersionMorphoDir() throw()
|
||||
{
|
||||
if ( isPortableVersion() )
|
||||
return getPortableVersionDictionaryDir() + "/morphology";
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
13
config.hh
13
config.hh
|
@ -375,6 +375,19 @@ QString getProgramDataDir() throw();
|
|||
|
||||
/// Returns the directory storing program localizized files (.qm).
|
||||
QString getLocDir() throw();
|
||||
|
||||
/// 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() throw();
|
||||
|
||||
/// Returns directory with dictionaries for portable version. It is content/
|
||||
/// in the application's directory.
|
||||
QString getPortableVersionDictionaryDir() throw();
|
||||
|
||||
/// Returns directory with morpgologies for portable version. It is
|
||||
/// content/morphology in the application's directory.
|
||||
QString getPortableVersionMorphoDir() throw();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "config.hh"
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace Dictionary {
|
||||
|
||||
bool Request::isFinished()
|
||||
|
@ -144,7 +148,33 @@ sptr< DataRequest > Class::getResource( string const & /*name*/ )
|
|||
|
||||
string makeDictionaryId( vector< string > const & dictionaryFiles ) throw()
|
||||
{
|
||||
std::vector< string > sortedList( dictionaryFiles );
|
||||
std::vector< string > sortedList;
|
||||
|
||||
if ( Config::isPortableVersion() )
|
||||
{
|
||||
// For portable version, we use relative paths
|
||||
sortedList.reserve( dictionaryFiles.size() );
|
||||
|
||||
QDir dictionariesDir( Config::getPortableVersionDictionaryDir() );
|
||||
|
||||
for( unsigned x = 0; x < dictionaryFiles.size(); ++x )
|
||||
{
|
||||
string const & full( dictionaryFiles[ x ] );
|
||||
|
||||
QFileInfo fileInfo( QString::fromLocal8Bit( full.c_str() ) );
|
||||
|
||||
if ( fileInfo.isAbsolute() )
|
||||
sortedList.push_back( dictionariesDir.relativeFilePath( fileInfo.filePath() ).toLocal8Bit().data() );
|
||||
else
|
||||
{
|
||||
// Well, it's relative. We don't technically support those, but
|
||||
// what the heck
|
||||
sortedList.push_back( full );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
sortedList = dictionaryFiles;
|
||||
|
||||
std::sort( sortedList.begin(), sortedList.end() );
|
||||
|
||||
|
|
9
main.cc
9
main.cc
|
@ -72,6 +72,15 @@ int main( int argc, char ** argv )
|
|||
|
||||
Config::Class cfg( Config::load() );
|
||||
|
||||
if ( Config::isPortableVersion() )
|
||||
{
|
||||
// For portable version, hardcode some settings
|
||||
|
||||
cfg.paths.clear();
|
||||
cfg.paths.push_back( Config::Path( Config::getPortableVersionDictionaryDir(), true ) );
|
||||
cfg.soundDirs.clear();
|
||||
cfg.hunspell.dictionariesPath = Config::getPortableVersionMorphoDir();
|
||||
}
|
||||
|
||||
// Prevent execution of the 2nd copy
|
||||
|
||||
|
|
46
sources.cc
46
sources.cc
|
@ -6,11 +6,12 @@
|
|||
#include <QMessageBox>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDateTime>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
Sources::Sources( QWidget * parent, Config::Paths const & paths,
|
||||
Config::SoundDirs const & soundDirs,
|
||||
Config::Hunspell const & hunspell,
|
||||
Config::Transliteration const & tr,
|
||||
Config::Transliteration const & trs,
|
||||
Config::MediaWikis const & mediawikis,
|
||||
Config::WebSites const & webSites ): QWidget( parent ),
|
||||
mediawikisModel( this, mediawikis ),
|
||||
|
@ -49,14 +50,41 @@ Sources::Sources( QWidget * parent, Config::Paths const & paths,
|
|||
|
||||
fitHunspellDictsColumns();
|
||||
|
||||
ui.enableRussianTransliteration->setChecked( tr.enableRussianTransliteration );
|
||||
ui.enableGermanTransliteration->setChecked( tr.enableGermanTransliteration );
|
||||
ui.enableRomaji->setChecked( tr.romaji.enable );
|
||||
ui.enableHepburn->setChecked( tr.romaji.enableHepburn );
|
||||
ui.enableNihonShiki->setChecked( tr.romaji.enableNihonShiki );
|
||||
ui.enableKunreiShiki->setChecked( tr.romaji.enableKunreiShiki );
|
||||
ui.enableHiragana->setChecked( tr.romaji.enableHiragana );
|
||||
ui.enableKatakana->setChecked( tr.romaji.enableKatakana );
|
||||
ui.enableRussianTransliteration->setChecked( trs.enableRussianTransliteration );
|
||||
ui.enableGermanTransliteration->setChecked( trs.enableGermanTransliteration );
|
||||
ui.enableRomaji->setChecked( trs.romaji.enable );
|
||||
ui.enableHepburn->setChecked( trs.romaji.enableHepburn );
|
||||
ui.enableNihonShiki->setChecked( trs.romaji.enableNihonShiki );
|
||||
ui.enableKunreiShiki->setChecked( trs.romaji.enableKunreiShiki );
|
||||
ui.enableHiragana->setChecked( trs.romaji.enableHiragana );
|
||||
ui.enableKatakana->setChecked( trs.romaji.enableKatakana );
|
||||
|
||||
if ( Config::isPortableVersion() )
|
||||
{
|
||||
// Paths
|
||||
|
||||
ui.paths->setEnabled( false );
|
||||
ui.addPath->setEnabled( false );
|
||||
ui.removePath->setEnabled( false );
|
||||
|
||||
// Sound dirs
|
||||
|
||||
{
|
||||
QStandardItemModel * model = new QStandardItemModel( this );
|
||||
model->setHorizontalHeaderLabels( QStringList() << " " );
|
||||
model->invisibleRootItem()->appendRow( new QStandardItem( tr( "(not available in portable version)" ) ) );
|
||||
ui.soundDirs->setModel( model );
|
||||
ui.soundDirs->setEnabled( false );
|
||||
|
||||
ui.addSoundDir->setEnabled( false );
|
||||
ui.removeSoundDir->setEnabled( false );
|
||||
}
|
||||
|
||||
// Morpho
|
||||
|
||||
ui.hunspellPath->setEnabled( false );
|
||||
ui.changeHunspellPath->setEnabled( false );
|
||||
}
|
||||
}
|
||||
|
||||
void Sources::fitPathsColumns()
|
||||
|
|
Loading…
Reference in a new issue