1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "settingspage.h"
35 #include "gitsettings.h"
36 #include "gitplugin.h"
37 #include "gitclient.h"
39 #include <vcsbase/vcsbaseconstants.h>
41 #include <QtCore/QCoreApplication>
42 #include <QtCore/QFileInfo>
43 #include <QtCore/QDebug>
44 #include <QtCore/QTextStream>
45 #include <QtCore/QProcessEnvironment>
46 #include <QtGui/QMessageBox>
51 SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
55 connect(m_ui.adoptButton, SIGNAL(clicked()), this, SLOT(setSystemPath()));
57 const QByteArray currentHome = qgetenv("HOME");
59 = tr("Set the environment variable HOME to '%1'\n(%2).\n"
60 "This causes msysgit to look for the SSH-keys in that location\n"
61 "instead of its installation directory when run outside git bash.").
62 arg(GitClient::fakeWinHome(QProcessEnvironment::systemEnvironment()),
63 currentHome.isEmpty() ? tr("not currently set") :
64 tr("currently set to '%1'").arg(QString::fromLocal8Bit(currentHome)));
65 m_ui.winHomeCheckBox->setToolTip(toolTip);
67 m_ui.winHomeCheckBox->setVisible(false);
71 GitSettings SettingsPageWidget::settings() const
74 rc.path = m_ui.pathLineEdit->text();
75 rc.adoptPath = m_ui.environmentGroupBox->isChecked() && !rc.path.isEmpty();
76 rc.logCount = m_ui.logCountSpinBox->value();
77 rc.timeoutSeconds = m_ui.timeoutSpinBox->value();
78 rc.pullRebase = m_ui.pullRebaseCheckBox->isChecked();
79 rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
80 rc.winSetHomeEnvironment = m_ui.winHomeCheckBox->isChecked();
81 rc.gitkOptions = m_ui.gitkOptionsLineEdit->text().trimmed();
85 void SettingsPageWidget::setSettings(const GitSettings &s)
87 m_ui.environmentGroupBox->setChecked(s.adoptPath);
88 m_ui.pathLineEdit->setText(s.path);
89 m_ui.logCountSpinBox->setValue(s.logCount);
90 m_ui.timeoutSpinBox->setValue(s.timeoutSeconds);
91 m_ui.pullRebaseCheckBox->setChecked(s.pullRebase);
92 m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
93 m_ui.winHomeCheckBox->setChecked(s.winSetHomeEnvironment);
94 m_ui.gitkOptionsLineEdit->setText(s.gitkOptions);
97 void SettingsPageWidget::setSystemPath()
99 m_ui.pathLineEdit->setText(QLatin1String(qgetenv("PATH")));
102 QString SettingsPageWidget::searchKeywords() const
105 QLatin1Char sep(' ');
107 << sep << m_ui.environmentGroupBox->title()
108 << sep << m_ui.pathlabel->text()
109 << sep << m_ui.winHomeCheckBox->text()
110 << sep << m_ui.groupBox->title()
111 << sep << m_ui.logCountLabel->text()
112 << sep << m_ui.timeoutLabel->text()
113 << sep << m_ui.promptToSubmitCheckBox->text()
114 << sep << m_ui.promptToSubmitCheckBox->text()
115 << sep << m_ui.gitkGroupBox->title()
116 << sep << m_ui.gitkOptionsLabel->text()
118 rc.remove(QLatin1Char('&'));
122 // -------- SettingsPage
123 SettingsPage::SettingsPage() :
128 QString SettingsPage::id() const
130 return QLatin1String(VCSBase::Constants::VCS_ID_GIT);
133 QString SettingsPage::displayName() const
138 QWidget *SettingsPage::createPage(QWidget *parent)
140 m_widget = new SettingsPageWidget(parent);
141 m_widget->setSettings(GitPlugin::instance()->settings());
142 if (m_searchKeywords.isEmpty())
143 m_searchKeywords = m_widget->searchKeywords();
147 void SettingsPage::apply()
149 const GitSettings newSettings = m_widget->settings();
150 // Warn if git cannot be found in path if the widget is on top
151 if (m_widget->isVisible()) {
153 QString errorMessage;
154 newSettings.gitBinaryPath(&gitFoundOk, &errorMessage);
156 QMessageBox::warning(m_widget, tr("Git Settings"), errorMessage);
159 GitPlugin::instance()->setSettings(newSettings);
162 bool SettingsPage::matches(const QString &s) const
164 return m_searchKeywords.contains(s, Qt::CaseInsensitive);