-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuckoo.cpp
More file actions
104 lines (90 loc) · 2.62 KB
/
cuckoo.cpp
File metadata and controls
104 lines (90 loc) · 2.62 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <QMessageBox>
#include <QFileDialog>
#include <QtNetwork/QtNetwork>
#include <QUrl>
#include <cstdlib>
#include <string>
#include "cuckoo.h"
#include "ui_cuckoo.h"
Cuckoo::Cuckoo(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Cuckoo), _file(""), _username(""), _password(""), _connectionStatus(""),
_consumerKey("A1UK5a0ZDRmQ1YIQTq58eA"), _consumerSecret("2eeFnhWzYNYOp0ync3U3oQxHFo3xm5N2izrz1b2I3bg"),
_started(false), _ready(false)
{
ui->setupUi(this);
ui->timeLeft->setTime(ui->timeBetween->time());
QNetworkAccessManager* _nam = new QNetworkAccessManager(this);
}
Cuckoo::~Cuckoo()
{
delete ui;
delete _nam;
}
void Cuckoo::checkReady()
{
if(!ui->twitterUsername->text().isEmpty() && !ui->twitterUsername->text().isEmpty())
{
_ready = true;
connectTwitter();
}
else
_ready = false;
}
void Cuckoo::connectTwitter()
{
requestToken();
}
void Cuckoo::requestToken()
{
QDateTime date;
uint timestamp = date.toTime_t();
QString timestampStr;
timestampStr.setNum(timestamp);
QByteArray data = QByteArray("POST") + "&" +
QUrl::toPercentEncoding("http://api.twitter.com/oauth/request_token") + "&" +
"oauth_callback" + "%3D" +
QUrl::toPercentEncoding("http://localhost:3005/the_dance/process_callback?service_provider_id=11") + "%26" +
"oauth_consumer_key" + "%3D" +
QUrl::toPercentEncoding(_consumerKey) + "%26" +
"oauth_nonce" + "%3D" +
QUrl::toPercentEncoding(_file.toAscii().toBase64()) + "%26" +
"oauth_signature_method" + "%3D" +
QUrl::toPercentEncoding("HMAC-SHA1") + "%26" +
"oauth_timestamp" + "%3D" +
QUrl::toPercentEncoding(timestampStr) + "%26" +
"oauth_version" + "%3D" +
QUrl::toPercentEncoding("1.0");
}
void Cuckoo::on_actionQuit_triggered()
{
QCoreApplication::quit();
}
void Cuckoo::on_actionAuthor_triggered()
{
QMessageBox::information(this, "About author", "Coded by : Hugo Laliberté");
}
void Cuckoo::on_actionQt_triggered()
{
QMessageBox::aboutQt(this);
}
void Cuckoo::on_browseFilesButton_clicked()
{
_file = QFileDialog::getOpenFileName(this, "Choose file", "", "Text files (*.txt)");
ui->tweetFile->setText(_file);
checkReady();
}
void Cuckoo::on_timeBetween_dateTimeChanged()
{
ui->timeLeft->setTime(ui->timeBetween->time());
}
void Cuckoo::on_twitterUsername_textChanged(const QString & text )
{
_username = text;
checkReady();
}
void Cuckoo::on_twitterPassword_textChanged(const QString & text )
{
_password = text;
checkReady();
}