File indexing completed on 2022-09-27 16:24:38

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 "PkInstallMimeTypes.h"
0022 #include "IntroDialog.h"
0023 #include "FilesModel.h"
0024 
0025 #include <Daemon>
0026 
0027 #include <PkStrings.h>
0028 
0029 #include <KLocalizedString>
0030 
0031 #include <QLoggingCategory>
0032 
0033 PkInstallMimeTypes::PkInstallMimeTypes(uint xid,
0034                                       const QStringList &mime_types,
0035                                       const QString &interaction,
0036                                       const QDBusMessage &message,
0037                                       QWidget *parent)
0038  : SessionTask(xid, interaction, message, parent),
0039    m_mimeTypes(mime_types)
0040 {
0041     setWindowTitle(i18n("Install Support for File Types"));
0042 
0043     auto introDialog = new IntroDialog(this);
0044     m_model = new FilesModel(QStringList(), mime_types, this);
0045     introDialog->setModel(m_model);
0046     connect(introDialog, &IntroDialog::continueChanged, this, &PkInstallMimeTypes::enableButtonOk);
0047     setMainWidget(introDialog);
0048 
0049     QString description;
0050     if (m_model->rowCount()) {
0051         description = i18np("Do you want to search for a program that can open this file type?",
0052                             "Do you want to search for a program that can open these file types?",
0053                             m_model->rowCount());
0054         enableButtonOk(true);
0055     } else {
0056         description = i18n("No valid file types were provided");
0057     }
0058     introDialog->setDescription(description);
0059 
0060     QString title;
0061     // this will come from DBus interface
0062     if (parentTitle.isNull()) {
0063         title = i18np("A program is requiring support to open this kind of files",
0064                       "A program is requiring support to open these kinds of files",
0065                       m_model->rowCount());
0066     } else {
0067         title = i18np("The application %2 is requiring support to open this kind of files",
0068                       "The application %2 is requiring support to open these kinds of files",
0069                       m_model->rowCount(),
0070                       parentTitle);
0071     }
0072     setTitle(title);
0073 }
0074 
0075 PkInstallMimeTypes::~PkInstallMimeTypes()
0076 {
0077 }
0078 
0079 void PkInstallMimeTypes::search()
0080 {
0081     QStringList mimeTypes = m_model->files();
0082     auto transaction = new PkTransaction(this);
0083     Transaction *t;
0084     t = Daemon::whatProvides(mimeTypes,
0085                              Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
0086     transaction->setupTransaction(t);
0087     setTransaction(Transaction::RoleWhatProvides, transaction);
0088     connect(transaction, &PkTransaction::finished, this, &PkInstallMimeTypes::searchFinished, Qt::UniqueConnection);
0089     connect(transaction, &PkTransaction::package, this, &PkInstallMimeTypes::addPackage);
0090 }
0091 
0092 void PkInstallMimeTypes::notFound()
0093 {
0094     QString msg = i18n("Could not find software");
0095     if (showWarning()) {
0096         setInfo(msg, i18n("No new applications can be found "
0097                           "to handle this type of file"));
0098     }
0099     sendErrorFinished(NoPackagesFound, QLatin1String("nothing was found to handle mime type"));
0100 }
0101 
0102 //setTitle(i18np("Application that can open this type of file",
0103 //               "Applications that can open this type of file",
0104 //               m_foundPackages.size()));
0105 
0106 #include "moc_PkInstallMimeTypes.cpp"