This is the serverlist.cpp:
#include <QDir>
#include <QMessageBox>
#include "serverlist.h"
QList<Server> listofServers;
serverList::serverList()
{
settings = new Settings();
QFile serverDataFile
(settings
->getappDataDir
() + QDir::separator() + "servers" + QDir::separator() + "servers.dat");
serverDataFileInfo
= new QFileInfo(serverDataFile
);
}
void serverList::saveServers()
{
if(serverDataFileInfo->exists())
{
QDir newFile
(serverDataFileInfo
->absoluteFilePath
());
newFile.mkpath(serverDataFileInfo->absolutePath());
}
if(!serverDataFile.
open(QIODevice::ReadWrite)) {
QMessageBox::critical( 0,
"Post program",
"There was a problem reading the server settings file" );
}
outputStream << listofServers;
}
void serverList::addServer(Server newServer)
{
}
#include <QDir>
#include <QMessageBox>
#include "serverlist.h"
QList<Server> listofServers;
serverList::serverList()
{
settings = new Settings();
QFile serverDataFile(settings->getappDataDir() + QDir::separator() + "servers" + QDir::separator() + "servers.dat");
serverDataFileInfo = new QFileInfo(serverDataFile);
QDataStream outputStream(&serverDataFile);
QDataStream inputStream(&serverDataFile);
}
void serverList::saveServers()
{
if(serverDataFileInfo->exists())
{
QDir newFile(serverDataFileInfo->absoluteFilePath());
newFile.mkpath(serverDataFileInfo->absolutePath());
}
if(!serverDataFile.open(QIODevice::ReadWrite))
{
QMessageBox::critical( 0, "Post program","There was a problem reading the server settings file" );
}
outputStream << listofServers;
}
void serverList::addServer(Server newServer)
{
}
To copy to clipboard, switch view to plain text mode
This is the serverlist.h:
#ifndef SERVERLIST_H
#define SERVERLIST_H
#include <QList>
#include <QFile>
#include <QFileInfo>
#include <QDataStream>
#include <server.h>
#include <settings.h>
class serverList
{
public:
serverList();
void saveServers();
void addServer(Server newServer);
void loadServers();
private:
static QList<Server> listofServers;
Settings *settings;
};
#endif // SERVERLIST_H
#ifndef SERVERLIST_H
#define SERVERLIST_H
#include <QList>
#include <QFile>
#include <QFileInfo>
#include <QDataStream>
#include <server.h>
#include <settings.h>
class serverList
{
public:
serverList();
void saveServers();
void addServer(Server newServer);
void loadServers();
private:
static QList<Server> listofServers;
Settings *settings;
QFileInfo *serverDataFileInfo;
QFile serverDataFile;
QDataStream outputStream;
QDataStream inputStream;
};
#endif // SERVERLIST_H
To copy to clipboard, switch view to plain text mode
I will post the Server class also to get the complete picture
server.cpp:
#include "server.h"
//#include <QDataStream>
Server::Server()
{
}
void Server
::setAddres(QString newAddres
) {
serverAddres = newAddres;
}
void Server
::setNickname(QString newNickname
) {
serverNickname = newNickname;
}
void Server::setPort(qint32 newPort)
{
serverPort = newPort;
}
void Server::setConnections(qint32 newConnections)
{
serverConnections = newConnections;
}
void Server
::setUsername(QString newUsername
) {
serverUsername = newUsername;
}
void Server
::setPassword(QString newPassword
) {
serverPassword = newPassword;
}
void Server::setRequireLogin(bool newRequireLogin)
{
serverRequireLogin = newRequireLogin;
}
void Server::setUseSsl(bool newUseSsl)
{
serverUseSsl = newUseSsl;
}
{
return serverAddres;
}
{
return serverNickname;
}
qint32 Server::getPort()
{
return serverPort;
}
qint32 Server::getConnections()
{
return serverConnections;
}
{
return serverUsername;
}
{
return serverPassword;
}
bool Server::getRequireLogin()
{
return serverRequireLogin;
}
bool Server::getUseSsl()
{
return serverUseSsl;
}
QDataStream& operator<<(QDataStream& out, const Server& server)
{
out << server.serverAddres;
out << server.serverNickname;
out << server.serverPort;
out << server.serverConnections;
out << server.serverUsername;
out << server.serverPassword;
out << server.serverRequireLogin;
out << server.serverUseSsl;
return out;
}
QDataStream& operator>>(QDataStream& in,Server& server)
{
in >> server.serverAddres;
in >> server.serverNickname;
in >> server.serverPort;
in >> server.serverConnections;
in >> server.serverUsername;
in >> server.serverPassword;
in >> server.serverRequireLogin;
in >> server.serverUseSsl;
return in;
}
#include "server.h"
//#include <QDataStream>
Server::Server()
{
}
void Server::setAddres(QString newAddres)
{
serverAddres = newAddres;
}
void Server::setNickname(QString newNickname)
{
serverNickname = newNickname;
}
void Server::setPort(qint32 newPort)
{
serverPort = newPort;
}
void Server::setConnections(qint32 newConnections)
{
serverConnections = newConnections;
}
void Server::setUsername(QString newUsername)
{
serverUsername = newUsername;
}
void Server::setPassword(QString newPassword)
{
serverPassword = newPassword;
}
void Server::setRequireLogin(bool newRequireLogin)
{
serverRequireLogin = newRequireLogin;
}
void Server::setUseSsl(bool newUseSsl)
{
serverUseSsl = newUseSsl;
}
QString Server::getAddres()
{
return serverAddres;
}
QString Server::getNickname()
{
return serverNickname;
}
qint32 Server::getPort()
{
return serverPort;
}
qint32 Server::getConnections()
{
return serverConnections;
}
QString Server::getUsername()
{
return serverUsername;
}
QString Server::getPassword()
{
return serverPassword;
}
bool Server::getRequireLogin()
{
return serverRequireLogin;
}
bool Server::getUseSsl()
{
return serverUseSsl;
}
QDataStream& operator<<(QDataStream& out, const Server& server)
{
out << server.serverAddres;
out << server.serverNickname;
out << server.serverPort;
out << server.serverConnections;
out << server.serverUsername;
out << server.serverPassword;
out << server.serverRequireLogin;
out << server.serverUseSsl;
return out;
}
QDataStream& operator>>(QDataStream& in,Server& server)
{
in >> server.serverAddres;
in >> server.serverNickname;
in >> server.serverPort;
in >> server.serverConnections;
in >> server.serverUsername;
in >> server.serverPassword;
in >> server.serverRequireLogin;
in >> server.serverUseSsl;
return in;
}
To copy to clipboard, switch view to plain text mode
server.h
#ifndef SERVER_H
#define SERVER_H
#include <QString>
#include <QtGlobal>
class Server
{
public:
Server();
//Set functions
void setNickname
(QString newNickname
);
void setPort(qint32 newPort);
void setConnections(qint32 newConnections);
void setUsername
(QString newUsername
);
void setPassword
(QString newPassword
);
void setRequireLogin(bool newRequireLogin);
void setUseSsl(bool newUseSsl);
//Get functions
qint32 getPort();
qint32 getConnections();
bool getRequireLogin();
bool getUseSsl();
private:
qint32 serverPort;
qint32 serverConnections;
bool serverRequireLogin;
bool serverUseSsl;
};
#endif // SERVER_H
#ifndef SERVER_H
#define SERVER_H
#include <QString>
#include <QtGlobal>
class Server
{
public:
Server();
//Set functions
void setAddres(QString newAddres);
void setNickname(QString newNickname);
void setPort(qint32 newPort);
void setConnections(qint32 newConnections);
void setUsername(QString newUsername);
void setPassword(QString newPassword);
void setRequireLogin(bool newRequireLogin);
void setUseSsl(bool newUseSsl);
//Get functions
QString getAddres();
QString getNickname();
qint32 getPort();
qint32 getConnections();
QString getUsername();
QString getPassword();
bool getRequireLogin();
bool getUseSsl();
private:
QString serverAddres;
QString serverNickname;
qint32 serverPort;
qint32 serverConnections;
QString serverUsername;
QString serverPassword;
bool serverRequireLogin;
bool serverUseSsl;
};
#endif // SERVER_H
To copy to clipboard, switch view to plain text mode
Bookmarks