1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "settingspage.h"
34 #include "perforcesettings.h"
35 #include "perforceplugin.h"
36 #include "perforcechecker.h"
38 #include <vcsbase/vcsbaseconstants.h>
40 #include <QtGui/QApplication>
41 #include <QtGui/QLineEdit>
42 #include <QtGui/QFileDialog>
43 #include <QtCore/QTextStream>
45 using namespace Perforce::Internal;
46 using namespace Utils;
48 SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
52 m_ui.errorLabel->clear();
53 m_ui.pathChooser->setPromptDialogTitle(tr("Perforce Command"));
54 m_ui.pathChooser->setExpectedKind(PathChooser::Command);
55 connect(m_ui.testPushButton, SIGNAL(clicked()), this, SLOT(slotTest()));
58 void SettingsPageWidget::slotTest()
61 m_checker = new PerforceChecker(this);
62 m_checker->setUseOverideCursor(true);
63 connect(m_checker.data(), SIGNAL(failed(QString)), this, SLOT(setStatusError(QString)));
64 connect(m_checker.data(), SIGNAL(succeeded(QString)), this, SLOT(testSucceeded(QString)));
67 if (m_checker->isRunning())
70 setStatusText(tr("Testing..."));
71 const Settings s = settings();
72 m_checker->start(s.p4Command, s.commonP4Arguments(), 10000);
75 void SettingsPageWidget::testSucceeded(const QString &repo)
77 setStatusText(tr("Test succeeded (%1).").arg(QDir::toNativeSeparators(repo)));
80 Settings SettingsPageWidget::settings() const
83 settings.p4Command = m_ui.pathChooser->path();
84 settings.defaultEnv = !m_ui.environmentGroupBox->isChecked();
85 settings.p4Port = m_ui.portLineEdit->text();
86 settings.p4User = m_ui.userLineEdit->text();
87 settings.p4Client= m_ui.clientLineEdit->text();
88 settings.timeOutS = m_ui.timeOutSpinBox->value();
89 settings.logCount = m_ui.logCountSpinBox->value();
90 settings.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
91 settings.autoOpen = m_ui.autoOpenCheckBox->isChecked();
95 void SettingsPageWidget::setSettings(const PerforceSettings &s)
97 m_ui.pathChooser->setPath(s.p4Command());
98 m_ui.environmentGroupBox->setChecked(!s.defaultEnv());
99 m_ui.portLineEdit->setText(s.p4Port());
100 m_ui.clientLineEdit->setText(s.p4Client());
101 m_ui.userLineEdit->setText(s.p4User());
102 m_ui.logCountSpinBox->setValue(s.logCount());
103 m_ui.timeOutSpinBox->setValue(s.timeOutS());
104 m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit());
105 m_ui.autoOpenCheckBox->setChecked(s.autoOpen());
108 void SettingsPageWidget::setStatusText(const QString &t)
110 m_ui.errorLabel->setStyleSheet(QString());
111 m_ui.errorLabel->setText(t);
114 void SettingsPageWidget::setStatusError(const QString &t)
116 m_ui.errorLabel->setStyleSheet(QLatin1String("background-color: red"));
117 m_ui.errorLabel->setText(t);
120 QString SettingsPageWidget::searchKeywords() const
123 QLatin1Char sep(' ');
125 << sep << m_ui.configGroupBox->title()
126 << sep << m_ui.commandLabel->text()
127 << sep << m_ui.environmentGroupBox->title()
128 << sep << m_ui.portLabel->text()
129 << sep << m_ui.clientLabel->text()
130 << sep << m_ui.userLabel->text()
131 << sep << m_ui.miscGroupBox->title()
132 << sep << m_ui.logCountLabel->text()
133 << sep << m_ui.timeOutLabel->text()
134 << sep << m_ui.promptToSubmitCheckBox->text()
135 << sep << m_ui.autoOpenCheckBox->text()
137 rc.remove(QLatin1Char('&'));
141 SettingsPage::SettingsPage()
145 QString SettingsPage::id() const
147 return QLatin1String(VCSBase::Constants::VCS_ID_PERFORCE);
150 QString SettingsPage::displayName() const
152 return tr("Perforce");
155 QWidget *SettingsPage::createPage(QWidget *parent)
157 m_widget = new SettingsPageWidget(parent);
158 m_widget->setSettings(PerforcePlugin::perforcePluginInstance()->settings());
159 if (m_searchKeywords.isEmpty())
160 m_searchKeywords = m_widget->searchKeywords();
164 void SettingsPage::apply()
166 PerforcePlugin::perforcePluginInstance()->setSettings(m_widget->settings());
169 bool SettingsPage::matches(const QString &s) const
171 return m_searchKeywords.contains(s, Qt::CaseInsensitive);