Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

Commit

Permalink
SPlitted kde and appindicator code into shared libraries to avoid
Browse files Browse the repository at this point in the history
additional dependencies.
  • Loading branch information
codestation committed Oct 5, 2014
1 parent fb5b881 commit 992bb2e
Show file tree
Hide file tree
Showing 17 changed files with 326 additions and 172 deletions.
10 changes: 10 additions & 0 deletions qcma.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ android {
# Compile the headless binary only on Linux because it depends on dbus
unix:!macx:!android {
SUBDIRS += qcma_cli.pro
# The appindicator and kde extensions are linux only too
ENABLE_APPINDICATOR {
SUBDIRS += qcma_appindicator.pro
}
ENABLE_KDENOTIFIER {
greaterThan(QT_MAJOR_VERSION, 4) {
#error("ENABLE_KDE can only be used with Qt4")
}
SUBDIRS += qcma_kdenotifier.pro
}
}

TRANSLATIONS += \
Expand Down
26 changes: 26 additions & 0 deletions qcma_appindicator.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
QT += gui widgets

TARGET = qcma_appindicator
TEMPLATE = lib
CONFIG += plugin link_pkgconfig
DEFINES += QCMA_TRAYINDICATOR_LIBRARY

QT_CONFIG -= no-pkg-config

PKGCONFIG += appindicator-0.1 libnotify
INCLUDEPATH += src/

SOURCES += \
src/indicator/unityindicator.cpp

HEADERS += \
src/indicator/trayindicator_global.h \
src/indicator/trayindicator.h \
src/indicator/unityindicator.h

actions64.path = $$DATADIR/icons/hicolor/64x64/actions
actions64.files += resources/images/qcma_on.png
actions64.files += resources/images/qcma_off.png

target.path = /usr/lib/qcma
INSTALLS += target actions64
53 changes: 13 additions & 40 deletions qcma_gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ SOURCES += \
src/gui/singleapplication.cpp \
src/gui/clientmanager.cpp \
src/gui/filterlineedit.cpp \
src/indicator/trayindicator.cpp \
src/indicator/qtrayicon.cpp \
# forms
src/forms/backupitem.cpp \
Expand All @@ -25,8 +24,7 @@ HEADERS += \
src/gui/singleapplication.h \
src/gui/clientmanager.h \
src/gui/filterlineedit.h \
src/indicator/trayindicator_global.h \
src/indicator/trayindicator.h \
src/indicator/trayindicator_import.h \
src/indicator/qtrayicon.h \
# forms
src/forms/backupitem.h \
Expand All @@ -46,6 +44,8 @@ FORMS += \

#Linux-only config
unix:!macx {
PKGCONFIG += libnotify

DATADIR = $$PREFIX/share

# config for desktop file and icon
Expand All @@ -55,46 +55,19 @@ unix:!macx {
icon64.path = $$DATADIR/icons/hicolor/64x64/apps
icon64.files += resources/images/$${TARGET}.png

# AppIndicator support
ENABLE_INDICATOR {
actions64.path = $$DATADIR/icons/hicolor/64x64/actions
actions64.files += resources/images/qcma_on.png
actions64.files += resources/images/qcma_off.png

SOURCES += src/indicator/unityindicator.cpp
HEADERS += src/indicator/unityindicator.h
PKGCONFIG += appindicator3-0.1
DEFINES += ENABLE_APPINDICATOR=1
}
target.path = $$BINDIR

INSTALLS += target desktop icon64 actions64

# KDE support
ENABLE_KDE {
greaterThan(QT_MAJOR_VERSION, 4) {
error("ENABLE_KDE can only be used with Qt4")
}
LIBS += -lkdeui
DEFINES += ENABLE_KDE_NOTIFIER=1
SOURCES += src/gui/kdenotifier.cpp
HEADERS += src/gui/kdenotifier.h
}
INSTALLS += target desktop icon64
}

unix:!macx {

PKGCONFIG += libnotify

QT += dbus

# Create the introspection XML
QT5_SUFFIX {
system(qdbuscpp2xml-qt5 -M -s src/gui/mainwidget.h -o org.qcma.ClientManager.xml)
} else {
system(qdbuscpp2xml -M -s src/gui/mainwidget.h -o org.qcma.ClientManager.xml)
}

# Create the helper class
DBUS_ADAPTORS = org.qcma.ClientManager.xml
QT += dbus
# Create the introspection XML
QT5_SUFFIX {
system(qdbuscpp2xml-qt5 -M -s src/gui/mainwidget.h -o org.qcma.ClientManager.xml)
} else {
system(qdbuscpp2xml -M -s src/gui/mainwidget.h -o org.qcma.ClientManager.xml)
}
# Create the helper class
DBUS_ADAPTORS = org.qcma.ClientManager.xml
}
21 changes: 0 additions & 21 deletions qcma_indicator.pro

This file was deleted.

19 changes: 19 additions & 0 deletions qcma_kdenotifier.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
QT += gui widgets

TARGET = qcma_kdenotifier
TEMPLATE = lib
CONFIG += plugin
DEFINES += QCMA_TRAYINDICATOR_LIBRARY
LIBS += -lkdeui
INCLUDEPATH += src/

SOURCES += \
src/indicator/kdenotifier.cpp \
src/indicator/kdenotifiertray.cpp

HEADERS += \
src/indicator/trayindicator.h \
src/indicator/kdenotifier.h \
src/indicator/kdenotifiertray.h

target.path = /usr/lib/qcma
60 changes: 33 additions & 27 deletions src/gui/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
#include "qlistdb.h"
#include "sqlitedb.h"

#ifdef ENABLE_APPINDICATOR
#include "indicator/unityindicator.h"
#else
#include "indicator/qtrayicon.h"
#endif

#include <QApplication>
#include <QDebug>
Expand All @@ -57,21 +53,13 @@ MainWidget::MainWidget(QWidget *parent) :
// expose qcma over dbus so the database update can be triggered
dbus.registerObject("/ClientManager", this);
dbus.registerService("org.qcma.ClientManager");
#ifndef ENABLE_KDE_NOTIFIER
trayIcon = NULL;
#else
notifierItem = NULL;
#endif
}
#else
MainWidget::MainWidget(QWidget *parent) :
QWidget(parent), db(NULL), configForm(NULL), managerForm(NULL), backupForm(NULL)
{
#ifndef ENABLE_KDE_NOTIFIER
trayIcon = NULL;
#else
notifierItem = NULL;
#endif
}
#endif

Expand Down Expand Up @@ -113,14 +101,10 @@ void MainWidget::stopServer()

void MainWidget::deviceDisconnect()
{
#ifndef ENABLE_KDE_NOTIFIER
#ifndef Q_OS_WIN32
trayIcon->setIcon("qcma_off.png");
#else
trayIcon->setIcon("qcma_off_16.png");
#endif
#else
notifierItem->setIconByPixmap(QIcon(":/main/resources/images/tray/qcma_off.png"));
#endif
qDebug("Icon changed - disconnected");
setTrayTooltip(tr("Disconnected"));
Expand All @@ -129,14 +113,10 @@ void MainWidget::deviceDisconnect()

void MainWidget::deviceConnect(QString message)
{
#ifndef ENABLE_KDE_NOTIFIER
#ifndef Q_OS_WIN32
trayIcon->setIcon("qcma_on.png");
#else
trayIcon->setIcon("qcma_off_16.png");
#endif
#else
notifierItem->setIconByPixmap(QIcon(":/main/resources/images/tray/qcma_on.png"));
#endif
qDebug("Icon changed - connected");
setTrayTooltip(message);
Expand Down Expand Up @@ -232,13 +212,41 @@ void MainWidget::refreshDatabase()
managerForm->refreshDatabase();
}

void MainWidget::createTrayIcon()
TrayIndicator *MainWidget::createTrayObject(QWidget *parent)
{
#ifdef ENABLE_APPINDICATOR
trayIcon = new UnityIndicator(this);
#else
trayIcon = new QTrayIcon(this);
TrayFunctionPointer create_tray = NULL;

QString desktop = getenv("XDG_CURRENT_DESKTOP");

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
if(desktop.toLower() == "kde")
{
// KDENotifier
QLibrary library("/usr/share/qcma/qcma_kdenotifier.so");
if(library.load())
create_tray = reinterpret_cast<TrayFunctionPointer>(library.resolve("createTrayIndicator"));
else
qDebug() << "Cannot load qcma_kdenotifier plugin";
}
else
#endif
// if(desktop.toLower() == "unity")
{
// AppIndicator
QLibrary library("/usr/share/qcma/qcma_appindicator.so");
if(library.load())
create_tray = reinterpret_cast<TrayFunctionPointer>(library.resolve("createTrayIndicator"));
else
qDebug() << "Cannot load qcma_appindicator plugin";
}

// else QSystemTrayIcon
return (create_tray != NULL) ? create_tray(parent) : createTrayIndicator(parent);
}

void MainWidget::createTrayIcon()
{
trayIcon = createTrayObject(this);
trayIcon->init();

#ifndef Q_OS_WIN32
Expand Down Expand Up @@ -275,10 +283,8 @@ void MainWidget::receiveMessage(QString message)

MainWidget::~MainWidget()
{
#ifndef ENABLE_KDE_NOTIFIER
if(trayIcon) {
trayIcon->hide();
}
#endif
delete db;
}
1 change: 1 addition & 0 deletions src/gui/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MainWidget : public QWidget
void connectSignals();
void createTrayIcon();
void checkSettings();
TrayIndicator *createTrayObject(QWidget *parent);

bool first_run;

Expand Down
File renamed without changes.
File renamed without changes.
94 changes: 94 additions & 0 deletions src/indicator/kdenotifiertray.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit 992bb2e

Please sign in to comment.