~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/tools/tunecontroller/tunecontrollermanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * turencontrollermanager.cpp
 
3
 * Copyright (C) 2006  Remko Troncon
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef QT_STATICPLUGIN
 
22
#define QT_STATICPLUGIN
 
23
#endif
 
24
 
 
25
#include <QtCore>
 
26
#include <QPluginLoader>
 
27
#include <QCoreApplication>
 
28
#include <QDebug>
 
29
 
 
30
#include "tunecontrollermanager.h"
 
31
#include "tunecontrollerplugin.h"
 
32
 
 
33
/**
 
34
 * \class TuneControllerManager
 
35
 * \brief A manager for all tune controller plugins.
 
36
 */
 
37
 
 
38
 
 
39
TuneControllerManager::TuneControllerManager() : QObject(QCoreApplication::instance())
 
40
{
 
41
        foreach(QObject* plugin,QPluginLoader::staticInstances()) {
 
42
                loadPlugin(plugin);        
 
43
        }
 
44
}
 
45
 
 
46
 
 
47
/**
 
48
 * \brief Returns a list of all the supported controllers.
 
49
 */
 
50
QList<QString> TuneControllerManager::controllerNames() const
 
51
{
 
52
        return plugins_.keys();
 
53
}
 
54
 
 
55
 
 
56
/**
 
57
 * \brief Creates a new controller.
 
58
 */
 
59
TuneController* TuneControllerManager::createController(const QString& name) const
 
60
{
 
61
        return plugins_[name]->createController();
 
62
}
 
63
 
 
64
 
 
65
/**
 
66
 * \brief Loads a TuneControllerPlugin from a file.
 
67
 */
 
68
bool TuneControllerManager::loadPlugin(const QString& file)
 
69
{
 
70
        //return QPluginLoader(file).load();
 
71
        return loadPlugin(QPluginLoader(file).instance());
 
72
}
 
73
 
 
74
 
 
75
bool TuneControllerManager::loadPlugin(QObject* plugin)
 
76
{
 
77
        if (!plugin)
 
78
                return false;
 
79
 
 
80
        TuneControllerPlugin* tcplugin = qobject_cast<TuneControllerPlugin*>(plugin);
 
81
        if (tcplugin) {
 
82
                if(!plugins_.contains(tcplugin->name())) {
 
83
                        //qDebug() << "Registering plugin " << tcplugin->name();
 
84
                        plugins_[tcplugin->name()] = tcplugin;
 
85
                }
 
86
                return true;
 
87
        }
 
88
 
 
89
        return false;
 
90
}
 
91
        
 
92
/**
 
93
 * \brief Retrieves the global plugin manager.
 
94
 */
 
95
TuneControllerManager* TuneControllerManager::instance()
 
96
{
 
97
        if (!instance_) 
 
98
                instance_ = new TuneControllerManager();
 
99
        return instance_;
 
100
}
 
101
        
 
102
TuneControllerManager* TuneControllerManager::instance_ = 0;
 
103
 
 
104
 
 
105
// ---------------------------------------------------------------------------- 
 
106
 
 
107
#ifdef TC_ITUNES
 
108
Q_IMPORT_PLUGIN(itunesplugin)
 
109
#endif
 
110
 
 
111
#ifdef TC_XMMS
 
112
Q_IMPORT_PLUGIN(xmmsplugin);
 
113
#endif
 
114
 
 
115
#ifdef TC_WINAMP
 
116
Q_IMPORT_PLUGIN(winampplugin);
 
117
#endif
 
118
 
 
119
#ifdef TC_PSIFILE
 
120
Q_IMPORT_PLUGIN(psifileplugin);
 
121
#endif