mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-26 02:40:54 +00:00
Changed: Profiles dialog code
This commit is contained in:
parent
38edd05618
commit
eab96ae5fe
3 changed files with 132 additions and 5 deletions
|
@ -16,17 +16,32 @@
|
|||
|
||||
#include "stdpch.h"
|
||||
#include "profilesdialog.h"
|
||||
#include "profilesmodel.h"
|
||||
|
||||
#ifdef DEBUG_NEW
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
CProfilesDialog::CProfilesDialog():QDialog()
|
||||
CProfilesDialog::CProfilesDialog():QDialog(), m_currentProfileIndex(-1)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
connect(addButton, SIGNAL(clicked()), SLOT(onAddProfile));
|
||||
connect(deleteButton, SIGNAL(clicked()), SLOT(onDeleteProfile));
|
||||
connect(addButton, SIGNAL(clicked()), SLOT(onAddProfile()));
|
||||
connect(deleteButton, SIGNAL(clicked()), SLOT(onDeleteProfile()));
|
||||
connect(profilesListView, SIGNAL(clicked(QModelIndex)), SLOT(onProfileClicked(QModelIndex)));
|
||||
connect(executableBrowseButton, SIGNAL(clicked()), SLOT(onExecutableBrowseClicked()));
|
||||
|
||||
m_model = new CProfilesModel(this);
|
||||
|
||||
profilesListView->setModel(m_model);
|
||||
|
||||
QStringList servers;
|
||||
servers << "Atys";
|
||||
servers << "Yubo";
|
||||
|
||||
QStringListModel *serversModel = new QStringListModel(servers, this);
|
||||
|
||||
serverComboBox->setModel(serversModel);
|
||||
}
|
||||
|
||||
CProfilesDialog::~CProfilesDialog()
|
||||
|
@ -35,7 +50,7 @@ CProfilesDialog::~CProfilesDialog()
|
|||
|
||||
void CProfilesDialog::accept()
|
||||
{
|
||||
// TODO: add save code
|
||||
m_model->save();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
@ -46,4 +61,101 @@ void CProfilesDialog::onAddProfile()
|
|||
|
||||
void CProfilesDialog::onDeleteProfile()
|
||||
{
|
||||
QMessageBox::StandardButton res = QMessageBox::question(this, tr("Confirmation"), tr("You're going to delete a profile, files won't be deleted and you'll have to do that manually.\nAre you sure to delete this profile?"));
|
||||
|
||||
if (res != QMessageBox::Yes) return;
|
||||
|
||||
QModelIndex index = profilesListView->currentIndex();
|
||||
|
||||
deleteProfile(index.row());
|
||||
}
|
||||
|
||||
void CProfilesDialog::onProfileClicked(const QModelIndex &index)
|
||||
{
|
||||
qDebug() << "clicked on" << index;
|
||||
|
||||
displayProfile(index.row());
|
||||
}
|
||||
|
||||
void CProfilesDialog::displayProfile(int index)
|
||||
{
|
||||
if (index < 0) return;
|
||||
|
||||
saveProfile(m_currentProfileIndex);
|
||||
|
||||
const CProfile &profile = m_model->getProfiles()[index];
|
||||
|
||||
profileIdLabel->setText(QString::number(profile.id));
|
||||
accountEdit->setText(profile.account);
|
||||
nameEdit->setText(profile.name);
|
||||
serverComboBox->setCurrentIndex(0);
|
||||
executablePathLabel->setText(QFileInfo(profile.executable).fileName());
|
||||
argumentsEdit->setText(profile.arguments);
|
||||
commentsEdit->setPlainText(profile.comments);
|
||||
directoryPathLabel->setText(CConfigFile::getInstance()->getProfileDirectory());
|
||||
|
||||
m_currentProfileIndex = index;
|
||||
}
|
||||
|
||||
void CProfilesDialog::saveProfile(int index)
|
||||
{
|
||||
if (index < 0) return;
|
||||
|
||||
CProfile &profile = m_model->getProfiles()[index];
|
||||
|
||||
profileIdLabel->setText(QString::number(profile.id));
|
||||
profile.account = accountEdit->text();
|
||||
profile.name = nameEdit->text();
|
||||
// serverComboBox->setCurrentIndex(0);
|
||||
profile.arguments = argumentsEdit->text();
|
||||
profile.comments = commentsEdit->toPlainText();
|
||||
}
|
||||
|
||||
void CProfilesDialog::deleteProfile(int index)
|
||||
{
|
||||
if (index < 0) return;
|
||||
|
||||
m_model->removeRow(index);
|
||||
}
|
||||
|
||||
void CProfilesDialog::addProfile()
|
||||
{
|
||||
// TODO: browse all folders in AppData/Roaming/Ryzom
|
||||
}
|
||||
|
||||
void CProfilesDialog::onExecutableBrowseClicked()
|
||||
{
|
||||
if (m_currentProfileIndex < 0) return;
|
||||
|
||||
CProfile &profile = m_model->getProfiles()[m_currentProfileIndex];
|
||||
|
||||
QString file = QFileDialog::getOpenFileName(this, tr("Please choose Ryzom client executable to launch"), profile.executable, tr("Executables (*.exe)"));
|
||||
|
||||
if (file.isEmpty()) return;
|
||||
|
||||
profile.executable = file;
|
||||
|
||||
executablePathLabel->setText(QFileInfo(profile.executable).fileName());
|
||||
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
process.start(profile.executable, QStringList() << "--version", QIODevice::ReadWrite);
|
||||
|
||||
if (!process.waitForStarted()) return;
|
||||
|
||||
QByteArray data;
|
||||
|
||||
while (process.waitForReadyRead()) data.append(process.readAll());
|
||||
|
||||
QString versionString = QString::fromUtf8(data);
|
||||
|
||||
QRegExp reg("([A-Za-z0-1_.]+) ((DEV|FV) ([0-9.]+))");
|
||||
|
||||
if (reg.indexIn(versionString) > -1)
|
||||
{
|
||||
executableVersionLabel->setText(reg.cap(2));
|
||||
}
|
||||
|
||||
// ryzom_client_dev_d.exe DEV 0.12.0.7331 (built on 2016-02-25 22:16:50)
|
||||
// Copyright (C) 2004-2016 Winchgate and The Ryzom Core Community
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "ui_profiles.h"
|
||||
|
||||
class CProfilesModel;
|
||||
|
||||
class CProfilesDialog : public QDialog, public Ui::ProfilesDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -32,6 +34,19 @@ private slots:
|
|||
|
||||
void onAddProfile();
|
||||
void onDeleteProfile();
|
||||
void onProfileClicked(const QModelIndex &index);
|
||||
|
||||
void displayProfile(int index);
|
||||
void saveProfile(int index);
|
||||
void deleteProfile(int index);
|
||||
void addProfile();
|
||||
|
||||
void onExecutableBrowseClicked();
|
||||
|
||||
private:
|
||||
CProfilesModel *m_model;
|
||||
|
||||
int m_currentProfileIndex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -224,7 +224,7 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="clientVersionStringLabel">
|
||||
<widget class="QLabel" name="executableVersionLabel">
|
||||
<property name="text">
|
||||
<string>FV 3.0.0</string>
|
||||
</property>
|
||||
|
|
Loading…
Reference in a new issue