Use the new progressbar value slot instead of wrapping around it.
[Rockbox.git] / rbutil / rbutilqt / install.cpp
blobdbdd2d4820a1a0ba63ab12ddb607958a0e0d73c9
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"
22 #include "rbzip.h"
23 #include "utils.h"
25 Install::Install(RbSettings *sett,QWidget *parent) : QDialog(parent)
27 settings = sett;
28 ui.setupUi(this);
30 connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setCached(bool)));
31 connect(ui.radioStable, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
32 connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
33 connect(ui.radioArchived, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
34 connect(ui.changeBackup,SIGNAL(pressed()),this,SLOT(changeBackupPath()));
35 connect(ui.backup,SIGNAL(stateChanged(int)),this,SLOT(backupCheckboxChanged(int)));
37 //! check if rockbox is already installed
38 QString version = installedVersion(settings->mountpoint());
40 if(version != "")
42 ui.Backupgroup->show();
43 m_backupName = settings->mountpoint();
44 if(!m_backupName.endsWith("/")) m_backupName += "/";
45 m_backupName += ".backup/rockbox-backup-"+version+".zip";
46 ui.backupLocation->setText(QDir::toNativeSeparators(fontMetrics().elidedText(m_backupName,Qt::ElideMiddle,200)));
48 else
50 ui.Backupgroup->hide();
52 backupCheckboxChanged(Qt::Unchecked);
55 void Install::backupCheckboxChanged(int state)
57 if(state == Qt::Checked)
59 ui.backupLabel->show();
60 ui.backupLocation->show();
61 ui.changeBackup->show();
63 else
65 ui.backupLabel->hide();
66 ui.backupLocation->hide();
67 ui.changeBackup->hide();
72 void Install::setCached(bool cache)
74 ui.checkBoxCache->setEnabled(!cache);
78 void Install::accept()
80 logger = new ProgressLoggerGui(this);
81 logger->show();
82 QString mountPoint = settings->mountpoint();
83 qDebug() << "mountpoint:" << settings->mountpoint();
84 // show dialog with error if mount point is wrong
85 if(!QFileInfo(mountPoint).isDir()) {
86 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
87 logger->abort();
88 return;
91 QString myversion;
92 QString buildname = settings->curPlatformName();
93 if(ui.radioStable->isChecked()) {
94 file = QString("%1/rockbox-%2-%3.zip")
95 .arg(settings->downloadUrl(),
96 settings->lastRelease(), buildname);
97 fileName = QString("rockbox-%1-%2.zip")
98 .arg(settings->lastRelease(), buildname);
99 settings->setBuild("stable");
100 myversion = version.value("rel_rev");
102 else if(ui.radioArchived->isChecked()) {
103 file = QString("%1%2/rockbox-%3-%4.zip")
104 .arg(settings->dailyUrl(),
105 buildname, buildname, version.value("arch_date"));
106 fileName = QString("rockbox-%1-%2.zip")
107 .arg(buildname, version.value("arch_date"));
108 settings->setBuild("archived");
109 myversion = "r" + version.value("arch_rev") + "-" + version.value("arch_date");
111 else if(ui.radioCurrent->isChecked()) {
112 file = QString("%1%2/rockbox.zip")
113 .arg(settings->bleedingUrl(), buildname);
114 fileName = QString("rockbox.zip");
115 settings->setBuild("current");
116 myversion = "r" + version.value("bleed_rev");
118 else {
119 qDebug() << "no build selected -- this shouldn't happen";
120 return;
122 settings->sync();
124 //! check if we should backup
125 if(ui.backup->isChecked())
127 logger->addItem(tr("Beginning Backup..."),LOGINFO);
129 //! create dir, if it doesnt exist
130 QFileInfo backupFile(m_backupName);
131 if(!QDir(backupFile.path()).exists())
133 QDir a;
134 a.mkpath(backupFile.path());
137 //! create backup
138 RbZip backup;
139 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
140 if(backup.createZip(m_backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
142 logger->addItem(tr("Backup successfull"),LOGOK);
144 else
146 logger->addItem(tr("Backup failed!"),LOGERROR);
147 logger->abort();
148 return;
152 //! install build
153 installer = new ZipInstaller(this);
154 installer->setUrl(file);
155 installer->setLogSection("Rockbox (Base)");
156 if(!settings->cacheDisabled()
157 && !ui.radioCurrent->isChecked()
158 && !ui.checkBoxCache->isChecked())
160 installer->setCache(true);
162 installer->setLogVersion(myversion);
163 installer->setMountPoint(mountPoint);
165 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
167 installer->install(logger);
171 void Install::changeBackupPath()
173 QString backupString = QFileDialog::getSaveFileName(this,"Select Backup Filename",m_backupName, "*.zip");
174 // only update if a filename was entered, ignore if cancelled
175 if(!backupString.isEmpty()) {
176 ui.backupLocation->setText(QDir::toNativeSeparators(fontMetrics().elidedText(backupString,Qt::ElideMiddle,200)));
177 m_backupName = backupString;
182 // Zip installer has finished
183 void Install::done(bool error)
185 qDebug() << "Install::done, error:" << error;
187 if(error)
189 logger->abort();
190 return;
193 // no error, close the window, when the logger is closed
194 connect(logger,SIGNAL(closed()),this,SLOT(close()));
195 // add platform info to log file for later detection
196 QSettings installlog(settings->mountpoint()
197 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
198 installlog.setValue("platform", settings->curPlatform());
199 installlog.sync();
203 void Install::setDetailsCurrent(bool show)
205 if(show) {
206 ui.labelDetails->setText(tr("This is the absolute up to the minute "
207 "Rockbox built. A current build will get updated every time "
208 "a change is made. Latest version is r%1 (%2).")
209 .arg(version.value("bleed_rev"), version.value("bleed_date")));
210 if(version.value("rel_rev").isEmpty())
211 ui.labelNote->setText(tr("<b>Note:</b> This option will always "
212 "download a fresh copy. "
213 "<b>This is the recommended version.</b>"));
214 else
215 ui.labelNote->setText(tr("<b>Note:</b> This option will always "
216 "download a fresh copy."));
221 void Install::setDetailsStable(bool show)
223 if(show) {
224 ui.labelDetails->setText(
225 tr("This is the last released version of Rockbox."));
227 if(!version.value("rel_rev").isEmpty())
228 ui.labelNote->setText(tr("<b>Note:</b>"
229 "The lastest released version is %1. "
230 "<b>This is the recommended version.</b>")
231 .arg(version.value("rel_rev")));
232 else ui.labelNote->setText("");
237 void Install::setDetailsArchived(bool show)
239 if(show) {
240 ui.labelDetails->setText(tr("These are automatically built each day "
241 "from the current development source code. This generally has more "
242 "features than the last stable release but may be much less stable. "
243 "Features may change regularly."));
244 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
245 .arg(version.value("arch_rev"), version.value("arch_date")));
251 void Install::setVersionStrings(QMap<QString, QString> ver)
253 version = ver;
254 // version strings map is as following:
255 // rel_rev release version revision id
256 // rel_date release version release date
257 // same for arch_* and bleed_*
259 if(version.value("arch_rev").isEmpty()) {
260 ui.radioArchived->setEnabled(false);
261 qDebug() << "no information about archived version available!";
264 if(!version.value("rel_rev").isEmpty()) {
265 ui.radioStable->setChecked(true);
266 ui.radioStable->setEnabled(true);
267 QFont font;
268 font.setBold(true);
269 ui.radioStable->setFont(font);
271 else {
272 ui.radioCurrent->setChecked(true);
273 ui.radioStable->setEnabled(false);
274 ui.radioStable->setChecked(false);
275 QFont font;
276 font.setBold(true);
277 ui.radioCurrent->setFont(font);
279 qDebug() << "Install::setVersionStrings" << version;