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

View File

@ -1002,19 +1002,7 @@ void Core::Account::bookmarksReceived(const QXmppBookmarkSet& bookmarks)
QString jid = c.jid(); QString jid = c.jid();
std::map<QString, Conference*>::const_iterator cItr = conferences.find(jid); std::map<QString, Conference*>::const_iterator cItr = conferences.find(jid);
if (cItr == conferences.end()) { if (cItr == conferences.end()) {
QXmppMucRoom* room = mm->addRoom(jid); addNewRoom(jid, c.nickName(), c.name(), c.autoJoin());
QString nick = c.nickName();
Conference* conf = new Conference(jid, getName(), c.autoJoin(), c.name(), nick == "" ? getName() : nick, room);
conferences.insert(std::make_pair(jid, conf));
handleNewConference(conf);
emit addRoom(jid, {
{"autoJoin", conf->getAutoJoin()},
{"joined", conf->getJoined()},
{"nick", conf->getNick()},
{"name", conf->getName()}
});
} else { } else {
qDebug() << "Received a bookmark to a MUC " << jid << " which is already booked by another bookmark, skipping"; qDebug() << "Received a bookmark to a MUC " << jid << " which is already booked by another bookmark, skipping";
} }
@ -1133,6 +1121,33 @@ void Core::Account::removeRoomRequest(const QString& jid)
storeConferences(); storeConferences();
} }
void Core::Account::addRoomRequest(const QString& jid, const QString& nick, bool autoJoin) void Core::Account::addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin)
{ {
std::map<QString, Conference*>::const_iterator cItr = conferences.find(jid);
if (cItr == conferences.end()) {
addNewRoom(jid, nick, "", autoJoin);
storeConferences();
} else {
qDebug() << "An attempt to add a MUC " << jid << " which is already present in the rester, skipping";
}
}
void Core::Account::addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin)
{
QXmppMucRoom* room = mm->addRoom(jid);
QString lNick = nick;
if (lNick.size() == 0) {
lNick = getName();
}
Conference* conf = new Conference(jid, getName(), autoJoin, roomName, lNick, room);
conferences.insert(std::make_pair(jid, conf));
handleNewConference(conf);
emit addRoom(jid, {
{"autoJoin", conf->getAutoJoin()},
{"joined", conf->getJoined()},
{"nick", conf->getNick()},
{"name", conf->getName()}
});
} }

View File

@ -74,7 +74,7 @@ public:
void setRoomJoined(const QString& jid, bool joined); void setRoomJoined(const QString& jid, bool joined);
void setRoomAutoJoin(const QString& jid, bool joined); void setRoomAutoJoin(const QString& jid, bool joined);
void removeRoomRequest(const QString& jid); void removeRoomRequest(const QString& jid);
void addRoomRequest(const QString& jid, const QString& nick, bool autoJoin); void addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin);
signals: signals:
void connectionStateChanged(int); void connectionStateChanged(int);
@ -164,6 +164,7 @@ private:
void handleNewConference(Conference* contact); void handleNewConference(Conference* contact);
bool handleChatMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false); bool handleChatMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false);
bool handleGroupMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false); bool handleGroupMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false);
void addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin);
void addToGroup(const QString& jid, const QString& group); void addToGroup(const QString& jid, const QString& group);
void removeFromGroup(const QString& jid, const QString& group); void removeFromGroup(const QString& jid, const QString& group);
void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const; void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const;

View File

@ -474,3 +474,14 @@ void Core::Squawk::removeRoomRequest(const QString& account, const QString& jid)
} }
itr->second->removeRoomRequest(jid); itr->second->removeRoomRequest(jid);
} }
void Core::Squawk::addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin)
{
AccountsMap::const_iterator itr = amap.find(account);
if (itr == amap.end()) {
qDebug() << "An attempt to add the room" << jid << "to non existing account" << account << ", skipping";
return;
}
itr->second->addRoomRequest(jid, nick, password, autoJoin);
}

View File

@ -79,6 +79,7 @@ public slots:
void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups); void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups);
void setRoomJoined(const QString& account, const QString& jid, bool joined); void setRoomJoined(const QString& account, const QString& jid, bool joined);
void setRoomAutoJoin(const QString& account, const QString& jid, bool joined); void setRoomAutoJoin(const QString& account, const QString& jid, bool joined);
void addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin);
void removeRoomRequest(const QString& account, const QString& jid); void removeRoomRequest(const QString& account, const QString& jid);
private: private:

