This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
kdevkernelconfigwidget.cpp
135 lines (113 loc) · 4.76 KB
/
kdevkernelconfigwidget.cpp
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
/*
* Copyright (C) 2012 Alexandre Courbot <[email protected]>
*
* 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 3 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 "kdevkernelconfigwidget.h"
#include "kdevkernelconfig.h"
#include <QtDebug>
#include <QDir>
#include <KJob>
#include <interfaces/icore.h>
#include <interfaces/iproject.h>
#include <interfaces/iprojectcontroller.h>
#include <interfaces/iruncontroller.h>
#include <language/backgroundparser/parseprojectjob.h>
KDevKernelConfigWidget::KDevKernelConfigWidget(QWidget *parent, const QString &projectRoot) : QWidget(parent), _projectRoot(projectRoot)
{
Ui::KDevKernelConfigWidget::setupUi(this);
connect(buildDir, SIGNAL(textChanged(const QString &)), this, SIGNAL(changed()));
connect(arch, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
connect(defconfig, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
connect(arch, SIGNAL(currentIndexChanged(QString)), this, SLOT(archChanged(QString)));
connect(crossCompiler, SIGNAL(textChanged(const QString &)), this, SIGNAL(changed()));
}
void KDevKernelConfigWidget::loadDefaults()
{
}
void KDevKernelConfigWidget::loadFrom(KConfig *config)
{
KConfigGroup group(config->group(KERN_KGROUP));
// Fill in the arch values
KUrl pRoot(_projectRoot);
pRoot.adjustPath(KUrl::AddTrailingSlash);
QDir archDir(KUrl(pRoot, "arch").toLocalFile());
archDir.setFilter(QDir::Dirs);
foreach (const QString &archEntry, archDir.entryList()) {
if (archEntry.startsWith('.')) continue;
arch->addItem(archEntry);
}
if (group.hasKey(KERN_BDIR)) {
buildDir->setUrl(group.readEntry(KERN_BDIR, KUrl()));
} else {
buildDir->setStartDir(pRoot);
}
if (group.hasKey(KERN_ARCH)) {
arch->setCurrentItem(group.readEntry(KERN_ARCH, ""));
}
if (group.hasKey(KERN_DEFCONFIG)) {
defconfig->setCurrentItem(group.readEntry(KERN_DEFCONFIG, ""));
}
if (group.hasKey(KERN_CROSS)) {
crossCompiler->setUrl(KUrl(group.readEntry(KERN_CROSS, "") + "gcc"));
} else {
crossCompiler->setStartDir(KUrl("/usr/bin/"));
}
}
void KDevKernelConfigWidget::saveTo(KConfig *config, KDevelop::IProject *project)
{
KConfigGroup group(config->group(KERN_KGROUP));
if (!buildDir->url().isEmpty())
group.writeEntry(KERN_BDIR, buildDir->url());
else group.deleteEntry(KERN_BDIR);
group.writeEntry(KERN_ARCH, arch->currentText());
if (!crossCompiler->url().isEmpty()) {
QString cc(crossCompiler->url().toLocalFile());
cc.remove("file://");
if (cc.endsWith("gcc")) {
QString crossPrefix(cc.mid(0, cc.size() - 3));
group.writeEntry(KERN_CROSS, crossPrefix);
} else {
// TODO notify error
}
} else group.deleteEntry(KERN_CROSS);
// Remove the .config file if configuration changed. This will trigger
// the corresponding make rule from the plugin the next time we parse.
if (defconfig->currentText() != group.readEntry(KERN_DEFCONFIG, "")) {
KUrl buildDir(group.readEntry(KERN_BDIR, _projectRoot));
buildDir.adjustPath(KUrl::AddTrailingSlash);
QFile dotConfig(KUrl(buildDir, ".config").toLocalFile());
if (dotConfig.exists()) dotConfig.remove();
}
group.writeEntry(KERN_DEFCONFIG, defconfig->currentText());
config->sync();
// For initial setup we get called with a null project. In this case KDev will
// do the parsing automatically anyway.
/*if (KDevelop::IProjectController::parseAllProjectSources() && project) {
KJob *parseProjectJob = new KDevelop::ParseProjectJob(project);
KDevelop::ICore::self()->runController()->registerJob(parseProjectJob);
}*/
}
void KDevKernelConfigWidget::archChanged (const QString &arch)
{
defconfig->clear();
// Fill in the configs values
KUrl pRoot(_projectRoot);
pRoot.adjustPath(KUrl::AddTrailingSlash);
QDir configDirs(KUrl(pRoot, QString("arch/%1/configs").arg(arch)).toLocalFile());
foreach (const QString &configFile, configDirs.entryList()) {
if (configFile.startsWith('.')) continue;
defconfig->addItem(configFile.left(configFile.size() - QString("_defconfig").size()));
}
}