fixed issue of loading the correct instance of RetroShare.conf when switching locations (Patch from AsamK #3423256)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4637 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-10-14 21:16:34 +00:00
parent 7a98e83df1
commit 6989a40312
6 changed files with 37 additions and 18 deletions

View File

@ -76,9 +76,9 @@
// the one and only global settings object
RshareSettings *Settings = NULL;
/*static*/ void RshareSettings::Create ()
/*static*/ void RshareSettings::Create(bool forceCreateNew)
{
if (Settings && Settings->m_bValid == false) {
if (Settings && (forceCreateNew || Settings->m_bValid == false)) {
// recreate with correct path
delete (Settings);
Settings = NULL;

View File

@ -86,7 +86,7 @@ public:
public:
/* create settings object */
static void Create ();
static void Create(bool forceCreateNew = false);
/** Gets the currently preferred language code for RShare. */
QString getLanguageCode();

View File

@ -123,6 +123,15 @@ LanguageSupport::translate(const QString &languageCode)
{
if (!isValidLanguageCode(languageCode))
return false;
static QTranslator *retroshareTranslator = NULL;
if (retroshareTranslator) {
// remove the previous translator, is needed, when switching to en
QApplication::removeTranslator(retroshareTranslator);
delete(retroshareTranslator);
retroshareTranslator = NULL;
}
if (languageCode == "en")
return true;
@ -144,7 +153,7 @@ LanguageSupport::translate(const QString &languageCode)
}
/* Install a translator for RetroShare's UI widgets */
QTranslator *retroshareTranslator = new QTranslator(rApp);
retroshareTranslator = new QTranslator(rApp);
Q_CHECK_PTR(retroshareTranslator);
if (retroshareTranslator->load(":/lang/retroshare_" + languageCode + ".qm")) {
@ -152,5 +161,6 @@ LanguageSupport::translate(const QString &languageCode)
return true;
}
delete retroshareTranslator;
retroshareTranslator = NULL;
return false;
}

View File

@ -212,14 +212,16 @@ int main(int argc, char *argv[])
return 1;
}
/* recreate global settings object, now with correct path */
RshareSettings::Create(true);
Rshare::resetLanguageAndStyle();
splashScreen.showMessage(rshare.translate("SplashScreen", "Load configuration"), Qt::AlignHCenter | Qt::AlignBottom);
rsicontrol->StartupRetroShare();
splashScreen.showMessage(rshare.translate("SplashScreen", "Create interface"), Qt::AlignHCenter | Qt::AlignBottom);
/* recreate global settings object, now with correct path */
RshareSettings::Create ();
RsharePeerSettings::Create();
#ifdef MINIMAL_RSGUI
@ -272,9 +274,7 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w->sharedfilesDialog ,SLOT(postModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ;
QObject::connect(notify,SIGNAL(friendsChanged()) ,w->friendsDialog ,SLOT(insertPeers() )) ;
QObject::connect(notify,SIGNAL(publicChatChanged(int)) ,w->friendsDialog ,SLOT(publicChatChanged(int) ));
QObject::connect(notify,SIGNAL(groupsChanged(int)) ,w->friendsDialog ,SLOT(groupsChanged(int) ));
QObject::connect(notify,SIGNAL(privateChatChanged(int, int)) ,w ,SLOT(privateChatChanged(int, int) ));
QObject::connect(notify,SIGNAL(neighboursChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ;
QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ;
@ -291,8 +291,6 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(discInfoChanged()) ,w->networkDialog,SLOT(updateNewDiscoveryInfo()),Qt::QueuedConnection) ;
QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ;
QObject::connect(w->friendsDialog,SIGNAL(friendsUpdated()),w->networkDialog,SLOT(insertConnect())) ;
w->installGroupChatNotifier();
/* only show window, if not startMinimized */

View File

@ -122,14 +122,7 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, QString dir)
/** Initialize support for language translations. */
//LanguageSupport::initialize();
/** Translate the GUI to the appropriate language. */
setLanguage(_args.value(ARG_LANGUAGE));
/** Set the GUI style appropriately. */
setStyle(_args.value(ARG_GUISTYLE));
/** Set the GUI stylesheet appropriately. */
setSheet(_args.value(ARG_GUISTYLESHEET));
resetLanguageAndStyle();
/* Switch off auto shutdown */
setQuitOnLastWindowClosed ( false );
@ -355,6 +348,18 @@ Rshare::setSheet(QString sheet)
}
void Rshare::resetLanguageAndStyle()
{
/** Translate the GUI to the appropriate language. */
setLanguage(_args.value(ARG_LANGUAGE));
/** Set the GUI style appropriately. */
setStyle(_args.value(ARG_GUISTYLE));
/** Set the GUI stylesheet appropriately. */
setSheet(_args.value(ARG_GUISTYLESHEET));
}
/** Returns the directory RetroShare uses for its data files. */
QString
Rshare::dataDirectory()

View File

@ -78,6 +78,12 @@ public:
/** Sets the current GUI stylesheet. */
static bool setSheet(QString sheet = QString());
/**
* Update Language, Style and StyleSheet.
* First args are cheked for a style then the settings.
*/
static void resetLanguageAndStyle();
/** Returns the current language. */
static QString language() { return _language; }