~dantti/apper/master

« back to all changes in this revision

Viewing changes to PkSession/PkInstallMimeTypes.cpp

  • Committer: Daniel Nicoletti
  • Date: 2012-12-16 13:51:04 UTC
  • Revision ID: git-v1:4e1499a55d1ec8a637f03979cde84aaa4a4440ba
Renaming ApperSentinel to ApperPkSession since that's all it will do now

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009-2011 by Daniel Nicoletti                           *
 
3
 *   dantti12@gmail.com                                                    *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; see the file COPYING. If not, write to       *
 
17
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
 
18
 *   Boston, MA 02110-1301, USA.                                           *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "PkInstallMimeTypes.h"
 
22
#include "IntroDialog.h"
 
23
#include "FilesModel.h"
 
24
 
 
25
#include <PkStrings.h>
 
26
 
 
27
#include <KLocale>
 
28
 
 
29
#include <KDebug>
 
30
 
 
31
PkInstallMimeTypes::PkInstallMimeTypes(uint xid,
 
32
                                      const QStringList &mime_types,
 
33
                                      const QString &interaction,
 
34
                                      const QDBusMessage &message,
 
35
                                      QWidget *parent)
 
36
 : SessionTask(xid, interaction, message, parent),
 
37
   m_mimeTypes(mime_types)
 
38
{
 
39
    setWindowTitle(i18n("Install Support for File Types"));
 
40
 
 
41
    IntroDialog *introDialog = new IntroDialog(this);
 
42
    m_model = new FilesModel(QStringList(), mime_types, this);
 
43
    introDialog->setModel(m_model);
 
44
    connect(introDialog, SIGNAL(continueChanged(bool)),
 
45
            this, SLOT(enableButtonOk(bool)));
 
46
    setMainWidget(introDialog);
 
47
 
 
48
    QString description;
 
49
    if (m_model->rowCount()) {
 
50
        description = i18np("Do you want to search for a program that can open this file type?",
 
51
                            "Do you want to search for a program that can open these file types?",
 
52
                            m_model->rowCount());
 
53
        enableButtonOk(true);
 
54
    } else {
 
55
        description = i18n("No valid file types were provided");
 
56
    }
 
57
    introDialog->setDescription(description);
 
58
 
 
59
    QString title;
 
60
    // this will come from DBus interface
 
61
    if (parentTitle.isNull()) {
 
62
        title = i18np("A program is requiring support to open this kind of files",
 
63
                      "A program is requiring support to open these kinds of files",
 
64
                      m_model->rowCount());
 
65
    } else {
 
66
        title = i18np("The application %2 is requiring support to open this kind of files",
 
67
                      "The application %2 is requiring support to open these kinds of files",
 
68
                      m_model->rowCount(),
 
69
                      parentTitle);
 
70
    }
 
71
    setTitle(title);
 
72
}
 
73
 
 
74
PkInstallMimeTypes::~PkInstallMimeTypes()
 
75
{
 
76
}
 
77
 
 
78
void PkInstallMimeTypes::search()
 
79
{
 
80
    QStringList mimeTypes = m_model->files();
 
81
    PkTransaction *transaction = new PkTransaction(this);
 
82
    setTransaction(Transaction::RoleWhatProvides, transaction);
 
83
    connect(transaction, SIGNAL(finished(PkTransaction::ExitStatus)),
 
84
            this, SLOT(searchFinished(PkTransaction::ExitStatus)), Qt::UniqueConnection);
 
85
    connect(transaction, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)),
 
86
            this, SLOT(addPackage(PackageKit::Transaction::Info,QString,QString)));
 
87
    transaction->whatProvides(Transaction::ProvidesMimetype,
 
88
                              mimeTypes,
 
89
                              Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
 
90
    if (transaction->error()) {
 
91
        if (showWarning()) {
 
92
            setError(i18n("Failed to search for provides"),
 
93
                     PkStrings::daemonError(transaction->error()));
 
94
        }
 
95
        sendErrorFinished(Failed, "Failed to search for provides");
 
96
    }
 
97
}
 
98
 
 
99
void PkInstallMimeTypes::notFound()
 
100
{
 
101
    QString msg = i18n("Could not find software");
 
102
    if (showWarning()) {
 
103
        setInfo(msg, i18n("No new applications can be found "
 
104
                          "to handle this type of file"));
 
105
    }
 
106
    sendErrorFinished(NoPackagesFound, "nothing was found to handle mime type");
 
107
}
 
108
 
 
109
//setTitle(i18np("Application that can open this type of file",
 
110
//               "Applications that can open this type of file",
 
111
//               m_foundPackages.size()));
 
112
 
 
113
#include "PkInstallMimeTypes.moc"