Skip to content

Commit

Permalink
Merge pull request #23 from nemomobile-ux/qt6
Browse files Browse the repository at this point in the history
Move to Qt6
  • Loading branch information
neochapay authored Oct 19, 2023
2 parents fc0f43f + 174742e commit d5b5f36
Show file tree
Hide file tree
Showing 23 changed files with 524 additions and 195 deletions.
26 changes: 16 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
cmake_minimum_required(VERSION 3.6.0)

project(glacier-messages
VERSION 0.1.2
VERSION 0.3
DESCRIPTION "The Glacier messages")

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INSTALL_PREFIX /usr)

include(FeatureSummary)
include(GNUInstallDirs)

set(QT_MIN_VERSION "5.12.0")
find_package(Qt5 COMPONENTS Gui Qml Quick DBus LinguistTools REQUIRED)
find_package(Glacier 0.8 COMPONENTS App REQUIRED)
find_package(Qt5QuickCompiler)
option(QML_DEBUG "Don't pack QML into binary for debug and develop" OFF)

set(QT_MIN_VERSION "6.0.0")
find_package(Qt6 COMPONENTS Gui Qml Quick DBus LinguistTools REQUIRED)
find_package(Glacier 1.0 COMPONENTS App REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(QOFONO qofono-qt6 REQUIRED IMPORTED_TARGET)
pkg_check_modules(NEMONOTIFICATIONS nemonotifications-qt6 REQUIRED IMPORTED_TARGET)
pkg_check_modules(COMMHISTORY commhistory-qt6 REQUIRED IMPORTED_TARGET)

add_subdirectory(src)
add_subdirectory(daemon)

# Translations
file(GLOB TS_FILES translations/*.ts)
qt5_add_translation(QM_FILES ${TS_FILES})
qt6_add_translation(QM_FILES ${TS_FILES})
add_custom_target(translations DEPENDS ${QM_FILES})
add_dependencies(glacier-messages translations)

Expand All @@ -40,11 +48,9 @@ install(FILES ${SVG_FILES}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/glacier-messages/images)

install(FILES
data/org.freedesktop.Telepathy.Client.qmlmessages.service
data/org.nemomobile.qmlmessages.service
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services)

install(FILES
data/glacier-messages.client
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/telepathy/clients)

data/glacier-messages.service
DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user/)
20 changes: 20 additions & 0 deletions daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(SRC main.cpp
messageshandler.cpp)

set(HEADERS messageshandler.h
constants.h)

add_executable(messagesd ${SRC} ${HEADERS})

target_link_libraries(messagesd
Qt6::Core
Qt6::DBus
PkgConfig::QOFONO
PkgConfig::NEMONOTIFICATIONS
PkgConfig::COMMHISTORY)

install(TARGETS messagesd RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR})

install(FILES messagesd.service
DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/user/)
10 changes: 10 additions & 0 deletions daemon/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H

#define LOCAL_UID QString("/org/glacier/messagesd")

#define MESSAGING_SERVICE_NAME QString("org.nemomobile.qmlmessages")
#define MESSAGING_INTERFACE QString("org.nemomobile.qmlmessages")
#define START_CONVERSATION_METHOD QString("startConversation")

#endif // CONSTANTS_H
43 changes: 43 additions & 0 deletions daemon/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (C) 2023 Chupligin Sergey <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "messageshandler.h"
#include <QCoreApplication>

int main(int argc, char** argv)
{
QCoreApplication* app = new QCoreApplication(argc, argv);
app->setOrganizationName("NemoMobile");
app->setApplicationName("messaged");

MessagesHandler messageHandler;

return app->exec();
}
11 changes: 11 additions & 0 deletions daemon/messagesd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Messages handler daemon
After=dbus.socket ofono.service
Requires=dbus.socket

[Service]
ExecStart=/usr/bin/messagesd
Restart=always

[Install]
WantedBy=graphical-session.target
135 changes: 135 additions & 0 deletions daemon/messageshandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* Copyright (C) 2023 Chupligin Sergey <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <QDebug>

#include "constants.h"
#include "messageshandler.h"
#include <notification.h>

MessagesHandler::MessagesHandler(QObject* parent)
: QObject(parent)
, m_ofonoManager(new QOfonoManager(this))
, m_commhistoryEventModel(new CommHistory::EventModel(this))
, m_groupModel(new CommHistory::GroupModel(this))
{
m_groupModel->setResolveContacts(CommHistory::GroupManager::DoNotResolve);
if (!m_groupModel->getGroups()) {
qFatal() << "Can't load CommHistory::GroupModel";
}
connect(m_ofonoManager, &QOfonoManager::modemsChanged, this,
&MessagesHandler::onModemsChanged);
}

void MessagesHandler::onModemsChanged(const QStringList& modems)
{
foreach (QOfonoMessageManager* manager, m_messageManagers) {
manager->disconnect();
}
m_messageManagers.clear();

foreach (QString modem, modems) {
QOfonoMessageManager* manager = new QOfonoMessageManager(this);
manager->setModemPath(modem);
connect(manager, &QOfonoMessageManager::incomingMessage, this,
&MessagesHandler::onIncomingMessage);
}
}

int MessagesHandler::getGroupId(QString sender)
{
CommHistory::Recipient recipient(LOCAL_UID, sender);
for (int i = 0; i < m_groupModel->rowCount(); i++) {
CommHistory::Group group = m_groupModel->group(m_groupModel->index(i, 0));
if (group.recipients().first() == recipient) {
qDebug() << "GROUP ID is " << group.id();
return group.id();
}
}

CommHistory::Group group;
group.setLocalUid(LOCAL_UID);
group.setRecipients(recipient);
group.setChatType(CommHistory::Group::ChatTypeP2P);
group.setChatName(sender);

if (m_groupModel->addGroup(group)) {
qDebug() << "New GROUP ID is " << group.id();
return group.id();
}

return -1;
}

void MessagesHandler::onIncomingMessage(const QString& message, const QVariantMap& info)
{
QString sender = info.value("Sender").toString();

int groupId = getGroupId(sender);
if (groupId < 0) {
return;
}

CommHistory::Event event;
event.setType(CommHistory::Event::SMSEvent);
event.setIsRead(false);
event.setDirection(CommHistory::Event::Inbound);
event.setFreeText(message.trimmed());
event.setStartTime(info.value("SentTime").toDateTime());
event.setGroupId(groupId);

if (m_commhistoryEventModel->addEvent(event)) {
Notification newMessageNotification;
newMessageNotification.setAppName(tr("Messages"));
newMessageNotification.setSummary(sender);
newMessageNotification.setBody(message);
newMessageNotification.setIcon("/usr/share/glacier-messages/glacier-messages.png");
newMessageNotification.setUrgency(Notification::Urgency::Normal);
newMessageNotification.setTimestamp(QDateTime::currentDateTimeUtc());
newMessageNotification.setHintValue("x-nemo-display-on", true);
newMessageNotification.setHintValue("x-nemo-priority", 120);

QVariantList remoteActions;
remoteActions.append(Notification::remoteAction("default",
QString(),
MESSAGING_SERVICE_NAME,
"/",
MESSAGING_INTERFACE,
START_CONVERSATION_METHOD,
QVariantList() << LOCAL_UID
<< sender
<< true));

newMessageNotification.setRemoteActions(remoteActions);
newMessageNotification.publish();
} else {
qWarning() << "Can`t save event";
}
}
61 changes: 61 additions & 0 deletions daemon/messageshandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Copyright (C) 2023 Chupligin Sergey <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef MESSAGESHANDLER_H
#define MESSAGESHANDLER_H

#include <QObject>
#include <qofono-qt6/qofonomanager.h>
#include <qofono-qt6/qofonomessagemanager.h>

#include <CommHistory/event.h>
#include <CommHistory/eventmodel.h>
#include <CommHistory/group.h>
#include <CommHistory/groupmodel.h>

class MessagesHandler : public QObject {
Q_OBJECT
public:
explicit MessagesHandler(QObject* parent = nullptr);

private slots:
void onModemsChanged(const QStringList& modems);
void onIncomingMessage(const QString& message, const QVariantMap& info);

private:
int getGroupId(QString sender);

QOfonoManager* m_ofonoManager;
QList<QOfonoMessageManager*> m_messageManagers;
CommHistory::EventModel* m_commhistoryEventModel;
CommHistory::GroupModel* m_groupModel;
};

#endif // MESSAGESHANDLER_H
17 changes: 0 additions & 17 deletions data/glacier-messages.client

This file was deleted.

4 changes: 2 additions & 2 deletions data/glacier-messages.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Glacier messaging application
Requires=dbus.socket mission-control-5.service lipstick.service
After=dbus.socket mission-control-5.service lipstick.service
Requires=dbus.socket lipstick.service
After=dbus.socket lipstick.service

[Service]
Type=dbus
Expand Down
4 changes: 0 additions & 4 deletions data/org.freedesktop.Telepathy.Client.qmlmessages.service

This file was deleted.

Loading

0 comments on commit d5b5f36

Please sign in to comment.