fix: default content directory in portable mode (#1872)

* fix: default `content` directory in portable mode

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
alex4814 2024-10-26 19:29:39 +08:00 committed by GitHub
parent 939e786331
commit 7229faeec7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 7 deletions

View file

@ -554,9 +554,13 @@ Class load()
if ( QDir( "/usr/share/myspell/dicts" ).exists() ) if ( QDir( "/usr/share/myspell/dicts" ).exists() )
c.hunspell.dictionariesPath = "/usr/share/myspell/dicts"; c.hunspell.dictionariesPath = "/usr/share/myspell/dicts";
#endif #endif
// Put portable hard-code directory the the config for the first time.
if ( isPortableVersion() ) {
// For portable version, hardcode some settings
c.paths.push_back( Path( getPortableVersionDictionaryDir(), true ) );
}
#ifndef Q_OS_WIN32 #ifndef Q_OS_WIN32
c.preferences.audioPlaybackProgram = "mplayer"; c.preferences.audioPlaybackProgram = "mplayer";
@ -625,6 +629,13 @@ Class load()
Class c; Class c;
// Put the hard-code portable directory to the first.
// To allow additional directories, this path should not be saved.
if ( isPortableVersion() ) {
// For portable version, hardcode some settings
c.paths.push_back( Path( getPortableVersionDictionaryDir(), true ) );
}
QDomNode paths = root.namedItem( "paths" ); QDomNode paths = root.namedItem( "paths" );
if ( !paths.isNull() ) { if ( !paths.isNull() ) {
@ -636,11 +647,6 @@ Class load()
} }
} }
if ( Config::isPortableVersion() && c.paths.empty() ) {
// For portable version, hardcode some settings
c.paths.push_back( Config::Path( Config::getPortableVersionDictionaryDir(), true ) );
}
QDomNode soundDirs = root.namedItem( "sounddirs" ); QDomNode soundDirs = root.namedItem( "sounddirs" );
if ( !soundDirs.isNull() ) { if ( !soundDirs.isNull() ) {
@ -1391,7 +1397,11 @@ void save( Class const & c )
QDomElement paths = dd.createElement( "paths" ); QDomElement paths = dd.createElement( "paths" );
root.appendChild( paths ); root.appendChild( paths );
for ( const auto & i : c.paths ) { // Save all paths except the hard-code portable path,
// which is stored in the first element of list.
qsizetype pos = Config::isPortableVersion();
for ( const auto & i : c.paths.mid( pos ) ) {
QDomElement path = dd.createElement( "path" ); QDomElement path = dd.createElement( "path" );
paths.appendChild( path ); paths.appendChild( path );

View file

@ -1171,6 +1171,13 @@ Qt::ItemFlags PathsModel::flags( QModelIndex const & index ) const
{ {
Qt::ItemFlags result = QAbstractItemModel::flags( index ); Qt::ItemFlags result = QAbstractItemModel::flags( index );
if ( Config::isPortableVersion() ) {
if ( index.isValid() && index.row() == 0 ) {
result &= ~Qt::ItemIsSelectable;
result &= ~Qt::ItemIsEnabled;
}
}
if ( index.isValid() && index.column() == 1 ) { if ( index.isValid() && index.column() == 1 ) {
result |= Qt::ItemIsUserCheckable; result |= Qt::ItemIsUserCheckable;
} }