Added DUI control panel applet
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / src / MafwGstRendererPlugin.cpp
1 /* 
2  * This file is part of QMAFW 
3  *
4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
5  * reserved.
6  *
7  * Contact: Visa Smolander <visa.smolander@nokia.com>
8  *
9  * This software, including documentation, is protected by copyright controlled
10  * by Nokia Corporation. All rights are reserved. Copying, including
11  * reproducing, storing, adapting or translating, any or all of this material
12  * requires the prior written consent of Nokia Corporation. This material also
13  * contains confidential information which may not be disclosed to others
14  * without the prior written consent of Nokia.
15  *
16  */
17
18 #include <QObject>
19 #include <QtPlugin>
20 #include <QDebug>
21 #include <QSettings>
22 #include <QCoreApplication>
23
24 #include <MafwInternalRegistry.h>
25
26 #include "MafwGstRendererPlugin.h"
27 #include "MafwGstRenderer.h"
28
29 #ifdef _VERSION_INFO
30 #include "version.h"
31 #endif
32
33 const QString PLUGIN_NAME = "MafwGstRendererPlugin";
34 const QString RENDERER_UUID = "mafw_gst_renderer";
35 const QString DBUS_WRAPPER_NAME = "qmafw-dbus-wrapper";
36 const QString RENDERER_PLUGIN_CONFIG_FILE = "/usr/share/qmafw/mafw-gst-renderer-plugin.conf";
37
38
39 MafwGstRendererPlugin::~MafwGstRendererPlugin()
40 {
41     qDebug() << __PRETTY_FUNCTION__;
42     for(int i = 0; i < m_rendererIds.count(); i++)
43     {
44         m_registry->removeExtension(m_rendererIds.at(i));
45     }
46 }
47
48 void MafwGstRendererPlugin::initialize(MafwInternalRegistry* registry)
49 {
50 #ifdef _VERSION_INFO
51     qDebug() << "mafw-gst-renderer revision:" << revision;
52     qDebug() << "mafw-gst-renderer library builtime:" << build_time;
53 #endif
54
55     Q_ASSERT(registry);
56
57     m_registry = registry;
58
59     QString rendererArrayKey;
60     QString appname = QCoreApplication::applicationName();
61     // appname can contain full path to config file
62     if(appname.endsWith(DBUS_WRAPPER_NAME))
63     {
64         // We are loading out-process renderers from config file
65         rendererArrayKey = "renderers";
66         loadRenderers(rendererArrayKey);
67     }
68     else
69     {
70         // We are loading in-process renderers from config file
71         rendererArrayKey = "in-process-renderers";
72         loadRenderers(rendererArrayKey);
73     }
74
75     // if there are no gst-renderers in config file, we create a "basic" gst-renderer
76     if(m_rendererIds.isEmpty())
77     {
78         MafwGstRenderer *rnd = new MafwGstRenderer(RENDERER_UUID,
79                                                    PLUGIN_NAME,
80                                                    "QMAFW GStreamer Renderer",
81                                                    registry);
82
83         QSettings settings(RENDERER_PLUGIN_CONFIG_FILE, QSettings::NativeFormat);
84
85         if(rnd->initialize(&settings))
86         {
87             m_registry->addRenderer(rnd);
88             m_rendererIds.append(RENDERER_UUID);
89         }
90         else
91         {
92             qCritical() << "Failed to initialize QMAFW GStreamer Renderer";
93             delete rnd;
94         }
95     }
96 }
97
98 void MafwGstRendererPlugin::loadRenderers(const QString& rendererArrayKey)
99 {
100     QSettings settings(RENDERER_PLUGIN_CONFIG_FILE, QSettings::NativeFormat);
101     QString id;
102     QString friendlyname;
103
104     QList<MafwGstRenderer*> rnds;
105
106     // Configuration file contains the array of renderer names and uuids as string.
107     // beginReadArray returns size of the array.
108     int size = settings.beginReadArray(rendererArrayKey);
109     for(int i = 0; i < size; i++)
110     {
111         settings.setArrayIndex(i);
112         id = settings.value("Id").toString();
113         friendlyname = settings.value("FriendlyName").toString();
114         MafwGstRenderer *rnd = new MafwGstRenderer(id,
115                                                    PLUGIN_NAME,
116                                                    friendlyname,
117                                                    m_registry);
118         rnds.append(rnd);
119     }
120     settings.endArray();
121
122     Q_FOREACH( MafwGstRenderer *rnd, rnds )
123     {
124         if(rnd->initialize(&settings))
125         {
126             m_registry->addRenderer(rnd);
127             m_rendererIds.append(rnd->uuid());
128         }
129         else
130         {
131             qCritical() << "Failed to initialize" << rnd->name();
132             delete rnd;
133         }
134     }
135 }
136
137 QString MafwGstRendererPlugin::name() const
138 {
139     return PLUGIN_NAME;
140 }
141
142 /*****************************************************************************
143  * Plugin export
144  ****************************************************************************/
145 Q_EXPORT_PLUGIN2(qmafw-gst-renderer-plugin, MafwGstRendererPlugin)