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"
35 #include "cpasterconstants.h"
37 #include <utils/qtcassert.h>
38 #include <coreplugin/icore.h>
40 #include <QtCore/QSettings>
41 #include <QtCore/QTextStream>
42 #include <QtCore/QCoreApplication>
44 namespace CodePaster {
46 SettingsWidget::SettingsWidget(const QStringList &protocols, QWidget *parent) :
50 m_ui.defaultProtocol->addItems(protocols);
53 QString SettingsWidget::searchKeywords() const
56 QTextStream(&rc) << m_ui.protocolLabel->text() << ' '
57 << m_ui.userNameLabel->text();
58 rc.remove(QLatin1Char('&'));
62 void SettingsWidget::setSettings(const Settings &settings)
64 m_ui.userEdit->setText(settings.username);
65 const int index = m_ui.defaultProtocol->findText(settings.protocol);
66 m_ui.defaultProtocol->setCurrentIndex(index == -1 ? 0 : index);
67 m_ui.clipboardBox->setChecked(settings.copyToClipboard);
68 m_ui.displayBox->setChecked(settings.displayOutput);
71 Settings SettingsWidget::settings()
74 rc.username = m_ui.userEdit->text();
75 rc.protocol = m_ui.defaultProtocol->currentText();
76 rc.copyToClipboard = m_ui.clipboardBox->isChecked();
77 rc.displayOutput = m_ui.displayBox->isChecked();
81 SettingsPage::SettingsPage(const QSharedPointer<Settings> &settings) :
82 m_settings(settings), m_widget(0)
86 SettingsPage::~SettingsPage()
90 QString SettingsPage::id() const
92 return QLatin1String("A.General");
95 QString SettingsPage::displayName() const
100 QString SettingsPage::category() const
102 return QLatin1String(Constants::CPASTER_SETTINGS_CATEGORY);
105 QString SettingsPage::displayCategory() const
107 return QCoreApplication::translate("CodePaster", Constants::CPASTER_SETTINGS_TR_CATEGORY);
110 QIcon SettingsPage::categoryIcon() const
112 return QIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPASTER_ICON));
115 QWidget *SettingsPage::createPage(QWidget *parent)
117 m_widget = new SettingsWidget(m_protocols, parent);
118 m_widget->setSettings(*m_settings);
120 if (m_searchKeywords.isEmpty())
121 m_searchKeywords = m_widget->searchKeywords();
125 void SettingsPage::apply()
127 if (!m_widget) // page was never shown
129 const Settings newSettings = m_widget->settings();
130 if (newSettings != *m_settings) {
131 *m_settings = newSettings;
132 m_settings->toSettings(Core::ICore::instance()->settings());
136 bool SettingsPage::matches(const QString &s) const
138 return m_searchKeywords.contains(s, Qt::CaseInsensitive);
141 void SettingsPage::addProtocol(const QString &name)
143 m_protocols.append(name);
146 } // namespace CodePaster