squawk/ui/widgets/newcontact.cpp

79 lines
2.1 KiB
C++
Raw Permalink Normal View History

/*
* 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 );
2022-06-03 06:44:48 +00:00
std::deque<QString> names = accounts->getActiveNames();
2022-06-03 06:44:48 +00:00
for (const QString& name : names) {
m_ui->account->addItem(name);
}
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 );
2022-06-03 06:44:48 +00:00
std::deque<QString> names = accounts->getActiveNames();
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(),
{}
};
}