1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
21 #include "ui_themesinstallfrm.h"
22 #include "themesinstallwindow.h"
23 #include "zipinstaller.h"
24 #include "progressloggergui.h"
26 #include "rbsettings.h"
27 #include "systeminfo.h"
28 #include "rockboxinfo.h"
31 ThemesInstallWindow::ThemesInstallWindow(QWidget
*parent
) : QDialog(parent
)
34 ui
.listThemes
->setAlternatingRowColors(true);
35 ui
.listThemes
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
36 ui
.listThemes
->setSortingEnabled(true);
37 ui
.themePreview
->clear();
38 ui
.themePreview
->setText(tr("no theme selected"));
39 ui
.labelSize
->setText(tr("no selection"));
40 ui
.listThemes
->setLayoutDirection(Qt::LeftToRight
);
41 ui
.themeDescription
->setLayoutDirection(Qt::LeftToRight
);
43 connect(ui
.buttonCancel
, SIGNAL(clicked()), this, SLOT(close()));
44 connect(ui
.buttonOk
, SIGNAL(clicked()), this, SLOT(accept()));
45 connect(ui
.listThemes
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
46 this, SLOT(updateDetails(QListWidgetItem
*, QListWidgetItem
*)));
47 connect(ui
.listThemes
, SIGNAL(itemSelectionChanged()), this, SLOT(updateSize()));
48 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
53 ThemesInstallWindow::~ThemesInstallWindow()
56 Utils::recursiveRmdir(infocachedir
);
60 void ThemesInstallWindow::downloadInfo()
62 // try to get the current build information
63 getter
= new HttpGet(this);
64 RockboxInfo installInfo
65 = RockboxInfo(RbSettings::value(RbSettings::Mountpoint
).toString());
68 qDebug() << "[Themes] downloading info to" << themesInfo
.fileName();
71 QString infoUrl
= SystemInfo::value(SystemInfo::ThemesInfoUrl
).toString();
72 infoUrl
.replace("%TARGET%",
73 SystemInfo::value(SystemInfo::CurConfigureModel
).toString());
74 infoUrl
.replace("%REVISION%", installInfo
.revision());
75 infoUrl
.replace("%RELEASE%", installInfo
.release());
76 infoUrl
.replace("%RBUTILVER%", VERSION
);
77 QUrl url
= QUrl(infoUrl
);
78 qDebug() << "[Themes] Info URL:" << url
<< "Query:" << url
.queryItems();
79 if(RbSettings::value(RbSettings::CacheOffline
).toBool())
80 getter
->setCache(true);
81 getter
->setFile(&themesInfo
);
83 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
84 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
89 void ThemesInstallWindow::downloadDone(int id
, bool error
)
92 qDebug() << "[Themes] Download" << id
<< "done, error:" << error
;
96 void ThemesInstallWindow::downloadDone(bool error
)
98 qDebug() << "[Themes] Download done, error:" << error
;
100 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
101 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
104 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
105 QStringList tl
= iniDetails
.childGroups();
106 qDebug() << "[Themes] Theme site result:"
107 << iniDetails
.value("error/code").toString()
108 << iniDetails
.value("error/description").toString()
109 << iniDetails
.value("error/query").toString();
112 logger
->addItem(tr("Network error: %1.\n"
113 "Please check your network and proxy settings.")
114 .arg(getter
->errorString()), LOGERROR
);
116 logger
->setFinished();
117 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
118 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
121 // handle possible error codes
122 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
123 qDebug() << "[Themes] Theme site returned an error:"
124 << iniDetails
.value("error/code");
125 logger
->addItem(tr("the following error occured:\n%1")
126 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
127 logger
->setFinished();
128 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
131 logger
->addItem(tr("done."), LOGOK
);
132 logger
->setFinished();
136 for(int i
= 0; i
< tl
.size(); i
++) {
137 iniDetails
.beginGroup(tl
.at(i
));
138 // skip all themes without name field set (i.e. error section)
139 if(iniDetails
.value("name").toString().isEmpty()) {
140 iniDetails
.endGroup();
143 qDebug() << "[Themes] adding to list:" << tl
.at(i
);
144 // convert to unicode and replace HTML-specific entities
145 QByteArray raw
= iniDetails
.value("name").toByteArray();
146 QTextCodec
* codec
= QTextCodec::codecForHtml(raw
);
147 QString name
= codec
->toUnicode(raw
);
148 name
.replace(""", "\"").replace("&", "&");
149 name
.replace("<", "<").replace(">", ">");
150 QListWidgetItem
*w
= new QListWidgetItem
;
151 w
->setData(Qt::DisplayRole
, name
.trimmed());
152 w
->setData(Qt::UserRole
, tl
.at(i
));
153 ui
.listThemes
->addItem(w
);
155 iniDetails
.endGroup();
157 // check if there's a themes "MOTD" available
158 if(iniDetails
.contains("status/msg")) {
159 // check if there's a localized msg available
160 QString lang
= RbSettings::value(RbSettings::Language
).toString().split("_").at(0);
162 if(iniDetails
.contains("status/msg." + lang
))
163 msg
= iniDetails
.value("status/msg." + lang
).toString();
165 msg
= iniDetails
.value("status/msg").toString();
166 qDebug() << "[Themes] MOTD" << msg
;
168 QMessageBox::information(this, tr("Information"), msg
);
173 void ThemesInstallWindow::updateSize(void)
176 // sum up size for all selected themes
177 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
178 int items
= ui
.listThemes
->selectedItems().size();
179 for(int i
= 0; i
< items
; i
++) {
180 iniDetails
.beginGroup(ui
.listThemes
->selectedItems()
181 .at(i
)->data(Qt::UserRole
).toString());
182 size
+= iniDetails
.value("size").toInt();
183 iniDetails
.endGroup();
185 ui
.labelSize
->setText(tr("Download size %L1 kiB (%n item(s))", "", items
)
186 .arg((size
+ 512) / 1024));
190 void ThemesInstallWindow::updateDetails(QListWidgetItem
* cur
, QListWidgetItem
* prev
)
195 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
197 QCoreApplication::processEvents();
198 ui
.themeDescription
->setText(tr("fetching details for %1")
199 .arg(cur
->data(Qt::DisplayRole
).toString()));
200 ui
.themePreview
->clear();
201 ui
.themePreview
->setText(tr("fetching preview ..."));
204 iniDetails
.beginGroup(cur
->data(Qt::UserRole
).toString());
207 txt
= QUrl(QString(SystemInfo::value(SystemInfo::ThemesUrl
).toString() + "/"
208 + iniDetails
.value("descriptionfile").toString()));
209 img
= QUrl(QString(SystemInfo::value(SystemInfo::ThemesUrl
).toString() + "/"
210 + iniDetails
.value("image").toString()));
213 QTextCodec
* codec
= QTextCodec::codecForName("UTF-8");
214 text
= tr("<b>Author:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
215 .value("author", tr("unknown")).toByteArray()));
216 text
+= tr("<b>Version:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
217 .value("version", tr("unknown")).toByteArray()));
218 text
+= tr("<b>Description:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
219 .value("about", tr("no description")).toByteArray()));
221 text
.replace("\n", "<br/>");
222 ui
.themeDescription
->setHtml(text
);
223 iniDetails
.endGroup();
226 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool())
227 igetter
.setCache(true);
232 infocachedir
= QDir::tempPath() + "rbutil-themeinfo";
233 QDir d
= QDir::temp();
234 d
.mkdir("rbutil-themeinfo");
236 igetter
.setCache(infocachedir
);
239 igetter
.getFile(img
);
243 void ThemesInstallWindow::updateImage(bool error
)
245 qDebug() << "[Themes] Updating image:"<< !error
;
248 ui
.themePreview
->clear();
249 ui
.themePreview
->setText(tr("Retrieving theme preview failed.\n"
250 "HTTP response code: %1").arg(igetter
.httpResponse()));
256 imgData
= igetter
.readAll();
257 if(imgData
.isNull()) return;
258 p
.loadFromData(imgData
);
260 ui
.themePreview
->clear();
261 ui
.themePreview
->setText(tr("no theme preview"));
264 ui
.themePreview
->setPixmap(p
);
269 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
271 qDebug() << "[Themes]" << e
;
275 img
.setHeight(ui
.themePreview
->height());
276 img
.setWidth(ui
.themePreview
->width());
278 p
.loadFromData(imgData
);
279 if(p
.isNull()) return;
280 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
281 ui
.themePreview
->setScaledContents(false);
282 ui
.themePreview
->setPixmap(p
);
287 void ThemesInstallWindow::show()
291 ui
.buttonOk
->setText(tr("Select"));
293 logger
= new ProgressLoggerGui(this);
295 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
297 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
304 void ThemesInstallWindow::abort()
307 logger
->setFinished();
312 void ThemesInstallWindow::accept(void)
314 if(!windowSelectOnly
)
321 void ThemesInstallWindow::install()
323 if(ui
.listThemes
->selectedItems().size() == 0) {
331 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
332 for(int i
= 0; i
< ui
.listThemes
->selectedItems().size(); i
++) {
333 iniDetails
.beginGroup(ui
.listThemes
->selectedItems().at(i
)->data(Qt::UserRole
).toString());
334 zip
= SystemInfo::value(SystemInfo::ThemesUrl
).toString()
335 + "/" + iniDetails
.value("archive").toString();
337 names
.append("Theme: " +
338 ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
339 // if no version info is available use installation (current) date
340 version
.append(iniDetails
.value("version",
341 QDate().currentDate().toString("yyyyMMdd")).toString());
342 iniDetails
.endGroup();
344 qDebug() << "[Themes] installing:" << themes
;
347 logger
= new ProgressLoggerGui(this);
349 QString mountPoint
= RbSettings::value(RbSettings::Mountpoint
).toString();
350 qDebug() << "[Themes] mountpoint:" << mountPoint
;
351 // show dialog with error if mount point is wrong
352 if(!QFileInfo(mountPoint
).isDir()) {
353 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
354 logger
->setFinished();
358 installer
= new ZipInstaller(this);
359 installer
->setUrl(themes
);
360 installer
->setLogSection(names
);
361 installer
->setLogVersion(version
);
362 installer
->setMountPoint(mountPoint
);
363 if(!RbSettings::value(RbSettings::CacheDisabled
).toBool())
364 installer
->setCache(true);
366 if(!windowSelectOnly
) {
367 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
368 connect(installer
, SIGNAL(done(bool)), logger
, SLOT(setFinished()));
370 connect(installer
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
371 connect(installer
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
372 connect(installer
, SIGNAL(done(bool)), this, SIGNAL(done(bool)));
373 connect(logger
, SIGNAL(aborted()), installer
, SLOT(abort()));
374 installer
->install();
378 void ThemesInstallWindow::changeEvent(QEvent
*e
)
380 if(e
->type() == QEvent::LanguageChange
) {
381 ui
.retranslateUi(this);
383 QWidget::changeEvent(e
);