forked from qt-creator/qt-creator
CPaster: Aspectify general settings
Change-Id: Ia0a24dd5fdc03217c54aee50ed1f39be0110a415 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -24,7 +24,6 @@ add_qtc_plugin(CodePaster
|
|||||||
pasteview.cpp pasteview.h pasteview.ui
|
pasteview.cpp pasteview.h pasteview.ui
|
||||||
protocol.cpp protocol.h
|
protocol.cpp protocol.h
|
||||||
settings.cpp settings.h
|
settings.cpp settings.h
|
||||||
settingspage.cpp settingspage.h settingspage.ui
|
|
||||||
stickynotespasteprotocol.cpp stickynotespasteprotocol.h
|
stickynotespasteprotocol.cpp stickynotespasteprotocol.h
|
||||||
urlopenprotocol.cpp urlopenprotocol.h
|
urlopenprotocol.cpp urlopenprotocol.h
|
||||||
|
|
||||||
|
@@ -2,7 +2,6 @@ QT += network
|
|||||||
include(../../qtcreatorplugin.pri)
|
include(../../qtcreatorplugin.pri)
|
||||||
HEADERS += cpasterplugin.h \
|
HEADERS += cpasterplugin.h \
|
||||||
dpastedotcomprotocol.h \
|
dpastedotcomprotocol.h \
|
||||||
settingspage.h \
|
|
||||||
protocol.h \
|
protocol.h \
|
||||||
pasteview.h \
|
pasteview.h \
|
||||||
cpasterconstants.h \
|
cpasterconstants.h \
|
||||||
@@ -18,7 +17,6 @@ HEADERS += cpasterplugin.h \
|
|||||||
|
|
||||||
SOURCES += cpasterplugin.cpp \
|
SOURCES += cpasterplugin.cpp \
|
||||||
dpastedotcomprotocol.cpp \
|
dpastedotcomprotocol.cpp \
|
||||||
settingspage.cpp \
|
|
||||||
protocol.cpp \
|
protocol.cpp \
|
||||||
pasteview.cpp \
|
pasteview.cpp \
|
||||||
pastebindotcomprotocol.cpp \
|
pastebindotcomprotocol.cpp \
|
||||||
@@ -30,7 +28,7 @@ SOURCES += cpasterplugin.cpp \
|
|||||||
stickynotespasteprotocol.cpp \
|
stickynotespasteprotocol.cpp \
|
||||||
urlopenprotocol.cpp
|
urlopenprotocol.cpp
|
||||||
|
|
||||||
FORMS += settingspage.ui \
|
FORMS += \
|
||||||
pasteselect.ui \
|
pasteselect.ui \
|
||||||
pasteview.ui \
|
pasteview.ui \
|
||||||
pastebindotcomsettings.ui \
|
pastebindotcomsettings.ui \
|
||||||
|
@@ -39,9 +39,6 @@ QtcPlugin {
|
|||||||
"protocol.h",
|
"protocol.h",
|
||||||
"settings.cpp",
|
"settings.cpp",
|
||||||
"settings.h",
|
"settings.h",
|
||||||
"settingspage.cpp",
|
|
||||||
"settingspage.h",
|
|
||||||
"settingspage.ui",
|
|
||||||
"stickynotespasteprotocol.cpp",
|
"stickynotespasteprotocol.cpp",
|
||||||
"stickynotespasteprotocol.h",
|
"stickynotespasteprotocol.h",
|
||||||
"urlopenprotocol.cpp",
|
"urlopenprotocol.cpp",
|
||||||
|
@@ -30,7 +30,6 @@
|
|||||||
#include "pastebindotcomprotocol.h"
|
#include "pastebindotcomprotocol.h"
|
||||||
#include "pasteselectdialog.h"
|
#include "pasteselectdialog.h"
|
||||||
#include "pasteview.h"
|
#include "pasteview.h"
|
||||||
#include "settingspage.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "urlopenprotocol.h"
|
#include "urlopenprotocol.h"
|
||||||
|
|
||||||
@@ -98,10 +97,7 @@ public:
|
|||||||
&dpasteProto
|
&dpasteProto
|
||||||
};
|
};
|
||||||
|
|
||||||
SettingsPage m_settingsPage {
|
SettingsPage m_settingsPage{&m_settings};
|
||||||
&m_settings,
|
|
||||||
Utils::transform(m_protocols, &Protocol::name)
|
|
||||||
};
|
|
||||||
|
|
||||||
QStringList m_fetchedSnippets;
|
QStringList m_fetchedSnippets;
|
||||||
|
|
||||||
@@ -154,15 +150,19 @@ bool CodePasterPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
|
|
||||||
CodePasterPluginPrivate::CodePasterPluginPrivate()
|
CodePasterPluginPrivate::CodePasterPluginPrivate()
|
||||||
{
|
{
|
||||||
// Create the settings Page
|
|
||||||
m_settings.fromSettings(ICore::settings());
|
|
||||||
|
|
||||||
// Connect protocols
|
// Connect protocols
|
||||||
for (Protocol *proto : m_protocols) {
|
if (!m_protocols.isEmpty()) {
|
||||||
connect(proto, &Protocol::pasteDone, this, &CodePasterPluginPrivate::finishPost);
|
for (Protocol *proto : m_protocols) {
|
||||||
connect(proto, &Protocol::fetchDone, this, &CodePasterPluginPrivate::finishFetch);
|
m_settings.protocols.addOption(proto->name());
|
||||||
|
connect(proto, &Protocol::pasteDone, this, &CodePasterPluginPrivate::finishPost);
|
||||||
|
connect(proto, &Protocol::fetchDone, this, &CodePasterPluginPrivate::finishFetch);
|
||||||
|
}
|
||||||
|
m_settings.protocols.setDefaultValue(m_protocols.at(0)->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the settings Page
|
||||||
|
m_settings.readSettings(ICore::settings());
|
||||||
|
|
||||||
connect(&m_urlOpen, &Protocol::fetchDone, this, &CodePasterPluginPrivate::finishFetch);
|
connect(&m_urlOpen, &Protocol::fetchDone, this, &CodePasterPluginPrivate::finishFetch);
|
||||||
|
|
||||||
//register actions
|
//register actions
|
||||||
@@ -267,20 +267,20 @@ void CodePasterPluginPrivate::post(QString data, const QString &mimeType)
|
|||||||
{
|
{
|
||||||
fixSpecialCharacters(data);
|
fixSpecialCharacters(data);
|
||||||
|
|
||||||
const QString username = m_settings.username;
|
const QString username = m_settings.username.value();
|
||||||
|
|
||||||
PasteView view(m_protocols, mimeType, ICore::dialogParent());
|
PasteView view(m_protocols, mimeType, ICore::dialogParent());
|
||||||
view.setProtocol(m_settings.protocol);
|
view.setProtocol(m_settings.protocols.stringValue());
|
||||||
|
|
||||||
const FileDataList diffChunks = splitDiffToFiles(data);
|
const FileDataList diffChunks = splitDiffToFiles(data);
|
||||||
const int dialogResult = diffChunks.isEmpty() ?
|
const int dialogResult = diffChunks.isEmpty() ?
|
||||||
view.show(username, QString(), QString(), m_settings.expiryDays, m_settings.publicPaste, data) :
|
view.show(username, {}, {}, m_settings.expiryDays.value(), m_settings.publicPaste.value(), data) :
|
||||||
view.show(username, QString(), QString(), m_settings.expiryDays, m_settings.publicPaste, diffChunks);
|
view.show(username, {}, {}, m_settings.expiryDays.value(), m_settings.publicPaste.value(), diffChunks);
|
||||||
|
|
||||||
// Save new protocol in case user changed it.
|
// Save new protocol in case user changed it.
|
||||||
if (dialogResult == QDialog::Accepted && m_settings.protocol != view.protocol()) {
|
if (dialogResult == QDialog::Accepted && m_settings.protocols.value() != view.protocol()) {
|
||||||
m_settings.protocol = view.protocol();
|
m_settings.protocols.setValue(view.protocol());
|
||||||
m_settings.toSettings(ICore::settings());
|
m_settings.writeSettings(ICore::settings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,14 +304,14 @@ void CodePasterPluginPrivate::pasteSnippet()
|
|||||||
void CodePasterPluginPrivate::fetch()
|
void CodePasterPluginPrivate::fetch()
|
||||||
{
|
{
|
||||||
PasteSelectDialog dialog(m_protocols, ICore::dialogParent());
|
PasteSelectDialog dialog(m_protocols, ICore::dialogParent());
|
||||||
dialog.setProtocol(m_settings.protocol);
|
dialog.setProtocol(m_settings.protocols.stringValue());
|
||||||
|
|
||||||
if (dialog.exec() != QDialog::Accepted)
|
if (dialog.exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
// Save new protocol in case user changed it.
|
// Save new protocol in case user changed it.
|
||||||
if (m_settings.protocol != dialog.protocol()) {
|
if (m_settings.protocols.value() != dialog.protocol()) {
|
||||||
m_settings.protocol = dialog.protocol();
|
m_settings.protocols.setValue(dialog.protocol());
|
||||||
m_settings.toSettings(ICore::settings());
|
m_settings.writeSettings(ICore::settings());
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString pasteID = dialog.pasteId();
|
const QString pasteID = dialog.pasteId();
|
||||||
@@ -324,9 +324,9 @@ void CodePasterPluginPrivate::fetch()
|
|||||||
|
|
||||||
void CodePasterPluginPrivate::finishPost(const QString &link)
|
void CodePasterPluginPrivate::finishPost(const QString &link)
|
||||||
{
|
{
|
||||||
if (m_settings.copyToClipboard)
|
if (m_settings.copyToClipboard.value())
|
||||||
QApplication::clipboard()->setText(link);
|
QApplication::clipboard()->setText(link);
|
||||||
if (m_settings.displayOutput)
|
if (m_settings.displayOutput.value())
|
||||||
MessageManager::writeDisrupting(link);
|
MessageManager::writeDisrupting(link);
|
||||||
else
|
else
|
||||||
MessageManager::writeSilently(link);
|
MessageManager::writeSilently(link);
|
||||||
|
@@ -84,9 +84,9 @@ void PasteSelectDialog::setProtocol(const QString &p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PasteSelectDialog::protocol() const
|
int PasteSelectDialog::protocol() const
|
||||||
{
|
{
|
||||||
return m_ui.protocolBox->currentText();
|
return m_ui.protocolBox->currentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PasteSelectDialog::protocolIndex() const
|
int PasteSelectDialog::protocolIndex() const
|
||||||
|
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
QString pasteId() const;
|
QString pasteId() const;
|
||||||
|
|
||||||
QString protocol() const;
|
int protocol() const;
|
||||||
void setProtocol(const QString &);
|
void setProtocol(const QString &);
|
||||||
|
|
||||||
int protocolIndex() const;
|
int protocolIndex() const;
|
||||||
|
@@ -94,9 +94,9 @@ QString PasteView::content() const
|
|||||||
return newContent;
|
return newContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PasteView::protocol() const
|
int PasteView::protocol() const
|
||||||
{
|
{
|
||||||
return m_ui.protocolBox->currentText();
|
return m_ui.protocolBox->currentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PasteView::contentChanged()
|
void PasteView::contentChanged()
|
||||||
|
@@ -63,7 +63,7 @@ public:
|
|||||||
QString description() const;
|
QString description() const;
|
||||||
QString comment() const;
|
QString comment() const;
|
||||||
QString content() const;
|
QString content() const;
|
||||||
QString protocol() const;
|
int protocol() const;
|
||||||
void setExpiryDays(int d);
|
void setExpiryDays(int d);
|
||||||
void setMakePublic(bool p);
|
void setMakePublic(bool p);
|
||||||
int expiryDays() const;
|
int expiryDays() const;
|
||||||
|
@@ -24,51 +24,109 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
#include "cpasterconstants.h"
|
||||||
#include "pastebindotcomprotocol.h"
|
#include "pastebindotcomprotocol.h"
|
||||||
|
|
||||||
#include <utils/environment.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
#include <QSettings>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
static const char groupC[] = "CodePaster";
|
using namespace Utils;
|
||||||
static const char userNameKeyC[] = "UserName";
|
|
||||||
static const char expiryDaysKeyC[] = "ExpiryDays";
|
|
||||||
static const char defaultProtocolKeyC[] = "DefaultProtocol";
|
|
||||||
static const char copyToClipboardKeyC[] = "CopyToClipboard";
|
|
||||||
static const char displayOutputKeyC[] = "DisplayOutput";
|
|
||||||
static const char publicPasteKeyC[] = "DisplayOutput";
|
|
||||||
|
|
||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
bool Settings::equals(const Settings &rhs) const
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
return copyToClipboard == rhs.copyToClipboard && displayOutput == rhs.displayOutput
|
setSettingsGroup("CodePaster");
|
||||||
&& expiryDays == rhs.expiryDays && username == rhs.username
|
setAutoApply(false);
|
||||||
&& protocol == rhs.protocol && publicPaste == rhs.publicPaste;
|
|
||||||
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::toSettings(QSettings *settings) const
|
// SettingsPage
|
||||||
|
|
||||||
|
class SettingsWidget final : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
settings->beginGroup(QLatin1String(groupC));
|
public:
|
||||||
settings->setValue(QLatin1String(userNameKeyC), username);
|
SettingsWidget(Settings *settings);
|
||||||
settings->setValue(QLatin1String(defaultProtocolKeyC), protocol);
|
|
||||||
settings->setValue(QLatin1String(expiryDaysKeyC), expiryDays);
|
private:
|
||||||
settings->setValue(QLatin1String(copyToClipboardKeyC), copyToClipboard);
|
void apply() final;
|
||||||
settings->setValue(QLatin1String(displayOutputKeyC), displayOutput);
|
|
||||||
settings->setValue(publicPasteKeyC, publicPaste);
|
Settings *m_settings;
|
||||||
settings->endGroup();
|
};
|
||||||
|
|
||||||
|
SettingsWidget::SettingsWidget(Settings *settings)
|
||||||
|
: m_settings(settings)
|
||||||
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::fromSettings(const QSettings *settings)
|
void SettingsWidget::apply()
|
||||||
{
|
{
|
||||||
const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
|
if (m_settings->isDirty()) {
|
||||||
const QString defaultUser = Utils::Environment::systemEnvironment().userName();
|
m_settings->apply();
|
||||||
expiryDays = settings->value(rootKey + QLatin1String(expiryDaysKeyC), 1).toInt();
|
m_settings->writeSettings(Core::ICore::settings());
|
||||||
username = settings->value(rootKey + QLatin1String(userNameKeyC), defaultUser).toString();
|
}
|
||||||
protocol = settings->value(rootKey + QLatin1String(defaultProtocolKeyC), PasteBinDotComProtocol::protocolName()).toString();
|
}
|
||||||
copyToClipboard = settings->value(rootKey + QLatin1String(copyToClipboardKeyC), true).toBool();
|
|
||||||
displayOutput = settings->value(rootKey + QLatin1String(displayOutputKeyC), true).toBool();
|
SettingsPage::SettingsPage(Settings *settings)
|
||||||
publicPaste = settings->value(rootKey + publicPasteKeyC, false).toBool();
|
{
|
||||||
|
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); });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CodePaster
|
} // namespace CodePaster
|
||||||
|
@@ -25,29 +25,33 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
#include <utils/aspects.h>
|
||||||
class QSettings;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
class Settings {
|
class Settings : public Utils::AspectContainer
|
||||||
public:
|
{
|
||||||
void toSettings(QSettings *s) const;
|
Q_DECLARE_TR_FUNCTIONS(CodePaster::Settings)
|
||||||
void fromSettings(const QSettings *s);
|
|
||||||
bool equals(const Settings &s) const;
|
|
||||||
|
|
||||||
QString username;
|
public:
|
||||||
QString protocol;
|
Settings();
|
||||||
int expiryDays = 1;
|
|
||||||
bool copyToClipboard = true;
|
Utils::StringAspect username;
|
||||||
bool displayOutput = true;
|
Utils::SelectionAspect protocols;
|
||||||
bool publicPaste = false;
|
Utils::IntegerAspect expiryDays;
|
||||||
|
Utils::BoolAspect copyToClipboard;
|
||||||
|
Utils::BoolAspect displayOutput;
|
||||||
|
Utils::BoolAspect publicPaste;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
|
class SettingsPage final : public Core::IOptionsPage
|
||||||
inline bool operator!=(const Settings &s1, const Settings &s2) { return !s1.equals(s2); }
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(CodePaster::SettingsPage)
|
||||||
|
|
||||||
|
public:
|
||||||
|
SettingsPage(Settings *settings);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace CodePaster
|
} // namespace CodePaster
|
||||||
|
@@ -1,92 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** 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 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.
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "settingspage.h"
|
|
||||||
#include "settings.h"
|
|
||||||
#include "cpasterconstants.h"
|
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
namespace CodePaster {
|
|
||||||
|
|
||||||
class SettingsWidget final : public Core::IOptionsPageWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SettingsWidget(const QStringList &protocols, Settings *settings);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void apply() final;
|
|
||||||
|
|
||||||
Settings *m_settings;
|
|
||||||
Internal::Ui::SettingsPage m_ui;
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsWidget::SettingsWidget(const QStringList &protocols, Settings *settings)
|
|
||||||
: m_settings(settings)
|
|
||||||
{
|
|
||||||
m_ui.setupUi(this);
|
|
||||||
m_ui.defaultProtocol->addItems(protocols);
|
|
||||||
|
|
||||||
m_ui.userEdit->setText(m_settings->username);
|
|
||||||
const int index = m_ui.defaultProtocol->findText(m_settings->protocol);
|
|
||||||
m_ui.defaultProtocol->setCurrentIndex(index == -1 ? 0 : index);
|
|
||||||
m_ui.expirySpinBox->setValue(m_settings->expiryDays);
|
|
||||||
m_ui.publicCheckBox->setChecked(m_settings->publicPaste);
|
|
||||||
m_ui.clipboardBox->setChecked(m_settings->copyToClipboard);
|
|
||||||
m_ui.displayBox->setChecked(m_settings->displayOutput);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsWidget::apply()
|
|
||||||
{
|
|
||||||
Settings rc;
|
|
||||||
rc.username = m_ui.userEdit->text();
|
|
||||||
rc.protocol = m_ui.defaultProtocol->currentText();
|
|
||||||
rc.expiryDays = m_ui.expirySpinBox->value();
|
|
||||||
rc.publicPaste = m_ui.publicCheckBox->isChecked();
|
|
||||||
rc.copyToClipboard = m_ui.clipboardBox->isChecked();
|
|
||||||
rc.displayOutput = m_ui.displayBox->isChecked();
|
|
||||||
|
|
||||||
if (rc != *m_settings) {
|
|
||||||
*m_settings = rc;
|
|
||||||
m_settings->toSettings(Core::ICore::settings());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SettingsPage::SettingsPage(Settings *settings, const QStringList &protocolNames)
|
|
||||||
{
|
|
||||||
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, protocolNames] {
|
|
||||||
return new SettingsWidget(protocolNames, settings);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace CodePaster
|
|
@@ -1,45 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** 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 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.
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ui_settingspage.h"
|
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
namespace CodePaster {
|
|
||||||
|
|
||||||
class Settings;
|
|
||||||
|
|
||||||
class SettingsPage final : public Core::IOptionsPage
|
|
||||||
{
|
|
||||||
Q_DECLARE_TR_FUNCTIONS(CodePaster::SettingsPage)
|
|
||||||
public:
|
|
||||||
SettingsPage(Settings *settings, const QStringList &protocolNames);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace CodePaster
|
|
@@ -1,102 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>CodePaster::Internal::SettingsPage</class>
|
|
||||||
<widget class="QWidget" name="CodePaster::Internal::SettingsPage">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>370</width>
|
|
||||||
<height>229</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="4" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="clipboardBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Copy-paste URL to clipboard</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="9" column="0" colspan="2">
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>223</width>
|
|
||||||
<height>100</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="userEdit"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QComboBox" name="defaultProtocol"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="protocolLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Default protocol:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="expiryLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Expires after:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>expirySpinBox</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="displayBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Display Output pane after sending a post</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="userNameLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Username:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QSpinBox" name="expirySpinBox">
|
|
||||||
<property name="suffix">
|
|
||||||
<string> Days</string>
|
|
||||||
</property>
|
|
||||||
<property name="minimum">
|
|
||||||
<number>1</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>365</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
|
||||||
<widget class="QCheckBox" name="publicCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Make pasted content public by default</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<tabstops>
|
|
||||||
<tabstop>defaultProtocol</tabstop>
|
|
||||||
<tabstop>userEdit</tabstop>
|
|
||||||
<tabstop>expirySpinBox</tabstop>
|
|
||||||
<tabstop>clipboardBox</tabstop>
|
|
||||||
<tabstop>displayBox</tabstop>
|
|
||||||
</tabstops>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
Reference in New Issue
Block a user