Use DBOP to check for left button on C200v2 like we are supposed to instead of right...
[kugel-rb.git] / rbutil / rbutilqt / installwindow.cpp
blob7b12303b96de2e4cfefac76b06710d7e45287317
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 "installwindow.h"
21 #include "ui_installwindowfrm.h"
22 #include "rbzip.h"
23 #include "system.h"
24 #include "rbsettings.h"
25 #include "serverinfo.h"
26 #include "systeminfo.h"
27 #include "utils.h"
28 #include "rockboxinfo.h"
30 InstallWindow::InstallWindow(QWidget *parent) : QDialog(parent)
32 ui.setupUi(this);
34 connect(ui.radioStable, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
35 connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
36 connect(ui.radioArchived, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
37 connect(ui.changeBackup, SIGNAL(pressed()), this, SLOT(changeBackupPath()));
38 connect(ui.backup, SIGNAL(stateChanged(int)), this, SLOT(backupCheckboxChanged(int)));
40 //! check if rockbox is already installed
41 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
42 QString version = rbinfo.version();
44 if(version != "")
46 ui.Backupgroup->show();
47 m_backupName = RbSettings::value(RbSettings::Mountpoint).toString();
48 if(!m_backupName.endsWith("/")) m_backupName += "/";
49 m_backupName += ".backup/rockbox-backup-"+version+".zip";
50 // for some reason the label doesn't return its final size yet.
51 // Delay filling ui.backupLocation until the checkbox is changed.
53 else
55 ui.Backupgroup->hide();
57 backupCheckboxChanged(Qt::Unchecked);
60 if(ServerInfo::value(ServerInfo::DailyRevision).toString().isEmpty()) {
61 ui.radioArchived->setEnabled(false);
62 qDebug() << "[Install] no information about archived version available!";
64 if(ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty()) {
65 ui.radioStable->setEnabled(false);
68 // try to use the old selection first. If no selection has been made
69 // in the past, use a preselection based on released status.
70 if(RbSettings::value(RbSettings::Build).toString() == "stable"
71 && !ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
72 ui.radioStable->setChecked(true);
73 else if(RbSettings::value(RbSettings::Build).toString() == "archived")
74 ui.radioArchived->setChecked(true);
75 else if(RbSettings::value(RbSettings::Build).toString() == "current")
76 ui.radioCurrent->setChecked(true);
77 else if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty()) {
78 ui.radioStable->setChecked(true);
79 ui.radioStable->setEnabled(true);
80 QFont font;
81 font.setBold(true);
82 ui.radioStable->setFont(font);
84 else {
85 ui.radioCurrent->setChecked(true);
86 ui.radioStable->setEnabled(false);
87 ui.radioStable->setChecked(false);
88 QFont font;
89 font.setBold(true);
90 ui.radioCurrent->setFont(font);
96 void InstallWindow::resizeEvent(QResizeEvent *e)
98 (void)e;
100 // recalculate width of elided text.
101 updateBackupLocation();
105 void InstallWindow::updateBackupLocation(void)
107 ui.backupLocation->setText(QDir::toNativeSeparators(
108 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName),
109 Qt::ElideMiddle, ui.backupLocation->size().width())));
113 void InstallWindow::backupCheckboxChanged(int state)
115 if(state == Qt::Checked)
117 ui.backupLocation->show();
118 ui.changeBackup->show();
119 // update backup location display.
120 updateBackupLocation();
122 else
124 ui.backupLocation->hide();
125 ui.changeBackup->hide();
130 void InstallWindow::accept()
132 logger = new ProgressLoggerGui(this);
133 logger->show();
134 QString mountPoint = RbSettings::value(RbSettings::Mountpoint).toString();
135 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint).toString();
136 // show dialog with error if mount point is wrong
137 if(!QFileInfo(mountPoint).isDir()) {
138 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
139 logger->setFinished();
140 return;
143 QString myversion;
144 QString buildname = SystemInfo::value(SystemInfo::CurBuildserverModel).toString();
145 if(ui.radioStable->isChecked()) {
146 file = SystemInfo::value(SystemInfo::ReleaseUrl).toString();
147 RbSettings::setValue(RbSettings::Build, "stable");
148 myversion = ServerInfo::value(ServerInfo::CurReleaseVersion).toString();
150 else if(ui.radioArchived->isChecked()) {
151 file = SystemInfo::value(SystemInfo::DailyUrl).toString();
152 RbSettings::setValue(RbSettings::Build, "archived");
153 myversion = "r" + ServerInfo::value(ServerInfo::DailyRevision).toString()
154 + "-" + ServerInfo::value(ServerInfo::DailyDate).toString();
156 else if(ui.radioCurrent->isChecked()) {
157 file = SystemInfo::value(SystemInfo::BleedingUrl).toString();
158 RbSettings::setValue(RbSettings::Build, "current");
159 myversion = "r" + ServerInfo::value(ServerInfo::BleedingRevision).toString();
161 else {
162 qDebug() << "[Install] no build selected -- this shouldn't happen";
163 return;
165 file.replace("%MODEL%", buildname);
166 file.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion).toString());
167 file.replace("%REVISION%", ServerInfo::value(ServerInfo::DailyRevision).toString());
168 file.replace("%DATE%", ServerInfo::value(ServerInfo::DailyDate).toString());
170 RbSettings::sync();
172 QString warning = Utils::checkEnvironment(false);
173 if(!warning.isEmpty())
175 if(QMessageBox::warning(this, tr("Really continue?"), warning,
176 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
177 == QMessageBox::Abort)
179 logger->addItem(tr("Aborted!"),LOGERROR);
180 logger->setFinished();
181 return;
185 //! check if we should backup
186 if(ui.backup->isChecked())
188 logger->addItem(tr("Beginning Backup..."),LOGINFO);
190 //! create dir, if it doesnt exist
191 QFileInfo backupFile(m_backupName);
192 if(!QDir(backupFile.path()).exists())
194 QDir a;
195 a.mkpath(backupFile.path());
198 //! create backup
199 RbZip backup;
200 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
201 if(backup.createZip(m_backupName,
202 RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok)
204 logger->addItem(tr("Backup successful"),LOGOK);
206 else
208 logger->addItem(tr("Backup failed!"),LOGERROR);
209 logger->setFinished();
210 return;
214 //! install build
215 installer = new ZipInstaller(this);
216 installer->setUrl(file);
217 installer->setLogSection("Rockbox (Base)");
218 if(!RbSettings::value(RbSettings::CacheDisabled).toBool()
219 && !ui.checkBoxCache->isChecked())
221 installer->setCache(true);
223 installer->setLogVersion(myversion);
224 installer->setMountPoint(mountPoint);
226 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
228 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
229 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
230 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
231 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
232 installer->install();
236 void InstallWindow::changeBackupPath()
238 QString backupString = QFileDialog::getSaveFileName(this,
239 tr("Select Backup Filename"), m_backupName, "*.zip");
240 // only update if a filename was entered, ignore if cancelled
241 if(!backupString.isEmpty()) {
242 m_backupName = backupString;
243 updateBackupLocation();
248 // Zip installer has finished
249 void InstallWindow::done(bool error)
251 qDebug() << "[Install] done, error:" << error;
253 if(error)
255 logger->setFinished();
256 return;
259 // no error, close the window, when the logger is closed
260 connect(logger,SIGNAL(closed()),this,SLOT(close()));
261 // add platform info to log file for later detection
262 QSettings installlog(RbSettings::value(RbSettings::Mountpoint).toString()
263 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
264 installlog.setValue("platform", RbSettings::value(RbSettings::Platform).toString());
265 installlog.sync();
269 void InstallWindow::setDetailsCurrent(bool show)
271 if(show) {
272 ui.labelDetails->setText(tr("This is the absolute up to the minute "
273 "Rockbox built. A current build will get updated every time "
274 "a change is made. Latest version is r%1 (%2).")
275 .arg(ServerInfo::value(ServerInfo::BleedingRevision).toString(),
276 ServerInfo::value(ServerInfo::BleedingDate).toString()));
277 if(ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
278 ui.labelNote->setText(tr("<b>This is the recommended version.</b>"));
279 else
280 ui.labelNote->setText("");
285 void InstallWindow::setDetailsStable(bool show)
287 if(show) {
288 ui.labelDetails->setText(
289 tr("This is the last released version of Rockbox."));
291 if(!ServerInfo::value(ServerInfo::CurReleaseVersion).toString().isEmpty())
292 ui.labelNote->setText(tr("<b>Note:</b> "
293 "The lastest released version is %1. "
294 "<b>This is the recommended version.</b>")
295 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion).toString()));
296 else ui.labelNote->setText("");
301 void InstallWindow::setDetailsArchived(bool show)
303 if(show) {
304 ui.labelDetails->setText(tr("These are automatically built each day "
305 "from the current development source code. This generally has more "
306 "features than the last stable release but may be much less stable. "
307 "Features may change regularly."));
308 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
309 .arg(ServerInfo::value(ServerInfo::DailyRevision).toString(),
310 ServerInfo::value(ServerInfo::DailyDate).toString()));