codepastersettings.cpp 3.81 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
hjk's avatar
hjk committed
3
4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
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.
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
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30

#include "codepastersettings.h"
31
#include "cpasterconstants.h"
32
33
34

#include <coreplugin/icore.h>

35
36
37
38
39
40
41
42
43
44
45
#include <QSettings>
#include <QCoreApplication>
#include <QLineEdit>
#include <QFileDialog>
#include <QGroupBox>
#include <QFormLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QIcon>
#include <QDebug>
#include <QVariant>
46

47
48
49
50
static const char settingsGroupC[] = "CodePasterSettings";
static const char serverKeyC[] = "Server";

namespace CodePaster {
51
52
53

CodePasterSettingsPage::CodePasterSettingsPage()
{
hjk's avatar
hjk committed
54
    setId("C.CodePaster");
55
    setDisplayName(tr("CodePaster"));
hjk's avatar
hjk committed
56
    setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
57
58
59
    setDisplayCategory(QCoreApplication::translate("CodePaster",
        Constants::CPASTER_SETTINGS_TR_CATEGORY));

hjk's avatar
hjk committed
60
    m_settings = Core::ICore::settings();
61
    if (m_settings) {
62
63
        const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
        m_host = m_settings->value(keyRoot + QLatin1String(serverKeyC), QString()).toString();
64
65
66
67
68
    }
}

QWidget *CodePasterSettingsPage::createPage(QWidget *parent)
{
69
70
71
    QWidget *outerWidget = new QWidget(parent);
    QVBoxLayout *outerLayout = new QVBoxLayout(outerWidget);

72
    QFormLayout *formLayout = new QFormLayout;
con's avatar
con committed
73
    formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
74
75
76
77
    QLineEdit *lineEdit = new QLineEdit(m_host);
    connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString)));
    formLayout->addRow(tr("Server:"), lineEdit);
    outerLayout->addLayout(formLayout);
78
    outerLayout->addSpacerItem(new QSpacerItem(0, 3, QSizePolicy::Ignored, QSizePolicy::Fixed));
79

80
81
    QLabel *noteLabel = new QLabel(tr("<i>Note: Specify the host name for the CodePaster service "
                                      "without any protocol prepended (e.g. codepaster.mycompany.com).</i>"));
82
    noteLabel->setWordWrap(true);
83
    outerLayout->addWidget(noteLabel);
84
85
86

    outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
    return outerWidget;
87
88
89
90
91
92
93
}

void CodePasterSettingsPage::apply()
{
    if (!m_settings)
        return;

94
95
    m_settings->beginGroup(QLatin1String(settingsGroupC));
    m_settings->setValue(QLatin1String(serverKeyC), m_host);
96
97
98
99
100
    m_settings->endGroup();
}

void CodePasterSettingsPage::serverChanged(const QString &host)
{
Tobias Hunger's avatar
Tobias Hunger committed
101
    m_host = host.trimmed();
102
103
104
105
106
107
}

QString CodePasterSettingsPage::hostName() const
{
    return m_host;
}
108
} // namespace CodePaster