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 ****************************************************************************/
22 #include "ui_themesinstallfrm.h"
23 #include "themesinstallwindow.h"
24 #include "installzip.h"
25 #include "progressloggergui.h"
28 ThemesInstallWindow::ThemesInstallWindow(QWidget
*parent
) : QDialog(parent
)
31 ui
.listThemes
->setAlternatingRowColors(true);
32 ui
.listThemes
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
33 ui
.listThemes
->setSortingEnabled(true);
34 ui
.themePreview
->clear();
35 ui
.themePreview
->setText(tr("no theme selected"));
36 ui
.labelSize
->setText(tr("no selection"));
38 connect(ui
.buttonCancel
, SIGNAL(clicked()), this, SLOT(close()));
39 connect(ui
.buttonOk
, SIGNAL(clicked()), this, SLOT(accept()));
40 connect(ui
.listThemes
, SIGNAL(currentItemChanged(QListWidgetItem
*, QListWidgetItem
*)),
41 this, SLOT(updateDetails(QListWidgetItem
*, QListWidgetItem
*)));
42 connect(ui
.listThemes
, SIGNAL(itemSelectionChanged()), this, SLOT(updateSize()));
43 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
46 ThemesInstallWindow::~ThemesInstallWindow()
49 recRmdir(infocachedir
);
53 void ThemesInstallWindow::downloadInfo()
55 // try to get the current build information
56 getter
= new HttpGet(this);
58 qDebug() << "downloading themes info";
60 qDebug() << "file:" << themesInfo
.fileName();
64 url
= QUrl(settings
->themeUrl() + "/rbutilqt.php?target="
65 + settings
->curConfigure_Modelname());
66 qDebug() << "downloadInfo()" << url
;
67 qDebug() << url
.queryItems();
68 if(settings
->cacheOffline())
69 getter
->setCache(true);
70 getter
->setFile(&themesInfo
);
72 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
73 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
78 void ThemesInstallWindow::downloadDone(int id
, bool error
)
81 qDebug() << "downloadDone(bool) =" << id
<< error
;
85 void ThemesInstallWindow::downloadDone(bool error
)
87 qDebug() << "downloadDone(bool) =" << error
;
89 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
90 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
93 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
94 QStringList tl
= iniDetails
.childGroups();
95 qDebug() << iniDetails
.value("error/code").toString()
96 << iniDetails
.value("error/description").toString()
97 << iniDetails
.value("error/query").toString();
100 logger
->addItem(tr("Network error: %1.\n"
101 "Please check your network and proxy settings.")
102 .arg(getter
->errorString()), LOGERROR
);
105 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
106 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
109 // handle possible error codes
110 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
111 qDebug() << "error!";
112 logger
->addItem(tr("the following error occured:\n%1")
113 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
115 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
118 logger
->addItem(tr("done."), LOGOK
);
123 for(int i
= 0; i
< tl
.size(); i
++) {
124 iniDetails
.beginGroup(tl
.at(i
));
125 // skip all themes without name field set (i.e. error section)
126 if(iniDetails
.value("name").toString().isEmpty()) {
127 iniDetails
.endGroup();
130 qDebug() << "adding theme:" << tl
.at(i
);
131 // convert to unicode and replace HTML-specific entities
132 QByteArray raw
= iniDetails
.value("name").toByteArray();
133 QTextCodec
* codec
= QTextCodec::codecForHtml(raw
);
134 QString name
= codec
->toUnicode(raw
);
135 name
.replace(""", "\"").replace("&", "&");
136 name
.replace("<", "<").replace(">", ">");
137 QListWidgetItem
*w
= new QListWidgetItem
;
138 w
->setData(Qt::DisplayRole
, name
.trimmed());
139 w
->setData(Qt::UserRole
, tl
.at(i
));
140 ui
.listThemes
->addItem(w
);
142 iniDetails
.endGroup();
144 // check if there's a themes "MOTD" available
145 if(iniDetails
.contains("status/msg")) {
146 // check if there's a localized msg available
147 QString lang
= settings
->curLang().split("_").at(0);
149 if(iniDetails
.contains("status/msg." + lang
))
150 msg
= iniDetails
.value("status/msg." + lang
).toString();
152 msg
= iniDetails
.value("status/msg").toString();
153 qDebug() << "[Themes] MOTD" << msg
;
155 QMessageBox::information(this, tr("Information"), msg
);
160 void ThemesInstallWindow::updateSize(void)
163 // sum up size for all selected themes
164 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
165 int items
= ui
.listThemes
->selectedItems().size();
166 for(int i
= 0; i
< items
; i
++) {
167 iniDetails
.beginGroup(ui
.listThemes
->selectedItems()
168 .at(i
)->data(Qt::UserRole
).toString());
169 size
+= iniDetails
.value("size").toInt();
170 iniDetails
.endGroup();
172 ui
.labelSize
->setText(tr("Download size %L1 kiB (%n item(s))", "", items
)
173 .arg((size
+ 512) / 1024));
177 void ThemesInstallWindow::updateDetails(QListWidgetItem
* cur
, QListWidgetItem
* prev
)
182 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
184 QCoreApplication::processEvents();
185 ui
.themeDescription
->setText(tr("fetching details for %1")
186 .arg(cur
->data(Qt::DisplayRole
).toString()));
187 ui
.themePreview
->clear();
188 ui
.themePreview
->setText(tr("fetching preview ..."));
191 iniDetails
.beginGroup(cur
->data(Qt::UserRole
).toString());
194 txt
= QUrl(QString(settings
->themeUrl() + "/"
195 + iniDetails
.value("descriptionfile").toString()));
196 img
= QUrl(QString(settings
->themeUrl() + "/"
197 + iniDetails
.value("image").toString()));
200 QTextCodec
* codec
= QTextCodec::codecForName("UTF-8");
201 text
= tr("<b>Author:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
202 .value("author", tr("unknown")).toByteArray()));
203 text
+= tr("<b>Version:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
204 .value("version", tr("unknown")).toByteArray()));
205 text
+= tr("<b>Description:</b> %1<hr/>").arg(codec
->toUnicode(iniDetails
206 .value("about", tr("no description")).toByteArray()));
209 text
.replace("\n", "<br/>");
210 ui
.themeDescription
->setHtml(text
);
211 iniDetails
.endGroup();
214 if(!settings
->cacheDisabled())
215 igetter
.setCache(true);
220 infocachedir
= QDir::tempPath() + "rbutil-themeinfo";
221 QDir d
= QDir::temp();
222 d
.mkdir("rbutil-themeinfo");
224 igetter
.setCache(infocachedir
);
227 igetter
.getFile(img
);
231 void ThemesInstallWindow::updateImage(bool error
)
233 qDebug() << "updateImage(bool) =" << error
;
236 ui
.themePreview
->clear();
237 ui
.themePreview
->setText(tr("Retrieving theme preview failed.\n"
238 "HTTP response code: %1").arg(igetter
.httpResponse()));
244 imgData
= igetter
.readAll();
245 if(imgData
.isNull()) return;
246 p
.loadFromData(imgData
);
248 ui
.themePreview
->clear();
249 ui
.themePreview
->setText(tr("no theme preview"));
252 ui
.themePreview
->setPixmap(p
);
257 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
259 qDebug() << "resizeEvent(QResizeEvent*) =" << e
;
263 img
.setHeight(ui
.themePreview
->height());
264 img
.setWidth(ui
.themePreview
->width());
266 p
.loadFromData(imgData
);
267 if(p
.isNull()) return;
268 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
269 ui
.themePreview
->setScaledContents(false);
270 ui
.themePreview
->setPixmap(p
);
275 void ThemesInstallWindow::show()
278 logger
= new ProgressLoggerGui(this);
280 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
282 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
289 void ThemesInstallWindow::abort()
297 void ThemesInstallWindow::accept()
299 if(ui
.listThemes
->selectedItems().size() == 0) {
307 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
308 for(int i
= 0; i
< ui
.listThemes
->selectedItems().size(); i
++) {
309 iniDetails
.beginGroup(ui
.listThemes
->selectedItems().at(i
)->data(Qt::UserRole
).toString());
310 zip
= settings
->themeUrl()
311 + "/" + iniDetails
.value("archive").toString();
313 names
.append("Theme: " +
314 ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
315 // if no version info is available use installation (current) date
316 version
.append(iniDetails
.value("version",
317 QDate().currentDate().toString("yyyyMMdd")).toString());
318 iniDetails
.endGroup();
320 qDebug() << "installing themes:" << themes
;
322 logger
= new ProgressLoggerGui(this);
324 QString mountPoint
= settings
->mountpoint();
325 qDebug() << "mountpoint:" << mountPoint
;
326 // show dialog with error if mount point is wrong
327 if(!QFileInfo(mountPoint
).isDir()) {
328 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
333 installer
= new ZipInstaller(this);
334 installer
->setUrl(themes
);
335 installer
->setLogSection(names
);
336 installer
->setLogVersion(version
);
337 installer
->setMountPoint(mountPoint
);
338 if(!settings
->cacheDisabled())
339 installer
->setCache(true);
341 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
342 installer
->install(logger
);