Commit f6bc879d authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

CodePaster: Clean up configuration checks.

Point user to settings if something goes wrong.
parent b169ff58
......@@ -15,7 +15,9 @@ HEADERS += cpasterplugin.h \
pastebindotcaprotocol.h \
settings.h \
pasteselectdialog.h \
columnindicatortextedit.h
columnindicatortextedit.h \
fileshareprotocol.h \
fileshareprotocolsettingspage.h
SOURCES += cpasterplugin.cpp \
settingspage.cpp \
protocol.cpp \
......@@ -27,9 +29,12 @@ SOURCES += cpasterplugin.cpp \
pastebindotcaprotocol.cpp \
settings.cpp \
pasteselectdialog.cpp \
columnindicatortextedit.cpp
columnindicatortextedit.cpp \
fileshareprotocol.cpp \
fileshareprotocolsettingspage.cpp
FORMS += settingspage.ui \
pasteselect.ui \
pasteview.ui \
pastebindotcomsettings.ui
pastebindotcomsettings.ui \
fileshareprotocolsettingswidget.ui
include(../../shared/cpaster/cpaster.pri)
......@@ -34,6 +34,7 @@
#include "codepasterprotocol.h"
#include "pastebindotcomprotocol.h"
#include "pastebindotcaprotocol.h"
#include "fileshareprotocol.h"
#include "pasteselectdialog.h"
#include "settingspage.h"
#include "settings.h"
......@@ -94,7 +95,8 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *error_m
const QSharedPointer<NetworkAccessManagerProxy> networkAccessMgrProxy(new NetworkAccessManagerProxy);
Protocol *protos[] = { new PasteBinDotComProtocol(networkAccessMgrProxy),
new PasteBinDotCaProtocol(networkAccessMgrProxy),
new CodePasterProtocol(networkAccessMgrProxy)
new CodePasterProtocol(networkAccessMgrProxy),
new FileShareProtocol
};
const int count = sizeof(protos) / sizeof(Protocol *);
for(int i = 0; i < count; ++i) {
......@@ -221,7 +223,8 @@ void CodepasterPlugin::post(QString data, const QString &mimeType)
foreach(Protocol *protocol, m_protocols) {
if (protocol->name() == protocolName) {
const Protocol::ContentType ct = Protocol::contentType(mimeType);
protocol->paste(data, ct, username, comment, description);
if (Protocol::ensureConfiguration(protocol))
protocol->paste(data, ct, username, comment, description);
break;
}
}
......@@ -237,7 +240,9 @@ void CodepasterPlugin::fetch()
const QString pasteID = dialog.pasteId();
if (pasteID.isEmpty())
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)
......
......@@ -320,7 +320,7 @@ void PasteBinDotComProtocol::listFinished()
m_listReply = 0;
}
Core::IOptionsPage *PasteBinDotComProtocol::settingsPage()
Core::IOptionsPage *PasteBinDotComProtocol::settingsPage() const
{
return m_settings;
}
......
......@@ -46,7 +46,7 @@ public:
virtual unsigned capabilities() const;
bool hasSettings() const { return true; }
Core::IOptionsPage *settingsPage();
Core::IOptionsPage *settingsPage() const;
virtual void fetch(const QString &id);
virtual void paste(const QString &text,
......
......@@ -114,11 +114,14 @@ void PasteSelectDialog::list()
{
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->addItem(new QListWidgetItem(tr("Waiting for items")));
m_protocols[index]->list();
if (Protocol::ensureConfiguration(protocol, this)) {
m_ui.listWidget->addItem(new QListWidgetItem(tr("Waiting for items")));
protocol->list();
}
}
void PasteSelectDialog::protocolChanged(int i)
......
......@@ -30,11 +30,16 @@
#include <cpptools/cpptoolsconstants.h>
#include <qmljseditor/qmljseditorconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtCore/QUrl>
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
namespace CodePaster {
......@@ -47,22 +52,17 @@ Protocol::~Protocol()
{
}
bool Protocol::canFetch() const
bool Protocol::hasSettings() const
{
return true;
return false;
}
bool Protocol::canPost() const
bool Protocol::checkConfiguration(QString *) const
{
return true;
}
bool Protocol::hasSettings() const
{
return false;
}
Core::IOptionsPage *Protocol::settingsPage()
Core::IOptionsPage *Protocol::settingsPage() const
{
return 0;
}
......@@ -115,6 +115,46 @@ QString Protocol::textFromHtml(QString 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()
{
......
......@@ -37,6 +37,7 @@
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class QNetworkReply;
class QWidget;
QT_END_NAMESPACE
namespace Core {
......@@ -62,14 +63,11 @@ public:
virtual QString name() const = 0;
bool canFetch() const;
bool canPost() const;
virtual unsigned capabilities() const = 0;
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 list();
virtual void paste(const QString &text,
......@@ -81,6 +79,16 @@ public:
// Convenience to determine content type from mime type
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:
void pasteDone(const QString &link);
void fetchDone(const QString &titleDescription,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment