save server profiles
This commit is contained in:
@@ -87,7 +87,11 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="4" >
|
<item row="0" column="4" >
|
||||||
<widget class="QLineEdit" name="lineEdit_password" />
|
<widget class="QLineEdit" name="lineEdit_password" >
|
||||||
|
<property name="echoMode" >
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" >
|
<item row="0" column="1" >
|
||||||
<widget class="QLineEdit" name="lineEdit_ipAddress" />
|
<widget class="QLineEdit" name="lineEdit_ipAddress" />
|
||||||
@@ -122,6 +126,24 @@
|
|||||||
</property>
|
</property>
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0" >
|
||||||
<widget class="QTreeWidget" name="treeWidget" >
|
<widget class="QTreeWidget" name="treeWidget" >
|
||||||
|
<property name="alternatingRowColors" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="indentation" >
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="sortingEnabled" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="animated" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="allColumnsShowFocus" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<column>
|
<column>
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string> Name </string>
|
<string> Name </string>
|
||||||
|
|||||||
@@ -22,18 +22,28 @@
|
|||||||
#include "configfile.h"
|
#include "configfile.h"
|
||||||
#include "tinyxml.h"
|
#include "tinyxml.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent)
|
joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
|
//Profile Name darf nicht mit einer Zahl beginnen --> XML konform
|
||||||
|
QRegExp rx("[A-Z|a-z]+[A-Z|a-z|\\d]*");
|
||||||
|
QValidator *validator = new QRegExpValidator(rx, this);
|
||||||
|
lineEdit_profileName->setValidator(validator);
|
||||||
|
|
||||||
lineEdit_ipAddress->setFocus();
|
lineEdit_ipAddress->setFocus();
|
||||||
|
|
||||||
myConfig = new ConfigFile;
|
myServerProfilesFile = myConfig.readConfigString("DataDir")+"serverprofiles.xml";
|
||||||
|
|
||||||
//Anlegen wenn noch nicht existiert!
|
//Anlegen wenn noch nicht existiert!
|
||||||
QFile serverProfilesfile(QString::fromStdString(myConfig->readConfigString("DataDir")+"serverprofiles.xml"));
|
QFile serverProfilesfile(QString::fromStdString(myServerProfilesFile));
|
||||||
|
|
||||||
|
if(!serverProfilesfile.exists()) {
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "");
|
||||||
doc.LinkEndChild( decl );
|
doc.LinkEndChild( decl );
|
||||||
@@ -44,11 +54,14 @@ joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent)
|
|||||||
TiXmlElement * profiles = new TiXmlElement( "ServerProfiles" );
|
TiXmlElement * profiles = new TiXmlElement( "ServerProfiles" );
|
||||||
root->LinkEndChild( profiles );
|
root->LinkEndChild( profiles );
|
||||||
|
|
||||||
TiXmlElement * profile = new TiXmlElement( lineEdit_profileName->text().toStdString() );
|
doc.SaveFile( myServerProfilesFile );
|
||||||
profiles->LinkEndChild( profile );
|
}
|
||||||
profile->SetAttribute("value", 1);
|
|
||||||
|
//Liste Füllen
|
||||||
|
fillServerProfileList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
doc.SaveFile( myConfig->readConfigString("DataDir")+"serverprofiles.xml" );
|
|
||||||
|
|
||||||
// QShortcut *connectKey = new QShortcut(QKeySequence(Qt::Key_Enter), this);
|
// QShortcut *connectKey = new QShortcut(QKeySequence(Qt::Key_Enter), this);
|
||||||
// connect( connectKey, SIGNAL(activated() ), pushButton_connect, SLOT( click() ) );
|
// connect( connectKey, SIGNAL(activated() ), pushButton_connect, SLOT( click() ) );
|
||||||
@@ -64,9 +77,94 @@ void joinNetworkGameDialogImpl::startClient() {
|
|||||||
// TODO: Check input values!
|
// TODO: Check input values!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void joinNetworkGameDialogImpl::fillServerProfileList() {
|
||||||
|
|
||||||
|
|
||||||
|
treeWidget->clear();
|
||||||
|
|
||||||
|
TiXmlDocument doc(myServerProfilesFile);
|
||||||
|
if(!doc.LoadFile()) {
|
||||||
|
QMessageBox::warning(this, tr("Load Server-Profile-File Error"),
|
||||||
|
tr("Could not load Server-Profiles-File:\n"+QString::fromStdString(myServerProfilesFile).toAscii()),
|
||||||
|
QMessageBox::Close);
|
||||||
|
}
|
||||||
|
TiXmlHandle docHandle( &doc );
|
||||||
|
|
||||||
|
TiXmlElement* profile = docHandle.FirstChild( "PokerTH" ).FirstChild( "ServerProfiles" ).FirstChild().ToElement();
|
||||||
|
if ( profile ) {
|
||||||
|
|
||||||
|
for( profile; profile; profile = profile->NextSiblingElement()) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
|
||||||
|
item->setData(0, 0, profile->Attribute("Name"));
|
||||||
|
item->setData(1, 0, profile->Attribute("Address"));
|
||||||
|
item->setData(2, 0, profile->Attribute("Port"));
|
||||||
|
|
||||||
|
string isIpv6 = "no";
|
||||||
|
int tempInt = 0;
|
||||||
|
profile->QueryIntAttribute("IsIpv6", &tempInt );
|
||||||
|
if( tempInt == 1 ) { isIpv6 = "yes"; }
|
||||||
|
item->setData(3, 0, QString::fromStdString(isIpv6));
|
||||||
|
|
||||||
|
treeWidget->addTopLevelItem(item);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { cout << "No Profiles Found \n"; }
|
||||||
|
|
||||||
|
treeWidget->resizeColumnToContents ( 0 );
|
||||||
|
treeWidget->resizeColumnToContents ( 1 );
|
||||||
|
treeWidget->resizeColumnToContents ( 2 );
|
||||||
|
treeWidget->resizeColumnToContents ( 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void joinNetworkGameDialogImpl::saveServerProfile() {
|
void joinNetworkGameDialogImpl::saveServerProfile() {
|
||||||
|
|
||||||
|
// bool toIntTrue;
|
||||||
|
|
||||||
|
TiXmlDocument doc(myServerProfilesFile);
|
||||||
|
if(!doc.LoadFile()) {
|
||||||
|
QMessageBox::warning(this, tr("Load Server-Profile-File Error"),
|
||||||
|
tr("Could not load Server-Profiles-File:\n"+QString::fromStdString(myServerProfilesFile).toAscii()),
|
||||||
|
QMessageBox::Close);
|
||||||
|
}
|
||||||
|
TiXmlHandle docHandle( &doc );
|
||||||
|
|
||||||
|
TiXmlElement* profiles = docHandle.FirstChild( "PokerTH" ).FirstChild( "ServerProfiles" ).ToElement();
|
||||||
|
if ( profiles ) {
|
||||||
|
|
||||||
|
TiXmlElement * testProfile = docHandle.FirstChild( "PokerTH" ).FirstChild( "ServerProfiles" ).FirstChild( lineEdit_profileName->text().toStdString() ).ToElement();
|
||||||
|
|
||||||
|
if( testProfile ) {
|
||||||
|
// Wenn der Name schon existiert --> Hinweis und nicht speichern
|
||||||
|
QMessageBox::warning(this, tr("Save Server Profile Error"),
|
||||||
|
tr("A Profile with this Name already exists.\nPlease select another Profile Name!"),
|
||||||
|
QMessageBox::Close);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Wenn der Name nicht existiert --> speichern
|
||||||
|
TiXmlElement * profile = new TiXmlElement( lineEdit_profileName->text().toStdString() );
|
||||||
|
profiles->LinkEndChild( profile );
|
||||||
|
profile->SetAttribute("Name", lineEdit_profileName->text().toStdString());
|
||||||
|
profile->SetAttribute("Address", lineEdit_ipAddress->text().toStdString());
|
||||||
|
profile->SetAttribute("Password", lineEdit_password->text().toStdString());
|
||||||
|
profile->SetAttribute("Port", spinBox_port->value());
|
||||||
|
profile->SetAttribute("IsIpv6", checkBox_ipv6->isChecked());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { QMessageBox::warning(this, tr("Read Server-Profile List Error"),
|
||||||
|
tr("Could not read Server-Profiles List"),
|
||||||
|
QMessageBox::Close); }
|
||||||
|
|
||||||
|
if(!doc.SaveFile()) { QMessageBox::warning(this, tr("Save Server-Profile-File Error"),
|
||||||
|
tr("Could not save Server-Profiles-File:\n"+QString::fromStdString(myServerProfilesFile).toAscii()),
|
||||||
|
QMessageBox::Close); }
|
||||||
|
|
||||||
|
fillServerProfileList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void joinNetworkGameDialogImpl::deleteServerProfile() {
|
void joinNetworkGameDialogImpl::deleteServerProfile() {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include "ui_joinnetworkgamedialog.h"
|
#include "ui_joinnetworkgamedialog.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "configfile.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
|
||||||
@@ -34,11 +36,13 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
joinNetworkGameDialogImpl(QWidget *parent = 0);
|
joinNetworkGameDialogImpl(QWidget *parent = 0);
|
||||||
|
|
||||||
ConfigFile *myConfig;
|
ConfigFile myConfig;
|
||||||
|
std::string myServerProfilesFile;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void startClient();
|
void startClient();
|
||||||
|
void fillServerProfileList();
|
||||||
void saveServerProfile();
|
void saveServerProfile();
|
||||||
void deleteServerProfile();
|
void deleteServerProfile();
|
||||||
void keyPressEvent ( QKeyEvent * event );
|
void keyPressEvent ( QKeyEvent * event );
|
||||||
|
|||||||
Reference in New Issue
Block a user