summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-03 18:29:18 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-03 18:29:18 +0100
commit997e9b168d362a50cdcdc82c6cc3488a6852737a (patch)
treefebf644d675ef07128f5c313e78a728a97aee89c
parent0311bed34d80abe518f11838271e39d1615ebf67 (diff)
Load conversations dynamically
-rw-r--r--CMakeLists.txt2
-rw-r--r--ContactList.qml22
-rw-r--r--Main.qml5
-rw-r--r--conversationmodel.cpp34
-rw-r--r--conversationmodel.h30
-rw-r--r--jiddb.cpp2
-rw-r--r--main.cpp5
-rw-r--r--yc.cpp10
-rw-r--r--yc.h5
9 files changed, 103 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f3bcb9..9fcd152 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,8 @@ qt_add_executable(${PROJECT_NAME}
atm_db.h
client.cpp
client.h
+ conversationmodel.cpp
+ conversationmodel.h
credentials.cpp
credentials.h
direction.h
diff --git a/ContactList.qml b/ContactList.qml
index f75aca6..fa83d51 100644
--- a/ContactList.qml
+++ b/ContactList.qml
@@ -2,6 +2,7 @@ import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
+import org.yachat.app 1.0
Page
{
@@ -16,17 +17,34 @@ Page
}
}
+ ConversationModel
+ {
+ id: cmodel
+ }
+
+ Connections
+ {
+ target: Yc
+ function onNewConversation(value)
+ {
+ cmodel.append(value)
+ }
+ }
+
ListView
{
width: parent.width
anchors.fill: parent
+ anchors.horizontalCenter: parent.horizontalCenter
+ model: cmodel
delegate: ItemDelegate
{
width: parent.width
- text: modelData
+ text: cmodel.conversations
+ anchors.horizontalCenter: parent.horizontalCenter
onClicked: stack.push("qrc:/org/yachat/app/ChatView.qml",
{
- destination: modelData
+ destination: cmodel.conversations
})
}
}
diff --git a/Main.qml b/Main.qml
index 7c5f217..380da63 100644
--- a/Main.qml
+++ b/Main.qml
@@ -32,10 +32,5 @@ ApplicationWindow
Component.onCompleted:
{
Yc.init()
- // Test.awesome = true;
- // Test.updateAwesomeness(true);
- // console.log("awesome is ", Test.isAwesome);
- // Test.updateAwesomeness(false);
- // console.log("awesome is ", Test.isAwesome);
}
}
diff --git a/conversationmodel.cpp b/conversationmodel.cpp
new file mode 100644
index 0000000..8257fb1
--- /dev/null
+++ b/conversationmodel.cpp
@@ -0,0 +1,34 @@
+#include "conversationmodel.h"
+#include <QAbstractItemModel>
+
+int ConversationModel::rowCount(const QModelIndex &parent) const
+{
+ qDebug() << conversations.count();
+ return conversations.count();
+}
+
+QVariant ConversationModel::data(const QModelIndex &index, int role) const
+{
+ qDebug() << conversations;
+ return conversations.at(index.row());
+}
+
+void ConversationModel::append(const QString &value)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ endInsertRows();
+ conversations << value;
+ qDebug() << conversations;
+ qDebug() << conversations.count();
+}
+
+bool ConversationModel::setData(const QModelIndex &index, const QVariant &value,
+ int role)
+{
+ return false;
+}
+
+QStringList ConversationModel::getConversations() const
+{
+ return conversations;
+}
diff --git a/conversationmodel.h b/conversationmodel.h
new file mode 100644
index 0000000..971d36f
--- /dev/null
+++ b/conversationmodel.h
@@ -0,0 +1,30 @@
+#ifndef CONVERSATION_MODEL_H
+#define CONVERSATION_MODEL_H
+
+#include <QAbstractListModel>
+#include <QQmlApplicationEngine>
+#include <QVariant>
+
+class ConversationModel : public QAbstractListModel
+{
+ Q_OBJECT
+ QML_ELEMENT
+
+ Q_PROPERTY(QStringList conversations READ getConversations NOTIFY conversationsChanged)
+
+public:
+ Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override;
+ Q_INVOKABLE void append(const QString &value);
+ QStringList getConversations() const;
+
+private:
+ QStringList conversations;
+
+signals:
+ void conversationsChanged();
+};
+
+#endif
diff --git a/jiddb.cpp b/jiddb.cpp
index 53d77e0..7853ff8 100644
--- a/jiddb.cpp
+++ b/jiddb.cpp
@@ -246,6 +246,8 @@ QList<JidDb::Conversation> JidDb::conversations() const
const auto conversations = tables();
QList<Conversation> ret;
+ qDebug() << conversations;
+
for (const auto &jid : conversations)
if (jid.contains('@'))
{
diff --git a/main.cpp b/main.cpp
index fd9a56e..7e4f5d9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,13 +5,16 @@
#include <QVariant>
#include <memory>
#include "yc.h"
+#include "conversationmodel.h"
int main(int argc, char *argv[])
{
+ static const char uri[] = "org.yachat.app";
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine("qrc:/org/yachat/app/Main.qml");
- qmlRegisterSingletonType<Yc>("org.yachat.app", 1, 0, "Yc",
+ qmlRegisterType<ConversationModel>(uri, 1, 0, "ConversationModel");
+ qmlRegisterSingletonType<Yc>(uri, 1, 0, "Yc",
[](QQmlEngine *, QJSEngine *) -> QObject *
{
return std::make_unique<Yc>().release();
diff --git a/yc.cpp b/yc.cpp
index fc132c1..08bcb31 100644
--- a/yc.cpp
+++ b/yc.cpp
@@ -147,18 +147,22 @@ void Yc::storeMessage(const QXmppMessage &msg, const Direction dir) const
storeMessage(msg.from(), msg.to(), msg.body(), msg.stamp(), dir);
}
-void Yc::retrieveConversations() const
+void Yc::retrieveConversations()
{
-#if 0
for (const auto c : clients)
{
const auto &db = c->database();
for (const auto &conv : db.conversations())
+ {
+#if 0
new Conversation(db.jid, conv.to,
ui.conversations_list, conv.last_msg, conv.dt);
- }
+#else
+ emit newConversation(conv.to);
#endif
+ }
+ }
}
void Yc::init()
diff --git a/yc.h b/yc.h
index 3d07176..0679b4d 100644
--- a/yc.h
+++ b/yc.h
@@ -26,12 +26,15 @@ private:
void storeMessage(const QString &from, const QString &to,
const QString &msg, const QDateTime &dt, const Direction dir) const;
void storeMessage(const QXmppMessage &msg, const Direction dir) const;
- void retrieveConversations() const;
+ void retrieveConversations();
enum Tab {Conversations, Chat};
QList<Client *> clients;
Credentials creds;
Client *selected;
+
+signals:
+ void newConversation(QString value);
};
#endif