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 ****************************************************************************/
20 #include "installwindow.h"
21 #include "ui_installfrm.h"
24 #include "rbsettings.h"
25 #include "serverinfo.h"
26 #include "systeminfo.h"
29 InstallWindow::InstallWindow(QWidget
*parent
) : QDialog(parent
)
33 connect(ui
.radioStable
, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
34 connect(ui
.radioCurrent
, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
35 connect(ui
.radioArchived
, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
36 connect(ui
.changeBackup
, SIGNAL(pressed()), this, SLOT(changeBackupPath()));
37 connect(ui
.backup
, SIGNAL(stateChanged(int)), this, SLOT(backupCheckboxChanged(int)));
39 //! check if rockbox is already installed
40 RockboxInfo
rbinfo(RbSettings::value(RbSettings::Mountpoint
).toString());
41 QString version
= rbinfo
.version();
45 ui
.Backupgroup
->show();
46 m_backupName
= RbSettings::value(RbSettings::Mountpoint
).toString();
47 if(!m_backupName
.endsWith("/")) m_backupName
+= "/";
48 m_backupName
+= ".backup/rockbox-backup-"+version
+".zip";
49 // for some reason the label doesn't return its final size yet.
50 // Delay filling ui.backupLocation until the checkbox is changed.
54 ui
.Backupgroup
->hide();
56 backupCheckboxChanged(Qt::Unchecked
);
59 if(ServerInfo::value(ServerInfo::DailyRevision
).toString().isEmpty()) {
60 ui
.radioArchived
->setEnabled(false);
61 qDebug() << "[Install] no information about archived version available!";
63 if(ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty()) {
64 ui
.radioStable
->setEnabled(false);
67 // try to use the old selection first. If no selection has been made
68 // in the past, use a preselection based on released status.
69 if(RbSettings::value(RbSettings::Build
).toString() == "stable"
70 && !ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty())
71 ui
.radioStable
->setChecked(true);
72 else if(RbSettings::value(RbSettings::Build
).toString() == "archived")
73 ui
.radioArchived
->setChecked(true);
74 else if(RbSettings::value(RbSettings::Build
).toString() == "current")
75 ui
.radioCurrent
->setChecked(true);
76 else if(!ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty()) {
77 ui
.radioStable
->setChecked(true);
78 ui
.radioStable
->setEnabled(true);
81 ui
.radioStable
->setFont(font
);
84 ui
.radioCurrent
->setChecked(true);
85 ui
.radioStable
->setEnabled(false);
86 ui
.radioStable
->setChecked(false);
89 ui
.radioCurrent
->setFont(font
);
95 void InstallWindow::resizeEvent(QResizeEvent
*e
)
99 // recalculate width of elided text.
100 updateBackupLocation();
104 void InstallWindow::updateBackupLocation(void)
106 ui
.backupLocation
->setText(QDir::toNativeSeparators(
107 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName
),
108 Qt::ElideMiddle
, ui
.backupLocation
->size().width())));
112 void InstallWindow::backupCheckboxChanged(int state
)
114 if(state
== Qt::Checked
)
116 ui
.backupLocation
->show();
117 ui
.changeBackup
->show();
118 // update backup location display.
119 updateBackupLocation();
123 ui
.backupLocation
->hide();
124 ui
.changeBackup
->hide();
129 void InstallWindow::accept()
131 logger
= new ProgressLoggerGui(this);
133 QString mountPoint
= RbSettings::value(RbSettings::Mountpoint
).toString();
134 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint
).toString();
135 // show dialog with error if mount point is wrong
136 if(!QFileInfo(mountPoint
).isDir()) {
137 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
138 logger
->setFinished();
143 QString buildname
= SystemInfo::value(SystemInfo::CurBuildserverModel
).toString();
144 if(ui
.radioStable
->isChecked()) {
145 file
= SystemInfo::value(SystemInfo::ReleaseUrl
).toString();
146 RbSettings::setValue(RbSettings::Build
, "stable");
147 myversion
= ServerInfo::value(ServerInfo::CurReleaseVersion
).toString();
149 else if(ui
.radioArchived
->isChecked()) {
150 file
= SystemInfo::value(SystemInfo::DailyUrl
).toString();
151 RbSettings::setValue(RbSettings::Build
, "archived");
152 myversion
= "r" + ServerInfo::value(ServerInfo::DailyRevision
).toString() + "-" + ServerInfo::value(ServerInfo::DailyDate
).toString();
154 else if(ui
.radioCurrent
->isChecked()) {
155 file
= SystemInfo::value(SystemInfo::BleedingUrl
).toString();
156 RbSettings::setValue(RbSettings::Build
, "current");
157 myversion
= "r" + ServerInfo::value(ServerInfo::BleedingRevision
).toString();
160 qDebug() << "[Install] no build selected -- this shouldn't happen";
163 file
.replace("%MODEL%", buildname
);
164 file
.replace("%RELVERSION%", ServerInfo::value(ServerInfo::CurReleaseVersion
).toString());
165 file
.replace("%REVISION%", ServerInfo::value(ServerInfo::DailyRevision
).toString());
166 file
.replace("%DATE%", ServerInfo::value(ServerInfo::DailyDate
).toString());
170 QString warning
= check(false);
171 if(!warning
.isEmpty())
173 if(QMessageBox::warning(this, tr("Really continue?"), warning
,
174 QMessageBox::Ok
| QMessageBox::Abort
, QMessageBox::Abort
)
175 == QMessageBox::Abort
)
177 logger
->addItem(tr("Aborted!"),LOGERROR
);
178 logger
->setFinished();
183 //! check if we should backup
184 if(ui
.backup
->isChecked())
186 logger
->addItem(tr("Beginning Backup..."),LOGINFO
);
188 //! create dir, if it doesnt exist
189 QFileInfo
backupFile(m_backupName
);
190 if(!QDir(backupFile
.path()).exists())
193 a
.mkpath(backupFile
.path());
198 connect(&backup
,SIGNAL(zipProgress(int,int)),logger
,SLOT(setProgress(int,int)));
199 if(backup
.createZip(m_backupName
,
200 RbSettings::value(RbSettings::Mountpoint
).toString() + "/.rockbox") == Zip::Ok
)
202 logger
->addItem(tr("Backup successful"),LOGOK
);
206 logger
->addItem(tr("Backup failed!"),LOGERROR
);
207 logger
->setFinished();
213 installer
= new ZipInstaller(this);
214 installer
->setUrl(file
);
215 installer
->setLogSection("Rockbox (Base)");
216 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool()
217 && !ui
.checkBoxCache
->isChecked())
219 installer
->setCache(true);
221 installer
->setLogVersion(myversion
);
222 installer
->setMountPoint(mountPoint
);
224 connect(installer
, SIGNAL(done(bool)), this, SLOT(done(bool)));
226 connect(installer
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
227 connect(installer
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
228 connect(installer
, SIGNAL(done(bool)), logger
, SLOT(setFinished()));
229 connect(logger
, SIGNAL(aborted()), installer
, SLOT(abort()));
230 installer
->install();
234 void InstallWindow::changeBackupPath()
236 QString backupString
= QFileDialog::getSaveFileName(this,
237 tr("Select Backup Filename"), m_backupName
, "*.zip");
238 // only update if a filename was entered, ignore if cancelled
239 if(!backupString
.isEmpty()) {
240 m_backupName
= backupString
;
241 updateBackupLocation();
246 // Zip installer has finished
247 void InstallWindow::done(bool error
)
249 qDebug() << "[Install] done, error:" << error
;
253 logger
->setFinished();
257 // no error, close the window, when the logger is closed
258 connect(logger
,SIGNAL(closed()),this,SLOT(close()));
259 // add platform info to log file for later detection
260 QSettings
installlog(RbSettings::value(RbSettings::Mountpoint
).toString()
261 + "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
262 installlog
.setValue("platform", RbSettings::value(RbSettings::Platform
).toString());
267 void InstallWindow::setDetailsCurrent(bool show
)
270 ui
.labelDetails
->setText(tr("This is the absolute up to the minute "
271 "Rockbox built. A current build will get updated every time "
272 "a change is made. Latest version is r%1 (%2).")
273 .arg(ServerInfo::value(ServerInfo::BleedingRevision
).toString(),ServerInfo::value(ServerInfo::BleedingDate
).toString()));
274 if(ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty())
275 ui
.labelNote
->setText(tr("<b>This is the recommended version.</b>"));
277 ui
.labelNote
->setText("");
282 void InstallWindow::setDetailsStable(bool show
)
285 ui
.labelDetails
->setText(
286 tr("This is the last released version of Rockbox."));
288 if(!ServerInfo::value(ServerInfo::CurReleaseVersion
).toString().isEmpty())
289 ui
.labelNote
->setText(tr("<b>Note:</b> "
290 "The lastest released version is %1. "
291 "<b>This is the recommended version.</b>")
292 .arg(ServerInfo::value(ServerInfo::CurReleaseVersion
).toString()));
293 else ui
.labelNote
->setText("");
298 void InstallWindow::setDetailsArchived(bool show
)
301 ui
.labelDetails
->setText(tr("These are automatically built each day "
302 "from the current development source code. This generally has more "
303 "features than the last stable release but may be much less stable. "
304 "Features may change regularly."));
305 ui
.labelNote
->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
306 .arg(ServerInfo::value(ServerInfo::DailyRevision
).toString(),ServerInfo::value(ServerInfo::DailyDate
).toString()));