Respect the exit code of external encoder called.
[maemo-rb.git] / rbutil / rbutilqt / installwindow.cpp
blob9eae0ce09f674f06517f6406275a79c48fd16132
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 "installwindow.h"
21 #include "ui_installwindowfrm.h"
22 #include "rbzip.h"
23 #include "system.h"
24 #include "rbsettings.h"
25 #include "serverinfo.h"
26 #include "systeminfo.h"
27 #include "utils.h"
29 InstallWindow::InstallWindow(QWidget *parent) : QDialog(parent)
31 ui.setupUi(this);
33 connect(ui.radioStable, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
34 connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
35 connect(ui.radioArchived, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
36 connect(ui.changeBackup, SIGNAL(pressed()), this, SLOT(changeBackupPath()));
37 connect(ui.backup, SIGNAL(stateChanged(int)), this, SLOT(backupCheckboxChanged(int)));
39 //! check if rockbox is already installed
40 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
41 QString version = rbinfo.version();
43 if(version != "")
45 ui.Backupgroup->show();
46 m_backupName = RbSettings::value(RbSettings::Mountpoint).toString();
47 if(!m_backupName.endsWith("/")) m_backupName += "/";
48 m_backupName += ".backup/rockbox-backup-"+version+".zip";
49 // for some reason the label doesn't return its final size yet.
50 // Delay filling ui.backupLocation until the checkbox is changed.
52 else
54 ui.Backupgroup->hide();
56 backupCheckboxChanged(Qt::Unchecked);
59 if(ServerInfo::value(ServerInfo::DailyRevision).toString().isEmpty()) {
60 ui.radioArchived->setEnabled(false);
61 qDebug() << "[Install] no information about archived version available!";
63 if(ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty()) {
64 ui.radioStable->setEnabled(false);
67 // try to use the old selection first. If no selection has been made
68 // in the past, use a preselection based on released status.
69 if(RbSettings::value(RbSettings::Build).toString() == "stable"
70 && !ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
71 ui.radioStable->setChecked(true);
72 else if(RbSettings::value(RbSettings::Build).toString() == "archived")
73 ui.radioArchived->setChecked(true);
74 else if(RbSettings::value(RbSettings::Build).toString() == "current")
75 ui.radioCurrent->setChecked(true);
76 else if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty()) {
77 ui.radioStable->setChecked(true);
78 ui.radioStable->setEnabled(true);
79 QFont font;
80 font.setBold(true);
81 ui.radioStable->setFont(font);
83 else {
84 ui.radioCurrent->setChecked(true);
85 ui.radioStable->setEnabled(false);
86 ui.radioStable->setChecked(false);
87 QFont font;
88 font.setBold(true);
89 ui.radioCurrent->setFont(font);
95 void InstallWindow::resizeEvent(QResizeEvent *e)
97 (void)e;
99 // recalculate width of elided text.
100 updateBackupLocation();
104 void InstallWindow::updateBackupLocation(void)
106 ui.backupLocation->setText(QDir::toNativeSeparators(
107 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName),
108 Qt::ElideMiddle, ui.backupLocation->size().width())));
112 void InstallWindow::backupCheckboxChanged(int state)
114 if(state == Qt::Checked)
116 ui.backupLocation->show();
117 ui.changeBackup->show();
118 // update backup location display.
119 updateBackupLocation();
121 else
123 ui.backupLocation->hide();
124 ui.changeBackup->hide();
129 void InstallWindow::accept()
131 logger = new ProgressLoggerGui(this);
132 logger->show();
133 QString mountPoint = RbSettings::value(RbSettings::Mountpoint).toString();
134 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint).toString();
135 // show dialog with error if mount point is wrong
136 if(!QFileInfo(mountPoint).isDir()) {
137 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
138 logger->setFinished();
139 return;
142 QString myversion;
143 QString buildname = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
144 if(ui.radioStable->isChecked()) {
145 file = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
146 RbSettings::setValue(RbSettings::Build, "stable");
147 myversion = ServerInfo::value(ServerInfo::CurReleaseVersion).toString();
149 else if(ui.radioArchived->isChecked()) {
150 file = SystemInfo::value(SystemInfo::DailyUrl).toString();
151 RbSettings::setValue(RbSettings::Build, "archived");
152 myversion = "r" + ServerInfo::value(ServerInfo::DailyRevision).toString()
153 + "-" + ServerInfo::value(ServerInfo::DailyDate).toString();
155 else if(ui.radioCurrent->isChecked()) {
156 file = SystemInfo::value(SystemInfo::BleedingUrl).toString();
157 RbSettings::setValue(RbSettings::Build, "current");
158 myversion = "r" + ServerInfo::value(ServerInfo::BleedingRevision).toString();
160 else {
161 qDebug() << "[Install] no build selected -- this shouldn't happen";
162 return;
164 file.replace("%MODEL%", buildname);
165 file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
166 file.replace("%REVISION%", ServerInfo::value(ServerInfo::DailyRevision).toString());
167 file.replace("%DATE%", ServerInfo::value(ServerInfo::DailyDate).toString());
169 RbSettings::sync();
171 QString warning = check(false);
172 if(!warning.isEmpty())
174 if(QMessageBox::warning(this, tr("Really continue?"), warning,
175 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
176 == QMessageBox::Abort)
178 logger->addItem(tr("Aborted!"),LOGERROR);
179 logger->setFinished();
180 return;
184 //! check if we should backup
185 if(ui.backup->isChecked())
187 logger->addItem(tr("Beginning Backup..."),LOGINFO);
189 //! create dir, if it doesnt exist
190 QFileInfo backupFile(m_backupName);
191 if(!QDir(backupFile.path()).exists())
193 QDir a;
194 a.mkpath(backupFile.path());
197 //! create backup
198 RbZip backup;
199 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
200 if(backup.createZip(m_backupName,
201 RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok)
203 logger->addItem(tr("Backup successful"),LOGOK);
205 else
207 logger->addItem(tr("Backup failed!"),LOGERROR);
208 logger->setFinished();
209 return;
213 //! install build
214 installer = new ZipInstaller(this);
215 installer->setUrl(file);
216 installer->setLogSection("Rockbox (Base)");
217 if(!RbSettings::value(RbSettings::CacheDisabled).toBool()
218 && !ui.checkBoxCache->isChecked())
220 installer->setCache(true);
222 installer->setLogVersion(myversion);
223 installer->setMountPoint(mountPoint);
225 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
227 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
228 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
229 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
230 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
231 installer->install();
235 void InstallWindow::changeBackupPath()
237 QString backupString = QFileDialog::getSaveFileName(this,
238 tr("Select Backup Filename"), m_backupName, "*.zip");
239 // only update if a filename was entered, ignore if cancelled
240 if(!backupString.isEmpty()) {
241 m_backupName = backupString;
242 updateBackupLocation();
247 // Zip installer has finished
248 void InstallWindow::done(bool error)
250 qDebug() << "[Install] done, error:" << error;
252 if(error)
254 logger->setFinished();
255 return;
258 // no error, close the window, when the logger is closed
259 connect(logger,SIGNAL(closed()),this,SLOT(close()));
260 // add platform info to log file for later detection
261 QSettings installlog(RbSettings::value(RbSettings::Mountpoint).toString()
262 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
263 installlog.setValue("platform", RbSettings::value(RbSettings::Platform).toString());
264 installlog.sync();
268 void InstallWindow::setDetailsCurrent(bool show)
270 if(show) {
271 ui.labelDetails->setText(tr("This is the absolute up to the minute "
272 "Rockbox built. A current build will get updated every time "
273 "a change is made. Latest version is r%1 (%2).")
274 .arg(ServerInfo::value(ServerInfo::BleedingRevision).toString(),
275 ServerInfo::value(ServerInfo::BleedingDate).toString()));
276 if(ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
277 ui.labelNote->setText(tr("<b>This is the recommended version.</b>"));
278 else
279 ui.labelNote->setText("");
284 void InstallWindow::setDetailsStable(bool show)
286 if(show) {
287 ui.labelDetails->setText(
288 tr("This is the last released version of Rockbox."));
290 if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
291 ui.labelNote->setText(tr("<b>Note:</b> "
292 "The lastest released version is %1. "
293 "<b>This is the recommended version.</b>")
294 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()));
295 else ui.labelNote->setText("");
300 void InstallWindow::setDetailsArchived(bool show)
302 if(show) {
303 ui.labelDetails->setText(tr("These are automatically built each day "
304 "from the current development source code. This generally has more "
305 "features than the last stable release but may be much less stable. "
306 "Features may change regularly."));
307 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
308 .arg(ServerInfo::value(ServerInfo::DailyRevision).toString(),
309 ServerInfo::value(ServerInfo::DailyDate).toString()));