From ddfb3419cc0db6c0fd899fb44b9f1271901adf26 Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 4 Apr 2020 01:28:15 +0300 Subject: [PATCH] Shared namespace refactoring, enum class refactoring, going offline related crash fix --- CMakeLists.txt | 20 +- core/account.cpp | 68 +-- core/account.h | 6 +- core/archive.h | 2 +- core/contact.cpp | 2 +- core/rosteritem.h | 4 +- core/squawk.cpp | 33 +- core/squawk.h | 12 +- global.cpp | 765 ------------------------------ global.h | 512 -------------------- main.cpp | 5 + shared.h | 29 ++ shared/enums.h | 114 +++++ shared/global.cpp | 170 +++++++ shared/global.h | 64 +++ shared/icons.cpp | 96 ++++ shared/icons.h | 176 +++++++ shared/message.cpp | 399 ++++++++++++++++ shared/message.h | 125 +++++ shared/utils.cpp | 29 ++ shared/utils.h | 72 +++ shared/vcard.cpp | 288 +++++++++++ shared/vcard.h | 152 ++++++ translations/squawk.ru.ts | 266 ++--------- ui/models/abstractparticipant.cpp | 12 +- ui/models/abstractparticipant.h | 6 +- ui/models/account.cpp | 32 +- ui/models/account.h | 5 +- ui/models/accounts.cpp | 2 +- ui/models/contact.cpp | 30 +- ui/models/contact.h | 6 +- ui/models/group.cpp | 2 +- ui/models/item.cpp | 4 +- ui/models/item.h | 2 +- ui/models/presence.cpp | 1 + ui/models/presence.h | 4 +- ui/models/room.cpp | 10 +- ui/models/room.h | 3 +- ui/models/roster.cpp | 24 +- ui/models/roster.h | 3 +- ui/squawk.cpp | 41 +- ui/squawk.h | 6 +- ui/utils/message.cpp | 4 +- ui/utils/message.h | 4 +- ui/utils/messageline.cpp | 1 + ui/utils/messageline.h | 2 +- ui/utils/progress.cpp | 2 + ui/utils/progress.h | 2 - ui/widgets/accounts.cpp | 2 +- ui/widgets/chat.cpp | 2 +- ui/widgets/chat.h | 4 +- ui/widgets/conversation.cpp | 2 + ui/widgets/conversation.h | 2 +- ui/widgets/vcard/emailsmodel.cpp | 3 + ui/widgets/vcard/emailsmodel.h | 2 +- ui/widgets/vcard/phonesmodel.cpp | 3 + ui/widgets/vcard/phonesmodel.h | 2 +- ui/widgets/vcard/vcard.cpp | 2 +- ui/widgets/vcard/vcard.h | 2 +- 59 files changed, 1948 insertions(+), 1695 deletions(-) delete mode 100644 global.cpp delete mode 100644 global.h create mode 100644 shared.h create mode 100644 shared/enums.h create mode 100644 shared/global.cpp create mode 100644 shared/global.h create mode 100644 shared/icons.cpp create mode 100644 shared/icons.h create mode 100644 shared/message.cpp create mode 100644 shared/message.h create mode 100644 shared/utils.cpp create mode 100644 shared/utils.h create mode 100644 shared/vcard.cpp create mode 100644 shared/vcard.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 59582a1..3e9968c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,25 @@ message("Build type: ${CMAKE_BUILD_TYPE}") set(squawk_SRC main.cpp - global.cpp exception.cpp signalcatcher.cpp + shared/global.cpp + shared/utils.cpp + shared/message.cpp + shared/vcard.cpp + shared/icons.cpp +) + +set(squawk_HEAD + exception.h + signalcatcher.h + shared.h + shared/enums.h + shared/message.h + shared/global.h + shared/utils.h + shared/vcard.h + shared/icons.h ) configure_file(resources/images/logo.svg squawk.svg COPYONLY) @@ -46,7 +62,7 @@ add_custom_target(translations ALL DEPENDS ${QM_FILES}) qt5_add_resources(RCC resources/resources.qrc) -add_executable(squawk ${squawk_SRC} ${RCC}) +add_executable(squawk ${squawk_SRC} ${squawk_HEAD} ${RCC}) target_link_libraries(squawk Qt5::Widgets) option(SYSTEM_QXMPP "Use system qxmpp lib" ON) diff --git a/core/account.cpp b/core/account.cpp index 3acdeae..37a8c16 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -30,7 +30,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString& client(), config(), presence(), - state(Shared::disconnected), + state(Shared::ConnectionState::disconnected), groups(), cm(new QXmppCarbonManager()), am(new QXmppMamManager()), @@ -182,9 +182,9 @@ Shared::ConnectionState Core::Account::getState() const void Core::Account::connect() { - if (state == Shared::disconnected) { + if (state == Shared::ConnectionState::disconnected) { reconnectTimes = maxReconnectTimes; - state = Shared::connecting; + state = Shared::ConnectionState::connecting; client.connectToServer(config, presence); emit connectionStateChanged(state); } else { @@ -195,19 +195,19 @@ void Core::Account::connect() void Core::Account::disconnect() { reconnectTimes = 0; - if (state != Shared::disconnected) { + if (state != Shared::ConnectionState::disconnected) { clearConferences(); client.disconnectFromServer(); - state = Shared::disconnected; + state = Shared::ConnectionState::disconnected; emit connectionStateChanged(state); } } void Core::Account::onClientConnected() { - if (state == Shared::connecting) { + if (state == Shared::ConnectionState::connecting) { reconnectTimes = maxReconnectTimes; - state = Shared::connected; + state = Shared::ConnectionState::connected; dm->requestItems(getServer()); dm->requestInfo(getServer()); emit connectionStateChanged(state); @@ -219,16 +219,16 @@ void Core::Account::onClientConnected() void Core::Account::onClientDisconnected() { clearConferences(); - if (state != Shared::disconnected) { + if (state != Shared::ConnectionState::disconnected) { if (reconnectTimes > 0) { qDebug() << "Account" << name << "is reconnecting for" << reconnectTimes << "more times"; --reconnectTimes; - state = Shared::connecting; + state = Shared::ConnectionState::connecting; client.connectToServer(config, presence); emit connectionStateChanged(state); } else { qDebug() << "Account" << name << "has been disconnected"; - state = Shared::disconnected; + state = Shared::ConnectionState::disconnected; emit connectionStateChanged(state); } } else { @@ -238,7 +238,7 @@ void Core::Account::onClientDisconnected() void Core::Account::reconnect() { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { ++reconnectTimes; client.disconnectFromServer(); } else { @@ -281,7 +281,7 @@ void Core::Account::onRosterReceived() void Core::Account::setReconnectTimes(unsigned int times) { maxReconnectTimes = times; - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { reconnectTimes = times; } } @@ -355,7 +355,7 @@ void Core::Account::addedAccount(const QString& jid) if (newContact) { QMap cData({ {"name", re.name()}, - {"state", state} + {"state", QVariant::fromValue(state)} }); Archive::AvatarInfo info; @@ -427,7 +427,7 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence) if (jid == myJid) { if (resource == getResource()) { - emit availabilityChanged(p_presence.availableStatusType()); + emit availabilityChanged(static_cast(p_presence.availableStatusType())); } else { if (!ownVCardRequestInProgress) { switch (p_presence.vCardUpdateType()) { @@ -521,21 +521,25 @@ void Core::Account::setServer(const QString& p_server) Shared::Availability Core::Account::getAvailability() const { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { QXmppPresence::AvailableStatusType pres = presence.availableStatusType(); return static_cast(pres); //they are compatible; } else { - return Shared::offline; + return Shared::Availability::offline; } } void Core::Account::setAvailability(Shared::Availability avail) { - QXmppPresence::AvailableStatusType pres = static_cast(avail); - - presence.setAvailableStatusType(pres); - if (state != Shared::disconnected) { //TODO not sure how to do here - changing state may cause connection or disconnection - client.setClientPresence(presence); + if (avail == Shared::Availability::offline) { + disconnect(); //TODO not sure how to do here - changing state may cause connection or disconnection + } else { + QXmppPresence::AvailableStatusType pres = static_cast(avail); + + presence.setAvailableStatusType(pres); + if (state != Shared::ConnectionState::disconnected) { + client.setClientPresence(presence); + } } } @@ -624,7 +628,7 @@ void Core::Account::sendMessage(Shared::Message data) QString jid = data.getPenPalJid(); QString id = data.getId(); RosterItem* ri = getRosterItem(jid); - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { QXmppMessage msg(getFullJid(), data.getTo(), data.getBody(), data.getThread()); msg.setId(id); msg.setType(static_cast(data.getType())); //it is safe here, my type is compatible @@ -660,7 +664,7 @@ void Core::Account::sendMessage(Shared::Message data) void Core::Account::sendMessage(const Shared::Message& data, const QString& path) { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { QString url = network->getFileRemoteUrl(path); if (url.size() != 0) { sendMessageWithLocalUploadedFile(data, url); @@ -727,9 +731,9 @@ bool Core::Account::handleChatMessage(const QXmppMessage& msg, bool outgoing, bo cnt = new Contact(jid, name); contacts.insert(std::make_pair(jid, cnt)); outOfRosterContacts.insert(jid); - cnt->setSubscriptionState(Shared::unknown); + cnt->setSubscriptionState(Shared::SubscriptionState::unknown); emit addContact(jid, "", QMap({ - {"state", Shared::unknown} + {"state", QVariant::fromValue(Shared::SubscriptionState::unknown)} })); handleNewContact(cnt); } @@ -963,7 +967,7 @@ void Core::Account::onContactGroupAdded(const QString& group) QMap cData({ {"name", contact->getName()}, - {"state", contact->getSubscriptionState()} + {"state", QVariant::fromValue(contact->getSubscriptionState())} }); addToGroup(contact->jid, group); emit addContact(contact->jid, group, cData); @@ -993,7 +997,7 @@ void Core::Account::onContactSubscriptionStateChanged(Shared::SubscriptionState { Contact* contact = static_cast(sender()); QMap cData({ - {"state", cstate}, + {"state", QVariant::fromValue(cstate)}, }); emit changeContact(contact->jid, cData); } @@ -1031,7 +1035,7 @@ Shared::SubscriptionState Core::Account::castSubscriptionState(QXmppRosterIq::It { Shared::SubscriptionState state; if (qs == QXmppRosterIq::Item::NotSet) { - state = Shared::unknown; + state = Shared::SubscriptionState::unknown; } else { state = static_cast(qs); } @@ -1145,7 +1149,7 @@ void Core::Account::onClientError(QXmppClient::Error err) void Core::Account::subscribeToContact(const QString& jid, const QString& reason) { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { rm->subscribe(jid, reason); } else { qDebug() << "An attempt to subscribe account " << name << " to contact " << jid << " but the account is not in the connected state, skipping"; @@ -1154,7 +1158,7 @@ void Core::Account::subscribeToContact(const QString& jid, const QString& reason void Core::Account::unsubscribeFromContact(const QString& jid, const QString& reason) { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { rm->unsubscribe(jid, reason); } else { qDebug() << "An attempt to unsubscribe account " << name << " from contact " << jid << " but the account is not in the connected state, skipping"; @@ -1163,7 +1167,7 @@ void Core::Account::unsubscribeFromContact(const QString& jid, const QString& re void Core::Account::removeContactRequest(const QString& jid) { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { std::set::const_iterator itr = outOfRosterContacts.find(jid); if (itr != outOfRosterContacts.end()) { outOfRosterContacts.erase(itr); @@ -1179,7 +1183,7 @@ void Core::Account::removeContactRequest(const QString& jid) void Core::Account::addContactRequest(const QString& jid, const QString& name, const QSet& groups) { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { std::map::const_iterator itr = queuedContacts.find(jid); if (itr != queuedContacts.end()) { qDebug() << "An attempt to add contact " << jid << " to account " << name << " but the account is already queued for adding, skipping"; diff --git a/core/account.h b/core/account.h index 02ae2ab..1688fc9 100644 --- a/core/account.h +++ b/core/account.h @@ -43,7 +43,7 @@ #include #include -#include "global.h" +#include "shared.h" #include "contact.h" #include "conference.h" #include "networkaccess.h" @@ -101,8 +101,8 @@ public slots: signals: void changed(const QMap& data); - void connectionStateChanged(int); - void availabilityChanged(int); + void connectionStateChanged(Shared::ConnectionState); + void availabilityChanged(Shared::Availability); void addGroup(const QString& name); void removeGroup(const QString& name); void addRoom(const QString& jid, const QMap& data); diff --git a/core/archive.h b/core/archive.h index 4d61f95..6facf68 100644 --- a/core/archive.h +++ b/core/archive.h @@ -24,7 +24,7 @@ #include #include -#include "global.h" +#include "shared/message.h" #include "exception.h" #include #include diff --git a/core/contact.cpp b/core/contact.cpp index 711c505..0471a5c 100644 --- a/core/contact.cpp +++ b/core/contact.cpp @@ -22,7 +22,7 @@ Core::Contact::Contact(const QString& pJid, const QString& account, QObject* parent): RosterItem(pJid, account, parent), groups(), - subscriptionState(Shared::unknown) + subscriptionState(Shared::SubscriptionState::unknown) { } diff --git a/core/rosteritem.h b/core/rosteritem.h index b6c60cd..387ebfc 100644 --- a/core/rosteritem.h +++ b/core/rosteritem.h @@ -31,7 +31,9 @@ #include #include -#include "../global.h" +#include "shared/enums.h" +#include "shared/message.h" +#include "shared/vcard.h" #include "archive.h" namespace Core { diff --git a/core/squawk.cpp b/core/squawk.cpp index 75cceec..387c685 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -146,8 +146,8 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const {"name", name}, {"password", password}, {"resource", resource}, - {"state", Shared::disconnected}, - {"offline", Shared::offline}, + {"state", QVariant::fromValue(Shared::ConnectionState::disconnected)}, + {"offline", QVariant::fromValue(Shared::Availability::offline)}, {"error", ""}, {"avatarPath", acc->getAvatarPath()} }; @@ -155,14 +155,11 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const emit newAccount(map); } -void Core::Squawk::changeState(int p_state) +void Core::Squawk::changeState(Shared::Availability p_state) { - Shared::Availability avail; - if (p_state < Shared::availabilityLowest && p_state > Shared::availabilityHighest) { - qDebug("An attempt to set invalid availability to Squawk core, skipping"); + if (state != p_state) { + state = p_state; } - avail = static_cast(p_state); - state = avail; for (std::deque::iterator itr = accounts.begin(), end = accounts.end(); itr != end; ++itr) { (*itr)->setAvailability(state); @@ -190,20 +187,20 @@ void Core::Squawk::disconnectAccount(const QString& account) itr->second->disconnect(); } -void Core::Squawk::onAccountConnectionStateChanged(int state) +void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_state) { Account* acc = static_cast(sender()); - emit changeAccount(acc->getName(), {{"state", state}}); + emit changeAccount(acc->getName(), {{"state", QVariant::fromValue(p_state)}}); - if (state == Shared::disconnected) { + if (p_state == Shared::ConnectionState::disconnected) { bool equals = true; for (Accounts::const_iterator itr = accounts.begin(), end = accounts.end(); itr != end; itr++) { - if ((*itr)->getState() != Shared::disconnected) { + if ((*itr)->getState() != Shared::ConnectionState::disconnected) { equals = false; } } - if (equals) { - state = Shared::offline; + if (equals && state != Shared::Availability::offline) { + state = Shared::Availability::offline; emit stateChanged(state); } } @@ -257,10 +254,10 @@ void Core::Squawk::onAccountRemovePresence(const QString& jid, const QString& na emit removePresence(acc->getName(), jid, name); } -void Core::Squawk::onAccountAvailabilityChanged(int state) +void Core::Squawk::onAccountAvailabilityChanged(Shared::Availability state) { Account* acc = static_cast(sender()); - emit changeAccount(acc->getName(), {{"availability", state}}); + emit changeAccount(acc->getName(), {{"availability", QVariant::fromValue(state)}}); } void Core::Squawk::onAccountChanged(const QMap& data) @@ -324,7 +321,7 @@ void Core::Squawk::modifyAccountRequest(const QString& name, const QMapsecond; Shared::ConnectionState st = acc->getState(); - if (st != Shared::disconnected) { + if (st != Shared::ConnectionState::disconnected) { acc->reconnect(); } @@ -367,7 +364,7 @@ void Core::Squawk::removeAccountRequest(const QString& name) } Account* acc = itr->second; - if (acc->getState() != Shared::disconnected) { + if (acc->getState() != Shared::ConnectionState::disconnected) { acc->disconnect(); } diff --git a/core/squawk.h b/core/squawk.h index 76f5170..29e5b8c 100644 --- a/core/squawk.h +++ b/core/squawk.h @@ -28,7 +28,9 @@ #include #include "account.h" -#include "../global.h" +#include "shared/enums.h" +#include "shared/message.h" +#include "shared/global.h" #include "networkaccess.h" namespace Core @@ -54,7 +56,7 @@ signals: void changeContact(const QString& account, const QString& jid, const QMap& data); void addPresence(const QString& account, const QString& jid, const QString& name, const QMap& data); void removePresence(const QString& account, const QString& jid, const QString& name); - void stateChanged(int state); + void stateChanged(Shared::Availability state); void accountMessage(const QString& account, const Shared::Message& data); void responseArchive(const QString& account, const QString& jid, const std::list& list); void addRoom(const QString& account, const QString jid, const QMap& data); @@ -79,7 +81,7 @@ public slots: void removeAccountRequest(const QString& name); void connectAccount(const QString& account); void disconnectAccount(const QString& account); - void changeState(int state); + void changeState(Shared::Availability state); void sendMessage(const QString& account, const Shared::Message& data); void sendMessage(const QString& account, const Shared::Message& data, const QString& path); void requestArchive(const QString& account, const QString& jid, int count, const QString& before); @@ -112,8 +114,8 @@ private: void addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource); private slots: - void onAccountConnectionStateChanged(int state); - void onAccountAvailabilityChanged(int state); + void onAccountConnectionStateChanged(Shared::ConnectionState state); + void onAccountAvailabilityChanged(Shared::Availability state); void onAccountChanged(const QMap& data); void onAccountAddGroup(const QString& name); void onAccountError(const QString& text); diff --git a/global.cpp b/global.cpp deleted file mode 100644 index 9ece2ba..0000000 --- a/global.cpp +++ /dev/null @@ -1,765 +0,0 @@ -/* - * Squawk messenger. - * Copyright (C) 2019 Yury Gubich - * - * 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 . - */ - -#include "global.h" -#include -#include -#include -#include -#include - -Shared::Message::Message(Shared::Message::Type p_type): - jFrom(), - rFrom(), - jTo(), - rTo(), - id(), - body(), - time(), - thread(), - type(p_type), - outgoing(false), - forwarded(false), - state(State::delivered), - edited(false) -{ -} - -Shared::Message::Message(): - jFrom(), - rFrom(), - jTo(), - rTo(), - id(), - body(), - time(), - thread(), - type(Message::normal), - outgoing(false), - forwarded(false), - state(State::delivered), - edited(false), - errorText(), - originalMessage(), - lastModified() -{ -} - -QString Shared::Message::getBody() const -{ - return body; -} - -QString Shared::Message::getFrom() const -{ - QString from = jFrom; - if (rFrom.size() > 0) { - from += "/" + rFrom; - } - return from; -} - -QString Shared::Message::getTo() const -{ - QString to = jTo; - if (rTo.size() > 0) { - to += "/" + rTo; - } - return to; -} - -QString Shared::Message::getId() const -{ - return id; -} - -QDateTime Shared::Message::getTime() const -{ - return time; -} - -void Shared::Message::setBody(const QString& p_body) -{ - body = p_body; -} - -void Shared::Message::setFrom(const QString& from) -{ - QStringList list = from.split("/"); - if (list.size() == 1) { - jFrom = from; - } else { - jFrom = list.front(); - rFrom = list.back(); - } -} - -void Shared::Message::setTo(const QString& to) -{ - QStringList list = to.split("/"); - if (list.size() == 1) { - jTo = to; - } else { - jTo = list.front(); - rTo = list.back(); - } -} - -void Shared::Message::setId(const QString& p_id) -{ - id = p_id; -} - -void Shared::Message::setTime(const QDateTime& p_time) -{ - time = p_time; -} - -QString Shared::Message::getFromJid() const -{ - return jFrom; -} - -QString Shared::Message::getFromResource() const -{ - return rFrom; -} - -QString Shared::Message::getToJid() const -{ - return jTo; -} - -QString Shared::Message::getToResource() const -{ - return rTo; -} - -QString Shared::Message::getErrorText() const -{ - return errorText; -} - -QString Shared::Message::getPenPalJid() const -{ - if (outgoing) { - return jTo; - } else { - return jFrom; - } -} - -QString Shared::Message::getPenPalResource() const -{ - if (outgoing) { - return rTo; - } else { - return rFrom; - } -} - -Shared::Message::State Shared::Message::getState() const -{ - return state; -} - -bool Shared::Message::getEdited() const -{ - return edited; -} - -void Shared::Message::setFromJid(const QString& from) -{ - jFrom = from; -} - -void Shared::Message::setFromResource(const QString& from) -{ - rFrom = from; -} - -void Shared::Message::setToJid(const QString& to) -{ - jTo = to; -} - -void Shared::Message::setToResource(const QString& to) -{ - rTo = to; -} - -void Shared::Message::setErrorText(const QString& err) -{ - if (state == State::error) { - errorText = err; - } -} - -bool Shared::Message::getOutgoing() const -{ - return outgoing; -} - -void Shared::Message::setOutgoing(bool og) -{ - outgoing = og; -} - -bool Shared::Message::getForwarded() const -{ - return forwarded; -} - -void Shared::Message::generateRandomId() -{ - id = generateUUID(); -} - -QString Shared::Message::getThread() const -{ - return thread; -} - -void Shared::Message::setForwarded(bool fwd) -{ - forwarded = fwd; -} - -void Shared::Message::setThread(const QString& p_body) -{ - thread = p_body; -} - -QDateTime Shared::Message::getLastModified() const -{ - return lastModified; -} - -QString Shared::Message::getOriginalBody() const -{ - return originalMessage; -} - -Shared::Message::Type Shared::Message::getType() const -{ - return type; -} - -void Shared::Message::setType(Shared::Message::Type t) -{ - type = t; -} - -void Shared::Message::setState(Shared::Message::State p_state) -{ - state = p_state; - - if (state != State::error) { - errorText = ""; - } -} - -bool Shared::Message::serverStored() const -{ - return state == State::delivered || state == State::sent; -} - -void Shared::Message::setEdited(bool p_edited) -{ - edited = p_edited; -} - -void Shared::Message::serialize(QDataStream& data) const -{ - data << jFrom; - data << rFrom; - data << jTo; - data << rTo; - data << id; - data << body; - data << time; - data << thread; - data << (quint8)type; - data << outgoing; - data << forwarded; - data << oob; - data << (quint8)state; - data << edited; - if (state == State::error) { - data << errorText; - } - if (edited) { - data << originalMessage; - data << lastModified; - } -} - -void Shared::Message::deserialize(QDataStream& data) -{ - data >> jFrom; - data >> rFrom; - data >> jTo; - data >> rTo; - data >> id; - data >> body; - data >> time; - data >> thread; - quint8 t; - data >> t; - type = static_cast(t); - data >> outgoing; - data >> forwarded; - data >> oob; - quint8 s; - data >> s; - state = static_cast(s); - data >> edited; - if (state == State::error) { - data >> errorText; - } - if (edited) { - data >> originalMessage; - data >> lastModified; - } -} - -bool Shared::Message::change(const QMap& data) -{ - QMap::const_iterator itr = data.find("state"); - if (itr != data.end()) { - setState(static_cast(itr.value().toUInt())); - } - - if (state == State::error) { - itr = data.find("errorText"); - if (itr != data.end()) { - setErrorText(itr.value().toString()); - } - } - - bool idChanged = false; - itr = data.find("id"); - if (itr != data.end()) { - QString newId = itr.value().toString(); - if (id != newId) { - setId(newId); - idChanged = true; - } - } - itr = data.find("body"); - if (itr != data.end()) { - QMap::const_iterator dItr = data.find("stamp"); - QDateTime correctionDate; - if (dItr != data.end()) { - correctionDate = dItr.value().toDateTime(); - } else { - correctionDate = QDateTime::currentDateTimeUtc(); //in case there is no information about time of this correction it's applied - } - if (!edited || lastModified < correctionDate) { - originalMessage = body; - lastModified = correctionDate; - setBody(itr.value().toString()); - setEdited(true); - } - } - - return idChanged; -} - -QString Shared::generateUUID() -{ - uuid_t uuid; - uuid_generate(uuid); - - char uuid_str[36]; - uuid_unparse_lower(uuid, uuid_str); - return uuid_str; -} - -void Shared::Message::setCurrentTime() -{ - time = QDateTime::currentDateTimeUtc(); -} - -QString Shared::Message::getOutOfBandUrl() const -{ - return oob; -} - -bool Shared::Message::hasOutOfBandUrl() const -{ - return oob.size() > 0; -} - -void Shared::Message::setOutOfBandUrl(const QString& url) -{ - oob = url; -} - -bool Shared::Message::storable() const -{ - return id.size() > 0 && (body.size() > 0 || oob.size()) > 0; -} - -Shared::VCard::Contact::Contact(Shared::VCard::Contact::Role p_role, bool p_prefered): - role(p_role), - prefered(p_prefered) -{} - -Shared::VCard::Email::Email(const QString& addr, Shared::VCard::Contact::Role p_role, bool p_prefered): - Contact(p_role, p_prefered), - address(addr) -{} - -Shared::VCard::Phone::Phone(const QString& nmbr, Shared::VCard::Phone::Type p_type, Shared::VCard::Contact::Role p_role, bool p_prefered): - Contact(p_role, p_prefered), - number(nmbr), - type(p_type) -{} - -Shared::VCard::Address::Address(const QString& zCode, const QString& cntry, const QString& rgn, const QString& lclty, const QString& strt, const QString& ext, Shared::VCard::Contact::Role p_role, bool p_prefered): - Contact(p_role, p_prefered), - zipCode(zCode), - country(cntry), - region(rgn), - locality(lclty), - street(strt), - external(ext) -{} - -Shared::VCard::VCard(): - fullName(), - firstName(), - middleName(), - lastName(), - nickName(), - description(), - url(), - organizationName(), - organizationUnit(), - organizationRole(), - jobTitle(), - birthday(), - photoType(Avatar::empty), - photoPath(), - receivingTime(QDateTime::currentDateTimeUtc()), - emails(), - phones(), - addresses() -{} - -Shared::VCard::VCard(const QDateTime& creationTime): - fullName(), - firstName(), - middleName(), - lastName(), - nickName(), - description(), - url(), - organizationName(), - organizationUnit(), - organizationRole(), - jobTitle(), - birthday(), - photoType(Avatar::empty), - photoPath(), - receivingTime(creationTime), - emails(), - phones(), - addresses() -{ -} - -QString Shared::VCard::getAvatarPath() const -{ - return photoPath; -} - -Shared::Avatar Shared::VCard::getAvatarType() const -{ - return photoType; -} - -QDate Shared::VCard::getBirthday() const -{ - return birthday; -} - -QString Shared::VCard::getDescription() const -{ - return description; -} - -QString Shared::VCard::getFirstName() const -{ - return firstName; -} - -QString Shared::VCard::getLastName() const -{ - return lastName; -} - -QString Shared::VCard::getMiddleName() const -{ - return middleName; -} - -QString Shared::VCard::getNickName() const -{ - return nickName; -} - -void Shared::VCard::setAvatarPath(const QString& path) -{ - if (path != photoPath) { - photoPath = path; - } -} - -void Shared::VCard::setAvatarType(Shared::Avatar type) -{ - if (photoType != type) { - photoType = type; - } -} - -void Shared::VCard::setBirthday(const QDate& date) -{ - if (date.isValid() && birthday != date) { - birthday = date; - } -} - -void Shared::VCard::setDescription(const QString& descr) -{ - if (description != descr) { - description = descr; - } -} - -void Shared::VCard::setFirstName(const QString& first) -{ - if (firstName != first) { - firstName = first; - } -} - -void Shared::VCard::setLastName(const QString& last) -{ - if (lastName != last) { - lastName = last; - } -} - -void Shared::VCard::setMiddleName(const QString& middle) -{ - if (middleName != middle) { - middleName = middle; - } -} - -void Shared::VCard::setNickName(const QString& nick) -{ - if (nickName != nick) { - nickName = nick; - } -} - -QString Shared::VCard::getFullName() const -{ - return fullName; -} - -QString Shared::VCard::getUrl() const -{ - return url; -} - -void Shared::VCard::setFullName(const QString& name) -{ - if (fullName != name) { - fullName = name; - } -} - -void Shared::VCard::setUrl(const QString& u) -{ - if (url != u) { - url = u; - } -} - -QString Shared::VCard::getOrgName() const -{ - return organizationName; -} - -QString Shared::VCard::getOrgRole() const -{ - return organizationRole; -} - -QString Shared::VCard::getOrgTitle() const -{ - return jobTitle; -} - -QString Shared::VCard::getOrgUnit() const -{ - return organizationUnit; -} - -void Shared::VCard::setOrgName(const QString& name) -{ - if (organizationName != name) { - organizationName = name; - } -} - -void Shared::VCard::setOrgRole(const QString& role) -{ - if (organizationRole != role) { - organizationRole = role; - } -} - -void Shared::VCard::setOrgTitle(const QString& title) -{ - if (jobTitle != title) { - jobTitle = title; - } -} - -void Shared::VCard::setOrgUnit(const QString& unit) -{ - if (organizationUnit != unit) { - organizationUnit = unit; - } -} - -QDateTime Shared::VCard::getReceivingTime() const -{ - return receivingTime; -} - -std::deque & Shared::VCard::getEmails() -{ - return emails; -} - -std::deque & Shared::VCard::getAddresses() -{ - return addresses; -} - -std::deque & Shared::VCard::getPhones() -{ - return phones; -} - -const std::deque & Shared::VCard::getEmails() const -{ - return emails; -} - -const std::deque & Shared::VCard::getAddresses() const -{ - return addresses; -} - -const std::deque & Shared::VCard::getPhones() const -{ - return phones; -} - -const std::dequeShared::VCard::Contact::roleNames = {"Not specified", "Personal", "Business"}; -const std::dequeShared::VCard::Phone::typeNames = {"Fax", "Pager", "Voice", "Cell", "Video", "Modem", "Other"}; - -QIcon Shared::availabilityIcon(Shared::Availability av, bool big) -{ - const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? - big ? - Shared::fallbackAvailabilityThemeIconsDarkBig: - Shared::fallbackAvailabilityThemeIconsDarkSmall: - big ? - Shared::fallbackAvailabilityThemeIconsLightBig: - Shared::fallbackAvailabilityThemeIconsLightSmall; - - return QIcon::fromTheme(availabilityThemeIcons[av], QIcon(fallback[av])); -} - -QIcon Shared::subscriptionStateIcon(Shared::SubscriptionState ss, bool big) -{ - const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? - big ? - Shared::fallbackSubscriptionStateThemeIconsDarkBig: - Shared::fallbackSubscriptionStateThemeIconsDarkSmall: - big ? - Shared::fallbackSubscriptionStateThemeIconsLightBig: - Shared::fallbackSubscriptionStateThemeIconsLightSmall; - - return QIcon::fromTheme(subscriptionStateThemeIcons[ss], QIcon(fallback[ss])); -} - -QIcon Shared::connectionStateIcon(Shared::ConnectionState cs, bool big) -{ - const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? - big ? - Shared::fallbackConnectionStateThemeIconsDarkBig: - Shared::fallbackConnectionStateThemeIconsDarkSmall: - big ? - Shared::fallbackConnectionStateThemeIconsLightBig: - Shared::fallbackConnectionStateThemeIconsLightSmall; - - return QIcon::fromTheme(connectionStateThemeIcons[cs], QIcon(fallback[cs])); -} - -static const QString ds = ":images/fallback/dark/small/"; -static const QString db = ":images/fallback/dark/big/"; -static const QString ls = ":images/fallback/light/small/"; -static const QString lb = ":images/fallback/light/big/"; - -QIcon Shared::icon(const QString& name, bool big) -{ - std::map>::const_iterator itr = icons.find(name); - if (itr != icons.end()) { - const QString& prefix = QApplication::palette().window().color().lightnessF() > 0.5 ? - big ? db : ds: - big ? lb : ls; - return QIcon::fromTheme(itr->second.first, QIcon(prefix + itr->second.second + ".svg")); - } else { - qDebug() << "Icon" << name << "not found"; - return QIcon::fromTheme(name); - } -} - - -QString Shared::iconPath(const QString& name, bool big) -{ - QString result = ""; - std::map>::const_iterator itr = icons.find(name); - if (itr != icons.end()) { - const QString& prefix = QApplication::palette().window().color().lightnessF() > 0.5 ? - big ? db : ds: - big ? lb : ls; - result = prefix + itr->second.second + ".svg"; - } - - return result; -} diff --git a/global.h b/global.h deleted file mode 100644 index aa5911a..0000000 --- a/global.h +++ /dev/null @@ -1,512 +0,0 @@ -/* - * Squawk messenger. - * Copyright (C) 2019 Yury Gubich - * - * 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 . - */ - -#ifndef GLOBAL_H -#define GLOBAL_H - -#include -#include -#include -#include -#include -#include -#include - -namespace Shared { - -enum ConnectionState { - disconnected, - connecting, - connected, - error -}; - -enum Availability { - online, - away, - extendedAway, - busy, - chatty, - invisible, - offline -}; - -enum SubscriptionState { - none, - from, - to, - both, - unknown -}; - -enum class Affiliation { - unspecified, - outcast, - nobody, - member, - admin, - owner -}; - -enum class Role { - unspecified, - nobody, - visitor, - participant, - moderator -}; - -enum class Avatar { - empty, - autocreated, - valid -}; - -static const Availability availabilityHighest = offline; -static const Availability availabilityLowest = online; - -static const SubscriptionState subscriptionStateHighest = unknown; -static const SubscriptionState subscriptionStateLowest = none; - -static const Affiliation affiliationHighest = Affiliation::owner; -static const Affiliation affiliationLowest = Affiliation::unspecified; - -static const Role roleHighest = Role::moderator; -static const Role roleLowest = Role::unspecified; - -static const std::deque connectionStateNames = {"Disconnected", "Connecting", "Connected", "Error"}; -static const std::deque connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; - -static const std::deque availabilityThemeIcons = { - "user-online", - "user-away", - "user-away-extended", - "user-busy", - "chatty", - "user-invisible", - "user-offline" -}; -static const std::deque availabilityNames = {"Online", "Away", "Absent", "Busy", "Chatty", "Invisible", "Offline"}; - -static const std::deque subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"}; -static const std::deque subscriptionStateNames = {"None", "From", "To", "Both", "Unknown"}; - -static const std::deque affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"}; -static const std::deque roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"}; - -static const std::deque messageStateNames = {"Pending", "Sent", "Delivered", "Error"}; -static const std::deque messageStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; - -QString generateUUID(); - -static const std::vector colorPalette = { - QColor(244, 27, 63), - QColor(21, 104, 156), - QColor(38, 156, 98), - QColor(247, 103, 101), - QColor(121, 37, 117), - QColor(242, 202, 33), - QColor(168, 22, 63), - QColor(35, 100, 52), - QColor(52, 161, 152), - QColor(239, 53, 111), - QColor(237, 234, 36), - QColor(153, 148, 194), - QColor(211, 102, 151), - QColor(194, 63, 118), - QColor(249, 149, 51), - QColor(244, 206, 109), - QColor(121, 105, 153), - QColor(244, 199, 30), - QColor(28, 112, 28), - QColor(172, 18, 20), - QColor(25, 66, 110), - QColor(25, 149, 104), - QColor(214, 148, 0), - QColor(203, 47, 57), - QColor(4, 54, 84), - QColor(116, 161, 97), - QColor(50, 68, 52), - QColor(237, 179, 20), - QColor(69, 114, 147), - QColor(242, 212, 31), - QColor(248, 19, 20), - QColor(84, 102, 84), - QColor(25, 53, 122), - QColor(91, 91, 109), - QColor(17, 17, 80), - QColor(54, 54, 94) -}; - -class Message { -public: - enum Type { - error, - normal, - chat, - groupChat, - headline - }; - - enum class State { - pending, - sent, - delivered, - error - }; - - Message(Type p_type); - Message(); - - void setFrom(const QString& from); - void setFromResource(const QString& from); - void setFromJid(const QString& from); - void setTo(const QString& to); - void setToResource(const QString& to); - void setToJid(const QString& to); - void setTime(const QDateTime& p_time); - void setId(const QString& p_id); - void setBody(const QString& p_body); - void setThread(const QString& p_body); - void setOutgoing(bool og); - void setForwarded(bool fwd); - void setType(Type t); - void setCurrentTime(); - void setOutOfBandUrl(const QString& url); - void setState(State p_state); - void setEdited(bool p_edited); - void setErrorText(const QString& err); - bool change(const QMap& data); - - QString getFrom() const; - QString getFromJid() const; - QString getFromResource() const; - QString getTo() const; - QString getToJid() const; - QString getToResource() const; - QDateTime getTime() const; - QString getId() const; - QString getBody() const; - QString getThread() const; - bool getOutgoing() const; - bool getForwarded() const; - Type getType() const; - bool hasOutOfBandUrl() const; - bool storable() const; - QString getOutOfBandUrl() const; - State getState() const; - bool getEdited() const; - QString getErrorText() const; - - QString getPenPalJid() const; - QString getPenPalResource() const; - void generateRandomId(); - bool serverStored() const; - QDateTime getLastModified() const; - QString getOriginalBody() const; - - void serialize(QDataStream& data) const; - void deserialize(QDataStream& data); - -private: - QString jFrom; - QString rFrom; - QString jTo; - QString rTo; - QString id; - QString body; - QDateTime time; - QString thread; - Type type; - bool outgoing; - bool forwarded; - QString oob; - State state; - bool edited; - QString errorText; - QString originalMessage; - QDateTime lastModified; -}; - -class VCard { - class Contact { - public: - enum Role { - none, - home, - work - }; - static const std::deque roleNames; - - Contact(Role p_role = none, bool p_prefered = false); - - Role role; - bool prefered; - }; -public: - class Email : public Contact { - public: - Email(const QString& address, Role p_role = none, bool p_prefered = false); - - QString address; - }; - class Phone : public Contact { - public: - enum Type { - fax, - pager, - voice, - cell, - video, - modem, - other - }; - static const std::deque typeNames; - Phone(const QString& number, Type p_type = voice, Role p_role = none, bool p_prefered = false); - - QString number; - Type type; - }; - class Address : public Contact { - public: - Address( - const QString& zCode = "", - const QString& cntry = "", - const QString& rgn = "", - const QString& lclty = "", - const QString& strt = "", - const QString& ext = "", - Role p_role = none, - bool p_prefered = false - ); - - QString zipCode; - QString country; - QString region; - QString locality; - QString street; - QString external; - }; - VCard(); - VCard(const QDateTime& creationTime); - - QString getFullName() const; - void setFullName(const QString& name); - QString getFirstName() const; - void setFirstName(const QString& first); - QString getMiddleName() const; - void setMiddleName(const QString& middle); - QString getLastName() const; - void setLastName(const QString& last); - QString getNickName() const; - void setNickName(const QString& nick); - QString getDescription() const; - void setDescription(const QString& descr); - QString getUrl() const; - void setUrl(const QString& u); - QDate getBirthday() const; - void setBirthday(const QDate& date); - Avatar getAvatarType() const; - void setAvatarType(Avatar type); - QString getAvatarPath() const; - void setAvatarPath(const QString& path); - QString getOrgName() const; - void setOrgName(const QString& name); - QString getOrgUnit() const; - void setOrgUnit(const QString& unit); - QString getOrgRole() const; - void setOrgRole(const QString& role); - QString getOrgTitle() const; - void setOrgTitle(const QString& title); - QDateTime getReceivingTime() const; - std::deque& getEmails(); - const std::deque& getEmails() const; - std::deque& getPhones(); - const std::deque& getPhones() const; - std::deque
& getAddresses(); - const std::deque
& getAddresses() const; - -private: - QString fullName; - QString firstName; - QString middleName; - QString lastName; - QString nickName; - QString description; - QString url; - QString organizationName; - QString organizationUnit; - QString organizationRole; - QString jobTitle; - QDate birthday; - Avatar photoType; - QString photoPath; - QDateTime receivingTime; - std::deque emails; - std::deque phones; - std::deque
addresses; -}; - -static const std::deque fallbackAvailabilityThemeIconsLightBig = { - ":images/fallback/light/big/online.svg", - ":images/fallback/light/big/away.svg", - ":images/fallback/light/big/absent.svg", - ":images/fallback/light/big/busy.svg", - ":images/fallback/light/big/chatty.svg", - ":images/fallback/light/big/invisible.svg", - ":images/fallback/light/big/offline.svg" -}; - -static const std::deque fallbackSubscriptionStateThemeIconsLightBig = { - ":images/fallback/light/big/edit-none.svg", - ":images/fallback/light/big/arrow-down-double.svg", - ":images/fallback/light/big/arrow-up-double.svg", - ":images/fallback/light/big/dialog-ok.svg", - ":images/fallback/light/big/question.svg" -}; - -static const std::deque fallbackConnectionStateThemeIconsLightBig = { - ":images/fallback/light/big/state-offline.svg", - ":images/fallback/light/big/state-sync.svg", - ":images/fallback/light/big/state-ok.svg", - ":images/fallback/light/big/state-error.svg" -}; - -static const std::deque fallbackAvailabilityThemeIconsLightSmall = { - ":images/fallback/light/small/online.svg", - ":images/fallback/light/small/away.svg", - ":images/fallback/light/small/absent.svg", - ":images/fallback/light/small/busy.svg", - ":images/fallback/light/small/chatty.svg", - ":images/fallback/light/small/invisible.svg", - ":images/fallback/light/small/offline.svg" -}; - -static const std::deque fallbackSubscriptionStateThemeIconsLightSmall = { - ":images/fallback/light/small/edit-none.svg", - ":images/fallback/light/small/arrow-down-double.svg", - ":images/fallback/light/small/arrow-up-double.svg", - ":images/fallback/light/small/dialog-ok.svg", - ":images/fallback/light/small/question.svg" -}; - -static const std::deque fallbackConnectionStateThemeIconsLightSmall = { - ":images/fallback/light/small/state-offline.svg", - ":images/fallback/light/small/state-sync.svg", - ":images/fallback/light/small/state-ok.svg", - ":images/fallback/light/small/state-error.svg" -}; - -static const std::deque fallbackAvailabilityThemeIconsDarkBig = { - ":images/fallback/dark/big/online.svg", - ":images/fallback/dark/big/away.svg", - ":images/fallback/dark/big/absent.svg", - ":images/fallback/dark/big/busy.svg", - ":images/fallback/dark/big/chatty.svg", - ":images/fallback/dark/big/invisible.svg", - ":images/fallback/dark/big/offline.svg" -}; - -static const std::deque fallbackSubscriptionStateThemeIconsDarkBig = { - ":images/fallback/dark/big/edit-none.svg", - ":images/fallback/dark/big/arrow-down-double.svg", - ":images/fallback/dark/big/arrow-up-double.svg", - ":images/fallback/dark/big/dialog-ok.svg", - ":images/fallback/dark/big/question.svg" -}; - -static const std::deque fallbackConnectionStateThemeIconsDarkBig = { - ":images/fallback/dark/big/state-offline.svg", - ":images/fallback/dark/big/state-sync.svg", - ":images/fallback/dark/big/state-ok.svg", - ":images/fallback/dark/big/state-error.svg" -}; - -static const std::deque fallbackAvailabilityThemeIconsDarkSmall = { - ":images/fallback/dark/small/online.svg", - ":images/fallback/dark/small/away.svg", - ":images/fallback/dark/small/absent.svg", - ":images/fallback/dark/small/busy.svg", - ":images/fallback/dark/small/chatty.svg", - ":images/fallback/dark/small/invisible.svg", - ":images/fallback/dark/small/offline.svg" -}; - -static const std::deque fallbackSubscriptionStateThemeIconsDarkSmall = { - ":images/fallback/dark/small/edit-none.svg", - ":images/fallback/dark/small/arrow-down-double.svg", - ":images/fallback/dark/small/arrow-up-double.svg", - ":images/fallback/dark/small/dialog-ok.svg", - ":images/fallback/dark/small/question.svg" -}; - -static const std::deque fallbackConnectionStateThemeIconsDarkSmall = { - ":images/fallback/dark/small/state-offline.svg", - ":images/fallback/dark/small/state-sync.svg", - ":images/fallback/dark/small/state-ok.svg", - ":images/fallback/dark/small/state-error.svg" -}; - -QIcon availabilityIcon(Availability av, bool big = false); -QIcon subscriptionStateIcon(SubscriptionState ss, bool big = false); -QIcon connectionStateIcon(ConnectionState cs, bool big = false); -QIcon icon(const QString& name, bool big = false); -QString iconPath(const QString& name, bool big = false); - -static const std::map> icons = { - {"user-online", {"user-online", "online"}}, - {"user-away", {"user-away", "away"}}, - {"user-away-extended", {"user-away-extended", "absent"}}, - {"user-busy", {"user-busy", "busy"}}, - {"user-chatty", {"chatty", "chatty"}}, - {"user-invisible", {"user-invisible", "invisible"}}, - {"user-offline", {"offline", "offline"}}, - {"edit-none", {"edit-none", "edit-none"}}, - {"arrow-down-double", {"arrow-down-double", "arrow-down-double"}}, - {"arrow-up-double", {"arrow-up-double", "arrow-up-double"}}, - {"dialog-ok", {"dialog-ok", "dialog-ok"}}, - {"question", {"question", "question"}}, - {"state-offline", {"state-offline", "state-offline"}}, - {"state-sync", {"state-sync", "state-sync"}}, - {"state-ok", {"state-ok", "state-ok"}}, - {"state-error", {"state-error", "state-error"}}, - - {"edit-copy", {"edit-copy", "copy"}}, - {"edit-delete", {"edit-delete", "edit-delete"}}, - {"edit-rename", {"edit-rename", "edit-rename"}}, - {"mail-message", {"mail-message", "mail-message"}}, - {"mail-attachment", {"mail-attachment", "mail-attachment"}}, - {"network-connect", {"network-connect", "network-connect"}}, - {"network-disconnect", {"network-disconnect", "network-disconnect"}}, - {"news-subscribe", {"news-subscribe", "news-subscribe"}}, - {"news-unsubscribe", {"news-unsubscribe", "news-unsubscribe"}}, - {"view-refresh", {"view-refresh", "view-refresh"}}, - {"send", {"document-send", "send"}}, - {"clean", {"edit-clear-all", "clean"}}, - {"user", {"user", "user"}}, - {"user-properties", {"user-properties", "user-properties"}}, - {"group", {"group", "group"}}, - {"group-new", {"resurce-group-new", "group-new"}}, - {"favorite", {"favorite", "favorite"}}, - {"unfavorite", {"draw-star", "unfavorite"}}, - {"list-add", {"list-add", "add"}}, -}; - -}; - -#endif // GLOBAL_H diff --git a/main.cpp b/main.cpp index c546b57..25de512 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ #include "ui/squawk.h" #include "core/squawk.h" #include "signalcatcher.h" +#include "shared/global.h" #include #include #include @@ -33,6 +34,8 @@ int main(int argc, char *argv[]) qRegisterMetaType("Shared::VCard"); qRegisterMetaType>("std::list"); qRegisterMetaType>("QSet"); + qRegisterMetaType("Shared::ConnectionState"); + qRegisterMetaType("Shared::Availability"); QApplication app(argc, argv); SignalCatcher sc(&app); @@ -72,6 +75,8 @@ int main(int argc, char *argv[]) icon.addFile(":images/logo.svg", QSize(512, 512)); QApplication::setWindowIcon(icon); + new Shared::Global(); //translates enums + Squawk w; w.show(); diff --git a/shared.h b/shared.h new file mode 100644 index 0000000..83bcd76 --- /dev/null +++ b/shared.h @@ -0,0 +1,29 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef SHARED_H +#define SHARED_H + +#include "shared/enums.h" +#include "shared/utils.h" +#include "shared/icons.h" +#include "shared/message.h" +#include "shared/vcard.h" +#include "shared/global.h" + +#endif // SHARED_H diff --git a/shared/enums.h b/shared/enums.h new file mode 100644 index 0000000..158695c --- /dev/null +++ b/shared/enums.h @@ -0,0 +1,114 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef SHARED_ENUMS_H +#define SHARED_ENUMS_H + +#include + +#include +#include + +namespace Shared { +Q_NAMESPACE + +enum class ConnectionState { + disconnected, + connecting, + connected, + error +}; +Q_ENUM_NS(ConnectionState) +static const std::deque connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; +static const ConnectionState connectionStateHighest = ConnectionState::error; +static const ConnectionState connectionStateLowest = ConnectionState::disconnected; + +enum class Availability { + online, + away, + extendedAway, + busy, + chatty, + invisible, + offline +}; +Q_ENUM_NS(Availability) +static const Availability availabilityHighest = Availability::offline; +static const Availability availabilityLowest = Availability::online; +static const std::deque availabilityThemeIcons = { + "user-online", + "user-away", + "user-away-extended", + "user-busy", + "chatty", + "user-invisible", + "user-offline" +}; +static const std::deque availabilityNames = {"Online", "Away", "Absent", "Busy", "Chatty", "Invisible", "Offline"}; + +enum class SubscriptionState { + none, + from, + to, + both, + unknown +}; +Q_ENUM_NS(SubscriptionState) +static const SubscriptionState subscriptionStateHighest = SubscriptionState::unknown; +static const SubscriptionState subscriptionStateLowest = SubscriptionState::none; +static const std::deque subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"}; +static const std::deque subscriptionStateNames = {"None", "From", "To", "Both", "Unknown"}; + +enum class Affiliation { + unspecified, + outcast, + nobody, + member, + admin, + owner +}; +Q_ENUM_NS(Affiliation) +static const Affiliation affiliationHighest = Affiliation::owner; +static const Affiliation affiliationLowest = Affiliation::unspecified; +static const std::deque affiliationNames = {"Unspecified", "Outcast", "Nobody", "Member", "Admin", "Owner"}; + +enum class Role { + unspecified, + nobody, + visitor, + participant, + moderator +}; +Q_ENUM_NS(Role) +static const Role roleHighest = Role::moderator; +static const Role roleLowest = Role::unspecified; +static const std::deque roleNames = {"Unspecified", "Nobody", "Visitor", "Participant", "Moderator"}; + +enum class Avatar { + empty, + autocreated, + valid +}; +Q_ENUM_NS(Avatar) + + +static const std::deque messageStateNames = {"Pending", "Sent", "Delivered", "Error"}; +static const std::deque messageStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; + +} +#endif // SHARED_ENUMS_H diff --git a/shared/global.cpp b/shared/global.cpp new file mode 100644 index 0000000..4d3399a --- /dev/null +++ b/shared/global.cpp @@ -0,0 +1,170 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include "global.h" + +#include "enums.h" + +Shared::Global* Shared::Global::instance = 0; + +Shared::Global::Global(): + availability({ + tr("Online"), + tr("Away"), + tr("Absent"), + tr("Busy"), + tr("Chatty"), + tr("Invisible"), + tr("Offline") + }), + connectionState({ + tr("Disconnected"), + tr("Connecting"), + tr("Connected"), + tr("Error") + }), + subscriptionState({ + tr("None"), + tr("From"), + tr("To"), + tr("Both"), + tr("Unknown") + }), + affiliation({ + tr("Unspecified"), + tr("Outcast"), + tr("Nobody"), + tr("Member"), + tr("Admin"), + tr("Owner") + }), + role({ + tr("Unspecified"), + tr("Nobody"), + tr("Visitor"), + tr("Participant"), + tr("Moderator") + }), + messageState({ + tr("Pending"), + tr("Sent"), + tr("Delivered"), + tr("Error") + }) +{ + if (instance != 0) { + throw 551; + } + + instance = this; +} + +Shared::Global * Shared::Global::getInstance() +{ + return instance; +} + +QString Shared::Global::getName(Message::State rl) +{ + return instance->messageState[int(rl)]; +} + +QString Shared::Global::getName(Shared::Affiliation af) +{ + return instance->affiliation[int(af)]; +} + +QString Shared::Global::getName(Shared::Availability av) +{ + return instance->availability[int(av)]; +} + +QString Shared::Global::getName(Shared::ConnectionState cs) +{ + return instance->connectionState[int(cs)]; +} + +QString Shared::Global::getName(Shared::Role rl) +{ + return instance->role[int(rl)]; +} + +QString Shared::Global::getName(Shared::SubscriptionState ss) +{ + return instance->subscriptionState[int(ss)]; +} + +template<> +Shared::Availability Shared::Global::fromInt(int src) +{ + if (src < static_cast(Shared::availabilityLowest) && src > static_cast(Shared::availabilityHighest)) { + qDebug("An attempt to set invalid availability to Squawk core, skipping"); + } + + return static_cast(src); +} + +template<> +Shared::Availability Shared::Global::fromInt(unsigned int src) +{ + if (src < static_cast(Shared::availabilityLowest) && src > static_cast(Shared::availabilityHighest)) { + qDebug("An attempt to set invalid availability to Squawk core, skipping"); + } + + return static_cast(src); +} + +template<> +Shared::ConnectionState Shared::Global::fromInt(int src) +{ + if (src < static_cast(Shared::connectionStateLowest) && src > static_cast(Shared::connectionStateHighest)) { + qDebug("An attempt to set invalid availability to Squawk core, skipping"); + } + + return static_cast(src); +} + +template<> +Shared::ConnectionState Shared::Global::fromInt(unsigned int src) +{ + if (src < static_cast(Shared::connectionStateLowest) && src > static_cast(Shared::connectionStateHighest)) { + qDebug("An attempt to set invalid availability to Squawk core, skipping"); + } + + return static_cast(src); +} + +template<> +Shared::SubscriptionState Shared::Global::fromInt(int src) +{ + if (src < static_cast(Shared::subscriptionStateLowest) && src > static_cast(Shared::subscriptionStateHighest)) { + qDebug("An attempt to set invalid availability to Squawk core, skipping"); + } + + return static_cast(src); +} + +template<> +Shared::SubscriptionState Shared::Global::fromInt(unsigned int src) +{ + if (src < static_cast(Shared::subscriptionStateLowest) && src > static_cast(Shared::subscriptionStateHighest)) { + qDebug("An attempt to set invalid availability to Squawk core, skipping"); + } + + return static_cast(src); +} diff --git a/shared/global.h b/shared/global.h new file mode 100644 index 0000000..ef61611 --- /dev/null +++ b/shared/global.h @@ -0,0 +1,64 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef SHARED_GLOBAL_H +#define SHARED_GLOBAL_H + +#include "enums.h" +#include "message.h" + +#include + +#include +#include + +namespace Shared { + + class Global { + Q_DECLARE_TR_FUNCTIONS(Global) + + public: + Global(); + + static Global* getInstance(); + static QString getName(Availability av); + static QString getName(ConnectionState cs); + static QString getName(SubscriptionState ss); + static QString getName(Affiliation af); + static QString getName(Role rl); + static QString getName(Message::State rl); + + const std::deque availability; + const std::deque connectionState; + const std::deque subscriptionState; + const std::deque affiliation; + const std::deque role; + const std::deque messageState; + + template + static T fromInt(int src); + + template + static T fromInt(unsigned int src); + + private: + static Global* instance; + }; +} + +#endif // SHARED_GLOBAL_H diff --git a/shared/icons.cpp b/shared/icons.cpp new file mode 100644 index 0000000..f3a4dcc --- /dev/null +++ b/shared/icons.cpp @@ -0,0 +1,96 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include "icons.h" + +#include +#include +#include + +QIcon Shared::availabilityIcon(Shared::Availability av, bool big) +{ + const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? + big ? + Shared::fallbackAvailabilityThemeIconsDarkBig: + Shared::fallbackAvailabilityThemeIconsDarkSmall: + big ? + Shared::fallbackAvailabilityThemeIconsLightBig: + Shared::fallbackAvailabilityThemeIconsLightSmall; + + return QIcon::fromTheme(availabilityThemeIcons[static_cast(av)], QIcon(fallback[static_cast(av)])); +} + +QIcon Shared::subscriptionStateIcon(Shared::SubscriptionState ss, bool big) +{ + const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? + big ? + Shared::fallbackSubscriptionStateThemeIconsDarkBig: + Shared::fallbackSubscriptionStateThemeIconsDarkSmall: + big ? + Shared::fallbackSubscriptionStateThemeIconsLightBig: + Shared::fallbackSubscriptionStateThemeIconsLightSmall; + + return QIcon::fromTheme(subscriptionStateThemeIcons[static_cast(ss)], QIcon(fallback[static_cast(ss)])); +} + +QIcon Shared::connectionStateIcon(Shared::ConnectionState cs, bool big) +{ + const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? + big ? + Shared::fallbackConnectionStateThemeIconsDarkBig: + Shared::fallbackConnectionStateThemeIconsDarkSmall: + big ? + Shared::fallbackConnectionStateThemeIconsLightBig: + Shared::fallbackConnectionStateThemeIconsLightSmall; + + return QIcon::fromTheme(connectionStateThemeIcons[static_cast(cs)], QIcon(fallback[static_cast(cs)])); +} + +static const QString ds = ":images/fallback/dark/small/"; +static const QString db = ":images/fallback/dark/big/"; +static const QString ls = ":images/fallback/light/small/"; +static const QString lb = ":images/fallback/light/big/"; + +QIcon Shared::icon(const QString& name, bool big) +{ + std::map>::const_iterator itr = icons.find(name); + if (itr != icons.end()) { + const QString& prefix = QApplication::palette().window().color().lightnessF() > 0.5 ? + big ? db : ds: + big ? lb : ls; + return QIcon::fromTheme(itr->second.first, QIcon(prefix + itr->second.second + ".svg")); + } else { + qDebug() << "Icon" << name << "not found"; + return QIcon::fromTheme(name); + } +} + + +QString Shared::iconPath(const QString& name, bool big) +{ + QString result = ""; + std::map>::const_iterator itr = icons.find(name); + if (itr != icons.end()) { + const QString& prefix = QApplication::palette().window().color().lightnessF() > 0.5 ? + big ? db : ds: + big ? lb : ls; + result = prefix + itr->second.second + ".svg"; + } + + return result; +} diff --git a/shared/icons.h b/shared/icons.h new file mode 100644 index 0000000..48ecc37 --- /dev/null +++ b/shared/icons.h @@ -0,0 +1,176 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef SHARED_ICONS_H +#define SHARED_ICONS_H + +#include + +#include + +#include "enums.h" + +namespace Shared { + +static const std::deque fallbackAvailabilityThemeIconsLightBig = { + ":images/fallback/light/big/online.svg", + ":images/fallback/light/big/away.svg", + ":images/fallback/light/big/absent.svg", + ":images/fallback/light/big/busy.svg", + ":images/fallback/light/big/chatty.svg", + ":images/fallback/light/big/invisible.svg", + ":images/fallback/light/big/offline.svg" +}; + +static const std::deque fallbackSubscriptionStateThemeIconsLightBig = { + ":images/fallback/light/big/edit-none.svg", + ":images/fallback/light/big/arrow-down-double.svg", + ":images/fallback/light/big/arrow-up-double.svg", + ":images/fallback/light/big/dialog-ok.svg", + ":images/fallback/light/big/question.svg" +}; + +static const std::deque fallbackConnectionStateThemeIconsLightBig = { + ":images/fallback/light/big/state-offline.svg", + ":images/fallback/light/big/state-sync.svg", + ":images/fallback/light/big/state-ok.svg", + ":images/fallback/light/big/state-error.svg" +}; + +static const std::deque fallbackAvailabilityThemeIconsLightSmall = { + ":images/fallback/light/small/online.svg", + ":images/fallback/light/small/away.svg", + ":images/fallback/light/small/absent.svg", + ":images/fallback/light/small/busy.svg", + ":images/fallback/light/small/chatty.svg", + ":images/fallback/light/small/invisible.svg", + ":images/fallback/light/small/offline.svg" +}; + +static const std::deque fallbackSubscriptionStateThemeIconsLightSmall = { + ":images/fallback/light/small/edit-none.svg", + ":images/fallback/light/small/arrow-down-double.svg", + ":images/fallback/light/small/arrow-up-double.svg", + ":images/fallback/light/small/dialog-ok.svg", + ":images/fallback/light/small/question.svg" +}; + +static const std::deque fallbackConnectionStateThemeIconsLightSmall = { + ":images/fallback/light/small/state-offline.svg", + ":images/fallback/light/small/state-sync.svg", + ":images/fallback/light/small/state-ok.svg", + ":images/fallback/light/small/state-error.svg" +}; + +static const std::deque fallbackAvailabilityThemeIconsDarkBig = { + ":images/fallback/dark/big/online.svg", + ":images/fallback/dark/big/away.svg", + ":images/fallback/dark/big/absent.svg", + ":images/fallback/dark/big/busy.svg", + ":images/fallback/dark/big/chatty.svg", + ":images/fallback/dark/big/invisible.svg", + ":images/fallback/dark/big/offline.svg" +}; + +static const std::deque fallbackSubscriptionStateThemeIconsDarkBig = { + ":images/fallback/dark/big/edit-none.svg", + ":images/fallback/dark/big/arrow-down-double.svg", + ":images/fallback/dark/big/arrow-up-double.svg", + ":images/fallback/dark/big/dialog-ok.svg", + ":images/fallback/dark/big/question.svg" +}; + +static const std::deque fallbackConnectionStateThemeIconsDarkBig = { + ":images/fallback/dark/big/state-offline.svg", + ":images/fallback/dark/big/state-sync.svg", + ":images/fallback/dark/big/state-ok.svg", + ":images/fallback/dark/big/state-error.svg" +}; + +static const std::deque fallbackAvailabilityThemeIconsDarkSmall = { + ":images/fallback/dark/small/online.svg", + ":images/fallback/dark/small/away.svg", + ":images/fallback/dark/small/absent.svg", + ":images/fallback/dark/small/busy.svg", + ":images/fallback/dark/small/chatty.svg", + ":images/fallback/dark/small/invisible.svg", + ":images/fallback/dark/small/offline.svg" +}; + +static const std::deque fallbackSubscriptionStateThemeIconsDarkSmall = { + ":images/fallback/dark/small/edit-none.svg", + ":images/fallback/dark/small/arrow-down-double.svg", + ":images/fallback/dark/small/arrow-up-double.svg", + ":images/fallback/dark/small/dialog-ok.svg", + ":images/fallback/dark/small/question.svg" +}; + +static const std::deque fallbackConnectionStateThemeIconsDarkSmall = { + ":images/fallback/dark/small/state-offline.svg", + ":images/fallback/dark/small/state-sync.svg", + ":images/fallback/dark/small/state-ok.svg", + ":images/fallback/dark/small/state-error.svg" +}; + +QIcon availabilityIcon(Availability av, bool big = false); +QIcon subscriptionStateIcon(SubscriptionState ss, bool big = false); +QIcon connectionStateIcon(ConnectionState cs, bool big = false); +QIcon icon(const QString& name, bool big = false); +QString iconPath(const QString& name, bool big = false); + +static const std::map> icons = { + {"user-online", {"user-online", "online"}}, + {"user-away", {"user-away", "away"}}, + {"user-away-extended", {"user-away-extended", "absent"}}, + {"user-busy", {"user-busy", "busy"}}, + {"user-chatty", {"chatty", "chatty"}}, + {"user-invisible", {"user-invisible", "invisible"}}, + {"user-offline", {"offline", "offline"}}, + {"edit-none", {"edit-none", "edit-none"}}, + {"arrow-down-double", {"arrow-down-double", "arrow-down-double"}}, + {"arrow-up-double", {"arrow-up-double", "arrow-up-double"}}, + {"dialog-ok", {"dialog-ok", "dialog-ok"}}, + {"question", {"question", "question"}}, + {"state-offline", {"state-offline", "state-offline"}}, + {"state-sync", {"state-sync", "state-sync"}}, + {"state-ok", {"state-ok", "state-ok"}}, + {"state-error", {"state-error", "state-error"}}, + + {"edit-copy", {"edit-copy", "copy"}}, + {"edit-delete", {"edit-delete", "edit-delete"}}, + {"edit-rename", {"edit-rename", "edit-rename"}}, + {"mail-message", {"mail-message", "mail-message"}}, + {"mail-attachment", {"mail-attachment", "mail-attachment"}}, + {"network-connect", {"network-connect", "network-connect"}}, + {"network-disconnect", {"network-disconnect", "network-disconnect"}}, + {"news-subscribe", {"news-subscribe", "news-subscribe"}}, + {"news-unsubscribe", {"news-unsubscribe", "news-unsubscribe"}}, + {"view-refresh", {"view-refresh", "view-refresh"}}, + {"send", {"document-send", "send"}}, + {"clean", {"edit-clear-all", "clean"}}, + {"user", {"user", "user"}}, + {"user-properties", {"user-properties", "user-properties"}}, + {"group", {"group", "group"}}, + {"group-new", {"resurce-group-new", "group-new"}}, + {"favorite", {"favorite", "favorite"}}, + {"unfavorite", {"draw-star", "unfavorite"}}, + {"list-add", {"list-add", "add"}}, +}; +} + +#endif // SHARED_ICONS_H diff --git a/shared/message.cpp b/shared/message.cpp new file mode 100644 index 0000000..7df0f28 --- /dev/null +++ b/shared/message.cpp @@ -0,0 +1,399 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include "message.h" +#include "utils.h" + +Shared::Message::Message(Shared::Message::Type p_type): + jFrom(), + rFrom(), + jTo(), + rTo(), + id(), + body(), + time(), + thread(), + type(p_type), + outgoing(false), + forwarded(false), + state(State::delivered), + edited(false) {} + +Shared::Message::Message(): + jFrom(), + rFrom(), + jTo(), + rTo(), + id(), + body(), + time(), + thread(), + type(Message::normal), + outgoing(false), + forwarded(false), + state(State::delivered), + edited(false), + errorText(), + originalMessage(), + lastModified() {} + +QString Shared::Message::getBody() const +{ + return body; +} + +QString Shared::Message::getFrom() const +{ + QString from = jFrom; + if (rFrom.size() > 0) { + from += "/" + rFrom; + } + return from; +} + +QString Shared::Message::getTo() const +{ + QString to = jTo; + if (rTo.size() > 0) { + to += "/" + rTo; + } + return to; +} + +QString Shared::Message::getId() const +{ + return id; +} + +QDateTime Shared::Message::getTime() const +{ + return time; +} + +void Shared::Message::setBody(const QString& p_body) +{ + body = p_body; +} + +void Shared::Message::setFrom(const QString& from) +{ + QStringList list = from.split("/"); + if (list.size() == 1) { + jFrom = from; + } else { + jFrom = list.front(); + rFrom = list.back(); + } +} + +void Shared::Message::setTo(const QString& to) +{ + QStringList list = to.split("/"); + if (list.size() == 1) { + jTo = to; + } else { + jTo = list.front(); + rTo = list.back(); + } +} + +void Shared::Message::setId(const QString& p_id) +{ + id = p_id; +} + +void Shared::Message::setTime(const QDateTime& p_time) +{ + time = p_time; +} + +QString Shared::Message::getFromJid() const +{ + return jFrom; +} + +QString Shared::Message::getFromResource() const +{ + return rFrom; +} + +QString Shared::Message::getToJid() const +{ + return jTo; +} + +QString Shared::Message::getToResource() const +{ + return rTo; +} + +QString Shared::Message::getErrorText() const +{ + return errorText; +} + +QString Shared::Message::getPenPalJid() const +{ + if (outgoing) { + return jTo; + } else { + return jFrom; + } +} + +QString Shared::Message::getPenPalResource() const +{ + if (outgoing) { + return rTo; + } else { + return rFrom; + } +} + +Shared::Message::State Shared::Message::getState() const +{ + return state; +} + +bool Shared::Message::getEdited() const +{ + return edited; +} + +void Shared::Message::setFromJid(const QString& from) +{ + jFrom = from; +} + +void Shared::Message::setFromResource(const QString& from) +{ + rFrom = from; +} + +void Shared::Message::setToJid(const QString& to) +{ + jTo = to; +} + +void Shared::Message::setToResource(const QString& to) +{ + rTo = to; +} + +void Shared::Message::setErrorText(const QString& err) +{ + if (state == State::error) { + errorText = err; + } +} + +bool Shared::Message::getOutgoing() const +{ + return outgoing; +} + +void Shared::Message::setOutgoing(bool og) +{ + outgoing = og; +} + +bool Shared::Message::getForwarded() const +{ + return forwarded; +} + +void Shared::Message::generateRandomId() +{ + id = generateUUID(); +} + +QString Shared::Message::getThread() const +{ + return thread; +} + +void Shared::Message::setForwarded(bool fwd) +{ + forwarded = fwd; +} + +void Shared::Message::setThread(const QString& p_body) +{ + thread = p_body; +} + +QDateTime Shared::Message::getLastModified() const +{ + return lastModified; +} + +QString Shared::Message::getOriginalBody() const +{ + return originalMessage; +} + +Shared::Message::Type Shared::Message::getType() const +{ + return type; +} + +void Shared::Message::setType(Shared::Message::Type t) +{ + type = t; +} + +void Shared::Message::setState(Shared::Message::State p_state) +{ + state = p_state; + + if (state != State::error) { + errorText = ""; + } +} + +bool Shared::Message::serverStored() const +{ + return state == State::delivered || state == State::sent; +} + +void Shared::Message::setEdited(bool p_edited) +{ + edited = p_edited; +} + +void Shared::Message::serialize(QDataStream& data) const +{ + data << jFrom; + data << rFrom; + data << jTo; + data << rTo; + data << id; + data << body; + data << time; + data << thread; + data << (quint8)type; + data << outgoing; + data << forwarded; + data << oob; + data << (quint8)state; + data << edited; + if (state == State::error) { + data << errorText; + } + if (edited) { + data << originalMessage; + data << lastModified; + } +} + +void Shared::Message::deserialize(QDataStream& data) +{ + data >> jFrom; + data >> rFrom; + data >> jTo; + data >> rTo; + data >> id; + data >> body; + data >> time; + data >> thread; + quint8 t; + data >> t; + type = static_cast(t); + data >> outgoing; + data >> forwarded; + data >> oob; + quint8 s; + data >> s; + state = static_cast(s); + data >> edited; + if (state == State::error) { + data >> errorText; + } + if (edited) { + data >> originalMessage; + data >> lastModified; + } +} + +bool Shared::Message::change(const QMap& data) +{ + QMap::const_iterator itr = data.find("state"); + if (itr != data.end()) { + setState(static_cast(itr.value().toUInt())); + } + + if (state == State::error) { + itr = data.find("errorText"); + if (itr != data.end()) { + setErrorText(itr.value().toString()); + } + } + + bool idChanged = false; + itr = data.find("id"); + if (itr != data.end()) { + QString newId = itr.value().toString(); + if (id != newId) { + setId(newId); + idChanged = true; + } + } + itr = data.find("body"); + if (itr != data.end()) { + QMap::const_iterator dItr = data.find("stamp"); + QDateTime correctionDate; + if (dItr != data.end()) { + correctionDate = dItr.value().toDateTime(); + } else { + correctionDate = QDateTime::currentDateTimeUtc(); //in case there is no information about time of this correction it's applied + } + if (!edited || lastModified < correctionDate) { + originalMessage = body; + lastModified = correctionDate; + setBody(itr.value().toString()); + setEdited(true); + } + } + + return idChanged; +} + +void Shared::Message::setCurrentTime() +{ + time = QDateTime::currentDateTimeUtc(); +} + +QString Shared::Message::getOutOfBandUrl() const +{ + return oob; +} + +bool Shared::Message::hasOutOfBandUrl() const +{ + return oob.size() > 0; +} + +void Shared::Message::setOutOfBandUrl(const QString& url) +{ + oob = url; +} + +bool Shared::Message::storable() const +{ + return id.size() > 0 && (body.size() > 0 || oob.size()) > 0; +} diff --git a/shared/message.h b/shared/message.h new file mode 100644 index 0000000..98ef206 --- /dev/null +++ b/shared/message.h @@ -0,0 +1,125 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#ifndef SHAPER_MESSAGE_H +#define SHAPER_MESSAGE_H + +namespace Shared { + +/** + * @todo write docs + */ +class Message { +public: + enum Type { + error, + normal, + chat, + groupChat, + headline + }; + + enum class State { + pending, + sent, + delivered, + error + }; + + Message(Type p_type); + Message(); + + void setFrom(const QString& from); + void setFromResource(const QString& from); + void setFromJid(const QString& from); + void setTo(const QString& to); + void setToResource(const QString& to); + void setToJid(const QString& to); + void setTime(const QDateTime& p_time); + void setId(const QString& p_id); + void setBody(const QString& p_body); + void setThread(const QString& p_body); + void setOutgoing(bool og); + void setForwarded(bool fwd); + void setType(Type t); + void setCurrentTime(); + void setOutOfBandUrl(const QString& url); + void setState(State p_state); + void setEdited(bool p_edited); + void setErrorText(const QString& err); + bool change(const QMap& data); + + QString getFrom() const; + QString getFromJid() const; + QString getFromResource() const; + QString getTo() const; + QString getToJid() const; + QString getToResource() const; + QDateTime getTime() const; + QString getId() const; + QString getBody() const; + QString getThread() const; + bool getOutgoing() const; + bool getForwarded() const; + Type getType() const; + bool hasOutOfBandUrl() const; + bool storable() const; + QString getOutOfBandUrl() const; + State getState() const; + bool getEdited() const; + QString getErrorText() const; + + QString getPenPalJid() const; + QString getPenPalResource() const; + void generateRandomId(); + bool serverStored() const; + QDateTime getLastModified() const; + QString getOriginalBody() const; + + void serialize(QDataStream& data) const; + void deserialize(QDataStream& data); + +private: + QString jFrom; + QString rFrom; + QString jTo; + QString rTo; + QString id; + QString body; + QDateTime time; + QString thread; + Type type; + bool outgoing; + bool forwarded; + QString oob; + State state; + bool edited; + QString errorText; + QString originalMessage; + QDateTime lastModified; +}; + +} + +#endif // SHAPER_MESSAGE_H diff --git a/shared/utils.cpp b/shared/utils.cpp new file mode 100644 index 0000000..776c052 --- /dev/null +++ b/shared/utils.cpp @@ -0,0 +1,29 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include "utils.h" + +QString Shared::generateUUID() +{ + uuid_t uuid; + uuid_generate(uuid); + + char uuid_str[36]; + uuid_unparse_lower(uuid, uuid_str); + return uuid_str; +} diff --git a/shared/utils.h b/shared/utils.h new file mode 100644 index 0000000..218b53a --- /dev/null +++ b/shared/utils.h @@ -0,0 +1,72 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef SHARED_UTILS_H +#define SHARED_UTILS_H + +#include +#include + +#include +#include + +namespace Shared { + +QString generateUUID(); + +static const std::vector colorPalette = { + QColor(244, 27, 63), + QColor(21, 104, 156), + QColor(38, 156, 98), + QColor(247, 103, 101), + QColor(121, 37, 117), + QColor(242, 202, 33), + QColor(168, 22, 63), + QColor(35, 100, 52), + QColor(52, 161, 152), + QColor(239, 53, 111), + QColor(237, 234, 36), + QColor(153, 148, 194), + QColor(211, 102, 151), + QColor(194, 63, 118), + QColor(249, 149, 51), + QColor(244, 206, 109), + QColor(121, 105, 153), + QColor(244, 199, 30), + QColor(28, 112, 28), + QColor(172, 18, 20), + QColor(25, 66, 110), + QColor(25, 149, 104), + QColor(214, 148, 0), + QColor(203, 47, 57), + QColor(4, 54, 84), + QColor(116, 161, 97), + QColor(50, 68, 52), + QColor(237, 179, 20), + QColor(69, 114, 147), + QColor(242, 212, 31), + QColor(248, 19, 20), + QColor(84, 102, 84), + QColor(25, 53, 122), + QColor(91, 91, 109), + QColor(17, 17, 80), + QColor(54, 54, 94) +}; +} + +#endif // SHARED_UTILS_H diff --git a/shared/vcard.cpp b/shared/vcard.cpp new file mode 100644 index 0000000..6b996e2 --- /dev/null +++ b/shared/vcard.cpp @@ -0,0 +1,288 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include "vcard.h" + +Shared::VCard::Contact::Contact(Shared::VCard::Contact::Role p_role, bool p_prefered): + role(p_role), + prefered(p_prefered) {} + +Shared::VCard::Email::Email(const QString& addr, Shared::VCard::Contact::Role p_role, bool p_prefered): + Contact(p_role, p_prefered), + address(addr) {} + +Shared::VCard::Phone::Phone(const QString& nmbr, Shared::VCard::Phone::Type p_type, Shared::VCard::Contact::Role p_role, bool p_prefered): + Contact(p_role, p_prefered), + number(nmbr), + type(p_type) {} + +Shared::VCard::Address::Address(const QString& zCode, const QString& cntry, const QString& rgn, const QString& lclty, const QString& strt, const QString& ext, Shared::VCard::Contact::Role p_role, bool p_prefered): + Contact(p_role, p_prefered), + zipCode(zCode), + country(cntry), + region(rgn), + locality(lclty), + street(strt), + external(ext) {} + +Shared::VCard::VCard(): + fullName(), + firstName(), + middleName(), + lastName(), + nickName(), + description(), + url(), + organizationName(), + organizationUnit(), + organizationRole(), + jobTitle(), + birthday(), + photoType(Avatar::empty), + photoPath(), + receivingTime(QDateTime::currentDateTimeUtc()), + emails(), + phones(), + addresses() {} + +Shared::VCard::VCard(const QDateTime& creationTime): + fullName(), + firstName(), + middleName(), + lastName(), + nickName(), + description(), + url(), + organizationName(), + organizationUnit(), + organizationRole(), + jobTitle(), + birthday(), + photoType(Avatar::empty), + photoPath(), + receivingTime(creationTime), + emails(), + phones(), + addresses() {} + +QString Shared::VCard::getAvatarPath() const +{ + return photoPath; +} + +Shared::Avatar Shared::VCard::getAvatarType() const +{ + return photoType; +} + +QDate Shared::VCard::getBirthday() const +{ + return birthday; +} + +QString Shared::VCard::getDescription() const +{ + return description; +} + +QString Shared::VCard::getFirstName() const +{ + return firstName; +} + +QString Shared::VCard::getLastName() const +{ + return lastName; +} + +QString Shared::VCard::getMiddleName() const +{ + return middleName; +} + +QString Shared::VCard::getNickName() const +{ + return nickName; +} + +void Shared::VCard::setAvatarPath(const QString& path) +{ + if (path != photoPath) { + photoPath = path; + } +} + +void Shared::VCard::setAvatarType(Shared::Avatar type) +{ + if (photoType != type) { + photoType = type; + } +} + +void Shared::VCard::setBirthday(const QDate& date) +{ + if (date.isValid() && birthday != date) { + birthday = date; + } +} + +void Shared::VCard::setDescription(const QString& descr) +{ + if (description != descr) { + description = descr; + } +} + +void Shared::VCard::setFirstName(const QString& first) +{ + if (firstName != first) { + firstName = first; + } +} + +void Shared::VCard::setLastName(const QString& last) +{ + if (lastName != last) { + lastName = last; + } +} + +void Shared::VCard::setMiddleName(const QString& middle) +{ + if (middleName != middle) { + middleName = middle; + } +} + +void Shared::VCard::setNickName(const QString& nick) +{ + if (nickName != nick) { + nickName = nick; + } +} + +QString Shared::VCard::getFullName() const +{ + return fullName; +} + +QString Shared::VCard::getUrl() const +{ + return url; +} + +void Shared::VCard::setFullName(const QString& name) +{ + if (fullName != name) { + fullName = name; + } +} + +void Shared::VCard::setUrl(const QString& u) +{ + if (url != u) { + url = u; + } +} + +QString Shared::VCard::getOrgName() const +{ + return organizationName; +} + +QString Shared::VCard::getOrgRole() const +{ + return organizationRole; +} + +QString Shared::VCard::getOrgTitle() const +{ + return jobTitle; +} + +QString Shared::VCard::getOrgUnit() const +{ + return organizationUnit; +} + +void Shared::VCard::setOrgName(const QString& name) +{ + if (organizationName != name) { + organizationName = name; + } +} + +void Shared::VCard::setOrgRole(const QString& role) +{ + if (organizationRole != role) { + organizationRole = role; + } +} + +void Shared::VCard::setOrgTitle(const QString& title) +{ + if (jobTitle != title) { + jobTitle = title; + } +} + +void Shared::VCard::setOrgUnit(const QString& unit) +{ + if (organizationUnit != unit) { + organizationUnit = unit; + } +} + +QDateTime Shared::VCard::getReceivingTime() const +{ + return receivingTime; +} + +std::deque & Shared::VCard::getEmails() +{ + return emails; +} + +std::deque & Shared::VCard::getAddresses() +{ + return addresses; +} + +std::deque & Shared::VCard::getPhones() +{ + return phones; +} + +const std::deque & Shared::VCard::getEmails() const +{ + return emails; +} + +const std::deque & Shared::VCard::getAddresses() const +{ + return addresses; +} + +const std::deque & Shared::VCard::getPhones() const +{ + return phones; +} + +const std::dequeShared::VCard::Contact::roleNames = {"Not specified", "Personal", "Business"}; +const std::dequeShared::VCard::Phone::typeNames = {"Fax", "Pager", "Voice", "Cell", "Video", "Modem", "Other"}; + diff --git a/shared/vcard.h b/shared/vcard.h new file mode 100644 index 0000000..68e5de3 --- /dev/null +++ b/shared/vcard.h @@ -0,0 +1,152 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef SHARED_VCARD_H +#define SHARED_VCARD_H + +#include +#include + +#include + +#include "enums.h" + +namespace Shared { + +class VCard { + class Contact { + public: + enum Role { + none, + home, + work + }; + static const std::deque roleNames; + + Contact(Role p_role = none, bool p_prefered = false); + + Role role; + bool prefered; + }; +public: + class Email : public Contact { + public: + Email(const QString& address, Role p_role = none, bool p_prefered = false); + + QString address; + }; + class Phone : public Contact { + public: + enum Type { + fax, + pager, + voice, + cell, + video, + modem, + other + }; + static const std::deque typeNames; + Phone(const QString& number, Type p_type = voice, Role p_role = none, bool p_prefered = false); + + QString number; + Type type; + }; + class Address : public Contact { + public: + Address( + const QString& zCode = "", + const QString& cntry = "", + const QString& rgn = "", + const QString& lclty = "", + const QString& strt = "", + const QString& ext = "", + Role p_role = none, + bool p_prefered = false + ); + + QString zipCode; + QString country; + QString region; + QString locality; + QString street; + QString external; + }; + VCard(); + VCard(const QDateTime& creationTime); + + QString getFullName() const; + void setFullName(const QString& name); + QString getFirstName() const; + void setFirstName(const QString& first); + QString getMiddleName() const; + void setMiddleName(const QString& middle); + QString getLastName() const; + void setLastName(const QString& last); + QString getNickName() const; + void setNickName(const QString& nick); + QString getDescription() const; + void setDescription(const QString& descr); + QString getUrl() const; + void setUrl(const QString& u); + QDate getBirthday() const; + void setBirthday(const QDate& date); + Avatar getAvatarType() const; + void setAvatarType(Avatar type); + QString getAvatarPath() const; + void setAvatarPath(const QString& path); + QString getOrgName() const; + void setOrgName(const QString& name); + QString getOrgUnit() const; + void setOrgUnit(const QString& unit); + QString getOrgRole() const; + void setOrgRole(const QString& role); + QString getOrgTitle() const; + void setOrgTitle(const QString& title); + QDateTime getReceivingTime() const; + std::deque& getEmails(); + const std::deque& getEmails() const; + std::deque& getPhones(); + const std::deque& getPhones() const; + std::deque
& getAddresses(); + const std::deque
& getAddresses() const; + +private: + QString fullName; + QString firstName; + QString middleName; + QString lastName; + QString nickName; + QString description; + QString url; + QString organizationName; + QString organizationUnit; + QString organizationRole; + QString jobTitle; + QDate birthday; + Avatar photoType; + QString photoPath; + QDateTime receivingTime; + std::deque emails; + std::deque phones; + std::deque
addresses; +}; + +} + +#endif // SHARED_VCARD_H diff --git a/translations/squawk.ru.ts b/translations/squawk.ru.ts index 4fe02e3..37686fb 100644 --- a/translations/squawk.ru.ts +++ b/translations/squawk.ru.ts @@ -4,93 +4,63 @@ Account - - Account Заголовок окна Учетная запись - - Your account login Имя пользователя Вашей учетной записи - - john_smith1987 ivan_ivanov1987 - - Server Сервер - - A server address of your account. Like 404.city or macaw.me Адресс сервера вашей учетной записи (выглядит как 404.city или macaw.me) - - macaw.me macaw.me - - Login Имя учетной записи - - Password Пароль - - Password of your account Пароль вашей учетной записи - - Name Имя - - Just a name how would you call this account, doesn't affect anything Просто имя, то как Вы называете свою учетную запись, может быть любым - - John Иван - - Resource Ресурс - - A resource name like "Home" or "Work" Имя этой программы для ваших контактов, может быть "Home" или "Phone" - - QXmpp Ресурс по умолчанию QXmpp @@ -99,45 +69,30 @@ Accounts - - Accounts Учетные записи - - Delete Удалить - - Add Добавить - - Edit Редактировать - - Change password Изменить пароль - - - - Connect Подключить - Disconnect Отключить @@ -145,16 +100,21 @@ Conversation - - Type your message here... Введите сообщение... - Chose a file to send Выберите файл для отправки + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Liberation Sans'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + Global @@ -260,43 +220,43 @@ Not specified - Не указан + Не указан Personal - Личный + Личный Business - Рабочий + Рабочий Fax - Факс + Факс Pager - Пэйджер + Пэйджер Voice - Стационарный + Стационарный Cell - Мобильный + Мобильный Video - Видеофон + Видеофон Modem - Модем + Модем Other - Другой + Другой Pending @@ -314,63 +274,43 @@ JoinConference - - Join new conference Заголовок окна Присоединиться к новой беседе - - JID JID - - Room JID Jabber-идентификатор беседы - - identifier@conference.server.org identifier@conference.server.org - - Account Учетная запись - - Join on login Автовход - - If checked Squawk will try to join this conference on login Если стоит галочка Squawk автоматически присоединится к этой беседе при подключении - - Nick name Псевдоним - - Your nick name for that conference. If you leave this field empty your account name will be used as a nick name Ваш псевдоним в этой беседе, если оставите это поле пустым - будет использовано имя Вашей учетной записи - - John Ivan @@ -379,10 +319,9 @@ Message Download - Скачать + Скачать - Open Открыть @@ -390,23 +329,18 @@ MessageLine - Downloading... Скачивается... - - Download Скачать - Push the button to daownload the file Нажмите на кнопку что бы загрузить файл - Error uploading file: %1 You can try again Ошибка загрузки файла на сервер: @@ -414,12 +348,10 @@ You can try again Для того, что бы попробовать снова нажмите на кнопку - Upload Загрузить - Error downloading file: %1 You can try again Ошибка скачивания файла: @@ -427,7 +359,6 @@ You can try again Вы можете попробовать снова - Uploading... Загружается... @@ -436,40 +367,36 @@ You can try again Models::Accounts Name - Имя + Имя Server - Сервер + Сервер State - Состояние + Состояние Error - Ошибка + Ошибка Models::Room - Subscribed Вы состоите в беседе - Temporarily unsubscribed Вы временно не состоите в беседе - Temporarily subscribed Вы временно состоите в беседе - Unsubscribed Вы не состоите в беседе @@ -477,67 +404,47 @@ You can try again Models::Roster - New messages Есть непрочитанные сообщения - - - - New messages: Новых сообщений: - Jabber ID: Идентификатор: - - - Availability: Доступность: - - - Status: Статус: - - - Subscription: Подписка: - Affiliation: Я правда не знаю, как это объяснить, не то что перевести Причастность: - Role: Роль: - Online contacts: Контакстов в сети: - Total contacts: Всего контактов: - Members: Участников: @@ -545,58 +452,40 @@ You can try again NewContact - - Add new contact Заголовок окна Добавление нового контакта - - Account Учетная запись - - An account that is going to have new contact Учетная запись для которой будет добавлен контакт - - JID JID - - Jabber id of your new contact Jabber-идентификатор нового контакта - - name@server.dmn Placeholder поля ввода JID name@server.dmn - - Name Имя - - The way this new contact will be labeled in your roster (optional) То, как будет подписан контакт в вашем списке контактов (не обязательно) - - John Smith Иван Иванов @@ -604,99 +493,70 @@ You can try again Squawk - - squawk Squawk - - Settings Настройки - - Squawk Squawk - - Accounts Учетные записи - - Quit Выйти - - Add contact Добавить контакт - - Add conference Присоединиться к беседе - Contact list Список контактов - Disconnect Отключить - Connect Подключить - - VCard Карточка - - - Remove Удалить - Open dialog Открыть диалог - - Unsubscribe Отписаться - - Subscribe Подписаться - Rename Переименовать - Input new name for %1 or leave it empty for the contact to be displayed as %1 @@ -706,269 +566,197 @@ to be displayed as %1 %1 - Renaming %1 Назначение имени контакту %1 - Groups Группы - New group Создать новую группу - New group name Имя группы - Add %1 to a new group Добавление %1 в новую группу - Open conversation Открыть окно беседы - %1 account card Карточка учетной записи %1 - %1 contact card Карточка контакта %1 - Downloading vCard Получение карточки + + Attached file + Прикрепленный файл + VCard - - Received 12.07.2007 at 17.35 Не обновлялось - - - - General Общее - - Organization Место работы - - Middle name Среднее имя - - First name Имя - - Last name Фамилия - - Nick name Псевдоним - - Birthday Дата рождения - - Organization name Название организации - - Unit / Department Отдел - - Role / Profession Профессия - - Job title Наименование должности - - Full name Полное имя - - Personal information Личная информация - - Addresses Адреса - - E-Mail addresses Адреса электронной почты - - Phone numbers Номера телефонов - - - - Contact Контактная информация - - Jabber ID Jabber ID - - Web site Веб сайт - - - - Description Описание - - Set avatar Установить иконку - - Clear avatar Убрать иконку - Account %1 card Карточка учетной записи %1 - Contact %1 card Карточка контакта %1 - Received %1 at %2 Получено %1 в %2 - Chose your new avatar Выберите новую иконку - Images (*.png *.jpg *.jpeg) Изображения (*.png *.jpg *.jpeg) - Add email address Добавить адрес электронной почты - Unset this email as preferred Убрать отметку "предпочтительный" с этого адреса - Set this email as preferred Отметить этот адрес как "предпочтительный" - Remove selected email addresses Удалить выбранные адреса - Copy selected emails to clipboard Скопировать выбранные адреса в буфер обмена - Add phone number Добавить номер телефона - Unset this phone as preferred Убрать отметку "предпочтительный" с этого номера - Set this phone as preferred Отметить этот номер как "предпочтительный" - Remove selected phone numbers Удалить выбранные телефонные номера - Copy selected phones to clipboard Скопировать выбранные телефонные номера в буфер обмена diff --git a/ui/models/abstractparticipant.cpp b/ui/models/abstractparticipant.cpp index 53d8b2d..029527d 100644 --- a/ui/models/abstractparticipant.cpp +++ b/ui/models/abstractparticipant.cpp @@ -22,7 +22,7 @@ using namespace Models; Models::AbstractParticipant::AbstractParticipant(Models::Item::Type p_type, const QMap& data, Models::Item* parentItem): Item(p_type, data, parentItem), - availability(Shared::offline), + availability(Shared::Availability::offline), lastActivity(data.value("lastActivity").toDateTime()), status(data.value("status").toString()) { @@ -58,7 +58,7 @@ QVariant Models::AbstractParticipant::data(int column) const case 1: return lastActivity; case 2: - return availability; + return QVariant::fromValue(availability); case 3: return status; default: @@ -91,15 +91,9 @@ void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail) void Models::AbstractParticipant::setAvailability(unsigned int avail) { - if (avail <= Shared::availabilityHighest) { - Shared::Availability state = static_cast(avail); - setAvailability(state); - } else { - qDebug("An attempt to set wrong state to the contact"); - } + setAvailability(Shared::Global::fromInt(avail)); } - void Models::AbstractParticipant::setLastActivity(const QDateTime& p_time) { if (lastActivity != p_time) { diff --git a/ui/models/abstractparticipant.h b/ui/models/abstractparticipant.h index 86d5629..cb20788 100644 --- a/ui/models/abstractparticipant.h +++ b/ui/models/abstractparticipant.h @@ -21,8 +21,12 @@ #include "item.h" -#include "../../global.h" +#include "shared/enums.h" +#include "shared/icons.h" +#include "shared/global.h" + #include +#include namespace Models { diff --git a/ui/models/account.cpp b/ui/models/account.cpp index eeb8731..8d9774e 100644 --- a/ui/models/account.cpp +++ b/ui/models/account.cpp @@ -27,8 +27,8 @@ Models::Account::Account(const QMap& data, Models::Item* pare resource(data.value("resource").toString()), error(data.value("error").toString()), avatarPath(data.value("avatarPath").toString()), - state(Shared::disconnected), - availability(Shared::offline) + state(Shared::ConnectionState::disconnected), + availability(Shared::Availability::offline) { QMap::const_iterator sItr = data.find("state"); if (sItr != data.end()) { @@ -49,7 +49,7 @@ void Models::Account::setState(Shared::ConnectionState p_state) if (state != p_state) { state = p_state; changed(2); - if (state == Shared::disconnected) { + if (state == Shared::ConnectionState::disconnected) { toOfflineState(); } } @@ -57,22 +57,12 @@ void Models::Account::setState(Shared::ConnectionState p_state) void Models::Account::setAvailability(unsigned int p_state) { - if (p_state <= Shared::availabilityHighest) { - Shared::Availability state = static_cast(p_state); - setAvailability(state); - } else { - qDebug() << "An attempt to set invalid availability " << p_state << " to the account " << name; - } + setAvailability(Shared::Global::fromInt(p_state)); } void Models::Account::setState(unsigned int p_state) { - if (p_state <= Shared::subscriptionStateHighest) { - Shared::ConnectionState state = static_cast(p_state); - setState(state); - } else { - qDebug() << "An attempt to set invalid subscription state " << p_state << " to the account " << name; - } + setState(Shared::Global::fromInt(p_state)); } Shared::Availability Models::Account::getAvailability() const @@ -90,10 +80,10 @@ void Models::Account::setAvailability(Shared::Availability p_avail) QIcon Models::Account::getStatusIcon(bool big) const { - if (state == Shared::connected) { + if (state == Shared::ConnectionState::connected) { return Shared::availabilityIcon(availability, big); - } else if (state == Shared::disconnected) { - return Shared::availabilityIcon(Shared::offline, big); + } else if (state == Shared::ConnectionState::disconnected) { + return Shared::availabilityIcon(Shared::Availability::offline, big); } else { return Shared::connectionStateIcon(state); } @@ -152,7 +142,7 @@ QVariant Models::Account::data(int column) const case 1: return server; case 2: - return QCoreApplication::translate("Global", Shared::connectionStateNames[state].toLatin1()); + return Shared::Global::getName(state); case 3: return error; case 4: @@ -160,7 +150,7 @@ QVariant Models::Account::data(int column) const case 5: return password; case 6: - return QCoreApplication::translate("Global", Shared::availabilityNames[availability].toLatin1()); + return Shared::Global::getName(availability); case 7: return resource; case 8: @@ -226,7 +216,7 @@ void Models::Account::setError(const QString& p_resource) void Models::Account::toOfflineState() { - setAvailability(Shared::offline); + setAvailability(Shared::Availability::offline); Item::toOfflineState(); } diff --git a/ui/models/account.h b/ui/models/account.h index e114699..428b049 100644 --- a/ui/models/account.h +++ b/ui/models/account.h @@ -19,7 +19,10 @@ #ifndef MODELS_ACCOUNT_H #define MODELS_ACCOUNT_H -#include "../../global.h" +#include "shared/enums.h" +#include "shared/utils.h" +#include "shared/icons.h" +#include "shared/global.h" #include "item.h" #include #include diff --git a/ui/models/accounts.cpp b/ui/models/accounts.cpp index 79ed159..f5ffce8 100644 --- a/ui/models/accounts.cpp +++ b/ui/models/accounts.cpp @@ -17,7 +17,7 @@ */ #include "accounts.h" -#include "../../global.h" +#include "shared/icons.h" #include #include diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index b968ce4..9cd011a 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -23,8 +23,8 @@ Models::Contact::Contact(const QString& p_jid ,const QMap &data, Item *parentItem): Item(Item::contact, data, parentItem), jid(p_jid), - availability(Shared::offline), - state(Shared::none), + availability(Shared::Availability::offline), + state(Shared::SubscriptionState::none), avatarState(Shared::Avatar::empty), presences(), messages(), @@ -66,22 +66,12 @@ void Models::Contact::setJid(const QString p_jid) void Models::Contact::setAvailability(unsigned int p_state) { - if (p_state <= Shared::availabilityHighest) { - Shared::Availability state = static_cast(p_state); - setAvailability(state); - } else { - qDebug() << "An attempt to set invalid availability " << p_state << " to the contact " << jid; - } + setAvailability(Shared::Global::fromInt(p_state)); } void Models::Contact::setState(unsigned int p_state) { - if (p_state <= Shared::subscriptionStateHighest) { - Shared::SubscriptionState state = static_cast(p_state); - setState(state); - } else { - qDebug() << "An attempt to set invalid subscription state " << p_state << " to the contact " << jid; - } + setState(Shared::Global::fromInt(p_state)); } Shared::Availability Models::Contact::getAvailability() const @@ -123,15 +113,15 @@ QVariant Models::Contact::data(int column) const case 1: return jid; case 2: - return state; + return QVariant::fromValue(state); case 3: - return availability; + return QVariant::fromValue(availability); case 4: return getMessagesCount(); case 5: return getStatus(); case 6: - return static_cast(getAvatarState()); + return QVariant::fromValue(getAvatarState()); case 7: return getAvatarPath(); default: @@ -216,7 +206,7 @@ void Models::Contact::refresh() setAvailability(presence->getAvailability()); setStatus(presence->getStatus()); } else { - setAvailability(Shared::offline); + setAvailability(Shared::Availability::offline); setStatus(""); } @@ -258,7 +248,7 @@ QIcon Models::Contact::getStatusIcon(bool big) const { if (getMessagesCount() > 0) { return Shared::icon("mail-message", big); - } else if (state == Shared::both || state == Shared::to) { + } else if (state == Shared::SubscriptionState::both || state == Shared::SubscriptionState::to) { return Shared::availabilityIcon(availability, big);; } else { return Shared::subscriptionStateIcon(state, big); @@ -276,7 +266,7 @@ void Models::Contact::addMessage(const Shared::Message& data) // the only issue is to find out when the sender is gone offline Presence* pr = new Presence({}); pr->setName(res); - pr->setAvailability(Shared::invisible); + pr->setAvailability(Shared::Availability::invisible); pr->setLastActivity(QDateTime::currentDateTimeUtc()); presences.insert(res, pr); appendChild(pr); diff --git a/ui/models/contact.h b/ui/models/contact.h index cffc53c..eb2be6b 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -21,7 +21,11 @@ #include "item.h" #include "presence.h" -#include "global.h" +#include "shared/enums.h" +#include "shared/message.h" +#include "shared/icons.h" +#include "shared/global.h" + #include #include #include diff --git a/ui/models/group.cpp b/ui/models/group.cpp index 5e4411e..76dc03e 100644 --- a/ui/models/group.cpp +++ b/ui/models/group.cpp @@ -96,7 +96,7 @@ unsigned int Models::Group::getOnlineContacts() const for (std::deque::const_iterator itr = childItems.begin(), end = childItems.end(); itr != end; ++itr) { Models::Contact* cnt = static_cast(*itr); - if (cnt->getAvailability() != Shared::offline) { + if (cnt->getAvailability() != Shared::Availability::offline) { ++amount; } } diff --git a/ui/models/item.cpp b/ui/models/item.cpp index f90f5e6..1d0437f 100644 --- a/ui/models/item.cpp +++ b/ui/models/item.cpp @@ -238,7 +238,7 @@ Shared::Availability Models::Item::getAccountAvailability() const { const Account* acc = static_cast(getParentAccount()); if (acc == 0) { - return Shared::offline; + return Shared::Availability::offline; } return acc->getAvailability(); } @@ -247,7 +247,7 @@ Shared::ConnectionState Models::Item::getAccountConnectionState() const { const Account* acc = static_cast(getParentAccount()); if (acc == 0) { - return Shared::disconnected; + return Shared::ConnectionState::disconnected; } return acc->getState(); } diff --git a/ui/models/item.h b/ui/models/item.h index 20f6f89..a936e34 100644 --- a/ui/models/item.h +++ b/ui/models/item.h @@ -25,7 +25,7 @@ #include -#include "../../global.h" +#include "shared/enums.h" namespace Models { diff --git a/ui/models/presence.cpp b/ui/models/presence.cpp index bf2ef12..bf931e9 100644 --- a/ui/models/presence.cpp +++ b/ui/models/presence.cpp @@ -17,6 +17,7 @@ */ #include "presence.h" +#include "shared/icons.h" Models::Presence::Presence(const QMap& data, Item* parentItem): AbstractParticipant(Item::presence, data, parentItem), diff --git a/ui/models/presence.h b/ui/models/presence.h index 5073e7a..fc430f0 100644 --- a/ui/models/presence.h +++ b/ui/models/presence.h @@ -20,7 +20,9 @@ #define MODELS_PRESENCE_H #include "abstractparticipant.h" -#include "../../global.h" +#include "shared/enums.h" +#include "shared/message.h" + #include #include diff --git a/ui/models/room.cpp b/ui/models/room.cpp index afcf8e9..be92d41 100644 --- a/ui/models/room.cpp +++ b/ui/models/room.cpp @@ -17,6 +17,8 @@ */ #include "room.h" +#include "shared/icons.h" + #include #include @@ -194,15 +196,15 @@ QIcon Models::Room::getStatusIcon(bool big) const } else { if (autoJoin) { if (joined) { - return Shared::connectionStateIcon(Shared::connected, big); + return Shared::connectionStateIcon(Shared::ConnectionState::connected, big); } else { - return Shared::connectionStateIcon(Shared::disconnected, big); + return Shared::connectionStateIcon(Shared::ConnectionState::disconnected, big); } } else { if (joined) { - return Shared::connectionStateIcon(Shared::connecting, big); + return Shared::connectionStateIcon(Shared::ConnectionState::connecting, big); } else { - return Shared::connectionStateIcon(Shared::error, big); + return Shared::connectionStateIcon(Shared::ConnectionState::error, big); } } } diff --git a/ui/models/room.h b/ui/models/room.h index 6a87a83..382b6e9 100644 --- a/ui/models/room.h +++ b/ui/models/room.h @@ -21,7 +21,8 @@ #include "item.h" #include "participant.h" -#include "global.h" +#include "shared/enums.h" +#include "shared/message.h" namespace Models { diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index 23e39af..609715f 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -181,7 +181,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const switch (item->type) { case Item::account: { Account* acc = static_cast(item); - result = QCoreApplication::translate("Global", Shared::availabilityNames[acc->getAvailability()].toLatin1()); + result = Shared::Global::getName(acc->getAvailability()); } break; case Item::contact: { @@ -193,18 +193,18 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const } str += tr("Jabber ID: ") + contact->getJid() + "\n"; Shared::SubscriptionState ss = contact->getState(); - if (ss == Shared::both || ss == Shared::to) { + if (ss == Shared::SubscriptionState::both || ss == Shared::SubscriptionState::to) { Shared::Availability av = contact->getAvailability(); - str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1()); - if (av != Shared::offline) { + str += tr("Availability: ") + Shared::Global::getName(av); + if (av != Shared::Availability::offline) { QString s = contact->getStatus(); if (s.size() > 0) { str += "\n" + tr("Status: ") + s; } } - str += "\n" + tr("Subscription: ") + QCoreApplication::translate("Global", Shared::subscriptionStateNames[ss].toLatin1()); + str += "\n" + tr("Subscription: ") + Shared::Global::getName(ss); } else { - str += tr("Subscription: ") + QCoreApplication::translate("Global", Shared::subscriptionStateNames[ss].toLatin1()); + str += tr("Subscription: ") + Shared::Global::getName(ss); } result = str; @@ -218,7 +218,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const str += tr("New messages: ") + std::to_string(mc).c_str() + "\n"; } Shared::Availability av = contact->getAvailability(); - str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1()); + str += tr("Availability: ") + Shared::Global::getName(av); QString s = contact->getStatus(); if (s.size() > 0) { str += "\n" + tr("Status: ") + s; @@ -231,18 +231,14 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const Participant* p = static_cast(item); QString str(""); Shared::Availability av = p->getAvailability(); - str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1()) + "\n"; + str += tr("Availability: ") + Shared::Global::getName(av) + "\n"; QString s = p->getStatus(); if (s.size() > 0) { str += tr("Status: ") + s + "\n"; } - str += tr("Affiliation: ") + - QCoreApplication::translate("Global", - Shared::affiliationNames[static_cast(p->getAffiliation())].toLatin1()) + "\n"; - str += tr("Role: ") + - QCoreApplication::translate("Global", - Shared::roleNames[static_cast(p->getRole())].toLatin1()); + str += tr("Affiliation: ") + Shared::Global::getName(p->getAffiliation()) + "\n"; + str += tr("Role: ") + Shared::Global::getName(p->getRole()); result = str; } diff --git a/ui/models/roster.h b/ui/models/roster.h index dde6370..50c6532 100644 --- a/ui/models/roster.h +++ b/ui/models/roster.h @@ -24,7 +24,8 @@ #include #include -#include "global.h" +#include "shared/message.h" +#include "shared/global.h" #include "accounts.h" #include "item.h" #include "account.h" diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 601e999..ad002c3 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -41,11 +41,11 @@ Squawk::Squawk(QWidget *parent) : m_ui->roster->header()->setStretchLastSection(false); m_ui->roster->header()->setSectionResizeMode(0, QHeaderView::Stretch); - for (unsigned int i = Shared::availabilityLowest; i < Shared::availabilityHighest + 1; ++i) { + for (int i = static_cast(Shared::availabilityLowest); i < static_cast(Shared::availabilityHighest) + 1; ++i) { Shared::Availability av = static_cast(i); - m_ui->comboBox->addItem(Shared::availabilityIcon(av), QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1())); + m_ui->comboBox->addItem(Shared::availabilityIcon(av), Shared::Global::getName(av)); } - m_ui->comboBox->setCurrentIndex(Shared::offline); + m_ui->comboBox->setCurrentIndex(static_cast(Shared::Availability::offline)); connect(m_ui->actionAccounts, &QAction::triggered, this, &Squawk::onAccounts); connect(m_ui->actionAddContact, &QAction::triggered, this, &Squawk::onNewContact); @@ -173,25 +173,26 @@ void Squawk::newAccount(const QMap& account) void Squawk::onComboboxActivated(int index) { - if (index != Shared::offline) { + Shared::Availability av = Shared::Global::fromInt(index); + if (av != Shared::Availability::offline) { int size = rosterModel.accountsModel->rowCount(QModelIndex()); if (size > 0) { - emit changeState(index); + emit changeState(av); for (int i = 0; i < size; ++i) { Models::Account* acc = rosterModel.accountsModel->getAccount(i); - if (acc->getState() == Shared::disconnected) { + if (acc->getState() == Shared::ConnectionState::disconnected) { emit connectAccount(acc->getName()); } } } else { - m_ui->comboBox->setCurrentIndex(Shared::offline); + m_ui->comboBox->setCurrentIndex(static_cast(Shared::Availability::offline)); } } else { - emit changeState(index); + emit changeState(av); int size = rosterModel.accountsModel->rowCount(QModelIndex()); for (int i = 0; i != size; ++i) { Models::Account* acc = rosterModel.accountsModel->getAccount(i); - if (acc->getState() != Shared::disconnected) { + if (acc->getState() != Shared::ConnectionState::disconnected) { emit disconnectAccount(acc->getName()); } } @@ -273,9 +274,9 @@ void Squawk::removePresence(const QString& account, const QString& jid, const QS rosterModel.removePresence(account, jid, name); } -void Squawk::stateChanged(int state) +void Squawk::stateChanged(Shared::Availability state) { - m_ui->comboBox->setCurrentIndex(state); + m_ui->comboBox->setCurrentIndex(static_cast(state)); } void Squawk::onRosterItemDoubleClicked(const QModelIndex& item) @@ -600,14 +601,14 @@ void Squawk::onRosterContextMenu(const QPoint& point) contextMenu->clear(); bool hasMenu = false; - bool active = item->getAccountConnectionState() == Shared::connected; + bool active = item->getAccountConnectionState() == Shared::ConnectionState::connected; switch (item->type) { case Models::Item::account: { Models::Account* acc = static_cast(item); hasMenu = true; QString name = acc->getName(); - if (acc->getState() != Shared::disconnected) { + if (acc->getState() != Shared::ConnectionState::disconnected) { QAction* con = contextMenu->addAction(Shared::icon("network-disconnect"), tr("Disconnect")); con->setEnabled(active); connect(con, &QAction::triggered, [this, name]() { @@ -644,8 +645,8 @@ void Squawk::onRosterContextMenu(const QPoint& point) Shared::SubscriptionState state = cnt->getState(); switch (state) { - case Shared::both: - case Shared::to: { + case Shared::SubscriptionState::both: + case Shared::SubscriptionState::to: { QAction* unsub = contextMenu->addAction(Shared::icon("news-unsubscribe"), tr("Unsubscribe")); unsub->setEnabled(active); connect(unsub, &QAction::triggered, [this, cnt]() { @@ -653,9 +654,9 @@ void Squawk::onRosterContextMenu(const QPoint& point) }); } break; - case Shared::from: - case Shared::unknown: - case Shared::none: { + case Shared::SubscriptionState::from: + case Shared::SubscriptionState::unknown: + case Shared::SubscriptionState::none: { QAction* sub = contextMenu->addAction(Shared::icon("news-subscribe"), tr("Subscribe")); sub->setEnabled(active); connect(sub, &QAction::triggered, [this, cnt]() { @@ -882,7 +883,7 @@ void Squawk::readSettings() if (settings.contains("availability")) { int avail = settings.value("availability").toInt(); m_ui->comboBox->setCurrentIndex(avail); - emit stateChanged(avail); + emit stateChanged(Shared::Global::fromInt(avail)); int size = settings.beginReadArray("connectedAccounts"); for (int i = 0; i < size; ++i) { @@ -909,7 +910,7 @@ void Squawk::writeSettings() int size = rosterModel.accountsModel->rowCount(QModelIndex()); for (int i = 0; i < size; ++i) { Models::Account* acc = rosterModel.accountsModel->getAccount(i); - if (acc->getState() != Shared::disconnected) { + if (acc->getState() != Shared::ConnectionState::disconnected) { settings.setArrayIndex(i); settings.setValue("name", acc->getName()); } diff --git a/ui/squawk.h b/ui/squawk.h index a3fbcba..adfff1d 100644 --- a/ui/squawk.h +++ b/ui/squawk.h @@ -38,7 +38,7 @@ #include "models/roster.h" #include "widgets/vcard/vcard.h" -#include "global.h" +#include "shared.h" namespace Ui { class Squawk; @@ -61,7 +61,7 @@ signals: void removeAccountRequest(const QString&); void connectAccount(const QString&); void disconnectAccount(const QString&); - void changeState(int state); + void changeState(Shared::Availability state); void sendMessage(const QString& account, const Shared::Message& data); void sendMessage(const QString& account, const Shared::Message& data, const QString& path); void requestArchive(const QString& account, const QString& jid, int count, const QString& before); @@ -93,7 +93,7 @@ public slots: void changeContact(const QString& account, const QString& jid, const QMap& data); void addPresence(const QString& account, const QString& jid, const QString& name, const QMap& data); void removePresence(const QString& account, const QString& jid, const QString& name); - void stateChanged(int state); + void stateChanged(Shared::Availability state); void accountMessage(const QString& account, const Shared::Message& data); void responseArchive(const QString& account, const QString& jid, const std::list& list); void addRoom(const QString& account, const QString jid, const QMap& data); diff --git a/ui/utils/message.cpp b/ui/utils/message.cpp index eb69ca0..c5149ef 100644 --- a/ui/utils/message.cpp +++ b/ui/utils/message.cpp @@ -16,12 +16,12 @@ * along with this program. If not, see . */ +#include "message.h" #include #include #include #include #include -#include "message.h" const QRegularExpression urlReg("(?(state)])); - QString tt = QCoreApplication::translate("Global", Shared::messageStateNames[static_cast(state)].toLatin1()); + QString tt = Shared::Global::getName(state); if (state == Shared::Message::State::error) { QString errText = msg.getErrorText(); if (errText.size() > 0) { diff --git a/ui/utils/message.h b/ui/utils/message.h index a885d5b..fc3f178 100644 --- a/ui/utils/message.h +++ b/ui/utils/message.h @@ -31,7 +31,9 @@ #include #include -#include "global.h" +#include "shared/message.h" +#include "shared/icons.h" +#include "shared/global.h" #include "resizer.h" #include "image.h" diff --git a/ui/utils/messageline.cpp b/ui/utils/messageline.cpp index 2077863..deb9a45 100644 --- a/ui/utils/messageline.cpp +++ b/ui/utils/messageline.cpp @@ -18,6 +18,7 @@ #include "messageline.h" #include +#include #include MessageLine::MessageLine(bool p_room, QWidget* parent): diff --git a/ui/utils/messageline.h b/ui/utils/messageline.h index 16eea21..277d429 100644 --- a/ui/utils/messageline.h +++ b/ui/utils/messageline.h @@ -26,7 +26,7 @@ #include #include -#include "global.h" +#include "shared/message.h" #include "message.h" #include "progress.h" diff --git a/ui/utils/progress.cpp b/ui/utils/progress.cpp index a028822..73e4d02 100644 --- a/ui/utils/progress.cpp +++ b/ui/utils/progress.cpp @@ -18,6 +18,8 @@ #include "progress.h" +#include "shared/icons.h" + Progress::Progress(quint16 p_size, QWidget* parent): QWidget(parent), pixmap(new QGraphicsPixmapItem(Shared::icon("view-refresh", true).pixmap(p_size))), diff --git a/ui/utils/progress.h b/ui/utils/progress.h index c6501aa..bbfef40 100644 --- a/ui/utils/progress.h +++ b/ui/utils/progress.h @@ -27,8 +27,6 @@ #include #include -#include "../../global.h" - /** * @todo write docs */ diff --git a/ui/widgets/accounts.cpp b/ui/widgets/accounts.cpp index 62e9ed3..e6c3da1 100644 --- a/ui/widgets/accounts.cpp +++ b/ui/widgets/accounts.cpp @@ -115,7 +115,7 @@ void Accounts::updateConnectButton() 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; + allConnected = mAcc->getState() == Shared::ConnectionState::connected; } if (allConnected) { toDisconnect = true; diff --git a/ui/widgets/chat.cpp b/ui/widgets/chat.cpp index 41c79be..c9a41ad 100644 --- a/ui/widgets/chat.cpp +++ b/ui/widgets/chat.cpp @@ -58,7 +58,7 @@ void Chat::updateState() { Shared::Availability av = contact->getAvailability(); statusIcon->setPixmap(Shared::availabilityIcon(av, true).pixmap(40)); - statusIcon->setToolTip(QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1())); + statusIcon->setToolTip(Shared::Global::getName(av)); } void Chat::handleSendMessage(const QString& text) diff --git a/ui/widgets/chat.h b/ui/widgets/chat.h index 5c0eb63..66ac53a 100644 --- a/ui/widgets/chat.h +++ b/ui/widgets/chat.h @@ -20,7 +20,9 @@ #define CHAT_H #include "conversation.h" -#include "../models/contact.h" +#include "ui/models/contact.h" +#include "shared/icons.h" +#include "shared/global.h" namespace Ui { diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 952973d..13cb881 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -19,6 +19,7 @@ #include "conversation.h" #include "ui_conversation.h" #include "ui/utils/dropshadoweffect.h" +#include "shared/icons.h" #include #include @@ -27,6 +28,7 @@ #include #include #include +#include Conversation::Conversation(bool muc, Models::Account* acc, const QString pJid, const QString pRes, QWidget* parent): QWidget(parent), diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index 64d7341..6ce8cad 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -23,7 +23,7 @@ #include #include -#include "global.h" +#include "shared/message.h" #include "order.h" #include "ui/models/account.h" #include "ui/utils/messageline.h" diff --git a/ui/widgets/vcard/emailsmodel.cpp b/ui/widgets/vcard/emailsmodel.cpp index 9723672..994fcc3 100644 --- a/ui/widgets/vcard/emailsmodel.cpp +++ b/ui/widgets/vcard/emailsmodel.cpp @@ -18,6 +18,9 @@ #include "emailsmodel.h" +#include "shared/icons.h" +#include + UI::VCard::EMailsModel::EMailsModel(bool p_edit, QObject* parent): QAbstractTableModel(parent), edit(p_edit), diff --git a/ui/widgets/vcard/emailsmodel.h b/ui/widgets/vcard/emailsmodel.h index 3ee3a02..bafbe9f 100644 --- a/ui/widgets/vcard/emailsmodel.h +++ b/ui/widgets/vcard/emailsmodel.h @@ -24,7 +24,7 @@ #include -#include "global.h" +#include "shared/vcard.h" namespace UI { namespace VCard { diff --git a/ui/widgets/vcard/phonesmodel.cpp b/ui/widgets/vcard/phonesmodel.cpp index ee0ff75..d3cace8 100644 --- a/ui/widgets/vcard/phonesmodel.cpp +++ b/ui/widgets/vcard/phonesmodel.cpp @@ -18,6 +18,9 @@ #include "phonesmodel.h" +#include "shared/icons.h" +#include + UI::VCard::PhonesModel::PhonesModel(bool p_edit, QObject* parent): QAbstractTableModel(parent), edit(p_edit), diff --git a/ui/widgets/vcard/phonesmodel.h b/ui/widgets/vcard/phonesmodel.h index f799f82..32d08b6 100644 --- a/ui/widgets/vcard/phonesmodel.h +++ b/ui/widgets/vcard/phonesmodel.h @@ -22,7 +22,7 @@ #include #include -#include "global.h" +#include "shared/vcard.h" namespace UI { namespace VCard { diff --git a/ui/widgets/vcard/vcard.cpp b/ui/widgets/vcard/vcard.cpp index 44b5aa3..e3aa1b9 100644 --- a/ui/widgets/vcard/vcard.cpp +++ b/ui/widgets/vcard/vcard.cpp @@ -18,7 +18,7 @@ #include "vcard.h" #include "ui_vcard.h" - +#include "shared/icons.h" #include #include diff --git a/ui/widgets/vcard/vcard.h b/ui/widgets/vcard/vcard.h index 8346fc3..4d579e1 100644 --- a/ui/widgets/vcard/vcard.h +++ b/ui/widgets/vcard/vcard.h @@ -36,7 +36,7 @@ #include -#include "global.h" +#include "shared/vcard.h" #include "emailsmodel.h" #include "phonesmodel.h" #include "ui/utils/progress.h"