Compare commits
2 Commits
861732edb6
...
ff17dca4d4
Author | SHA1 | Date |
---|---|---|
Xavier Del Campo Romero | ff17dca4d4 | |
Xavier Del Campo Romero | 98b5243c75 |
|
@ -0,0 +1,74 @@
|
|||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
build*/
|
|
@ -1,3 +1,3 @@
|
|||
[submodule "qxmpp/qxmpp"]
|
||||
path = qxmpp/qxmpp
|
||||
url = https://github.com/qxmpp-project/qxmpp
|
||||
url = https://gitea.privatedns.org/Xavi92/qxmpp
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
cmake_minimum_required(VERSION 3.13.5)
|
||||
|
||||
project(xxcc VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
add_compile_options(-fdata-sections -ffunction-sections)
|
||||
|
||||
set(QT_VERSION_MAJOR 5)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
# QXmpp requires C++17.
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Sql REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Sql REQUIRED)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
account.ui
|
||||
accounts.cpp
|
||||
accounts.ui
|
||||
contact.ui
|
||||
contacts.cpp
|
||||
contacts.ui
|
||||
conversation.ui
|
||||
credentials.cpp
|
||||
jiddb.cpp
|
||||
login.cpp
|
||||
login.ui
|
||||
main.cpp
|
||||
message.ui
|
||||
xxcc.cpp
|
||||
xxcc.ui
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(${PROJECT_NAME}
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
else()
|
||||
add_executable(${PROJECT_NAME}
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(qca REQUIRED IMPORTED_TARGET qca2-qt${QT_VERSION_MAJOR})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::qca)
|
||||
|
||||
find_package(Qt5Keychain REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5Keychain::Qt5Keychain)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Sql)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--gc-sections)
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
add_subdirectory(qxmpp)
|
||||
|
||||
#target_compile_definitions(${PROJECT_NAME} PUBLIC QT_NO_KEYWORDS)
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC -Wall)
|
|
@ -0,0 +1,3 @@
|
|||
```
|
||||
# apt install qtkeychain-qt5-dev qttools5-dev-tools qtbase5-dev
|
||||
```
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>account</class>
|
||||
<widget class="QWidget" name="account">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>139</width>
|
||||
<height>36</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="jid">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="alias">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="connected">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connected</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,53 @@
|
|||
#include "accounts.h"
|
||||
#include "ui_account.h"
|
||||
#include "login.h"
|
||||
#include <utility>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
Accounts::Accounts(const QList<QXmppClient *> &accounts,
|
||||
QWidget *const parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
for (const auto &a : accounts)
|
||||
add(a);
|
||||
|
||||
connect(ui.add, &QPushButton::released,
|
||||
[this]
|
||||
{
|
||||
Login l(this);
|
||||
|
||||
l.connect(&l, &Login::auth_success,
|
||||
[this] (QXmppClient *c)
|
||||
{
|
||||
add(c);
|
||||
Q_EMIT new_account(c);
|
||||
});
|
||||
|
||||
l.exec();
|
||||
});
|
||||
}
|
||||
|
||||
void Accounts::add(QXmppClient *c)
|
||||
{
|
||||
const auto it = new QListWidgetItem(ui.accounts_list);
|
||||
const auto w = new QWidget;
|
||||
/* TODO: derive QWidget with Ui_account as a member. */
|
||||
const auto account = new Ui_account;
|
||||
|
||||
account->setupUi(w);
|
||||
account->jid->setText(c->configuration().jidBare());
|
||||
account->connected->setChecked(
|
||||
c->state() == QXmppClient::State::ConnectedState);
|
||||
w->connect(c, &QXmppClient::stateChanged,
|
||||
[account] (const QXmppClient::State state)
|
||||
{
|
||||
account->connected->setChecked(
|
||||
state == QXmppClient::State::ConnectedState);
|
||||
});
|
||||
|
||||
it->setSizeHint(w->sizeHint());
|
||||
ui.accounts_list->addItem(it);
|
||||
ui.accounts_list->setItemWidget(it, w);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef ACCOUNTS_H
|
||||
#define ACCOUNTS_H
|
||||
|
||||
#include "ui_accounts.h"
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QString>
|
||||
#include <QXmppClient.h>
|
||||
|
||||
class Accounts : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Accounts(const QList<QXmppClient *> &accounts, QWidget *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void new_account(QXmppClient *c);
|
||||
|
||||
private:
|
||||
void add(QXmppClient *c);
|
||||
Ui_accounts ui;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>accounts</class>
|
||||
<widget class="QDialog" name="accounts">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>188</width>
|
||||
<height>173</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>100</horstretch>
|
||||
<verstretch>100</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>xxcc - Accounts</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">Accounts</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="accounts_list"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="rm">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>contact</class>
|
||||
<widget class="QWidget" name="contact">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>117</width>
|
||||
<height>60</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="picture">
|
||||
<property name="text">
|
||||
<string>Picture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="contact_jid">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Contact</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="own_jid">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Own</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,56 @@
|
|||
#include "contacts.h"
|
||||
#include "ui_contact.h"
|
||||
#include <QListWidgetItem>
|
||||
|
||||
Contacts::Contacts(QList<JidDb *> &databases, QWidget *const parent) :
|
||||
QDialog(parent),
|
||||
databases(databases)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
for (const auto db : databases)
|
||||
for (const auto &contact : db->roster())
|
||||
add(db->jid, contact);
|
||||
|
||||
connect(ui.contacts_list, &QListWidget::itemActivated,
|
||||
[this]
|
||||
{
|
||||
ui.chat->setEnabled(true);
|
||||
});
|
||||
|
||||
connect(ui.chat, &QPushButton::released,
|
||||
[this]
|
||||
{
|
||||
const auto items = ui.contacts_list->selectedItems();
|
||||
|
||||
if (items.isEmpty())
|
||||
{
|
||||
ui.chat->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto it = items.first();
|
||||
const auto from = it->data(Role::From).toString(),
|
||||
to = it->data(Role::To).toString();
|
||||
|
||||
Q_EMIT startChat(from, to);
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
void Contacts::add(const QString &own, const QString &other)
|
||||
{
|
||||
const auto it = new QListWidgetItem(ui.contacts_list);
|
||||
const auto w = new QWidget;
|
||||
/* TODO: derive QWidget with Ui_contact as a member. */
|
||||
const auto contact = new Ui_contact;
|
||||
|
||||
contact->setupUi(w);
|
||||
contact->own_jid->setText(own);
|
||||
contact->contact_jid->setText(other);
|
||||
it->setSizeHint(w->sizeHint());
|
||||
it->setData(Role::From, QVariant(own));
|
||||
it->setData(Role::To, QVariant(own));
|
||||
ui.contacts_list->addItem(it);
|
||||
ui.contacts_list->setItemWidget(it, w);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef CONTACTS_H
|
||||
#define CONTACTS_H
|
||||
|
||||
#include "ui_contacts.h"
|
||||
#include "jiddb.h"
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
class Contacts : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Contacts(QList<JidDb *> &databases, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
Ui_contacts ui;
|
||||
QList<JidDb *> &databases;
|
||||
void add(const QString &own, const QString &other);
|
||||
enum Role {From = Qt::UserRole, To};
|
||||
|
||||
Q_SIGNALS:
|
||||
void startChat(QString from, QString to);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>contacts</class>
|
||||
<widget class="QDialog" name="contacts">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>278</width>
|
||||
<height>173</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>100</horstretch>
|
||||
<verstretch>100</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>xxcc - Contacts</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">Contacts</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="contacts_list"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="rm">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="chat">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Chat</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>conversation</class>
|
||||
<widget class="QWidget" name="conversation">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>189</width>
|
||||
<height>60</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="picture">
|
||||
<property name="text">
|
||||
<string>Picture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="contact">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Contact</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="message">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Last message</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="time">
|
||||
<property name="text">
|
||||
<string>Time</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,105 @@
|
|||
#include "credentials.h"
|
||||
#include <QEventLoop>
|
||||
#include <qt5keychain/keychain.h>
|
||||
#include <QXmppConfiguration.h>
|
||||
#include <iostream>
|
||||
|
||||
static const QString service = "xxcc", sep = ";";
|
||||
|
||||
QList<Credentials::Pair> Credentials::load()
|
||||
{
|
||||
const QStringList users = storedUsers();
|
||||
QList<Pair> ret;
|
||||
|
||||
for (const auto &user : users)
|
||||
{
|
||||
QKeychain::ReadPasswordJob job(service);
|
||||
QEventLoop loop;
|
||||
|
||||
job.setKey(user);
|
||||
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
||||
job.start();
|
||||
loop.exec();
|
||||
|
||||
const QString pwd = job.textData();
|
||||
|
||||
if (job.error())
|
||||
std::cerr << "Failed to retrieve password for " << qPrintable(user)
|
||||
<< ": " << qPrintable(job.errorString()) << std::endl;
|
||||
else
|
||||
ret.append(Pair(user, pwd));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Credentials::store(QXmppClient *c)
|
||||
{
|
||||
QKeychain::WritePasswordJob job(service);
|
||||
const QXmppConfiguration &cfg = c->configuration();
|
||||
const QString user = cfg.jidBare();
|
||||
QEventLoop loop;
|
||||
|
||||
job.setKey(user);
|
||||
job.setTextData(cfg.password());
|
||||
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
||||
job.start();
|
||||
loop.exec();
|
||||
|
||||
if (job.error())
|
||||
std::cerr << "Failed to store password: "
|
||||
<< qPrintable(job.errorString()) << std::endl;
|
||||
#if 0
|
||||
else
|
||||
storeUser(user);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Credentials::storeUser(const QString &user)
|
||||
{
|
||||
QString list = storedUsersList();
|
||||
QKeychain::WritePasswordJob job(service);
|
||||
QEventLoop loop;
|
||||
|
||||
if (!list.isEmpty())
|
||||
list += sep;
|
||||
|
||||
list += user;
|
||||
|
||||
job.setKey("users");
|
||||
job.setTextData(list);
|
||||
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
||||
job.start();
|
||||
loop.exec();
|
||||
|
||||
if (job.error())
|
||||
std::cerr << "Failed to store user: "
|
||||
<< qPrintable(job.errorString()) << std::endl;
|
||||
}
|
||||
|
||||
QString Credentials::storedUsersList()
|
||||
{
|
||||
QKeychain::ReadPasswordJob job(service);
|
||||
QString ret;
|
||||
QEventLoop loop;
|
||||
|
||||
job.setKey("users");
|
||||
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
|
||||
job.start();
|
||||
loop.exec();
|
||||
|
||||
const QString users = job.textData();
|
||||
|
||||
if (job.error())
|
||||
std::cerr << "Failed to retrieve users: "
|
||||
<< qPrintable(job.errorString()) << std::endl;
|
||||
else
|
||||
ret = users;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QStringList Credentials::storedUsers()
|
||||
{
|
||||
return storedUsersList().split(sep);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef CREDENTIALS_H
|
||||
#define CREDENTIALS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QStringList>
|
||||
#include <QXmppClient.h>
|
||||
|
||||
class Credentials : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Pair = QPair<QString, QString>;
|
||||
QList<Pair> load();
|
||||
|
||||
public Q_SLOTS:
|
||||
void store(QXmppClient *c);
|
||||
|
||||
private:
|
||||
static void storeUser(const QString &user);
|
||||
static QString storedUsersList();
|
||||
static QStringList storedUsers();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,54 @@
|
|||
#include "jiddb.h"
|
||||
#include <QDir>
|
||||
#include <QSqlQuery>
|
||||
#include <QStandardPaths>
|
||||
#include <QVariant>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
JidDb::JidDb(const QString &jid) :
|
||||
jid(jid),
|
||||
db(QSqlDatabase::addDatabase("QSQLITE"))
|
||||
{
|
||||
const auto path = QStandardPaths::writableLocation(
|
||||
QStandardPaths::AppDataLocation);
|
||||
QDir dir;
|
||||
|
||||
if (!dir.exists(path) && !dir.mkdir(path))
|
||||
throw std::runtime_error("Failed to create app dir");
|
||||
|
||||
const auto abspath = path + "/" + jid + ".db";
|
||||
|
||||
db.setDatabaseName(abspath);
|
||||
|
||||
if (!db.open())
|
||||
throw std::runtime_error(qPrintable("database" + abspath
|
||||
+ "could not be created"));
|
||||
|
||||
QSqlQuery q(db);
|
||||
|
||||
if (!q.exec("create table if not exists roster (jid TEXT) strict;"))
|
||||
std::cerr << "query exec failed" << std::endl;
|
||||
}
|
||||
|
||||
void JidDb::addToRoster(const QString &jid) const
|
||||
{
|
||||
QSqlQuery q(db);
|
||||
|
||||
if (!q.exec("insert into if not exists roster (jid) values (" + jid +");"))
|
||||
throw std::runtime_error("JidDb::addToRoster: query exec failed");
|
||||
}
|
||||
|
||||
QStringList JidDb::roster() const
|
||||
{
|
||||
QStringList ret;
|
||||
QSqlQuery q(db);
|
||||
|
||||
if (!q.exec("select jid from roster;"))
|
||||
std::cerr << "query exec failed" << std::endl;
|
||||
else
|
||||
while (q.next())
|
||||
ret.append(q.value("jid").toString());
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef JID_DB_H
|
||||
#define JID_DB_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
class JidDb : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
JidDb(const QString &jid);
|
||||
QStringList roster() const;
|
||||
const QString jid;
|
||||
|
||||
public Q_SLOTS:
|
||||
void addToRoster(const QString &jid) const;
|
||||
|
||||
private:
|
||||
QSqlDatabase db;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,150 @@
|
|||
#include "login.h"
|
||||
#include "ui_login.h"
|
||||
#include <QString>
|
||||
#include "QXmppStanza.h"
|
||||
#include <memory>
|
||||
|
||||
static QString error_to_str(const QXmppStanza::Error::Condition c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case QXmppStanza::Error::BadRequest:
|
||||
return "BadRequest";
|
||||
case QXmppStanza::Error::Conflict:
|
||||
return "Conflict";
|
||||
case QXmppStanza::Error::FeatureNotImplemented:
|
||||
return "FeatureNotImplemented";
|
||||
case QXmppStanza::Error::Forbidden:
|
||||
return "Forbidden";
|
||||
case QXmppStanza::Error::Gone:
|
||||
return "Gone";
|
||||
case QXmppStanza::Error::InternalServerError:
|
||||
return "internal server error";
|
||||
case QXmppStanza::Error::ItemNotFound:
|
||||
return "item not found";
|
||||
case QXmppStanza::Error::JidMalformed:
|
||||
return "JID Malformed";
|
||||
case QXmppStanza::Error::NotAcceptable:
|
||||
return "not acceptable";
|
||||
case QXmppStanza::Error::NotAllowed:
|
||||
return "not allowed";
|
||||
case QXmppStanza::Error::NotAuthorized:
|
||||
return "not authorized";
|
||||
case QXmppStanza::Error::RecipientUnavailable:
|
||||
return "recipient unavailable";
|
||||
case QXmppStanza::Error::Redirect:
|
||||
return "Redirect";
|
||||
case QXmppStanza::Error::RegistrationRequired:
|
||||
return "RegistrationRequired";
|
||||
case QXmppStanza::Error::RemoteServerNotFound:
|
||||
return "RemoteServerNotFound";
|
||||
case QXmppStanza::Error::RemoteServerTimeout:
|
||||
return "RemoteServerTimeout";
|
||||
case QXmppStanza::Error::ResourceConstraint:
|
||||
return "ResourceConstraint";
|
||||
case QXmppStanza::Error::ServiceUnavailable:
|
||||
return "ServiceUnavailable";
|
||||
case QXmppStanza::Error::SubscriptionRequired:
|
||||
return "SubscriptionRequired";
|
||||
case QXmppStanza::Error::UndefinedCondition:
|
||||
return "UndefinedCondition";
|
||||
case QXmppStanza::Error::UnexpectedRequest:
|
||||
return "UnexpectedRequest";
|
||||
case QXmppStanza::Error::PolicyViolation:
|
||||
return "PolicyViolation";
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return "UnknownError";
|
||||
}
|
||||
|
||||
Login::Login(QDialog *const parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
ui.error->setVisible(false);
|
||||
|
||||
connect(ui.next, &QPushButton::released,
|
||||
[sw = ui.sw]
|
||||
{
|
||||
sw->setCurrentIndex(sw->currentIndex() + 1);
|
||||
});
|
||||
|
||||
connect(ui.back, &QPushButton::released,
|
||||
[sw = ui.sw]
|
||||
{
|
||||
const int i = sw->currentIndex();
|
||||
|
||||
if (i)
|
||||
sw->setCurrentIndex(i - 1);
|
||||
});
|
||||
|
||||
connect(ui.login_b, &QPushButton::released,
|
||||
[this]
|
||||
{
|
||||
const QString jid = ui.username->text(), pwd = ui.password->text();
|
||||
QString domain, error;
|
||||
|
||||
if (!jid_is_valid(jid, domain))
|
||||
error = tr("Invalid username");
|
||||
else if (pwd.isEmpty())
|
||||
error = tr("Invalid password");
|
||||
else
|
||||
setup(jid, pwd, domain);
|
||||
|
||||
ui.error->setText(error);
|
||||
ui.error->setVisible(!error.isEmpty());
|
||||
});
|
||||
}
|
||||
|
||||
bool Login::jid_is_valid(const QString &jid, QString &domain)
|
||||
{
|
||||
if (jid.isEmpty() || jid.count('@') != 1)
|
||||
return false;
|
||||
else if ((domain = jid.mid(jid.indexOf('@') + 1)).isEmpty())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Login::setup(const QString &jid, const QString pwd, const QString &domain)
|
||||
{
|
||||
QXmppConfiguration cfg;
|
||||
|
||||
cfg.setStreamSecurityMode(QXmppConfiguration::TLSRequired);
|
||||
cfg.setJid(jid);
|
||||
cfg.setPassword(pwd);
|
||||
cfg.setAutoReconnectionEnabled(false);
|
||||
|
||||
auto client = new QXmppClient;
|
||||
|
||||
connect(client, &QXmppClient::stateChanged,
|
||||
[d = domain, e = ui.error] (const QXmppClient::State state)
|
||||
{
|
||||
if (state == QXmppClient::ConnectingState)
|
||||
{
|
||||
e->setVisible(true);
|
||||
e->setText(tr("Connecting to ") + d + "...");
|
||||
}
|
||||
});
|
||||
|
||||
connect(client, &QXmppClient::connected,
|
||||
[this, client]
|
||||
{
|
||||
Q_EMIT auth_success(client);
|
||||
close();
|
||||
});
|
||||
|
||||
connect(client, &QXmppClient::disconnected,
|
||||
[client, e = ui.error]
|
||||
{
|
||||
e->setText("Disconnected from server: "
|
||||
+ error_to_str(client->xmppStreamError()));
|
||||
e->setVisible(true);
|
||||
delete client;
|
||||
});
|
||||
|
||||
client->connectToServer(cfg);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef LOGIN_H
|
||||
#define LOGIN_H
|
||||
|
||||
#include "ui_login.h"
|
||||
#include <QDialog>
|
||||
#include <QString>
|
||||
#include <QXmppClient.h>
|
||||
|
||||
class Login : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Login(QDialog *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void auth_success(QXmppClient *c);
|
||||
|
||||
private:
|
||||
void setup(const QString &jid, const QString pwd, const QString &domain);
|
||||
static bool jid_is_valid(const QString &jid, QString &domain);
|
||||
Ui_login ui;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,191 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>login</class>
|
||||
<widget class="QDialog" name="login">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>323</width>
|
||||
<height>104</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Log into a XMPP server</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="sw">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="username_tab">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="username">
|
||||
<property name="inputMethodHints">
|
||||
<set>Qt::ImhEmailCharactersOnly|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Enter JID</string>
|
||||
</property>
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="next">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Next</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="password_tab">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="password">
|
||||
<property name="inputMethodHints">
|
||||
<set>Qt::ImhHiddenText|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhSensitiveData</set>
|
||||
</property>
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Enter password</string>
|
||||
</property>
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="error">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="back">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Back</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Create account</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="login_b">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>cancel</sender>
|
||||
<signal>released()</signal>
|
||||
<receiver>login</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>86</x>
|
||||
<y>71</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>161</x>
|
||||
<y>51</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -0,0 +1,11 @@
|
|||
#include "xxcc.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
xxcc x;
|
||||
x.show();
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>message</class>
|
||||
<widget class="QWidget" name="message">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>278</width>
|
||||
<height>76</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="quote">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Quote</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="edit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="retry">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Retry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="text">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,15 @@
|
|||
set(BUILD_SHARED OFF)
|
||||
set(BUILD_OMEMO ON)
|
||||
set(BUILD_TESTS OFF)
|
||||
add_subdirectory(qxmpp)
|
||||
target_link_libraries(xxcc PRIVATE
|
||||
QXmppQt${QT_VERSION_MAJOR}
|
||||
QXmppOmemoQt${QT_VERSION_MAJOR})
|
||||
target_include_directories(QXmppQt${QT_VERSION_MAJOR} PRIVATE
|
||||
${CMAKE_BINARY_DIR}/qxmpp/qxmpp/src)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_BINARY_DIR}/qxmpp/qxmpp/src)
|
||||
target_include_directories(QXmppOmemoQt${QT_VERSION_MAJOR} PRIVATE
|
||||
${CMAKE_BINARY_DIR}/qxmpp/qxmpp/src/omemo)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_BINARY_DIR}/qxmpp/qxmpp/src/omemo)
|
|
@ -1 +1 @@
|
|||
Subproject commit 6fe82239fc55b16953f965ea4e20e5fbfe806dd5
|
||||
Subproject commit 697249844a4bdf70165e97f77e71cbabbfee5933
|
|
@ -0,0 +1,130 @@
|
|||
#include "xxcc.h"
|
||||
#include "accounts.h"
|
||||
#include "contacts.h"
|
||||
#include "ui_message.h"
|
||||
#include <QPushButton>
|
||||
#include <utility>
|
||||
|
||||
xxcc::xxcc(QWidget *const parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
const auto pairs = creds.load();
|
||||
|
||||
ui.setupUi(this);
|
||||
setupDatabases(pairs);
|
||||
connectAccounts(pairs);
|
||||
connect(ui.accounts, &QPushButton::released,
|
||||
[this]
|
||||
{
|
||||
Accounts a(clients, this);
|
||||
|
||||
a.connect(&a, &Accounts::new_account,
|
||||
[this] (QXmppClient *c)
|
||||
{
|
||||
c->configuration().setAutoReconnectionEnabled(true);
|
||||
clients.append(c);
|
||||
});
|
||||
|
||||
a.connect(&a, &Accounts::new_account, &creds, &Credentials::store);
|
||||
a.exec();
|
||||
});
|
||||
|
||||
connect(ui.contacts, &QPushButton::released,
|
||||
[this]
|
||||
{
|
||||
Contacts c(databases, this);
|
||||
|
||||
connect(&c, &Contacts::startChat, this, &xxcc::startChat);
|
||||
c.exec();
|
||||
});
|
||||
|
||||
connect(ui.back, &QPushButton::released,
|
||||
[this]
|
||||
{
|
||||
ui.sw->setCurrentIndex(static_cast<int>(Tab::Conversations));
|
||||
});
|
||||
|
||||
/* TODO: remove */
|
||||
addMessage("Hi! This is a test");
|
||||
addMessage("Hi! This is a multi-line test\nLet's see how it works!");
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
addMessage("Test " + QString::number(i));
|
||||
}
|
||||
|
||||
xxcc::~xxcc()
|
||||
{
|
||||
for (auto c : clients)
|
||||
delete c;
|
||||
|
||||
for (auto db : databases)
|
||||
delete db;
|
||||
}
|
||||
|
||||
void xxcc::connectAccounts(const QList<Credentials::Pair> &pairs)
|
||||
{
|
||||
for (const auto &p : pairs)
|
||||
{
|
||||
QXmppConfiguration cfg;
|
||||
|
||||
cfg.setStreamSecurityMode(QXmppConfiguration::TLSRequired);
|
||||
cfg.setJid(p.first);
|
||||
cfg.setPassword(p.second);
|
||||
cfg.setAutoReconnectionEnabled(true);
|
||||
|
||||
auto client = new QXmppClient;
|
||||
|
||||
connect(client, &QXmppClient::connected,
|
||||
[this, client]
|
||||
{
|
||||
clients.append(client);
|
||||
});
|
||||
|
||||
connect(client, &QXmppClient::disconnected,
|
||||
[client]
|
||||
{
|
||||
delete client;
|
||||
});
|
||||
|
||||
client->connectToServer(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
void xxcc::setupDatabases(const QList<Credentials::Pair> &pairs)
|
||||
{
|
||||
for (const auto &p : pairs)
|
||||
databases.append(new JidDb(p.first));
|
||||
}
|
||||
|
||||
void xxcc::startChat(const QString from, const QString to)
|
||||
{
|
||||
ui.sw->setCurrentIndex(static_cast<int>(Tab::Chat));
|
||||
ui.jid->setText(to);
|
||||
}
|
||||
|
||||
void xxcc::addMessage(const QString msg)
|
||||
{
|
||||
const auto it = new QListWidgetItem(ui.messages);
|
||||
const auto w = new QWidget;
|
||||
/* TODO: derive QWidget with Ui_message as a member. */
|
||||
const auto msg_ui = new Ui_message;
|
||||
|
||||
msg_ui->setupUi(w);
|
||||
msg_ui->text->setText(msg);
|
||||
it->setSizeHint(w->sizeHint());
|
||||
ui.messages->addItem(it);
|
||||
ui.messages->setItemWidget(it, w);
|
||||
msg_ui->edit->setVisible(false);
|
||||
msg_ui->quote->setVisible(false);
|
||||
msg_ui->retry->setVisible(false);
|
||||
|
||||
w->connect(ui.messages, &QListWidget::itemActivated,
|
||||
[it, msg_ui] (QListWidgetItem *const item)
|
||||
{
|
||||
const bool visible = item == it;
|
||||
|
||||
msg_ui->edit->setVisible(visible);
|
||||
msg_ui->quote->setVisible(visible);
|
||||
msg_ui->retry->setVisible(visible);
|
||||
});
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef XXCC_H
|
||||
#define XXCC_H
|
||||
|
||||
#include "ui_xxcc.h"
|
||||
#include "credentials.h"
|
||||
#include "jiddb.h"
|
||||
#include <QList>
|
||||
#include <QWidget>
|
||||
#include <QSqlDatabase>
|
||||
#include <QString>
|
||||
#include <QXmppClient.h>
|
||||
|
||||
class xxcc : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
xxcc(QWidget *parent = nullptr);
|
||||
~xxcc();
|
||||
|
||||
private:
|
||||
enum Tab {Conversations, Chat};
|
||||
Ui_main ui;
|
||||
QList<QXmppClient *> clients;
|
||||
QList<JidDb *> databases;
|
||||
Credentials creds;
|
||||
void setupDatabases(const QList<Credentials::Pair> &pairs);
|
||||
void connectAccounts(const QList<Credentials::Pair> &pairs);
|
||||
|
||||
private Q_SLOTS:
|
||||
void startChat(QString from, QString to);
|
||||
void addMessage(QString msg);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,213 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>main</class>
|
||||
<widget class="QWidget" name="main">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>290</width>
|
||||
<height>248</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>100</horstretch>
|
||||
<verstretch>100</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>xxcc</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="sw">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeIncrement">
|
||||
<size>
|
||||
<width>13767</width>
|
||||
<height>13767</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="conversations">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">xxcc</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="conversations_list"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="accounts">
|
||||
<property name="text">
|
||||
<string>Accounts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="contacts">
|
||||
<property name="text">
|
||||
<string>Contacts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rooms">
|
||||
<property name="text">
|
||||
<string>Rooms</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="chat_tab">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="back">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="jid">
|
||||
<property name="text">
|
||||
<string notr="true"><html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">Contact name</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="messages"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="chatinput_hbox">
|
||||
<property name="spacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="chatinput">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="midLineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="tabChangesFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="backgroundVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Write a message...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="send">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OMEMO</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue