forked from qt-creator/qt-creator
CodePaster: Clean up configuration checks.
Point user to settings if something goes wrong.
This commit is contained in:
@@ -15,7 +15,9 @@ HEADERS += cpasterplugin.h \
|
|||||||
pastebindotcaprotocol.h \
|
pastebindotcaprotocol.h \
|
||||||
settings.h \
|
settings.h \
|
||||||
pasteselectdialog.h \
|
pasteselectdialog.h \
|
||||||
columnindicatortextedit.h
|
columnindicatortextedit.h \
|
||||||
|
fileshareprotocol.h \
|
||||||
|
fileshareprotocolsettingspage.h
|
||||||
SOURCES += cpasterplugin.cpp \
|
SOURCES += cpasterplugin.cpp \
|
||||||
settingspage.cpp \
|
settingspage.cpp \
|
||||||
protocol.cpp \
|
protocol.cpp \
|
||||||
@@ -27,9 +29,12 @@ SOURCES += cpasterplugin.cpp \
|
|||||||
pastebindotcaprotocol.cpp \
|
pastebindotcaprotocol.cpp \
|
||||||
settings.cpp \
|
settings.cpp \
|
||||||
pasteselectdialog.cpp \
|
pasteselectdialog.cpp \
|
||||||
columnindicatortextedit.cpp
|
columnindicatortextedit.cpp \
|
||||||
|
fileshareprotocol.cpp \
|
||||||
|
fileshareprotocolsettingspage.cpp
|
||||||
FORMS += settingspage.ui \
|
FORMS += settingspage.ui \
|
||||||
pasteselect.ui \
|
pasteselect.ui \
|
||||||
pasteview.ui \
|
pasteview.ui \
|
||||||
pastebindotcomsettings.ui
|
pastebindotcomsettings.ui \
|
||||||
|
fileshareprotocolsettingswidget.ui
|
||||||
include(../../shared/cpaster/cpaster.pri)
|
include(../../shared/cpaster/cpaster.pri)
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "codepasterprotocol.h"
|
#include "codepasterprotocol.h"
|
||||||
#include "pastebindotcomprotocol.h"
|
#include "pastebindotcomprotocol.h"
|
||||||
#include "pastebindotcaprotocol.h"
|
#include "pastebindotcaprotocol.h"
|
||||||
|
#include "fileshareprotocol.h"
|
||||||
#include "pasteselectdialog.h"
|
#include "pasteselectdialog.h"
|
||||||
#include "settingspage.h"
|
#include "settingspage.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
@@ -94,7 +95,8 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *error_m
|
|||||||
const QSharedPointer<NetworkAccessManagerProxy> networkAccessMgrProxy(new NetworkAccessManagerProxy);
|
const QSharedPointer<NetworkAccessManagerProxy> networkAccessMgrProxy(new NetworkAccessManagerProxy);
|
||||||
Protocol *protos[] = { new PasteBinDotComProtocol(networkAccessMgrProxy),
|
Protocol *protos[] = { new PasteBinDotComProtocol(networkAccessMgrProxy),
|
||||||
new PasteBinDotCaProtocol(networkAccessMgrProxy),
|
new PasteBinDotCaProtocol(networkAccessMgrProxy),
|
||||||
new CodePasterProtocol(networkAccessMgrProxy)
|
new CodePasterProtocol(networkAccessMgrProxy),
|
||||||
|
new FileShareProtocol
|
||||||
};
|
};
|
||||||
const int count = sizeof(protos) / sizeof(Protocol *);
|
const int count = sizeof(protos) / sizeof(Protocol *);
|
||||||
for(int i = 0; i < count; ++i) {
|
for(int i = 0; i < count; ++i) {
|
||||||
@@ -221,6 +223,7 @@ void CodepasterPlugin::post(QString data, const QString &mimeType)
|
|||||||
foreach(Protocol *protocol, m_protocols) {
|
foreach(Protocol *protocol, m_protocols) {
|
||||||
if (protocol->name() == protocolName) {
|
if (protocol->name() == protocolName) {
|
||||||
const Protocol::ContentType ct = Protocol::contentType(mimeType);
|
const Protocol::ContentType ct = Protocol::contentType(mimeType);
|
||||||
|
if (Protocol::ensureConfiguration(protocol))
|
||||||
protocol->paste(data, ct, username, comment, description);
|
protocol->paste(data, ct, username, comment, description);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -237,7 +240,9 @@ void CodepasterPlugin::fetch()
|
|||||||
const QString pasteID = dialog.pasteId();
|
const QString pasteID = dialog.pasteId();
|
||||||
if (pasteID.isEmpty())
|
if (pasteID.isEmpty())
|
||||||
return;
|
return;
|
||||||
m_protocols[dialog.protocolIndex()]->fetch(pasteID);
|
Protocol *protocol = m_protocols[dialog.protocolIndex()];
|
||||||
|
if (Protocol::ensureConfiguration(protocol))
|
||||||
|
protocol->fetch(pasteID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodepasterPlugin::finishPost(const QString &link)
|
void CodepasterPlugin::finishPost(const QString &link)
|
||||||
|
@@ -320,7 +320,7 @@ void PasteBinDotComProtocol::listFinished()
|
|||||||
m_listReply = 0;
|
m_listReply = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IOptionsPage *PasteBinDotComProtocol::settingsPage()
|
Core::IOptionsPage *PasteBinDotComProtocol::settingsPage() const
|
||||||
{
|
{
|
||||||
return m_settings;
|
return m_settings;
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ public:
|
|||||||
|
|
||||||
virtual unsigned capabilities() const;
|
virtual unsigned capabilities() const;
|
||||||
bool hasSettings() const { return true; }
|
bool hasSettings() const { return true; }
|
||||||
Core::IOptionsPage *settingsPage();
|
Core::IOptionsPage *settingsPage() const;
|
||||||
|
|
||||||
virtual void fetch(const QString &id);
|
virtual void fetch(const QString &id);
|
||||||
virtual void paste(const QString &text,
|
virtual void paste(const QString &text,
|
||||||
|
@@ -114,11 +114,14 @@ void PasteSelectDialog::list()
|
|||||||
{
|
{
|
||||||
const int index = protocolIndex();
|
const int index = protocolIndex();
|
||||||
|
|
||||||
QTC_ASSERT((m_protocols.at(index)->capabilities() & Protocol::ListCapability), return);
|
Protocol *protocol = m_protocols[index];
|
||||||
|
QTC_ASSERT((protocol->capabilities() & Protocol::ListCapability), return);
|
||||||
|
|
||||||
m_ui.listWidget->clear();
|
m_ui.listWidget->clear();
|
||||||
|
if (Protocol::ensureConfiguration(protocol, this)) {
|
||||||
m_ui.listWidget->addItem(new QListWidgetItem(tr("Waiting for items")));
|
m_ui.listWidget->addItem(new QListWidgetItem(tr("Waiting for items")));
|
||||||
m_protocols[index]->list();
|
protocol->list();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PasteSelectDialog::protocolChanged(int i)
|
void PasteSelectDialog::protocolChanged(int i)
|
||||||
|
@@ -30,11 +30,16 @@
|
|||||||
|
|
||||||
#include <cpptools/cpptoolsconstants.h>
|
#include <cpptools/cpptoolsconstants.h>
|
||||||
#include <qmljseditor/qmljseditorconstants.h>
|
#include <qmljseditor/qmljseditorconstants.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
#include <QtNetwork/QNetworkRequest>
|
#include <QtNetwork/QNetworkRequest>
|
||||||
|
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
#include <QtGui/QMainWindow>
|
||||||
|
#include <QtGui/QPushButton>
|
||||||
|
|
||||||
namespace CodePaster {
|
namespace CodePaster {
|
||||||
|
|
||||||
@@ -47,22 +52,17 @@ Protocol::~Protocol()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Protocol::canFetch() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Protocol::canPost() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Protocol::hasSettings() const
|
bool Protocol::hasSettings() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IOptionsPage *Protocol::settingsPage()
|
bool Protocol::checkConfiguration(QString *) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::IOptionsPage *Protocol::settingsPage() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -115,6 +115,46 @@ QString Protocol::textFromHtml(QString data)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Protocol::ensureConfiguration(const Protocol *p, QWidget *parent)
|
||||||
|
{
|
||||||
|
QString errorMessage;
|
||||||
|
bool ok = false;
|
||||||
|
while (true) {
|
||||||
|
if (p->checkConfiguration(&errorMessage)) {
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!showConfigurationError(p, errorMessage, parent))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Protocol::showConfigurationError(const Protocol *p,
|
||||||
|
const QString &message,
|
||||||
|
QWidget *parent,
|
||||||
|
bool showConfig)
|
||||||
|
{
|
||||||
|
if (!p->settingsPage())
|
||||||
|
showConfig = false;
|
||||||
|
|
||||||
|
if (!parent)
|
||||||
|
parent = Core::ICore::instance()->mainWindow();
|
||||||
|
const QString title = tr("%1 - Configuration Error").arg(p->name());
|
||||||
|
QMessageBox mb(QMessageBox::Warning, title, message, QMessageBox::Cancel, parent);
|
||||||
|
QPushButton *settingsButton = 0;
|
||||||
|
if (showConfig)
|
||||||
|
settingsButton = mb.addButton(tr("Settings..."), QMessageBox::AcceptRole);
|
||||||
|
mb.exec();
|
||||||
|
bool rc = false;
|
||||||
|
if (mb.clickedButton() == settingsButton)
|
||||||
|
rc = Core::ICore::instance()->showOptionsDialog(p->settingsPage()->category(),
|
||||||
|
p->settingsPage()->id(),
|
||||||
|
parent);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------ NetworkAccessManagerProxy
|
// ------------ NetworkAccessManagerProxy
|
||||||
NetworkAccessManagerProxy::NetworkAccessManagerProxy()
|
NetworkAccessManagerProxy::NetworkAccessManagerProxy()
|
||||||
{
|
{
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class QWidget;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -62,14 +63,11 @@ public:
|
|||||||
|
|
||||||
virtual QString name() const = 0;
|
virtual QString name() const = 0;
|
||||||
|
|
||||||
bool canFetch() const;
|
|
||||||
bool canPost() const;
|
|
||||||
|
|
||||||
|
|
||||||
virtual unsigned capabilities() const = 0;
|
virtual unsigned capabilities() const = 0;
|
||||||
virtual bool hasSettings() const;
|
virtual bool hasSettings() const;
|
||||||
virtual Core::IOptionsPage *settingsPage();
|
virtual Core::IOptionsPage *settingsPage() const;
|
||||||
|
|
||||||
|
virtual bool checkConfiguration(QString *errorMessage = 0) const;
|
||||||
virtual void fetch(const QString &id) = 0;
|
virtual void fetch(const QString &id) = 0;
|
||||||
virtual void list();
|
virtual void list();
|
||||||
virtual void paste(const QString &text,
|
virtual void paste(const QString &text,
|
||||||
@@ -81,6 +79,16 @@ public:
|
|||||||
// Convenience to determine content type from mime type
|
// Convenience to determine content type from mime type
|
||||||
static ContentType contentType(const QString &mimeType);
|
static ContentType contentType(const QString &mimeType);
|
||||||
|
|
||||||
|
// Show a configuration error and point user to settings.
|
||||||
|
// Return true when settings changed.
|
||||||
|
static bool showConfigurationError(const Protocol *p,
|
||||||
|
const QString &message,
|
||||||
|
QWidget *parent = 0,
|
||||||
|
bool showConfig = true);
|
||||||
|
// Ensure configuration is correct
|
||||||
|
static bool ensureConfiguration(const Protocol *p,
|
||||||
|
QWidget *parent = 0);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pasteDone(const QString &link);
|
void pasteDone(const QString &link);
|
||||||
void fetchDone(const QString &titleDescription,
|
void fetchDone(const QString &titleDescription,
|
||||||
|
Reference in New Issue
Block a user