optionspage.cpp 4.68 KB
Newer Older
cerf's avatar
cerf committed
1
2
/**************************************************************************
**
3
** Copyright (c) 2013 Hugues Delorme
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
cerf's avatar
cerf committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
cerf's avatar
cerf committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
cerf's avatar
cerf committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
cerf's avatar
cerf committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
cerf's avatar
cerf committed
29
30
31
32
33
34
35
#include "optionspage.h"
#include "bazaarsettings.h"
#include "bazaarplugin.h"

#include <coreplugin/icore.h>
#include <vcsbase/vcsbaseconstants.h>

36
#include <QTextStream>
cerf's avatar
cerf committed
37
38
39
40

using namespace Bazaar::Internal;
using namespace Bazaar;

41
42
OptionsPageWidget::OptionsPageWidget(QWidget *parent)
    : QWidget(parent)
cerf's avatar
cerf committed
43
44
45
46
47
48
49
50
{
    m_ui.setupUi(this);
    m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
    m_ui.commandChooser->setPromptDialogTitle(tr("Bazaar Command"));
}

BazaarSettings OptionsPageWidget::settings() const
{
51
    BazaarSettings s = BazaarPlugin::instance()->settings();
52
    s.setValue(BazaarSettings::binaryPathKey, m_ui.commandChooser->rawPath());
53
54
55
56
57
58
    s.setValue(BazaarSettings::userNameKey, m_ui.defaultUsernameLineEdit->text().trimmed());
    s.setValue(BazaarSettings::userEmailKey, m_ui.defaultEmailLineEdit->text().trimmed());
    s.setValue(BazaarSettings::logCountKey, m_ui.logEntriesCount->value());
    s.setValue(BazaarSettings::timeoutKey, m_ui.timeout->value());
    s.setValue(BazaarSettings::promptOnSubmitKey, m_ui.promptOnSubmitCheckBox->isChecked());
    return s;
cerf's avatar
cerf committed
59
60
61
62
}

void OptionsPageWidget::setSettings(const BazaarSettings &s)
{
63
64
65
66
67
68
    m_ui.commandChooser->setPath(s.stringValue(BazaarSettings::binaryPathKey));
    m_ui.defaultUsernameLineEdit->setText(s.stringValue(BazaarSettings::userNameKey));
    m_ui.defaultEmailLineEdit->setText(s.stringValue(BazaarSettings::userEmailKey));
    m_ui.logEntriesCount->setValue(s.intValue(BazaarSettings::logCountKey));
    m_ui.timeout->setValue(s.intValue(BazaarSettings::timeoutKey));
    m_ui.promptOnSubmitCheckBox->setChecked(s.boolValue(BazaarSettings::promptOnSubmitKey));
cerf's avatar
cerf committed
69
70
71
72
73
74
75
76
}

QString OptionsPageWidget::searchKeywords() const
{
    QString rc;
    QLatin1Char sep(' ');
    QTextStream(&rc)
            << sep << m_ui.configGroupBox->title()
77
            << sep << m_ui.commandLabel->text()
cerf's avatar
cerf committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
            << sep << m_ui.userGroupBox->title()
            << sep << m_ui.defaultUsernameLabel->text()
            << sep << m_ui.defaultEmailLabel->text()
            << sep << m_ui.miscGroupBox->title()
            << sep << m_ui.showLogEntriesLabel->text()
            << sep << m_ui.timeoutSecondsLabel->text()
            << sep << m_ui.promptOnSubmitCheckBox->text()
               ;
    rc.remove(QLatin1Char('&'));
    return rc;
}

OptionsPage::OptionsPage()
{
hjk's avatar
hjk committed
92
    setId(VcsBase::Constants::VCS_ID_BAZAAR);
93
    setDisplayName(tr("Bazaar"));
cerf's avatar
cerf committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
}

QWidget *OptionsPage::createPage(QWidget *parent)
{
    if (!m_optionsPageWidget)
        m_optionsPageWidget = new OptionsPageWidget(parent);
    m_optionsPageWidget->setSettings(BazaarPlugin::instance()->settings());
    if (m_searchKeywords.isEmpty())
        m_searchKeywords = m_optionsPageWidget->searchKeywords();
    return m_optionsPageWidget;
}

void OptionsPage::apply()
{
    if (!m_optionsPageWidget)
        return;
    BazaarPlugin *plugin = BazaarPlugin::instance();
    const BazaarSettings newSettings = m_optionsPageWidget->settings();
    if (newSettings != plugin->settings()) {
        //assume success and emit signal that settings are changed;
        plugin->setSettings(newSettings);
hjk's avatar
hjk committed
115
        newSettings.writeSettings(Core::ICore::settings());
cerf's avatar
cerf committed
116
117
118
119
120
121
122
123
        emit settingsChanged();
    }
}

bool OptionsPage::matches(const QString &s) const
{
    return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}