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"
25 Install::Install(RbSettings
*sett
,QWidget
*parent
) : QDialog(parent
)
30 connect(ui
.radioStable
, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
31 connect(ui
.radioCurrent
, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
32 connect(ui
.radioArchived
, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
33 connect(ui
.changeBackup
, SIGNAL(pressed()), this, SLOT(changeBackupPath()));
34 connect(ui
.backup
, SIGNAL(stateChanged(int)), this, SLOT(backupCheckboxChanged(int)));
36 //! check if rockbox is already installed
37 QString version
= Detect::installedVersion(settings
->mountpoint());
41 ui
.Backupgroup
->show();
42 m_backupName
= settings
->mountpoint();
43 if(!m_backupName
.endsWith("/")) m_backupName
+= "/";
44 m_backupName
+= ".backup/rockbox-backup-"+version
+".zip";
45 // for some reason the label doesn't return its final size yet.
46 // Delay filling ui.backupLocation until the checkbox is changed.
50 ui
.Backupgroup
->hide();
52 backupCheckboxChanged(Qt::Unchecked
);
56 void Install::resizeEvent(QResizeEvent
*e
)
60 // recalculate width of elided text.
61 updateBackupLocation();
65 void Install::updateBackupLocation(void)
67 ui
.backupLocation
->setText(QDir::toNativeSeparators(
68 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName
),
69 Qt::ElideMiddle
, ui
.backupLocation
->size().width())));
73 void Install::backupCheckboxChanged(int state
)
75 if(state
== Qt::Checked
)
77 ui
.backupLocation
->show();
78 ui
.changeBackup
->show();
79 // update backup location display.
80 updateBackupLocation();
84 ui
.backupLocation
->hide();
85 ui
.changeBackup
->hide();
90 void Install::accept()
92 logger
= new ProgressLoggerGui(this);
94 QString mountPoint
= settings
->mountpoint();
95 qDebug() << "mountpoint:" << settings
->mountpoint();
96 // show dialog with error if mount point is wrong
97 if(!QFileInfo(mountPoint
).isDir()) {
98 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
104 QString buildname
= settings
->curPlatformName();
105 if(ui
.radioStable
->isChecked()) {
106 file
= QString("%1/%2/rockbox-%3-%4.zip")
107 .arg(settings
->releaseUrl(), version
.value("rel_rev"),
108 buildname
, version
.value("rel_rev"));
109 fileName
= QString("rockbox-%1-%2.zip")
110 .arg(version
.value("rel_rev"), buildname
);
111 settings
->setBuild("stable");
112 myversion
= version
.value("rel_rev");
114 else if(ui
.radioArchived
->isChecked()) {
115 file
= QString("%1%2/rockbox-%3-%4.zip")
116 .arg(settings
->dailyUrl(),
117 buildname
, buildname
, version
.value("arch_date"));
118 fileName
= QString("rockbox-%1-%2.zip")
119 .arg(buildname
, version
.value("arch_date"));
120 settings
->setBuild("archived");
121 myversion
= "r" + version
.value("arch_rev") + "-" + version
.value("arch_date");
123 else if(ui
.radioCurrent
->isChecked()) {
124 file
= QString("%1%2/rockbox.zip")
125 .arg(settings
->bleedingUrl(), buildname
);
126 fileName
= QString("rockbox.zip");
127 settings
->setBuild("current");
128 myversion
= "r" + version
.value("bleed_rev");
131 qDebug() << "no build selected -- this shouldn't happen";
136 QString warning
= Detect::check(settings
, false, settings
->curTargetId());
137 if(!warning
.isEmpty())
139 if(QMessageBox::warning(this, tr("Really continue?"), warning
,
140 QMessageBox::Ok
| QMessageBox::Abort
, QMessageBox::Abort
)
141 == QMessageBox::Abort
)
143 logger
->addItem(tr("Aborted!"),LOGERROR
);
149 //! check if we should backup
150 if(ui
.backup
->isChecked())
152 logger
->addItem(tr("Beginning Backup..."),LOGINFO
);
154 //! create dir, if it doesnt exist
155 QFileInfo
backupFile(m_backupName
);
156 if(!QDir(backupFile
.path()).exists())
159 a
.mkpath(backupFile
.path());
164 connect(&backup
,SIGNAL(zipProgress(int,int)),logger
,SLOT(setProgress(int,int)));
165 if(backup
.createZip(m_backupName
,settings
->mountpoint() + "/.rockbox") == Zip::Ok
)
167 logger
->addItem(tr("Backup successful"),LOGOK
);
171 logger
->addItem(tr("Backup failed!"),LOGERROR
);
178 installer
= new ZipInstaller(this);
179 installer
->setUrl(file
);
180 installer
->setLogSection("Rockbox (Base)");
181 if(!settings
->cacheDisabled()
182 && !ui
.checkBoxCache
->isChecked())
184 installer
->setCache(true);
186 installer
->setLogVersion(myversion
);
187 installer
->setMountPoint(mountPoint
);
189 connect(installer
, SIGNAL(done(bool)), this, SLOT(done(bool)));
191 installer
->install(logger
);
195 void Install::changeBackupPath()
197 QString backupString
= QFileDialog::getSaveFileName(this,
198 tr("Select Backup Filename"), m_backupName
, "*.zip");
199 // only update if a filename was entered, ignore if cancelled
200 if(!backupString
.isEmpty()) {
201 m_backupName
= backupString
;
202 updateBackupLocation();
207 // Zip installer has finished
208 void Install::done(bool error
)
210 qDebug() << "Install::done, error:" << error
;
218 // no error, close the window, when the logger is closed
219 connect(logger
,SIGNAL(closed()),this,SLOT(close()));
220 // add platform info to log file for later detection
221 QSettings
installlog(settings
->mountpoint()
222 + "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
223 installlog
.setValue("platform", settings
->curPlatform());
228 void Install::setDetailsCurrent(bool show
)
231 ui
.labelDetails
->setText(tr("This is the absolute up to the minute "
232 "Rockbox built. A current build will get updated every time "
233 "a change is made. Latest version is r%1 (%2).")
234 .arg(version
.value("bleed_rev"), version
.value("bleed_date")));
235 if(version
.value("rel_rev").isEmpty())
236 ui
.labelNote
->setText(tr("<b>This is the recommended version.</b>"));
241 void Install::setDetailsStable(bool show
)
244 ui
.labelDetails
->setText(
245 tr("This is the last released version of Rockbox."));
247 if(!version
.value("rel_rev").isEmpty())
248 ui
.labelNote
->setText(tr("<b>Note:</b>"
249 "The lastest released version is %1. "
250 "<b>This is the recommended version.</b>")
251 .arg(version
.value("rel_rev")));
252 else ui
.labelNote
->setText("");
257 void Install::setDetailsArchived(bool show
)
260 ui
.labelDetails
->setText(tr("These are automatically built each day "
261 "from the current development source code. This generally has more "
262 "features than the last stable release but may be much less stable. "
263 "Features may change regularly."));
264 ui
.labelNote
->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
265 .arg(version
.value("arch_rev"), version
.value("arch_date")));
271 void Install::setVersionStrings(QMap
<QString
, QString
> ver
)
274 // version strings map is as following:
275 // rel_rev release version revision id
276 // rel_date release version release date
277 // same for arch_* and bleed_*
279 if(version
.value("arch_rev").isEmpty()) {
280 ui
.radioArchived
->setEnabled(false);
281 qDebug() << "no information about archived version available!";
283 if(version
.value("rel_rev").isEmpty()) {
284 ui
.radioStable
->setEnabled(false);
287 // try to use the old selection first. If no selection has been made
288 // in the past, use a preselection based on released status.
289 if(settings
->build() == "stable" && !version
.value("rel_rev").isEmpty())
290 ui
.radioStable
->setChecked(true);
291 else if(settings
->build() == "archived")
292 ui
.radioArchived
->setChecked(true);
293 else if(settings
->build() == "current")
294 ui
.radioCurrent
->setChecked(true);
295 else if(!version
.value("rel_rev").isEmpty()) {
296 ui
.radioStable
->setChecked(true);
297 ui
.radioStable
->setEnabled(true);
300 ui
.radioStable
->setFont(font
);
303 ui
.radioCurrent
->setChecked(true);
304 ui
.radioStable
->setEnabled(false);
305 ui
.radioStable
->setChecked(false);
308 ui
.radioCurrent
->setFont(font
);
311 qDebug() << "Install::setVersionStrings" << version
;