diff --git a/src/plugins/cpaster/codepasterprotocol.cpp b/src/plugins/cpaster/codepasterprotocol.cpp index f6a701594f3ded7e470341c28ada7fac4cc6fad0..7661498717d9ed0e2ee4bef79c6c8480b99b0d5a 100644 --- a/src/plugins/cpaster/codepasterprotocol.cpp +++ b/src/plugins/cpaster/codepasterprotocol.cpp @@ -62,10 +62,29 @@ bool CodePasterProtocol::canList() const return true; } +bool CodePasterProtocol::isValidHostName(const QString& hostName) +{ + if (hostName.isEmpty()) { + ICore::instance()->messageManager()->printToOutputPane( +#ifdef Q_OS_MAC + tr("No Server defined in the CodePaster preferences!"), +#else + tr("No Server defined in the CodePaster options!"), +#endif + true /*error*/); + ICore::instance()->messageManager()->showOutputPane(); + return false; + } + return true; +} + void CodePasterProtocol::fetch(const QString &id) { + QString hostName = m_page->hostName(); + if (!isValidHostName(hostName)) + return; QString link = "http://"; - link.append(m_page->hostName()); + link.append(hostName); link.append("/?format=raw&id="); link.append(id); QUrl url(link); @@ -78,9 +97,12 @@ void CodePasterProtocol::fetch(const QString &id) void CodePasterProtocol::list(QListWidget *listWidget) { + QString hostName = m_page->hostName(); + if (!isValidHostName(hostName)) + return; this->listWidget = listWidget; QString link = QLatin1String("http://"); - link += m_page->hostName(); + link += hostName; link += QLatin1String("/?command=browse&format=raw"); QUrl url(link); QNetworkRequest r(url); @@ -93,6 +115,10 @@ void CodePasterProtocol::paste(const QString &text, const QString &comment, const QString &description) { + QString hostName = m_page->hostName(); + if (!isValidHostName(hostName)) + return; + QByteArray data = "command=processcreate&submit=submit&highlight_type=0&description="; data += CGI::encodeURL(description).toLatin1(); data += "&comment="; @@ -102,7 +128,7 @@ void CodePasterProtocol::paste(const QString &text, data += "&poster="; data += CGI::encodeURL(username).toLatin1(); - http.setHost(m_page->hostName()); + http.setHost(hostName); http.post("/", data); } diff --git a/src/plugins/cpaster/codepasterprotocol.h b/src/plugins/cpaster/codepasterprotocol.h index dcf4039c30d0b02a37980de15966c5403cf9ea6f..c3f3c90a874b87652796a1dd2f940c672625e2c0 100644 --- a/src/plugins/cpaster/codepasterprotocol.h +++ b/src/plugins/cpaster/codepasterprotocol.h @@ -66,6 +66,7 @@ public slots: void readPostResponseHeader(const QHttpResponseHeader &); private: + bool isValidHostName(const QString& hostName); CodePasterSettingsPage *m_page; QHttp http; QNetworkAccessManager manager;