OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cpaster / fileshareprotocolsettingspage.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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "fileshareprotocolsettingspage.h"
35 #include "cpasterconstants.h"
36
37 #include <coreplugin/icore.h>
38
39 #include <QtCore/QDir>
40 #include <QtCore/QSettings>
41 #include <QtCore/QCoreApplication>
42
43 static const char settingsGroupC[] = "FileSharePasterSettings";
44 static const char pathKeyC[] = "Path";
45 static const char displayCountKeyC[] = "DisplayCount";
46
47 namespace CodePaster {
48
49 FileShareProtocolSettings::FileShareProtocolSettings() :
50         path(QDir::tempPath()), displayCount(10)
51 {
52 }
53
54 void FileShareProtocolSettings::toSettings(QSettings *s) const
55 {
56     s->beginGroup(QLatin1String(settingsGroupC));
57     s->setValue(QLatin1String(pathKeyC), path);
58     s->setValue(QLatin1String(displayCountKeyC), displayCount);
59     s->endGroup();
60 }
61
62 void FileShareProtocolSettings::fromSettings(const QSettings *s)
63 {
64     FileShareProtocolSettings defaultValues;
65     const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
66     path = s->value(keyRoot + QLatin1String(pathKeyC), defaultValues.path).toString();
67     displayCount = s->value(keyRoot + QLatin1String(displayCountKeyC), defaultValues.displayCount).toInt();
68 }
69
70 bool FileShareProtocolSettings::equals(const FileShareProtocolSettings &rhs) const
71 {
72     return displayCount == rhs.displayCount &&  path == rhs.path;
73 }
74
75 FileShareProtocolSettingsWidget::FileShareProtocolSettingsWidget(QWidget *parent) :
76     QWidget(parent)
77 {
78     m_ui.setupUi(this);
79
80     // Add a space in front of the suffix
81     QString suffix = m_ui.displayCountSpinBox->suffix();
82     suffix.prepend(QLatin1Char(' '));
83     m_ui.displayCountSpinBox->setSuffix(suffix);
84 }
85
86 void FileShareProtocolSettingsWidget::setSettings(const FileShareProtocolSettings &s)
87 {
88     m_ui.pathChooser->setPath(s.path);
89     m_ui.displayCountSpinBox->setValue(s.displayCount);
90 }
91
92 FileShareProtocolSettings FileShareProtocolSettingsWidget::settings() const
93 {
94     FileShareProtocolSettings rc;
95     rc.path = m_ui.pathChooser->path();
96     rc.displayCount = m_ui.displayCountSpinBox->value();
97     return rc;
98 }
99
100 // ----------FileShareProtocolSettingsPage
101 FileShareProtocolSettingsPage::FileShareProtocolSettingsPage(const QSharedPointer<FileShareProtocolSettings> &s,
102                                                              QObject *parent) :
103     Core::IOptionsPage(parent), m_settings(s), m_widget(0)
104 {
105 }
106
107 QString FileShareProtocolSettingsPage::id() const
108 {
109     return QLatin1String("X.FileSharePaster");
110 }
111
112 QString FileShareProtocolSettingsPage::displayName() const
113 {
114     return tr("Fileshare");
115 }
116
117 QString FileShareProtocolSettingsPage::category() const
118 {
119     return QLatin1String(Constants::CPASTER_SETTINGS_CATEGORY);
120 }
121
122 QString FileShareProtocolSettingsPage::displayCategory() const
123 {
124     return QCoreApplication::translate("CodePaster", Constants::CPASTER_SETTINGS_TR_CATEGORY);
125 }
126
127 QIcon FileShareProtocolSettingsPage::categoryIcon() const
128 {
129     return QIcon();
130 }
131
132 QWidget *FileShareProtocolSettingsPage::createPage(QWidget *parent)
133 {
134     m_widget = new FileShareProtocolSettingsWidget(parent);
135     m_widget->setSettings(*m_settings);
136     return m_widget;
137 }
138
139 void FileShareProtocolSettingsPage::apply()
140 {
141     if (!m_widget) // page was never shown
142         return;
143     const FileShareProtocolSettings newSettings = m_widget->settings();
144     if (newSettings != *m_settings) {
145         *m_settings = newSettings;
146         m_settings->toSettings(Core::ICore::instance()->settings());
147     }
148 }
149 } // namespace CodePaster