diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp index bc3cf8d76..e56eb0b96 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp @@ -60,6 +60,7 @@ void CProfilesDialog::accept() void CProfilesDialog::onAddProfile() { + addProfile(); } void CProfilesDialog::onDeleteProfile() @@ -137,7 +138,50 @@ void CProfilesDialog::deleteProfile(int index) void CProfilesDialog::addProfile() { - // TODO: browse all folders in AppData/Roaming/Ryzom + int index = m_model->rowCount(); + + // append the new profile + m_model->insertRow(index); + + CConfigFile *config = CConfigFile::getInstance(); + + CProfile &profile = m_model->getProfiles()[index]; + const CServer &server = config->getServer(config->getDefaultServerIndex()); + + int nextId = 0; + + // search an ID that doesn't correspond to an existing profile directory + while (QFile::exists(config->getProfileDirectory() + "/" + QString::number(nextId))) ++nextId; + + // increment this ID until not used in profiles + while(nextId < 100) + { + bool found = false; + + // search if this ID is already used in existing profiles + foreach(const CProfile &p, m_model->getProfiles()) + { + if (p.id == QString::number(nextId)) + { + found = true; + break; + } + } + + if (!found) break; + + // increment ID + ++nextId; + } + + // set default parameters + profile.id = QString::number(nextId); + profile.server = server.id; + + profilesListView->setCurrentIndex(m_model->index(index, 0)); + displayProfile(index); + + // TODO: copy files to new server if files don't exist } void CProfilesDialog::updateExecutableVersion(int index) diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp index 9f8ee02ff..42f07ad4c 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp @@ -27,6 +27,21 @@ QVariant CProfilesModel::data(const QModelIndex &index, int role) const return tr("#%1: %2").arg(profile.id).arg(profile.name); } +bool CProfilesModel::insertRows(int row, int count, const QModelIndex &parent) +{ + if (row < 0) return false; + + beginInsertRows(parent, row, row + count - 1); + + // prepend empty profiles + CProfile profile; + m_profiles.insert(row, count, profile); + + endInsertRows(); + + return true; +} + bool CProfilesModel::removeRows(int row, int count, const QModelIndex &parent) { if (row < 0) return false; diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h index 4a3a71a77..ca78ec028 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h @@ -19,6 +19,7 @@ public: virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); CProfiles& getProfiles() { return m_profiles; }