File: qmakebuilddirchooser.cpp

package info (click to toggle)
kdevelop 4%3A5.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 52,544 kB
  • sloc: cpp: 254,897; python: 3,380; sh: 1,271; ansic: 657; xml: 221; php: 95; makefile: 36; lisp: 13; sed: 12
file content (223 lines) | stat: -rw-r--r-- 7,612 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/***************************************************************************
 *   This file is part of KDevelop                                         *
 *   Copyright (C) 2011 Martin Heide <martin.heide@gmx.net>                *
 *   Copyright (C) 2011 Julien Desgats <julien.desgats@gmail.com>          *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library 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 Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include "qmakebuilddirchooser.h"
#include "qmakeconfig.h"

#include <KLocalizedString>
#include <KMessageWidget>

#include <QSignalBlocker>
#include <QUrl>

#include <util/path.h>

#include <project/helper.h>
#include <project/interfaces/iprojectbuilder.h>

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

using namespace KDevelop;

QMakeBuildDirChooser::QMakeBuildDirChooser(KDevelop::IProject* project, QWidget* parent)
    : QWidget(parent)
    , Ui::QMakeBuildDirChooser()
    , m_project(project)
{
    setupUi(this);

    status->hide();
    status->setCloseButtonVisible(false);
    status->setMessageType(KMessageWidget::Error);
    status->setWordWrap(true);

    kcfg_buildDir->setMode(KFile::Directory | KFile::LocalOnly);
    kcfg_installPrefix->setMode(KFile::Directory | KFile::LocalOnly);
    kcfg_qmakeExecutable->setMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly);

    connect(kcfg_qmakeExecutable, &KUrlRequester::textChanged, this, &QMakeBuildDirChooser::changed);
    connect(kcfg_buildDir, &KUrlRequester::textChanged, this, &QMakeBuildDirChooser::changed);
    connect(kcfg_installPrefix, &KUrlRequester::textChanged, this, &QMakeBuildDirChooser::changed);
    connect(kcfg_buildType, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
            &QMakeBuildDirChooser::changed);
    connect(kcfg_extraArgs, &KLineEdit::textChanged, this, &QMakeBuildDirChooser::changed);
}

QMakeBuildDirChooser::~QMakeBuildDirChooser()
{
    // don't save in destructor; instead, on click of OK-button
    // saveConfig();
}

QString QMakeBuildDirChooser::errorString() const
{
    return status->text();
}

void QMakeBuildDirChooser::setErrorString(const QString& errorString)
{
    if (errorString.isEmpty()) {
        status->animatedHide();
    } else {
        status->setText(errorString);
        status->animatedShow();
    }
}

IProject* QMakeBuildDirChooser::project() const
{
    return m_project;
}

void QMakeBuildDirChooser::saveConfig()
{
    KConfigGroup config = KConfigGroup(m_project->projectConfiguration(), QMakeConfig::CONFIG_GROUP).group(buildDir());
    saveConfig(config);
}

void QMakeBuildDirChooser::saveConfig(KConfigGroup& config)
{
    qCDebug(KDEV_QMAKE) << "Writing config for" << buildDir() << "to config" << config.name();

    config.writeEntry(QMakeConfig::QMAKE_EXECUTABLE, qmakeExecutable());
    config.writeEntry(QMakeConfig::INSTALL_PREFIX, installPrefix());
    config.writeEntry(QMakeConfig::EXTRA_ARGUMENTS, extraArgs());
    config.writeEntry(QMakeConfig::BUILD_TYPE, buildType());
    config.sync();
}

void QMakeBuildDirChooser::loadConfig()
{
    KConfigGroup cg(m_project->projectConfiguration(), QMakeConfig::CONFIG_GROUP);
    loadConfig(cg.readEntry(QMakeConfig::BUILD_FOLDER, KDevelop::proposedBuildFolder(m_project->path()).toLocalFile()));
}

void QMakeBuildDirChooser::loadConfig(const QString& config)
{
    // get correct group
    KConfigGroup cg(m_project->projectConfiguration(), QMakeConfig::CONFIG_GROUP);
    const KConfigGroup build = cg.group(config);

    {
        QSignalBlocker blocker(this); // only emit changed once

        // sets values into fields
        setQMakeExecutable(QMakeConfig::qmakeExecutable(m_project));
        setBuildDir(config);
        setInstallPrefix(build.readEntry(QMakeConfig::INSTALL_PREFIX, QString()));
        setExtraArgs(build.readEntry(QMakeConfig::EXTRA_ARGUMENTS, QString()));
        setBuildType(build.readEntry(QMakeConfig::BUILD_TYPE, 0));
    }
    emit changed();
}

bool QMakeBuildDirChooser::validate(QString* message)
{
    bool valid = true;
    QString msg;
    if (qmakeExecutable().isEmpty()) {
        msg = i18n("Please specify path to QMake executable.");
        valid = false;
    } else {
        QFileInfo info(qmakeExecutable());
        if (!info.exists()) {
            msg = i18n("QMake executable \"%1\" does not exist.", qmakeExecutable());
            valid = false;
        } else if (!info.isFile()) {
            msg = i18n("QMake executable is not a file.");
            valid = false;
        } else if (!info.isExecutable()) {
            msg = i18n("QMake executable is not executable.");
            valid = false;
        } else {
            const QHash<QString, QString> vars = QMakeConfig::queryQMake(info.absoluteFilePath());
            if (vars.isEmpty()) {
                msg = i18n("QMake executable cannot be queried for variables.");
                valid = false;
            } else if (QMakeConfig::findBasicMkSpec(vars).isEmpty()) {
                msg = i18n("No basic MkSpec file could be found for the given QMake executable.");
                valid = false;
            }
        }
    }

    if (buildDir().isEmpty()) {
        msg = i18n("Please specify a build folder.");
        valid = false;
    }
    if (message) {
        *message = msg;
    }
    setErrorString(msg);
    qCDebug(KDEV_QMAKE) << "VALID == " << valid;
    return valid;
}

QString QMakeBuildDirChooser::qmakeExecutable() const
{
    return kcfg_qmakeExecutable->url().toLocalFile();
}

QString QMakeBuildDirChooser::buildDir() const
{
    return kcfg_buildDir->url().toLocalFile();
}

QString QMakeBuildDirChooser::installPrefix() const
{
    return kcfg_installPrefix->url().toLocalFile();
}

int QMakeBuildDirChooser::buildType() const
{
    return kcfg_buildType->currentIndex();
}

QString QMakeBuildDirChooser::extraArgs() const
{
    return kcfg_extraArgs->text();
}

void QMakeBuildDirChooser::setQMakeExecutable(const QString& executable)
{
    kcfg_qmakeExecutable->setUrl(QUrl::fromLocalFile(executable));
}

void QMakeBuildDirChooser::setBuildDir(const QString& buildDir)
{
    kcfg_buildDir->setUrl(QUrl::fromLocalFile(buildDir));
}

void QMakeBuildDirChooser::setInstallPrefix(const QString& prefix)
{
    kcfg_installPrefix->setUrl(QUrl::fromLocalFile(prefix));
}

void QMakeBuildDirChooser::setBuildType(int type)
{
    kcfg_buildType->setCurrentIndex(type);
}

void QMakeBuildDirChooser::setExtraArgs(const QString& args)
{
    kcfg_extraArgs->setText(args);
}