File: launchconfiguration.cpp

package info (click to toggle)
kdevelop 4%3A22.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 70,096 kB
  • sloc: cpp: 284,635; javascript: 3,558; python: 3,422; sh: 1,319; ansic: 685; xml: 331; php: 95; lisp: 66; makefile: 39; sed: 12
file content (201 lines) | stat: -rw-r--r-- 4,994 bytes parent folder | download
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
    SPDX-FileCopyrightText: 2009 Andreas Pakulat <apaku@gmx.de>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "launchconfiguration.h"


#include <interfaces/iproject.h>
#include <interfaces/launchconfigurationtype.h>

#include "core.h"
#include "runcontroller.h"
#include <interfaces/ilauncher.h>

namespace KDevelop
{

class LaunchConfigurationPrivate
{
public:
    LaunchConfigurationPrivate(const KConfigGroup& grp, IProject* project)
        : baseGroup(grp)
        , project(project)
    {}

    KConfigGroup baseGroup;
    IProject* const project;
    LaunchConfigurationType* type;
};

QString LaunchConfiguration::LaunchConfigurationNameEntry()
{
    return QStringLiteral("Name");
}

QString LaunchConfiguration::LaunchConfigurationTypeEntry()
{
    return QStringLiteral("Type");
}

LaunchConfiguration::LaunchConfiguration(const KConfigGroup& grp, IProject* project, QObject* parent )
    : QObject(parent)
    , ILaunchConfiguration()
    , d_ptr(new LaunchConfigurationPrivate(grp, project))
{
    Q_D(LaunchConfiguration);

    d->type = Core::self()->runControllerInternal()->launchConfigurationTypeForId(grp.readEntry(LaunchConfigurationTypeEntry(), QString()));
}

LaunchConfiguration::~LaunchConfiguration()
{
}

KConfigGroup LaunchConfiguration::config()
{
    Q_D(LaunchConfiguration);

    return d->baseGroup.group("Data");
}

const KConfigGroup LaunchConfiguration::config() const
{
    Q_D(const LaunchConfiguration);

    return d->baseGroup.group("Data");
}

QString LaunchConfiguration::name() const
{
    Q_D(const LaunchConfiguration);

    return d->baseGroup.readEntry(LaunchConfigurationNameEntry(), QString());
}

IProject* LaunchConfiguration::project() const
{
    Q_D(const LaunchConfiguration);

    return d->project;
}

LaunchConfigurationType* LaunchConfiguration::type() const
{
    Q_D(const LaunchConfiguration);

    return d->type;
}

void LaunchConfiguration::setName(const QString& name)
{
    Q_D(LaunchConfiguration);

    d->baseGroup.writeEntry(LaunchConfigurationNameEntry(), name);
    d->baseGroup.sync();
    emit nameChanged( this );
}

void LaunchConfiguration::setType(const QString& typeId)
{
    Q_D(LaunchConfiguration);

    LaunchConfigurationType* t = Core::self()->runControllerInternal()->launchConfigurationTypeForId( typeId );
    // If this ever happens something seriously screwed in the launch config dialog, as that is 
    // the only place from where this method should be called
    Q_ASSERT(t);
    if( t )
    {
        d->baseGroup.deleteGroup("Data");
        d->type = t;
        d->baseGroup.writeEntry(LaunchConfigurationTypeEntry(), d->type->id());
        d->baseGroup.sync();
        emit typeChanged( t );
    }
}

void LaunchConfiguration::save()
{
    Q_D(LaunchConfiguration);

    d->baseGroup.sync();
}

QString LaunchConfiguration::configGroupName() const
{
    Q_D(const LaunchConfiguration);

    return d->baseGroup.name();
}

QString LaunchConfiguration::launcherForMode(const QString& mode) const
{
    Q_D(const LaunchConfiguration);

    QStringList modes = d->baseGroup.readEntry("Configured Launch Modes", QStringList());
    int idx = modes.indexOf( mode );
    if( idx != -1 )
    {
        const QStringList launcherIds = d->baseGroup.readEntry("Configured Launchers", QStringList());
        if (launcherIds.count() > idx ) {
            const auto& id = launcherIds.at(idx);
            const auto typeLaunchers = type()->launchers();
            for (ILauncher* l : typeLaunchers) {
                if (l->id() == id) {
                    return id;
                }
            }
        }
    }

    // No launcher configured, if it's debug mode, prefer GDB if available.
    if( mode == QLatin1String("debug") )
    {
        const auto launchers = type()->launchers();
        for (ILauncher* l : launchers) {
            if( l->supportedModes().contains( mode ) && l->id() == QLatin1String("gdb") )
            {
                return l->id();
            }
        }
    }
    // Otherwise, lets just try with the first one in the list and hope it works
    const auto launchers = type()->launchers();
    for (ILauncher* l : launchers) {
        if( l->supportedModes().contains( mode ) )
        {
            return l->id();
        }
    }

    return QString();
}

void LaunchConfiguration::setLauncherForMode(const QString& mode, const QString& id)
{
    Q_D(LaunchConfiguration);

    QStringList modes = d->baseGroup.readEntry("Configured Launch Modes", QStringList());
    int idx = modes.indexOf( mode );
    if( idx == -1 )
    {
        idx = modes.count();
        modes << mode;
        d->baseGroup.writeEntry("Configured Launch Modes", modes);
    }
    QStringList launchers = d->baseGroup.readEntry("Configured Launchers", QStringList());
    if( launchers.count() > idx )
    {
        launchers.replace(idx, id);
    } else
    {
        launchers.append( id );
    }
    d->baseGroup.writeEntry("Configured Launchers", launchers);
}


}