aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui
diff options
context:
space:
mode:
authorvovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38>2008-02-07 13:36:34 +0000
committervovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38>2008-02-07 13:36:34 +0000
commit06d1877811fa6aa97dddc0e03bcde4e766928c87 (patch)
treec25462d0e58c3d58c728664440412bf4f16a49ec /src/qmmpui
parent3f6b60f23c44a8ba8dd97ca6f41a16e2af7ef2f7 (diff)
downloadqmmp-06d1877811fa6aa97dddc0e03bcde4e766928c87.tar.gz
qmmp-06d1877811fa6aa97dddc0e03bcde4e766928c87.tar.bz2
qmmp-06d1877811fa6aa97dddc0e03bcde4e766928c87.zip
new directory structure
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@232 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
-rw-r--r--src/qmmpui/general.cpp157
-rw-r--r--src/qmmpui/general.h86
-rw-r--r--src/qmmpui/generalfactory.h52
-rw-r--r--src/qmmpui/generalhandler.cpp143
-rw-r--r--src/qmmpui/generalhandler.h69
-rw-r--r--src/qmmpui/qmmpui.pro38
-rw-r--r--src/qmmpui/songinfo.cpp137
-rw-r--r--src/qmmpui/songinfo.h76
8 files changed, 758 insertions, 0 deletions
diff --git a/src/qmmpui/general.cpp b/src/qmmpui/general.cpp
new file mode 100644
index 000000000..aebd06647
--- /dev/null
+++ b/src/qmmpui/general.cpp
@@ -0,0 +1,157 @@
+/***************************************************************************
+ * Copyright (C) 2008 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 <QObject>
+#include <QList>
+#include <QApplication>
+
+#include "config.h"
+#include "general.h"
+
+
+static QList<GeneralFactory*> *factories = 0;
+static QStringList files;
+
+static void checkFactories()
+{
+ if (! factories)
+ {
+ files.clear();
+ factories = new QList<GeneralFactory *>;
+
+ QDir pluginsDir (qApp->applicationDirPath());
+ pluginsDir.cdUp();
+ pluginsDir.cd("./"LIB_DIR"/qmmp/General");
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files))
+ {
+ QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = loader.instance();
+ if (loader.isLoaded())
+ {
+ qDebug("General: plugin loaded - %s", qPrintable(fileName));
+ }
+ GeneralFactory *factory = 0;
+ if (plugin)
+ factory = qobject_cast<GeneralFactory *>(plugin);
+
+ if (factory)
+ {
+ factories->append(factory);
+ files << pluginsDir.absoluteFilePath(fileName);
+ }
+ }
+ }
+}
+
+General::General(QObject *parent)
+ : QObject(parent)
+{
+}
+
+
+General::~General()
+{
+}
+
+void General::setState(const uint&)
+{}
+
+void General::setSongInfo(const SongInfo &song)
+{}
+
+
+QList<GeneralFactory*> *General::generalFactories()
+{
+ checkFactories();
+ return factories;
+}
+
+QStringList General::generalFiles()
+{
+ checkFactories();
+ return files;
+}
+
+void General::setEnabled(GeneralFactory* factory, bool enable)
+{
+ checkFactories();
+ if(!factories->contains(factory))
+ return;
+
+ QString name = files.at(factories->indexOf(factory)).section('/',-1);
+ QSettings settings ( QDir::homePath() +"/.qmmp/qmmprc", QSettings::IniFormat );
+ QStringList genList = settings.value("General/plugin_files").toStringList();
+
+ if(enable)
+ {
+ if (!genList.contains(name))
+ genList << name;
+ }
+ else
+ genList.removeAll(name);
+ settings.setValue("General/plugin_files", genList);
+}
+
+bool General::isEnabled(GeneralFactory* factory)
+{
+ checkFactories();
+ if(!factories->contains(factory))
+ return FALSE;
+ QString name = files.at(factories->indexOf(factory)).section('/',-1);
+ QSettings settings ( QDir::homePath() +"/.qmmp/qmmprc", QSettings::IniFormat );
+ QStringList genList = settings.value("General/plugin_files").toStringList();
+ return genList.contains(name);
+}
+
+void General::play()
+{
+ emit commandCalled(Play);
+}
+
+void General::pause()
+{
+ emit commandCalled(Pause);
+}
+
+void General::stop()
+{
+ emit commandCalled(Stop);
+}
+
+void General::next()
+{
+ emit commandCalled(Next);
+}
+
+void General::previous()
+{
+ emit commandCalled(Previous);
+}
+
+void General::exit()
+{
+ emit commandCalled(Exit);
+}
+
+void General::toggleVisibility()
+{
+ emit commandCalled(ToggleVisibility);
+}
diff --git a/src/qmmpui/general.h b/src/qmmpui/general.h
new file mode 100644
index 000000000..a7cc0e142
--- /dev/null
+++ b/src/qmmpui/general.h
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * Copyright (C) 2008 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 GENERAL_H
+#define GENERAL_H
+
+#include <QObject>
+#include <QStringList>
+#include <QMap>
+
+#include "songinfo.h"
+#include "generalfactory.h"
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class General : public QObject
+{
+ Q_OBJECT
+public:
+ General(QObject *parent = 0);
+
+ ~General();
+
+ enum State
+ {
+ Playing = 0,
+ Paused,
+ Stopped
+ };
+
+ enum Command
+ {
+ Play = 0,
+ Stop,
+ Pause,
+ Previous,
+ Next,
+ Exit,
+ ToggleVisibility
+ };
+
+ virtual void setState(const uint &state);
+ virtual void setSongInfo(const SongInfo &song);
+
+ //static methods
+ static QList<GeneralFactory*> *generalFactories();
+ static QStringList generalFiles();
+ static void setEnabled(GeneralFactory* factory, bool enable = TRUE);
+ static bool isEnabled(GeneralFactory* factory);
+
+signals:
+ void commandCalled(uint command);
+
+public slots:
+ void play();
+ void pause();
+ void stop();
+ void next();
+ void previous();
+ void exit();
+ void toggleVisibility();
+
+private:
+ QMap <uint, QString> m_strValues;
+ QMap <uint, uint> m_numValues;
+
+};
+
+#endif
diff --git a/src/qmmpui/generalfactory.h b/src/qmmpui/generalfactory.h
new file mode 100644
index 000000000..3038b597c
--- /dev/null
+++ b/src/qmmpui/generalfactory.h
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * Copyright (C) 2008 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 GENERALFACTORY_H
+#define GENERALFACTORY_H
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class QObject;
+class QTranslator;
+
+class General;
+
+struct GeneralProperties
+{
+ QString name;
+ bool hasAbout;
+ bool hasSettings;
+};
+
+class GeneralFactory
+{
+public:
+ virtual ~GeneralFactory() {}
+ virtual const GeneralProperties properties() const = 0;
+ virtual General *create(QObject *parent) = 0;
+ virtual void showSettings(QWidget *parent) = 0;
+ virtual void showAbout(QWidget *parent) = 0;
+ virtual QTranslator *createTranslator(QObject *parent) = 0;
+};
+
+Q_DECLARE_INTERFACE(GeneralFactory, "GeneralFactory/1.0");
+
+
+#endif
diff --git a/src/qmmpui/generalhandler.cpp b/src/qmmpui/generalhandler.cpp
new file mode 100644
index 000000000..dc29f281a
--- /dev/null
+++ b/src/qmmpui/generalhandler.cpp
@@ -0,0 +1,143 @@
+/***************************************************************************
+ * Copyright (C) 2008 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 "general.h"
+#include "generalfactory.h"
+
+#include "generalhandler.h"
+
+GeneralHandler *GeneralHandler::m_instance = 0;
+
+GeneralHandler::GeneralHandler(QObject *parent)
+ : QObject(parent)
+{
+ m_instance = this;
+ m_state = General::Stopped;
+ GeneralFactory* factory;
+ foreach(factory, *General::generalFactories())
+ {
+ if (General::isEnabled(factory))
+ {
+ General *general = factory->create(parent);
+ connect(general, SIGNAL(commandCalled(uint)), SLOT(processCommand(uint)));
+ m_generals.append(general);
+ }
+ }
+}
+
+GeneralHandler::~GeneralHandler()
+{}
+
+void GeneralHandler::setState(uint state)
+{
+ if (state == m_state)
+ return;
+ m_state = state;
+ General *general;
+ if (state == General::Stopped)
+ m_songInfo.clear();
+
+ foreach(general, m_generals)
+ {
+ general->setState(state);
+ }
+}
+
+void GeneralHandler::setSongInfo(const SongInfo &info)
+{
+ if (m_state == General::Stopped)
+ return;
+ if (m_songInfo != info)
+ {
+ m_songInfo = info;
+ General *general;
+ foreach(general, m_generals)
+ {
+ general->setSongInfo(m_songInfo);
+ }
+ }
+}
+
+void GeneralHandler::updateConfig()
+{
+ while (!m_generals.isEmpty())
+ delete m_generals.takeFirst();
+
+ GeneralFactory* factory;
+ foreach(factory, *General::generalFactories())
+ {
+ if (General::isEnabled(factory))
+ {
+ General *general = factory->create(parent());
+ connect(general, SIGNAL(commandCalled(uint)), SLOT(processCommand(uint)));
+ m_generals.append(general);
+ general->setState(m_state);
+ if (m_state != General::Stopped)
+ general->setSongInfo(m_songInfo);
+ }
+ }
+}
+
+GeneralHandler* GeneralHandler::instance()
+{
+ return m_instance;
+}
+
+void GeneralHandler::processCommand(uint command)
+{
+ switch ((uint) command)
+ {
+ case General::Play:
+ {
+ emit playCalled();
+ break;
+ }
+ case General::Stop:
+ {
+ emit stopCalled();
+ break;
+ }
+ case General::Pause:
+ {
+ emit pauseCalled();
+ break;
+ }
+ case General::Previous:
+ {
+ emit previousCalled();
+ break;
+ }
+ case General::Next:
+ {
+ emit nextCalled();
+ break;
+ }
+ case General::Exit:
+ {
+ emit exitCalled();
+ break;
+ }
+ case General::ToggleVisibility:
+ {
+ emit toggleVisibilityCalled();
+ break;
+ }
+ }
+}
diff --git a/src/qmmpui/generalhandler.h b/src/qmmpui/generalhandler.h
new file mode 100644
index 000000000..308a0a694
--- /dev/null
+++ b/src/qmmpui/generalhandler.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (C) 2008 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 GENERALHANDLER_H
+#define GENERALHANDLER_H
+
+#include <QObject>
+
+#include "songinfo.h"
+
+class General;
+class GeneralFactory;
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class GeneralHandler : public QObject
+{
+ Q_OBJECT
+public:
+ GeneralHandler(QObject *parent = 0);
+
+ ~GeneralHandler();
+
+ void setSongInfo(const SongInfo &info);
+ void updateConfig();
+ static GeneralHandler* instance();
+
+signals:
+ void playCalled();
+ void pauseCalled();
+ void stopCalled();
+ void nextCalled();
+ void previousCalled();
+ void exitCalled();
+ void toggleVisibilityCalled();
+
+public slots:
+ void setState(uint state);
+
+private slots:
+ void processCommand(uint command);
+
+private:
+ void connectSignals(General*);
+ QList <General*> m_generals;
+ SongInfo m_songInfo;
+ uint m_state;
+ static GeneralHandler* m_instance;
+
+};
+
+#endif
diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro
new file mode 100644
index 000000000..88c60a0da
--- /dev/null
+++ b/src/qmmpui/qmmpui.pro
@@ -0,0 +1,38 @@
+include(../../qmmp.pri)
+
+TARGET = ../../lib/qmmpui
+CONFIG += release \
+warn_on \
+qt \
+thread
+
+TEMPLATE = lib
+
+
+isEmpty(LIB_DIR){
+ LIB_DIR = /lib
+}
+
+unix {
+ LINE1 = $$sprintf(echo \"%1ifndef CONFIG_H\" > ./config.h, $$LITERAL_HASH)
+ LINE2 = $$sprintf(echo \"%1define CONFIG_H\" >> ./config.h, $$LITERAL_HASH)
+ LINE3 = $$sprintf(echo \"%1define LIB_DIR \\\"%2\\\"\" >> ./config.h, $$LITERAL_HASH, $$LIB_DIR)
+ LINE4 = $$sprintf(echo \"%1endif\" >> ./config.h, $$LITERAL_HASH)
+ system($$LINE1)
+ system($$LINE2)
+ system($$LINE3)
+ system($$LINE4)
+ QMAKE_CLEAN = ./config.h
+}
+
+
+target.path = $$LIB_DIR
+INSTALLS += target
+HEADERS += general.h \
+generalfactory.h \
+ generalhandler.h \
+ songinfo.h
+SOURCES += general.cpp \
+ generalhandler.cpp \
+ songinfo.cpp
+
diff --git a/src/qmmpui/songinfo.cpp b/src/qmmpui/songinfo.cpp
new file mode 100644
index 000000000..6fa1e831e
--- /dev/null
+++ b/src/qmmpui/songinfo.cpp
@@ -0,0 +1,137 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 "songinfo.h"
+
+SongInfo::SongInfo()
+{}
+
+SongInfo::SongInfo(const SongInfo &other)
+{
+ *this = other;
+}
+
+SongInfo::~SongInfo()
+{}
+
+void SongInfo::operator=(const SongInfo &info)
+{
+ setValue(TITLE,info.title ());
+ setValue(ARTIST,info.artist ());
+ setValue(ALBUM,info.album ());
+ setValue(COMMENT,info.comment ());
+ setValue(GENRE,info.genre ());
+ setValue(YEAR,info.year ());
+ setValue(TRACK,info.track ());
+ setValue(LENGTH,info.length ());
+ setValue(STREAM,info.isStream());
+}
+
+bool SongInfo::operator==(const SongInfo &info)
+{
+ return title() == info.title() &&
+ artist() == info.artist() &&
+ album() == info.album() &&
+ comment() == info.comment() &&
+ genre() == info.genre() &&
+ track() == info.track() &&
+ year() == info.year() &&
+ isStream() == info.isStream();
+}
+
+bool SongInfo::operator!=(const SongInfo &info)
+{
+ return !operator==(info);
+}
+
+void SongInfo::setValue(uint name, const QString &value)
+{
+ if (!value.isEmpty())
+ m_strValues.insert (name, value);
+}
+
+void SongInfo::setValue(uint name, const uint &value)
+{
+ if (value > 0)
+ m_numValues.insert (name, value);
+}
+
+void SongInfo::setValue(uint name, const bool &value)
+{
+ if(name == STREAM)
+ m_stream = value;
+}
+
+const QString SongInfo::title () const
+{
+ return m_strValues[TITLE];
+}
+
+const QString SongInfo::artist () const
+{
+ return m_strValues[ARTIST];
+}
+
+const QString SongInfo::album () const
+{
+ return m_strValues[ALBUM];
+}
+
+const QString SongInfo::comment () const
+{
+ return m_strValues[COMMENT];
+}
+
+const QString SongInfo::genre () const
+{
+ return m_strValues[GENRE];
+}
+
+const uint SongInfo::year () const
+{
+ return m_numValues[YEAR];
+}
+
+const uint SongInfo::track () const
+{
+ return m_numValues[TRACK];
+}
+
+const uint SongInfo::length () const
+{
+ return m_numValues[LENGTH];
+}
+
+const bool SongInfo::isEmpty () const
+{
+ return m_strValues.isEmpty();
+}
+
+void SongInfo::clear ()
+{
+ m_strValues.clear();
+ m_numValues.clear();
+ m_stream = FALSE;
+}
+
+const bool SongInfo::isStream () const
+{
+ return m_stream;
+}
+
diff --git a/src/qmmpui/songinfo.h b/src/qmmpui/songinfo.h
new file mode 100644
index 000000000..7bc43381d
--- /dev/null
+++ b/src/qmmpui/songinfo.h
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 SONGINFO_H
+#define SONGINFO_H
+
+#include <QMap>
+#include <QString>
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+
+class SongInfo{
+public:
+ public:
+ SongInfo();
+ SongInfo(const SongInfo &other);
+
+ ~SongInfo();
+
+ enum Type
+ {
+ TITLE = 0,
+ ARTIST,
+ ALBUM,
+ COMMENT,
+ GENRE,
+ YEAR,
+ TRACK,
+ LENGTH,
+ STREAM
+ };
+
+ void operator=(const SongInfo &info);
+ bool operator==(const SongInfo &info);
+ bool operator!=(const SongInfo &info);
+ void setValue(uint name, const QString &value);
+ void setValue(uint name, const uint &value);
+ void setValue(uint name, const bool &value);
+ const QString title () const;
+ const QString artist () const;
+ const QString album () const;
+ const QString comment () const;
+ const QString genre () const;
+ const uint year () const;
+ const uint track () const;
+ const uint length () const;
+ const bool isEmpty () const;
+ const bool isStream () const;
+ void clear();
+
+private:
+ QMap <uint, QString> m_strValues;
+ QMap <uint, uint> m_numValues;
+ bool m_stream;
+
+};
+
+#endif