OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / perforce / settingspage.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 "settingspage.h"
34 #include "perforcesettings.h"
35 #include "perforceplugin.h"
36 #include "perforcechecker.h"
37
38 #include <vcsbase/vcsbaseconstants.h>
39
40 #include <QtGui/QApplication>
41 #include <QtGui/QLineEdit>
42 #include <QtGui/QFileDialog>
43 #include <QtCore/QTextStream>
44
45 using namespace Perforce::Internal;
46 using namespace Utils;
47
48 SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
49     QWidget(parent)
50 {
51     m_ui.setupUi(this);
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()));
56 }
57
58 void SettingsPageWidget::slotTest()
59 {
60     if (!m_checker) {
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)));
65     }
66
67     if (m_checker->isRunning())
68         return;
69
70     setStatusText(tr("Testing..."));
71     const Settings s = settings();
72     m_checker->start(s.p4Command, s.commonP4Arguments(), 10000);
73 }
74
75 void SettingsPageWidget::testSucceeded(const QString &repo)
76 {
77     setStatusText(tr("Test succeeded (%1).").arg(QDir::toNativeSeparators(repo)));
78 }
79
80 Settings SettingsPageWidget::settings() const
81 {
82     Settings  settings;
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();
92     return settings;
93 }
94
95 void SettingsPageWidget::setSettings(const PerforceSettings &s)
96 {
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());
106 }
107
108 void SettingsPageWidget::setStatusText(const QString &t)
109 {
110     m_ui.errorLabel->setStyleSheet(QString());
111     m_ui.errorLabel->setText(t);
112 }
113
114 void SettingsPageWidget::setStatusError(const QString &t)
115 {
116     m_ui.errorLabel->setStyleSheet(QLatin1String("background-color: red"));
117     m_ui.errorLabel->setText(t);
118 }
119
120 QString SettingsPageWidget::searchKeywords() const
121 {
122     QString rc;
123     QLatin1Char sep(' ');
124     QTextStream(&rc)
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()
136                ;
137     rc.remove(QLatin1Char('&'));
138     return rc;
139 }
140
141 SettingsPage::SettingsPage()
142 {
143 }
144
145 QString SettingsPage::id() const
146 {
147     return QLatin1String(VCSBase::Constants::VCS_ID_PERFORCE);
148 }
149
150 QString SettingsPage::displayName() const
151 {
152     return tr("Perforce");
153 }
154
155 QWidget *SettingsPage::createPage(QWidget *parent)
156 {
157     m_widget = new SettingsPageWidget(parent);
158     m_widget->setSettings(PerforcePlugin::perforcePluginInstance()->settings());
159     if (m_searchKeywords.isEmpty())
160         m_searchKeywords = m_widget->searchKeywords();
161     return m_widget;
162 }
163
164 void SettingsPage::apply()
165 {
166     PerforcePlugin::perforcePluginInstance()->setSettings(m_widget->settings());
167 }
168
169 bool SettingsPage::matches(const QString &s) const
170 {
171     return m_searchKeywords.contains(s, Qt::CaseInsensitive);
172 }