Own omemo key display, a bit of CMake clean up

This commit is contained in:
Blue 2023-11-13 19:05:26 -03:00
parent 19835af3cf
commit 00af582287
Signed by: blue
GPG Key ID: 9B203B252A63EE38
16 changed files with 443 additions and 360 deletions

View File

@ -47,7 +47,7 @@ find_package(Boost COMPONENTS)
target_include_directories(squawk PRIVATE ${Boost_INCLUDE_DIRS}) target_include_directories(squawk PRIVATE ${Boost_INCLUDE_DIRS})
#OMEMO ## OMEMO
if (WITH_OMEMO) if (WITH_OMEMO)
find_package(PkgConfig) find_package(PkgConfig)
if (PKG_CONFIG_FOUND) if (PKG_CONFIG_FOUND)
@ -65,22 +65,6 @@ if (WITH_OMEMO)
endif () endif ()
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 ## KIO
if (WITH_KIO) if (WITH_KIO)
find_package(KF5KIO CONFIG) find_package(KF5KIO CONFIG)
@ -107,6 +91,7 @@ if (WITH_KWALLET)
endif () endif ()
endif () endif ()
## KConfig
if (WITH_KCONFIG) if (WITH_KCONFIG)
find_package(KF5Config CONFIG) find_package(KF5Config CONFIG)
if (NOT KF5Config_FOUND) if (NOT KF5Config_FOUND)
@ -125,7 +110,22 @@ if (WITH_KCONFIG)
endif() endif()
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") message("Building with bundled QXmpp")
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/base) target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/base)
@ -141,19 +141,10 @@ if (NOT SYSTEM_QXMPP)
set(BUILD_OMEMO OFF) set(BUILD_OMEMO OFF)
endif () endif ()
add_subdirectory(external/qxmpp) add_subdirectory(external/qxmpp)
add_library(QXmpp::QXmpp ALIAS QXmppQt${QT_VERSION_MAJOR})
if (WITH_OMEMO) if (WITH_OMEMO)
target_include_directories(QXmppOmemoQt${QT_VERSION_MAJOR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src) target_include_directories(QXmppOmemoQt${QT_VERSION_MAJOR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src)
endif() add_library(QXmpp::Omemo ALIAS QXmppOmemoQt${QT_VERSION_MAJOR})
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)
endif () endif ()
endif () endif ()
@ -166,18 +157,14 @@ if (SYSTEM_LMDBAL)
else () else ()
message("Building with system LMDBAL") message("Building with system LMDBAL")
endif () endif ()
endif() else()
if (NOT SYSTEM_LMDBAL)
message("Building with bundled LMDBAL") message("Building with bundled LMDBAL")
set(BUILD_STATIC ON) set(BUILD_STATIC ON)
add_subdirectory(external/lmdbal) add_subdirectory(external/lmdbal)
add_library(LMDBAL::LMDBAL ALIAS LMDBAL) add_library(LMDBAL::LMDBAL ALIAS LMDBAL)
endif() endif()
target_link_libraries(squawk PRIVATE LMDBAL::LMDBAL) ## Linking
# Linking
target_link_libraries(squawk target_link_libraries(squawk
PRIVATE PRIVATE
Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Core
@ -186,17 +173,23 @@ target_link_libraries(squawk
Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Xml Qt${QT_VERSION_MAJOR}::Xml
LMDBAL::LMDBAL
QXmpp::QXmpp
simpleCrypt
) )
target_link_libraries(squawk PRIVATE lmdb)
target_link_libraries(squawk PRIVATE simpleCrypt) if (WITH_OMEMO)
# Link thread libraries on Linux target_link_libraries(squawk PRIVATE QXmpp::Omemo)
endif ()
## Link thread libraries on Linux
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
target_link_libraries(squawk PRIVATE Threads::Threads) target_link_libraries(squawk PRIVATE Threads::Threads)
endif() endif()
# Build type ## Build type
if (NOT CMAKE_BUILD_TYPE) if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif () endif ()
@ -228,7 +221,7 @@ add_subdirectory(shared)
add_subdirectory(translations) add_subdirectory(translations)
add_subdirectory(ui) add_subdirectory(ui)
# Install the executable ## Install the executable
install(TARGETS squawk DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS squawk DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk) install(FILES README.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk)
install(FILES LICENSE.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk) install(FILES LICENSE.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk)

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "manager.h" #include "manager.h"
@ -39,17 +41,14 @@ Core::DelayManager::Manager::Manager(const QString& poj, Job::Id mpj, QObject* p
requestedBundles(), requestedBundles(),
#endif #endif
ownJid(poj) ownJid(poj)
{ {}
}
Core::DelayManager::Manager::~Manager() { Core::DelayManager::Manager::~Manager() {
for (const std::pair<const Job::Id, Job*>& pair : runningJobs) { for (const std::pair<const Job::Id, Job*>& pair : runningJobs)
delete pair.second; delete pair.second;
}
for (Job* job : jobSequence) { for (Job* job : jobSequence)
delete job; delete job;
}
} }
Core::DelayManager::Job::Id Core::DelayManager::Manager::getNextJobId() { 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) { void Core::DelayManager::Manager::scheduleJob(Job* job) {
preScheduleJob(job); preScheduleJob(job);
if (runningJobs.size() < maxParallelJobs) { if (runningJobs.size() < maxParallelJobs)
executeJob(job); executeJob(job);
} else { else
scheduledJobs.push_back(job); scheduledJobs.push_back(job);
}
} }
void Core::DelayManager::Manager::preExecuteJob(Job* 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) { void Core::DelayManager::Manager::jobIsDone(Job::Id jobId) {
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId); std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
if (itr == runningJobs.end()) { if (itr == runningJobs.end())
throw JobNotFound(jobId, "jobIsDone"); throw JobNotFound(jobId, "jobIsDone");
}
Job* job = itr->second; Job* job = itr->second;
delete job; delete job;
runningJobs.erase(itr); runningJobs.erase(itr);
@ -292,9 +290,9 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared
Job::Id jobId = cardItr->second; Job::Id jobId = cardItr->second;
requestedVCards.erase(cardItr); requestedVCards.erase(cardItr);
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId); std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
if (itr == runningJobs.end()) { if (itr == runningJobs.end())
throw JobNotFound(jobId, "receivedVCard"); throw JobNotFound(jobId, "receivedVCard");
}
Job* job = itr->second; Job* job = itr->second;
switch (job->type) { switch (job->type) {
@ -330,9 +328,9 @@ void Core::DelayManager::Manager::receivedOwnVCard(const Shared::VCard& card) {
Job::Id jobId = ownVCardJobId; Job::Id jobId = ownVCardJobId;
ownVCardJobId = 0; ownVCardJobId = 0;
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId); std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
if (itr == runningJobs.end()) { if (itr == runningJobs.end())
throw JobNotFound(jobId, "receivedOwnVCard"); throw JobNotFound(jobId, "receivedOwnVCard");
}
Job* job = itr->second; Job* job = itr->second;
switch (job->type) { switch (job->type) {
case Job::Type::ownCardInternal: case Job::Type::ownCardInternal:
@ -388,9 +386,9 @@ void Core::DelayManager::Manager::receivedOwnBundles(const std::list<Shared::Key
Job::Id jobId = ownInfoJobId; Job::Id jobId = ownInfoJobId;
ownInfoJobId = 0; ownInfoJobId = 0;
std::map<Job::Id, Job*>::const_iterator jitr = runningJobs.find(jobId); std::map<Job::Id, Job*>::const_iterator jitr = runningJobs.find(jobId);
if (jitr == runningJobs.end()) { if (jitr == runningJobs.end())
throw JobNotFound(jobId, "receivedOwnBundles"); throw JobNotFound(jobId, "receivedOwnBundles");
}
Job* jb = jitr->second; Job* jb = jitr->second;
OwnInfoForUser* job = dynamic_cast<OwnInfoForUser*>(jb); OwnInfoForUser* job = dynamic_cast<OwnInfoForUser*>(jb);
@ -414,9 +412,9 @@ Core::DelayManager::Manager::UnexpectedJobType::UnexpectedJobType(Job::Type p_ty
std::string Core::DelayManager::Manager::UnexpectedJobType::getMessage() const{ std::string Core::DelayManager::Manager::UnexpectedJobType::getMessage() const{
std::string msg("Unexpected job type: "); std::string msg("Unexpected job type: ");
msg += Job::TypeString[static_cast<int>(type)]; msg += Job::TypeString[static_cast<int>(type)];
if (method.size() > 0) { if (method.size() > 0)
msg += " in method " + method; msg += " in method " + method;
}
return msg; return msg;
} }
@ -430,8 +428,8 @@ std::string Core::DelayManager::Manager::JobNotFound::getMessage() const {
std::string msg("Job with id "); std::string msg("Job with id ");
msg += std::to_string(id); msg += std::to_string(id);
msg += " was not found"; msg += " was not found";
if (method.size() > 0) { if (method.size() > 0)
msg += " in method " + method; msg += " in method " + method;
}
return msg; return msg;
} }

View File

@ -147,10 +147,9 @@ bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outg
initializeMessage(sMsg, msg, outgoing, forwarded, guessing); initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
QString jid = sMsg.getPenPalJid(); QString jid = sMsg.getPenPalJid();
Conference* cnt = acc->rh->getConference(jid); Conference* cnt = acc->rh->getConference(jid);
if (cnt == 0) { if (cnt == 0)
return false; return false;
}
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(msg.id()); std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(msg.id());
if (std::get<0>(ids)) { if (std::get<0>(ids)) {
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}}; QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}};

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CORE_MESSAGEHANDLER_H #pragma once
#define CORE_MESSAGEHANDLER_H
#include <QObject> #include <QObject>
@ -36,15 +35,9 @@
#include <shared/pathcheck.h> #include <shared/pathcheck.h>
namespace Core { namespace Core {
/**
* @todo write docs
*/
class Account; class Account;
class MessageHandler : public QObject class MessageHandler : public QObject {
{
Q_OBJECT Q_OBJECT
public: public:
MessageHandler(Account* account); MessageHandler(Account* account);
@ -90,5 +83,3 @@ private:
}; };
} }
#endif // CORE_MESSAGEHANDLER_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug> #include <QDebug>
#include "omemohandler.h" #include "omemohandler.h"
@ -196,18 +198,7 @@ void Core::OmemoHandler::requestOwnBundles() {
} }
void Core::OmemoHandler::onBundlesReceived(const QString& jid) { void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
std::list<Shared::KeyInfo> keys; std::list<Shared::KeyInfo> keys = readKeys(jid);
acc->oh->getDevices(jid, keys);
std::map<QByteArray, Shared::TrustLevel> 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<QByteArray, Shared::TrustLevel>::const_iterator itr = trustLevels.find(key.fingerPrint);
if (itr != trustLevels.end()) {
key.trustLevel = itr->second;
qDebug() << "Found a trust level for a device!";
}
}
Contact* cnt = acc->rh->getContact(jid); Contact* cnt = acc->rh->getContact(jid);
if (cnt) if (cnt)
@ -217,23 +208,35 @@ void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
} }
void Core::OmemoHandler::onOwnBundlesReceived() { void Core::OmemoHandler::onOwnBundlesReceived() {
QString jid = acc->getBareJid(); std::list<Shared::KeyInfo> keys = readKeys(acc->getBareJid());
std::list<Shared::KeyInfo> keys; if (ownDevice)
acc->oh->getDevices(jid, keys); keys.emplace_front(
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid); ownDevice->id,
ownDevice->publicIdentityKey,
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); ownDevice->label,
for (Shared::KeyInfo& key : keys) { QDateTime::currentDateTime(),
std::map<QByteArray, Shared::TrustLevel>::const_iterator itr = trustLevels.find(key.fingerPrint); Shared::TrustLevel::authenticated,
if (itr != trustLevels.end()) { Shared::EncryptionProtocol::omemo2,
key.trustLevel = itr->second; true
qDebug() << "Found a trust level for a device!"; );
}
}
acc->delay->receivedOwnBundles(keys); acc->delay->receivedOwnBundles(keys);
} }
std::list<Shared::KeyInfo> Core::OmemoHandler::readKeys(const QString& jid) {
std::list<Shared::KeyInfo> keys;
getDevices(jid, keys);
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid);
for (Shared::KeyInfo& key : keys) {
std::map<QByteArray, Shared::TrustLevel>::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) { void Core::OmemoHandler::onOmemoDeviceAdded(const QString& jid, uint32_t id) {
SHARED_UNUSED(id); SHARED_UNUSED(id);
qDebug() << "OMEMO device added for" << jid; qDebug() << "OMEMO device added for" << jid;

View File

@ -69,6 +69,7 @@ public slots:
private slots: private slots:
void onBundlesReceived(const QString& jid); void onBundlesReceived(const QString& jid);
void onOwnBundlesReceived(); void onOwnBundlesReceived();
std::list<Shared::KeyInfo> readKeys(const QString& jid);
private: private:
Account* acc; Account* acc;

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHARED_KEYINFO_H #pragma once
#define SHARED_KEYINFO_H
#include <QString> #include <QString>
#include <QByteArray> #include <QByteArray>
@ -27,8 +28,7 @@
namespace Shared { namespace Shared {
class KeyInfo class KeyInfo {
{
public: public:
KeyInfo( KeyInfo(
uint32_t id, uint32_t id,
@ -56,5 +56,3 @@ public:
}; };
} }
#endif // SHARED_KEYINFO_H

View File

@ -1,43 +1,60 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "expandinglist.h" #include "expandinglist.h"
QSize ExpandingList::viewportSizeHint() const { #include <QApplication>
if (QAbstractItemView::sizeAdjustPolicy() != QAbstractScrollArea::AdjustToContents)
return QListView::viewportSizeHint();
if (model() == nullptr) ExpandingList::ExpandingList(QWidget* parent) :
return QSize(0, 0); QListView(parent),
if (model()->rowCount() == 0) scrollBarExtent(qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent))
return QSize(0, 0); {
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
}
bool ExpandingList::hasHeightForWidth() const {
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
const int rowCount = model()->rowCount(); return
int height = 0; QAbstractItemView::sizeAdjustPolicy() == QAbstractScrollArea::AdjustToContents &&
for (int i = 0; i < rowCount; i++) { scrollBarExtent > 0;
height += QListView::sizeHintForRow(i);
}
return QSize(QListView::viewportSizeHint().width(), height);
#else #else
return QListView::viewportSizeHint(); return false;
#endif #endif
} }
QSize ExpandingList::minimumSizeHint() const { int ExpandingList::heightForWidth(int width) const {
return viewportSizeHint(); 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;
}

View File

@ -1,31 +1,35 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EXPANDINGLIST_H #pragma once
#define EXPANDINGLIST_H
#include <QListView> #include <QListView>
class ExpandingList : public QListView { class ExpandingList : public QListView {
Q_OBJECT Q_OBJECT
public: public:
using QListView::QListView; //explicit constructor inheriatnce ExpandingList(QWidget* parent = nullptr);
QSize viewportSizeHint() const override; bool hasHeightForWidth() const override;
QSize minimumSizeHint() const override; int heightForWidth(int width) const override;
// QSize viewportSizeHint() const override;
// QSize minimumSizeHint() const override;
private:
int scrollBarExtent;
}; };
#endif // EXPANDINGLIST_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "info.h" #include "info.h"
#include "ui_info.h" #include "ui_info.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UI_WIDGETS_INFO_H #pragma once
#define UI_WIDGETS_INFO_H
#include <list> #include <list>
@ -88,5 +89,3 @@ private:
}; };
} }
#endif // UI_WIDGETS_INFO_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "keydelegate.h" #include "keydelegate.h"
#include <QPainter> #include <QPainter>

View File

@ -1,35 +1,37 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UI_KEYDELEGATE_H #pragma once
#define UI_KEYDELEGATE_H
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QString> #include <QString>
#include <vector> #include <vector>
namespace UI { namespace UI {
class KeyDelegate : public QStyledItemDelegate class KeyDelegate : public QStyledItemDelegate {
{ Q_OBJECT
public: public:
KeyDelegate(QObject *parent = nullptr); KeyDelegate(QObject* parent = nullptr);
~KeyDelegate(); ~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; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
private: private:
@ -46,5 +48,3 @@ private:
}; };
} }
#endif // UI_KEYDELEGATE_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "omemo.h" #include "omemo.h"
#include "ui_omemo.h" #include "ui_omemo.h"
@ -23,25 +25,31 @@ constexpr uint8_t fingerprintLength = 32;
UI::Omemo::Omemo(QWidget* parent): UI::Omemo::Omemo(QWidget* parent):
QWidget(parent), QWidget(parent),
m_ui(new Ui::Omemo()), m_ui(new Ui::Omemo()),
deviceKeyDelegate(),
keysDelegate(), keysDelegate(),
unusedKeysDelegate(), unusedKeysDelegate(),
deviceKeyModel(),
keysModel(), keysModel(),
unusedKeysModel(), unusedKeysModel(),
contextMenu(new QMenu()) contextMenu(new QMenu())
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->deviceKeyView->setItemDelegate(&deviceKeyDelegate);
m_ui->deviceKeyView->setModel(&deviceKeyModel);
m_ui->keysView->setItemDelegate(&keysDelegate); m_ui->keysView->setItemDelegate(&keysDelegate);
m_ui->keysView->setModel(&keysModel); m_ui->keysView->setModel(&keysModel);
m_ui->unusedKeysView->setItemDelegate(&unusedKeysDelegate); m_ui->unusedKeysView->setItemDelegate(&unusedKeysDelegate);
m_ui->unusedKeysView->setModel(&unusedKeysModel); m_ui->unusedKeysView->setModel(&unusedKeysModel);
unusedVisibility(false);
deviceKeyVisibility(false);
m_ui->keysView->setContextMenuPolicy(Qt::CustomContextMenu); m_ui->keysView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui->keysView, &QWidget::customContextMenuRequested, this, &Omemo::onActiveKeysContextMenu); connect(m_ui->keysView, &QWidget::customContextMenuRequested, this, &Omemo::onActiveKeysContextMenu);
} }
UI::Omemo::~Omemo() UI::Omemo::~Omemo() {
{
contextMenu->deleteLater(); contextMenu->deleteLater();
} }
@ -50,9 +58,9 @@ void UI::Omemo::generateMockData() {
std::uniform_int_distribution<char> dist(CHAR_MIN, CHAR_MAX); std::uniform_int_distribution<char> dist(CHAR_MIN, CHAR_MAX);
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
QByteArray fp(fingerprintLength, 0); QByteArray fp(fingerprintLength, 0);
for (int i = 0; i < fingerprintLength; ++i) { for (int i = 0; i < fingerprintLength; ++i)
fp[i] = dist(rd); fp[i] = dist(rd);
}
Shared::KeyInfo info; Shared::KeyInfo info;
info.id = i; info.id = i;
if (i % 3 == 0) if (i % 3 == 0)
@ -68,14 +76,21 @@ void UI::Omemo::generateMockData() {
void UI::Omemo::setData(const std::list<Shared::KeyInfo>& keys) { void UI::Omemo::setData(const std::list<Shared::KeyInfo>& keys) {
keysModel.clear(); keysModel.clear();
unusedKeysModel.clear(); unusedKeysModel.clear();
deviceKeyModel.clear();
for (const Shared::KeyInfo& key : keys) { 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 { const QString UI::Omemo::title() const {
return m_ui->OMEMOHeading->text();} return m_ui->OMEMOHeading->text();
}
void UI::Omemo::onActiveKeysContextMenu(const QPoint& pos) { void UI::Omemo::onActiveKeysContextMenu(const QPoint& pos) {
contextMenu->clear(); contextMenu->clear();
@ -119,3 +134,15 @@ void UI::Omemo::onActiveKeysContextMenu(const QPoint& pos) {
contextMenu->popup(m_ui->keysView->viewport()->mapToGlobal(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);
}

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * Squawk messenger.
// * Copyright (C) 2019 Yury Gubich <blue@macaw.me>
// This program is free software: you can redistribute it and/or modify *
// it under the terms of the GNU General Public License as published by * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// You should have received a copy of the GNU General Public License *
// along with this program. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VCARD_OMEMO_H #pragma once
#define VCARD_OMEMO_H
#include <list> #include <list>
@ -29,8 +30,7 @@
#include "shared/keyinfo.h" #include "shared/keyinfo.h"
namespace UI { namespace UI {
namespace Ui namespace Ui {
{
class Omemo; class Omemo;
} }
@ -48,14 +48,17 @@ private slots:
private: private:
void generateMockData(); void generateMockData();
void unusedVisibility(bool visible);
void deviceKeyVisibility(bool visible);
private: private:
QScopedPointer<Ui::Omemo> m_ui; QScopedPointer<Ui::Omemo> m_ui;
UI::KeyDelegate deviceKeyDelegate;
UI::KeyDelegate keysDelegate; UI::KeyDelegate keysDelegate;
UI::KeyDelegate unusedKeysDelegate; UI::KeyDelegate unusedKeysDelegate;
Models::Keys deviceKeyModel;
Models::Keys keysModel; Models::Keys keysModel;
Models::Keys unusedKeysModel; Models::Keys unusedKeysModel;
QMenu* contextMenu; QMenu* contextMenu;
}; };
} }
#endif // VCARD_OMEMO_H

View File

@ -64,7 +64,28 @@
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,3,1"> <layout class="QGridLayout" name="gridLayout" columnstretch="1,3,1">
<item row="1" column="1"> <item row="7" column="1">
<widget class="QLabel" name="unusedKeysHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Unused keys</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="ExpandingList" name="keysView"> <widget class="ExpandingList" name="keysView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -89,42 +110,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="8" column="1">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="keysHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Active keys</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="unusedKeysHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Unused keys</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="ExpandingList" name="unusedKeysView"> <widget class="ExpandingList" name="unusedKeysView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -149,8 +135,68 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" rowspan="6"> <item row="0" column="1">
<spacer name="spacerLeft"> <widget class="QLabel" name="deviceKeyHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Device key</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="keysHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Active keys</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="ExpandingList" name="deviceKeyView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="uniformItemSizes">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Line" name="deviceKeyline">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="9">
<spacer name="spacerRight">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -162,8 +208,8 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="2" rowspan="6"> <item row="0" column="0" rowspan="9">
<spacer name="spacerRight"> <spacer name="spacerLeft">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>