diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index d3327c9..b971a88 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -3,22 +3,30 @@ if(WIN32) set(SIGNALCATCHER_SOURCE signalcatcher_win32.cpp) endif(WIN32) +set(SOURCE_FILES + account.cpp + adapterfunctions.cpp + conference.cpp + contact.cpp + rosteritem.cpp + ${SIGNALCATCHER_SOURCE} + squawk.cpp +) + +set(HEADER_FILES + account.h + adapterfunctions.h + conference.h + contact.h + rosteritem.h + signalcatcher.h + squawk.h +) + target_sources(squawk PRIVATE - account.cpp - account.h - adapterfunctions.cpp - adapterfunctions.h - conference.cpp - conference.h - contact.cpp - contact.h - rosteritem.cpp - rosteritem.h - ${SIGNALCATCHER_SOURCE} - signalcatcher.h - squawk.cpp - squawk.h - ) + ${SOURCE_FILES} + ${HEADER_FILES} +) target_include_directories(squawk PRIVATE ${LMDB_INCLUDE_DIRS}) diff --git a/core/components/CMakeLists.txt b/core/components/CMakeLists.txt index 5faf837..0e26037 100644 --- a/core/components/CMakeLists.txt +++ b/core/components/CMakeLists.txt @@ -1,6 +1,16 @@ -target_sources(squawk PRIVATE - networkaccess.cpp - networkaccess.h - clientcache.cpp - clientcache.h +set(SOURCE_FILES + networkaccess.cpp + clientcache.cpp + delaymanager.cpp +) + +set(HEADER_FILES + networkaccess.h + clientcache.h + delaymanager.h +) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${HEADER_FILES} ) diff --git a/core/components/delaymanager.cpp b/core/components/delaymanager.cpp new file mode 100644 index 0000000..627eab8 --- /dev/null +++ b/core/components/delaymanager.cpp @@ -0,0 +1,136 @@ +// 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 "delaymanager.h" + +Core::DelayManager::DelayManager(uint16_t mpj, QObject* parent) : + QObject(parent), + maxParallelJobs(mpj), + nextJobId(0), + scheduledJobs(), + runningJobs(), + pendingVCards(), + requestedVCards() +{ +} + +Core::DelayManager::~DelayManager() {} + +void Core::DelayManager::requestInfo(const QString& jid) { + bool needToRequest = false; + std::pair::const_iterator, bool> result = pendingVCards.insert(jid); + if (result.second) { //if there is a clear evidence that we have not alredy been asked to request a VCard - just request it + needToRequest = true; + } else { + std::map::const_iterator itr = requestedVCards.find(jid); + if (itr != requestedVCards.end()) { //first check if the card is already requested, and if it is make sure we reply to user after we receive it + runningJobs[itr->second].first = TaskType::infoForUser; + } else { + needToRequest = true; + for (Job& job : scheduledJobs) { //looks like we need to manually check all the scheduled job and find the one with that jid there + if (job.first == TaskType::cardInternal || job.first == TaskType::infoForUser) { //to make sure we reply to user after we receive it + QString* jobJid = static_cast(job.second); + if (*jobJid == jid) { + needToRequest = false; + job.first = TaskType::infoForUser; + break; + } + } + } + if (needToRequest) { + throw 8573; //something went terribly wrong here, the state is not correct; + } + } + } + + if (needToRequest) + scheduleJob(TaskType::infoForUser, new QString(jid)); +} + +void Core::DelayManager::requestVCard(const QString& jid) { + std::pair::const_iterator, bool> result = pendingVCards.insert(jid); + if (result.second) + scheduleJob(TaskType::cardInternal, new QString(jid)); +} + +void Core::DelayManager::scheduleJob(Core::DelayManager::TaskType type, void* data) { + if (runningJobs.size() < maxParallelJobs) { + uint16_t currentJobId = nextJobId++; + runningJobs.emplace(currentJobId, std::make_pair(type, data)); + switch (type) { + case TaskType::cardInternal: + case TaskType::infoForUser: { + QString* jid = static_cast(data); + requestedVCards.emplace(*jid, currentJobId); + emit requestVCard(*jid); + } + break; + } + } else { + scheduledJobs.emplace_back(type, data); + } +} + +void Core::DelayManager::executeJob(Core::DelayManager::Job job) { + uint16_t currentJobId = nextJobId++; + runningJobs.emplace(currentJobId, job); + switch (job.first) { + case TaskType::cardInternal: + case TaskType::infoForUser: { + QString* jid = static_cast(job.second); + requestedVCards.emplace(*jid, currentJobId); + emit requestVCard(*jid); + } + break; + } +} + + +void Core::DelayManager::jobIsDone(uint16_t jobId) { + std::map::const_iterator itr = runningJobs.find(jobId); + if (itr == runningJobs.end()) { + throw 8574; //not supposed to happen, never + } + runningJobs.erase(itr); + if (scheduledJobs.size() > 0) { + Job job = scheduledJobs.front(); + scheduledJobs.pop_front(); + executeJob(job); + } +} + + +void Core::DelayManager::receivedVCard(const QString& jid, const Shared::VCard& card) { + std::map::const_iterator cardItr = requestedVCards.find(jid); + if (cardItr == requestedVCards.end()) { + throw 8575; //never supposed to happen, the state is not correct; + } else { + uint16_t jobId = cardItr->second; + requestedVCards.erase(cardItr); + pendingVCards.erase(jid); + const Job& job = runningJobs[jobId]; + switch (job.first) { + case TaskType::cardInternal: + jobIsDone(jobId); + break; + case TaskType::infoForUser: + //all that stuff with further requesting + break; + default: + throw 8576; + } + } +} diff --git a/core/components/delaymanager.h b/core/components/delaymanager.h new file mode 100644 index 0000000..f34b00e --- /dev/null +++ b/core/components/delaymanager.h @@ -0,0 +1,71 @@ +// 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 CORE_DELAYMANAGER_H +#define CORE_DELAYMANAGER_H + +#include +#include + +#include +#include + +#include +#include + +namespace Core { + +class DelayManager : public QObject +{ + Q_OBJECT + + enum class TaskType { + cardInternal, + infoForUser + } +public: + DelayManager(uint16_t maxParallelJobs = 5, QObject* parent = nullptr); + ~DelayManager(); + + void requestVCard(const QString& jid); + void requestInfo(const QString& jid); + +signals: + void requestVCard(const QString& jid); + +public slots: + void receivedVCard(const QString& jid, const Shared::VCard& card); + +private: + typedef std::pair Job; + + void scheduleJob(TaskType type, void* data); + void executeJob(Job job); + void jobIsDone(uint16_t jobId); + +private: + uint16_t maxParallelJobs; + uint16_t nextJobId; + std::list scheduledJobs; + std::map runningJobs; + + std::set pendingVCards; + std::map requestedVCards; +}; + +} + +#endif // CORE_DELAYMANAGER_H diff --git a/core/handlers/CMakeLists.txt b/core/handlers/CMakeLists.txt index 746a36f..11a902d 100644 --- a/core/handlers/CMakeLists.txt +++ b/core/handlers/CMakeLists.txt @@ -1,14 +1,22 @@ -target_sources(squawk PRIVATE +set(SOURCE_FILES messagehandler.cpp - messagehandler.h rosterhandler.cpp - rosterhandler.h vcardhandler.cpp - vcardhandler.h discoveryhandler.cpp - discoveryhandler.h omemohandler.cpp - omemohandler.h trusthandler.cpp +) + +set(HEADER_FILES + messagehandler.h + rosterhandler.h + vcardhandler.h + discoveryhandler.h + omemohandler.h trusthandler.h - ) +) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${HEADER_FILES} +) diff --git a/core/passwordStorageEngines/CMakeLists.txt b/core/passwordStorageEngines/CMakeLists.txt index 4da3873..2afda3f 100644 --- a/core/passwordStorageEngines/CMakeLists.txt +++ b/core/passwordStorageEngines/CMakeLists.txt @@ -2,7 +2,7 @@ if (WITH_KWALLET) target_sources(squawk PRIVATE kwallet.cpp kwallet.h - ) + ) add_subdirectory(wrappers) target_include_directories(squawk PRIVATE $) diff --git a/ui/widgets/info/omemo/CMakeLists.txt b/ui/widgets/info/omemo/CMakeLists.txt index f1dc4ed..4c76900 100644 --- a/ui/widgets/info/omemo/CMakeLists.txt +++ b/ui/widgets/info/omemo/CMakeLists.txt @@ -1,7 +1,19 @@ -target_sources(squawk PRIVATE +set(SOURCE_FILES omemo.cpp - omemo.h - omemo.ui keydelegate.cpp +) + +set(UI_FILES + omemo.ui +) + +set(HEADER_FILES + omemo.h keydelegate.h ) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${UI_FILES} + ${HEADER_FILES} +)