summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-03 23:06:44 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-03 23:06:44 +0100
commitb934e6b0fdcc56f2cca1cca9ebce289cebaaafa2 (patch)
tree686950abbdc508561a635d5551a38d811c75d337
parent997e9b168d362a50cdcdc82c6cc3488a6852737a (diff)
downloadyachat6-b934e6b0fdcc56f2cca1cca9ebce289cebaaafa2.tar.gz
Replace ConversationModel with ListModel
-rw-r--r--CMakeLists.txt2
-rw-r--r--ContactList.qml34
-rw-r--r--conversationmodel.cpp34
-rw-r--r--conversationmodel.h30
-rw-r--r--main.cpp2
-rw-r--r--yc.cpp2
-rw-r--r--yc.h2
7 files changed, 23 insertions, 83 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9fcd152..8f3bcb9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,8 +20,6 @@ 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 fa83d51..0eee13b 100644
--- a/ContactList.qml
+++ b/ContactList.qml
@@ -17,34 +17,42 @@ Page
}
}
- ConversationModel
+ ListView
{
- id: cmodel
- }
+ ListModel
+ {
+ id: cmodel
+ }
- Connections
- {
- target: Yc
- function onNewConversation(value)
+ Connections
{
- cmodel.append(value)
+ target: Yc
+ function onNewConversation(jid, to, lastmsg)
+ {
+ console.log("jid:", jid, ", to:", to, ", lastmsg:", lastmsg)
+ cmodel.append({
+ "jid": jid,
+ "to": to,
+ "lastmsg": lastmsg,
+ })
+ }
}
- }
- ListView
- {
width: parent.width
anchors.fill: parent
anchors.horizontalCenter: parent.horizontalCenter
model: cmodel
delegate: ItemDelegate
{
+ required property int index
+ required property var model
+
width: parent.width
- text: cmodel.conversations
+ text: "<b>" + model.jid + "</b>"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: stack.push("qrc:/org/yachat/app/ChatView.qml",
{
- destination: cmodel.conversations
+ destination: model.to
})
}
}
diff --git a/conversationmodel.cpp b/conversationmodel.cpp
deleted file mode 100644
index 8257fb1..0000000
--- a/conversationmodel.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#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
deleted file mode 100644
index 971d36f..0000000
--- a/conversationmodel.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#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/main.cpp b/main.cpp
index 7e4f5d9..d2581e2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,7 +5,6 @@
#include <QVariant>
#include <memory>
#include "yc.h"
-#include "conversationmodel.h"
int main(int argc, char *argv[])
{
@@ -13,7 +12,6 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine("qrc:/org/yachat/app/Main.qml");
- qmlRegisterType<ConversationModel>(uri, 1, 0, "ConversationModel");
qmlRegisterSingletonType<Yc>(uri, 1, 0, "Yc",
[](QQmlEngine *, QJSEngine *) -> QObject *
{
diff --git a/yc.cpp b/yc.cpp
index 08bcb31..94798f6 100644
--- a/yc.cpp
+++ b/yc.cpp
@@ -159,7 +159,7 @@ void Yc::retrieveConversations()
new Conversation(db.jid, conv.to,
ui.conversations_list, conv.last_msg, conv.dt);
#else
- emit newConversation(conv.to);
+ emit newConversation(db.jid, conv.to, conv.last_msg);
#endif
}
}
diff --git a/yc.h b/yc.h
index 0679b4d..0bfa786 100644
--- a/yc.h
+++ b/yc.h
@@ -34,7 +34,7 @@ private:
Client *selected;
signals:
- void newConversation(QString value);
+ void newConversation(QString jid, QString to, QString lastmsg);
};
#endif