Changed: Index is not the ID

This commit is contained in:
kervala 2016-05-16 11:12:30 +02:00
parent 224821be7d
commit c84d665027
3 changed files with 29 additions and 49 deletions

View file

@ -29,7 +29,7 @@ const CProfile NoProfile;
CConfigFile *CConfigFile::s_instance = NULL; CConfigFile *CConfigFile::s_instance = NULL;
CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServer(0), m_defaultProfile(0), m_use64BitsClient(false) CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServerIndex(0), m_defaultProfileIndex(0), m_use64BitsClient(false)
{ {
s_instance = this; s_instance = this;
@ -60,7 +60,7 @@ bool CConfigFile::load(const QString &filename)
settings.beginGroup("servers"); settings.beginGroup("servers");
int serversCount = settings.value("size").toInt(); int serversCount = settings.value("size").toInt();
m_defaultServer = settings.value("default").toInt(); m_defaultServerIndex = settings.value("default").toInt();
settings.endGroup(); settings.endGroup();
m_servers.resize(serversCount); m_servers.resize(serversCount);
@ -94,7 +94,7 @@ bool CConfigFile::load(const QString &filename)
settings.beginGroup("profiles"); settings.beginGroup("profiles");
int profilesCounts = settings.value("size").toInt(); int profilesCounts = settings.value("size").toInt();
m_defaultProfile = settings.value("default").toInt(); m_defaultProfileIndex = settings.value("default").toInt();
settings.endGroup(); settings.endGroup();
m_profiles.resize(profilesCounts); m_profiles.resize(profilesCounts);
@ -134,7 +134,7 @@ bool CConfigFile::save() const
settings.beginGroup("servers"); settings.beginGroup("servers");
settings.setValue("size", m_servers.size()); settings.setValue("size", m_servers.size());
settings.setValue("default", m_defaultServer); settings.setValue("default", m_defaultServerIndex);
settings.endGroup(); settings.endGroup();
for(int i = 0; i < m_servers.size(); ++i) for(int i = 0; i < m_servers.size(); ++i)
@ -166,7 +166,7 @@ bool CConfigFile::save() const
settings.beginGroup("profiles"); settings.beginGroup("profiles");
settings.setValue("size", m_profiles.size()); settings.setValue("size", m_profiles.size());
settings.setValue("default", m_defaultProfile); settings.setValue("default", m_defaultProfileIndex);
settings.endGroup(); settings.endGroup();
for(int i = 0; i < m_profiles.size(); ++i) for(int i = 0; i < m_profiles.size(); ++i)
@ -203,7 +203,7 @@ int CConfigFile::getServersCount() const
const CServer& CConfigFile::getServer(int i) const const CServer& CConfigFile::getServer(int i) const
{ {
if (i < 0) i = m_defaultServer; if (i < 0) i = m_defaultServerIndex;
if (i >= m_servers.size()) return NoServer; if (i >= m_servers.size()) return NoServer;
@ -228,7 +228,7 @@ int CConfigFile::getProfilesCount() const
CProfile CConfigFile::getProfile(int i) const CProfile CConfigFile::getProfile(int i) const
{ {
if (i < 0) i = m_defaultProfile; if (i < 0) i = m_defaultProfileIndex;
if (i >= m_profiles.size()) return NoProfile; if (i >= m_profiles.size()) return NoProfile;
@ -259,14 +259,24 @@ bool CConfigFile::has64bitsOS()
return QSysInfo::currentCpuArchitecture() == "x86_64"; return QSysInfo::currentCpuArchitecture() == "x86_64";
} }
int CConfigFile::getDefaultProfile() const int CConfigFile::getDefaultServerIndex() const
{ {
return m_defaultProfile; return m_defaultServerIndex;
} }
int CConfigFile::getDefaultServer() const void CConfigFile::setDefaultServerIndex(int index)
{ {
return m_defaultServer; m_defaultServerIndex = index;
}
int CConfigFile::getDefaultProfileIndex() const
{
return m_defaultProfileIndex;
}
void CConfigFile::setDefaultProfileIndex(int index)
{
m_defaultProfileIndex = index;
} }
bool CConfigFile::isRyzomInstallerConfigured() const bool CConfigFile::isRyzomInstallerConfigured() const
@ -601,33 +611,3 @@ CConfigFile::InstallationStep CConfigFile::getNextStep() const
return Done; return Done;
} }
bool CConfigFile::createDefaultProfile()
{
CServer server = getServer(getDefaultServer());
CProfile profile;
profile.id = 0;
profile.executable = getClientFullPath();
profile.name = QString("Ryzom (%1)").arg(server.name);
profile.server = server.id;
profile.comments = "Default profile created by Ryzom Installer";
#ifdef Q_OS_WIN32
profile.desktopShortcut = QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk");
#endif
// TODO
// profile.menuShortcut
addProfile(profile);
save();
return true;
}
bool CConfigFile::createDefaultShortcuts()
{
return true;
}

View file

@ -119,8 +119,11 @@ public:
int addProfile(const CProfile &profile); int addProfile(const CProfile &profile);
void removeProfile(int i); void removeProfile(int i);
int getDefaultServer() const; int getDefaultServerIndex() const;
int getDefaultProfile() const; void setDefaultServerIndex(int index);
int getDefaultProfileIndex() const;
void setDefaultProfileIndex(int index);
bool isRyzomInstallerConfigured() const; bool isRyzomInstallerConfigured() const;
@ -162,12 +165,9 @@ public:
InstallationStep getNextStep() const; InstallationStep getNextStep() const;
bool createDefaultProfile();
bool createDefaultShortcuts();
private: private:
int m_defaultServer; int m_defaultServerIndex;
int m_defaultProfile; int m_defaultProfileIndex;
CServers m_servers; CServers m_servers;
CProfiles m_profiles; CProfiles m_profiles;

View file

@ -38,7 +38,7 @@ CProfilesDialog::CProfilesDialog():QDialog(), m_currentProfileIndex(-1)
profilesListView->setModel(m_model); profilesListView->setModel(m_model);
serverComboBox->setModel(m_serversModel); serverComboBox->setModel(m_serversModel);
int index = m_model->getIndexFromProfileID(CConfigFile::getInstance()->getDefaultProfile()); int index = m_model->getIndexFromProfileID(CConfigFile::getInstance()->getDefaultProfileIndex());
profilesListView->setCurrentIndex(m_model->index(index, 0)); profilesListView->setCurrentIndex(m_model->index(index, 0));
displayProfile(index); displayProfile(index);