minor fixes, form to join MUC

This commit is contained in:
Blue 2019-09-04 19:38:52 +03:00
parent 5f8d38bd9a
commit c295fa1c1d
23 changed files with 385 additions and 34 deletions

56
ui/widgets/account.cpp Normal file
View file

@ -0,0 +1,56 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "account.h"
#include "ui_account.h"
Account::Account()
: m_ui ( new Ui::Account )
{
m_ui->setupUi ( this );
}
Account::~Account()
{
}
QMap<QString, QVariant> Account::value() const
{
QMap<QString, QVariant> map;
map["login"] = m_ui->login->text();
map["password"] = m_ui->password->text();
map["server"] = m_ui->server->text();
map["name"] = m_ui->name->text();
map["resource"] = m_ui->resource->text();
return map;
}
void Account::lockId()
{
m_ui->name->setReadOnly(true);;
}
void Account::setData(const QMap<QString, QVariant>& data)
{
m_ui->login->setText(data.value("login").toString());
m_ui->password->setText(data.value("password").toString());
m_ui->server->setText(data.value("server").toString());
m_ui->name->setText(data.value("name").toString());
m_ui->resource->setText(data.value("resource").toString());
}

49
ui/widgets/account.h Normal file
View file

@ -0,0 +1,49 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <QScopedPointer>
#include <QDialog>
#include <QMap>
#include <QString>
#include <QVariant>
namespace Ui
{
class Account;
}
class Account : public QDialog
{
Q_OBJECT
public:
Account();
~Account();
QMap<QString, QVariant> value() const;
void setData(const QMap<QString, QVariant>& data);
void lockId();
private:
QScopedPointer<Ui::Account> m_ui;
};
#endif // ACCOUNT_H

177
ui/widgets/account.ui Normal file
View file

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Account</class>
<widget class="QDialog" name="Account">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>395</width>
<height>272</height>
</rect>
</property>
<property name="windowTitle">
<string>Account</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="1" column="1">
<widget class="QLineEdit" name="login">
<property name="toolTip">
<string>Your account login</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Server</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="server">
<property name="toolTip">
<string>A server address of your account. Like 404.city or macaw.me</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="password">
<property name="toolTip">
<string>Password of your account</string>
</property>
<property name="inputMask">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="name">
<property name="toolTip">
<string>Just a name how would you call this account, doesn't affect anything</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Resource</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="resource">
<property name="toolTip">
<string>A resource name like &quot;Home&quot; or &quot;Work&quot;</string>
</property>
<property name="text">
<string>QXmpp</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>name</tabstop>
<tabstop>login</tabstop>
<tabstop>server</tabstop>
<tabstop>password</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Account</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Account</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

157
ui/widgets/accounts.cpp Normal file
View file

