SPlitted kde and appindicator code into shared libraries to avoid
additional dependencies.
This commit is contained in:
25
src/indicator/kdenotifier.cpp
Normal file
25
src/indicator/kdenotifier.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
||||
*
|
||||
* Copyright (C) 2014 Codestation
|
||||
*
|
||||
* 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 3 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "kdenotifier.h"
|
||||
|
||||
KDENotifier::KDENotifier(const QString &id, QObject *parent) :
|
||||
KStatusNotifierItem(id, parent)
|
||||
{
|
||||
}
|
||||
41
src/indicator/kdenotifier.h
Normal file
41
src/indicator/kdenotifier.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
||||
*
|
||||
* Copyright (C) 2014 Codestation
|
||||
*
|
||||
* 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 3 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KDENOTIFIER_H
|
||||
#define KDENOTIFIER_H
|
||||
|
||||
#include <kstatusnotifieritem.h>
|
||||
#include <kmenu.h>
|
||||
|
||||
class KDENotifier : public KStatusNotifierItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KDENotifier(const QString &id, QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
// block left click because it shows the default widget
|
||||
virtual void activate (const QPoint &pos=QPoint()) {
|
||||
Q_UNUSED(pos);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // KDENOTIFIER_H
|
||||
94
src/indicator/kdenotifiertray.cpp
Normal file
94
src/indicator/kdenotifiertray.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
||||
*
|
||||
* Copyright (C) 2014 Codestation
|
||||
*
|
||||
* 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 3 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "kdenotifiertray.h"
|
||||
#include <kmenu.h>
|
||||
|
||||
KDENotifierTray::KDENotifierTray(QWidget *parent)
|
||||
: TrayIndicator(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void KDENotifierTray::init()
|
||||
{
|
||||
options = new QAction(tr("Settings"), this);
|
||||
reload = new QAction(tr("Refresh database"), this);
|
||||
backup = new QAction(tr("Backup Manager"), this);
|
||||
about = new QAction(tr("About QCMA"), this);
|
||||
about_qt = new QAction(tr("About Qt"), this);
|
||||
quit = new QAction(tr("Quit"), this);
|
||||
|
||||
connect(options, SIGNAL(triggered()), this, SIGNAL(openConfig()));
|
||||
connect(backup, SIGNAL(triggered()), this, SIGNAL(openManager()));
|
||||
connect(reload, SIGNAL(triggered()), this, SIGNAL(refreshDatabase()));
|
||||
connect(about, SIGNAL(triggered()), this, SIGNAL(showAboutDialog()));
|
||||
connect(about_qt, SIGNAL(triggered()), this, SIGNAL(showAboutQt()));
|
||||
connect(quit, SIGNAL(triggered()), this, SIGNAL(stopServer()));
|
||||
|
||||
KMenu *tray_icon_menu = new KMenu(this);
|
||||
|
||||
tray_icon_menu->addAction(options);
|
||||
tray_icon_menu->addAction(reload);
|
||||
tray_icon_menu->addAction(backup);
|
||||
tray_icon_menu->addSeparator();
|
||||
tray_icon_menu->addAction(about);
|
||||
tray_icon_menu->addAction(about_qt);
|
||||
tray_icon_menu->addSeparator();
|
||||
tray_icon_menu->addAction(quit);
|
||||
|
||||
m_notifier_item = new KDENotifier("QcmaNotifier", this);
|
||||
m_notifier_item->setContextMenu(tray_icon_menu);
|
||||
m_notifier_item->setTitle("Qcma");
|
||||
m_notifier_item->setCategory(KStatusNotifierItem::ApplicationStatus);
|
||||
m_notifier_item->setIconByPixmap(QIcon(":/main/resources/images/tray/qcma_off.png"));
|
||||
m_notifier_item->setStatus(KStatusNotifierItem::Active);
|
||||
m_notifier_item->setToolTipTitle(tr("Qcma status"));
|
||||
m_notifier_item->setToolTipIconByPixmap(QIcon(":/main/resources/images/qcma.png"));
|
||||
m_notifier_item->setToolTipSubTitle(tr("Disconnected"));
|
||||
m_notifier_item->setStandardActionsEnabled(false);
|
||||
}
|
||||
|
||||
void KDENotifierTray::showMessage(const QString &title, const QString &message)
|
||||
{
|
||||
m_notifier_item->showMessage(title, message, "dialog-information", 3000);
|
||||
}
|
||||
|
||||
bool KDENotifierTray::isVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void KDENotifierTray::setIcon(const QString &icon)
|
||||
{
|
||||
m_notifier_item->setIconByPixmap(QIcon(":/main/resources/images/tray/" + icon));
|
||||
}
|
||||
|
||||
void KDENotifierTray::show()
|
||||
{
|
||||
}
|
||||
|
||||
void KDENotifierTray::hide()
|
||||
{
|
||||
}
|
||||
|
||||
// exported library function
|
||||
TrayIndicator *createTrayIndicator(QWidget *parent)
|
||||
{
|
||||
return new KDENotifierTray(parent);
|
||||
}
|
||||
@@ -17,38 +17,40 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KDENOTIFIERTRAY_H
|
||||
#define KDENOTIFIERTRAY_H
|
||||
|
||||
#include "trayindicator.h"
|
||||
#include "kdenotifier.h"
|
||||
|
||||
#undef signals
|
||||
extern "C" {
|
||||
#include <libnotify/notify.h>
|
||||
}
|
||||
#define signals public
|
||||
class QAction;
|
||||
class QSystemTrayIcon;
|
||||
|
||||
|
||||
TrayIndicator::TrayIndicator(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
class KDENotifierTray : public TrayIndicator
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
notify_init("qcma");
|
||||
#endif
|
||||
}
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KDENotifierTray(QWidget *parent = 0);
|
||||
void init();
|
||||
void setIcon(const QString &icon);
|
||||
bool isVisible();
|
||||
void show();
|
||||
void hide();
|
||||
void showMessage(const QString &title, const QString &message);
|
||||
|
||||
TrayIndicator::~TrayIndicator()
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
notify_uninit();
|
||||
#endif
|
||||
}
|
||||
private:
|
||||
//system tray
|
||||
QAction *quit;
|
||||
QAction *reload;
|
||||
QAction *options;
|
||||
QAction *backup;
|
||||
QAction *about;
|
||||
QAction *about_qt;
|
||||
|
||||
void TrayIndicator::showMessage(const QString &title, const QString &message)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
NotifyNotification *notif = notify_notification_new(qPrintable(title), qPrintable(message), "dialog-information");
|
||||
notify_notification_show(notif, NULL);
|
||||
g_object_unref(G_OBJECT(notif));
|
||||
#else
|
||||
Q_UNUSED(title);
|
||||
Q_UNUSED(message);
|
||||
#endif
|
||||
}
|
||||
KDENotifier *m_notifier_item;
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // KDENOTIFIERTRAY_H
|
||||
@@ -19,18 +19,31 @@
|
||||
|
||||
#include "qtrayicon.h"
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#ifdef ENABLE_KDE_NOTIFIER
|
||||
#include <kmenu.h>
|
||||
#else
|
||||
#include <QIcon>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#undef signals
|
||||
extern "C" {
|
||||
#include <libnotify/notify.h>
|
||||
}
|
||||
#define signals public
|
||||
#endif
|
||||
|
||||
QTrayIcon::QTrayIcon(QWidget *parent)
|
||||
: TrayIndicator(parent)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
notify_init("qcma");
|
||||
#endif
|
||||
}
|
||||
|
||||
QTrayIcon::~QTrayIcon()
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
notify_uninit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void QTrayIcon::init()
|
||||
@@ -49,11 +62,7 @@ void QTrayIcon::init()
|
||||
connect(about_qt, SIGNAL(triggered()), this, SIGNAL(showAboutQt()));
|
||||
connect(quit, SIGNAL(triggered()), this, SIGNAL(stopServer()));
|
||||
|
||||
#ifndef ENABLE_KDE_NOTIFIER
|
||||
QMenu *tray_icon_menu = new QMenu(this);
|
||||
#else
|
||||
KMenu *tray_icon_menu = new KMenu(this);
|
||||
#endif
|
||||
|
||||
tray_icon_menu->addAction(options);
|
||||
tray_icon_menu->addAction(reload);
|
||||
@@ -64,37 +73,25 @@ void QTrayIcon::init()
|
||||
tray_icon_menu->addSeparator();
|
||||
tray_icon_menu->addAction(quit);
|
||||
|
||||
#ifndef ENABLE_KDE_NOTIFIER
|
||||
m_tray_icon = new QSystemTrayIcon(this);
|
||||
m_tray_icon->setContextMenu(tray_icon_menu);
|
||||
#else
|
||||
m_notifier_item = new KDENotifier("QcmaNotifier", this);
|
||||
m_notifier_item->setContextMenu(tray_icon_menu);
|
||||
m_notifier_item->setTitle("Qcma");
|
||||
m_notifier_item->setCategory(KStatusNotifierItem::ApplicationStatus);
|
||||
m_notifier_item->setIconByPixmap(QIcon(":/main/resources/images/tray/qcma_off.png"));
|
||||
m_notifier_item->setStatus(KStatusNotifierItem::Active);
|
||||
m_notifier_item->setToolTipTitle(tr("Qcma status"));
|
||||
m_notifier_item->setToolTipIconByPixmap(QIcon(":/main/resources/images/qcma.png"));
|
||||
m_notifier_item->setToolTipSubTitle(tr("Disconnected"));
|
||||
m_notifier_item->setStandardActionsEnabled(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef Q_OS_LINUX
|
||||
|
||||
void QTrayIcon::showMessage(const QString &title, const QString &message)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
NotifyNotification *notif = notify_notification_new(qPrintable(title), qPrintable(message), "dialog-information");
|
||||
notify_notification_show(notif, NULL);
|
||||
g_object_unref(G_OBJECT(notif));
|
||||
#else
|
||||
m_tray_icon->showMessage(title, message);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool QTrayIcon::isVisible()
|
||||
{
|
||||
#ifndef ENABLE_KDE_NOTIFIER
|
||||
return m_tray_icon->isVisible();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void QTrayIcon::setIcon(const QString &icon)
|
||||
@@ -104,14 +101,16 @@ void QTrayIcon::setIcon(const QString &icon)
|
||||
|
||||
void QTrayIcon::show()
|
||||
{
|
||||
#ifndef ENABLE_KDE_NOTIFIER
|
||||
m_tray_icon->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
void QTrayIcon::hide()
|
||||
{
|
||||
#ifndef ENABLE_KDE_NOTIFIER
|
||||
m_tray_icon->hide();
|
||||
#endif
|
||||
}
|
||||
|
||||
// exported library function
|
||||
TrayIndicator *createTrayIndicator(QWidget *parent)
|
||||
{
|
||||
return new QTrayIcon(parent);
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@ class QTrayIcon : public TrayIndicator
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QTrayIcon(QWidget *parent = 0);
|
||||
~QTrayIcon();
|
||||
void init();
|
||||
void setIcon(const QString &icon);
|
||||
bool isVisible();
|
||||
void show();
|
||||
void hide();
|
||||
void showMessage(const QString &title, const QString &message);
|
||||
|
||||
#ifndef Q_OS_LINUX
|
||||
void showMessage(const QString &title, const QString &message);
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
#ifndef TRAYINDICATOR_H
|
||||
#define TRAYINDICATOR_H
|
||||
|
||||
#include "trayindicator_global.h"
|
||||
|
||||
/*
|
||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
||||
*
|
||||
@@ -22,23 +17,34 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRAYINDICATOR_H
|
||||
#define TRAYINDICATOR_H
|
||||
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
class TRAYINDICATORSHARED_EXPORT TrayIndicator : public QWidget
|
||||
#include "trayindicator_global.h"
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
// in Qt4 signals are protected
|
||||
#undef signals
|
||||
#define signals public
|
||||
#endif
|
||||
|
||||
class TrayIndicator : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~TrayIndicator();
|
||||
virtual ~TrayIndicator() {}
|
||||
virtual void init() = 0;
|
||||
virtual bool isVisible() = 0;
|
||||
virtual void setIcon(const QString &icon) = 0;
|
||||
virtual void showMessage(const QString &title, const QString &message);
|
||||
virtual void showMessage(const QString &title, const QString &message) = 0;
|
||||
virtual void show() = 0;
|
||||
virtual void hide() = 0;
|
||||
|
||||
protected:
|
||||
TrayIndicator(QWidget *parent = 0);
|
||||
TrayIndicator(QWidget *parent = 0) : QWidget(parent) {}
|
||||
|
||||
signals:
|
||||
void openConfig();
|
||||
@@ -50,4 +56,7 @@ signals:
|
||||
|
||||
};
|
||||
|
||||
typedef TrayIndicator *(*TrayFunctionPointer)(QWidget *parent);
|
||||
extern "C" TRAYINDICATORSHARED_EXPORT TrayIndicator *createTrayIndicator(QWidget *parent = 0);
|
||||
|
||||
#endif // TRAYINDICATOR_H
|
||||
|
||||
1
src/indicator/trayindicator_import.h
Symbolic link
1
src/indicator/trayindicator_import.h
Symbolic link
@@ -0,0 +1 @@
|
||||
trayindicator.h
|
||||
@@ -28,10 +28,13 @@
|
||||
#endif
|
||||
|
||||
#include <QDir>
|
||||
#include <QVector>
|
||||
|
||||
#undef signals
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libnotify/notify.h>
|
||||
|
||||
void optionsIndicator(GtkMenu *menu, gpointer data);
|
||||
void reloadIndicator(GtkMenu *menu, gpointer data);
|
||||
@@ -39,16 +42,19 @@ void backupIndicator(GtkMenu *menu, gpointer data);
|
||||
void aboutIndicator(GtkMenu *menu, gpointer data);
|
||||
void aboutQtIndicator(GtkMenu *menu, gpointer data);
|
||||
void quitIndicator(GtkMenu *menu, gpointer data);
|
||||
|
||||
}
|
||||
|
||||
#define signals public
|
||||
|
||||
UnityIndicator::UnityIndicator(QWidget *parent) :
|
||||
TrayIndicator(parent)
|
||||
{
|
||||
notify_init("qcma");
|
||||
}
|
||||
|
||||
UnityIndicator::~UnityIndicator()
|
||||
{
|
||||
notify_uninit();
|
||||
for(QVector<QPair<gpointer, gulong> >::iterator it = m_handlers.begin(); it != m_handlers.end(); ++it)
|
||||
{
|
||||
g_signal_handler_disconnect(it->first, it->second);
|
||||
@@ -142,12 +148,16 @@ void UnityIndicator::init()
|
||||
APP_INDICATOR_CATEGORY_APPLICATION_STATUS
|
||||
);
|
||||
|
||||
QString icon_name = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "icons/hicolor/64x64/tray/qcma_on.png");
|
||||
if(!icon_name.isEmpty())
|
||||
{
|
||||
QString icon_path = QFileInfo(icon_name).absolutePath();
|
||||
QString icon_path;
|
||||
QString icon_name = "share/icons/hicolor/64x64/tray/qcma_on.png";
|
||||
|
||||
if(QFile("/usr/" + icon_name).exists())
|
||||
icon_path = QFileInfo("/usr/" + icon_name).absolutePath();
|
||||
else if(QFile("/usr/local" + icon_name).exists())
|
||||
icon_path = QFileInfo("/usr/" + icon_name).absolutePath();
|
||||
|
||||
if(!icon_path.isEmpty())
|
||||
app_indicator_set_icon_theme_path(m_indicator, qPrintable(icon_path));
|
||||
}
|
||||
|
||||
app_indicator_set_status(m_indicator, APP_INDICATOR_STATUS_ACTIVE);
|
||||
app_indicator_set_menu(m_indicator, GTK_MENU(menu));
|
||||
@@ -170,3 +180,16 @@ void UnityIndicator::show()
|
||||
void UnityIndicator::hide()
|
||||
{
|
||||
}
|
||||
|
||||
void UnityIndicator::showMessage(const QString &title, const QString &message)
|
||||
{
|
||||
NotifyNotification *notif = notify_notification_new(qPrintable(title), qPrintable(message), "dialog-information");
|
||||
notify_notification_show(notif, NULL);
|
||||
g_object_unref(G_OBJECT(notif));
|
||||
}
|
||||
|
||||
// exported library function
|
||||
TrayIndicator *createTrayIndicator(QWidget *parent)
|
||||
{
|
||||
return new UnityIndicator(parent);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#ifndef UNITYINDICATOR_H
|
||||
#define UNITYINDICATOR_H
|
||||
|
||||
/*
|
||||
* QCMA: Cross-platform content manager assistant for the PS Vita
|
||||
*
|
||||
@@ -20,16 +17,28 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "indicator/trayindicator.h"
|
||||
#ifndef UNITYINDICATOR_H
|
||||
#define UNITYINDICATOR_H
|
||||
|
||||
#undef signals
|
||||
extern "C" {
|
||||
#include <libappindicator/app-indicator.h>
|
||||
}
|
||||
#define signals public
|
||||
#include "trayindicator.h"
|
||||
|
||||
#include <QVector>
|
||||
|
||||
#undef signals
|
||||
|
||||
extern "C" {
|
||||
#include <libappindicator/app-indicator.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
void optionsIndicator(GtkMenu *menu, gpointer data);
|
||||
void reloadIndicator(GtkMenu *menu, gpointer data);
|
||||
void backupIndicator(GtkMenu *menu, gpointer data);
|
||||
void aboutIndicator(GtkMenu *menu, gpointer data);
|
||||
void aboutQtIndicator(GtkMenu *menu, gpointer data);
|
||||
void quitIndicator(GtkMenu *menu, gpointer data);
|
||||
}
|
||||
|
||||
#define signals public
|
||||
|
||||
class UnityIndicator : public TrayIndicator
|
||||
{
|
||||
@@ -42,6 +51,7 @@ public:
|
||||
bool isVisible();
|
||||
void show();
|
||||
void hide();
|
||||
void showMessage(const QString &title, const QString &message);
|
||||
|
||||
private:
|
||||
AppIndicator *m_indicator;
|
||||
|
||||
Reference in New Issue
Block a user