From 00af58228724e2cfb39467f887ad9220de6cfedd Mon Sep 17 00:00:00 2001 From: blue Date: Mon, 13 Nov 2023 19:05:26 -0300 Subject: [PATCH] Own omemo key display, a bit of CMake clean up --- CMakeLists.txt | 73 +++++++-------- core/delayManager/manager.cpp | 70 +++++++------- core/handlers/messagehandler.cpp | 5 +- core/handlers/messagehandler.h | 13 +-- core/handlers/omemohandler.cpp | 83 +++++++++-------- core/handlers/omemohandler.h | 1 + shared/keyinfo.h | 40 ++++---- ui/utils/expandinglist.cpp | 81 +++++++++------- ui/utils/expandinglist.h | 48 +++++----- ui/widgets/info/info.cpp | 32 ++++--- ui/widgets/info/info.h | 37 ++++---- ui/widgets/info/omemo/keydelegate.cpp | 32 ++++--- ui/widgets/info/omemo/keydelegate.h | 46 ++++----- ui/widgets/info/omemo/omemo.cpp | 71 +++++++++----- ui/widgets/info/omemo/omemo.h | 43 +++++---- ui/widgets/info/omemo/omemo.ui | 128 +++++++++++++++++--------- 16 files changed, 443 insertions(+), 360 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 280fb22..edf9297 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ find_package(Boost COMPONENTS) target_include_directories(squawk PRIVATE ${Boost_INCLUDE_DIRS}) -#OMEMO +## OMEMO if (WITH_OMEMO) find_package(PkgConfig) if (PKG_CONFIG_FOUND) @@ -65,22 +65,6 @@ if (WITH_OMEMO) endif () endif () -## QXmpp -if (SYSTEM_QXMPP) - if (WITH_OMEMO) - find_package(QXmpp CONFIG COMPONENTS Omemo) - else () - find_package(QXmpp CONFIG) - endif () - - if (NOT QXmpp_FOUND) - set(SYSTEM_QXMPP OFF) - message("QXmpp package wasn't found, trying to build with bundled QXmpp") - else () - message("Building with system QXmpp") - endif () -endif () - ## KIO if (WITH_KIO) find_package(KF5KIO CONFIG) @@ -107,6 +91,7 @@ if (WITH_KWALLET) endif () endif () +## KConfig if (WITH_KCONFIG) find_package(KF5Config CONFIG) if (NOT KF5Config_FOUND) @@ -125,7 +110,22 @@ if (WITH_KCONFIG) endif() endif() -if (NOT SYSTEM_QXMPP) +## QXmpp +if (SYSTEM_QXMPP) + if (WITH_OMEMO) + find_package(QXmpp CONFIG COMPONENTS Omemo) + else () + find_package(QXmpp CONFIG) + endif () + + if (NOT QXmpp_FOUND) + set(SYSTEM_QXMPP OFF) + message("QXmpp package wasn't found, trying to build with bundled QXmpp") + else () + message("Building with system QXmpp") + endif () +endif () #it's endif() + if() and not else() because I want it to have a fallback behaviour +if (NOT SYSTEM_QXMPP) #we can fail finding system QXmpp and this way we'll check bundled before failing completely message("Building with bundled QXmpp") target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/base) @@ -141,19 +141,10 @@ if (NOT SYSTEM_QXMPP) set(BUILD_OMEMO OFF) endif () add_subdirectory(external/qxmpp) - + add_library(QXmpp::QXmpp ALIAS QXmppQt${QT_VERSION_MAJOR}) if (WITH_OMEMO) target_include_directories(QXmppOmemoQt${QT_VERSION_MAJOR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src) - endif() - - target_link_libraries(squawk PRIVATE QXmppQt${QT_VERSION_MAJOR}) - if (WITH_OMEMO) - target_link_libraries(squawk PRIVATE QXmppOmemoQt${QT_VERSION_MAJOR}) - endif () -else () - target_link_libraries(squawk PRIVATE QXmpp::QXmpp) - if (WITH_OMEMO) - target_link_libraries(squawk PRIVATE QXmpp::Omemo) + add_library(QXmpp::Omemo ALIAS QXmppOmemoQt${QT_VERSION_MAJOR}) endif () endif () @@ -166,18 +157,14 @@ if (SYSTEM_LMDBAL) else () message("Building with system LMDBAL") endif () -endif() - -if (NOT SYSTEM_LMDBAL) +else() message("Building with bundled LMDBAL") set(BUILD_STATIC ON) add_subdirectory(external/lmdbal) add_library(LMDBAL::LMDBAL ALIAS LMDBAL) endif() -target_link_libraries(squawk PRIVATE LMDBAL::LMDBAL) - -# Linking +## Linking target_link_libraries(squawk PRIVATE Qt${QT_VERSION_MAJOR}::Core @@ -186,17 +173,23 @@ target_link_libraries(squawk Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Xml + LMDBAL::LMDBAL + QXmpp::QXmpp + simpleCrypt ) -target_link_libraries(squawk PRIVATE lmdb) -target_link_libraries(squawk PRIVATE simpleCrypt) -# Link thread libraries on Linux + +if (WITH_OMEMO) + target_link_libraries(squawk PRIVATE QXmpp::Omemo) +endif () + +## Link thread libraries on Linux if(UNIX AND NOT APPLE) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(squawk PRIVATE Threads::Threads) endif() -# Build type +## Build type if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif () @@ -228,7 +221,7 @@ add_subdirectory(shared) add_subdirectory(translations) add_subdirectory(ui) -# Install the executable +## Install the executable install(TARGETS squawk DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES README.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk) install(FILES LICENSE.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk) diff --git a/core/delayManager/manager.cpp b/core/delayManager/manager.cpp index 07d6431..de37d47 100644 --- a/core/delayManager/manager.cpp +++ b/core/delayManager/manager.cpp @@ -1,18 +1,20 @@ -// 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 . +/* + * 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 "manager.h" @@ -39,17 +41,14 @@ Core::DelayManager::Manager::Manager(const QString& poj, Job::Id mpj, QObject* p requestedBundles(), #endif ownJid(poj) -{ -} +{} Core::DelayManager::Manager::~Manager() { - for (const std::pair& pair : runningJobs) { + for (const std::pair& pair : runningJobs) delete pair.second; - } - for (Job* job : jobSequence) { + for (Job* job : jobSequence) delete job; - } } Core::DelayManager::Job::Id Core::DelayManager::Manager::getNextJobId() { @@ -151,11 +150,10 @@ void Core::DelayManager::Manager::preScheduleJob(Job* job) { void Core::DelayManager::Manager::scheduleJob(Job* job) { preScheduleJob(job); - if (runningJobs.size() < maxParallelJobs) { + if (runningJobs.size() < maxParallelJobs) executeJob(job); - } else { + else scheduledJobs.push_back(job); - } } void Core::DelayManager::Manager::preExecuteJob(Job* job) { @@ -190,9 +188,9 @@ void Core::DelayManager::Manager::executeJob(Job* job) { void Core::DelayManager::Manager::jobIsDone(Job::Id jobId) { std::map::const_iterator itr = runningJobs.find(jobId); - if (itr == runningJobs.end()) { + if (itr == runningJobs.end()) throw JobNotFound(jobId, "jobIsDone"); - } + Job* job = itr->second; delete job; runningJobs.erase(itr); @@ -292,9 +290,9 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared Job::Id jobId = cardItr->second; requestedVCards.erase(cardItr); std::map::const_iterator itr = runningJobs.find(jobId); - if (itr == runningJobs.end()) { + if (itr == runningJobs.end()) throw JobNotFound(jobId, "receivedVCard"); - } + Job* job = itr->second; switch (job->type) { @@ -330,9 +328,9 @@ void Core::DelayManager::Manager::receivedOwnVCard(const Shared::VCard& card) { Job::Id jobId = ownVCardJobId; ownVCardJobId = 0; std::map::const_iterator itr = runningJobs.find(jobId); - if (itr == runningJobs.end()) { + if (itr == runningJobs.end()) throw JobNotFound(jobId, "receivedOwnVCard"); - } + Job* job = itr->second; switch (job->type) { case Job::Type::ownCardInternal: @@ -388,9 +386,9 @@ void Core::DelayManager::Manager::receivedOwnBundles(const std::list::const_iterator jitr = runningJobs.find(jobId); - if (jitr == runningJobs.end()) { + if (jitr == runningJobs.end()) throw JobNotFound(jobId, "receivedOwnBundles"); - } + Job* jb = jitr->second; OwnInfoForUser* job = dynamic_cast(jb); @@ -414,9 +412,9 @@ Core::DelayManager::Manager::UnexpectedJobType::UnexpectedJobType(Job::Type p_ty std::string Core::DelayManager::Manager::UnexpectedJobType::getMessage() const{ std::string msg("Unexpected job type: "); msg += Job::TypeString[static_cast(type)]; - if (method.size() > 0) { + if (method.size() > 0) msg += " in method " + method; - } + return msg; } @@ -430,8 +428,8 @@ std::string Core::DelayManager::Manager::JobNotFound::getMessage() const { std::string msg("Job with id "); msg += std::to_string(id); msg += " was not found"; - if (method.size() > 0) { + if (method.size() > 0) msg += " in method " + method; - } + return msg; } diff --git a/core/handlers/messagehandler.cpp b/core/handlers/messagehandler.cpp index f9b331f..8489dba 100644 --- a/core/handlers/messagehandler.cpp +++ b/core/handlers/messagehandler.cpp @@ -147,10 +147,9 @@ bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outg initializeMessage(sMsg, msg, outgoing, forwarded, guessing); QString jid = sMsg.getPenPalJid(); Conference* cnt = acc->rh->getConference(jid); - if (cnt == 0) { + if (cnt == 0) return false; - } - + std::tuple ids = getOriginalPendingMessageId(msg.id()); if (std::get<0>(ids)) { QMap cData = {{"state", static_cast(Shared::Message::State::delivered)}}; diff --git a/core/handlers/messagehandler.h b/core/handlers/messagehandler.h index 99a77d3..e3199dc 100644 --- a/core/handlers/messagehandler.h +++ b/core/handlers/messagehandler.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef CORE_MESSAGEHANDLER_H -#define CORE_MESSAGEHANDLER_H +#pragma once #include @@ -36,15 +35,9 @@ #include namespace Core { - -/** - * @todo write docs - */ - class Account; -class MessageHandler : public QObject -{ +class MessageHandler : public QObject { Q_OBJECT public: MessageHandler(Account* account); @@ -90,5 +83,3 @@ private: }; } - -#endif // CORE_MESSAGEHANDLER_H diff --git a/core/handlers/omemohandler.cpp b/core/handlers/omemohandler.cpp index 7f7c53b..eaa674f 100644 --- a/core/handlers/omemohandler.cpp +++ b/core/handlers/omemohandler.cpp @@ -1,18 +1,20 @@ -// 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 . +/* + * 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 "omemohandler.h" @@ -196,18 +198,7 @@ void Core::OmemoHandler::requestOwnBundles() { } void Core::OmemoHandler::onBundlesReceived(const QString& jid) { - std::list keys; - acc->oh->getDevices(jid, keys); - std::map trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid); - - qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); - for (Shared::KeyInfo& key : keys) { - std::map::const_iterator itr = trustLevels.find(key.fingerPrint); - if (itr != trustLevels.end()) { - key.trustLevel = itr->second; - qDebug() << "Found a trust level for a device!"; - } - } + std::list keys = readKeys(jid); Contact* cnt = acc->rh->getContact(jid); if (cnt) @@ -217,23 +208,35 @@ void Core::OmemoHandler::onBundlesReceived(const QString& jid) { } void Core::OmemoHandler::onOwnBundlesReceived() { - QString jid = acc->getBareJid(); - std::list keys; - acc->oh->getDevices(jid, keys); - std::map trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid); - - qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); - for (Shared::KeyInfo& key : keys) { - std::map::const_iterator itr = trustLevels.find(key.fingerPrint); - if (itr != trustLevels.end()) { - key.trustLevel = itr->second; - qDebug() << "Found a trust level for a device!"; - } - } + std::list keys = readKeys(acc->getBareJid()); + if (ownDevice) + keys.emplace_front( + ownDevice->id, + ownDevice->publicIdentityKey, + ownDevice->label, + QDateTime::currentDateTime(), + Shared::TrustLevel::authenticated, + Shared::EncryptionProtocol::omemo2, + true + ); acc->delay->receivedOwnBundles(keys); } +std::list Core::OmemoHandler::readKeys(const QString& jid) { + std::list keys; + getDevices(jid, keys); + std::map trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid); + + for (Shared::KeyInfo& key : keys) { + std::map::const_iterator itr = trustLevels.find(key.fingerPrint); + if (itr != trustLevels.end()) + key.trustLevel = itr->second; + } + + return keys; +} + void Core::OmemoHandler::onOmemoDeviceAdded(const QString& jid, uint32_t id) { SHARED_UNUSED(id); qDebug() << "OMEMO device added for" << jid; diff --git a/core/handlers/omemohandler.h b/core/handlers/omemohandler.h index 2d46546..99bfe38 100644 --- a/core/handlers/omemohandler.h +++ b/core/handlers/omemohandler.h @@ -69,6 +69,7 @@ public slots: private slots: void onBundlesReceived(const QString& jid); void onOwnBundlesReceived(); + std::list readKeys(const QString& jid); private: Account* acc; diff --git a/shared/keyinfo.h b/shared/keyinfo.h index 8d7db0a..500a2c1 100644 --- a/shared/keyinfo.h +++ b/shared/keyinfo.h @@ -1,21 +1,22 @@ -// 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 . +/* + * 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_KEYINFO_H -#define SHARED_KEYINFO_H +#pragma once #include #include @@ -27,8 +28,7 @@ namespace Shared { -class KeyInfo -{ +class KeyInfo { public: KeyInfo( uint32_t id, @@ -56,5 +56,3 @@ public: }; } - -#endif // SHARED_KEYINFO_H diff --git a/ui/utils/expandinglist.cpp b/ui/utils/expandinglist.cpp index 6d1546d..5cc9bad 100644 --- a/ui/utils/expandinglist.cpp +++ b/ui/utils/expandinglist.cpp @@ -1,43 +1,60 @@ -// 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 . +/* + * 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 "expandinglist.h" -QSize ExpandingList::viewportSizeHint() const { - if (QAbstractItemView::sizeAdjustPolicy() != QAbstractScrollArea::AdjustToContents) - return QListView::viewportSizeHint(); +#include - if (model() == nullptr) - return QSize(0, 0); - if (model()->rowCount() == 0) - return QSize(0, 0); +ExpandingList::ExpandingList(QWidget* parent) : + QListView(parent), + scrollBarExtent(qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)) +{ + setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); +} +bool ExpandingList::hasHeightForWidth() const { #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) - const int rowCount = model()->rowCount(); - int height = 0; - for (int i = 0; i < rowCount; i++) { - height += QListView::sizeHintForRow(i); - } - return QSize(QListView::viewportSizeHint().width(), height); + return + QAbstractItemView::sizeAdjustPolicy() == QAbstractScrollArea::AdjustToContents && + scrollBarExtent > 0; #else - return QListView::viewportSizeHint(); + return false; #endif } -QSize ExpandingList::minimumSizeHint() const { - return viewportSizeHint(); -} +int ExpandingList::heightForWidth(int width) const { + QAbstractItemModel* md = model(); + if (md == nullptr) + return 0; + if (md->rowCount() == 0) + return 0; + + const int rowCount = md->rowCount(); + int height = 0; + for (int i = 0; i < rowCount; i++) + height += QListView::sizeHintForRow(i); + + height += frameWidth(); + int minWidth = sizeHintForColumn(0) + frameWidth() + 1; + + if (width <= minWidth) + height += scrollBarExtent + 1; + + return height; +} diff --git a/ui/utils/expandinglist.h b/ui/utils/expandinglist.h index 0b29e89..9084757 100644 --- a/ui/utils/expandinglist.h +++ b/ui/utils/expandinglist.h @@ -1,31 +1,35 @@ -// 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 . +/* + * 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 EXPANDINGLIST_H -#define EXPANDINGLIST_H +#pragma once #include class ExpandingList : public QListView { Q_OBJECT public: - using QListView::QListView; //explicit constructor inheriatnce + ExpandingList(QWidget* parent = nullptr); - QSize viewportSizeHint() const override; - QSize minimumSizeHint() const override; + bool hasHeightForWidth() const override; + int heightForWidth(int width) const override; + // QSize viewportSizeHint() const override; + // QSize minimumSizeHint() const override; + +private: + int scrollBarExtent; }; - -#endif // EXPANDINGLIST_H diff --git a/ui/widgets/info/info.cpp b/ui/widgets/info/info.cpp index 6a1105d..948ee27 100644 --- a/ui/widgets/info/info.cpp +++ b/ui/widgets/info/info.cpp @@ -1,18 +1,20 @@ -// 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 . +/* + * 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 "info.h" #include "ui_info.h" diff --git a/ui/widgets/info/info.h b/ui/widgets/info/info.h index 10bc063..7d52693 100644 --- a/ui/widgets/info/info.h +++ b/ui/widgets/info/info.h @@ -1,21 +1,22 @@ -// 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 . +/* + * 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 UI_WIDGETS_INFO_H -#define UI_WIDGETS_INFO_H +#pragma once #include @@ -88,5 +89,3 @@ private: }; } - -#endif // UI_WIDGETS_INFO_H diff --git a/ui/widgets/info/omemo/keydelegate.cpp b/ui/widgets/info/omemo/keydelegate.cpp index fd687ad..074ef1c 100644 --- a/ui/widgets/info/omemo/keydelegate.cpp +++ b/ui/widgets/info/omemo/keydelegate.cpp @@ -1,18 +1,20 @@ -// 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 . +/* + * 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 "keydelegate.h" #include diff --git a/ui/widgets/info/omemo/keydelegate.h b/ui/widgets/info/omemo/keydelegate.h index 01b45c1..6d7f067 100644 --- a/ui/widgets/info/omemo/keydelegate.h +++ b/ui/widgets/info/omemo/keydelegate.h @@ -1,35 +1,37 @@ -// 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 . +/* + * 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 UI_KEYDELEGATE_H -#define UI_KEYDELEGATE_H +#pragma once #include #include + #include namespace UI { -class KeyDelegate : public QStyledItemDelegate -{ +class KeyDelegate : public QStyledItemDelegate { + Q_OBJECT public: - KeyDelegate(QObject *parent = nullptr); + KeyDelegate(QObject* parent = nullptr); ~KeyDelegate(); - QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const override; + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; private: @@ -46,5 +48,3 @@ private: }; } - -#endif // UI_KEYDELEGATE_H diff --git a/ui/widgets/info/omemo/omemo.cpp b/ui/widgets/info/omemo/omemo.cpp index d3722fe..294fbe2 100644 --- a/ui/widgets/info/omemo/omemo.cpp +++ b/ui/widgets/info/omemo/omemo.cpp @@ -1,18 +1,20 @@ -// 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 . +/* + * 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 "omemo.h" #include "ui_omemo.h" @@ -23,25 +25,31 @@ constexpr uint8_t fingerprintLength = 32; UI::Omemo::Omemo(QWidget* parent): QWidget(parent), m_ui(new Ui::Omemo()), + deviceKeyDelegate(), keysDelegate(), unusedKeysDelegate(), + deviceKeyModel(), keysModel(), unusedKeysModel(), contextMenu(new QMenu()) { m_ui->setupUi(this); + m_ui->deviceKeyView->setItemDelegate(&deviceKeyDelegate); + m_ui->deviceKeyView->setModel(&deviceKeyModel); m_ui->keysView->setItemDelegate(&keysDelegate); m_ui->keysView->setModel(&keysModel); m_ui->unusedKeysView->setItemDelegate(&unusedKeysDelegate); m_ui->unusedKeysView->setModel(&unusedKeysModel); + unusedVisibility(false); + deviceKeyVisibility(false); + m_ui->keysView->setContextMenuPolicy(Qt::CustomContextMenu); connect(m_ui->keysView, &QWidget::customContextMenuRequested, this, &Omemo::onActiveKeysContextMenu); } -UI::Omemo::~Omemo() -{ +UI::Omemo::~Omemo() { contextMenu->deleteLater(); } @@ -50,9 +58,9 @@ void UI::Omemo::generateMockData() { std::uniform_int_distribution dist(CHAR_MIN, CHAR_MAX); for (int i = 0; i < 5; ++i) { QByteArray fp(fingerprintLength, 0); - for (int i = 0; i < fingerprintLength; ++i) { + for (int i = 0; i < fingerprintLength; ++i) fp[i] = dist(rd); - } + Shared::KeyInfo info; info.id = i; if (i % 3 == 0) @@ -68,14 +76,21 @@ void UI::Omemo::generateMockData() { void UI::Omemo::setData(const std::list& keys) { keysModel.clear(); unusedKeysModel.clear(); + deviceKeyModel.clear(); for (const Shared::KeyInfo& key : keys) { - keysModel.addKey(key); + if (key.currentDevice) + deviceKeyModel.addKey(key); + else + keysModel.addKey(key); } + + unusedVisibility(unusedKeysModel.rowCount() > 0); + deviceKeyVisibility(deviceKeyModel.rowCount() > 0); } const QString UI::Omemo::title() const { - return m_ui->OMEMOHeading->text();} - + return m_ui->OMEMOHeading->text(); +} void UI::Omemo::onActiveKeysContextMenu(const QPoint& pos) { contextMenu->clear(); @@ -119,3 +134,15 @@ void UI::Omemo::onActiveKeysContextMenu(const QPoint& pos) { contextMenu->popup(m_ui->keysView->viewport()->mapToGlobal(pos)); } + +void UI::Omemo::deviceKeyVisibility(bool visible) { + m_ui->deviceKeyHeading->setVisible(visible); + m_ui->deviceKeyline->setVisible(visible); + m_ui->deviceKeyView->setVisible(visible); +} + +void UI::Omemo::unusedVisibility(bool visible) { + m_ui->unusedKeysView->setVisible(visible); + m_ui->unusedKeysHeading->setVisible(visible); + m_ui->line->setVisible(visible); +} diff --git a/ui/widgets/info/omemo/omemo.h b/ui/widgets/info/omemo/omemo.h index a279492..75b1df2 100644 --- a/ui/widgets/info/omemo/omemo.h +++ b/ui/widgets/info/omemo/omemo.h @@ -1,21 +1,22 @@ -// 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 . +/* + * 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 VCARD_OMEMO_H -#define VCARD_OMEMO_H +#pragma once #include @@ -29,8 +30,7 @@ #include "shared/keyinfo.h" namespace UI { -namespace Ui -{ +namespace Ui { class Omemo; } @@ -48,14 +48,17 @@ private slots: private: void generateMockData(); + void unusedVisibility(bool visible); + void deviceKeyVisibility(bool visible); private: QScopedPointer m_ui; + UI::KeyDelegate deviceKeyDelegate; UI::KeyDelegate keysDelegate; UI::KeyDelegate unusedKeysDelegate; + Models::Keys deviceKeyModel; Models::Keys keysModel; Models::Keys unusedKeysModel; QMenu* contextMenu; }; } -#endif // VCARD_OMEMO_H diff --git a/ui/widgets/info/omemo/omemo.ui b/ui/widgets/info/omemo/omemo.ui index 745b981..64361f9 100644 --- a/ui/widgets/info/omemo/omemo.ui +++ b/ui/widgets/info/omemo/omemo.ui @@ -64,7 +64,28 @@ - + + + + + 16 + 75 + true + + + + Unused keys + + + + + + + Qt::Horizontal + + + + @@ -89,42 +110,7 @@ - - - - Qt::Horizontal - - - - - - - - 16 - 75 - true - - - - Active keys - - - - - - - - 16 - 75 - true - - - - Unused keys - - - - + @@ -149,8 +135,68 @@ - - + + + + + 16 + 75 + true + + + + Device key + + + + + + + + 16 + 75 + true + + + + Active keys + + + + + + + + 0 + 0 + + + + QAbstractScrollArea::AdjustToContents + + + false + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + false + + + + + + + Qt::Horizontal + + + + + Qt::Horizontal @@ -162,8 +208,8 @@ - - + + Qt::Horizontal