Move device and mountpoint selection to configuration to eliminate the need of asking...
[Rockbox.git] / rbutil / rbutilqt / rbutilqt.cpp
blob2e82b31335763c0657bdff859ad248f3984fc656
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 <QtGui>
22 #include "version.h"
23 #include "rbutilqt.h"
24 #include "ui_rbutilqtfrm.h"
25 #include "ui_aboutbox.h"
26 #include "configure.h"
27 #include "install.h"
28 #include "installbl.h"
29 #include "httpget.h"
30 #include "installbootloader.h"
31 #include "installzipwindow.h"
33 #ifdef __linux
34 #include <stdio.h>
35 #endif
37 RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
39 QString programPath = qApp->arguments().at(0);
40 absolutePath = QFileInfo(programPath).absolutePath() + "/";
41 // use built-in rbutil.ini if no external file in binary folder
42 QString iniFile = absolutePath + "rbutil.ini";
43 if(QFileInfo(iniFile).isFile()) {
44 qDebug() << "using external rbutil.ini";
45 devices = new QSettings(iniFile, QSettings::IniFormat, 0);
47 else {
48 qDebug() << "using built-in rbutil.ini";
49 devices = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat, 0);
52 ui.setupUi(this);
54 // portable installation:
55 // check for a configuration file in the program folder.
56 QFileInfo config;
57 config.setFile(absolutePath + "RockboxUtility.ini");
58 if(config.isFile()) {
59 userSettings = new QSettings(absolutePath + "RockboxUtility.ini",
60 QSettings::IniFormat, 0);
61 qDebug() << "config: portable";
63 else {
64 userSettings = new QSettings(QSettings::IniFormat,
65 QSettings::UserScope, "rockbox.org", "RockboxUtility");
66 qDebug() << "config: system";
69 // manual tab
70 ui.buttonDownloadManual->setEnabled(false);
71 updateManual();
72 updateDevice();
74 connect(ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
75 connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about()));
76 connect(ui.action_Configure, SIGNAL(triggered()), this, SLOT(configDialog()));
77 connect(ui.buttonChangeDevice, SIGNAL(clicked()), this, SLOT(configDialog()));
78 connect(ui.buttonRockbox, SIGNAL(clicked()), this, SLOT(install()));
79 connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBl()));
80 connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts()));
81 connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom()));
83 // disable unimplemented stuff
84 ui.buttonThemes->setEnabled(false);
85 ui.buttonSmall->setEnabled(false);
86 ui.buttonRemoveRockbox->setEnabled(false);
87 ui.buttonRemoveBootloader->setEnabled(false);
88 ui.buttonComplete->setEnabled(false);
90 initIpodpatcher();
91 downloadInfo();
96 void RbUtilQt::downloadInfo()
98 // try to get the current build information
99 daily = new HttpGet(this);
100 connect(daily, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
101 connect(daily, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
102 if(userSettings->value("defaults/proxytype") == "manual")
103 daily->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
104 #ifdef __linux
105 else if(userSettings->value("defaults/proxytype") == "system")
106 daily->setProxy(QUrl(getenv("http_proxy")));
107 #endif
109 qDebug() << "downloading build info";
110 daily->setFile(&buildInfo);
111 daily->getFile(QUrl(devices->value("server_conf_url").toString()));
115 void RbUtilQt::downloadDone(bool error)
117 if(error) qDebug() << "network error:" << daily->error();
118 qDebug() << "network status:" << daily->error();
123 void RbUtilQt::downloadDone(int id, bool error)
125 QString errorString;
126 errorString = tr("Network error: %1. Please check your network and proxy settings.")
127 .arg(daily->errorString());
128 if(error) QMessageBox::about(this, "Network Error", errorString);
129 qDebug() << "downloadDone:" << id << error;
133 void RbUtilQt::about()
135 QDialog *window = new QDialog(this);
136 Ui::aboutBox about;
137 about.setupUi(window);
138 window->setModal(true);
140 QFile licence(":/docs/gpl-2.0.html");
141 licence.open(QIODevice::ReadOnly);
142 QTextStream c(&licence);
143 QString cline = c.readAll();
144 about.browserLicense->insertHtml(cline);
145 about.browserLicense->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
146 QFile credits(":/docs/CREDITS");
147 credits.open(QIODevice::ReadOnly);
148 QTextStream r(&credits);
149 QString rline = r.readAll();
150 about.browserCredits->insertPlainText(rline);
151 about.browserCredits->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
152 QString title = QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION);
153 about.labelTitle->setText(title);
154 about.labelHomepage->setText("<a href='http://www.rockbox.org'>http://www.rockbox.org</a>");
156 window->show();
161 void RbUtilQt::configDialog()
163 Config *cw = new Config(this);
164 cw->setUserSettings(userSettings);
165 cw->setDevices(devices);
166 cw->show();
167 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
168 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
172 void RbUtilQt::updateSettings()
174 qDebug() << "updateSettings()";
175 updateDevice();
176 updateManual();
180 void RbUtilQt::updateDevice()
182 platform = userSettings->value("defaults/platform").toString();
183 // buttons
184 devices->beginGroup(platform);
185 if(devices->value("needsbootloader", "") == "no") {
186 ui.buttonBootloader->setEnabled(false);
187 ui.buttonRemoveBootloader->setEnabled(false);
188 ui.labelBootloader->setEnabled(false);
189 ui.labelRemoveBootloader->setEnabled(false);
191 else {
192 ui.buttonBootloader->setEnabled(true);
193 ui.labelBootloader->setEnabled(true);
194 if(devices->value("bootloadermethod") == "fwpatcher") {
195 ui.labelRemoveBootloader->setEnabled(false);
196 ui.buttonRemoveBootloader->setEnabled(false);
198 else {
199 ui.labelRemoveBootloader->setEnabled(true);
200 ui.buttonRemoveBootloader->setEnabled(true);
203 devices->endGroup();
204 // displayed device info
205 platform = userSettings->value("defaults/platform").toString();
206 QString mountpoint = userSettings->value("defaults/mountpoint").toString();
207 devices->beginGroup(platform);
208 QString brand = devices->value("brand").toString();
209 QString name = devices->value("name").toString();
210 devices->endGroup();
211 ui.labelDevice->setText(tr("<b>%1 %2</b> at <b>%3</b>")
212 .arg(brand, name, mountpoint));
216 void RbUtilQt::updateManual()
218 if(userSettings->value("defaults/platform").toString() != "")
220 devices->beginGroup(userSettings->value("defaults/platform").toString());
221 QString manual;
222 manual = devices->value("manualname", "").toString();
224 if(manual == "")
225 manual = "rockbox-" + devices->value("platform").toString();
226 devices->endGroup();
227 QString pdfmanual;
228 pdfmanual = devices->value("manual_url").toString() + "/" + manual + ".pdf";
229 QString htmlmanual;
230 htmlmanual = devices->value("manual_url").toString() + "/" + manual + "/rockbox-build.html";
231 ui.labelPdfManual->setText(tr("<a href='%1'>PDF Manual</a>")
232 .arg(pdfmanual));
233 ui.labelHtmlManual->setText(tr("<a href='%1'>HTML Manual (opens in browser)</a>")
234 .arg(htmlmanual));
236 else {
237 ui.labelPdfManual->setText(tr("Select a device for a link to the correct manual"));
238 ui.labelHtmlManual->setText(tr("<a href='%1'>Manual Overview</a>")
239 .arg("http://www.rockbox.org/manual.shtml"));
245 void RbUtilQt::install()
247 Install *installWindow = new Install(this);
248 installWindow->setUserSettings(userSettings);
249 installWindow->setDeviceSettings(devices);
250 if(userSettings->value("defaults/proxytype") == "manual")
251 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
252 #ifdef __linux
253 else if(userSettings->value("defaults/proxytype") == "system")
254 installWindow->setProxy(QUrl(getenv("http_proxy")));
255 #endif
256 installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
258 buildInfo.open();
259 QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
260 buildInfo.close();
261 installWindow->setArchivedString(info.value("dailies/date").toString());
263 devices->beginGroup(platform);
264 QString released = devices->value("released").toString();
265 devices->endGroup();
266 if(released == "yes")
267 installWindow->setReleased(devices->value("last_release", "").toString());
268 else
269 installWindow->setReleased(0);
271 installWindow->show();
275 void RbUtilQt::installBl()
277 InstallBl *installWindow = new InstallBl(this);
278 installWindow->setUserSettings(userSettings);
279 installWindow->setDeviceSettings(devices);
280 if(userSettings->value("defaults/proxytype") == "manual")
281 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
282 #ifdef __linux
283 else if(userSettings->value("defaults/proxytype") == "system")
284 installWindow->setProxy(QUrl(getenv("http_proxy")));
285 #endif
286 installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
288 installWindow->show();
292 void RbUtilQt::installFonts()
294 InstallZipWindow* installWindow = new InstallZipWindow(this);
295 installWindow->setUserSettings(userSettings);
296 installWindow->setDeviceSettings(devices);
297 if(userSettings->value("defaults/proxytype") == "manual")
298 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
299 #ifdef __linux
300 else if(userSettings->value("defaults/proxytype") == "system")
301 installWindow->setProxy(QUrl(getenv("http_proxy")));
302 #endif
303 installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
304 installWindow->setLogSection("Fonts");
305 installWindow->setUrl(devices->value("font_url").toString());
306 installWindow->setWindowTitle("Font Installation");
307 installWindow->show();
312 void RbUtilQt::installDoom()
314 InstallZipWindow* installWindow = new InstallZipWindow(this);
315 installWindow->setUserSettings(userSettings);
316 installWindow->setDeviceSettings(devices);
317 if(userSettings->value("defaults/proxytype") == "manual")
318 installWindow->setProxy(QUrl(userSettings->value("defaults/proxy").toString()));
319 #ifdef __linux
320 else if(userSettings->value("defaults/proxytype") == "system")
321 installWindow->setProxy(QUrl(getenv("http_proxy")));
322 #endif
323 installWindow->setMountPoint(userSettings->value("defaults/mountpoint").toString());
324 installWindow->setLogSection("Doom");
325 installWindow->setUrl(devices->value("doom_url").toString());
326 installWindow->setWindowTitle("Doom Installation");
327 installWindow->show();