Commit 01478114 authored by Dennis Beier's avatar Dennis Beier
Browse files

added possibilty to add description

parent 61237902
......@@ -36,9 +36,9 @@ ServerChoiceModel::ServerChoiceModel()
}
}
QStringList ServerChoiceModel::getDomainList() const
QList<ServerChoice> ServerChoiceModel::getServerList() const
{
QStringList domains;
QList<ServerChoice> servers;
QSqlQuery domainQuery( mDb );
domainQuery.prepare( "Select * from server_choice" );
......@@ -48,21 +48,24 @@ QStringList ServerChoiceModel::getDomainList() const
QSqlRecord rec = domainQuery.record();
int hostNameCol = rec.indexOf("hostname");
int descCol = rec.indexOf("description");
while ( domainQuery.next() ) {
QString domain = domainQuery.value( hostNameCol ).toString();
domains.append(domain);
QString description = domainQuery.value( descCol ).toString();
servers.append({description,domain});
}
}
domains.push_front("chat.fairkom.net");
return domains;
servers.push_front({"Default Server", "chat.fairkom.net"});
return servers;
}
void ServerChoiceModel::addDomain(QString value)
void ServerChoiceModel::addDomain(QString value, QString description)
{
QSqlQuery domainQuery( mDb );
beginResetModel();
domainQuery.prepare("INSERT INTO server_choice (hostname) VALUES(?)");
domainQuery.prepare("INSERT INTO server_choice (hostname, description) VALUES(?,?)");
domainQuery.addBindValue(value);
domainQuery.addBindValue(description);
if ( !domainQuery.exec() ) {
qWarning() <<"db error"<< domainQuery.lastError();
}
......@@ -82,13 +85,16 @@ void ServerChoiceModel::removeDomain(QString value)
int ServerChoiceModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return getDomainList().count();
return getServerList().count();
}
QVariant ServerChoiceModel::data(const QModelIndex &index, int role) const
{
auto choice = getServerList()[index.row()];
if(role == 1)
return getDomainList()[index.row()];
return choice.domain;
if(role == 2)
return choice.description;
return QVariant();
}
......@@ -96,6 +102,7 @@ QHash<int, QByteArray> ServerChoiceModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[1] = "domain";
roles[2] = "description";
return roles;
}
......
......@@ -26,6 +26,11 @@
#include <QJsonObject>
#include <QAbstractListModel>
struct ServerChoice{
QString description;
QString domain;
};
class ServerChoiceModel : public QAbstractListModel
{
Q_OBJECT
......@@ -33,8 +38,8 @@ class ServerChoiceModel : public QAbstractListModel
public:
Q_PROPERTY(QString currentServer READ getCurrentServer WRITE setCurrentServer NOTIFY currentServerChanged)
ServerChoiceModel(void);
Q_INVOKABLE QStringList getDomainList(void) const;
Q_INVOKABLE void addDomain(QString);
QList<ServerChoice> getServerList(void) const;
Q_INVOKABLE void addDomain(QString,QString);
Q_INVOKABLE void removeDomain(QString);
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
......
......@@ -56,7 +56,7 @@ Page {
Text {
id: serverName
text: model.domain
text: model.description
font.bold: true
textFormat: Text.PlainText
font.family: Fonts.opensans.name
......
......@@ -80,7 +80,7 @@ Popup {
StdButton{
text: qsTr("add")
onPressed: {
serverChoices.addDomain(serverAddress.text)
serverChoices.addDomain(serverAddress.text,serverName.text)
serverSelectionPopup.close()
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment