Ejemplo n.º 1
0
void UrlShortener::shorten(const QString &url) {
	qDebug() << "UrlShortener::shorten() " + url;

	Configuration *config = Configuration::getInstance();

	if (!enabled || config->urlShortener == "0") {
		emit urlShortened(url);
		return;
	}

	currentUrl = url;

	QUrl shortenerUrl(Services::urlShorteners[config->urlShortener]["apiurl"]);

    if (config->useProxy) {
		http->setProxy(config->proxyAddress, config->proxyPort, config->proxyUsername, config->proxyPassword);
	} else {
		http->setProxy(QNetworkProxy(QNetworkProxy::NoProxy));
	}

	if(shortenerUrl.toString().indexOf("https") == 0) {
		http->setHost(shortenerUrl.host(), QHttp::ConnectionModeHttps, shortenerUrl.port(443));
	} else {
		http->setHost(shortenerUrl.host(), QHttp::ConnectionModeHttp, shortenerUrl.port(80));
	}

	buffer.open(QIODevice::WriteOnly);
	QString request = Services::urlShorteners[config->urlShortener]["requesttemplate"];
	request.replace("%url", QUrl::toPercentEncoding(url));
	if(Services::urlShorteners[config->urlShortener]["useapikey"] == "true") {
		QString tmpapikey = config->urlShortenerAPIKey;
		if(tmpapikey == "") {
			tmpapikey = Services::urlShorteners[config->urlShortener]["defaultapikey"];
		}
		request.replace("%apikey", tmpapikey);
	}
	if(Services::urlShorteners[config->urlShortener]["useusername"] == "true") {
		QString tmpusername = config->urlShortenerUsername;
		if(tmpusername == "") {
			tmpusername = Services::urlShorteners[config->urlShortener]["defaultusername"];
		}
		request.replace("%username", tmpusername);
	}
	requestId = http->get(shortenerUrl.path() + request, &buffer);
}
Ejemplo n.º 2
0
void UrlShortener::requestFinished(int id, bool error) {
	if (id == requestId) {
		QString shortenedUrl = currentUrl;
		if (!error && (http->lastResponse().statusCode() == 200)) {
			qDebug() << ("UrlShortener::requestFinished() " + QString::number(id) + " " + currentUrl);
			Configuration *config = Configuration::getInstance();
			QString response = buffer.data();
			response.replace("\\/", "/");
			QRegExp responseRegexp(Services::urlShorteners[config->urlShortener]["responseregexp"]);
			if (responseRegexp.indexIn(response, 0) == -1) {
                qWarning() << ("UrlShortener::requestFinished() error parsing request");
			} else {
				shortenedUrl = responseRegexp.cap(0);
			}
		} else {
            qWarning() << ("UrlShortener::requestFinished() " + QString::number(id) + " error " + QString::number(http->lastResponse().statusCode()) + " " + http->lastResponse().reasonPhrase());
		}
		emit urlShortened(shortenedUrl);
	}
}
Ejemplo n.º 3
0
Qtwitter::Qtwitter( QWidget *parent ) : MainWindow( parent )
{
  connect( this, SIGNAL(switchModel(QString)), SLOT(setCurrentModel(QString)) );
  connect( this, SIGNAL(switchToPublicTimelineModel()), SLOT(setPublicTimelineModel()) );

  core = new Core( this );
  connect( this, SIGNAL(updateTweets()), core, SLOT(forceGet()) );
  connect( this, SIGNAL(openBrowser(QUrl)), core, SLOT(openBrowser(QUrl)) );
  connect( this, SIGNAL(post(QString,QString,int)), core, SLOT(post(QString,QString,int)) );
  connect( this, SIGNAL(resizeView(int,int)), core, SIGNAL(resizeData(int,int)));
  connect( this, SIGNAL(shortenUrl(QString)), core, SLOT(shortenUrl(QString)));
  connect( core, SIGNAL(twitterAccountsChanged(QList<TwitterAccount>,bool)), this, SLOT(setupTwitterAccounts(QList<TwitterAccount>,bool)) );
  connect( core, SIGNAL(urlShortened(QString)), this, SLOT(replaceUrl(QString)));
  connect( core, SIGNAL(about()), this, SLOT(about()) );
  connect( core, SIGNAL(addReplyString(QString,int)), this, SIGNAL(addReplyString(QString,int)) );
  connect( core, SIGNAL(addRetweetString(QString)), this, SIGNAL(addRetweetString(QString)) );
  connect( core, SIGNAL(errorMessage(QString)), this, SLOT(popupError(QString)) );
  connect( core, SIGNAL(resetUi()), this, SLOT(resetStatusEdit()) );
  connect( core, SIGNAL(requestStarted()), this, SLOT(showProgressIcon()) );
  if ( QSystemTrayIcon::supportsMessages() )
    connect( core, SIGNAL(sendNewsReport(QString)), this, SLOT(popupMessage(QString)) );

  twitpic = new TwitPicView( this );
  connect( twitpic, SIGNAL(uploadPhoto(QString,QString,QString)), core, SLOT(uploadPhoto(QString,QString,QString)) );
  connect( twitpic, SIGNAL(abortUpload()), core, SLOT(abortUploadPhoto()) );
  connect( this, SIGNAL(openTwitPicDialog()), twitpic, SLOT(show()) );
  connect( core, SIGNAL(twitPicResponseReceived()), twitpic, SLOT(resetForm()) );
  connect( core, SIGNAL(twitPicDataSendProgress(int,int)), twitpic, SLOT(showUploadProgress(int,int)) );

  settingsDialog = new Settings( this, core, twitpic, this );
  connect( this, SIGNAL(settingsDialogRequested()), settingsDialog, SLOT( show() ) );

  QSignalMapper *mapper = new QSignalMapper( this );
  mapper->setMapping( qApp, 1 );
  connect( qApp, SIGNAL(aboutToQuit()), mapper, SLOT(map()) );
  connect( mapper, SIGNAL(mapped(int)), settingsDialog, SLOT(saveConfig(int)) );
}