mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 05:07:27 +02:00
Add Unity systray hack from Clementine.
This commit is contained in:
@@ -40,6 +40,7 @@ SET( tomahawkSources ${tomahawkSources}
|
|||||||
musicscanner.cpp
|
musicscanner.cpp
|
||||||
shortcuthandler.cpp
|
shortcuthandler.cpp
|
||||||
scanmanager.cpp
|
scanmanager.cpp
|
||||||
|
ubuntuunityhack.cpp
|
||||||
tomahawkapp.cpp
|
tomahawkapp.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
@@ -85,6 +86,7 @@ SET( tomahawkHeaders ${tomahawkHeaders}
|
|||||||
|
|
||||||
musicscanner.h
|
musicscanner.h
|
||||||
scanmanager.h
|
scanmanager.h
|
||||||
|
ubuntuunityhack.h
|
||||||
shortcuthandler.h
|
shortcuthandler.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
#include "breakpad/BreakPad.h"
|
#include "breakpad/BreakPad.h"
|
||||||
|
#include "ubuntuunityhack.h"
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
#include "tomahawkapp_mac.h"
|
#include "tomahawkapp_mac.h"
|
||||||
@@ -60,6 +61,14 @@ main( int argc, char *argv[] )
|
|||||||
translator.load( QString( ":/lang/tomahawk_" ) + locale );
|
translator.load( QString( ":/lang/tomahawk_" ) + locale );
|
||||||
a.installTranslator( &translator );
|
a.installTranslator( &translator );
|
||||||
|
|
||||||
|
// Unity hack taken from Clementine's main.cpp
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
// In 11.04 Ubuntu decided that the system tray should be reserved for certain
|
||||||
|
// whitelisted applications. Tomahawk will override this setting and insert
|
||||||
|
// itself into the list of whitelisted apps.
|
||||||
|
UbuntuUnityHack hack;
|
||||||
|
#endif
|
||||||
|
|
||||||
if ( argc > 1 )
|
if ( argc > 1 )
|
||||||
{
|
{
|
||||||
QString arg = a.arguments()[ 1 ];
|
QString arg = a.arguments()[ 1 ];
|
||||||
|
83
src/ubuntuunityhack.cpp
Normal file
83
src/ubuntuunityhack.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
|
|
||||||
|
Clementine 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.
|
||||||
|
|
||||||
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ubuntuunityhack.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
const char* UbuntuUnityHack::kGSettingsFileName = "gsettings";
|
||||||
|
const char* UbuntuUnityHack::kUnityPanel = "com.canonical.Unity.Panel";
|
||||||
|
const char* UbuntuUnityHack::kUnitySystrayWhitelist = "systray-whitelist";
|
||||||
|
|
||||||
|
UbuntuUnityHack::UbuntuUnityHack(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
// Get the systray whitelist from gsettings. If this fails we're probably
|
||||||
|
// not running on a system with unity
|
||||||
|
QProcess* get = new QProcess(this);
|
||||||
|
connect(get, SIGNAL(finished(int)), SLOT(GetFinished(int)));
|
||||||
|
connect(get, SIGNAL(error(QProcess::ProcessError)), SLOT(GetError()));
|
||||||
|
get->start(kGSettingsFileName, QStringList()
|
||||||
|
<< "get" << kUnityPanel << kUnitySystrayWhitelist);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UbuntuUnityHack::GetError() {
|
||||||
|
QProcess* get = qobject_cast<QProcess*>(sender());
|
||||||
|
if (!get) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UbuntuUnityHack::GetFinished(int exit_code) {
|
||||||
|
QProcess* get = qobject_cast<QProcess*>(sender());
|
||||||
|
if (!get) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get->deleteLater();
|
||||||
|
|
||||||
|
if (exit_code != 0) {
|
||||||
|
// Probably not running in Unity.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray whitelist = get->readAllStandardOutput();
|
||||||
|
|
||||||
|
tDebug() << "Unity whitelist is" << whitelist;
|
||||||
|
|
||||||
|
int index = whitelist.lastIndexOf(']');
|
||||||
|
if (index == -1 || whitelist.contains("'tomahawk'")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
whitelist = whitelist.left(index) + QString(", 'tomahawk'").toUtf8() +
|
||||||
|
whitelist.mid(index);
|
||||||
|
|
||||||
|
tLog() << "Setting unity whitelist to" << whitelist;
|
||||||
|
|
||||||
|
QProcess* set = new QProcess(this);
|
||||||
|
connect(set, SIGNAL(finished(int)), set, SLOT(deleteLater()));
|
||||||
|
set->start(kGSettingsFileName, QStringList()
|
||||||
|
<< "set" << kUnityPanel << kUnitySystrayWhitelist << whitelist);
|
||||||
|
|
||||||
|
tLog() << "Tomahawk has added itself to the Unity system tray" <<
|
||||||
|
"whitelist, but this won't take effect until the next time" <<
|
||||||
|
"you log out and log back in.";
|
||||||
|
}
|
40
src/ubuntuunityhack.h
Normal file
40
src/ubuntuunityhack.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/* This file is part of Clementine.
|
||||||
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
|
|
||||||
|
Clementine 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.
|
||||||
|
|
||||||
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UBUNTUUNITYHACK_H
|
||||||
|
#define UBUNTUUNITYHACK_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class QProcess;
|
||||||
|
|
||||||
|
class UbuntuUnityHack : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
UbuntuUnityHack(QObject* parent = NULL);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void GetFinished(int exit_code);
|
||||||
|
void GetError();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const char* kGSettingsFileName;
|
||||||
|
static const char* kUnityPanel;
|
||||||
|
static const char* kUnitySystrayWhitelist;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UBUNTUUNITYHACK_H
|
Reference in New Issue
Block a user