Reorganised DataFilesPage.cpp code.

Removed some recursive calling of saveSettings() and loadSettings().
This commit is contained in:
dteviot 2015-01-26 18:46:18 +13:00
parent 70e4f821ba
commit e298589e7f
2 changed files with 22 additions and 27 deletions

View file

@ -68,6 +68,23 @@ void Launcher::DataFilesPage::buildView()
}
bool Launcher::DataFilesPage::loadSettings()
{
QStringList profiles = mLauncherSettings.getContentLists();
QString currentProfile = mLauncherSettings.getCurrentContentListName();
qDebug() << "current profile is: " << currentProfile;
foreach (const QString &item, profiles)
addProfile (item, false);
// Hack: also add the current profile
if (!currentProfile.isEmpty())
addProfile(currentProfile, true);
return true;
}
void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName)
{
QStringList paths = mGameSettings.getDataDirs();
@ -82,21 +99,7 @@ bool Launcher::DataFilesPage::loadSettings()
paths.insert(0, mDataLocal);
PathIterator pathIterator(paths);
QStringList profiles = mLauncherSettings.getContentLists();
QString currentProfile = mLauncherSettings.getCurrentContentListName();
qDebug() << "current profile is: " << currentProfile;
foreach (const QString &item, profiles)
addProfile (item, false);
// Hack: also add the current profile
if (!currentProfile.isEmpty())
addProfile(currentProfile, true);
mSelector->setProfileContent(filesInProfile(currentProfile, pathIterator));
return true;
mSelector->setProfileContent(filesInProfile(contentModelName, pathIterator));
}
QStringList Launcher::DataFilesPage::filesInProfile(const QString& profileName, PathIterator& pathIterator)
@ -175,7 +178,7 @@ void Launcher::DataFilesPage::setProfile (const QString &previous, const QString
ui.profilesComboBox->setCurrentProfile (ui.profilesComboBox->findText (current));
loadSettings();
populateFileViews(current);
checkForDefaultProfile();
}
@ -229,13 +232,6 @@ void Launcher::DataFilesPage::on_newProfileAction_triggered()
mLauncherSettings.setCurrentContentListName(profile);
addProfile(profile, true);
mSelector->clearCheckStates();
mSelector->setGameFile();
saveSettings();
emit signalProfileChanged (ui.profilesComboBox->findText(profile));
}
void Launcher::DataFilesPage::addProfile (const QString &profile, bool setAsCurrent)
@ -262,15 +258,13 @@ void Launcher::DataFilesPage::on_deleteProfileAction_triggered()
// this should work since the Default profile can't be deleted and is always index 0
int next = ui.profilesComboBox->currentIndex()-1;
// changing the profile forces a reload of plugin file views.
ui.profilesComboBox->setCurrentIndex(next);
removeProfile(profile);
ui.profilesComboBox->removeItem(ui.profilesComboBox->findText(profile));
saveSettings();
loadSettings();
checkForDefaultProfile();
}

View file

@ -82,6 +82,7 @@ namespace Launcher
bool showDeleteMessageBox (const QString &text);
void addProfile (const QString &profile, bool setAsCurrent);
void checkForDefaultProfile();
void populateFileViews(const QString& contentModelName);
class PathIterator
{