View File

@ -85,6 +85,8 @@ int main(int argc, char *argv[])
QObject::connect(&w, SIGNAL(removeRoomRequest(const QString&, const QString&)), QObject::connect(&w, SIGNAL(removeRoomRequest(const QString&, const QString&)),
squawk, SLOT(removeRoomRequest(const QString&, const QString&))); squawk, SLOT(removeRoomRequest(const QString&, const QString&)));
QObject::connect(&w, SIGNAL(addRoomRequest(const QString&, const QString&, const QString&, const QString&, bool)),
squawk, SLOT(addRoomRequest(const QString&, const QString&, const QString&, const QString&, bool)));
QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&))); QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&)));
QObject::connect(squawk, SIGNAL(addContact(const QString&, const QString&, const QString&, const QMap<QString, QVariant>&)), QObject::connect(squawk, SIGNAL(addContact(const QString&, const QString&, const QString&, const QMap<QString, QVariant>&)),

View File

@ -12,8 +12,6 @@ find_package(Qt5DBus CONFIG REQUIRED)
set(squawkUI_SRC set(squawkUI_SRC
squawk.cpp squawk.cpp
accounts.cpp
account.cpp
models/accounts.cpp models/accounts.cpp
models/roster.cpp models/roster.cpp
models/item.cpp models/item.cpp
@ -28,7 +26,10 @@ set(squawkUI_SRC
widgets/chat.cpp widgets/chat.cpp
widgets/room.cpp widgets/room.cpp
widgets/messageline.cpp widgets/messageline.cpp
newcontact.cpp widgets/newcontact.cpp
widgets/accounts.cpp
widgets/account.cpp
widgets/joinconference.cpp
) )
# Tell CMake to create the helloworld executable # Tell CMake to create the helloworld executable

View File

@ -90,6 +90,7 @@ void Models::Accounts::addAccount(Account* account)
void Models::Accounts::onAccountChanged(Item* item, int row, int col) void Models::Accounts::onAccountChanged(Item* item, int row, int col)
{ {
if (row < accs.size()) {
Account* acc = getAccount(row); Account* acc = getAccount(row);
if (item != acc) { if (item != acc) {
return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that
@ -100,6 +101,7 @@ void Models::Accounts::onAccountChanged(Item* item, int row, int col)
} }
emit changed(); emit changed();
} }
}
Models::Account * Models::Accounts::getAccount(int index) Models::Account * Models::Accounts::getAccount(int index)
{ {

View File

@ -153,7 +153,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
if (mc > 0) { if (mc > 0) {
str += QString("New messages: ") + std::to_string(mc).c_str() + "\n"; str += QString("New messages: ") + std::to_string(mc).c_str() + "\n";
} }
str += "Jabber ID: " + contact->getJid(); str += "Jabber ID: " + contact->getJid() + "\n";
Shared::SubscriptionState ss = contact->getState(); Shared::SubscriptionState ss = contact->getState();
if (ss == Shared::both) { if (ss == Shared::both) {
Shared::Availability av = contact->getAvailability(); Shared::Availability av = contact->getAvailability();

View File

@ -42,6 +42,7 @@ Squawk::Squawk(QWidget *parent) :
connect(m_ui->actionAccounts, SIGNAL(triggered()), this, SLOT(onAccounts())); connect(m_ui->actionAccounts, SIGNAL(triggered()), this, SLOT(onAccounts()));
connect(m_ui->actionAddContact, SIGNAL(triggered()), this, SLOT(onNewContact())); connect(m_ui->actionAddContact, SIGNAL(triggered()), this, SLOT(onNewContact()));
connect(m_ui->actionAddConference, SIGNAL(triggered()), this, SLOT(onNewConference()));
connect(m_ui->comboBox, SIGNAL(activated(int)), this, SLOT(onComboboxActivated(int))); connect(m_ui->comboBox, SIGNAL(activated(int)), this, SLOT(onComboboxActivated(int)));
connect(m_ui->roster, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onRosterItemDoubleClicked(const QModelIndex&))); connect(m_ui->roster, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onRosterItemDoubleClicked(const QModelIndex&)));
connect(m_ui->roster, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onRosterContextMenu(const QPoint&))); connect(m_ui->roster, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onRosterContextMenu(const QPoint&)));
@ -78,8 +79,10 @@ void Squawk::onAccountsSizeChanged(unsigned int size)
{ {
if (size > 0) { if (size > 0) {
m_ui->actionAddContact->setEnabled(true); m_ui->actionAddContact->setEnabled(true);
m_ui->actionAddConference->setEnabled(true);
} else { } else {
m_ui->actionAddContact->setEnabled(false); m_ui->actionAddContact->setEnabled(false);
m_ui->actionAddConference->setEnabled(false);
} }
} }
@ -93,6 +96,16 @@ void Squawk::onNewContact()
nc->exec(); nc->exec();
} }
void Squawk::onNewConference()
{
JoinConference* jc = new JoinConference(rosterModel.accountsModel, this);
connect(jc, SIGNAL(accepted()), this, SLOT(onJoinConferenceAccepted()));
connect(jc, SIGNAL(rejected()), jc, SLOT(deleteLater()));
jc->exec();
}
void Squawk::onNewContactAccepted() void Squawk::onNewContactAccepted()
{ {
NewContact* nc = static_cast<NewContact*>(sender()); NewContact* nc = static_cast<NewContact*>(sender());
@ -103,6 +116,16 @@ void Squawk::onNewContactAccepted()
nc->deleteLater(); nc->deleteLater();
} }
void Squawk::onJoinConferenceAccepted()
{
JoinConference* jc = static_cast<JoinConference*>(sender());
JoinConference::Data value = jc->value();
emit addRoomRequest(value.account, value.jid, value.nick, value.password, value.autoJoin);
jc->deleteLater();
}
void Squawk::closeEvent(QCloseEvent* event) void Squawk::closeEvent(QCloseEvent* event)
{ {
if (accounts != 0) { if (accounts != 0) {

View File

@ -27,11 +27,12 @@
#include <map> #include <map>
#include <list> #include <list>
#include "accounts.h" #include "widgets/accounts.h"
#include "widgets/chat.h" #include "widgets/chat.h"
#include "widgets/room.h" #include "widgets/room.h"
#include "widgets/newcontact.h"
#include "widgets/joinconference.h"
#include "models/roster.h" #include "models/roster.h"
#include "newcontact.h"
#include "../global.h" #include "../global.h"
@ -62,6 +63,7 @@ signals:
void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups); void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups);
void setRoomJoined(const QString& account, const QString& jid, bool joined); void setRoomJoined(const QString& account, const QString& jid, bool joined);
void setRoomAutoJoin(const QString& account, const QString& jid, bool joined); void setRoomAutoJoin(const QString& account, const QString& jid, bool joined);
void addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin);
void removeRoomRequest(const QString& account, const QString& jid); void removeRoomRequest(const QString& account, const QString& jid);
public slots: public slots:
@ -103,7 +105,9 @@ protected:
private slots: private slots:
void onAccounts(); void onAccounts();
void onNewContact(); void onNewContact();
void onNewConference();
void onNewContactAccepted(); void onNewContactAccepted();
void onJoinConferenceAccepted();
void onAccountsSizeChanged(unsigned int size); void onAccountsSizeChanged(unsigned int size);
void onAccountsClosed(QObject* parent = 0); void onAccountsClosed(QObject* parent = 0);
void onConversationClosed(QObject* parent = 0); void onConversationClosed(QObject* parent = 0);

View File

@ -78,9 +78,10 @@
</widget> </widget>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
<property name="title"> <property name="title">
<string>File</string> <string>Squawk</string>
</property> </property>
<addaction name="actionAddContact"/> <addaction name="actionAddContact"/>
<addaction name="actionAddConference"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
@ -109,12 +110,24 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="list-add-user"/> <iconset theme="list-add-user">
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Add contact</string> <string>Add contact</string>
</property> </property>
</action> </action>
<action name="actionAddConference">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="resource-group-new"/>
</property>
<property name="text">
<string>Add conference</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -24,7 +24,7 @@
#include <QItemSelection> #include <QItemSelection>
#include "account.h" #include "account.h"
#include "models/accounts.h" #include "../models/accounts.h"
namespace Ui namespace 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>

View File

@ -23,7 +23,7 @@
#include <QScopedPointer> #include <QScopedPointer>
#include <QSet> #include <QSet>
#include "models/accounts.h" #include "../models/accounts.h"
namespace Ui namespace Ui
{ {

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>NewContact</string> <string>Add new contact</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
<item> <item>