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_installthemesfrm.h"
23 #include "installthemes.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
.themePreview
->clear();
34 ui
.themePreview
->setText(tr("no theme selected"));
36 connect(ui
.buttonCancel
, SIGNAL(clicked()), this, SLOT(close()));
37 connect(ui
.buttonOk
, SIGNAL(clicked()), this, SLOT(accept()));
41 QString
ThemesInstallWindow::resolution()
44 devices
->beginGroup(userSettings
->value("defaults/platform").toString());
45 resolution
= devices
->value("resolution").toString();
51 void ThemesInstallWindow::setDeviceSettings(QSettings
*dev
)
54 qDebug() << "setDeviceSettings()" << devices
;
58 void ThemesInstallWindow::setUserSettings(QSettings
*user
)
64 void ThemesInstallWindow::downloadInfo()
66 // try to get the current build information
67 getter
= new HttpGet(this);
68 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
70 qDebug() << "downloading themes info";
72 qDebug() << "file:" << themesInfo
.fileName();
76 url
= QUrl(devices
->value("themes_url").toString() + "/rbutilqt.php?res=" + resolution());
77 qDebug() << "downloadInfo()" << url
;
78 qDebug() << url
.queryItems();
79 getter
->setProxy(proxy
);
80 getter
->setFile(&themesInfo
);
85 void ThemesInstallWindow::downloadDone(int id
, bool error
)
88 qDebug() << "downloadDone(bool) =" << id
<< error
;
92 void ThemesInstallWindow::downloadDone(bool error
)
94 qDebug() << "downloadDone(bool) =" << error
;
96 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
97 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
100 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
101 QStringList tl
= iniDetails
.childGroups();
102 qDebug() << tl
.size();
103 qDebug() << iniDetails
.value("error/code").toString()
104 << iniDetails
.value("error/description").toString()
105 << iniDetails
.value("error/query").toString();
108 logger
->addItem(tr("Network error: %1.\nPlease check your network and proxy settings.")
109 .arg(getter
->errorString()), LOGERROR
);
112 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
113 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
116 // handle possible error codes
117 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
118 qDebug() << "error!";
119 logger
->addItem(tr("the following error occured:\n%1")
120 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
122 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
125 logger
->addItem(tr("done."), LOGOK
);
130 for(int i
= 0; i
< tl
.size(); i
++) {
131 iniDetails
.beginGroup(tl
.at(i
));
132 // skip all themes without name field set (i.e. error section)
133 if(iniDetails
.value("name").toString().isEmpty()) continue;
134 QListWidgetItem
*w
= new QListWidgetItem
;
135 w
->setData(Qt::DisplayRole
, iniDetails
.value("name").toString());
136 w
->setData(Qt::UserRole
, tl
.at(i
));
137 ui
.listThemes
->addItem(w
);
139 iniDetails
.endGroup();
141 connect(ui
.listThemes
, SIGNAL(currentRowChanged(int)), this, SLOT(updateDetails(int)));
145 void ThemesInstallWindow::updateDetails(int row
)
147 if(row
== currentItem
) return;
150 qDebug() << "updateDetails(int) =" << row
;
151 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
152 ui
.themeDescription
->setText(tr("fetching details for %1")
153 .arg(ui
.listThemes
->item(row
)->data(Qt::DisplayRole
).toString()));
154 ui
.themePreview
->clear();
155 ui
.themePreview
->setText(tr("fetching preview ..."));
159 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
160 size
+= iniDetails
.value("size").toInt();
161 qDebug() << ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString() << size
;
162 iniDetails
.endGroup();
163 ui
.labelSize
->setText(tr("Download size %1 kiB").arg(size
));
165 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
168 txt
= QUrl(QString(devices
->value("themes_url").toString() + "/"
169 + iniDetails
.value("descriptionfile").toString()));
170 img
= QUrl(QString(devices
->value("themes_url").toString() + "/"
171 + iniDetails
.value("image").toString()));
172 qDebug() << "txt:" << txt
;
173 qDebug() << "img:" << img
;
176 text
= tr("<b>Author:</b> %1<hr/>").arg(iniDetails
.value("author", tr("unknown")).toString());
177 text
+= tr("<b>Version:</b> %1<hr/>").arg(iniDetails
.value("version", tr("unknown")).toString());
178 text
+= tr("<b>Description:</b> %1<br/>").arg(iniDetails
.value("about", tr("no description")).toString());
179 ui
.themeDescription
->setHtml(text
);
180 iniDetails
.endGroup();
183 igetter
.setProxy(proxy
);
184 igetter
.getFile(img
);
185 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
189 void ThemesInstallWindow::updateImage(bool error
)
191 qDebug() << "updateImage(bool) =" << error
;
196 imgData
= igetter
.readAll();
197 if(imgData
.isNull()) return;
198 p
.loadFromData(imgData
);
200 ui
.themePreview
->clear();
201 ui
.themePreview
->setText(tr("no theme preview"));
204 ui
.themePreview
->setPixmap(p
);
209 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
211 qDebug() << "resizeEvent(QResizeEvent*) =" << e
;
215 img
.setHeight(ui
.themePreview
->height());
216 img
.setWidth(ui
.themePreview
->width());
218 p
.loadFromData(imgData
);
219 if(p
.isNull()) return;
220 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
221 ui
.themePreview
->setScaledContents(false);
222 ui
.themePreview
->setPixmap(p
);
227 void ThemesInstallWindow::show()
231 logger
= new ProgressLoggerGui(this);
233 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
234 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
235 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
239 void ThemesInstallWindow::abort()
247 void ThemesInstallWindow::setProxy(QUrl p
)
250 qDebug() << "setProxy()" << proxy
;
254 void ThemesInstallWindow::accept()
256 if(ui
.listThemes
->selectedItems().size() == 0) {
263 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
264 for(int i
= 0; i
< ui
.listThemes
->selectedItems().size(); i
++) {
265 iniDetails
.beginGroup(ui
.listThemes
->selectedItems().at(i
)->data(Qt::UserRole
).toString());
266 zip
= devices
->value("themes_url").toString() + "/" + iniDetails
.value("archive").toString();
268 names
.append("Theme: " + ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
269 iniDetails
.endGroup();
271 qDebug() << "installing themes:" << themes
;
273 logger
= new ProgressLoggerGui(this);
275 QString mountPoint
= userSettings
->value("defaults/mountpoint").toString();
276 qDebug() << "mountpoint:" << userSettings
->value("defaults/mountpoint").toString();
277 // show dialog with error if mount point is wrong
278 if(!QFileInfo(mountPoint
).isDir()) {
279 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
284 installer
= new ZipInstaller(this);
285 installer
->setUrl(themes
);
286 installer
->setProxy(proxy
);
287 installer
->setLogSection(names
);
288 installer
->setMountPoint(mountPoint
);
289 installer
->install(logger
);
290 connect(logger
, SIGNAL(closed()), this, SLOT(close()));