1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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"
22 #include "rbsettings.h"
23 #include "serverinfo.h"
24 #include "systeminfo.h"
26 #include "rockboxinfo.h"
29 InstallWindow::InstallWindow(QWidget
*parent
) : QDialog(parent
)
33 connect(ui
.radioStable
, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
34 connect(ui
.radioCandidate
, SIGNAL(toggled(bool)), this, SLOT(setDetailsCandidate(bool)));
35 connect(ui
.radioCurrent
, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(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();
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.
52 ui
.Backupgroup
->hide();
54 backupCheckboxChanged(Qt::Unchecked
);
56 if(ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty()) {
57 ui
.radioStable
->setEnabled(false);
60 // try to use the old selection first. If no selection has been made
61 // in the past, use a preselection based on released status.
62 QString lastinstalled
= RbSettings::value(RbSettings::Build
).toString();
63 if(lastinstalled
== "stable"
64 && !ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty()) {
65 ui
.radioStable
->setChecked(true);
67 else if(lastinstalled
== "rc"
68 && !ServerInfo::value(ServerInfo::RelCandidateVersion
).toString().isEmpty()) {
69 ui
.radioCandidate
->setChecked(true);
71 else if(lastinstalled
== "current") {
72 ui
.radioCurrent
->setChecked(true);
74 else if(!ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty()) {
75 ui
.radioStable
->setChecked(true);
76 ui
.radioStable
->setEnabled(true);
79 ui
.radioCurrent
->setChecked(true);
80 ui
.radioStable
->setEnabled(false);
81 ui
.radioStable
->setChecked(false);
83 if(ServerInfo::value(ServerInfo::RelCandidateVersion
).toString().isEmpty()) {
84 ui
.radioCandidate
->setEnabled(false);
90 void InstallWindow::resizeEvent(QResizeEvent
*e
)
94 // recalculate width of elided text.
95 updateBackupLocation();
99 void InstallWindow::updateBackupLocation(void)
101 ui
.backupLocation
->setText(QDir::toNativeSeparators(
102 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName
),
103 Qt::ElideMiddle
, ui
.backupLocation
->size().width())));
107 void InstallWindow::backupCheckboxChanged(int state
)
109 if(state
== Qt::Checked
)
111 ui
.backupLocation
->show();
112 ui
.changeBackup
->show();
113 // update backup location display.
114 updateBackupLocation();
118 ui
.backupLocation
->hide();
119 ui
.changeBackup
->hide();
124 void InstallWindow::accept()
127 logger
= new ProgressLoggerGui(this);
129 QString mountPoint
= RbSettings::value(RbSettings::Mountpoint
).toString();
130 qDebug() << "[Install] mountpoint:" << mountPoint
;
131 // show dialog with error if mount point is wrong
132 if(!QFileInfo(mountPoint
).isDir()) {
133 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
134 logger
->setFinished();
139 if(ui
.radioStable
->isChecked()) {
140 url
= ServerInfo::value(ServerInfo::CurReleaseUrl
).toString();
141 RbSettings::setValue(RbSettings::Build
, "stable");
142 myversion
= ServerInfo::value(ServerInfo::CurReleaseVersion
).toString();
144 else if(ui
.radioCurrent
->isChecked()) {
145 url
= ServerInfo::value(ServerInfo::CurDevelUrl
).toString();
146 RbSettings::setValue(RbSettings::Build
, "current");
147 myversion
= "r" + ServerInfo::value(ServerInfo::BleedingRevision
).toString();
149 else if(ui
.radioCandidate
->isChecked()) {
150 url
= ServerInfo::value(ServerInfo::RelCandidateUrl
).toString();
151 RbSettings::setValue(RbSettings::Build
, "rc");
152 myversion
= ServerInfo::value(ServerInfo::RelCandidateVersion
).toString();
155 qDebug() << "[Install] no build selected -- this shouldn't happen";
160 QString warning
= Utils::checkEnvironment(false);
161 if(!warning
.isEmpty())
163 if(QMessageBox::warning(this, tr("Really continue?"), warning
,
164 QMessageBox::Ok
| QMessageBox::Abort
, QMessageBox::Abort
)
165 == QMessageBox::Abort
)
167 logger
->addItem(tr("Aborted!"),LOGERROR
);
168 logger
->setFinished();
173 //! check if we should backup
174 if(ui
.backup
->isChecked())
176 logger
->addItem(tr("Beginning Backup..."),LOGINFO
);
177 QCoreApplication::processEvents();
179 //! create dir, if it doesnt exist
180 QFileInfo
backupFile(m_backupName
);
181 if(!QDir(backupFile
.path()).exists())
184 a
.mkpath(backupFile
.path());
190 connect(&zip
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
191 connect(&zip
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
192 zip
.open(m_backupName
, QuaZip::mdCreate
);
193 QString mp
= RbSettings::value(RbSettings::Mountpoint
).toString();
194 QString folder
= mp
+ "/.rockbox";
195 result
= zip
.appendDirToArchive(folder
, mp
);
198 logger
->addItem(tr("Backup finished."), LOGINFO
);
201 logger
->addItem(tr("Backup failed!"), LOGERROR
);
202 logger
->setFinished();
208 installer
= new ZipInstaller(this);
209 installer
->setUrl(url
);
210 installer
->setLogSection("Rockbox (Base)");
211 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool()
212 && !ui
.checkBoxCache
->isChecked())
214 installer
->setCache(true);
216 installer
->setLogVersion(myversion
);
217 installer
->setMountPoint(mountPoint
);
219 connect(installer
, SIGNAL(done(bool)), this, SLOT(done(bool)));
221 connect(installer
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
222 connect(installer
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
223 connect(installer
, SIGNAL(done(bool)), logger
, SLOT(setFinished()));
224 connect(logger
, SIGNAL(aborted()), installer
, SLOT(abort()));
225 installer
->install();
229 void InstallWindow::changeBackupPath()
231 QString backupString
= QFileDialog::getSaveFileName(this,
232 tr("Select Backup Filename"), m_backupName
, "*.zip");
233 // only update if a filename was entered, ignore if cancelled
234 if(!backupString
.isEmpty()) {
235 m_backupName
= backupString
;
236 updateBackupLocation();
241 // Zip installer has finished
242 void InstallWindow::done(bool error
)
244 qDebug() << "[Install] done, error:" << error
;
248 logger
->setFinished();
252 // no error, close the window, when the logger is closed
253 connect(logger
,SIGNAL(closed()),this,SLOT(close()));
254 // add platform info to log file for later detection
255 QSettings
installlog(RbSettings::value(RbSettings::Mountpoint
).toString()
256 + "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
257 installlog
.setValue("platform", RbSettings::value(RbSettings::Platform
).toString());
262 void InstallWindow::setDetailsCurrent(bool show
)
265 ui
.labelDetails
->setText(tr("This is the absolute up to the minute "
266 "Rockbox built. The development version will get updated every time "
267 "a change is made. Latest development version is %1 (%2).")
268 .arg(ServerInfo::value(ServerInfo::BleedingRevision
).toString(),
269 ServerInfo::value(ServerInfo::BleedingDate
).toString()));
274 void InstallWindow::setDetailsStable(bool show
)
277 ui
.labelDetails
->setText(
278 tr("This is the last released version of Rockbox."));
280 if(!ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty())
281 ui
.labelNote
->setText(tr("<b>Note:</b> "
282 "The lastest stable version is %1.")
283 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion
).toString()));
284 else ui
.labelNote
->setText("");
289 void InstallWindow::setDetailsCandidate(bool show
)
292 ui
.labelDetails
->setText(
293 tr("This is the release candidate for the next Rockbox version."
294 "<br/>A release candidate is intended for testing. It will "
295 "receive bugfixes and eventually become the next stable "
296 "release of Rockbox. If you want to help testing Rockbox and "
297 "improve the next release install the release candidate."));
299 if(!ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty())
300 ui
.labelNote
->setText(tr("<b>Note:</b> "
301 "The lastest release candidate is %1.")
302 .arg(ServerInfo::value(ServerInfo::RelCandidateVersion
).toString()));
303 else ui
.labelNote
->setText("");
308 void InstallWindow::changeEvent(QEvent
*e
)
310 if(e
->type() == QEvent::LanguageChange
) {
311 ui
.retranslateUi(this);
313 QWidget::changeEvent(e
);