forked from qt-creator/qt-creator
CPaster: Aspectify FileShareProtocolSettings
Change-Id: I9ae9975eb6fd2c4124d17e2862afa9cde32e9438 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -14,7 +14,6 @@ add_qtc_plugin(CodePaster
|
|||||||
dpastedotcomprotocol.cpp dpastedotcomprotocol.h
|
dpastedotcomprotocol.cpp dpastedotcomprotocol.h
|
||||||
fileshareprotocol.cpp fileshareprotocol.h
|
fileshareprotocol.cpp fileshareprotocol.h
|
||||||
fileshareprotocolsettingspage.cpp fileshareprotocolsettingspage.h
|
fileshareprotocolsettingspage.cpp fileshareprotocolsettingspage.h
|
||||||
fileshareprotocolsettingswidget.ui
|
|
||||||
frontend/argumentscollector.cpp frontend/argumentscollector.h
|
frontend/argumentscollector.cpp frontend/argumentscollector.h
|
||||||
frontend/main.cpp
|
frontend/main.cpp
|
||||||
pastebindotcomprotocol.cpp pastebindotcomprotocol.h
|
pastebindotcomprotocol.cpp pastebindotcomprotocol.h
|
||||||
|
@@ -31,8 +31,7 @@ SOURCES += cpasterplugin.cpp \
|
|||||||
FORMS += \
|
FORMS += \
|
||||||
pasteselect.ui \
|
pasteselect.ui \
|
||||||
pasteview.ui \
|
pasteview.ui \
|
||||||
pastebindotcomsettings.ui \
|
pastebindotcomsettings.ui
|
||||||
fileshareprotocolsettingswidget.ui
|
|
||||||
include(../../shared/cpaster/cpaster.pri)
|
include(../../shared/cpaster/cpaster.pri)
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
|
@@ -25,7 +25,6 @@ QtcPlugin {
|
|||||||
"fileshareprotocol.h",
|
"fileshareprotocol.h",
|
||||||
"fileshareprotocolsettingspage.cpp",
|
"fileshareprotocolsettingspage.cpp",
|
||||||
"fileshareprotocolsettingspage.h",
|
"fileshareprotocolsettingspage.h",
|
||||||
"fileshareprotocolsettingswidget.ui",
|
|
||||||
"pastebindotcomprotocol.cpp",
|
"pastebindotcomprotocol.cpp",
|
||||||
"pastebindotcomprotocol.h",
|
"pastebindotcomprotocol.h",
|
||||||
"pastebindotcomsettings.ui",
|
"pastebindotcomsettings.ui",
|
||||||
|
@@ -48,10 +48,9 @@ static const char textElementC[] = "text";
|
|||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
FileShareProtocol::FileShareProtocol() :
|
FileShareProtocol::FileShareProtocol() :
|
||||||
m_settings(new FileShareProtocolSettings),
|
m_settingsPage(new FileShareProtocolSettingsPage(&m_settings))
|
||||||
m_settingsPage(new FileShareProtocolSettingsPage(m_settings))
|
|
||||||
{
|
{
|
||||||
m_settings->fromSettings(Core::ICore::settings());
|
m_settings.readSettings(Core::ICore::settings());
|
||||||
}
|
}
|
||||||
|
|
||||||
FileShareProtocol::~FileShareProtocol()
|
FileShareProtocol::~FileShareProtocol()
|
||||||
@@ -127,7 +126,7 @@ static bool parse(const QString &fileName,
|
|||||||
|
|
||||||
bool FileShareProtocol::checkConfiguration(QString *errorMessage)
|
bool FileShareProtocol::checkConfiguration(QString *errorMessage)
|
||||||
{
|
{
|
||||||
if (m_settings->path.isEmpty()) {
|
if (m_settings.path.value().isEmpty()) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = tr("Please configure a path.");
|
*errorMessage = tr("Please configure a path.");
|
||||||
return false;
|
return false;
|
||||||
@@ -140,7 +139,7 @@ void FileShareProtocol::fetch(const QString &id)
|
|||||||
// Absolute or relative path name.
|
// Absolute or relative path name.
|
||||||
QFileInfo fi(id);
|
QFileInfo fi(id);
|
||||||
if (fi.isRelative())
|
if (fi.isRelative())
|
||||||
fi = QFileInfo(m_settings->path + QLatin1Char('/') + id);
|
fi = QFileInfo(m_settings.path.value() + '/' + id);
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
QString text;
|
QString text;
|
||||||
if (parse(fi.absoluteFilePath(), &errorMessage, nullptr, nullptr, &text))
|
if (parse(fi.absoluteFilePath(), &errorMessage, nullptr, nullptr, &text))
|
||||||
@@ -152,7 +151,7 @@ void FileShareProtocol::fetch(const QString &id)
|
|||||||
void FileShareProtocol::list()
|
void FileShareProtocol::list()
|
||||||
{
|
{
|
||||||
// Read out directory, display by date (latest first)
|
// Read out directory, display by date (latest first)
|
||||||
QDir dir(m_settings->path, QLatin1String(tempGlobPatternC),
|
QDir dir(m_settings.path.value(), tempGlobPatternC,
|
||||||
QDir::Time, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
|
QDir::Time, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
|
||||||
QStringList entries;
|
QStringList entries;
|
||||||
QString user;
|
QString user;
|
||||||
@@ -160,7 +159,7 @@ void FileShareProtocol::list()
|
|||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
const QChar blank = QLatin1Char(' ');
|
const QChar blank = QLatin1Char(' ');
|
||||||
const QFileInfoList entryInfoList = dir.entryInfoList();
|
const QFileInfoList entryInfoList = dir.entryInfoList();
|
||||||
const int count = qMin(m_settings->displayCount, entryInfoList.size());
|
const int count = qMin(int(m_settings.displayCount.value()), entryInfoList.size());
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
const QFileInfo& entryFi = entryInfoList.at(i);
|
const QFileInfo& entryFi = entryInfoList.at(i);
|
||||||
if (parse(entryFi.absoluteFilePath(), &errorMessage, &user, &description)) {
|
if (parse(entryFi.absoluteFilePath(), &errorMessage, &user, &description)) {
|
||||||
@@ -188,7 +187,7 @@ void FileShareProtocol::paste(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Write out temp XML file
|
// Write out temp XML file
|
||||||
Utils::TempFileSaver saver(m_settings->path + QLatin1Char('/') + QLatin1String(tempPatternC));
|
Utils::TempFileSaver saver(m_settings.path.value() + '/' + tempPatternC);
|
||||||
saver.setAutoRemove(false);
|
saver.setAutoRemove(false);
|
||||||
if (!saver.hasError()) {
|
if (!saver.hasError()) {
|
||||||
// Flat text sections embedded into pasterElement
|
// Flat text sections embedded into pasterElement
|
||||||
|
@@ -26,13 +26,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
#include "fileshareprotocolsettingspage.h"
|
||||||
#include <QSharedPointer>
|
|
||||||
|
|
||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
class FileShareProtocolSettingsPage;
|
class FileShareProtocolSettingsPage;
|
||||||
class FileShareProtocolSettings;
|
|
||||||
|
|
||||||
/* FileShareProtocol: Allows for pasting via a shared network
|
/* FileShareProtocol: Allows for pasting via a shared network
|
||||||
* drive by writing XML files. */
|
* drive by writing XML files. */
|
||||||
@@ -60,7 +58,7 @@ public:
|
|||||||
const QString &description = QString()) override;
|
const QString &description = QString()) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QSharedPointer<FileShareProtocolSettings> m_settings;
|
FileShareProtocolSettings m_settings;
|
||||||
FileShareProtocolSettingsPage *m_settingsPage;
|
FileShareProtocolSettingsPage *m_settingsPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -28,93 +28,76 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/temporarydirectory.h>
|
#include <utils/temporarydirectory.h>
|
||||||
|
|
||||||
#include <QSettings>
|
using namespace Utils;
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
static const char settingsGroupC[] = "FileSharePasterSettings";
|
|
||||||
static const char pathKeyC[] = "Path";
|
|
||||||
static const char displayCountKeyC[] = "DisplayCount";
|
|
||||||
|
|
||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
FileShareProtocolSettings::FileShareProtocolSettings() :
|
FileShareProtocolSettings::FileShareProtocolSettings()
|
||||||
path(Utils::TemporaryDirectory::masterDirectoryPath()), displayCount(10)
|
|
||||||
{
|
{
|
||||||
|
setSettingsGroup("FileSharePasterSettings");
|
||||||
|
setAutoApply(false);
|
||||||
|
|
||||||
|
registerAspect(&path);
|
||||||
|
path.setSettingsKey("Path");
|
||||||
|
path.setDisplayStyle(StringAspect::PathChooserDisplay);
|
||||||
|
path.setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
|
path.setDefaultValue(TemporaryDirectory::masterDirectoryPath());
|
||||||
|
path.setLabelText(tr("&Path:"));
|
||||||
|
|
||||||
|
registerAspect(&displayCount);
|
||||||
|
displayCount.setSettingsKey("DisplayCount");
|
||||||
|
displayCount.setDefaultValue(10);
|
||||||
|
displayCount.setSuffix(' ' + tr("entries"));
|
||||||
|
displayCount.setLabelText(tr("&Display:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileShareProtocolSettings::toSettings(QSettings *s) const
|
// Settings page
|
||||||
|
|
||||||
|
class FileShareProtocolSettingsWidget final : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
s->beginGroup(QLatin1String(settingsGroupC));
|
public:
|
||||||
s->setValue(QLatin1String(pathKeyC), path);
|
FileShareProtocolSettingsWidget(FileShareProtocolSettings *settings)
|
||||||
s->setValue(QLatin1String(displayCountKeyC), displayCount);
|
: m_settings(settings)
|
||||||
s->endGroup();
|
{
|
||||||
}
|
FileShareProtocolSettings &s = *settings;
|
||||||
|
using namespace Layouting;
|
||||||
|
|
||||||
void FileShareProtocolSettings::fromSettings(const QSettings *s)
|
auto label = new QLabel(tr("The fileshare-based paster protocol allows for sharing code"
|
||||||
{
|
"snippets using simple files on a shared network drive. "
|
||||||
FileShareProtocolSettings defaultValues;
|
"Files are never deleted."));
|
||||||
const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
|
label->setWordWrap(true);
|
||||||
path = s->value(keyRoot + QLatin1String(pathKeyC), defaultValues.path).toString();
|
|
||||||
displayCount = s->value(keyRoot + QLatin1String(displayCountKeyC), defaultValues.displayCount).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileShareProtocolSettings::equals(const FileShareProtocolSettings &rhs) const
|
Column {
|
||||||
{
|
Form {
|
||||||
return displayCount == rhs.displayCount && path == rhs.path;
|
label, Break(),
|
||||||
}
|
s.path,
|
||||||
|
s.displayCount
|
||||||
|
},
|
||||||
|
Stretch()
|
||||||
|
}.attachTo(this);
|
||||||
|
}
|
||||||
|
|
||||||
FileShareProtocolSettingsWidget::FileShareProtocolSettingsWidget()
|
void apply() final
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
if (m_settings->isDirty()) {
|
||||||
|
m_settings->apply();
|
||||||
|
m_settings->writeSettings(Core::ICore::settings());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add a space in front of the suffix
|
private:
|
||||||
QString suffix = m_ui.displayCountSpinBox->suffix();
|
FileShareProtocolSettings *m_settings;
|
||||||
suffix.prepend(QLatin1Char(' '));
|
};
|
||||||
m_ui.displayCountSpinBox->setSuffix(suffix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileShareProtocolSettingsWidget::setSettings(const FileShareProtocolSettings &s)
|
FileShareProtocolSettingsPage::FileShareProtocolSettingsPage(FileShareProtocolSettings *s)
|
||||||
{
|
|
||||||
m_ui.pathChooser->setPath(s.path);
|
|
||||||
m_ui.displayCountSpinBox->setValue(s.displayCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileShareProtocolSettings FileShareProtocolSettingsWidget::settings() const
|
|
||||||
{
|
|
||||||
FileShareProtocolSettings rc;
|
|
||||||
rc.path = m_ui.pathChooser->filePath().toString();
|
|
||||||
rc.displayCount = m_ui.displayCountSpinBox->value();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------FileShareProtocolSettingsPage
|
|
||||||
FileShareProtocolSettingsPage::FileShareProtocolSettingsPage(const QSharedPointer<FileShareProtocolSettings> &s)
|
|
||||||
: m_settings(s), m_widget(nullptr)
|
|
||||||
{
|
{
|
||||||
setId("X.CodePaster.FileSharePaster");
|
setId("X.CodePaster.FileSharePaster");
|
||||||
setDisplayName(tr("Fileshare"));
|
setDisplayName(FileShareProtocolSettingsWidget::tr("Fileshare"));
|
||||||
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
||||||
|
setWidgetCreator([s] { return new FileShareProtocolSettingsWidget(s); });
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *FileShareProtocolSettingsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
m_widget = new FileShareProtocolSettingsWidget;
|
|
||||||
m_widget->setSettings(*m_settings);
|
|
||||||
}
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileShareProtocolSettingsPage::apply()
|
|
||||||
{
|
|
||||||
if (!m_widget) // page was never shown
|
|
||||||
return;
|
|
||||||
const FileShareProtocolSettings newSettings = m_widget->settings();
|
|
||||||
if (newSettings != *m_settings) {
|
|
||||||
*m_settings = newSettings;
|
|
||||||
m_settings->toSettings(Core::ICore::settings());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace CodePaster
|
} // namespace CodePaster
|
||||||
|
@@ -26,61 +26,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include "ui_fileshareprotocolsettingswidget.h"
|
|
||||||
|
|
||||||
#include <QSharedPointer>
|
#include <utils/aspects.h>
|
||||||
#include <QPointer>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QSettings;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
class FileShareProtocolSettings {
|
class FileShareProtocolSettings : public Utils::AspectContainer
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(CodePaster::FileShareProtocolSettings)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileShareProtocolSettings();
|
FileShareProtocolSettings();
|
||||||
void toSettings(QSettings *) const;
|
|
||||||
void fromSettings(const QSettings *);
|
|
||||||
bool equals(const FileShareProtocolSettings &rhs) const;
|
|
||||||
|
|
||||||
QString path;
|
Utils::StringAspect path;
|
||||||
int displayCount;
|
Utils::IntegerAspect displayCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const FileShareProtocolSettings &s1, const FileShareProtocolSettings &s2)
|
class FileShareProtocolSettingsPage final : public Core::IOptionsPage
|
||||||
{ return s1.equals(s2); }
|
|
||||||
inline bool operator!=(const FileShareProtocolSettings &s1, const FileShareProtocolSettings &s2)
|
|
||||||
{ return !s1.equals(s2); }
|
|
||||||
|
|
||||||
class FileShareProtocolSettingsWidget : public QWidget
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileShareProtocolSettingsWidget();
|
explicit FileShareProtocolSettingsPage(FileShareProtocolSettings *s);
|
||||||
|
|
||||||
void setSettings(const FileShareProtocolSettings &);
|
|
||||||
FileShareProtocolSettings settings() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Internal::Ui::FileShareProtocolSettingsWidget m_ui;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileShareProtocolSettingsPage : public Core::IOptionsPage
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit FileShareProtocolSettingsPage(const QSharedPointer<FileShareProtocolSettings> &s);
|
|
||||||
|
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const QSharedPointer<FileShareProtocolSettings> m_settings;
|
|
||||||
QPointer<FileShareProtocolSettingsWidget> m_widget;
|
|
||||||
};
|
|
||||||
} // namespace CodePaster
|
} // namespace CodePaster
|
||||||
|
@@ -1,101 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>CodePaster::Internal::FileShareProtocolSettingsWidget</class>
|
|
||||||
<widget class="QWidget" name="CodePaster::Internal::FileShareProtocolSettingsWidget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>438</width>
|
|
||||||
<height>101</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<property name="fieldGrowthPolicy">
|
|
||||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QLabel" name="helpLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>The fileshare-based paster protocol allows for sharing code snippets using simple files on a shared network drive. Files are never deleted.</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>3</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="pathLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Path:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>pathChooser</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="Utils::PathChooser" name="pathChooser" native="true"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="displayCountLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Display:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>displayCountSpinBox</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QSpinBox" name="displayCountSpinBox">
|
|
||||||
<property name="suffix">
|
|
||||||
<string>entries</string>
|
|
||||||
</property>
|
|
||||||
<property name="minimum">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>100</number>
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<number>11</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>Utils::PathChooser</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header location="global">utils/pathchooser.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
<slots>
|
|
||||||
<signal>editingFinished()</signal>
|
|
||||||
<signal>browsingFinished()</signal>
|
|
||||||
</slots>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
Reference in New Issue
Block a user