OSDN Git Service

It's 2011 now.
[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     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 }
94
95 QString ProjectExplorerSettingsWidget::projectsDirectory() const
96 {
97     return m_ui.projectsDirectoryPathChooser->path();
98 }
99
100 void ProjectExplorerSettingsWidget::setProjectsDirectory(const QString &pd)
101 {
102     m_ui.projectsDirectoryPathChooser->setPath(pd);
103 }
104
105 bool ProjectExplorerSettingsWidget::useProjectsDirectory()
106 {
107     return m_ui.directoryButtonGroup->checkedId() == UseProjectDirectory;
108 }
109
110 void ProjectExplorerSettingsWidget::setUseProjectsDirectory(bool b)
111 {
112     if (useProjectsDirectory() != b) {
113         (b ? m_ui.directoryRadioButton : m_ui.currentDirectoryRadioButton)->setChecked(true);
114         slotDirectoryButtonGroupChanged();
115     }
116 }
117
118 void ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged()
119 {
120     m_ui.projectsDirectoryPathChooser->setEnabled(useProjectsDirectory());
121 }
122
123 QString ProjectExplorerSettingsWidget::searchKeywords() const
124 {
125     if (m_searchKeywords.isEmpty()) {
126         QLatin1Char sep(' ');
127         m_searchKeywords = m_ui.directoryGroupBox->title()
128                 + sep + m_ui.currentDirectoryRadioButton->text()
129                 + sep + m_ui.directoryRadioButton->text()
130                 + sep + m_ui.buildAndRunGroupBox->title()
131                 + sep + m_ui.saveAllFilesCheckBox->text()
132                 + sep + m_ui.buildProjectBeforeDeployCheckBox->text()
133                 + sep + m_ui.deployProjectBeforeRunCheckBox->text()
134                 + sep + m_ui.showCompileOutputCheckBox->text()
135                 + sep + m_ui.cleanOldAppOutputCheckBox->text()
136                 + sep + m_ui.wrapAppOutputCheckBox->text()
137                 + sep + m_ui.jomLabel->text()
138                 ;
139         m_searchKeywords.remove(QLatin1Char('&'));
140     }
141     return m_searchKeywords;
142 }
143
144 // ------------------ ProjectExplorerSettingsPage
145 ProjectExplorerSettingsPage::ProjectExplorerSettingsPage()
146 {
147 }
148
149 QString ProjectExplorerSettingsPage::id() const
150 {
151     return QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_ID);
152 }
153
154 QString ProjectExplorerSettingsPage::displayName() const
155 {
156     return tr("General");
157 }
158
159 QString ProjectExplorerSettingsPage::category() const
160 {
161     return QLatin1String(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
162 }
163
164 QString ProjectExplorerSettingsPage::displayCategory() const
165 {
166     return QCoreApplication::translate("ProjectExplorer",
167                                        Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY);
168 }
169
170 QIcon ProjectExplorerSettingsPage::categoryIcon() const
171 {
172     return QIcon(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON);
173 }
174
175 QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent)
176 {
177     m_widget = new ProjectExplorerSettingsWidget(parent);
178     m_widget->setSettings(ProjectExplorerPlugin::instance()->projectExplorerSettings());
179     const Core::FileManager *fm = Core::ICore::instance()->fileManager();
180     m_widget->setProjectsDirectory(fm->projectsDirectory());
181     m_widget->setUseProjectsDirectory(fm->useProjectsDirectory());
182     if (m_searchKeywords.isEmpty())
183         m_searchKeywords = m_widget->searchKeywords();
184     return m_widget;
185 }
186
187 void ProjectExplorerSettingsPage::apply()
188 {
189     if (m_widget) {
190         ProjectExplorerPlugin::instance()->setProjectExplorerSettings(m_widget->settings());
191         Core::FileManager *fm = Core::ICore::instance()->fileManager();
192         fm->setProjectsDirectory(m_widget->projectsDirectory());
193         fm->setUseProjectsDirectory(m_widget->useProjectsDirectory());
194     }
195 }
196
197 void ProjectExplorerSettingsPage::finish()
198 {
199     // Nothing to do
200 }
201
202 bool ProjectExplorerSettingsPage::matches(const QString &s) const
203 {
204     return m_searchKeywords.contains(s, Qt::CaseInsensitive);
205 }
206
207 } // namespace Internal
208 } // namespace ProjectExplorer
209