Changed: Use servers and profiles ID instead of indices for uninstall

This commit is contained in:
kervala 2016-06-14 19:43:45 +02:00
parent 388b7239bf
commit 94bf161016
8 changed files with 30 additions and 16 deletions

View file

@ -277,6 +277,17 @@ CProfile CConfigFile::getProfile(int i) const
return m_profiles.at(i); return m_profiles.at(i);
} }
CProfile CConfigFile::getProfile(const QString &id) const
{
for (int i = 0; i < m_profiles.size(); ++i)
{
if (m_profiles[i].id == id) return m_profiles[i];
}
// default profile
return getProfile();
}
void CConfigFile::setProfile(int i, const CProfile &profile) void CConfigFile::setProfile(int i, const CProfile &profile)
{ {
m_profiles[i] = profile; m_profiles[i] = profile;

View file

@ -106,6 +106,7 @@ public:
int getProfilesCount() const; int getProfilesCount() const;
CProfile getProfile(int i = -1) const; CProfile getProfile(int i = -1) const;
CProfile getProfile(const QString &id) const;
void setProfile(int i, const CProfile &profile); void setProfile(int i, const CProfile &profile);
int addProfile(const CProfile &profile); int addProfile(const CProfile &profile);
void removeProfile(int i); void removeProfile(int i);

View file

@ -114,7 +114,7 @@ int main(int argc, char *argv[])
// add all servers by default // add all servers by default
for (int i = 0; i < config.getServersCount(); ++i) for (int i = 0; i < config.getServersCount(); ++i)
{ {
components.servers << i; components.servers << config.getServer(i).id;
} }
// show uninstall wizard dialog if not in silent mode // show uninstall wizard dialog if not in silent mode

View file

@ -197,7 +197,7 @@ void CMainWindow::onUninstall()
// add all servers by default // add all servers by default
for (int i = 0; i < config->getServersCount(); ++i) for (int i = 0; i < config->getServersCount(); ++i)
{ {
components.servers << i; components.servers << config->getServer(i).id;
} }
{ {

View file

@ -40,8 +40,8 @@ struct SUninstallComponents
installer = true; installer = true;
} }
QVector<int> servers; QStringList servers;
QVector<int> profiles; QStringList profiles;
bool installer; bool installer;
}; };

View file

@ -708,7 +708,7 @@ void COperationDialog::deleteComponentsServers()
int i = 0; int i = 0;
foreach(int serverIndex, m_components.servers) foreach(const QString &serverId, m_components.servers)
{ {
if (operationShouldStop()) if (operationShouldStop())
{ {
@ -716,7 +716,7 @@ void COperationDialog::deleteComponentsServers()
return; return;
} }
const CServer &server = config->getServer(serverIndex); const CServer &server = config->getServer(serverId);
emit progress(i++, server.name); emit progress(i++, server.name);
@ -747,7 +747,7 @@ void COperationDialog::deleteComponentsProfiles()
int i = 0; int i = 0;
foreach(int profileIndex, m_components.profiles) foreach(const QString &profileId, m_components.profiles)
{ {
if (operationShouldStop()) if (operationShouldStop())
{ {
@ -755,7 +755,7 @@ void COperationDialog::deleteComponentsProfiles()
return; return;
} }
const CProfile &profile = config->getProfile(profileIndex); const CProfile &profile = config->getProfile(profileId);
emit progress(i++, profile.name); emit progress(i++, profile.name);

View file

@ -53,7 +53,7 @@ CUninstallDialog::CUninstallDialog(QWidget *parent):QDialog(parent), m_installer
if (QFile::exists(config->getInstallationDirectory() + "/" + server.id)) if (QFile::exists(config->getInstallationDirectory() + "/" + server.id))
{ {
m_serversIndices[row] = model->rowCount(); m_serversIndices[server.id] = model->rowCount();
item = new QStandardItem(tr("Client for %1").arg(server.name)); item = new QStandardItem(tr("Client for %1").arg(server.name));
item->setCheckable(true); item->setCheckable(true);
@ -66,10 +66,10 @@ CUninstallDialog::CUninstallDialog(QWidget *parent):QDialog(parent), m_installer
// profiles // profiles
for (int row = 0; row < profilesCount; ++row) for (int row = 0; row < profilesCount; ++row)
{ {
m_profilesIndices[row] = model->rowCount();
const CProfile &profile = config->getProfile(row); const CProfile &profile = config->getProfile(row);
m_profilesIndices[profile.id] = model->rowCount();
item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name)); item = new QStandardItem(tr("Profile #%1: %2").arg(profile.id).arg(profile.name));
item->setCheckable(true); item->setCheckable(true);
model->appendRow(item); model->appendRow(item);
@ -122,7 +122,7 @@ void CUninstallDialog::setSelectedComponents(const SUninstallComponents &compone
QStandardItem *item = NULL; QStandardItem *item = NULL;
// servers // servers
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end(); IDIndicesMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
while (it != iend) while (it != iend)
{ {
@ -160,7 +160,7 @@ SUninstallComponents CUninstallDialog::getSelectedCompenents() const
QStandardItem *item = NULL; QStandardItem *item = NULL;
// servers // servers
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end(); IDIndicesMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
while (it != iend) while (it != iend)
{ {
@ -222,7 +222,7 @@ void CUninstallDialog::updateSizes()
CConfigFile *config = CConfigFile::getInstance(); CConfigFile *config = CConfigFile::getInstance();
// clients // clients
QMap<int, int>::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end(); IDIndicesMap::const_iterator it = m_serversIndices.begin(), iend = m_serversIndices.end();
while(it != iend) while(it != iend)
{ {

View file

@ -55,8 +55,10 @@ private:
void updateButtons(); void updateButtons();
// key is original ID, value is row index // key is original ID, value is row index
QMap<int, int> m_serversIndices; typedef QMap<QString, int> IDIndicesMap;
QMap<int, int> m_profilesIndices;
IDIndicesMap m_serversIndices;
IDIndicesMap m_profilesIndices;
int m_installerIndex; int m_installerIndex;
}; };