2019-12-11 15:00:39 +00:00
|
|
|
/*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2019 Weixuan XIAO <veyx.shaw@gmail.com>
|
2019-12-11 15:00:39 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-12-11 15:00:39 +00:00
|
|
|
*/
|
|
|
|
|
2024-09-21 10:27:24 +01:00
|
|
|
#include "indicatorhelper.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
2019-12-11 15:00:39 +00:00
|
|
|
#include <QApplication>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QDebug>
|
2019-12-11 15:00:39 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QMessageBox>
|
2024-09-21 10:27:24 +01:00
|
|
|
#include <QProcess>
|
2019-12-11 15:00:39 +00:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QThread>
|
|
|
|
|
2020-05-19 14:41:02 +01:00
|
|
|
#include "serviceregister_mac.h"
|
2024-09-21 10:27:24 +01:00
|
|
|
#include <dbushelper.h>
|
2022-04-12 06:40:03 +01:00
|
|
|
#include <kdeconnectconfig.h>
|
|
|
|
|
2019-12-11 15:00:39 +00:00
|
|
|
IndicatorHelper::IndicatorHelper()
|
|
|
|
{
|
2020-05-19 14:41:02 +01:00
|
|
|
registerServices();
|
2019-12-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorHelper::~IndicatorHelper()
|
2022-09-10 22:23:52 +01:00
|
|
|
{
|
|
|
|
}
|
2019-12-11 15:00:39 +00:00
|
|
|
|
|
|
|
void IndicatorHelper::iconPathHook()
|
|
|
|
{
|
2020-04-16 23:05:48 +01:00
|
|
|
const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdeconnect-icons"), QStandardPaths::LocateDirectory);
|
2019-12-11 15:00:39 +00:00
|
|
|
if (!iconPath.isNull()) {
|
|
|
|
QStringList themeSearchPaths = QIcon::themeSearchPaths();
|
|
|
|
themeSearchPaths << iconPath;
|
|
|
|
QIcon::setThemeSearchPaths(themeSearchPaths);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-21 10:27:24 +01:00
|
|
|
int IndicatorHelper::startDaemon()
|
2019-12-11 15:00:39 +00:00
|
|
|
{
|
2024-09-21 10:27:24 +01:00
|
|
|
int dbusStatus = DBusHelper::startDBusDaemon();
|
|
|
|
if (dbusStatus) {
|
|
|
|
QMessageBox::critical(nullptr,
|
|
|
|
i18n("KDE Connect"),
|
|
|
|
i18n("Cannot connect to DBus\n"
|
|
|
|
"KDE Connect will quit"),
|
|
|
|
QMessageBox::Abort,
|
|
|
|
QMessageBox::Abort);
|
|
|
|
QApplication::exit(dbusStatus);
|
2022-04-12 06:40:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start kdeconnectd, the daemon will not duplicate when there is already one
|
2024-09-21 10:27:24 +01:00
|
|
|
QString daemonPath = QCoreApplication::applicationDirPath() + QLatin1String("/kdeconnectd");
|
|
|
|
if (!QFile::exists(daemonPath)) {
|
2022-09-10 22:23:52 +01:00
|
|
|
QMessageBox::critical(nullptr, i18n("KDE Connect"), i18n("Cannot find kdeconnectd"), QMessageBox::Abort, QMessageBox::Abort);
|
2024-09-21 10:27:24 +01:00
|
|
|
QApplication::exit(-10);
|
2022-04-12 06:40:03 +01:00
|
|
|
}
|
2024-09-21 10:27:24 +01:00
|
|
|
QProcess::startDetached(daemonPath);
|
2019-12-11 15:00:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray)
|
|
|
|
{
|
2020-04-16 23:05:48 +01:00
|
|
|
const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kdeconnect-icons"), QStandardPaths::LocateDirectory);
|
2019-12-11 15:00:39 +00:00
|
|
|
if (!iconPath.isNull()) {
|
2022-03-02 12:06:36 +00:00
|
|
|
auto icon = QIcon::fromTheme(QStringLiteral("kdeconnectindicator"));
|
|
|
|
icon.setIsMask(true); // Make icon adapt to menu bar color
|
|
|
|
systray.setIconByPixmap(icon);
|
2019-12-11 15:00:39 +00:00
|
|
|
} else {
|
|
|
|
// We are in macOS dev env, just continue
|
|
|
|
qWarning() << "Fail to find indicator icon, continue anyway";
|
|
|
|
}
|
|
|
|
}
|