@ -0,0 +1,157 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "accounts.h"
#include "ui_accounts.h"
#include <QDebug>
Accounts::Accounts(Models::Accounts* p_model, QWidget *parent) :
m_ui(new Ui::Accounts),
model(p_model),
editing(false),
toDisconnect(false)
{
m_ui->setupUi(this);
connect(m_ui->addButton, SIGNAL(clicked(bool)), this, SLOT(onAddButton(bool)));
connect(m_ui->editButton, SIGNAL(clicked(bool)), this, SLOT(onEditButton(bool)));
connect(m_ui->connectButton, SIGNAL(clicked(bool)), this, SLOT(onConnectButton(bool)));
connect(m_ui->deleteButton, SIGNAL(clicked(bool)), this, SLOT(onDeleteButton(bool)));
m_ui->tableView->setModel(model);
connect(m_ui->tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
connect(p_model, SIGNAL(changed()), this, SLOT(updateConnectButton()));
}
Accounts::~Accounts() = default;
void Accounts::onAddButton(bool clicked)
{
Account* acc = new Account();
connect(acc, SIGNAL(accepted()), this, SLOT(onAccountAccepted()));
connect(acc, SIGNAL(rejected()), this, SLOT(onAccountRejected()));
acc->exec();
}
void Accounts::onAccountAccepted()
{
Account* acc = static_cast<Account*>(sender());
QMap<QString, QVariant> map = acc->value();
if (editing) {
const Models::Account* mAcc = model->getAccount(m_ui->tableView->selectionModel()->selectedRows().at(0).row());
emit changeAccount(mAcc->getName(), map);
} else {
emit newAccount(map);
}
acc->deleteLater();
editing = false;
}
void Accounts::onAccountRejected()
{
Account* acc = static_cast<Account*>(sender());
acc->deleteLater();
editing = false;
}
void Accounts::onEditButton(bool clicked)
{
Account* acc = new Account();
const Models::Account* mAcc = model->getAccount(m_ui->tableView->selectionModel()->selectedRows().at(0).row());
acc->setData({
{"login", mAcc->getLogin()},
{"password", mAcc->getPassword()},
{"server", mAcc->getServer()},
{"name", mAcc->getName()},
{"resource", mAcc->getResource()}
});
acc->lockId();
connect(acc, SIGNAL(accepted()), this, SLOT(onAccountAccepted()));
connect(acc, SIGNAL(rejected()), this, SLOT(onAccountRejected()));
editing = true;
acc->exec();
}
void Accounts::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
int selectionSize = m_ui->tableView->selectionModel()->selection().size();
if (selectionSize == 0) {
m_ui->editButton->setEnabled(false);
m_ui->deleteButton->setEnabled(false);
} else if (selectionSize == 1) {
m_ui->editButton->setEnabled(true);
m_ui->deleteButton->setEnabled(true);
} else {
m_ui->editButton->setEnabled(false);
m_ui->deleteButton->setEnabled(true);
}
updateConnectButton();
}
void Accounts::updateConnectButton()
{
QItemSelectionModel* sm = m_ui->tableView->selectionModel();
if (sm->hasSelection()) {
m_ui->connectButton->setEnabled(true);
int selectionSize = sm->selection().size();
bool allConnected = true;
for (int i = 0; i < selectionSize && allConnected; ++i) {
const Models::Account* mAcc = model->getAccount(sm->selectedRows().at(i).row());
allConnected = mAcc->getState() == Shared::connected;
}
if (allConnected) {
toDisconnect = true;
m_ui->connectButton->setText("Disconnect");
} else {
toDisconnect = false;
m_ui->connectButton->setText("Connect");
}
} else {
m_ui->connectButton->setText("Connect");
toDisconnect = false;
m_ui->connectButton->setEnabled(false);
}
}
void Accounts::onConnectButton(bool clicked)
{
QItemSelectionModel* sm = m_ui->tableView->selectionModel();
int selectionSize = sm->selection().size();
for (int i = 0; i < selectionSize; ++i) {
const Models::Account* mAcc = model->getAccount(sm->selectedRows().at(i).row());
if (toDisconnect) {
emit disconnectAccount(mAcc->getName());
} else {
emit connectAccount(mAcc->getName());
}
}
}
void Accounts::onDeleteButton(bool clicked)
{
QItemSelectionModel* sm = m_ui->tableView->selectionModel();
int selectionSize = sm->selection().size();
for (int i = 0; i < selectionSize; ++i) {
const Models::Account* mAcc = model->getAccount(sm->selectedRows().at(i).row());
emit removeAccount(mAcc->getName());
}
}

65
ui/widgets/accounts.h Normal file
View file

@ -0,0 +1,65 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ACCOUNTS_H
#define ACCOUNTS_H
#include <QWidget>
#include <QScopedPointer>
#include <QItemSelection>
#include "account.h"
#include "../models/accounts.h"
namespace Ui
{
class Accounts;
}
class Accounts : public QWidget
{
Q_OBJECT
public:
explicit Accounts(Models::Accounts* p_model, QWidget *parent = nullptr);
~Accounts() override;
signals:
void newAccount(const QMap<QString, QVariant>&);
void changeAccount(const QString&, const QMap<QString, QVariant>&);
void connectAccount(const QString&);
void disconnectAccount(const QString&);
void removeAccount(const QString&);
private slots:
void onAddButton(bool clicked = 0);
void onEditButton(bool clicked = 0);
void onConnectButton(bool clicked = 0);
void onDeleteButton(bool clicked = 0);
void onAccountAccepted();
void onAccountRejected();
void onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void updateConnectButton();
private:
QScopedPointer<Ui::Accounts> m_ui;
Models::Accounts* model;
bool editing;
bool toDisconnect;
};
#endif // ACCOUNTS_H

137
ui/widgets/accounts.ui Normal file
View file

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Accounts</class>
<widget class="QWidget" name="Accounts">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>598</width>
<height>249</height>
</rect>
</property>
<property name="windowTitle">
<string>Accounts</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="4" column="1">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="deleteButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="8">
<widget class="QTableView" name="tableView">
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="gridStyle">
<enum>Qt::SolidLine</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="editButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="changePassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Change password</string>
</property>
</widget>
</item>
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="connectButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,79 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "joinconference.h"
#include "ui_joinconference.h"
#include <QDebug>
JoinConference::JoinConference(const Models::Accounts* accounts, QWidget* parent):
QDialog(parent),
m_ui(new Ui::JoinConference())
{
m_ui->setupUi ( this );
std::deque<QString> names = accounts->getNames();
for (std::deque<QString>::const_iterator i = names.begin(), end = names.end(); i != end; i++) {
m_ui->account->addItem(*i);
}
m_ui->account->setCurrentIndex(0);
}
JoinConference::JoinConference(const QString& acc, const Models::Accounts* accounts, QWidget* parent):
QDialog(parent),
m_ui(new Ui::JoinConference())
{
m_ui->setupUi ( this );
std::deque<QString> names = accounts->getNames();
int index = 0;
bool found = false;
for (std::deque<QString>::const_iterator i = names.begin(), end = names.end(); i != end; i++) {
const QString& name = *i;
m_ui->account->addItem(name);
if (!found) {
if (name == acc) {
found = true;
} else {
index++;
}
}
}
if (!found) {
qDebug() << "Couldn't find a correct account among available accounts creating JoinConference dialog, setting to 0";
}
m_ui->account->setCurrentIndex(index);
}
JoinConference::~JoinConference()
{
}
JoinConference::Data JoinConference::value() const
{
return {
m_ui->jid->text(),
m_ui->nick->text(),
m_ui->account->currentText(),
m_ui->autoJoin->isChecked(),
""
};
}

