1
0
forked from blue/squawk

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 untrusted user: 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})
#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)

View File

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

View File

@ -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<bool, QString, QString> ids = getOriginalPendingMessageId(msg.id());
if (std::get<0>(ids)) {
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/>.
*/
#ifndef CORE_MESSAGEHANDLER_H
#define CORE_MESSAGEHANDLER_H
#pragma once
#include <QObject>
@ -36,15 +35,9 @@
#include <shared/pathcheck.h>
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

View File

@ -1,18 +1,20 @@
// Squawk messenger.
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include "omemohandler.h"
@ -196,18 +198,7 @@ void Core::OmemoHandler::requestOwnBundles() {
}
void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
std::list<Shared::KeyInfo> keys;
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!";
}
}
std::list<Shared::KeyInfo> 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<Shared::KeyInfo> keys;
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!";
}
}
std::list<Shared::KeyInfo> 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<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) {
SHARED_UNUSED(id);
qDebug() << "OMEMO device added for" << jid;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -64,7 +64,28 @@
</rect>
</property>
<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">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -89,42 +110,7 @@
</property>
</widget>
</item>
<item row="3" 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">
<item row="8" column="1">
<widget class="ExpandingList" name="unusedKeysView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -149,8 +135,68 @@
</property>
</widget>
</item>
<item row="0" column="0" rowspan="6">
<spacer name="spacerLeft">
<item row="0" column="1">
<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">
<enum>Qt::Horizontal</enum>
</property>
@ -162,8 +208,8 @@
</property>
</spacer>
</item>
<item row="0" column="2" rowspan="6">
<spacer name="spacerRight">
<item row="0" column="0" rowspan="9">
<spacer name="spacerLeft">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>