codec.link must be created with -DCODEC
[kugel-rb.git] / rbutil / rbutilqt / install.cpp
blobee0d2114da3f879580b8bef46e1585353d08f7a3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
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 ****************************************************************************/
20 #include "install.h"
21 #include "ui_installfrm.h"
22 #include "rbzip.h"
23 #include "detect.h"
25 Install::Install(RbSettings *sett,QWidget *parent) : QDialog(parent)
27 settings = sett;
28 ui.setupUi(this);
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 = Detect::installedVersion(settings->mountpoint());
40 if(version != "")
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)));
48 else
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();
63 else
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);
81 logger->show();
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);
87 logger->abort();
88 return;
91 QString myversion;
92 QString buildname = settings->curPlatformName();
93 if(ui.radioStable->isChecked()) {
94 file = QString("%1/%2/rockbox-%3-%4.zip")
95 .arg(settings->releaseUrl(),settings->lastRelease(settings->curPlatform()),
96 buildname, settings->lastRelease(settings->curPlatform()));
97 fileName = QString("rockbox-%1-%2.zip")
98 .arg(settings->lastRelease(settings->curPlatform()), 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");
118 else {
119 qDebug() << "no build selected -- this shouldn't happen";
120 return;
122 settings->sync();
124 QString warning = Detect::check(settings, false, settings->curTargetId());
125 if(!warning.isEmpty())
127 if(QMessageBox::warning(this, tr("Really continue?"), warning,
128 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
129 == QMessageBox::Abort)
131 logger->addItem(tr("Aborted!"),LOGERROR);
132 logger->abort();
133 return;
137 //! check if we should backup
138 if(ui.backup->isChecked())
140 logger->addItem(tr("Beginning Backup..."),LOGINFO);
142 //! create dir, if it doesnt exist
143 QFileInfo backupFile(m_backupName);
144 if(!QDir(backupFile.path()).exists())
146 QDir a;
147 a.mkpath(backupFile.path());
150 //! create backup
151 RbZip backup;
152 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
153 if(backup.createZip(m_backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
155 logger->addItem(tr("Backup successful"),LOGOK);
157 else
159 logger->addItem(tr("Backup failed!"),LOGERROR);
160 logger->abort();
161 return;
165 //! install build
166 installer = new ZipInstaller(this);
167 installer->setUrl(file);
168 installer->setLogSection("Rockbox (Base)");
169 if(!settings->cacheDisabled()
170 && !ui.radioCurrent->isChecked()
171 && !ui.checkBoxCache->isChecked())
173 installer->setCache(true);
175 installer->setLogVersion(myversion);
176 installer->setMountPoint(mountPoint);
178 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
180 installer->install(logger);
184 void Install::changeBackupPath()
186 QString backupString = QFileDialog::getSaveFileName(this,"Select Backup Filename",m_backupName, "*.zip");
187 // only update if a filename was entered, ignore if cancelled
188 if(!backupString.isEmpty()) {
189 ui.backupLocation->setText(QDir::toNativeSeparators(fontMetrics().elidedText(backupString,Qt::ElideMiddle,200)));
190 m_backupName = backupString;
195 // Zip installer has finished
196 void Install::done(bool error)
198 qDebug() << "Install::done, error:" << error;
200 if(error)
202 logger->abort();
203 return;
206 // no error, close the window, when the logger is closed
207 connect(logger,SIGNAL(closed()),this,SLOT(close()));
208 // add platform info to log file for later detection
209 QSettings installlog(settings->mountpoint()
210 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
211 installlog.setValue("platform", settings->curPlatform());
212 installlog.sync();
216 void Install::setDetailsCurrent(bool show)
218 if(show) {
219 ui.labelDetails->setText(tr("This is the absolute up to the minute "
220 "Rockbox built. A current build will get updated every time "
221 "a change is made. Latest version is r%1 (%2).")
222 .arg(version.value("bleed_rev"), version.value("bleed_date")));
223 if(version.value("rel_rev").isEmpty())
224 ui.labelNote->setText(tr("<b>Note:</b> This option will always "
225 "download a fresh copy. "
226 "<b>This is the recommended version.</b>"));
227 else
228 ui.labelNote->setText(tr("<b>Note:</b> This option will always "
229 "download a fresh copy."));
234 void Install::setDetailsStable(bool show)
236 if(show) {
237 ui.labelDetails->setText(
238 tr("This is the last released version of Rockbox."));
240 if(!version.value("rel_rev").isEmpty())
241 ui.labelNote->setText(tr("<b>Note:</b>"
242 "The lastest released version is %1. "
243 "<b>This is the recommended version.</b>")
244 .arg(version.value("rel_rev")));
245 else ui.labelNote->setText("");
250 void Install::setDetailsArchived(bool show)
252 if(show) {
253 ui.labelDetails->setText(tr("These are automatically built each day "
254 "from the current development source code. This generally has more "
255 "features than the last stable release but may be much less stable. "
256 "Features may change regularly."));
257 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
258 .arg(version.value("arch_rev"), version.value("arch_date")));
264 void Install::setVersionStrings(QMap<QString, QString> ver)
266 version = ver;
267 // version strings map is as following:
268 // rel_rev release version revision id
269 // rel_date release version release date
270 // same for arch_* and bleed_*
272 if(version.value("arch_rev").isEmpty()) {
273 ui.radioArchived->setEnabled(false);
274 qDebug() << "no information about archived version available!";
277 if(!version.value("rel_rev").isEmpty()) {
278 ui.radioStable->setChecked(true);
279 ui.radioStable->setEnabled(true);
280 QFont font;
281 font.setBold(true);
282 ui.radioStable->setFont(font);
284 else {
285 ui.radioCurrent->setChecked(true);
286 ui.radioStable->setEnabled(false);
287 ui.radioStable->setChecked(false);
288 QFont font;
289 font.setBold(true);
290 ui.radioCurrent->setFont(font);
292 qDebug() << "Install::setVersionStrings" << version;