Move Info tab content to a separate widget.
[maemo-rb.git] / rbutil / rbutilqt / installwindow.cpp
blob584b014ae81afc029969a6f616f5e54c399e1df5
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.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 = Utils::checkEnvironment(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);
188 QCoreApplication::processEvents();
190 //! create dir, if it doesnt exist
191 QFileInfo backupFile(m_backupName);
192 if(!QDir(backupFile.path()).exists())
194 QDir a;
195 a.mkpath(backupFile.path());
198 //! create backup
199 bool result = true;
200 ZipUtil zip(this);
201 connect(&zip, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
202 connect(&zip, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
203 zip.open(m_backupName, QuaZip::mdCreate);
204 QString mp = RbSettings::value(RbSettings::Mountpoint).toString();
205 QString folder = mp + "/.rockbox";
206 result = zip.appendDirToArchive(folder, mp);
207 zip.close();
208 if(result) {
209 logger->addItem(tr("Backup finished."), LOGINFO);
211 else {
212 logger->addItem(tr("Backup failed!"), LOGERROR);
213 logger->setFinished();
214 return;
218 //! install build
219 installer = new ZipInstaller(this);
220 installer->setUrl(file);
221 installer->setLogSection("Rockbox (Base)");
222 if(!RbSettings::value(RbSettings::CacheDisabled).toBool()
223 && !ui.checkBoxCache->isChecked())
225 installer->setCache(true);
227 installer->setLogVersion(myversion);
228 installer->setMountPoint(mountPoint);
230 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
232 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
233 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
234 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
235 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
236 installer->install();
240 void InstallWindow::changeBackupPath()
242 QString backupString = QFileDialog::getSaveFileName(this,
243 tr("Select Backup Filename"), m_backupName, "*.zip");
244 // only update if a filename was entered, ignore if cancelled
245 if(!backupString.isEmpty()) {
246 m_backupName = backupString;
247 updateBackupLocation();
252 // Zip installer has finished
253 void InstallWindow::done(bool error)
255 qDebug() << "[Install] done, error:" << error;
257 if(error)
259 logger->setFinished();
260 return;
263 // no error, close the window, when the logger is closed
264 connect(logger,SIGNAL(closed()),this,SLOT(close()));
265 // add platform info to log file for later detection
266 QSettings installlog(RbSettings::value(RbSettings::Mountpoint).toString()
267 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
268 installlog.setValue("platform", RbSettings::value(RbSettings::Platform).toString());
269 installlog.sync();
273 void InstallWindow::setDetailsCurrent(bool show)
275 if(show) {
276 ui.labelDetails->setText(tr("This is the absolute up to the minute "
277 "Rockbox built. A current build will get updated every time "
278 "a change is made. Latest version is %1 (%2).")
279 .arg(ServerInfo::value(ServerInfo::BleedingRevision).toString(),
280 ServerInfo::value(ServerInfo::BleedingDate).toString()));
281 if(ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
282 ui.labelNote->setText(tr("<b>This is the recommended version.</b>"));
283 else
284 ui.labelNote->setText("");
289 void InstallWindow::setDetailsStable(bool show)
291 if(show) {
292 ui.labelDetails->setText(
293 tr("This is the last released version of Rockbox."));
295 if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
296 ui.labelNote->setText(tr("<b>Note:</b> "
297 "The lastest released version is %1. "
298 "<b>This is the recommended version.</b>")
299 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()));
300 else ui.labelNote->setText("");
305 void InstallWindow::setDetailsArchived(bool show)
307 if(show) {
308 ui.labelDetails->setText(tr("These are automatically built each day "
309 "from the current development source code. This generally has more "
310 "features than the last stable release but may be much less stable. "
311 "Features may change regularly."));
312 ui.labelNote->setText(tr("<b>Note:</b> archived version is %1 (%2).")
313 .arg(ServerInfo::value(ServerInfo::DailyRevision).toString(),
314 ServerInfo::value(ServerInfo::DailyDate).toString()));
319 void InstallWindow::changeEvent(QEvent *e)
321 if(e->type() == QEvent::LanguageChange) {
322 ui.retranslateUi(this);
323 } else {
324 QWidget::changeEvent(e);