Move the dummy conversation model to c++
This commit is contained in:
parent
4097b6f71f
commit
8dba3898e5
5 changed files with 98 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
qt5_add_resources(KCSMS_SRCS resources.qrc)
|
qt5_add_resources(KCSMS_SRCS resources.qrc)
|
||||||
|
|
||||||
add_executable(kdeconnect-sms main.cpp ${KCSMS_SRCS})
|
add_executable(kdeconnect-sms main.cpp conversationmodel.cpp ${KCSMS_SRCS})
|
||||||
target_link_libraries(kdeconnect-sms Qt5::Quick Qt5::Widgets KF5::DBusAddons KF5::CoreAddons KF5::I18n)
|
target_link_libraries(kdeconnect-sms Qt5::Quick Qt5::Widgets KF5::DBusAddons KF5::CoreAddons KF5::I18n)
|
||||||
|
|
||||||
install(TARGETS kdeconnect-sms ${INSTALL_TARGETS_DEFAULT_ARGS})
|
install(TARGETS kdeconnect-sms ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
|
|
43
smsapp/conversationmodel.cpp
Normal file
43
smsapp/conversationmodel.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* This file is part of KDE Telepathy Chat
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "conversationmodel.h"
|
||||||
|
|
||||||
|
ConversationModel::ConversationModel(QObject* parent)
|
||||||
|
: QStandardItemModel(parent)
|
||||||
|
{
|
||||||
|
auto roles = roleNames();
|
||||||
|
roles.insert(FromMeRole, "fromMe");
|
||||||
|
setItemRoleNames(roles);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConversationModel::threadId() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConversationModel::setThreadId(const QString &threadId)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
appendRow(new QStandardItem(threadId + QStringLiteral(" - A")));
|
||||||
|
appendRow(new QStandardItem(threadId + QStringLiteral(" - A1")));
|
||||||
|
appendRow(new QStandardItem(threadId + QStringLiteral(" - A2")));
|
||||||
|
appendRow(new QStandardItem(threadId + QStringLiteral(" - A3")));
|
||||||
|
}
|
44
smsapp/conversationmodel.h
Normal file
44
smsapp/conversationmodel.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* This file is part of KDE Telepathy Chat
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONVERSATIONMODEL_H
|
||||||
|
#define CONVERSATIONMODEL_H
|
||||||
|
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
|
class ConversationModel : public QStandardItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString threadId READ threadId WRITE setThreadId)
|
||||||
|
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId)
|
||||||
|
|
||||||
|
public:
|
||||||
|
ConversationModel(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
enum Roles { FromMeRole = Qt::UserRole };
|
||||||
|
|
||||||
|
QString threadId() const;
|
||||||
|
void setThreadId(const QString &threadId);
|
||||||
|
|
||||||
|
QString deviceId() const { return {}; }
|
||||||
|
void setDeviceId(const QString &/*deviceId*/) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONVERSATIONMODEL_H
|
|
@ -26,7 +26,9 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KLocalizedContext>
|
#include <KLocalizedContext>
|
||||||
#include <KDBusService>
|
#include <KDBusService>
|
||||||
|
#include "conversationmodel.h"
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
#include <QtQml>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -46,6 +48,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
KDBusService service(KDBusService::Unique);
|
KDBusService service(KDBusService::Unique);
|
||||||
|
|
||||||
|
qmlRegisterType<ConversationModel>("org.kde.kdeconnect.sms", 1, 0, "ConversationModel");
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||||
engine.load(QUrl("qrc:/qml/main.qml"));
|
engine.load(QUrl("qrc:/qml/main.qml"));
|
||||||
|
|
|
@ -22,6 +22,7 @@ import QtQuick 2.1
|
||||||
import QtQuick.Controls 2.1
|
import QtQuick.Controls 2.1
|
||||||
import QtQuick.Layouts 1.1
|
import QtQuick.Layouts 1.1
|
||||||
import org.kde.kirigami 2.2 as Kirigami
|
import org.kde.kirigami 2.2 as Kirigami
|
||||||
|
import org.kde.kdeconnect.sms 1.0
|
||||||
|
|
||||||
Kirigami.ScrollablePage
|
Kirigami.ScrollablePage
|
||||||
{
|
{
|
||||||
|
@ -34,14 +35,12 @@ Kirigami.ScrollablePage
|
||||||
title: i18n("%1: %2", person.name, phoneNumber)
|
title: i18n("%1: %2", person.name, phoneNumber)
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
model: ListModel {
|
model: ConversationModel {
|
||||||
ListElement { display: "aaa"; fromMe: true }
|
id: model
|
||||||
ListElement { display: "aaa" }
|
deviceId: device.id()
|
||||||
ListElement { display: "aaa"; fromMe: true }
|
threadId: "xxxx"
|
||||||
ListElement { display: "aaa" }
|
|
||||||
ListElement { display: "aaa" }
|
|
||||||
ListElement { display: "aaa" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: Kirigami.BasicListItem {
|
delegate: Kirigami.BasicListItem {
|
||||||
readonly property real margin: 100
|
readonly property real margin: 100
|
||||||
x: fromMe ? Kirigami.Units.gridUnit : margin
|
x: fromMe ? Kirigami.Units.gridUnit : margin
|
||||||
|
|
Loading…
Reference in a new issue