1/*
2 Copyright (C) 2009 George Kiagiadakis <gkiagia@users.sourceforge.net>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "debuggerlaunchers.h"
18
19#include <QtDBus/QDBusConnection>
20
21#include <KShell>
22#include <KProcess>
23#include <KDebug>
24
25#include "detachedprocessmonitor.h"
26#include "drkonqi.h"
27#include "crashedapplication.h"
28
29DefaultDebuggerLauncher::DefaultDebuggerLauncher(const Debugger & debugger, DebuggerManager *parent)
30 : AbstractDebuggerLauncher(parent), m_debugger(debugger)
31{
32 m_monitor = new DetachedProcessMonitor(this);
33 connect(m_monitor, SIGNAL(processFinished()), SLOT(onProcessFinished()));
34}
35
36QString DefaultDebuggerLauncher::name() const
37{
38 return m_debugger.name();
39}
40
41void DefaultDebuggerLauncher::start()
42{
43 if ( qobject_cast<DebuggerManager*>(parent())->debuggerIsRunning() ) {
44 kWarning() << "Another debugger is already running";
45 return;
46 }
47
48 QString str = m_debugger.command();
49 Debugger::expandString(str, Debugger::ExpansionUsageShell);
50
51 emit starting();
52 int pid = KProcess::startDetached(KShell::splitArgs(str));
53 if ( pid > 0 ) {
54 m_monitor->startMonitoring(pid);
55 } else {
56 kError() << "Could not start debugger:" << name();
57 emit finished();
58 }
59}
60
61void DefaultDebuggerLauncher::onProcessFinished()
62{
63 emit finished();
64}
65
66#if 0
67TerminalDebuggerLauncher::TerminalDebuggerLauncher(const Debugger & debugger, DebuggerManager *parent)
68 : DefaultDebuggerLauncher(debugger, parent)
69{
70}
71
72void TerminalDebuggerLauncher::start()
73{
74 DefaultDebuggerLauncher::start(); //FIXME
75}
76#endif
77
78
79DBusOldInterfaceLauncher::DBusOldInterfaceLauncher(DebuggerManager *parent)
80 : AbstractDebuggerLauncher(parent)
81{
82 m_adaptor = new DBusOldInterfaceAdaptor(this);
83 QDBusConnection::sessionBus().registerObject("/krashinfo", this);
84}
85
86QString DBusOldInterfaceLauncher::name() const
87{
88 return m_name;
89}
90
91void DBusOldInterfaceLauncher::start()
92{
93 emit starting();
94 emit m_adaptor->acceptDebuggingApplication();
95}
96
97
98DBusOldInterfaceAdaptor::DBusOldInterfaceAdaptor(DBusOldInterfaceLauncher *parent)
99 : QDBusAbstractAdaptor(parent)
100{
101 Q_ASSERT(parent);
102}
103
104int DBusOldInterfaceAdaptor::pid()
105{
106 return DrKonqi::crashedApplication()->pid();
107}
108
109void DBusOldInterfaceAdaptor::registerDebuggingApplication(const QString & name)
110{
111 if ( static_cast<DBusOldInterfaceLauncher*>(parent())->m_name.isEmpty() && !name.isEmpty() ) {
112 static_cast<DBusOldInterfaceLauncher*>(parent())->m_name = name;
113 emit static_cast<DBusOldInterfaceLauncher*>(parent())->available();
114 }
115}
116
117#include "debuggerlaunchers.moc"
118