Skip to content
Snippets Groups Projects
Commit 6a91b63a authored by Maurice Kalinowski's avatar Maurice Kalinowski
Browse files

move editor creation to plugin

each protocol needed to create the editor on their own.
Instead emit fetchDone and let the plugin instantiate it for
every protocol
parent a46e71d0
No related branches found
No related tags found
No related merge requests found
......@@ -118,17 +118,22 @@ Core::IOptionsPage* CodePasterProtocol::settingsPage()
void CodePasterProtocol::fetchFinished()
{
if (reply->error()) {
ICore::instance()->messageManager()->printToOutputPane(reply->errorString(), true);
QString title;
QString content;
bool error = reply->error();
if (error) {
content = reply->errorString();
} else {
QString data = reply->readAll();
if (data.contains("<B>No such paste!</B>"))
ICore::instance()->messageManager()->printToOutputPane(tr("No such paste"), true);
QString title = QString::fromLatin1("Codepaster: %1").arg(fetchId);
EditorManager::instance()->newFile(Core::Constants::K_DEFAULT_TEXT_EDITOR, &title, data);
content = reply->readAll();
if (content.contains("<B>No such paste!</B>")) {
content = tr("No such paste");
error = true;
}
title = QString::fromLatin1("Codepaster: %1").arg(fetchId);
}
reply->deleteLater();
reply = 0;
emit fetchDone(title, content, error);
}
void CodePasterProtocol::listFinished()
......
......@@ -95,6 +95,8 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *error_m
0};
for(int i=0; protos[i] != 0; ++i) {
connect(protos[i], SIGNAL(pasteDone(QString)), this, SLOT(finishPost(QString)));
connect(protos[i], SIGNAL(fetchDone(QString,QString,bool)),
this, SLOT(finishFetch(QString,QString,bool)));
m_settingsPage->addProtocol(protos[i]->name());
if (protos[i]->hasSettings())
addObject(protos[i]->settingsPage());
......@@ -251,4 +253,16 @@ void CodepasterPlugin::finishPost(const QString &link)
m_settingsPage->displayOutput());
}
void CodepasterPlugin::finishFetch(const QString &titleDescription,
const QString &content,
bool error)
{
QString title = titleDescription;
if (error) {
ICore::instance()->messageManager()->printToOutputPane(content, true);
} else {
EditorManager::instance()->newFile(Core::Constants::K_DEFAULT_TEXT_EDITOR, &title, content);
}
}
Q_EXPORT_PLUGIN(CodepasterPlugin)
......@@ -64,6 +64,9 @@ public slots:
void post();
void fetch();
void finishPost(const QString &link);
void finishFetch(const QString &titleDescription,
const QString &content,
bool error);
private:
QAction *m_postAction;
......
......@@ -115,14 +115,18 @@ void PasteBinDotComProtocol::postRequestFinished(int id, bool error)
void PasteBinDotComProtocol::fetchFinished()
{
if (reply->error()) {
ICore::instance()->messageManager()->printToOutputPane(reply->errorString(), true);
QString title;
QString content;
bool error = reply->error();
if (error) {
content = reply->errorString();
} else {
QString title = QString::fromLatin1("Pastebin.com: %1").arg(fetchId);
QString data = reply->readAll();
EditorManager::instance()->newFile(Core::Constants::K_DEFAULT_TEXT_EDITOR, &title, data);
title = QString::fromLatin1("Pastebin.com: %1").arg(fetchId);
content = reply->readAll();
}
reply->deleteLater();
reply = 0;
emit fetchDone(title, content, error);
}
Core::IOptionsPage* PasteBinDotComProtocol::settingsPage()
......
......@@ -61,6 +61,9 @@ public:
signals:
void pasteDone(const QString &link);
void fetchDone(const QString &titleDescription,
const QString &content,
bool error);
};
#endif // PROTOCOL_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment