mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-23 07:36:16 +00:00
Changed: Adding new profile
--HG-- branch : develop
This commit is contained in:
parent
d8f53a1fcb
commit
32e3dfe54b
3 changed files with 61 additions and 1 deletions
|
@ -60,6 +60,7 @@ void CProfilesDialog::accept()
|
||||||
|
|
||||||
void CProfilesDialog::onAddProfile()
|
void CProfilesDialog::onAddProfile()
|
||||||
{
|
{
|
||||||
|
addProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProfilesDialog::onDeleteProfile()
|
void CProfilesDialog::onDeleteProfile()
|
||||||
|
@ -137,7 +138,50 @@ void CProfilesDialog::deleteProfile(int index)
|
||||||
|
|
||||||
void CProfilesDialog::addProfile()
|
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)
|
void CProfilesDialog::updateExecutableVersion(int index)
|
||||||
|
|
|
@ -27,6 +27,21 @@ QVariant CProfilesModel::data(const QModelIndex &index, int role) const
|
||||||
return tr("#%1: %2").arg(profile.id).arg(profile.name);
|
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)
|
bool CProfilesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (row < 0) return false;
|
if (row < 0) return false;
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) 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());
|
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
|
||||||
|
|
||||||
CProfiles& getProfiles() { return m_profiles; }
|
CProfiles& getProfiles() { return m_profiles; }
|
||||||
|
|
Loading…
Reference in a new issue