1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
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 ****************************************************************************/
21 #include "ui_installfrm.h"
24 #include "rbsettings.h"
27 Install::Install(QWidget
*parent
) : QDialog(parent
)
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 RockboxInfo
rbinfo(RbSettings::value(RbSettings::Mountpoint
).toString());
39 QString version
= rbinfo
.version();
43 ui
.Backupgroup
->show();
44 m_backupName
= RbSettings::value(RbSettings::Mountpoint
).toString();
45 if(!m_backupName
.endsWith("/")) m_backupName
+= "/";
46 m_backupName
+= ".backup/rockbox-backup-"+version
+".zip";
47 // for some reason the label doesn't return its final size yet.
48 // Delay filling ui.backupLocation until the checkbox is changed.
52 ui
.Backupgroup
->hide();
54 backupCheckboxChanged(Qt::Unchecked
);
58 void Install::resizeEvent(QResizeEvent
*e
)
62 // recalculate width of elided text.
63 updateBackupLocation();
67 void Install::updateBackupLocation(void)
69 ui
.backupLocation
->setText(QDir::toNativeSeparators(
70 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName
),
71 Qt::ElideMiddle
, ui
.backupLocation
->size().width())));
75 void Install::backupCheckboxChanged(int state
)
77 if(state
== Qt::Checked
)
79 ui
.backupLocation
->show();
80 ui
.changeBackup
->show();
81 // update backup location display.
82 updateBackupLocation();
86 ui
.backupLocation
->hide();
87 ui
.changeBackup
->hide();
92 void Install::accept()
94 logger
= new ProgressLoggerGui(this);
96 QString mountPoint
= RbSettings::value(RbSettings::Mountpoint
).toString();
97 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint
).toString();
98 // show dialog with error if mount point is wrong
99 if(!QFileInfo(mountPoint
).isDir()) {
100 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
101 logger
->setFinished();
106 QString buildname
= RbSettings::value(RbSettings::CurBuildserverModel
).toString();
107 if(ui
.radioStable
->isChecked()) {
108 file
= RbSettings::value(RbSettings::ReleaseUrl
).toString();
109 RbSettings::setValue(RbSettings::Build
, "stable");
110 myversion
= version
.value("rel_rev");
112 else if(ui
.radioArchived
->isChecked()) {
113 file
= RbSettings::value(RbSettings::DailyUrl
).toString();
114 RbSettings::setValue(RbSettings::Build
, "archived");
115 myversion
= "r" + version
.value("arch_rev") + "-" + version
.value("arch_date");
117 else if(ui
.radioCurrent
->isChecked()) {
118 file
= RbSettings::value(RbSettings::BleedingUrl
).toString();
119 RbSettings::setValue(RbSettings::Build
, "current");
120 myversion
= "r" + version
.value("bleed_rev");
123 qDebug() << "[Install] no build selected -- this shouldn't happen";
126 file
.replace("%MODEL%", buildname
);
127 file
.replace("%RELVERSION%", version
.value("rel_rev"));
128 file
.replace("%REVISION%", version
.value("arch_rev"));
129 file
.replace("%DATE%", version
.value("arch_date"));
133 QString warning
= check(false);
134 if(!warning
.isEmpty())
136 if(QMessageBox::warning(this, tr("Really continue?"), warning
,
137 QMessageBox::Ok
| QMessageBox::Abort
, QMessageBox::Abort
)
138 == QMessageBox::Abort
)
140 logger
->addItem(tr("Aborted!"),LOGERROR
);
141 logger
->setFinished();
146 //! check if we should backup
147 if(ui
.backup
->isChecked())
149 logger
->addItem(tr("Beginning Backup..."),LOGINFO
);
151 //! create dir, if it doesnt exist
152 QFileInfo
backupFile(m_backupName
);
153 if(!QDir(backupFile
.path()).exists())
156 a
.mkpath(backupFile
.path());
161 connect(&backup
,SIGNAL(zipProgress(int,int)),logger
,SLOT(setProgress(int,int)));
162 if(backup
.createZip(m_backupName
,
163 RbSettings::value(RbSettings::Mountpoint
).toString() + "/.rockbox") == Zip::Ok
)
165 logger
->addItem(tr("Backup successful"),LOGOK
);
169 logger
->addItem(tr("Backup failed!"),LOGERROR
);
170 logger
->setFinished();
176 installer
= new ZipInstaller(this);
177 installer
->setUrl(file
);
178 installer
->setLogSection("Rockbox (Base)");
179 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool()
180 && !ui
.checkBoxCache
->isChecked())
182 installer
->setCache(true);
184 installer
->setLogVersion(myversion
);
185 installer
->setMountPoint(mountPoint
);
187 connect(installer
, SIGNAL(done(bool)), this, SLOT(done(bool)));
189 connect(installer
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
190 connect(installer
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
191 connect(installer
, SIGNAL(done(bool)), logger
, SLOT(setFinished()));
192 connect(logger
, SIGNAL(aborted()), installer
, SLOT(abort()));
193 installer
->install();
197 void Install::changeBackupPath()
199 QString backupString
= QFileDialog::getSaveFileName(this,
200 tr("Select Backup Filename"), m_backupName
, "*.zip");
201 // only update if a filename was entered, ignore if cancelled
202 if(!backupString
.isEmpty()) {
203 m_backupName
= backupString
;
204 updateBackupLocation();
209 // Zip installer has finished
210 void Install::done(bool error
)
212 qDebug() << "[Install] done, error:" << error
;
216 logger
->setFinished();
220 // no error, close the window, when the logger is closed
221 connect(logger
,SIGNAL(closed()),this,SLOT(close()));
222 // add platform info to log file for later detection
223 QSettings
installlog(RbSettings::value(RbSettings::Mountpoint
).toString()
224 + "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
225 installlog
.setValue("platform", RbSettings::value(RbSettings::Platform
).toString());
230 void Install::setDetailsCurrent(bool show
)
233 ui
.labelDetails
->setText(tr("This is the absolute up to the minute "
234 "Rockbox built. A current build will get updated every time "
235 "a change is made. Latest version is r%1 (%2).")
236 .arg(version
.value("bleed_rev"), version
.value("bleed_date")));
237 if(version
.value("rel_rev").isEmpty())
238 ui
.labelNote
->setText(tr("<b>This is the recommended version.</b>"));
240 ui
.labelNote
->setText("");
245 void Install::setDetailsStable(bool show
)
248 ui
.labelDetails
->setText(
249 tr("This is the last released version of Rockbox."));
251 if(!version
.value("rel_rev").isEmpty())
252 ui
.labelNote
->setText(tr("<b>Note:</b> "
253 "The lastest released version is %1. "
254 "<b>This is the recommended version.</b>")
255 .arg(version
.value("rel_rev")));
256 else ui
.labelNote
->setText("");
261 void Install::setDetailsArchived(bool show
)
264 ui
.labelDetails
->setText(tr("These are automatically built each day "
265 "from the current development source code. This generally has more "
266 "features than the last stable release but may be much less stable. "
267 "Features may change regularly."));
268 ui
.labelNote
->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
269 .arg(version
.value("arch_rev"), version
.value("arch_date")));
275 void Install::setVersionStrings(QMap
<QString
, QString
>& ver
)
278 // version strings map is as following:
279 // rel_rev release version revision id
280 // rel_date release version release date
281 // same for arch_* and bleed_*
283 if(version
.value("arch_rev").isEmpty()) {
284 ui
.radioArchived
->setEnabled(false);
285 qDebug() << "[Install] no information about archived version available!";
287 if(version
.value("rel_rev").isEmpty()) {
288 ui
.radioStable
->setEnabled(false);
291 // try to use the old selection first. If no selection has been made
292 // in the past, use a preselection based on released status.
293 if(RbSettings::value(RbSettings::Build
).toString() == "stable"
294 && !version
.value("rel_rev").isEmpty())
295 ui
.radioStable
->setChecked(true);
296 else if(RbSettings::value(RbSettings::Build
).toString() == "archived")
297 ui
.radioArchived
->setChecked(true);
298 else if(RbSettings::value(RbSettings::Build
).toString() == "current")
299 ui
.radioCurrent
->setChecked(true);
300 else if(!version
.value("rel_rev").isEmpty()) {
301 ui
.radioStable
->setChecked(true);
302 ui
.radioStable
->setEnabled(true);
305 ui
.radioStable
->setFont(font
);
308 ui
.radioCurrent
->setChecked(true);
309 ui
.radioStable
->setEnabled(false);
310 ui
.radioStable
->setChecked(false);
313 ui
.radioCurrent
->setFont(font
);
316 qDebug() << "[Install] setting version strings to:" << version
;