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()));
40 ThemesInstallWindow::~ThemesInstallWindow()
43 recRmdir(infocachedir
);
46 QString
ThemesInstallWindow::resolution()
48 return settings
->curResolution();
52 void ThemesInstallWindow::downloadInfo()
54 // try to get the current build information
55 getter
= new HttpGet(this);
57 qDebug() << "downloading themes info";
59 qDebug() << "file:" << themesInfo
.fileName();
63 url
= QUrl(settings
->themeUrl() + "/rbutilqt.php?res=" + resolution());
64 qDebug() << "downloadInfo()" << url
;
65 qDebug() << url
.queryItems();
66 if(settings
->cacheOffline())
67 getter
->setCache(true);
68 getter
->setFile(&themesInfo
);
70 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
71 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
76 void ThemesInstallWindow::downloadDone(int id
, bool error
)
79 qDebug() << "downloadDone(bool) =" << id
<< error
;
83 void ThemesInstallWindow::downloadDone(bool error
)
85 qDebug() << "downloadDone(bool) =" << error
;
87 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
88 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
91 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
92 QStringList tl
= iniDetails
.childGroups();
93 qDebug() << tl
.size();
94 qDebug() << iniDetails
.value("error/code").toString()
95 << iniDetails
.value("error/description").toString()
96 << iniDetails
.value("error/query").toString();
99 logger
->addItem(tr("Network error: %1.\nPlease check your network and proxy settings.")
100 .arg(getter
->errorString()), LOGERROR
);
103 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
104 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
107 // handle possible error codes
108 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
109 qDebug() << "error!";
110 logger
->addItem(tr("the following error occured:\n%1")
111 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
113 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
116 logger
->addItem(tr("done."), LOGOK
);
121 for(int i
= 0; i
< tl
.size(); i
++) {
122 iniDetails
.beginGroup(tl
.at(i
));
123 // skip all themes without name field set (i.e. error section)
124 if(iniDetails
.value("name").toString().isEmpty()) continue;
125 QListWidgetItem
*w
= new QListWidgetItem
;
126 w
->setData(Qt::DisplayRole
, iniDetails
.value("name").toString());
127 w
->setData(Qt::UserRole
, tl
.at(i
));
128 ui
.listThemes
->addItem(w
);
130 iniDetails
.endGroup();
132 connect(ui
.listThemes
, SIGNAL(currentRowChanged(int)), this, SLOT(updateDetails(int)));
136 void ThemesInstallWindow::updateDetails(int row
)
138 if(row
== currentItem
) return;
141 qDebug() << "updateDetails(int) =" << row
;
142 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
143 ui
.themeDescription
->setText(tr("fetching details for %1")
144 .arg(ui
.listThemes
->item(row
)->data(Qt::DisplayRole
).toString()));
145 ui
.themePreview
->clear();
146 ui
.themePreview
->setText(tr("fetching preview ..."));
150 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
151 size
+= iniDetails
.value("size").toInt();
152 qDebug() << ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString() << size
;
153 iniDetails
.endGroup();
154 ui
.labelSize
->setText(tr("Download size %L1 kiB").arg(size
));
156 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
159 txt
= QUrl(QString(settings
->themeUrl() + "/"
160 + iniDetails
.value("descriptionfile").toString()));
161 img
= QUrl(QString(settings
->themeUrl() + "/"
162 + iniDetails
.value("image").toString()));
163 qDebug() << "txt:" << txt
;
164 qDebug() << "img:" << img
;
167 text
= tr("<b>Author:</b> %1<hr/>").arg(iniDetails
.value("author", tr("unknown")).toString());
168 text
+= tr("<b>Version:</b> %1<hr/>").arg(iniDetails
.value("version", tr("unknown")).toString());
169 text
+= tr("<b>Description:</b> %1<hr/>").arg(iniDetails
.value("about", tr("no description")).toString());
171 ui
.themeDescription
->setHtml(text
);
172 iniDetails
.endGroup();
175 if(!settings
->cacheDisabled())
176 igetter
.setCache(true);
181 infocachedir
= QDir::tempPath()+"rbutil-themeinfo";
182 QDir d
= QDir::temp();
183 d
.mkdir("rbutil-themeinfo");
185 igetter
.setCache(infocachedir
);
187 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
188 igetter
.getFile(img
);
192 void ThemesInstallWindow::updateImage(bool error
)
194 qDebug() << "updateImage(bool) =" << error
;
200 imgData
= igetter
.readAll();
201 if(imgData
.isNull()) return;
202 p
.loadFromData(imgData
);
204 ui
.themePreview
->clear();
205 ui
.themePreview
->setText(tr("no theme preview"));
208 ui
.themePreview
->setPixmap(p
);
213 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
215 qDebug() << "resizeEvent(QResizeEvent*) =" << e
;
219 img
.setHeight(ui
.themePreview
->height());
220 img
.setWidth(ui
.themePreview
->width());
222 p
.loadFromData(imgData
);
223 if(p
.isNull()) return;
224 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
225 ui
.themePreview
->setScaledContents(false);
226 ui
.themePreview
->setPixmap(p
);
231 void ThemesInstallWindow::show()
234 logger
= new ProgressLoggerGui(this);
236 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
238 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
245 void ThemesInstallWindow::abort()
253 void ThemesInstallWindow::accept()
255 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
= settings
->themeUrl()
267 + "/" + iniDetails
.value("archive").toString();
269 names
.append("Theme: " +
270 ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
271 // if no version info is available use installation (current) date
272 version
.append(iniDetails
.value("version",
273 QDate().currentDate().toString("yyyyMMdd")).toString());
274 iniDetails
.endGroup();
276 qDebug() << "installing themes:" << themes
;
278 logger
= new ProgressLoggerGui(this);
280 QString mountPoint
= settings
->mountpoint();
281 qDebug() << "mountpoint:" << mountPoint
;
282 // show dialog with error if mount point is wrong
283 if(!QFileInfo(mountPoint
).isDir()) {
284 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
289 installer
= new ZipInstaller(this);
290 installer
->setUrl(themes
);
291 installer
->setLogSection(names
);
292 installer
->setLogVersion(version
);
293 installer
->setMountPoint(mountPoint
);
294 if(!settings
->cacheDisabled())
295 installer
->setCache(true);
297 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
298 installer
->install(logger
);