File indexing completed on 2024-05-05 05:28:46
0001 // SPDX-FileCopyrightText: 2020 Anthony Fieroni <bvbfan@abv.bg> 0002 // SPDX-FileCopyrightText: 2021 Jonah BrĂ¼chert <jbb@kaidan.im> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 0006 #include "channelhandler.h" 0007 0008 #include <QLocale> 0009 0010 #include <database.h> 0011 #include <global.h> 0012 0013 ChannelHandler::ChannelHandler(QObject *parent) 0014 : QObject(parent) 0015 { 0016 // daemon dbus interface 0017 m_interface = new org::kde::spacebar::Daemon(QStringLiteral("org.kde.Spacebar"), QStringLiteral("/Daemon"), QDBusConnection::sessionBus(), this); 0018 0019 const QLocale locale; 0020 const QStringList qcountry = locale.name().split(u'_'); 0021 QString countryCode = qcountry.constLast(); 0022 PhoneNumber::setCountryCode(countryCode); 0023 0024 // prefer locale country code, but use modem country code if not set 0025 if (countryCode == QStringLiteral("C")) { 0026 countryCode = m_interface->countryCode(); 0027 if (countryCode != SL("The name org.kde.Spacebar was not provided by any .service files")) { 0028 PhoneNumber::setCountryCode(countryCode); 0029 } 0030 } 0031 0032 // Update the chat list when message arrives 0033 // The message is saved to the database by the background daemon 0034 connect(m_interface, &OrgKdeSpacebarDaemonInterface::messageAdded, [this](const QString &phoneNumber, const QString &id) { 0035 Q_UNUSED(id); 0036 Q_EMIT messagesChanged(PhoneNumberList(phoneNumber)); 0037 }); 0038 } 0039 0040 Database &ChannelHandler::database() 0041 { 0042 return m_database; 0043 } 0044 0045 org::kde::spacebar::Daemon *ChannelHandler::interface() 0046 { 0047 return m_interface; 0048 }