2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-26 12:47:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-03-26 12:47:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-03-26 12:47:06 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-03-26 12:47:06 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-03-26 12:47:06 +01:00
|
|
|
|
|
|
|
|
#include "settings.h"
|
2021-03-22 17:01:23 +01:00
|
|
|
|
|
|
|
|
#include "cpasterconstants.h"
|
2010-04-06 14:40:33 +02:00
|
|
|
#include "pastebindotcomprotocol.h"
|
2010-03-26 12:47:06 +01:00
|
|
|
|
2021-03-22 17:01:23 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
|
2021-03-22 17:01:23 +01:00
|
|
|
#include <utils/layoutbuilder.h>
|
2010-03-26 12:47:06 +01:00
|
|
|
|
2021-03-22 17:01:23 +01:00
|
|
|
using namespace Utils;
|
2010-03-26 12:47:06 +01:00
|
|
|
|
|
|
|
|
namespace CodePaster {
|
|
|
|
|
|
2021-03-22 17:01:23 +01:00
|
|
|
Settings::Settings()
|
|
|
|
|
{
|
|
|
|
|
setSettingsGroup("CodePaster");
|
|
|
|
|
setAutoApply(false);
|
|
|
|
|
|
|
|
|
|
registerAspect(&username);
|
|
|
|
|
username.setDisplayStyle(StringAspect::LineEditDisplay);
|
|
|
|
|
username.setSettingsKey("UserName");
|
|
|
|
|
username.setLabelText(tr("Username:"));
|
|
|
|
|
|
|
|
|
|
registerAspect(&protocols);
|
|
|
|
|
protocols.setSettingsKey("DefaultProtocol");
|
|
|
|
|
protocols.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
|
|
|
|
|
protocols.setLabelText(tr("Default protocol:"));
|
|
|
|
|
protocols.setToSettingsTransformation([this](const QVariant &val) {
|
|
|
|
|
return protocols.displayForIndex(val.toInt());
|
|
|
|
|
});
|
|
|
|
|
protocols.setFromSettingsTransformation([this](const QVariant &val) {
|
|
|
|
|
return protocols.indexForDisplay(val.toString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
registerAspect(&expiryDays);
|
|
|
|
|
expiryDays.setSettingsKey("ExpiryDays");
|
|
|
|
|
expiryDays.setDefaultValue(1);
|
|
|
|
|
expiryDays.setSuffix(tr(" Days"));
|
|
|
|
|
expiryDays.setLabelText(tr("&Expires after:"));
|
|
|
|
|
|
|
|
|
|
registerAspect(©ToClipboard);
|
|
|
|
|
copyToClipboard.setSettingsKey("CopyToClipboard");
|
|
|
|
|
copyToClipboard.setDefaultValue(true);
|
|
|
|
|
copyToClipboard.setLabelText(tr("Copy-paste URL to clipboard"));
|
|
|
|
|
|
|
|
|
|
registerAspect(&displayOutput);
|
|
|
|
|
displayOutput.setSettingsKey("DisplayOutput");
|
|
|
|
|
displayOutput.setDefaultValue(true);
|
|
|
|
|
displayOutput.setLabelText(tr("Display Output pane after sending a post"));
|
|
|
|
|
|
|
|
|
|
registerAspect(&publicPaste);
|
|
|
|
|
publicPaste.setSettingsKey("DisplayOutput");
|
|
|
|
|
publicPaste.setLabelText(tr("Make pasted content public by default"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SettingsPage
|
|
|
|
|
|
|
|
|
|
class SettingsWidget final : public Core::IOptionsPageWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SettingsWidget(Settings *settings);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
Settings *m_settings;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SettingsWidget::SettingsWidget(Settings *settings)
|
|
|
|
|
: m_settings(settings)
|
2010-03-26 12:47:06 +01:00
|
|
|
{
|
2021-03-22 17:01:23 +01:00
|
|
|
Settings &s = *settings;
|
|
|
|
|
using namespace Layouting;
|
|
|
|
|
const Break nl;
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Form {
|
|
|
|
|
s.protocols, nl,
|
|
|
|
|
s.username, nl,
|
|
|
|
|
s.expiryDays
|
|
|
|
|
},
|
|
|
|
|
s.copyToClipboard,
|
|
|
|
|
s.displayOutput,
|
|
|
|
|
s.publicPaste,
|
|
|
|
|
Stretch()
|
|
|
|
|
}.attachTo(this);
|
2010-03-26 12:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:01:23 +01:00
|
|
|
void SettingsWidget::apply()
|
2010-03-26 12:47:06 +01:00
|
|
|
{
|
2021-03-22 17:01:23 +01:00
|
|
|
if (m_settings->isDirty()) {
|
|
|
|
|
m_settings->apply();
|
|
|
|
|
m_settings->writeSettings(Core::ICore::settings());
|
|
|
|
|
}
|
2010-03-26 12:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:01:23 +01:00
|
|
|
SettingsPage::SettingsPage(Settings *settings)
|
2010-03-26 12:47:06 +01:00
|
|
|
{
|
2021-03-22 17:01:23 +01:00
|
|
|
setId("A.CodePaster.General");
|
|
|
|
|
setDisplayName(tr("General"));
|
|
|
|
|
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("CodePaster", "Code Pasting"));
|
|
|
|
|
setCategoryIconPath(":/cpaster/images/settingscategory_cpaster.png");
|
|
|
|
|
setWidgetCreator([settings] { return new SettingsWidget(settings); });
|
2010-03-26 12:47:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace CodePaster
|