diff --git a/smsapp/CMakeLists.txt b/smsapp/CMakeLists.txt index 8aadde5d..a3d9e877 100644 --- a/smsapp/CMakeLists.txt +++ b/smsapp/CMakeLists.txt @@ -1,7 +1,7 @@ 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) install(TARGETS kdeconnect-sms ${INSTALL_TARGETS_DEFAULT_ARGS}) install(PROGRAMS org.kde.kdeconnect.sms.desktop DESTINATION ${KDE_INSTALL_APPDIR}) diff --git a/smsapp/conversationmodel.cpp b/smsapp/conversationmodel.cpp new file mode 100644 index 00000000..0aac7251 --- /dev/null +++ b/smsapp/conversationmodel.cpp @@ -0,0 +1,43 @@ +/* + * This file is part of KDE Telepathy Chat + * + * Copyright (C) 2018 Aleix Pol Gonzalez + * + * 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"))); +} diff --git a/smsapp/conversationmodel.h b/smsapp/conversationmodel.h new file mode 100644 index 00000000..d504b566 --- /dev/null +++ b/smsapp/conversationmodel.h @@ -0,0 +1,44 @@ +/* + * This file is part of KDE Telepathy Chat + * + * Copyright (C) 2018 Aleix Pol Gonzalez + * + * 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 + +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 diff --git a/smsapp/main.cpp b/smsapp/main.cpp index 58c6dc64..77072586 100644 --- a/smsapp/main.cpp +++ b/smsapp/main.cpp @@ -1,54 +1,58 @@ /* * This file is part of KDE Telepathy Chat * * Copyright (C) 2015 Aleix Pol Gonzalez * * 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 #include #include #include #include #include #include #include +#include "conversationmodel.h" #include "kdeconnect-version.h" +#include int main(int argc, char *argv[]) { QApplication app(argc, argv); KAboutData aboutData("org.kde.kdeconnect.sms", i18n("SMS Instant Messaging"), QStringLiteral(KDECONNECT_VERSION_STRING), i18n("KDE Connect SMS"), KAboutLicense::GPL, i18n("(c) 2018, Aleix Pol Gonzalez")); aboutData.addAuthor(i18n("Aleix Pol Gonzalez"), {}, "aleixpol@kde.org"); KAboutData::setApplicationData(aboutData); { QCommandLineParser parser; aboutData.setupCommandLine(&parser); parser.addVersionOption(); parser.addHelpOption(); parser.process(app); aboutData.processCommandLine(&parser); } KDBusService service(KDBusService::Unique); + qmlRegisterType("org.kde.kdeconnect.sms", 1, 0, "ConversationModel"); + QQmlApplicationEngine engine; engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.load(QUrl("qrc:/qml/main.qml")); return app.exec(); } diff --git a/smsapp/qml/ConversationDisplay.qml b/smsapp/qml/ConversationDisplay.qml index 03e82cf1..00825fb0 100644 --- a/smsapp/qml/ConversationDisplay.qml +++ b/smsapp/qml/ConversationDisplay.qml @@ -1,70 +1,69 @@ /* * This file is part of KDE Telepathy Chat * * Copyright (C) 2015 Aleix Pol Gonzalez * * 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 */ import QtQuick 2.1 import QtQuick.Controls 2.1 import QtQuick.Layouts 1.1 import org.kde.kirigami 2.2 as Kirigami +import org.kde.kdeconnect.sms 1.0 Kirigami.ScrollablePage { id: page property QtObject person property QtObject device readonly property string phoneNumber: person.contactCustomProperty("phoneNumber") readonly property QtObject telephony: device ? TelephonyDbusInterfaceFactory.create(device.id()) : null title: i18n("%1: %2", person.name, phoneNumber) ListView { - model: ListModel { - ListElement { display: "aaa"; fromMe: true } - ListElement { display: "aaa" } - ListElement { display: "aaa"; fromMe: true } - ListElement { display: "aaa" } - ListElement { display: "aaa" } - ListElement { display: "aaa" } + model: ConversationModel { + id: model + deviceId: device.id() + threadId: "xxxx" } + delegate: Kirigami.BasicListItem { readonly property real margin: 100 x: fromMe ? Kirigami.Units.gridUnit : margin width: parent.width - margin - Kirigami.Units.gridUnit contentItem: Label { text: model.display } } } footer: RowLayout { enabled: page.device TextField { id: message Layout.fillWidth: true placeholderText: i18n("Say hi...") onAccepted: { console.log("sending sms", page.phoneNumber) page.telephony.sendSms(page.phoneNumber, message.text) } } Button { text: "Send" onClicked: { message.accepted() } } } }