Implement download caching. Set the folder for the cache data in the configuration...
[Rockbox.git] / rbutil / rbutilqt / install.cpp
blobb1b8d638fa5a3ea5d309e6d48e39082cda0e2a8b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "install.h"
21 #include "ui_installfrm.h"
23 Install::Install(QWidget *parent) : QDialog(parent)
25 ui.setupUi(this);
27 connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setCached(bool)));
28 connect(ui.radioStable, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
29 connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
30 connect(ui.radioArchived, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
34 void Install::setCached(bool cache)
36 ui.checkBoxCache->setEnabled(!cache);
40 void Install::setProxy(QUrl proxy_url)
42 proxy = proxy_url;
43 qDebug() << "Install::setProxy" << proxy;
47 void Install::accept()
49 logger = new ProgressLoggerGui(this);
50 logger->show();
51 QString mountPoint = userSettings->value("defaults/mountpoint").toString();
52 qDebug() << "mountpoint:" << userSettings->value("defaults/mountpoint").toString();
53 // show dialog with error if mount point is wrong
54 if(!QFileInfo(mountPoint).isDir()) {
55 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
56 logger->abort();
57 return;
60 QString myversion;
61 if(ui.radioStable->isChecked()) {
62 file = QString("%1/rockbox-%2-%3.zip")
63 .arg(devices->value("download_url").toString(),
64 devices->value("last_release").toString(),
65 userSettings->value("defaults/platform").toString());
66 fileName = QString("rockbox-%1-%2.zip")
67 .arg(devices->value("last_release").toString(),
68 userSettings->value("defaults/platform").toString());
69 userSettings->setValue("defaults/build", "stable");
70 myversion = version.value("rel_rev");
72 else if(ui.radioArchived->isChecked()) {
73 file = QString("%1%2/rockbox-%3-%4.zip")
74 .arg(devices->value("daily_url").toString(),
75 userSettings->value("defaults/platform").toString(),
76 userSettings->value("defaults/platform").toString(),
77 version.value("arch_date"));
78 fileName = QString("rockbox-%1-%2.zip")
79 .arg(userSettings->value("defaults/platform").toString(),
80 version.value("arch_date"));
81 userSettings->setValue("defaults/build", "archived");
82 myversion = "r" + version.value("arch_rev") + "-" + version.value("arch_date");
84 else if(ui.radioCurrent->isChecked()) {
85 file = QString("%1%2/rockbox.zip")
86 .arg(devices->value("bleeding_url").toString(),
87 userSettings->value("defaults/platform").toString());
88 fileName = QString("rockbox.zip");
89 userSettings->setValue("defaults/build", "current");
90 myversion = "r" + version.value("bleed_rev");
92 else {
93 qDebug() << "no build selected -- this shouldn't happen";
94 return;
96 userSettings->sync();
98 installer = new ZipInstaller(this);
99 installer->setUrl(file);
100 installer->setProxy(proxy);
101 installer->setLogSection("rockboxbase");
102 if(!userSettings->value("defaults/cachedisable").toBool())
103 installer->setCache(userSettings->value("defaults/cachepath", QDir::tempPath()).toString());
104 installer->setLogVersion(myversion);
105 installer->setMountPoint(mountPoint);
106 installer->install(logger);
108 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
112 // Zip installer has finished
113 void Install::done(bool error)
115 qDebug() << "Install::done, error:" << error;
117 if(error)
119 logger->abort();
120 return;
123 // no error, close the window, when the logger is closed
124 connect(logger,SIGNAL(closed()),this,SLOT(close()));
129 void Install::setDetailsCurrent(bool show)
131 if(show) {
132 ui.labelDetails->setText(tr("This is the absolute up to the minute "
133 "Rockbox built. A current build will get updated every time "
134 "a change is made. Latest version is r%1 (%2).")
135 .arg(version.value("bleed_rev"), version.value("bleed_date")));
136 if(version.value("rel_rev").isEmpty())
137 ui.labelNote->setText(tr("<b>Note:</b> This option will always "
138 "download a fresh copy. "
139 "<b>This is the recommended version.</b>"));
140 else
141 ui.labelNote->setText(tr("<b>Note:</b> This option will always "
142 "download a fresh copy."));
147 void Install::setDetailsStable(bool show)
149 if(show) {
150 ui.labelDetails->setText(
151 tr("This is the last released version of Rockbox."));
153 if(!version.value("rel_rev").isEmpty())
154 ui.labelNote->setText(tr("<b>Note:</b>"
155 "The lastest released version is %1. "
156 "<b>This is the recommended version.</b>")
157 .arg(version.value("rel_rev")));
158 else ui.labelNote->setText("");
163 void Install::setDetailsArchived(bool show)
165 if(show) {
166 ui.labelDetails->setText(tr("These are automatically built each day "
167 "from the current development source code. This generally has more "
168 "features than the last release but may be much less stable. "
169 "Features may change regularly."));
170 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
171 .arg(version.value("arch_rev"), version.value("arch_date")));
176 void Install::setDeviceSettings(QSettings *dev)
178 devices = dev;
179 qDebug() << "Install::setDeviceSettings:" << devices;
183 void Install::setVersionStrings(QMap<QString, QString> ver)
185 version = ver;
186 // version strings map is as following:
187 // rel_rev release version revision id
188 // rel_date release version release date
189 // same for arch_* and bleed_*
191 if(version.value("arch_rev").isEmpty()) {
192 ui.radioArchived->setEnabled(false);
193 qDebug() << "no information about archived version available!";
196 if(!version.value("rel_rev").isEmpty()) {
197 ui.radioStable->setChecked(true);
198 ui.radioStable->setEnabled(true);
199 QFont font;
200 font.setBold(true);
201 ui.radioStable->setFont(font);
203 else {
204 ui.radioCurrent->setChecked(true);
205 ui.radioStable->setEnabled(false);
206 ui.radioStable->setChecked(false);
207 QFont font;
208 font.setBold(true);
209 ui.radioCurrent->setFont(font);
211 qDebug() << "Install::setVersionStrings" << version;
214 void Install::setUserSettings(QSettings *user)
216 userSettings = user;