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)
113
descType = "decoder";
116
descType = "encoder";
125
return QString("gstreamer|0.10|%0|%1|%2-%3")
126
.arg( qApp->applicationName() )
127
.arg( description(caps, type) )
129
.arg( getCapType(caps) );
132
QString PluginInstaller::buildInstallationString(const gchar *name, PluginType type)
137
descType = "element";
142
return QString("gstreamer|0.10|%0|%1|%2-%3")
143
.arg( qApp->applicationName() )
144
.arg( description(name, type) )
149
PluginInstaller::PluginInstaller(QObject *parent)
154
void PluginInstaller::addPlugin(const QString &name, PluginType type)
156
m_pluginList.insert(name, type);
159
void PluginInstaller::addPlugin(const GstCaps *caps, PluginType type)
161
m_capList.insert(gst_caps_copy(caps), type);
164
#ifdef PLUGIN_INSTALL_API
165
void PluginInstaller::run()
167
GstInstallPluginsContext *ctx = gst_install_plugins_context_new();
168
QWidget *activeWindow = QApplication::activeWindow();
170
gst_install_plugins_context_set_xid(ctx, static_cast<int>(activeWindow->winId()));
172
gchar *details[m_pluginList.size()+m_capList.size()+1];
174
foreach(QString plugin, m_pluginList.keys()) {
175
details[i] = strdup(buildInstallationString(plugin.toLocal8Bit().data(), m_pluginList[plugin]).toLocal8Bit().data());
178
foreach(GstCaps *caps, m_capList.keys()) {
179
details[i] = strdup(buildInstallationString(caps, m_capList[caps]).toLocal8Bit().data());
184
GstInstallPluginsReturn status;
185
status = gst_install_plugins_async(details, ctx, pluginInstallationDone, new QPointer<PluginInstaller>(this));
186
gst_install_plugins_context_free(ctx);
187
if (status != GST_INSTALL_PLUGINS_STARTED_OK) {
188
if (status == GST_INSTALL_PLUGINS_HELPER_MISSING)
189
emit failure(tr("Missing codec helper script assistant."));
191
emit failure(tr("Plugin codec installation failed."));
200
void PluginInstaller::pluginInstallationDone(GstInstallPluginsReturn result, gpointer data)
202
QPointer<PluginInstaller> *that = static_cast<QPointer<PluginInstaller>*>(data);
204
qRegisterMetaType<GstInstallPluginsReturn>("GstInstallPluginsReturn");
205
(*that)->pluginInstallationResult(result);
209
void PluginInstaller::pluginInstallationResult(GstInstallPluginsReturn result)
212
case GST_INSTALL_PLUGINS_INVALID:
213
emit failure(tr("Phonon attempted to install an invalid codec name."));
215
case GST_INSTALL_PLUGINS_CRASHED:
216
emit failure(tr("The codec installer crashed."));
218
case GST_INSTALL_PLUGINS_NOT_FOUND:
219
emit failure(tr("The required codec could not be found for installation."));
221
case GST_INSTALL_PLUGINS_ERROR:
222
emit failure(tr("An unspecified error occurred during codec installation."));
224
case GST_INSTALL_PLUGINS_PARTIAL_SUCCESS:
225
emit failure(tr("Not all codecs could be installed."));
227
case GST_INSTALL_PLUGINS_USER_ABORT:
228
emit failure(tr("User aborted codec installation"));
230
//These four should never ever be passed in.
231
//If they have, gstreamer has probably imploded in on itself.
232
case GST_INSTALL_PLUGINS_STARTED_OK:
233
case GST_INSTALL_PLUGINS_INTERNAL_FAILURE:
234
case GST_INSTALL_PLUGINS_HELPER_MISSING:
235
case GST_INSTALL_PLUGINS_INSTALL_IN_PROGRESS:
236
//But this one is OK.
237
case GST_INSTALL_PLUGINS_SUCCESS:
238
if (!gst_update_registry()) {
239
emit failure(tr("Could not update plugin registry after update."));
248
PluginInstaller::InstallStatus PluginInstaller::checkInstalledPlugins()
250
bool allFound = true;
251
foreach(QString plugin, m_pluginList.keys()) {
252
if (!gst_default_registry_check_feature_version(plugin.toLocal8Bit().data(), 0, 10, 0)) {
257
if (!allFound || m_capList.size() > 0) {
258
#ifdef PLUGIN_INSTALL_API
269
QString PluginInstaller::getCapType(const GstCaps *caps)
271
GstStructure *str = gst_caps_get_structure (caps, 0);
272
return QString::fromUtf8(gst_structure_get_name (str));;
275
void PluginInstaller::reset()
277
foreach(GstCaps *caps, m_capList.keys()) {
278
gst_caps_unref(caps);
281
m_pluginList.clear();
289
#include "moc_plugininstaller.cpp"