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()));
38 connect(ui
.buttonOkAll
, SIGNAL(clicked()), this, SLOT(acceptAll()));
41 ThemesInstallWindow::~ThemesInstallWindow()
44 recRmdir(infocachedir
);
47 QString
ThemesInstallWindow::resolution()
50 devices
->beginGroup(userSettings
->value("platform").toString());
51 resolution
= devices
->value("resolution").toString();
57 void ThemesInstallWindow::setDeviceSettings(QSettings
*dev
)
60 qDebug() << "setDeviceSettings()" << devices
;
64 void ThemesInstallWindow::setUserSettings(QSettings
*user
)
70 void ThemesInstallWindow::downloadInfo()
72 // try to get the current build information
73 getter
= new HttpGet(this);
74 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
76 qDebug() << "downloading themes info";
78 qDebug() << "file:" << themesInfo
.fileName();
82 url
= QUrl(devices
->value("themes_url").toString() + "/rbutilqt.php?res=" + resolution());
83 qDebug() << "downloadInfo()" << url
;
84 qDebug() << url
.queryItems();
85 getter
->setProxy(proxy
);
86 if(userSettings
->value("offline").toBool())
87 getter
->setCache(userSettings
->value("cachepath", QDir::tempPath()).toString());
88 getter
->setFile(&themesInfo
);
93 void ThemesInstallWindow::downloadDone(int id
, bool error
)
96 qDebug() << "downloadDone(bool) =" << id
<< error
;
100 void ThemesInstallWindow::downloadDone(bool error
)
102 qDebug() << "downloadDone(bool) =" << error
;
104 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
105 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
108 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
109 QStringList tl
= iniDetails
.childGroups();
110 qDebug() << tl
.size();
111 qDebug() << iniDetails
.value("error/code").toString()
112 << iniDetails
.value("error/description").toString()
113 << iniDetails
.value("error/query").toString();
116 logger
->addItem(tr("Network error: %1.\nPlease check your network and proxy settings.")
117 .arg(getter
->errorString()), LOGERROR
);
120 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
121 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
124 // handle possible error codes
125 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
126 qDebug() << "error!";
127 logger
->addItem(tr("the following error occured:\n%1")
128 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
130 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
133 logger
->addItem(tr("done."), LOGOK
);
138 for(int i
= 0; i
< tl
.size(); i
++) {
139 iniDetails
.beginGroup(tl
.at(i
));
140 // skip all themes without name field set (i.e. error section)
141 if(iniDetails
.value("name").toString().isEmpty()) continue;
142 QListWidgetItem
*w
= new QListWidgetItem
;
143 w
->setData(Qt::DisplayRole
, iniDetails
.value("name").toString());
144 w
->setData(Qt::UserRole
, tl
.at(i
));
145 ui
.listThemes
->addItem(w
);
147 iniDetails
.endGroup();
149 connect(ui
.listThemes
, SIGNAL(currentRowChanged(int)), this, SLOT(updateDetails(int)));
153 void ThemesInstallWindow::updateDetails(int row
)
155 if(row
== currentItem
) return;
158 qDebug() << "updateDetails(int) =" << row
;
159 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
160 ui
.themeDescription
->setText(tr("fetching details for %1")
161 .arg(ui
.listThemes
->item(row
)->data(Qt::DisplayRole
).toString()));
162 ui
.themePreview
->clear();
163 ui
.themePreview
->setText(tr("fetching preview ..."));
167 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
168 size
+= iniDetails
.value("size").toInt();
169 qDebug() << ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString() << size
;
170 iniDetails
.endGroup();
171 ui
.labelSize
->setText(tr("Download size %L1 kiB").arg(size
));
173 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
176 txt
= QUrl(QString(devices
->value("themes_url").toString() + "/"
177 + iniDetails
.value("descriptionfile").toString()));
178 img
= QUrl(QString(devices
->value("themes_url").toString() + "/"
179 + iniDetails
.value("image").toString()));
180 qDebug() << "txt:" << txt
;
181 qDebug() << "img:" << img
;
184 text
= tr("<b>Author:</b> %1<hr/>").arg(iniDetails
.value("author", tr("unknown")).toString());
185 text
+= tr("<b>Version:</b> %1<hr/>").arg(iniDetails
.value("version", tr("unknown")).toString());
186 text
+= tr("<b>Description:</b> %1<hr/>").arg(iniDetails
.value("about", tr("no description")).toString());
188 ui
.themeDescription
->setHtml(text
);
189 iniDetails
.endGroup();
192 igetter
.setProxy(proxy
);
193 if(!userSettings
->value("cachedisable").toBool())
194 igetter
.setCache(userSettings
->value("cachepath", QDir::tempPath()).toString());
199 infocachedir
= QDir::tempPath()+"rbutil-themeinfo";
200 QDir d
= QDir::temp();
201 d
.mkdir("rbutil-themeinfo");
203 igetter
.setCache(infocachedir
);
205 igetter
.getFile(img
);
206 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
210 void ThemesInstallWindow::updateImage(bool error
)
212 qDebug() << "updateImage(bool) =" << error
;
217 imgData
= igetter
.readAll();
218 if(imgData
.isNull()) return;
219 p
.loadFromData(imgData
);
221 ui
.themePreview
->clear();
222 ui
.themePreview
->setText(tr("no theme preview"));
225 ui
.themePreview
->setPixmap(p
);
230 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
232 qDebug() << "resizeEvent(QResizeEvent*) =" << e
;
236 img
.setHeight(ui
.themePreview
->height());
237 img
.setWidth(ui
.themePreview
->width());
239 p
.loadFromData(imgData
);
240 if(p
.isNull()) return;
241 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
242 ui
.themePreview
->setScaledContents(false);
243 ui
.themePreview
->setPixmap(p
);
248 void ThemesInstallWindow::show()
252 logger
= new ProgressLoggerGui(this);
254 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
255 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
256 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
260 void ThemesInstallWindow::abort()
268 void ThemesInstallWindow::setProxy(QUrl p
)
271 qDebug() << "setProxy()" << proxy
;
275 void ThemesInstallWindow::acceptAll()
277 ui
.listThemes
->selectAll();
281 void ThemesInstallWindow::accept()
283 if(ui
.listThemes
->selectedItems().size() == 0) {
291 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
292 for(int i
= 0; i
< ui
.listThemes
->selectedItems().size(); i
++) {
293 iniDetails
.beginGroup(ui
.listThemes
->selectedItems().at(i
)->data(Qt::UserRole
).toString());
294 zip
= devices
->value("themes_url").toString()
295 + "/" + iniDetails
.value("archive").toString();
297 names
.append("Theme: " +
298 ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
299 // if no version info is available use installation (current) date
300 version
.append(iniDetails
.value("version",
301 QDate().currentDate().toString("yyyyMMdd")).toString());
302 iniDetails
.endGroup();
304 qDebug() << "installing themes:" << themes
;
306 logger
= new ProgressLoggerGui(this);
308 QString mountPoint
= userSettings
->value("mountpoint").toString();
309 qDebug() << "mountpoint:" << userSettings
->value("mountpoint").toString();
310 // show dialog with error if mount point is wrong
311 if(!QFileInfo(mountPoint
).isDir()) {
312 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
317 installer
= new ZipInstaller(this);
318 installer
->setUrl(themes
);
319 installer
->setProxy(proxy
);
320 installer
->setLogSection(names
);
321 installer
->setLogVersion(version
);
322 installer
->setMountPoint(mountPoint
);
323 if(!userSettings
->value("cachedisable").toBool())
324 installer
->setCache(userSettings
->value("cachepath", QDir::tempPath()).toString());
325 installer
->install(logger
);
326 connect(logger
, SIGNAL(closed()), this, SLOT(close()));