View file

@ -0,0 +1,57 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JOINCONFERENCE_H
#define JOINCONFERENCE_H
#include <QDialog>
#include <QScopedPointer>
#include "../models/accounts.h"
namespace Ui
{
class JoinConference;
}
/**
* @todo write docs
*/
class JoinConference : public QDialog
{
Q_OBJECT
public:
struct Data {
QString jid;
QString nick;
QString account;
bool autoJoin;
QString password;
};
JoinConference(const Models::Accounts* accounts, QWidget* parent = 0);
JoinConference(const QString& acc, const Models::Accounts* accounts, QWidget* parent = 0);
~JoinConference();
Data value() const;
private:
QScopedPointer<Ui::JoinConference> m_ui;
};
#endif // JOINCONFERENCE_H

View file

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JoinConference</class>
<widget class="QDialog" name="JoinConference">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>189</height>
</rect>
</property>
<property name="windowTitle">
<string>Join new conference</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>JID</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="jid">
<property name="toolTip">
<string>Room JID</string>
</property>
<property name="placeholderText">
<string>identifier@conference.server.org</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Account</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="account"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Join on login</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="autoJoin">
<property name="toolTip">
<string>If checked Squawk will try to join this conference on login</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Nick name</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="nick">
<property name="toolTip">
<string>Your nick name for that conference. If you leave this field empty your account name will be used as a nick name</string>
</property>
<property name="placeholderText">
<string>John</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>JoinConference</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>JoinConference</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

78
ui/widgets/newcontact.cpp Normal file
View file

@ -0,0 +1,78 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "newcontact.h"
#include "ui_newcontact.h"
#include <QDebug>
NewContact::NewContact(const Models::Accounts* accounts, QWidget* parent):
QDialog(parent),
m_ui(new Ui::NewContact())
{
m_ui->setupUi ( this );
std::deque<QString> names = accounts->getNames();
for (std::deque<QString>::const_iterator i = names.begin(), end = names.end(); i != end; i++) {
m_ui->account->addItem(*i);
}
m_ui->account->setCurrentIndex(0);
}
NewContact::NewContact(const QString& acc, const Models::Accounts* accounts, QWidget* parent):
QDialog(parent),
m_ui(new Ui::NewContact())
{
m_ui->setupUi ( this );
std::deque<QString> names = accounts->getNames();
int index = 0;
bool found = false;
for (std::deque<QString>::const_iterator i = names.begin(), end = names.end(); i != end; i++) {
const QString& name = *i;
m_ui->account->addItem(name);
if (!found) {
if (name == acc) {
found = true;
} else {
index++;
}
}
}
if (!found) {
qDebug() << "Couldn't find a correct account among available accounts creating NewContact dialog, setting to 0";
}
m_ui->account->setCurrentIndex(index);
}
NewContact::~NewContact()
{
}
NewContact::Data NewContact::value() const
{
return {
m_ui->jid->text(),
m_ui->name->text(),
m_ui->account->currentText(),
{}
};
}

54
ui/widgets/newcontact.h Normal file
View file

@ -0,0 +1,54 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NEWCONTACT_H
#define NEWCONTACT_H
#include <QDialog>
#include <QScopedPointer>
#include <QSet>
#include "../models/accounts.h"
namespace Ui
{
class NewContact;
}
class NewContact : public QDialog
{
Q_OBJECT
public:
struct Data {
QString jid;
QString name;
QString account;
QSet<QString> groups;
};
NewContact(const Models::Accounts* accounts, QWidget* parent = 0);
NewContact(const QString& acc, const Models::Accounts* accounts, QWidget* parent = 0);
~NewContact();
Data value() const;
private:
QScopedPointer<Ui::NewContact> m_ui;
};
#endif // NEWCONTACT_H

129
ui/widgets/newcontact.ui Normal file
View file

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewContact</class>
<widget class="QDialog" name="NewContact">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>208</height>
</rect>
</property>
<property name="windowTitle">
<string>Add new contact</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Account</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="account">
<property name="toolTip">
<string>An account that is going to have new contact</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>JID</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="jid">
<property name="toolTip">
<string>Jabber id of your new contact</string>
</property>
<property name="placeholderText">
<string>name@server.dmn</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="name">
<property name="toolTip">
<string>The way this new contact will be labeled in your roster (optional)</string>
</property>
<property name="placeholderText">
<string>John Smith</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>NewContact</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NewContact</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>