1 | /******************************************************************* |
2 | * debugpackageinstaller.cpp |
3 | * Copyright 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as |
7 | * published by the Free Software Foundation; either version 2 of |
8 | * the License, or (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. If not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | ******************************************************************/ |
19 | |
20 | #include <config-drkonqi.h> |
21 | |
22 | #include "debugpackageinstaller.h" |
23 | |
24 | #include <KStandardDirs> |
25 | #include <KDebug> |
26 | #include <KProcess> |
27 | #include <KLocalizedString> |
28 | #include <KProgressDialog> |
29 | |
30 | #include "drkonqi.h" |
31 | #include "crashedapplication.h" |
32 | |
33 | DebugPackageInstaller::DebugPackageInstaller(QObject *parent) |
34 | : QObject(parent), m_installerProcess(0), m_progressDialog(0) |
35 | { |
36 | m_executablePath = KStandardDirs::findExe(DEBUG_PACKAGE_INSTALLER_NAME); //defined from CMakeLists.txt |
37 | } |
38 | |
39 | bool DebugPackageInstaller::canInstallDebugPackages() const |
40 | { |
41 | return !m_executablePath.isEmpty(); |
42 | } |
43 | |
44 | void DebugPackageInstaller::setMissingLibraries(const QStringList & libraries) |
45 | { |
46 | m_missingLibraries = libraries; |
47 | } |
48 | |
49 | void DebugPackageInstaller::installDebugPackages() |
50 | { |
51 | Q_ASSERT(canInstallDebugPackages()); |
52 | |
53 | if (!m_installerProcess) { |
54 | //Run process |
55 | m_installerProcess = new KProcess(this); |
56 | connect(m_installerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), |
57 | this, SLOT(processFinished(int,QProcess::ExitStatus))); |
58 | |
59 | *m_installerProcess << m_executablePath |
60 | << DrKonqi::crashedApplication()->executable().absoluteFilePath() |
61 | << m_missingLibraries; |
62 | m_installerProcess->start(); |
63 | |
64 | //Show dialog |
65 | m_progressDialog = new KProgressDialog(qobject_cast<QWidget*>(parent())); |
66 | connect(m_progressDialog, SIGNAL(cancelClicked()), this, SLOT(progressDialogCanceled())); |
67 | m_progressDialog->progressBar()->setRange(0,0); |
68 | m_progressDialog->setWindowTitle(i18nc("@title:window" , "Missing debug symbols" )); |
69 | m_progressDialog->setLabelText(i18nc("@info:progress" , "Requesting installation of missing " |
70 | "debug symbols packages..." )); |
71 | m_progressDialog->show(); |
72 | } |
73 | } |
74 | |
75 | void DebugPackageInstaller::progressDialogCanceled() |
76 | { |
77 | m_progressDialog->deleteLater(); |
78 | m_progressDialog = 0; |
79 | |
80 | if (m_installerProcess) { |
81 | if (m_installerProcess->state() == QProcess::Running) { |
82 | disconnect(m_installerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), |
83 | this, SLOT(processFinished(int,QProcess::ExitStatus))); |
84 | m_installerProcess->kill(); |
85 | disconnect(m_installerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), |
86 | m_installerProcess, SLOT(deleteLater())); |
87 | } |
88 | m_installerProcess = 0; |
89 | } |
90 | |
91 | emit canceled(); |
92 | } |
93 | |
94 | void DebugPackageInstaller::processFinished(int exitCode, QProcess::ExitStatus) |
95 | { |
96 | switch(exitCode) { |
97 | case ResultInstalled: |
98 | { |
99 | emit packagesInstalled(); |
100 | break; |
101 | } |
102 | case ResultSymbolsNotFound: |
103 | { |
104 | emit error(i18nc("@info" , "Could not find debug symbol packages for this application." )); |
105 | break; |
106 | } |
107 | case ResultCanceled: |
108 | { |
109 | emit canceled(); |
110 | break; |
111 | } |
112 | case ResultError: |
113 | default: |
114 | { |
115 | emit error(i18nc("@info" , "An error was encountered during the installation " |
116 | "of the debug symbol packages." )); |
117 | break; |
118 | } |
119 | } |
120 | |
121 | m_progressDialog->reject(); |
122 | |
123 | delete m_progressDialog; |
124 | m_progressDialog = 0; |
125 | |
126 | delete m_installerProcess; |
127 | m_installerProcess = 0; |
128 | } |
129 | |