1
/* This file is part of the KDE project.
3
Copyright (C) 2011 Trever Fischer <tdfischer@fedoraproject.org>
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include "plugininstaller.h"
20
#include <QtCore/QCoreApplication>
21
#include <QtGui/QApplication>
22
#include <QtGui/QWidget>
23
#include <QtCore/QLibrary>
24
#include <QtCore/QPointer>
25
#include <QtCore/QMetaType>
26
#include <QtCore/QDebug>
28
#ifdef PLUGIN_INSTALL_API
29
#include <gst/pbutils/pbutils.h>
38
bool PluginInstaller::s_ready = false;
40
bool PluginInstaller::init()
43
#ifdef PLUGIN_INSTALL_API
51
QString PluginInstaller::description(const GstCaps *caps, PluginType type)
53
#ifdef PLUGIN_INSTALL_API
56
gchar *pluginDesc = NULL;
59
pluginDesc = gst_pb_utils_get_decoder_description(caps);
62
pluginDesc = gst_pb_utils_get_encoder_description(caps);
65
pluginDesc = gst_pb_utils_get_codec_description(caps);
70
pluginStr = QString::fromUtf8(pluginDesc);
78
return getCapType(caps);
81
QString PluginInstaller::description(const gchar *name, PluginType type)
83
#ifdef PLUGIN_INSTALL_API
86
gchar *pluginDesc = NULL;
89
pluginDesc = gst_pb_utils_get_source_description(name);
92
pluginDesc = gst_pb_utils_get_sink_description(name);
95
pluginDesc = gst_pb_utils_get_element_description(name);
100
pluginStr = QString::fromUtf8(pluginDesc);
108
QString PluginInstaller::buildInstallationString(const GstCaps *caps, PluginType type)
114
descType = "decoder";
117
descType = "encoder";
123
return QString("gstreamer|0.10|%0|%1|%2-%3")
124
.arg( qApp->applicationName() )
125
.arg( description(caps, type) )
127
.arg( getCapType(caps) );
130
QString PluginInstaller::buildInstallationString(const gchar *name, PluginType type)
135
descType = "element";
140
return QString("gstreamer|0.10|%0|%1|%2-%3")
141
.arg( qApp->applicationName() )
142
.arg( description(name, type) )
147
PluginInstaller::PluginInstaller(QObject *parent)
152
void PluginInstaller::addPlugin(const QString &name, PluginType type)
154
m_pluginList.insert(name, type);
157
void PluginInstaller::addPlugin(const GstCaps *caps, PluginType type)
159
m_capList.insert(gst_caps_copy(caps), type);
162
#ifdef PLUGIN_INSTALL_API
163
void PluginInstaller::run()
165
GstInstallPluginsContext *ctx = gst_install_plugins_context_new();
166
QWidget *activeWindow = QApplication::activeWindow();
168
gst_install_plugins_context_set_xid(ctx, static_cast<int>(activeWindow->winId()));
170
gchar *details[m_pluginList.size()+m_capList.size()+1];
172
foreach(QString plugin, m_pluginList.keys()) {
173
details[i] = strdup(buildInstallationString(plugin.toLocal8Bit().data(), m_pluginList[plugin]).toLocal8Bit().data());
176
foreach(GstCaps *caps, m_capList.keys()) {
177
details[i] = strdup(buildInstallationString(caps, m_capList[caps]).toLocal8Bit().data());
182
GstInstallPluginsReturn status;
183
status = gst_install_plugins_async(details, ctx, pluginInstallationDone, new QPointer<PluginInstaller>(this));
184
gst_install_plugins_context_free(ctx);
185
if (status != GST_INSTALL_PLUGINS_STARTED_OK) {
186
if (status == GST_INSTALL_PLUGINS_HELPER_MISSING)
187
emit failure(tr("Missing codec helper script assistant."));
189
emit failure(tr("Plugin codec installation failed."));
198
void PluginInstaller::pluginInstallationDone(GstInstallPluginsReturn result, gpointer data)
200
QPointer<PluginInstaller> *that = static_cast<QPointer<PluginInstaller>*>(data);
202
qRegisterMetaType<GstInstallPluginsReturn>("GstInstallPluginsReturn");
203
(*that)->pluginInstallationResult(result);
207
void PluginInstaller::pluginInstallationResult(GstInstallPluginsReturn result)
210
case GST_INSTALL_PLUGINS_INVALID:
211
emit failure(tr("Phonon attempted to install an invalid codec name."));
213
case GST_INSTALL_PLUGINS_CRASHED:
214
emit failure(tr("The codec installer crashed."));
216
case GST_INSTALL_PLUGINS_NOT_FOUND:
217
emit failure(tr("The required codec could not be found for installation."));
219
case GST_INSTALL_PLUGINS_ERROR:
220
emit failure(tr("An unspecified error occurred during codec installation."));
222
case GST_INSTALL_PLUGINS_PARTIAL_SUCCESS:
223
emit failure(tr("Not all codecs could be installed."));
225
case GST_INSTALL_PLUGINS_USER_ABORT:
226
emit failure(tr("User aborted codec installation"));
228
//These four should never ever be passed in.
229
//If they have, gstreamer has probably imploded in on itself.
230
case GST_INSTALL_PLUGINS_STARTED_OK:
231
case GST_INSTALL_PLUGINS_INTERNAL_FAILURE:
232
case GST_INSTALL_PLUGINS_HELPER_MISSING:
233
case GST_INSTALL_PLUGINS_INSTALL_IN_PROGRESS:
234
//But this one is OK.
235
case GST_INSTALL_PLUGINS_SUCCESS:
236
if (!gst_update_registry()) {
237
emit failure(tr("Could not update plugin registry after update."));
246
PluginInstaller::InstallStatus PluginInstaller::checkInstalledPlugins()
248
bool allFound = true;
249
foreach(QString plugin, m_pluginList.keys()) {
250
if (!gst_default_registry_check_feature_version(plugin.toLocal8Bit().data(), 0, 10, 0)) {
255
if (!allFound || m_capList.size() > 0) {
256
#ifdef PLUGIN_INSTALL_API
267
QString PluginInstaller::getCapType(const GstCaps *caps)
269
GstStructure *str = gst_caps_get_structure (caps, 0);
270
return QString::fromUtf8(gst_structure_get_name (str));;
273
void PluginInstaller::reset()
275
foreach(GstCaps *caps, m_capList.keys()) {
276
gst_caps_unref(caps);
279
m_pluginList.clear();
287
#include "moc_plugininstaller.cpp"