2013-03-20 13:03:49 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Cédric Bellegarde <gnumdk@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2019-12-02 16:10:18 +03:00
|
|
|
#include "accountmanager.h"
|
2013-03-20 13:03:49 +04:00
|
|
|
#include "systray.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "theme.h"
|
2017-03-27 12:12:28 +03:00
|
|
|
#include "config.h"
|
2013-03-20 13:03:49 +04:00
|
|
|
|
2019-12-02 16:10:18 +03:00
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
|
2013-03-22 14:34:21 +04:00
|
|
|
#ifdef USE_FDO_NOTIFICATIONS
|
2013-03-20 13:03:49 +04:00
|
|
|
#include <QDBusConnection>
|
2013-03-22 14:58:55 +04:00
|
|
|
#include <QDBusInterface>
|
2013-03-20 13:03:49 +04:00
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingCall>
|
2013-03-22 14:58:55 +04:00
|
|
|
#define NOTIFICATIONS_SERVICE "org.freedesktop.Notifications"
|
|
|
|
#define NOTIFICATIONS_PATH "/org/freedesktop/Notifications"
|
|
|
|
#define NOTIFICATIONS_IFACE "org.freedesktop.Notifications"
|
2013-03-20 13:03:49 +04:00
|
|
|
#endif
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-01 15:51:40 +04:00
|
|
|
|
2019-12-02 16:10:18 +03:00
|
|
|
Systray::Systray() // TODO: make singleton, provide ::instance()
|
|
|
|
: _currentAccount(nullptr)
|
|
|
|
, _trayContext(nullptr)
|
|
|
|
{
|
|
|
|
_currentAccount = AccountManager::instance()->accounts().first();
|
|
|
|
|
|
|
|
QQmlEngine *engine = new QQmlEngine;
|
|
|
|
QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/systemtray.qml")));
|
|
|
|
_trayContext = engine->contextForObject(systray.create());
|
|
|
|
|
|
|
|
// TODO: hack to pass the icon to QML
|
|
|
|
//ctxt->setContextProperty("theme", QLatin1String("colored"));
|
|
|
|
//ctxt->setContextProperty("filename", "state-offline");
|
|
|
|
}
|
|
|
|
|
|
|
|
Systray::~Systray()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Systray::slotChangeActivityModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-20 13:03:49 +04:00
|
|
|
void Systray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint)
|
|
|
|
{
|
2013-03-22 14:34:21 +04:00
|
|
|
#ifdef USE_FDO_NOTIFICATIONS
|
2019-11-29 19:06:35 +03:00
|
|
|
if (QDBusInterface(NOTIFICATIONS_SERVICE, NOTIFICATIONS_PATH, NOTIFICATIONS_IFACE).isValid()) {
|
2017-03-27 12:12:28 +03:00
|
|
|
QList<QVariant> args = QList<QVariant>() << APPLICATION_NAME << quint32(0) << APPLICATION_ICON_NAME
|
2013-03-22 14:58:55 +04:00
|
|
|
<< title << message << QStringList() << QVariantMap() << qint32(-1);
|
|
|
|
QDBusMessage method = QDBusMessage::createMethodCall(NOTIFICATIONS_SERVICE, NOTIFICATIONS_PATH, NOTIFICATIONS_IFACE, "Notify");
|
|
|
|
method.setArguments(args);
|
|
|
|
QDBusConnection::sessionBus().asyncCall(method);
|
2013-05-22 19:39:49 +04:00
|
|
|
} else
|
2015-02-07 20:23:09 +03:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_OSX
|
|
|
|
if (canOsXSendUserNotification()) {
|
|
|
|
sendOsXUserNotification(title, message);
|
|
|
|
} else
|
2013-05-22 19:39:49 +04:00
|
|
|
#endif
|
|
|
|
{
|
2013-03-22 14:58:55 +04:00
|
|
|
QSystemTrayIcon::showMessage(title, message, icon, millisecondsTimeoutHint);
|
|
|
|
}
|
2013-03-22 14:34:21 +04:00
|
|
|
}
|
2013-10-01 15:51:40 +04:00
|
|
|
|
2013-11-23 03:05:50 +04:00
|
|
|
void Systray::setToolTip(const QString &tip)
|
|
|
|
{
|
|
|
|
QSystemTrayIcon::setToolTip(tr("%1: %2").arg(Theme::instance()->appNameGUI(), tip));
|
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|