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()
49 return settings
->curResolution();
53 void ThemesInstallWindow::downloadInfo()
55 // try to get the current build information
56 getter
= new HttpGet(this);
57 connect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
59 qDebug() << "downloading themes info";
61 qDebug() << "file:" << themesInfo
.fileName();
65 url
= QUrl(settings
->themeUrl() + "/rbutilqt.php?res=" + resolution());
66 qDebug() << "downloadInfo()" << url
;
67 qDebug() << url
.queryItems();
68 if(settings
->cacheOffline())
69 getter
->setCache(true);
70 getter
->setFile(&themesInfo
);
75 void ThemesInstallWindow::downloadDone(int id
, bool error
)
78 qDebug() << "downloadDone(bool) =" << id
<< error
;
82 void ThemesInstallWindow::downloadDone(bool error
)
84 qDebug() << "downloadDone(bool) =" << error
;
86 disconnect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
87 disconnect(logger
, SIGNAL(aborted()), this, SLOT(close()));
90 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
91 QStringList tl
= iniDetails
.childGroups();
92 qDebug() << tl
.size();
93 qDebug() << iniDetails
.value("error/code").toString()
94 << iniDetails
.value("error/description").toString()
95 << iniDetails
.value("error/query").toString();
98 logger
->addItem(tr("Network error: %1.\nPlease check your network and proxy settings.")
99 .arg(getter
->errorString()), LOGERROR
);
102 disconnect(getter
, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
103 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
106 // handle possible error codes
107 if(iniDetails
.value("error/code").toInt() != 0 || !iniDetails
.contains("error/code")) {
108 qDebug() << "error!";
109 logger
->addItem(tr("the following error occured:\n%1")
110 .arg(iniDetails
.value("error/description", "unknown error").toString()), LOGERROR
);
112 connect(logger
, SIGNAL(closed()), this, SLOT(close()));
115 logger
->addItem(tr("done."), LOGOK
);
120 for(int i
= 0; i
< tl
.size(); i
++) {
121 iniDetails
.beginGroup(tl
.at(i
));
122 // skip all themes without name field set (i.e. error section)
123 if(iniDetails
.value("name").toString().isEmpty()) continue;
124 QListWidgetItem
*w
= new QListWidgetItem
;
125 w
->setData(Qt::DisplayRole
, iniDetails
.value("name").toString());
126 w
->setData(Qt::UserRole
, tl
.at(i
));
127 ui
.listThemes
->addItem(w
);
129 iniDetails
.endGroup();
131 connect(ui
.listThemes
, SIGNAL(currentRowChanged(int)), this, SLOT(updateDetails(int)));
135 void ThemesInstallWindow::updateDetails(int row
)
137 if(row
== currentItem
) return;
140 qDebug() << "updateDetails(int) =" << row
;
141 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
142 ui
.themeDescription
->setText(tr("fetching details for %1")
143 .arg(ui
.listThemes
->item(row
)->data(Qt::DisplayRole
).toString()));
144 ui
.themePreview
->clear();
145 ui
.themePreview
->setText(tr("fetching preview ..."));
149 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
150 size
+= iniDetails
.value("size").toInt();
151 qDebug() << ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString() << size
;
152 iniDetails
.endGroup();
153 ui
.labelSize
->setText(tr("Download size %L1 kiB").arg(size
));
155 iniDetails
.beginGroup(ui
.listThemes
->item(row
)->data(Qt::UserRole
).toString());
158 txt
= QUrl(QString(settings
->themeUrl() + "/"
159 + iniDetails
.value("descriptionfile").toString()));
160 img
= QUrl(QString(settings
->themeUrl() + "/"
161 + iniDetails
.value("image").toString()));
162 qDebug() << "txt:" << txt
;
163 qDebug() << "img:" << img
;
166 text
= tr("<b>Author:</b> %1<hr/>").arg(iniDetails
.value("author", tr("unknown")).toString());
167 text
+= tr("<b>Version:</b> %1<hr/>").arg(iniDetails
.value("version", tr("unknown")).toString());
168 text
+= tr("<b>Description:</b> %1<hr/>").arg(iniDetails
.value("about", tr("no description")).toString());
170 ui
.themeDescription
->setHtml(text
);
171 iniDetails
.endGroup();
174 if(!settings
->cacheDisabled())
175 igetter
.setCache(true);
180 infocachedir
= QDir::tempPath()+"rbutil-themeinfo";
181 QDir d
= QDir::temp();
182 d
.mkdir("rbutil-themeinfo");
184 igetter
.setCache(infocachedir
);
186 igetter
.getFile(img
);
187 connect(&igetter
, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
191 void ThemesInstallWindow::updateImage(bool error
)
193 qDebug() << "updateImage(bool) =" << error
;
198 imgData
= igetter
.readAll();
199 if(imgData
.isNull()) return;
200 p
.loadFromData(imgData
);
202 ui
.themePreview
->clear();
203 ui
.themePreview
->setText(tr("no theme preview"));
206 ui
.themePreview
->setPixmap(p
);
211 void ThemesInstallWindow::resizeEvent(QResizeEvent
* e
)
213 qDebug() << "resizeEvent(QResizeEvent*) =" << e
;
217 img
.setHeight(ui
.themePreview
->height());
218 img
.setWidth(ui
.themePreview
->width());
220 p
.loadFromData(imgData
);
221 if(p
.isNull()) return;
222 q
= p
.scaled(img
, Qt::KeepAspectRatio
, Qt::SmoothTransformation
);
223 ui
.themePreview
->setScaledContents(false);
224 ui
.themePreview
->setPixmap(p
);
229 void ThemesInstallWindow::show()
232 logger
= new ProgressLoggerGui(this);
234 logger
->addItem(tr("getting themes information ..."), LOGINFO
);
236 connect(logger
, SIGNAL(aborted()), getter
, SLOT(abort()));
237 connect(logger
, SIGNAL(aborted()), this, SLOT(close()));
241 void ThemesInstallWindow::abort()
249 void ThemesInstallWindow::acceptAll()
251 ui
.listThemes
->selectAll();
255 void ThemesInstallWindow::accept()
257 if(ui
.listThemes
->selectedItems().size() == 0) {
265 QSettings
iniDetails(themesInfo
.fileName(), QSettings::IniFormat
, this);
266 for(int i
= 0; i
< ui
.listThemes
->selectedItems().size(); i
++) {
267 iniDetails
.beginGroup(ui
.listThemes
->selectedItems().at(i
)->data(Qt::UserRole
).toString());
268 zip
= settings
->themeUrl()
269 + "/" + iniDetails
.value("archive").toString();
271 names
.append("Theme: " +
272 ui
.listThemes
->selectedItems().at(i
)->data(Qt::DisplayRole
).toString());
273 // if no version info is available use installation (current) date
274 version
.append(iniDetails
.value("version",
275 QDate().currentDate().toString("yyyyMMdd")).toString());
276 iniDetails
.endGroup();
278 qDebug() << "installing themes:" << themes
;
280 logger
= new ProgressLoggerGui(this);
282 QString mountPoint
= settings
->mountpoint();
283 qDebug() << "mountpoint:" << mountPoint
;
284 // show dialog with error if mount point is wrong
285 if(!QFileInfo(mountPoint
).isDir()) {
286 logger
->addItem(tr("Mount point is wrong!"),LOGERROR
);
291 installer
= new ZipInstaller(this);
292 installer
->setUrl(themes
);
293 installer
->setLogSection(names
);
294 installer
->setLogVersion(version
);
295 installer
->setMountPoint(mountPoint
);
296 if(!settings
->cacheDisabled())
297 installer
->setCache(true);
298 installer
->install(logger
);
299 connect(logger
, SIGNAL(closed()), this, SLOT(close()));