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
.radioCurrent
, SIGNAL(toggled(bool)), this, SLOT(setCached(bool)));
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 QString version
= installedVersion(settings
->mountpoint());
42 ui
.Backupgroup
->show();
43 m_backupName
= settings
->mountpoint();
44 if(!m_backupName
.endsWith("/")) m_backupName
+= "/";
45 m_backupName
+= ".backup/rockbox-backup-"+version
+".zip";
46 ui
.backupLocation
->setText(QDir::toNativeSeparators(fontMetrics().elidedText(m_backupName
,Qt::ElideMiddle
,200)));
50 ui
.Backupgroup
->hide();
52 backupCheckboxChanged(Qt::Unchecked
);
55 void Install::backupCheckboxChanged(int state
)
57 if(state
== Qt::Checked
)
59 ui
.backupLabel
->show();
60 ui
.backupLocation
->show();
61 ui
.changeBackup
->show();
65 ui
.backupLabel
->hide();
66 ui
.backupLocation
->hide();
67 ui
.changeBackup
->hide();
72 void Install::setCached(bool cache
)
74 ui
.checkBoxCache
->setEnabled(!cache
);
78 void Install::accept()
80 logger
= new ProgressLoggerGui(this);
82 QString mountPoint
= settings
->mountpoint();
83 qDebug() << "mountpoint:" << settings
->mountpoint();
84 // show dialog with error if mount point is wrong
85 if(!QFileInfo(mountPoint
).isDir()) {
86 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
92 QString buildname
= settings
->curPlatformName();
93 if(ui
.radioStable
->isChecked()) {
94 file
= QString("%1/rockbox-%2-%3.zip")
95 .arg(settings
->downloadUrl(),
96 settings
->lastRelease(), buildname
);
97 fileName
= QString("rockbox-%1-%2.zip")
98 .arg(settings
->lastRelease(), buildname
);
99 settings
->setBuild("stable");
100 myversion
= version
.value("rel_rev");
102 else if(ui
.radioArchived
->isChecked()) {
103 file
= QString("%1%2/rockbox-%3-%4.zip")
104 .arg(settings
->dailyUrl(),
105 buildname
, buildname
, version
.value("arch_date"));
106 fileName
= QString("rockbox-%1-%2.zip")
107 .arg(buildname
, version
.value("arch_date"));
108 settings
->setBuild("archived");
109 myversion
= "r" + version
.value("arch_rev") + "-" + version
.value("arch_date");
111 else if(ui
.radioCurrent
->isChecked()) {
112 file
= QString("%1%2/rockbox.zip")
113 .arg(settings
->bleedingUrl(), buildname
);
114 fileName
= QString("rockbox.zip");
115 settings
->setBuild("current");
116 myversion
= "r" + version
.value("bleed_rev");
119 qDebug() << "no build selected -- this shouldn't happen";
124 //! check if we should backup
125 if(ui
.backup
->isChecked())
127 logger
->addItem(tr("Beginning Backup..."),LOGINFO
);
129 //! create dir, if it doesnt exist
130 QFileInfo
backupFile(m_backupName
);
131 if(!QDir(backupFile
.path()).exists())
134 a
.mkpath(backupFile
.path());
139 connect(&backup
,SIGNAL(zipProgress(int,int)),this,SLOT(updateDataReadProgress(int,int)));
140 if(backup
.createZip(m_backupName
,settings
->mountpoint() + "/.rockbox") == Zip::Ok
)
142 logger
->addItem(tr("Backup successfull"),LOGOK
);
146 logger
->addItem(tr("Backup failed!"),LOGERROR
);
153 installer
= new ZipInstaller(this);
154 installer
->setUrl(file
);
155 installer
->setLogSection("Rockbox (Base)");
156 if(!settings
->cacheDisabled()
157 && !ui
.radioCurrent
->isChecked()
158 && !ui
.checkBoxCache
->isChecked())
160 installer
->setCache(true);
162 installer
->setLogVersion(myversion
);
163 installer
->setMountPoint(mountPoint
);
165 connect(installer
, SIGNAL(done(bool)), this, SLOT(done(bool)));
167 installer
->install(logger
);
171 void Install::changeBackupPath()
173 QString backupString
= QFileDialog::getSaveFileName(this,"Select Backup Filename",m_backupName
, "*.zip");
174 // only update if a filename was entered, ignore if cancelled
175 if(!backupString
.isEmpty()) {
176 ui
.backupLocation
->setText(QDir::toNativeSeparators(backupString
));
177 m_backupName
= backupString
;
181 void Install::updateDataReadProgress(int read
, int total
)
183 logger
->setProgressMax(total
);
184 logger
->setProgressValue(read
);
185 //qDebug() << "progress:" << read << "/" << total;
189 // Zip installer has finished
190 void Install::done(bool error
)
192 qDebug() << "Install::done, error:" << error
;
200 // no error, close the window, when the logger is closed
201 connect(logger
,SIGNAL(closed()),this,SLOT(close()));
202 // add platform info to log file for later detection
203 QSettings
installlog(settings
->mountpoint()
204 + "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
205 installlog
.setValue("platform", settings
->curPlatform());
210 void Install::setDetailsCurrent(bool show
)
213 ui
.labelDetails
->setText(tr("This is the absolute up to the minute "
214 "Rockbox built. A current build will get updated every time "
215 "a change is made. Latest version is r%1 (%2).")
216 .arg(version
.value("bleed_rev"), version
.value("bleed_date")));
217 if(version
.value("rel_rev").isEmpty())
218 ui
.labelNote
->setText(tr("<b>Note:</b> This option will always "
219 "download a fresh copy. "
220 "<b>This is the recommended version.</b>"));
222 ui
.labelNote
->setText(tr("<b>Note:</b> This option will always "
223 "download a fresh copy."));
228 void Install::setDetailsStable(bool show
)
231 ui
.labelDetails
->setText(
232 tr("This is the last released version of Rockbox."));
234 if(!version
.value("rel_rev").isEmpty())
235 ui
.labelNote
->setText(tr("<b>Note:</b>"
236 "The lastest released version is %1. "
237 "<b>This is the recommended version.</b>")
238 .arg(version
.value("rel_rev")));
239 else ui
.labelNote
->setText("");
244 void Install::setDetailsArchived(bool show
)
247 ui
.labelDetails
->setText(tr("These are automatically built each day "
248 "from the current development source code. This generally has more "
249 "features than the last stable release but may be much less stable. "
250 "Features may change regularly."));
251 ui
.labelNote
->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
252 .arg(version
.value("arch_rev"), version
.value("arch_date")));
258 void Install::setVersionStrings(QMap
<QString
, QString
> ver
)
261 // version strings map is as following:
262 // rel_rev release version revision id
263 // rel_date release version release date
264 // same for arch_* and bleed_*
266 if(version
.value("arch_rev").isEmpty()) {
267 ui
.radioArchived
->setEnabled(false);
268 qDebug() << "no information about archived version available!";
271 if(!version
.value("rel_rev").isEmpty()) {
272 ui
.radioStable
->setChecked(true);
273 ui
.radioStable
->setEnabled(true);
276 ui
.radioStable
->setFont(font
);
279 ui
.radioCurrent
->setChecked(true);
280 ui
.radioStable
->setEnabled(false);
281 ui
.radioStable
->setChecked(false);
284 ui
.radioCurrent
->setFont(font
);
286 qDebug() << "Install::setVersionStrings" << version
;