test test test
[kugel-rb.git] / rbutil / rbutilqt / install.cpp
blob099575fec432f97da54bacf3af69186bcaef4107
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"
24 #include "rbsettings.h"
26 Install::Install(QWidget *parent) : QDialog(parent)
28 ui.setupUi(this);
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(RbSettings::value(RbSettings::Mountpoint).toString());
39 if(version != "")
41 ui.Backupgroup->show();
42 m_backupName = RbSettings::value(RbSettings::Mountpoint).toString();
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.
48 else
50 ui.Backupgroup->hide();
52 backupCheckboxChanged(Qt::Unchecked);
56 void Install::resizeEvent(QResizeEvent *e)
58 (void)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();
82 else
84 ui.backupLocation->hide();
85 ui.changeBackup->hide();
90 void Install::accept()
92 logger = new ProgressLoggerGui(this);
93 logger->show();
94 QString mountPoint = RbSettings::value(RbSettings::Mountpoint).toString();
95 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint).toString();
96 // show dialog with error if mount point is wrong
97 if(!QFileInfo(mountPoint).isDir()) {
98 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
99 logger->setFinished();
100 return;
103 QString myversion;
104 QString buildname = RbSettings::value(RbSettings::CurBuildserverModel).toString();
105 if(ui.radioStable->isChecked()) {
106 file = QString("%1/%2/rockbox-%3-%4.zip")
107 .arg(RbSettings::value(RbSettings::ReleaseUrl).toString(), 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 RbSettings::setValue(RbSettings::Build, "stable");
112 myversion = version.value("rel_rev");
114 else if(ui.radioArchived->isChecked()) {
115 file = QString("%1%2/rockbox-%3-%4.zip")
116 .arg(RbSettings::value(RbSettings::DailyUrl).toString(),
117 buildname, buildname, version.value("arch_date"));
118 fileName = QString("rockbox-%1-%2.zip")
119 .arg(buildname, version.value("arch_date"));
120 RbSettings::setValue(RbSettings::Build, "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(RbSettings::value(RbSettings::BleedingUrl).toString(), buildname);
126 fileName = QString("rockbox.zip");
127 RbSettings::setValue(RbSettings::Build, "current");
128 myversion = "r" + version.value("bleed_rev");
130 else {
131 qDebug() << "[Install] no build selected -- this shouldn't happen";
132 return;
134 RbSettings::sync();
136 QString warning = Detect::check(false);
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);
144 logger->setFinished();
145 return;
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())
158 QDir a;
159 a.mkpath(backupFile.path());
162 //! create backup
163 RbZip backup;
164 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
165 if(backup.createZip(m_backupName,
166 RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok)
168 logger->addItem(tr("Backup successful"),LOGOK);
170 else
172 logger->addItem(tr("Backup failed!"),LOGERROR);
173 logger->setFinished();
174 return;
178 //! install build
179 installer = new ZipInstaller(this);
180 installer->setUrl(file);
181 installer->setLogSection("Rockbox (Base)");
182 if(!RbSettings::value(RbSettings::CacheDisabled).toBool()
183 && !ui.checkBoxCache->isChecked())
185 installer->setCache(true);
187 installer->setLogVersion(myversion);
188 installer->setMountPoint(mountPoint);
190 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
192 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
193 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
194 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
195 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
196 installer->install();
200 void Install::changeBackupPath()
202 QString backupString = QFileDialog::getSaveFileName(this,
203 tr("Select Backup Filename"), m_backupName, "*.zip");
204 // only update if a filename was entered, ignore if cancelled
205 if(!backupString.isEmpty()) {
206 m_backupName = backupString;
207 updateBackupLocation();
212 // Zip installer has finished
213 void Install::done(bool error)
215 qDebug() << "[Install] done, error:" << error;
217 if(error)
219 logger->setFinished();
220 return;
223 // no error, close the window, when the logger is closed
224 connect(logger,SIGNAL(closed()),this,SLOT(close()));
225 // add platform info to log file for later detection
226 QSettings installlog(RbSettings::value(RbSettings::Mountpoint).toString()
227 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
228 installlog.setValue("platform", RbSettings::value(RbSettings::Platform).toString());
229 installlog.sync();
233 void Install::setDetailsCurrent(bool show)
235 if(show) {
236 ui.labelDetails->setText(tr("This is the absolute up to the minute "
237 "Rockbox built. A current build will get updated every time "
238 "a change is made. Latest version is r%1 (%2).")
239 .arg(version.value("bleed_rev"), version.value("bleed_date")));
240 if(version.value("rel_rev").isEmpty())
241 ui.labelNote->setText(tr("<b>This is the recommended version.</b>"));
242 else
243 ui.labelNote->setText("");
248 void Install::setDetailsStable(bool show)
250 if(show) {
251 ui.labelDetails->setText(
252 tr("This is the last released version of Rockbox."));
254 if(!version.value("rel_rev").isEmpty())
255 ui.labelNote->setText(tr("<b>Note:</b> "
256 "The lastest released version is %1. "
257 "<b>This is the recommended version.</b>")
258 .arg(version.value("rel_rev")));
259 else ui.labelNote->setText("");
264 void Install::setDetailsArchived(bool show)
266 if(show) {
267 ui.labelDetails->setText(tr("These are automatically built each day "
268 "from the current development source code. This generally has more "
269 "features than the last stable release but may be much less stable. "
270 "Features may change regularly."));
271 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
272 .arg(version.value("arch_rev"), version.value("arch_date")));
278 void Install::setVersionStrings(QMap<QString, QString>& ver)
280 version = ver;
281 // version strings map is as following:
282 // rel_rev release version revision id
283 // rel_date release version release date
284 // same for arch_* and bleed_*
286 if(version.value("arch_rev").isEmpty()) {
287 ui.radioArchived->setEnabled(false);
288 qDebug() << "[Install] no information about archived version available!";
290 if(version.value("rel_rev").isEmpty()) {
291 ui.radioStable->setEnabled(false);
294 // try to use the old selection first. If no selection has been made
295 // in the past, use a preselection based on released status.
296 if(RbSettings::value(RbSettings::Build).toString() == "stable"
297 && !version.value("rel_rev").isEmpty())
298 ui.radioStable->setChecked(true);
299 else if(RbSettings::value(RbSettings::Build).toString() == "archived")
300 ui.radioArchived->setChecked(true);
301 else if(RbSettings::value(RbSettings::Build).toString() == "current")
302 ui.radioCurrent->setChecked(true);
303 else if(!version.value("rel_rev").isEmpty()) {
304 ui.radioStable->setChecked(true);
305 ui.radioStable->setEnabled(true);
306 QFont font;
307 font.setBold(true);
308 ui.radioStable->setFont(font);
310 else {
311 ui.radioCurrent->setChecked(true);
312 ui.radioStable->setEnabled(false);
313 ui.radioStable->setChecked(false);
314 QFont font;
315 font.setBold(true);
316 ui.radioCurrent->setFont(font);
319 qDebug() << "[Install] setting version strings to:" << version;