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 ****************************************************************************/
24 #include "ui_rbutilqtfrm.h"
25 #include "ui_aboutbox.h"
26 #include "configure.h"
28 #include "installbl.h"
30 #include "installbootloader.h"
31 #include "installzipwindow.h"
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);
48 qDebug() << "using built-in rbutil.ini";
49 devices
= new QSettings(":/ini/rbutil.ini", QSettings::IniFormat
, 0);
55 // portable installation:
56 // check for a configuration file in the program folder.
58 config
.setFile(absolutePath
+ "RockboxUtility.ini");
60 userSettings
= new QSettings(absolutePath
+ "RockboxUtility.ini",
61 QSettings::IniFormat
, 0);
62 qDebug() << "config: portable";
65 userSettings
= new QSettings(QSettings::IniFormat
,
66 QSettings::UserScope
, "rockbox.org", "RockboxUtility");
67 qDebug() << "config: system";
70 userSettings
->beginGroup("defaults");
71 platform
= userSettings
->value("platform").toString();
72 userSettings
->endGroup();
73 ui
.comboBoxDevice
->setCurrentIndex(ui
.comboBoxDevice
->findData(platform
));
74 updateDevice(ui
.comboBoxDevice
->currentIndex());
76 connect(ui
.actionAbout_Qt
, SIGNAL(triggered()), qApp
, SLOT(aboutQt()));
77 connect(ui
.action_About
, SIGNAL(triggered()), this, SLOT(about()));
78 connect(ui
.action_Configure
, SIGNAL(triggered()), this, SLOT(configDialog()));
79 connect(ui
.comboBoxDevice
, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDevice(int)));
80 connect(ui
.buttonRockbox
, SIGNAL(clicked()), this, SLOT(install()));
81 connect(ui
.buttonBootloader
, SIGNAL(clicked()), this, SLOT(installBl()));
82 connect(ui
.buttonFonts
, SIGNAL(clicked()), this, SLOT(installFonts()));
83 connect(ui
.buttonGames
, SIGNAL(clicked()), this, SLOT(installDoom()));
85 // disable unimplemented stuff
86 ui
.buttonThemes
->setEnabled(false);
87 ui
.buttonSmall
->setEnabled(false);
88 ui
.buttonRemoveRockbox
->setEnabled(false);
89 ui
.buttonRemoveBootloader
->setEnabled(false);
90 ui
.buttonComplete
->setEnabled(false);
91 ui
.buttonDetect
->setEnabled(false);
99 void RbUtilQt::downloadInfo()
101 // try to get the current build information
102 daily
= new HttpGet(this);
103 connect(daily
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
104 connect(daily
, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
105 if(userSettings
->value("defaults/proxytype") == "manual")
106 daily
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
108 else if(userSettings
->value("defaults/proxytype") == "system")
109 daily
->setProxy(QUrl(getenv("http_proxy")));
112 qDebug() << "downloading build info";
113 daily
->setFile(&buildInfo
);
114 daily
->getFile(QUrl(devices
->value("server_conf_url").toString()));
118 void RbUtilQt::downloadDone(bool error
)
120 if(error
) qDebug() << "network error:" << daily
->error();
121 qDebug() << "network status:" << daily
->error();
126 void RbUtilQt::downloadDone(int id
, bool error
)
129 errorString
= tr("Network error: %1. Please check your network and proxy settings.").arg(daily
->errorString());
130 if(error
) QMessageBox::about(this, "Network Error", errorString
);
131 qDebug() << "downloadDone:" << id
<< error
;
135 void RbUtilQt::about()
137 QDialog
*window
= new QDialog
;
139 about
.setupUi(window
);
141 QFile
licence(":/docs/gpl-2.0.html");
142 licence
.open(QIODevice::ReadOnly
);
143 QTextStream
c(&licence
);
144 QString cline
= c
.readAll();
145 about
.browserLicense
->insertHtml(cline
);
146 about
.browserLicense
->moveCursor(QTextCursor::Start
, QTextCursor::MoveAnchor
);
147 QFile
credits(":/docs/CREDITS");
148 credits
.open(QIODevice::ReadOnly
);
149 QTextStream
r(&credits
);
150 QString rline
= r
.readAll();
151 about
.browserCredits
->insertPlainText(rline
);
152 about
.browserCredits
->moveCursor(QTextCursor::Start
, QTextCursor::MoveAnchor
);
153 QString title
= QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION
);
154 about
.labelTitle
->setText(title
);
161 void RbUtilQt::configDialog()
163 Config
*cw
= new Config(this);
164 cw
->setUserSettings(userSettings
);
166 connect(cw
, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
170 void RbUtilQt::initDeviceNames()
172 qDebug() << "RbUtilQt::initDeviceNames()";
173 devices
->beginGroup("platforms");
174 QStringList a
= devices
->childKeys();
177 for(int it
= 0; it
< a
.size(); it
++) {
179 devices
->beginGroup("platforms");
180 curdev
= devices
->value(a
.at(it
), "null").toString();
183 devices
->beginGroup(curdev
);
184 curname
= devices
->value("name", "null").toString();
186 ui
.comboBoxDevice
->addItem(curname
, curdev
);
191 void RbUtilQt::updateDevice(int index
)
193 platform
= ui
.comboBoxDevice
->itemData(index
).toString();
194 userSettings
->setValue("defaults/platform", platform
);
195 userSettings
->sync();
197 devices
->beginGroup(platform
);
198 if(devices
->value("needsbootloader", "") == "no") {
199 ui
.buttonBootloader
->setEnabled(false);
200 ui
.buttonRemoveBootloader
->setEnabled(false);
201 ui
.labelBootloader
->setEnabled(false);
202 ui
.labelRemoveBootloader
->setEnabled(false);
205 ui
.buttonBootloader
->setEnabled(true);
206 ui
.labelBootloader
->setEnabled(true);
207 if(devices
->value("bootloadermethod") == "fwpatcher") {
208 ui
.labelRemoveBootloader
->setEnabled(false);
209 ui
.buttonRemoveBootloader
->setEnabled(false);
212 ui
.labelRemoveBootloader
->setEnabled(true);
213 ui
.buttonRemoveBootloader
->setEnabled(true);
218 qDebug() << "new device selected:" << platform
;
222 void RbUtilQt::install()
224 Install
*installWindow
= new Install(this);
225 installWindow
->setUserSettings(userSettings
);
226 installWindow
->setDeviceSettings(devices
);
227 if(userSettings
->value("defaults/proxytype") == "manual")
228 installWindow
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
230 else if(userSettings
->value("defaults/proxytype") == "system")
231 installWindow
->setProxy(QUrl(getenv("http_proxy")));
233 installWindow
->setMountPoint(userSettings
->value("defaults/mountpoint").toString());
236 QSettings
info(buildInfo
.fileName(), QSettings::IniFormat
, this);
238 installWindow
->setArchivedString(info
.value("dailies/date").toString());
240 devices
->beginGroup(platform
);
241 QString released
= devices
->value("released").toString();
243 if(released
== "yes")
244 installWindow
->setReleased(devices
->value("last_release", "").toString());
246 installWindow
->setReleased(0);
248 installWindow
->show();
251 void RbUtilQt::installBl()
253 InstallBl
*installWindow
= new InstallBl(this);
254 installWindow
->setUserSettings(userSettings
);
255 installWindow
->setDeviceSettings(devices
);
256 if(userSettings
->value("defaults/proxytype") == "manual")
257 installWindow
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
259 else if(userSettings
->value("defaults/proxytype") == "system")
260 installWindow
->setProxy(QUrl(getenv("http_proxy")));
262 installWindow
->setMountPoint(userSettings
->value("defaults/mountpoint").toString());
264 installWindow
->show();
267 void RbUtilQt::installFonts()
269 InstallZipWindow
* installWindow
= new InstallZipWindow(this);
270 installWindow
->setUserSettings(userSettings
);
271 installWindow
->setDeviceSettings(devices
);
272 if(userSettings
->value("defaults/proxytype") == "manual")
273 installWindow
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
275 else if(userSettings
->value("defaults/proxytype") == "system")
276 installWindow
->setProxy(QUrl(getenv("http_proxy")));
278 installWindow
->setMountPoint(userSettings
->value("defaults/mountpoint").toString());
279 installWindow
->setLogSection("Fonts");
280 installWindow
->setUrl(devices
->value("font_url").toString());
281 installWindow
->setWindowTitle("Font Installation");
282 installWindow
->show();
286 void RbUtilQt::installDoom()
288 InstallZipWindow
* installWindow
= new InstallZipWindow(this);
289 installWindow
->setUserSettings(userSettings
);
290 installWindow
->setDeviceSettings(devices
);
291 if(userSettings
->value("defaults/proxytype") == "manual")
292 installWindow
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
294 else if(userSettings
->value("defaults/proxytype") == "system")
295 installWindow
->setProxy(QUrl(getenv("http_proxy")));
297 installWindow
->setMountPoint(userSettings
->value("defaults/mountpoint").toString());
298 installWindow
->setLogSection("Doom");
299 installWindow
->setUrl(devices
->value("doom_url").toString());
300 installWindow
->setWindowTitle("Doom Installation");
301 installWindow
->show();