started the work to get the list of participants in the room, license fix, little gui models refactor

This commit is contained in:
Blue 2019-09-01 22:46:12 +03:00
parent f5fa45d853
commit 70f9739cf5
25 changed files with 508 additions and 117 deletions

View file

@ -0,0 +1,126 @@
/*
* 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 "abstractparticipant.h"
using namespace Models;
Models::AbstractParticipant::AbstractParticipant(Models::Item::Type p_type, const QMap<QString, QVariant>& data, Models::Item* parentItem):
Item(p_type, data, parentItem),
availability(Shared::offline),
lastActivity(data.value("lastActivity").toDateTime()),
status(data.value("status").toString())
{
QMap<QString, QVariant>::const_iterator itr = data.find("availability");
if (itr != data.end()) {
setAvailability(itr.value().toUInt());
}
}
Models::AbstractParticipant::~AbstractParticipant()
{
}
int Models::AbstractParticipant::columnCount() const
{
return 5;
}
QVariant Models::AbstractParticipant::data(int column) const
{
switch (column) {
case 0:
return Item::data(column);
case 1:
return lastActivity;
case 2:
return availability;
case 3:
return status;
default:
return QVariant();
}
}
Shared::Availability Models::AbstractParticipant::getAvailability() const
{
return availability;
}
QDateTime Models::AbstractParticipant::getLastActivity() const
{
return lastActivity;
}
QString Models::AbstractParticipant::getStatus() const
{
return status;
}
void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail)
{
if (availability != p_avail) {
availability = p_avail;
changed(2);
}
}
void Models::AbstractParticipant::setAvailability(unsigned int avail)
{
if (avail <= Shared::availabilityHighest) {
Shared::Availability state = static_cast<Shared::Availability>(avail);
setAvailability(state);
} else {
qDebug("An attempt to set wrong state to the contact");
}
}
void Models::AbstractParticipant::setLastActivity(const QDateTime& p_time)
{
if (lastActivity != p_time) {
lastActivity = p_time;
changed(1);
}
}
void Models::AbstractParticipant::setStatus(const QString& p_state)
{
if (status != p_state) {
status = p_state;
changed(3);
}
}
QIcon Models::AbstractParticipant::getStatusIcon(bool big) const
{
return Shared::availabilityIcon(availability, big);
}
void Models::AbstractParticipant::update(const QString& key, const QVariant& value)
{
if (key == "name") {
setName(value.toString());
} else if (key == "status") {
setStatus(value.toString());
} else if (key == "availability") {
setAvailability(value.toUInt());
} else if (key == "lastActivity") {
setLastActivity(value.toDateTime());
}
}

View file

@ -0,0 +1,60 @@
/*
* 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 MODELS_ABSTRACTPARTICIPANT_H
#define MODELS_ABSTRACTPARTICIPANT_H
#include "item.h"
#include "../../global.h"
#include <QIcon>
namespace Models {
class AbstractParticipant : public Models::Item
{
Q_OBJECT
public:
explicit AbstractParticipant(Type p_type, const QMap<QString, QVariant> &data, Item *parentItem = 0);
~AbstractParticipant();
virtual int columnCount() const override;
virtual QVariant data(int column) const override;
Shared::Availability getAvailability() const;
void setAvailability(Shared::Availability p_avail);
void setAvailability(unsigned int avail);
QDateTime getLastActivity() const;
void setLastActivity(const QDateTime& p_time);
QString getStatus() const;
void setStatus(const QString& p_state);
virtual QIcon getStatusIcon(bool big = false) const;
virtual void update(const QString& key, const QVariant& value);
protected:
Shared::Availability availability;
QDateTime lastActivity;
QString status;
};
}
#endif // MODELS_ABSTRACTPARTICIPANT_H

View file

@ -1,3 +1,21 @@
/*
* 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 <QDebug>

View file

@ -1,3 +1,21 @@
/*
* 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 MODELS_ACCOUNT_H
#define MODELS_ACCOUNT_H

View file

@ -1,3 +1,21 @@
/*
* 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 "../../global.h"

View file

@ -1,3 +1,21 @@
/*
* 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 MODELS_ACCOUNTS_H
#define MODELS_ACCOUNTS_H

View file

@ -1,3 +1,21 @@
/*
* 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 "contact.h"
#include <QDebug>

View file

@ -1,3 +1,21 @@
/*
* 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 MODELS_CONTACT_H
#define MODELS_CONTACT_H

View file

@ -1,6 +1,6 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2019 Юрий Губич <y.gubich@initi.ru>
* 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

View file

@ -1,6 +1,6 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2019 Юрий Губич <y.gubich@initi.ru>
* 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

View file

@ -1,3 +1,21 @@
/*
* 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 "item.h"
#include "account.h"

View file

@ -1,3 +1,21 @@
/*
* 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 MODELS_ITEM_H
#define MODELS_ITEM_H
@ -18,6 +36,7 @@ class Item : public QObject{
contact,
room,
presence,
participant,
root
};

View file

@ -1,5 +1,5 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
@ -19,105 +19,22 @@
#include "presence.h"
Models::Presence::Presence(const QMap<QString, QVariant>& data, Item* parentItem):
Item(Item::presence, data, parentItem),
availability(Shared::offline),
lastActivity(data.value("lastActivity").toDateTime()),
status(data.value("status").toString()),
AbstractParticipant(Item::presence, data, parentItem),
messages()
{
QMap<QString, QVariant>::const_iterator itr = data.find("availability");
if (itr != data.end()) {
setAvailability(itr.value().toUInt());
}
}
Models::Presence::~Presence()
{
}
int Models::Presence::columnCount() const
{
return 5;
}
QVariant Models::Presence::data(int column) const
{
switch (column) {
case 0:
return Item::data(column);
case 1:
return lastActivity;
case 2:
return availability;
case 3:
return status;
case 4:
return getMessagesCount();
default:
return QVariant();
}
}
Shared::Availability Models::Presence::getAvailability() const
{
return availability;
}
QDateTime Models::Presence::getLastActivity() const
{
return lastActivity;
}
QString Models::Presence::getStatus() const
{
return status;
}
void Models::Presence::setAvailability(Shared::Availability p_avail)
{
if (availability != p_avail) {
availability = p_avail;
changed(2);
}
}
void Models::Presence::setAvailability(unsigned int avail)
{
if (avail <= Shared::availabilityHighest) {
Shared::Availability state = static_cast<Shared::Availability>(avail);
setAvailability(state);
} else {
qDebug("An attempt to set wrong state to the contact");
}
}
void Models::Presence::setLastActivity(const QDateTime& p_time)
{
if (lastActivity != p_time) {
lastActivity = p_time;
changed(1);
}
}
void Models::Presence::setStatus(const QString& p_state)
{
if (status != p_state) {
status = p_state;
changed(3);
}
}
void Models::Presence::update(const QString& key, const QVariant& value)
{
if (key == "name") {
setName(value.toString());
} else if (key == "status") {
setStatus(value.toString());
} else if (key == "availability") {
setAvailability(value.toUInt());
} else if (key == "lastActivity") {
setLastActivity(value.toDateTime());
return AbstractParticipant::data(column);
}
}
@ -143,9 +60,9 @@ void Models::Presence::dropMessages()
QIcon Models::Presence::getStatusIcon(bool big) const
{
if (getMessagesCount() > 0) {
return Shared::icon("mail-message");
return Shared::icon("mail-message", big);
} else {
return Shared::availabilityIcon(availability, big);
return AbstractParticipant::getStatusIcon();
}
}

View file

@ -1,5 +1,5 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
@ -19,14 +19,14 @@
#ifndef MODELS_PRESENCE_H
#define MODELS_PRESENCE_H
#include "item.h"
#include "abstractparticipant.h"
#include "../../global.h"
#include <QDateTime>
#include <QIcon>
namespace Models {
class Presence : public Models::Item
class Presence : public Models::AbstractParticipant
{
Q_OBJECT
public:
@ -34,21 +34,10 @@ public:
explicit Presence(const QMap<QString, QVariant> &data, Item *parentItem = 0);
~Presence();
virtual int columnCount() const override;
virtual QVariant data(int column) const override;
QVariant data(int column) const override;
Shared::Availability getAvailability() const;
void setAvailability(Shared::Availability p_avail);
void setAvailability(unsigned int avail);
QIcon getStatusIcon(bool big = false) const override;
QDateTime getLastActivity() const;
void setLastActivity(const QDateTime& p_time);
QString getStatus() const;
void setStatus(const QString& p_state);
QIcon getStatusIcon(bool big = false) const;
void update(const QString& key, const QVariant& value);
unsigned int getMessagesCount() const;
void dropMessages();
void addMessage(const Shared::Message& data);
@ -56,9 +45,6 @@ public:
void getMessages(Messages& container) const;
private:
Shared::Availability availability;
QDateTime lastActivity;
QString status;
Messages messages;
};

View file

@ -1,6 +1,6 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2019 Юрий Губич <y.gubich@initi.ru>
* 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

View file

@ -1,6 +1,6 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2019 Юрий Губич <y.gubich@initi.ru>
* 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

View file

@ -1,3 +1,21 @@
/*
* 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 "roster.h"
#include <QDebug>
#include <QIcon>

View file

@ -1,3 +1,21 @@
/*
* 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 MODELS_ROSTER_H
#define MODELS_ROSTER_H