OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / projectexplorersettingspage.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "projectexplorersettingspage.h"
34 #include "projectexplorersettings.h"
35 #include "projectexplorerconstants.h"
36 #include "projectexplorer.h"
37
38 #include <coreplugin/icore.h>
39 #include <coreplugin/filemanager.h>
40
41 #include <QtGui/QLabel>
42 #include <QtCore/QCoreApplication>
43
44 namespace ProjectExplorer {
45 namespace Internal {
46
47     enum { UseCurrentDirectory, UseProjectDirectory };
48
49 ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) :
50     QWidget(parent)
51 {
52     m_ui.setupUi(this);
53 #ifndef Q_OS_WIN
54     setJomVisible(false);
55 #endif
56     m_ui.directoryButtonGroup->setId(m_ui.currentDirectoryRadioButton, UseCurrentDirectory);
57     m_ui.directoryButtonGroup->setId(m_ui.directoryRadioButton, UseProjectDirectory);
58     connect(m_ui.directoryButtonGroup, SIGNAL(buttonClicked(int)),
59             this, SLOT(slotDirectoryButtonGroupChanged()));
60 }
61
62 void ProjectExplorerSettingsWidget::setJomVisible(bool v)
63 {
64     m_ui.jomCheckbox->setVisible(v);
65     m_ui.jomLabel->setVisible(v);
66 }
67
68 ProjectExplorerSettings ProjectExplorerSettingsWidget::settings() const
69 {
70     ProjectExplorerSettings pes;
71     pes.buildBeforeDeploy = m_ui.buildProjectBeforeDeployCheckBox->isChecked();
72     pes.deployBeforeRun = m_ui.deployProjectBeforeRunCheckBox->isChecked();
73     pes.saveBeforeBuild = m_ui.saveAllFilesCheckBox->isChecked();
74     pes.showCompilerOutput = m_ui.showCompileOutputCheckBox->isChecked();
75     pes.showRunOutput = m_ui.showRunOutputCheckBox->isChecked();
76     pes.cleanOldAppOutput = m_ui.cleanOldAppOutputCheckBox->isChecked();
77     pes.wrapAppOutput = m_ui.wrapAppOutputCheckBox->isChecked();
78     pes.useJom = m_ui.jomCheckbox->isChecked();
79     pes.prompToStopRunControl = m_ui.promptToStopRunControlCheckBox->isChecked();
80     return pes;
81 }
82
83 void ProjectExplorerSettingsWidget::setSettings(const ProjectExplorerSettings  &pes) const
84 {
85     m_ui.buildProjectBeforeDeployCheckBox->setChecked(pes.buildBeforeDeploy);
86     m_ui.deployProjectBeforeRunCheckBox->setChecked(pes.deployBeforeRun);
87     m_ui.saveAllFilesCheckBox->setChecked(pes.saveBeforeBuild);
88     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     m_ui.jomCheckbox->setChecked(pes.useJom);
93     m_ui.promptToStopRunControlCheckBox->setChecked(pes.prompToStopRunControl);
94 }
95
96 QString ProjectExplorerSettingsWidget::projectsDirectory() const
97 {
98     return m_ui.projectsDirectoryPathChooser->path();
99 }
100
101 void ProjectExplorerSettingsWidget::setProjectsDirectory(const QString &pd)
102 {
103     m_ui.projectsDirectoryPathChooser->setPath(pd);
104 }
105
106 bool ProjectExplorerSettingsWidget::useProjectsDirectory()
107 {
108     return m_ui.directoryButtonGroup->checkedId() == UseProjectDirectory;
109 }
110
111 void ProjectExplorerSettingsWidget::setUseProjectsDirectory(bool b)
112 {
113     if (useProjectsDirectory() != b) {
114         (b ? m_ui.directoryRadioButton : m_ui.currentDirectoryRadioButton)->setChecked(true);
115         slotDirectoryButtonGroupChanged();
116     }
117 }
118
119 void ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged()
120 {
121     m_ui.projectsDirectoryPathChooser->setEnabled(useProjectsDirectory());
122 }
123
124 QString ProjectExplorerSettingsWidget::searchKeywords() const
125 {
126     if (m_searchKeywords.isEmpty()) {
127         QLatin1Char sep(' ');
128         m_searchKeywords = m_ui.directoryGroupBox->title()
129                 + sep + m_ui.currentDirectoryRadioButton->text()
130                 + sep + m_ui.directoryRadioButton->text()
131                 + sep + m_ui.buildAndRunGroupBox->title()
132                 + sep + m_ui.saveAllFilesCheckBox->text()
133                 + sep + m_ui.buildProjectBeforeDeployCheckBox->text()
134                 + sep + m_ui.deployProjectBeforeRunCheckBox->text()
135                 + sep + m_ui.showCompileOutputCheckBox->text()
136                 + sep + m_ui.cleanOldAppOutputCheckBox->text()
137                 + sep + m_ui.wrapAppOutputCheckBox->text()
138                 + sep + m_ui.jomLabel->text()
139                 ;
140         m_searchKeywords.remove(QLatin1Char('&'));
141     }
142     return m_searchKeywords;
143 }
144
145 // ------------------ ProjectExplorerSettingsPage
146 ProjectExplorerSettingsPage::ProjectExplorerSettingsPage()
147 {
148 }
149
150 QString ProjectExplorerSettingsPage::id() const
151 {
152     return QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_ID);
153 }
154
155 QString ProjectExplorerSettingsPage::displayName() const
156 {
157     return tr("General");
158 }
159
160 QString ProjectExplorerSettingsPage::category() const
161 {
162     return QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
163 }
164
165 QString ProjectExplorerSettingsPage::displayCategory() const
166 {
167     return QCoreApplication::translate("ProjectExplorer",
168                                        Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY);
169 }
170
171 QIcon ProjectExplorerSettingsPage::categoryIcon() const
172 {
173     return QIcon(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON);
174 }
175
176 QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent)
177 {
178     m_widget = new ProjectExplorerSettingsWidget(parent);
179     m_widget->setSettings(ProjectExplorerPlugin::instance()->projectExplorerSettings());
180     const Core::FileManager *fm = Core::ICore::instance()->fileManager();
181     m_widget->setProjectsDirectory(fm->projectsDirectory());
182     m_widget->setUseProjectsDirectory(fm->useProjectsDirectory());
183     if (m_searchKeywords.isEmpty())
184         m_searchKeywords = m_widget->searchKeywords();
185     return m_widget;
186 }
187
188 void ProjectExplorerSettingsPage::apply()
189 {
190     if (m_widget) {
191         ProjectExplorerPlugin::instance()->setProjectExplorerSettings(m_widget->settings());
192         Core::FileManager *fm = Core::ICore::instance()->fileManager();
193         fm->setProjectsDirectory(m_widget->projectsDirectory());
194         fm->setUseProjectsDirectory(m_widget->useProjectsDirectory());
195     }
196 }
197
198 void ProjectExplorerSettingsPage::finish()
199 {
200     // Nothing to do
201 }
202
203 bool ProjectExplorerSettingsPage::matches(const QString &s) const
204 {
205     return m_searchKeywords.contains(s, Qt::CaseInsensitive);
206 }
207
208 } // namespace Internal
209 } // namespace ProjectExplorer
210