projectexplorersettingspage.cpp 7.17 KB
Newer Older
dt's avatar
dt committed
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
dt's avatar
dt committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
dt's avatar
dt committed
8
**
con's avatar
con committed
9
** No Commercial Usage
dt's avatar
dt committed
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
dt's avatar
dt committed
15 16 17 18 19 20 21 22 23 24
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
dt's avatar
dt committed
31 32 33 34
**
**************************************************************************/

#include "projectexplorersettingspage.h"
35
#include "projectexplorersettings.h"
dt's avatar
dt committed
36 37 38
#include "projectexplorerconstants.h"
#include "projectexplorer.h"

39 40 41
#include <coreplugin/icore.h>
#include <coreplugin/filemanager.h>

dt's avatar
dt committed
42
#include <QtGui/QLabel>
43
#include <QtCore/QCoreApplication>
dt's avatar
dt committed
44

45 46
namespace ProjectExplorer {
namespace Internal {
dt's avatar
dt committed
47

48 49
    enum { UseCurrentDirectory, UseProjectDirectory };

50 51 52 53 54 55 56
ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) :
    QWidget(parent)
{
    m_ui.setupUi(this);
#ifndef Q_OS_WIN
    setJomVisible(false);
#endif
57 58 59 60
    m_ui.directoryButtonGroup->setId(m_ui.currentDirectoryRadioButton, UseCurrentDirectory);
    m_ui.directoryButtonGroup->setId(m_ui.directoryRadioButton, UseProjectDirectory);
    connect(m_ui.directoryButtonGroup, SIGNAL(buttonClicked(int)),
            this, SLOT(slotDirectoryButtonGroupChanged()));
61 62 63 64 65 66 67 68 69 70 71
}

void ProjectExplorerSettingsWidget::setJomVisible(bool v)
{
    m_ui.jomCheckbox->setVisible(v);
    m_ui.jomLabel->setVisible(v);
}

ProjectExplorerSettings ProjectExplorerSettingsWidget::settings() const
{
    ProjectExplorerSettings pes;
Tobias Hunger's avatar
Tobias Hunger committed
72 73
    pes.buildBeforeDeploy = m_ui.buildProjectBeforeDeployCheckBox->isChecked();
    pes.deployBeforeRun = m_ui.deployProjectBeforeRunCheckBox->isChecked();
74 75
    pes.saveBeforeBuild = m_ui.saveAllFilesCheckBox->isChecked();
    pes.showCompilerOutput = m_ui.showCompileOutputCheckBox->isChecked();
76
    pes.showRunOutput = m_ui.showRunOutputCheckBox->isChecked();
77
    pes.cleanOldAppOutput = m_ui.cleanOldAppOutputCheckBox->isChecked();
78
    pes.wrapAppOutput = m_ui.wrapAppOutputCheckBox->isChecked();
79 80 81 82 83 84
    pes.useJom = m_ui.jomCheckbox->isChecked();
    return pes;
}

void ProjectExplorerSettingsWidget::setSettings(const ProjectExplorerSettings  &pes) const
{
Tobias Hunger's avatar
Tobias Hunger committed
85 86
    m_ui.buildProjectBeforeDeployCheckBox->setChecked(pes.buildBeforeDeploy);
    m_ui.deployProjectBeforeRunCheckBox->setChecked(pes.deployBeforeRun);
87 88
    m_ui.saveAllFilesCheckBox->setChecked(pes.saveBeforeBuild);
    m_ui.showCompileOutputCheckBox->setChecked(pes.showCompilerOutput);
89
    m_ui.showRunOutputCheckBox->setChecked(pes.showRunOutput);
90
    m_ui.cleanOldAppOutputCheckBox->setChecked(pes.cleanOldAppOutput);
91
    m_ui.wrapAppOutputCheckBox->setChecked(pes.wrapAppOutput);
92 93 94
    m_ui.jomCheckbox->setChecked(pes.useJom);
}

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
QString ProjectExplorerSettingsWidget::projectsDirectory() const
{
    return m_ui.projectsDirectoryPathChooser->path();
}

void ProjectExplorerSettingsWidget::setProjectsDirectory(const QString &pd)
{
    m_ui.projectsDirectoryPathChooser->setPath(pd);
}

bool ProjectExplorerSettingsWidget::useProjectsDirectory()
{
    return m_ui.directoryButtonGroup->checkedId() == UseProjectDirectory;
}

void ProjectExplorerSettingsWidget::setUseProjectsDirectory(bool b)
{
    if (useProjectsDirectory() != b) {
        (b ? m_ui.directoryRadioButton : m_ui.currentDirectoryRadioButton)->setChecked(true);
        slotDirectoryButtonGroupChanged();
    }
}

void ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged()
{
    m_ui.projectsDirectoryPathChooser->setEnabled(useProjectsDirectory());
}

123 124
QString ProjectExplorerSettingsWidget::searchKeywords() const
{
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    if (m_searchKeywords.isEmpty()) {
        QLatin1Char sep(' ');
        m_searchKeywords = m_ui.directoryGroupBox->title()
                + sep + m_ui.currentDirectoryRadioButton->text()
                + sep + m_ui.directoryRadioButton->text()
                + sep + m_ui.buildAndRunGroupBox->title()
                + sep + m_ui.saveAllFilesCheckBox->text()
                + sep + m_ui.buildProjectBeforeDeployCheckBox->text()
                + sep + m_ui.deployProjectBeforeRunCheckBox->text()
                + sep + m_ui.showCompileOutputCheckBox->text()
                + sep + m_ui.cleanOldAppOutputCheckBox->text()
                + sep + m_ui.wrapAppOutputCheckBox->text()
                + sep + m_ui.jomLabel->text()
                ;
        m_searchKeywords.remove(QLatin1Char('&'));
    }
    return m_searchKeywords;
142 143
}

144
// ------------------ ProjectExplorerSettingsPage
145
ProjectExplorerSettingsPage::ProjectExplorerSettingsPage()
dt's avatar
dt committed
146 147 148 149 150
{
}

QString ProjectExplorerSettingsPage::id() const
{
151
    return QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_ID);
dt's avatar
dt committed
152 153
}

