Update for single build-info file.
[maemo-rb.git] / rbutil / rbutilqt / installwindow.cpp
blob7a78154561319d2657a88db5b5e1163e5c4365e6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include "installwindow.h"
20 #include "ui_installwindowfrm.h"
21 #include "system.h"
22 #include "rbsettings.h"
23 #include "serverinfo.h"
24 #include "systeminfo.h"
25 #include "utils.h"
26 #include "rockboxinfo.h"
27 #include "ziputil.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.changeBackup, SIGNAL(pressed()), this, SLOT(changeBackupPath()));
36 connect(ui.backup, SIGNAL(stateChanged(int)), this, SLOT(backupCheckboxChanged(int)));
38 //! check if rockbox is already installed
39 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
40 QString version = rbinfo.version();
42 if(version != "")
44 ui.Backupgroup->show();
45 m_backupName = RbSettings::value(RbSettings::Mountpoint).toString();
46 if(!m_backupName.endsWith("/")) m_backupName += "/";
47 m_backupName += ".backup/rockbox-backup-"+version+".zip";
48 // for some reason the label doesn't return its final size yet.
49 // Delay filling ui.backupLocation until the checkbox is changed.
51 else
53 ui.Backupgroup->hide();
55 backupCheckboxChanged(Qt::Unchecked);
58 if(ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty()) {
59 ui.radioStable->setEnabled(false);
62 // try to use the old selection first. If no selection has been made
63 // in the past, use a preselection based on released status.
64 if(RbSettings::value(RbSettings::Build).toString() == "stable"
65 && !ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
66 ui.radioStable->setChecked(true);
67 else if(RbSettings::value(RbSettings::Build).toString() == "current")
68 ui.radioCurrent->setChecked(true);
69 else if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty()) {
70 ui.radioStable->setChecked(true);
71 ui.radioStable->setEnabled(true);
73 else {
74 ui.radioCurrent->setChecked(true);
75 ui.radioStable->setEnabled(false);
76 ui.radioStable->setChecked(false);
82 void InstallWindow::resizeEvent(QResizeEvent *e)
84 (void)e;
86 // recalculate width of elided text.
87 updateBackupLocation();
91 void InstallWindow::updateBackupLocation(void)
93 ui.backupLocation->setText(QDir::toNativeSeparators(
94 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName),
95 Qt::ElideMiddle, ui.backupLocation->size().width())));
99 void InstallWindow::backupCheckboxChanged(int state)
101 if(state == Qt::Checked)
103 ui.backupLocation->show();
104 ui.changeBackup->show();
105 // update backup location display.
106 updateBackupLocation();
108 else
110 ui.backupLocation->hide();
111 ui.changeBackup->hide();
116 void InstallWindow::accept()
118 logger = new ProgressLoggerGui(this);
119 logger->show();
120 QString mountPoint = RbSettings::value(RbSettings::Mountpoint).toString();
121 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint).toString();
122 // show dialog with error if mount point is wrong
123 if(!QFileInfo(mountPoint).isDir()) {
124 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
125 logger->setFinished();
126 return;
129 QString myversion;
130 QString buildname = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
131 if(ui.radioStable->isChecked()) {
132 file = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
133 RbSettings::setValue(RbSettings::Build, "stable");
134 myversion = ServerInfo::value(ServerInfo::CurReleaseVersion).toString();
136 else if(ui.radioCurrent->isChecked()) {
137 file = SystemInfo::value(SystemInfo::BleedingUrl).toString();
138 RbSettings::setValue(RbSettings::Build, "current");
139 myversion = "r" + ServerInfo::value(ServerInfo::BleedingRevision).toString();
141 else {
142 qDebug() << "[Install] no build selected -- this shouldn't happen";
143 return;
145 file.replace("%MODEL%", buildname);
146 file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
148 RbSettings::sync();
150 QString warning = Utils::checkEnvironment(false);
151 if(!warning.isEmpty())
153 if(QMessageBox::warning(this, tr("Really continue?"), warning,
154 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
155 == QMessageBox::Abort)
157 logger->addItem(tr("Aborted!"),LOGERROR);
158 logger->setFinished();
159 return;
163 //! check if we should backup
164 if(ui.backup->isChecked())
166 logger->addItem(tr("Beginning Backup..."),LOGINFO);
167 QCoreApplication::processEvents();
169 //! create dir, if it doesnt exist
170 QFileInfo backupFile(m_backupName);
171 if(!QDir(backupFile.path()).exists())
173 QDir a;
174 a.mkpath(backupFile.path());
177 //! create backup
178 bool result = true;
179 ZipUtil zip(this);
180 connect(&zip, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
181 connect(&zip, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
182 zip.open(m_backupName, QuaZip::mdCreate);
183 QString mp = RbSettings::value(RbSettings::Mountpoint).toString();
184 QString folder = mp + "/.rockbox";
185 result = zip.appendDirToArchive(folder, mp);
186 zip.close();
187 if(result) {
188 logger->addItem(tr("Backup finished."), LOGINFO);
190 else {
191 logger->addItem(tr("Backup failed!"), LOGERROR);
192 logger->setFinished();
193 return;
197 //! install build
198 installer = new ZipInstaller(this);
199 installer->setUrl(file);
200 installer->setLogSection("Rockbox (Base)");
201 if(!RbSettings::value(RbSettings::CacheDisabled).toBool()
202 && !ui.checkBoxCache->isChecked())
204 installer->setCache(true);
206 installer->setLogVersion(myversion);
207 installer->setMountPoint(mountPoint);
209 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
211 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
212 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
213 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
214 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
215 installer->install();
219 void InstallWindow::changeBackupPath()
221 QString backupString = QFileDialog::getSaveFileName(this,
222 tr("Select Backup Filename"), m_backupName, "*.zip");
223 // only update if a filename was entered, ignore if cancelled
224 if(!backupString.isEmpty()) {
225 m_backupName = backupString;
226 updateBackupLocation();
231 // Zip installer has finished
232 void InstallWindow::done(bool error)
234 qDebug() << "[Install] done, error:" << error;
236 if(error)
238 logger->setFinished();
239 return;
242 // no error, close the window, when the logger is closed
243 connect(logger,SIGNAL(closed()),this,SLOT(close()));
244 // add platform info to log file for later detection
245 QSettings installlog(RbSettings::value(RbSettings::Mountpoint).toString()
246 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
247 installlog.setValue("platform", RbSettings::value(RbSettings::Platform).toString());
248 installlog.sync();
252 void InstallWindow::setDetailsCurrent(bool show)
254 if(show) {
255 ui.labelDetails->setText(tr("This is the absolute up to the minute "
256 "Rockbox built. The development version will get updated every time "
257 "a change is made. Latest development version is %1 (%2).")
258 .arg(ServerInfo::value(ServerInfo::BleedingRevision).toString(),
259 ServerInfo::value(ServerInfo::BleedingDate).toString()));
264 void InstallWindow::setDetailsStable(bool show)
266 if(show) {
267 ui.labelDetails->setText(
268 tr("This is the last released version of Rockbox."));
270 if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
271 ui.labelNote->setText(tr("<b>Note:</b> "
272 "The lastest stable version is %1.")
273 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()));
274 else ui.labelNote->setText("");
279 void InstallWindow::changeEvent(QEvent *e)
281 if(e->type() == QEvent::LanguageChange) {
282 ui.retranslateUi(this);
283 } else {
284 QWidget::changeEvent(e);