File indexing completed on 2024-04-14 15:48:57

0001 /***************************************************************************
0002  *   Copyright (C) 2009-2011 by Daniel Nicoletti                           *
0003  *   dantti12@gmail.com                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; see the file COPYING. If not, write to       *
0017  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0018  *   Boston, MA 02110-1301, USA.                                           *
0019  ***************************************************************************/
0020 
0021 #include "PkInstallGStreamerResources.h"
0022 
0023 #include "IntroDialog.h"
0024 #include <Daemon>
0025 
0026 #include <PkStrings.h>
0027 
0028 #include <QStandardItemModel>
0029 #include <KLocalizedString>
0030 
0031 #include <QLoggingCategory>
0032 
0033 PkInstallGStreamerResources::PkInstallGStreamerResources(uint xid,
0034                                                          const QStringList &resources,
0035                                                          const QString &interaction,
0036                                                          const QDBusMessage &message,
0037                                                          QWidget *parent)
0038     : SessionTask(xid, interaction, message, parent)
0039 {
0040     setWindowTitle(i18n("Install GStreamer Resources"));
0041 
0042     auto introDialog = new IntroDialog(this);
0043     auto model = new QStandardItemModel(this);
0044     introDialog->setModel(model);
0045     connect(introDialog, &IntroDialog::continueChanged, this, &PkInstallGStreamerResources::enableButtonOk);
0046     setMainWidget(introDialog);
0047 
0048     bool encoder = false;
0049     bool decoder = false;
0050     // Resources are strings like "ID3 tag|gstreamer0.10(decoder-application/x-id3)()(64bit)"
0051     for (const QString &codec : resources) {
0052         if (codec.contains(QLatin1String("|gstreamer0.10(decoder"))) {
0053             decoder = true;
0054         } else if (codec.contains(QLatin1String("|gstreamer0.10(encoder"))) {
0055             encoder = true;
0056         }
0057 
0058         auto item = new QStandardItem(codec.section(QLatin1Char('|'), 0, 0));
0059         item->setIcon(QIcon::fromTheme(QLatin1String("x-kde-nsplugin-generated")).pixmap(32, 32));
0060         item->setFlags(Qt::ItemIsEnabled);
0061         model->appendRow(item);
0062 
0063         m_resources << codec.section(QLatin1Char('|'), 1, -1);
0064     }
0065 
0066 
0067     QString description;
0068     description = i18np("The following plugin is required. "
0069                         "Do you want to search for this now?",
0070                         "The following plugins are required. "
0071                         "Do you want to search for these now?",
0072                         m_resources.size());
0073     enableButtonOk(true);
0074 
0075     QString title;
0076     // this will come from DBus interface
0077     if (parentTitle.isNull()) {
0078         if (decoder && !encoder) {
0079             // TRANSLATORS: a random program which we can't get the name wants to decode something
0080             title = i18np("A program requires an additional plugin to decode this file",
0081                           "A program requires additional plugins to decode this file",
0082                           m_resources.size());
0083         } else if (!decoder && encoder) {
0084             // TRANSLATORS: a random program which we can't get the name wants to encode something
0085             title = i18np("A program requires an additional plugin to encode this file",
0086                           "A program requires additional plugins to encode this file",
0087                           m_resources.size());
0088         } else {
0089             // TRANSLATORS: a random program which we can't get the name wants to do something (unknown)
0090             title = i18np("A program requires an additional plugin for this operation",
0091                           "A program requires additional plugins for this operation",
0092                           m_resources.size());
0093         }
0094     } else {
0095         if (decoder && !encoder) {
0096             // TRANSLATORS: a program wants to decode something (unknown) -- string is a program name, e.g. "Movie Player"
0097             title = i18np("%2 requires an additional plugin to decode this file",
0098                         "%2 requires additional plugins to decode this file",
0099                         m_resources.size(),
0100                         parentTitle);
0101         } else if (!decoder && encoder) {
0102             // TRANSLATORS: a program wants to encode something (unknown) -- string is a program name, e.g. "Movie Player"
0103             title = i18np("%2 requires an additional plugin to encode this file",
0104                         "%2 requires additional plugins to encode this file",
0105                         m_resources.size(),
0106                         parentTitle);
0107         } else {
0108             // TRANSLATORS: a program wants to do something (unknown) -- string is a program name, e.g. "Movie Player"
0109             title = i18np("%2 requires an additional plugin for this operation",
0110                         "%2 requires additional plugins for this operation",
0111                         m_resources.size(),
0112                         parentTitle);
0113         }
0114     }
0115 
0116     introDialog->setDescription(description);
0117     setTitle(title);
0118 }
0119 
0120 PkInstallGStreamerResources::~PkInstallGStreamerResources()
0121 {
0122 }
0123 
0124 void PkInstallGStreamerResources::search()
0125 {
0126     auto transaction = new PkTransaction(this);
0127     Transaction *t;
0128     t = Daemon::whatProvides(m_resources,
0129                              Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
0130     transaction->setupTransaction(t);
0131     setTransaction(Transaction::RoleWhatProvides, transaction);
0132     connect(transaction, &PkTransaction::finished, this, &PkInstallGStreamerResources::searchFinished, Qt::UniqueConnection);
0133     connect(transaction, &PkTransaction::package, this, &PkInstallGStreamerResources::addPackage);
0134 }
0135 
0136 void PkInstallGStreamerResources::notFound()
0137 {
0138     if (showWarning()) {
0139         QString mgs = i18n("No results found");
0140         setInfo(mgs,
0141                 i18n("Could not find plugin "
0142                      "in any configured software source"));
0143     }
0144     sendErrorFinished(NoPackagesFound, QLatin1String("failed to find codec"));
0145 }
0146 
0147 #include "moc_PkInstallGStreamerResources.cpp"