154
QString ProjectExplorerSettingsPage::displayName() const
dt's avatar
dt committed
155
{
156
    return tr("General");
dt's avatar
dt committed
157 158 159 160
}

QString ProjectExplorerSettingsPage::category() const
{
161
    return QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
dt's avatar
dt committed
162 163
}

164
QString ProjectExplorerSettingsPage::displayCategory() const
dt's avatar
dt committed
165
{
166 167
    return QCoreApplication::translate("ProjectExplorer",
                                       Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY);
dt's avatar
dt committed
168 169
}

170 171 172 173 174
QIcon ProjectExplorerSettingsPage::categoryIcon() const
{
    return QIcon(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON);
}

dt's avatar
dt committed
175 176
QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent)
{
177 178
    m_widget = new ProjectExplorerSettingsWidget(parent);
    m_widget->setSettings(ProjectExplorerPlugin::instance()->projectExplorerSettings());
179 180 181
    const Core::FileManager *fm = Core::ICore::instance()->fileManager();
    m_widget->setProjectsDirectory(fm->projectsDirectory());
    m_widget->setUseProjectsDirectory(fm->useProjectsDirectory());
182 183 184
    if (m_searchKeywords.isEmpty())
        m_searchKeywords = m_widget->searchKeywords();
    return m_widget;
dt's avatar
dt committed
185 186 187 188
}

void ProjectExplorerSettingsPage::apply()
{
189
    if (m_widget) {
190
        ProjectExplorerPlugin::instance()->setProjectExplorerSettings(m_widget->settings());
191 192 193 194
        Core::FileManager *fm = Core::ICore::instance()->fileManager();
        fm->setProjectsDirectory(m_widget->projectsDirectory());
        fm->setUseProjectsDirectory(m_widget->useProjectsDirectory());
    }
dt's avatar
dt committed
195 196 197 198 199 200
}

void ProjectExplorerSettingsPage::finish()
{
    // Nothing to do
}
201 202 203 204 205

bool ProjectExplorerSettingsPage::matches(const QString &s) const
{
    return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
206

207 208
} // namespace Internal
} // namespace ProjectExplorer
209