File: requestauthdialog.cpp

package info (click to toggle)
psi-plugins 1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,368 kB
  • sloc: cpp: 42,063; xml: 714; ansic: 84; makefile: 61; sh: 12
file content (65 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
    requestAuthDialog

    Copyright (c) 2008-2009 by Alexander Kazarin <boiler@co.ru>
		  2011 by Evgeny Khryukin

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
*/

#include <QNetworkCookieJar>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include "requestauthdialog.h"
#include "options.h"

requestAuthDialog::requestAuthDialog(QWidget *parent)
	: QDialog(parent)
	, manager_(0)
{
	ui.setupUi(this);
	setFixedHeight(210);
	ui.frameCaptcha->hide();
	setFixedSize(size());
}


requestAuthDialog::~requestAuthDialog()
{
	
}

void requestAuthDialog::setCaptcha(const QList<QNetworkCookie> &cooks, const QString &url)
{
	if(!manager_) {
		manager_ = new QNetworkAccessManager(this);
		if(Options::instance()->useProxy())
			manager_->setProxy(Options::instance()->getProxy());

		connect(manager_, SIGNAL(finished(QNetworkReply*)), SLOT(reply(QNetworkReply*)));
	}
	manager_->cookieJar()->setCookiesFromUrl(cooks, url);
	manager_->get(QNetworkRequest(QUrl(url)));
}

void requestAuthDialog::reply(QNetworkReply *r)
{
	if(r->error() == QNetworkReply::NoError) {
		ui.frameCaptcha->show();
		ui.labelCaptcha->show();
		QPixmap pix = QPixmap::fromImage(QImage::fromData(r->readAll()));
		ui.webCaptcha->setPixmap(pix);
		setFixedHeight(350);
		setFixedSize(size());
	}

	r->deleteLater();
}