~ubuntu-branches/ubuntu/saucy/kde-runtime/saucy-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*******************************************************************
* debugpackageinstaller.cpp
* Copyright  2009    Dario Andres Rodriguez <andresbajotierra@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************/

#include <config-drkonqi.h>

#include "debugpackageinstaller.h"

#include <KStandardDirs>
#include <KDebug>
#include <KProcess>
#include <KLocalizedString>
#include <KProgressDialog>

#include "drkonqi.h"
#include "crashedapplication.h"

DebugPackageInstaller::DebugPackageInstaller(QObject *parent)
    : QObject(parent), m_installerProcess(0), m_progressDialog(0)
{
    m_executablePath = KStandardDirs::findExe(DEBUG_PACKAGE_INSTALLER_NAME); //defined from CMakeLists.txt
}

bool DebugPackageInstaller::canInstallDebugPackages() const
{
    return !m_executablePath.isEmpty();
}

void DebugPackageInstaller::setMissingLibraries(const QStringList & libraries)
{
    m_missingLibraries = libraries;
}

void DebugPackageInstaller::installDebugPackages()
{
    Q_ASSERT(canInstallDebugPackages());

    if (!m_installerProcess) {
        //Run process
        m_installerProcess = new KProcess(this);
        connect(m_installerProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
                                            this, SLOT(processFinished(int,QProcess::ExitStatus)));

        *m_installerProcess << m_executablePath
                            << DrKonqi::crashedApplication()->executable().absoluteFilePath()
                            << m_missingLibraries;
        m_installerProcess->start();

        //Show dialog
        m_progressDialog = new KProgressDialog(qobject_cast<QWidget*>(parent()));
        connect(m_progressDialog, SIGNAL(cancelClicked()), this, SLOT(progressDialogCanceled()));
        m_progressDialog->progressBar()->setRange(0,0);
        m_progressDialog->setWindowTitle(i18nc("@title:window", "Missing debug symbols"));
        m_progressDialog->setLabelText(i18nc("@info:progress", "Requesting installation of missing "
                                                                    "debug symbols packages..."));
        m_progressDialog->show();
    }
}

void DebugPackageInstaller::progressDialogCanceled()
{
    m_progressDialog->deleteLater();
    m_progressDialog = 0;

    if (m_installerProcess) {
        if (m_installerProcess->state() == QProcess::Running) {
            disconnect(m_installerProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
                                            this, SLOT(processFinished(int,QProcess::ExitStatus)));
            m_installerProcess->kill();
            disconnect(m_installerProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
                                            m_installerProcess, SLOT(deleteLater()));
        }
        m_installerProcess = 0;
    }

    emit canceled();
}

void DebugPackageInstaller::processFinished(int exitCode, QProcess::ExitStatus)
{
    switch(exitCode) {
    case ResultInstalled:
    {
        emit packagesInstalled();
        break;
    }
    case ResultSymbolsNotFound:
    {
        emit error(i18nc("@info", "Could not find debug symbol packages for this application."));
        break;
    }
    case ResultCanceled:
    {
        emit canceled();
        break;
    }
    case ResultError:
    default:
    {
        emit error(i18nc("@info", "An error was encountered during the installation "
                                  "of the debug symbol packages."));
        break;
    }
    }

    m_progressDialog->reject();

    delete m_progressDialog;
    m_progressDialog = 0;

    delete m_installerProcess;
    m_installerProcess = 0;
}