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"
30 RbUtilQt::RbUtilQt(QWidget
*parent
) : QMainWindow(parent
)
32 QString programPath
= qApp
->arguments().at(0);
33 absolutePath
= QFileInfo(programPath
).absolutePath() + "/";
34 // use built-in rbutil.ini if no external file in binary folder
35 QString iniFile
= absolutePath
+ "rbutil.ini";
36 if(QFileInfo(iniFile
).isFile()) {
37 qDebug() << "using external rbutil.ini";
38 devices
= new QSettings(iniFile
, QSettings::IniFormat
, 0);
41 qDebug() << "using built-in rbutil.ini";
42 devices
= new QSettings(":/ini/rbutil.ini", QSettings::IniFormat
, 0);
48 // portable installation:
49 // check for a configuration file in the program folder.
51 config
.setFile(absolutePath
+ "RockboxUtility.ini");
53 userSettings
= new QSettings(absolutePath
+ "RockboxUtility.ini",
54 QSettings::IniFormat
, 0);
55 qDebug() << "config: portable";
58 userSettings
= new QSettings(QSettings::IniFormat
,
59 QSettings::UserScope
, "rockbox.org", "RockboxUtility");
60 qDebug() << "config: system";
63 userSettings
->beginGroup("defaults");
64 platform
= userSettings
->value("platform").toString();
65 userSettings
->endGroup();
66 ui
.comboBoxDevice
->setCurrentIndex(ui
.comboBoxDevice
->findData(platform
));
67 updateDevice(ui
.comboBoxDevice
->currentIndex());
69 connect(ui
.actionAbout_Qt
, SIGNAL(triggered()), qApp
, SLOT(aboutQt()));
70 connect(ui
.action_About
, SIGNAL(triggered()), this, SLOT(about()));
71 connect(ui
.action_Configure
, SIGNAL(triggered()), this, SLOT(configDialog()));
72 connect(ui
.comboBoxDevice
, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDevice(int)));
73 connect(ui
.buttonRockbox
, SIGNAL(clicked()), this, SLOT(install()));
75 // disable unimplemented stuff
76 ui
.buttonThemes
->setEnabled(false);
77 ui
.buttonSmall
->setEnabled(false);
78 ui
.buttonRemoveRockbox
->setEnabled(false);
79 ui
.buttonRemoveBootloader
->setEnabled(false);
80 ui
.buttonGames
->setEnabled(false);
81 ui
.buttonFonts
->setEnabled(false);
82 ui
.buttonComplete
->setEnabled(false);
89 void RbUtilQt::downloadInfo()
91 // try to get the current build information
92 daily
= new HttpGet(this);
93 connect(daily
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
94 connect(daily
, SIGNAL(requestFinished(int, bool)), this, SLOT(downloadDone(int, bool)));
95 if(userSettings
->value("defaults/proxytype") == "manual")
96 daily
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
98 qDebug() << "downloading build info";
99 daily
->setFile(&buildInfo
);
100 daily
->getFile(QUrl(devices
->value("server_conf_url").toString()));
104 void RbUtilQt::downloadDone(bool error
)
106 if(error
) qDebug() << "network error:" << daily
->error();
107 qDebug() << "network status:" << daily
->error();
112 void RbUtilQt::downloadDone(int id
, bool error
)
115 errorString
= tr("Network error: %1. Please check your network and proxy settings.").arg(daily
->errorString());
116 if(error
) QMessageBox::about(this, "Network Error", errorString
);
117 qDebug() << "downloadDone:" << id
<< error
;
121 void RbUtilQt::about()
123 QDialog
*window
= new QDialog
;
125 about
.setupUi(window
);
127 QFile
copy(":/docs/COPYING");
128 copy
.open(QIODevice::ReadOnly
);
129 QTextStream
c(©
);
130 QString cline
= c
.readAll();
131 about
.browserLicense
->insertPlainText(cline
);
132 about
.browserLicense
->moveCursor(QTextCursor::Start
, QTextCursor::MoveAnchor
);
133 QFile
credits(":/docs/CREDITS");
134 credits
.open(QIODevice::ReadOnly
);
135 QTextStream
r(&credits
);
136 QString rline
= r
.readAll();
137 about
.browserCredits
->insertPlainText(rline
);
138 about
.browserCredits
->moveCursor(QTextCursor::Start
, QTextCursor::MoveAnchor
);
139 QString title
= QString("<b>The Rockbox Utility</b> Version %1").arg(VERSION
);
140 about
.labelTitle
->setText(title
);
147 void RbUtilQt::configDialog()
149 Config
*cw
= new Config(this);
150 cw
->setUserSettings(userSettings
);
152 connect(cw
, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
156 void RbUtilQt::initDeviceNames()
158 qDebug() << "RbUtilQt::initDeviceNames()";
159 devices
->beginGroup("platforms");
160 QStringList a
= devices
->childKeys();
163 for(int it
= 0; it
< a
.size(); it
++) {
165 devices
->beginGroup("platforms");
166 curdev
= devices
->value(a
.at(it
), "null").toString();
169 devices
->beginGroup(curdev
);
170 curname
= devices
->value("name", "null").toString();
172 ui
.comboBoxDevice
->addItem(curname
, curdev
);
177 void RbUtilQt::updateDevice(int index
)
179 platform
= ui
.comboBoxDevice
->itemData(index
).toString();
180 userSettings
->setValue("defaults/platform", platform
);
181 userSettings
->sync();
183 devices
->beginGroup(platform
);
184 if(devices
->value("needsbootloader", "") == "no") {
185 ui
.buttonBootloader
->setEnabled(false);
186 ui
.buttonRemoveBootloader
->setEnabled(false);
187 ui
.labelBootloader
->setEnabled(false);
188 ui
.labelRemoveBootloader
->setEnabled(false);
191 ui
.buttonBootloader
->setEnabled(true);
192 ui
.labelBootloader
->setEnabled(true);
193 if(devices
->value("bootloadermethod") == "fwpatcher") {
194 ui
.labelRemoveBootloader
->setEnabled(false);
195 ui
.buttonRemoveBootloader
->setEnabled(false);
198 ui
.labelRemoveBootloader
->setEnabled(true);
199 ui
.buttonRemoveBootloader
->setEnabled(true);
204 qDebug() << "new device selected:" << platform
;
208 void RbUtilQt::install()
210 Install
*installWindow
= new Install(this);
211 installWindow
->setUserSettings(userSettings
);
212 installWindow
->setDeviceSettings(devices
);
213 if(userSettings
->value("defaults/proxytype") == "manual")
214 installWindow
->setProxy(QUrl(userSettings
->value("defaults/proxy").toString()));
215 installWindow
->setMountPoint(userSettings
->value("defaults/mountpoint").toString());
218 QSettings
info(buildInfo
.fileName(), QSettings::IniFormat
, this);
220 installWindow
->setArchivedString(info
.value("dailies/date").toString());
222 devices
->beginGroup(platform
);
223 QString released
= devices
->value("released").toString();
225 if(released
== "yes")
226 installWindow
->setReleased(devices
->value("last_release", "").toString());
228 installWindow
->setReleased(0);
230 installWindow
->show();