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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#include "installerform.h"
#include "ui_installerform.h"
InstallerForm::InstallerForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::InstallerForm)
{
ui->setupUi(this);
setModal(true);
// setWindowModality(Qt::ApplicationModal);
ui->launchBrowser->setVisible(false);
ui->showWizard->setVisible(false);
connect(ui->launchBrowser, SIGNAL(clicked()), SLOT(authThroughBrowser()));
connect(ui->showWizard, SIGNAL(clicked()), SLOT(runGtkInstaller()));
//! @todo download to temp file name
//! @todo KIO::NetAccess::download(daemonUrl, tmpFile,this) .... and possibly uncompress?
downloadPath=QDir::toNativeSeparators(QDir::homePath().append("/daemon.tar.gz"));
if(QSysInfo::WordSize==64)
daemonUrl="http://www.dropbox.com/download?plat=lnx.x86_64";
else
daemonUrl="http://www.dropbox.com/download?plat=lnx.x86";
if(DropboxClient::isInstalled())
runConfiguration();
else
downloadDaemon();
}
InstallerForm::~InstallerForm()
{
delete request;
delete ui;
}
void InstallerForm::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
//! called twice
void InstallerForm::downloadDaemon()
{
show();
manager = new QNetworkAccessManager(this);
file.setFileName(downloadPath);
file.open(QIODevice::WriteOnly);
request = new QNetworkRequest(QUrl(daemonUrl));
request->setRawHeader("User-Agent", "Kfilebox");
reply = manager->get(*request);
connect(reply, SIGNAL(finished()), SLOT(downloadFinished()));
connect(reply, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
connect(reply,SIGNAL(downloadProgress(qint64,qint64)), SLOT(setProgressValue(qint64,qint64)));
connect(reply,SIGNAL(error(QNetworkReply::NetworkError)), SLOT(displayError(QNetworkReply::NetworkError)));
}
void InstallerForm::setProgressValue(qint64 bytesReceived, qint64 bytesTotal){
ui->progressBar->setValue(100*bytesReceived/bytesTotal);
}
void InstallerForm::processFile()
{
ui->label->setText(tr("unpacking downloaded file"));
QProcess sc;
sc.execute("tar -xf "+downloadPath+" -C "+QDir::homePath());
sc.waitForFinished();
sc.startDetached("rm -f "+ downloadPath);
runConfiguration();
}
//! Run if ~/.dropbox-dist/ installed, but computer is not linked to any account
void InstallerForm::runConfiguration()
{
dc = new DropboxClient(this);
dc->setShowAuthUrlNotification(false);
dc->hideGtkUi(true);
dc->start();
ui->launchBrowser->setVisible(true);
ui->showWizard->setVisible(true);
ui->progressBar->setVisible(false);
ui->label->setText(tr("Choose action"));
}
void InstallerForm::authThroughBrowser()
{
hide();
QDesktopServices::openUrl(dc->getAuthUrl());
dc->stop();
dc->setShowAuthUrlNotification(true);
}
void InstallerForm::runGtkInstaller()
{
dc->stop();
dc->setShowAuthUrlNotification(true);
dc->hideGtkUi(false);
dc->start();
hide();
}
void InstallerForm::downloadFinished()
{
file.close();
QVariant possible_redirect=reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (!possible_redirect.toString().isEmpty() && possible_redirect.toString()!=daemonUrl) {
daemonUrl=possible_redirect.toUrl().toString();
downloadDaemon();
} else {
reply->close();
processFile();
}
}
void InstallerForm::downloadReadyRead()
{
file.write(reply->readAll());
}
void InstallerForm::displayError(QNetworkReply::NetworkError err){
qDebug() << err << tr("Error downloading file");
}
|