aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-01-23 16:22:56 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-01-23 16:22:56 +0000
commit95563aa52d1b15be8efcb23c979c40c0515cfa10 (patch)
tree3dbc3a50e83fe12fb510f28ee29299a7d3bda074
parent9793ca4daeeffed1c2c2472c4697e354bf157902 (diff)
downloadqmmp-95563aa52d1b15be8efcb23c979c40c0515cfa10.tar.gz
qmmp-95563aa52d1b15be8efcb23c979c40c0515cfa10.tar.bz2
qmmp-95563aa52d1b15be8efcb23c979c40c0515cfa10.zip
hal support (experimental)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@752 90c681e8-e032-0410-971d-27865f9a5e38
-rw-r--r--CMakeLists.txt5
-rw-r--r--src/plugins/General/CMakeLists.txt11
-rw-r--r--src/plugins/General/General.pro1
-rw-r--r--src/plugins/General/hal/CMakeLists.txt61
-rw-r--r--src/plugins/General/hal/hal.pro46
-rw-r--r--src/plugins/General/hal/haldevice.cpp86
-rw-r--r--src/plugins/General/hal/haldevice.h60
-rw-r--r--src/plugins/General/hal/halfactory.cpp62
-rw-r--r--src/plugins/General/hal/halfactory.h45
-rw-r--r--src/plugins/General/hal/halmanager.cpp59
-rw-r--r--src/plugins/General/hal/halmanager.h50
-rw-r--r--src/plugins/General/hal/halplugin.cpp137
-rw-r--r--src/plugins/General/hal/halplugin.h55
13 files changed, 673 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d2471b1d2..30ef2605e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -108,11 +108,12 @@ PRINT_SUMMARY ("Analyzer .........................." USE_ANALYZER 1)
MESSAGE("")
MESSAGE("General Plugins:")
-PRINT_SUMMARY ("DBUS support ......................" USE_DBUS 1)
+PRINT_SUMMARY ("MPRIS support ....................." USE_MPRIS 1)
PRINT_SUMMARY ("Scrobbler ........................." USE_SCROBBLER 1)
PRINT_SUMMARY ("Tray support ......................" USE_STATICON 1)
PRINT_SUMMARY ("Notifier support .................." USE_NOTIFIER 1)
-PRINT_SUMMARY ("Lyrics support....................." USE_LYRICS 1)
+PRINT_SUMMARY ("Lyrics support ...................." USE_LYRICS 1)
+PRINT_SUMMARY ("HAL support ......................." USE_HAL 1)
MESSAGE("")
MESSAGE("File Dialogs:")
diff --git a/src/plugins/General/CMakeLists.txt b/src/plugins/General/CMakeLists.txt
index 6e69595da..c79d34025 100644
--- a/src/plugins/General/CMakeLists.txt
+++ b/src/plugins/General/CMakeLists.txt
@@ -1,12 +1,13 @@
-SET(USE_DBUS TRUE CACHE BOOL "enable/disable dbus plugin")
+SET(USE_MPRIS TRUE CACHE BOOL "enable/disable mpris plugin")
SET(USE_SCROBBLER TRUE CACHE BOOL "enable/disable scrobbler plugin")
SET(USE_STATICON TRUE CACHE BOOL "enable/disable status icon plugin")
SET(USE_NOTIFIER TRUE CACHE BOOL "enable/disable notifier plugin")
SET(USE_LYRICS TRUE CACHE BOOL "enable/disable lyrics version")
+SET(USE_HAL TRUE CACHE BOOL "enable/disable hal plugin")
-IF(USE_DBUS)
+IF(USE_MPRIS)
add_subdirectory(mpris)
-ENDIF(USE_DBUS)
+ENDIF(USE_MPRIS)
IF(USE_SCROBBLER)
add_subdirectory(scrobbler)
@@ -23,3 +24,7 @@ ENDIF(USE_NOTIFIER)
IF(USE_LYRICS)
add_subdirectory(lyrics)
ENDIF(USE_LYRICS)
+
+IF(USE_HAL)
+add_subdirectory(hal)
+ENDIF(USE_HAL)
diff --git a/src/plugins/General/General.pro b/src/plugins/General/General.pro
index c905a5254..ce699c66b 100644
--- a/src/plugins/General/General.pro
+++ b/src/plugins/General/General.pro
@@ -2,5 +2,6 @@ SUBDIRS += statusicon \
scrobbler \
mpris \
notifier \
+ hal \
lyrics
TEMPLATE = subdirs
diff --git a/src/plugins/General/hal/CMakeLists.txt b/src/plugins/General/hal/CMakeLists.txt
new file mode 100644
index 000000000..79c41aa83
--- /dev/null
+++ b/src/plugins/General/hal/CMakeLists.txt
@@ -0,0 +1,61 @@
+project(libhal)
+
+cmake_minimum_required(VERSION 2.4.8 FATAL_ERROR)
+
+SET (QT_USE_QTDBUS TRUE)
+
+INCLUDE(FindQt4)
+
+include(${QT_USE_FILE})
+
+if(COMMAND cmake_policy)
+cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+# qt plugin
+ADD_DEFINITIONS( -Wall )
+ADD_DEFINITIONS(${QT_DEFINITIONS})
+ADD_DEFINITIONS(-DQT_PLUGIN)
+ADD_DEFINITIONS(-DQT_NO_DEBUG)
+ADD_DEFINITIONS(-DQT_SHARED)
+ADD_DEFINITIONS(-DQT_THREAD)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+# libqmmpui & libqmmp
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
+link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui)
+link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp)
+
+SET(libhal_SRCS
+ halfactory.cpp
+ halmanager.cpp
+ halplugin.cpp
+ haldevice.cpp
+)
+
+SET(libhal_MOC_HDRS
+ halfactory.h
+ halmanager.h
+ halplugin.h
+ haldevice.h
+)
+
+#SET(libhal_RCCS translations/translations.qrc)
+
+QT4_ADD_RESOURCES(libhal_RCC_SRCS ${libhal_RCCS})
+
+QT4_WRAP_CPP(libhal_MOC_SRCS ${libhal_MOC_HDRS})
+
+# user interface
+
+
+# QT4_WRAP_UI(libhal_UIS_H ${libhal_UIS})
+# Don't forget to include output directory, otherwise
+# the UI file won't be wrapped!
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+ADD_LIBRARY(hal SHARED ${libhal_SRCS} ${libhal_MOC_SRCS} ${libhal_RCC_SRCS})
+add_dependencies(hal qmmpui)
+target_link_libraries(hal ${QT_LIBRARIES} -lqmmpui -lqmmp)
+install(TARGETS hal DESTINATION ${LIB_DIR}/qmmp/General)
diff --git a/src/plugins/General/hal/hal.pro b/src/plugins/General/hal/hal.pro
new file mode 100644
index 000000000..bb1df4fcf
--- /dev/null
+++ b/src/plugins/General/hal/hal.pro
@@ -0,0 +1,46 @@
+include(../../plugins.pri)
+
+CONFIG += release \
+warn_on \
+plugin \
+ lib \
+ qdbus
+
+TARGET =$$PLUGINS_PREFIX/General/hal
+QMAKE_CLEAN =$$PLUGINS_PREFIX/General/libhal.so
+
+TEMPLATE = lib
+QMAKE_LIBDIR += ../../../../lib
+
+#TRANSLATIONS = translations/hal_plugin_cs.ts
+# translations/hal_plugin_de.ts
+# translations/hal_plugin_zh_CN.ts
+# translations/hal_plugin_zh_TW.ts
+# translations/hal_plugin_ru.ts
+# translations/hal_plugin_uk_UA.ts
+#RESOURCES = translations/translations.qrc
+
+isEmpty(LIB_DIR){
+ LIB_DIR = /lib
+}
+target.path = $$LIB_DIR/qmmp/General
+INSTALLS += target
+#FORMS += settingsdialog.ui
+
+#RESOURCES += images/images.qrc
+
+
+HEADERS += halfactory.h \
+ halplugin.h \
+ halmanager.h \
+ haldevice.h
+
+SOURCES += halfactory.cpp \
+ halplugin.cpp \
+ halmanager.cpp \
+ haldevice.cpp
+
+INCLUDEPATH += ../../../../src
+
+LIBS += -lqmmpui -lqmmp
+
diff --git a/src/plugins/General/hal/haldevice.cpp b/src/plugins/General/hal/haldevice.cpp
new file mode 100644
index 000000000..045bade80
--- /dev/null
+++ b/src/plugins/General/hal/haldevice.cpp
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+//TODO based on solid
+
+#include <QDBusInterface>
+#include <QDBusConnection>
+
+#include "haldevice.h"
+
+
+Q_DECLARE_METATYPE(ChangeDescription);
+Q_DECLARE_METATYPE(QList<ChangeDescription>);
+
+const QDBusArgument &operator<<(QDBusArgument &arg, const ChangeDescription &change)
+{
+ arg.beginStructure();
+ arg << change.key << change.added << change.removed;
+ arg.endStructure();
+ return arg;
+}
+
+const QDBusArgument &operator>>(const QDBusArgument &arg, ChangeDescription &change)
+{
+ arg.beginStructure();
+ arg >> change.key >> change.added >> change.removed;
+ arg.endStructure();
+ return arg;
+}
+
+HalDevice::HalDevice(const QString &udi, QObject *parent)
+ : QObject(parent)
+{
+ qDBusRegisterMetaType<ChangeDescription>();
+ qDBusRegisterMetaType< QList<ChangeDescription> >();
+ m_interface = new QDBusInterface("org.freedesktop.Hal", udi,
+ "org.freedesktop.Hal.Device", QDBusConnection::systemBus(), this);
+ m_interface->connection().connect("org.freedesktop.Hal", udi,
+ "org.freedesktop.Hal.Device","PropertyModified",
+ this, SIGNAL(propertyModified(int, const QList<ChangeDescription> &)));
+ m_interface->connection().connect("org.freedesktop.Hal", udi,
+ "org.freedesktop.Hal.Device","Condition",
+ this, SIGNAL(condition(const QString &, const QString &)));
+ m_udi = udi;
+}
+
+QVariant HalDevice::property (const QString &key)
+{
+ QDBusMessage reply = m_interface->call("GetProperty", key);
+ if (reply.type() != QDBusMessage::ReplyMessage && reply.errorName() != "org.freedesktop.Hal.NoSuchProperty")
+ {
+ qWarning("%s error: %s, key: %s", Q_FUNC_INFO, qPrintable(reply.errorName()), qPrintable(key));
+ return QVariant();
+ }
+
+ if (reply.errorName() != "org.freedesktop.Hal.NoSuchProperty")
+ return reply.arguments().at(0);
+ else
+ return QVariant();
+}
+
+HalDevice::~HalDevice()
+{
+}
+
+QString HalDevice::udi() const
+{
+ return m_udi;
+}
diff --git a/src/plugins/General/hal/haldevice.h b/src/plugins/General/hal/haldevice.h
new file mode 100644
index 000000000..9c3023a46
--- /dev/null
+++ b/src/plugins/General/hal/haldevice.h
@@ -0,0 +1,60 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef HALDEVICE_H
+#define HALDEVICE_H
+
+#include <QObject>
+#include <QDBusMetaType>
+#include <QList>
+#include <QVariant>
+
+class QDBusInterface;
+
+struct ChangeDescription
+{
+ QString key;
+ bool added;
+ bool removed;
+};
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class HalDevice : public QObject
+{
+ Q_OBJECT
+public:
+ HalDevice(const QString &udi, QObject *parent = 0);
+
+ ~HalDevice();
+
+ QVariant property (const QString &key);
+ QString udi() const;
+
+signals:
+ void propertyModified(int count, const QList<ChangeDescription> &changes);
+ void condition(const QString &condition, const QString &reason);
+
+private:
+ QDBusInterface *m_interface;
+ QString m_udi;
+};
+
+#endif
diff --git a/src/plugins/General/hal/halfactory.cpp b/src/plugins/General/hal/halfactory.cpp
new file mode 100644
index 000000000..48b7aa7e6
--- /dev/null
+++ b/src/plugins/General/hal/halfactory.cpp
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <QtGui>
+
+#include "halplugin.h"
+#include "halfactory.h"
+
+const GeneralProperties HalFactory::properties() const
+{
+ GeneralProperties properties;
+ properties.name = tr("HAL Plugin");
+ properties.hasAbout = FALSE;
+ properties.hasSettings = FALSE;
+ properties.visibilityControl = FALSE;
+ return properties;
+}
+
+General *HalFactory::create(QObject *parent)
+{
+ return new HalPlugin(parent);
+}
+
+QDialog *HalFactory::createConfigDialog(QWidget *)
+{
+ return 0;
+}
+
+void HalFactory::showAbout(QWidget *parent)
+{
+ /*QMessageBox::about (parent, tr("About Hal Plugin"),
+ tr("Qmmp Hal Plugin")+"\n"+
+ tr("Writen by: Ilya Kotov <forkotov02@hotmail.ru>"));*/
+ //TODO based on solid
+}
+
+QTranslator *HalFactory::createTranslator(QObject *parent)
+{
+ QTranslator *translator = new QTranslator(parent);
+ QString locale = QLocale::system().name();
+ translator->load(QString(":/hal_plugin_") + locale);
+ return translator;
+}
+
+Q_EXPORT_PLUGIN(HalFactory)
diff --git a/src/plugins/General/hal/halfactory.h b/src/plugins/General/hal/halfactory.h
new file mode 100644
index 000000000..632cf9f5e
--- /dev/null
+++ b/src/plugins/General/hal/halfactory.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef DEVDETECTFACTORY_H
+#define DEVDETECTFACTORY_H
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+#include <QObject>
+#include <QTranslator>
+
+#include <qmmpui/general.h>
+#include <qmmpui/generalfactory.h>
+
+class HalFactory : public QObject, public GeneralFactory
+{
+Q_OBJECT
+Q_INTERFACES(GeneralFactory);
+public:
+ const GeneralProperties properties() const;
+ General *create(QObject *parent);
+ QDialog *createConfigDialog(QWidget *parent);
+ void showAbout(QWidget *parent);
+ QTranslator *createTranslator(QObject *parent);
+
+};
+
+#endif
diff --git a/src/plugins/General/hal/halmanager.cpp b/src/plugins/General/hal/halmanager.cpp
new file mode 100644
index 000000000..2db56c186
--- /dev/null
+++ b/src/plugins/General/hal/halmanager.cpp
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+//TODO based on solid
+
+#include <QDBusInterface>
+#include <QDBusConnection>
+#include <QDBusReply>
+
+#include "halmanager.h"
+
+HalManager::HalManager(QObject *parent)
+ : QObject(parent)
+{
+ m_interface = new QDBusInterface("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager",
+ "org.freedesktop.Hal.Manager", QDBusConnection::systemBus(), this);
+
+ m_interface->connection().connect("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager",
+ "org.freedesktop.Hal.Manager", "DeviceAdded",
+ this, SIGNAL(deviceAdded(const QString &)));
+
+ m_interface->connection().connect("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager",
+ "org.freedesktop.Hal.Manager", "DeviceRemoved",
+ this, SIGNAL(deviceRemoved(const QString &)));
+
+}
+
+
+HalManager::~HalManager()
+{
+}
+
+QStringList HalManager::findDeviceByCapability(const QString &cap)
+{
+ QDBusReply <QStringList> reply = m_interface->call("FindDeviceByCapability", cap);
+ if (!reply.isValid())
+ {
+ qWarning("HalManager: error: %s", qPrintable(reply.error().name()));
+ return QStringList();
+ }
+ return reply.value();
+}
diff --git a/src/plugins/General/hal/halmanager.h b/src/plugins/General/hal/halmanager.h
new file mode 100644
index 000000000..fcabd5538
--- /dev/null
+++ b/src/plugins/General/hal/halmanager.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef HALMANAGER_H
+#define HALMANAGER_H
+
+#include <QObject>
+#include <QStringList>
+
+class QDBusInterface;
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class HalManager : public QObject
+{
+Q_OBJECT
+public:
+ HalManager(QObject *parent = 0);
+
+ ~HalManager();
+
+ QStringList findDeviceByCapability(const QString &cap);
+
+signals:
+ void deviceAdded(const QString &udi);
+ void deviceRemoved(const QString &udi);
+
+private:
+ QDBusInterface *m_interface;
+
+};
+
+#endif
diff --git a/src/plugins/General/hal/halplugin.cpp b/src/plugins/General/hal/halplugin.cpp
new file mode 100644
index 000000000..0314f9337
--- /dev/null
+++ b/src/plugins/General/hal/halplugin.cpp
@@ -0,0 +1,137 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <QtDBus>
+#include <QActionGroup>
+
+#include <qmmpui/generalhandler.h>
+#include <qmmpui/mediaplayer.h>
+#include <qmmpui/playlistmodel.h>
+#include "haldevice.h"
+#include "halmanager.h"
+#include "halplugin.h"
+
+HalPlugin::HalPlugin(QObject *parent)
+ : General(parent)
+{
+ m_manager = new HalManager(this);
+ m_actions = new QActionGroup(this);
+ connect(m_manager,SIGNAL(deviceAdded(const QString &)), SLOT(addDevice(const QString &)));
+ connect(m_manager,SIGNAL(deviceRemoved(const QString &)), SLOT(removeDevice(const QString &)));
+ connect(m_actions,SIGNAL(triggered (QAction *)), SLOT(processAction(QAction *)));
+ //find existing devices
+ QStringList udis = m_manager->findDeviceByCapability("volume");
+ foreach(QString udi, udis)
+ {
+ qDebug(qPrintable(udi));
+ addDevice(udi);
+ }
+}
+
+
+HalPlugin::~HalPlugin()
+{
+}
+
+void HalPlugin::removeDevice(const QString &udi)
+{
+ foreach(HalDevice *device, m_devices)
+ {
+ if (device->udi() == udi)
+ {
+ m_devices.removeAll(device);
+ delete device;
+ qDebug("HalPlugin: device \"%s\" removed", qPrintable(udi));
+ updateActions();
+ break;
+ }
+ }
+}
+
+void HalPlugin::addDevice(const QString &udi)
+{
+ foreach(HalDevice *device, m_devices) //is it already exists?
+ {
+ if (device->udi() == udi)
+ return;
+ }
+ HalDevice *device = new HalDevice(udi, this);
+ if (device->property("info.category").toString() == "volume"
+ && device->property("volume.disc.has_audio").toBool()) //add audio cd only TODO usb devices support
+ {
+ qDebug("HalPlugin: device \"%s\" added (cd audio)", qPrintable(udi));
+ m_devices << device;
+ updateActions();
+ return;
+ }
+ delete device;
+}
+
+void HalPlugin::updateActions()
+{
+ // add device
+ foreach(HalDevice *device, m_devices)
+ {
+ QString dev_path = "cdda://" + device->property("block.device").toString();
+ bool exists = FALSE;
+ foreach(QAction *action, m_actions->actions ())
+ {
+ if (action->data().toString() == dev_path)
+ {
+ exists = TRUE;
+ break;
+ }
+ }
+ if (!exists)
+ {
+ QAction *action = new QAction(QString(tr("Add CD (%1)"))
+ .arg(device->property("block.device").toString()), this);
+ action->setData(dev_path);
+ m_actions->addAction(action);
+ GeneralHandler::instance()->addAction(action, GeneralHandler::TOOLS_MENU);
+ }
+ }
+ // remove device
+ foreach(QAction *action, m_actions->actions ())
+ {
+ bool exists = FALSE;
+ foreach(HalDevice *device, m_devices)
+ {
+ QString dev_path = "cdda://" + device->property("block.device").toString();
+ if (dev_path == action->data().toString())
+ {
+ exists = TRUE;
+ break;
+ }
+ }
+ if (!exists)
+ {
+ m_actions->removeAction(action);
+ GeneralHandler::instance()->removeAction(action);
+ action->deleteLater();
+ }
+ }
+}
+
+void HalPlugin::processAction(QAction *action)
+{
+ qDebug("HalPlugin: action triggered: %s", qPrintable(action->data().toString()));
+ MediaPlayer::instance()->playListModel()->addFile(action->data().toString());
+}
diff --git a/src/plugins/General/hal/halplugin.h b/src/plugins/General/hal/halplugin.h
new file mode 100644
index 000000000..3c9717f3c
--- /dev/null
+++ b/src/plugins/General/hal/halplugin.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (C) 2009 by Ilya Kotov *
+ * forkotov02@hotmail.ru *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#ifndef DEVDETECT_H
+#define DEVDETECT_H
+
+
+#include <qmmpui/general.h>
+
+class HalManager;
+class HalDevice;
+class QActionGroup;
+class QAction;
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+
+class HalPlugin : public General
+{
+Q_OBJECT
+public:
+ HalPlugin(QObject *parent = 0);
+
+ ~HalPlugin();
+
+private slots:
+ void removeDevice(const QString &udi);
+ void addDevice(const QString &udi);
+ void processAction(QAction *action);
+
+private:
+ void updateActions();
+ HalManager *m_manager;
+ QList <HalDevice *> m_devices;
+ QActionGroup *m_actions;
+};
+
+#endif