OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / cpaster / pastebindotcomsettings.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 "pastebindotcomsettings.h"
35 #include "cpasterconstants.h"
36 #include "ui_pastebindotcomsettings.h"
37
38 #include <coreplugin/icore.h>
39 #include <QtCore/QSettings>
40 #include <QtCore/QCoreApplication>
41
42 static const char groupC[] = "PasteBinDotComSettings";
43 static const char prefixKeyC[] = "Prefix";
44
45 namespace CodePaster {
46 PasteBinDotComSettings::PasteBinDotComSettings()
47 {
48     m_settings = Core::ICore::instance()->settings();
49     if (m_settings) {
50         const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
51         m_hostPrefix = m_settings->value(rootKey + QLatin1String(prefixKeyC), QString()).toString();
52     }
53 }
54
55 QString PasteBinDotComSettings::id() const
56 {
57     return QLatin1String("B.Pastebin.com");
58 }
59
60 QString PasteBinDotComSettings::displayName() const
61 {
62     return tr("Pastebin.com");
63 }
64
65 QString PasteBinDotComSettings::category() const
66 {
67     return QLatin1String(CodePaster::Constants::CPASTER_SETTINGS_CATEGORY);
68 }
69
70 QString PasteBinDotComSettings::displayCategory() const
71 {
72     return QCoreApplication::translate("CodePaster", CodePaster::Constants::CPASTER_SETTINGS_TR_CATEGORY);
73 }
74
75 QIcon PasteBinDotComSettings::categoryIcon() const
76 {
77     return QIcon(); // TODO: Icon for CodePaster
78 }
79
80 QWidget *PasteBinDotComSettings::createPage(QWidget *parent)
81 {
82     Ui_PasteBinComSettingsWidget ui;
83     QWidget *w = new QWidget(parent);
84     ui.setupUi(w);
85     ui.lineEdit->setText(hostPrefix());
86     connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString)));
87     return w;
88 }
89
90 void PasteBinDotComSettings::apply()
91 {
92     if (!m_settings)
93         return;
94
95     m_settings->beginGroup(QLatin1String(groupC));
96     m_settings->setValue(QLatin1String(prefixKeyC), m_hostPrefix);
97     m_settings->endGroup();
98 }
99
100 void PasteBinDotComSettings::serverChanged(const QString &prefix)
101 {
102     m_hostPrefix = prefix;
103 }
104
105 QString PasteBinDotComSettings::hostPrefix() const
106 {
107     return m_hostPrefix;
108 }
109 } //namespace CodePaster