OSDN Git Service

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