-
Notifications
You must be signed in to change notification settings - Fork 2
/
newfromurldialog.cpp
50 lines (38 loc) · 984 Bytes
/
newfromurldialog.cpp
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
#include "newfromurldialog.h"
#include "ui_newfromurldialog.h"
#include <QNetworkRequest>
#include <QNetworkReply>
NewFromUrlDialog::NewFromUrlDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewFromUrlDialog)
{
ui->setupUi(this);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
QRegExp re("http[s]?://.+");
ui->leUrl->setValidator(new QRegExpValidator(re, this));
connect(&m, SIGNAL(finished(QNetworkReply*)), this, SLOT(on_json_downloaded(QNetworkReply*)));
}
NewFromUrlDialog::~NewFromUrlDialog()
{
delete ui;
}
void NewFromUrlDialog::leaveEvent(QEvent *)
{
hide();
}
void NewFromUrlDialog::on_leUrl_textChanged(const QString &arg1)
{
Q_UNUSED(arg1);
ui->btGet->setEnabled(ui->leUrl->hasAcceptableInput());
}
void NewFromUrlDialog::on_btGet_clicked()
{
QNetworkRequest r(QUrl(ui->leUrl->text()));
m.get(r);
}
void NewFromUrlDialog::on_json_downloaded(QNetworkReply *r)
{
buff = QString(r->readAll());
r->deleteLater();
accept();
}