summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/installwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/installwindow.cpp')
-rw-r--r--rbutil/rbutilqt/installwindow.cpp309
1 files changed, 309 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/installwindow.cpp b/rbutil/rbutilqt/installwindow.cpp
new file mode 100644
index 0000000000..eb0dbf228d
--- /dev/null
+++ b/rbutil/rbutilqt/installwindow.cpp
@@ -0,0 +1,309 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "installwindow.h"
21#include "ui_installfrm.h"
22#include "rbzip.h"
23#include "system.h"
24#include "rbsettings.h"
25#include "utils.h"
26
27InstallWindow::InstallWindow(QWidget *parent) : QDialog(parent)
28{
29 ui.setupUi(this);
30
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)));
36
37 //! check if rockbox is already installed
38 RockboxInfo rbinfo(RbSettings::value(RbSettings::Mountpoint).toString());
39 QString version = rbinfo.version();
40
41 if(version != "")
42 {
43 ui.Backupgroup->show();
44 m_backupName = RbSettings::value(RbSettings::Mountpoint).toString();
45 if(!m_backupName.endsWith("/")) m_backupName += "/";
46 m_backupName += ".backup/rockbox-backup-"+version+".zip";
47 // for some reason the label doesn't return its final size yet.
48 // Delay filling ui.backupLocation until the checkbox is changed.
49 }
50 else
51 {
52 ui.Backupgroup->hide();
53 }
54 backupCheckboxChanged(Qt::Unchecked);
55
56
57 if(RbSettings::value(RbSettings::DailyRevision).toString().isEmpty()) {
58 ui.radioArchived->setEnabled(false);
59 qDebug() << "[Install] no information about archived version available!";
60 }
61 if(RbSettings::value(RbSettings::CurReleaseVersion).toString().isEmpty()) {
62 ui.radioStable->setEnabled(false);
63 }
64
65 // try to use the old selection first. If no selection has been made
66 // in the past, use a preselection based on released status.
67 if(RbSettings::value(RbSettings::Build).toString() == "stable"
68 && !RbSettings::value(RbSettings::CurReleaseVersion).toString().isEmpty())
69 ui.radioStable->setChecked(true);
70 else if(RbSettings::value(RbSettings::Build).toString() == "archived")
71 ui.radioArchived->setChecked(true);
72 else if(RbSettings::value(RbSettings::Build).toString() == "current")
73 ui.radioCurrent->setChecked(true);
74 else if(!RbSettings::value(RbSettings::CurReleaseVersion).toString().isEmpty()) {
75 ui.radioStable->setChecked(true);
76 ui.radioStable->setEnabled(true);
77 QFont font;
78 font.setBold(true);
79 ui.radioStable->setFont(font);
80 }
81 else {
82 ui.radioCurrent->setChecked(true);
83 ui.radioStable->setEnabled(false);
84 ui.radioStable->setChecked(false);
85 QFont font;
86 font.setBold(true);
87 ui.radioCurrent->setFont(font);
88 }
89
90}
91
92
93void InstallWindow::resizeEvent(QResizeEvent *e)
94{
95 (void)e;
96
97 // recalculate width of elided text.
98 updateBackupLocation();
99}
100
101
102void InstallWindow::updateBackupLocation(void)
103{
104 ui.backupLocation->setText(QDir::toNativeSeparators(
105 fontMetrics().elidedText(tr("Backup to %1").arg(m_backupName),
106 Qt::ElideMiddle, ui.backupLocation->size().width())));
107}
108
109
110void InstallWindow::backupCheckboxChanged(int state)
111{
112 if(state == Qt::Checked)
113 {
114 ui.backupLocation->show();
115 ui.changeBackup->show();
116 // update backup location display.
117 updateBackupLocation();
118 }
119 else
120 {
121 ui.backupLocation->hide();
122 ui.changeBackup->hide();
123 }
124}
125
126
127void InstallWindow::accept()
128{
129 logger = new ProgressLoggerGui(this);
130 logger->show();
131 QString mountPoint = RbSettings::value(RbSettings::Mountpoint).toString();
132 qDebug() << "[Install] mountpoint:" << RbSettings::value(RbSettings::Mountpoint).toString();
133 // show dialog with error if mount point is wrong
134 if(!QFileInfo(mountPoint).isDir()) {
135 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
136 logger->setFinished();
137 return;
138 }
139
140 QString myversion;
141 QString buildname = RbSettings::value(RbSettings::CurBuildserverModel).toString();
142 if(ui.radioStable->isChecked()) {
143 file = RbSettings::value(RbSettings::ReleaseUrl).toString();
144 RbSettings::setValue(RbSettings::Build, "stable");
145 myversion = RbSettings::value(RbSettings::CurReleaseVersion).toString();
146 }
147 else if(ui.radioArchived->isChecked()) {
148 file = RbSettings::value(RbSettings::DailyUrl).toString();
149 RbSettings::setValue(RbSettings::Build, "archived");
150 myversion = "r" + RbSettings::value(RbSettings::DailyRevision).toString() + "-" + RbSettings::value(RbSettings::DailyDate).toString();
151 }
152 else if(ui.radioCurrent->isChecked()) {
153 file = RbSettings::value(RbSettings::BleedingUrl).toString();
154 RbSettings::setValue(RbSettings::Build, "current");
155 myversion = "r" + RbSettings::value(RbSettings::BleedingRevision).toString();
156 }
157 else {
158 qDebug() << "[Install] no build selected -- this shouldn't happen";
159 return;
160 }
161 file.replace("%MODEL%", buildname);
162 file.replace("%RELVERSION%", RbSettings::value(RbSettings::CurReleaseVersion).toString());
163 file.replace("%REVISION%", RbSettings::value(RbSettings::DailyRevision).toString());
164 file.replace("%DATE%", RbSettings::value(RbSettings::DailyDate).toString());
165
166 RbSettings::sync();
167
168 QString warning = check(false);
169 if(!warning.isEmpty())
170 {
171 if(QMessageBox::warning(this, tr("Really continue?"), warning,
172 QMessageBox::Ok | QMessageBox::Abort, QMessageBox::Abort)
173 == QMessageBox::Abort)
174 {
175 logger->addItem(tr("Aborted!"),LOGERROR);
176 logger->setFinished();
177 return;
178 }
179 }
180
181 //! check if we should backup
182 if(ui.backup->isChecked())
183 {
184 logger->addItem(tr("Beginning Backup..."),LOGINFO);
185
186 //! create dir, if it doesnt exist
187 QFileInfo backupFile(m_backupName);
188 if(!QDir(backupFile.path()).exists())
189 {
190 QDir a;
191 a.mkpath(backupFile.path());
192 }
193
194 //! create backup
195 RbZip backup;
196 connect(&backup,SIGNAL(zipProgress(int,int)),logger,SLOT(setProgress(int,int)));
197 if(backup.createZip(m_backupName,
198 RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox") == Zip::Ok)
199 {
200 logger->addItem(tr("Backup successful"),LOGOK);
201 }
202 else
203 {
204 logger->addItem(tr("Backup failed!"),LOGERROR);
205 logger->setFinished();
206 return;
207 }
208 }
209
210 //! install build
211 installer = new ZipInstaller(this);
212 installer->setUrl(file);
213 installer->setLogSection("Rockbox (Base)");
214 if(!RbSettings::value(RbSettings::CacheDisabled).toBool()
215 && !ui.checkBoxCache->isChecked())
216 {
217 installer->setCache(true);
218 }
219 installer->setLogVersion(myversion);
220 installer->setMountPoint(mountPoint);
221
222 connect(installer, SIGNAL(done(bool)), this, SLOT(done(bool)));
223
224 connect(installer, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
225 connect(installer, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
226 connect(installer, SIGNAL(done(bool)), logger, SLOT(setFinished()));
227 connect(logger, SIGNAL(aborted()), installer, SLOT(abort()));
228 installer->install();
229
230}
231
232void InstallWindow::changeBackupPath()
233{
234 QString backupString = QFileDialog::getSaveFileName(this,
235 tr("Select Backup Filename"), m_backupName, "*.zip");
236 // only update if a filename was entered, ignore if cancelled
237 if(!backupString.isEmpty()) {
238 m_backupName = backupString;
239 updateBackupLocation();
240 }
241}
242
243
244// Zip installer has finished
245void InstallWindow::done(bool error)
246{
247 qDebug() << "[Install] done, error:" << error;
248
249 if(error)
250 {
251 logger->setFinished();
252 return;
253 }
254
255 // no error, close the window, when the logger is closed
256 connect(logger,SIGNAL(closed()),this,SLOT(close()));
257 // add platform info to log file for later detection
258 QSettings installlog(RbSettings::value(RbSettings::Mountpoint).toString()
259 + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
260 installlog.setValue("platform", RbSettings::value(RbSettings::Platform).toString());
261 installlog.sync();
262}
263
264
265void InstallWindow::setDetailsCurrent(bool show)
266{
267 if(show) {
268 ui.labelDetails->setText(tr("This is the absolute up to the minute "
269 "Rockbox built. A current build will get updated every time "
270 "a change is made. Latest version is r%1 (%2).")
271 .arg(RbSettings::value(RbSettings::BleedingRevision).toString(),RbSettings::value(RbSettings::BleedingDate).toString()));
272 if(RbSettings::value(RbSettings::CurReleaseVersion).toString().isEmpty())
273 ui.labelNote->setText(tr("<b>This is the recommended version.</b>"));
274 else
275 ui.labelNote->setText("");
276 }
277}
278
279
280void InstallWindow::setDetailsStable(bool show)
281{
282 if(show) {
283 ui.labelDetails->setText(
284 tr("This is the last released version of Rockbox."));
285
286 if(!RbSettings::value(RbSettings::CurReleaseVersion).toString().isEmpty())
287 ui.labelNote->setText(tr("<b>Note:</b> "
288 "The lastest released version is %1. "
289 "<b>This is the recommended version.</b>")
290 .arg(RbSettings::value(RbSettings::CurReleaseVersion).toString()));
291 else ui.labelNote->setText("");
292 }
293}
294
295
296void InstallWindow::setDetailsArchived(bool show)
297{
298 if(show) {
299 ui.labelDetails->setText(tr("These are automatically built each day "
300 "from the current development source code. This generally has more "
301 "features than the last stable release but may be much less stable. "
302 "Features may change regularly."));
303 ui.labelNote->setText(tr("<b>Note:</b> archived version is r%1 (%2).")
304 .arg(RbSettings::value(RbSettings::DailyRevision).toString(),RbSettings::value(RbSettings::DailyDate).toString()));
305 }
306}
307
308
309