forked from len0rd/rockbox
Clean up theme size display.
- show the size and number of all selected themes instead of the selected one only - use currentItemChanged() signal instead of currentRowChanged() to simplify code a bit. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20587 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
83aa2d2b18
commit
246192b349
2 changed files with 32 additions and 23 deletions
|
|
@ -33,12 +33,13 @@ ThemesInstallWindow::ThemesInstallWindow(QWidget *parent) : QDialog(parent)
|
||||||
ui.listThemes->setSortingEnabled(true);
|
ui.listThemes->setSortingEnabled(true);
|
||||||
ui.themePreview->clear();
|
ui.themePreview->clear();
|
||||||
ui.themePreview->setText(tr("no theme selected"));
|
ui.themePreview->setText(tr("no theme selected"));
|
||||||
currentItem = -1;
|
ui.labelSize->setText(tr("no selection"));
|
||||||
|
|
||||||
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
|
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
|
||||||
connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
|
connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
connect(ui.listThemes, SIGNAL(currentRowChanged(int)),
|
connect(ui.listThemes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||||
this, SLOT(updateDetails(int)));
|
this, SLOT(updateDetails(QListWidgetItem*, QListWidgetItem*)));
|
||||||
|
connect(ui.listThemes, SIGNAL(itemSelectionChanged()), this, SLOT(updateSize()));
|
||||||
connect(&igetter, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
|
connect(&igetter, SIGNAL(done(bool)), this, SLOT(updateImage(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,35 +151,43 @@ void ThemesInstallWindow::downloadDone(bool error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ThemesInstallWindow::updateDetails(int row)
|
void ThemesInstallWindow::updateSize(void)
|
||||||
{
|
{
|
||||||
if(row == currentItem) return;
|
long size = 0;
|
||||||
|
// sum up size for all selected themes
|
||||||
currentItem = row;
|
|
||||||
qDebug() << "updateDetails(int) =" << row;
|
|
||||||
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
||||||
|
int items = ui.listThemes->selectedItems().size();
|
||||||
|
for(int i = 0; i < items; i++) {
|
||||||
|
iniDetails.beginGroup(ui.listThemes->selectedItems()
|
||||||
|
.at(i)->data(Qt::UserRole).toString());
|
||||||
|
size += iniDetails.value("size").toInt();
|
||||||
|
iniDetails.endGroup();
|
||||||
|
}
|
||||||
|
ui.labelSize->setText(tr("Download size %L1 kiB (%n item(s))", "", items)
|
||||||
|
.arg((size + 512) / 1024));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ThemesInstallWindow::updateDetails(QListWidgetItem* cur, QListWidgetItem* prev)
|
||||||
|
{
|
||||||
|
if(cur == prev)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
|
||||||
|
|
||||||
|
QCoreApplication::processEvents();
|
||||||
ui.themeDescription->setText(tr("fetching details for %1")
|
ui.themeDescription->setText(tr("fetching details for %1")
|
||||||
.arg(ui.listThemes->item(row)->data(Qt::DisplayRole).toString()));
|
.arg(cur->data(Qt::DisplayRole).toString()));
|
||||||
ui.themePreview->clear();
|
ui.themePreview->clear();
|
||||||
ui.themePreview->setText(tr("fetching preview ..."));
|
ui.themePreview->setText(tr("fetching preview ..."));
|
||||||
|
|
||||||
double size = 0;
|
iniDetails.beginGroup(cur->data(Qt::UserRole).toString());
|
||||||
|
|
||||||
iniDetails.beginGroup(ui.listThemes->item(row)->data(Qt::UserRole).toString());
|
|
||||||
size += iniDetails.value("size").toDouble();
|
|
||||||
qDebug() << ui.listThemes->item(row)->data(Qt::UserRole).toString() << size;
|
|
||||||
iniDetails.endGroup();
|
|
||||||
ui.labelSize->setText(tr("Download size %L1 kiB").arg(size));
|
|
||||||
|
|
||||||
iniDetails.beginGroup(ui.listThemes->item(row)->data(Qt::UserRole).toString());
|
|
||||||
|
|
||||||
QUrl img, txt;
|
QUrl img, txt;
|
||||||
txt = QUrl(QString(settings->themeUrl() + "/"
|
txt = QUrl(QString(settings->themeUrl() + "/"
|
||||||
+ iniDetails.value("descriptionfile").toString()));
|
+ iniDetails.value("descriptionfile").toString()));
|
||||||
img = QUrl(QString(settings->themeUrl() + "/"
|
img = QUrl(QString(settings->themeUrl() + "/"
|
||||||
+ iniDetails.value("image").toString()));
|
+ iniDetails.value("image").toString()));
|
||||||
qDebug() << "txt:" << txt;
|
|
||||||
qDebug() << "img:" << img;
|
|
||||||
|
|
||||||
QString text;
|
QString text;
|
||||||
text = tr("<b>Author:</b> %1<hr/>").arg(iniDetails.value("author",
|
text = tr("<b>Author:</b> %1<hr/>").arg(iniDetails.value("author",
|
||||||
|
|
@ -198,7 +207,7 @@ void ThemesInstallWindow::updateDetails(int row)
|
||||||
{
|
{
|
||||||
if(infocachedir=="")
|
if(infocachedir=="")
|
||||||
{
|
{
|
||||||
infocachedir = QDir::tempPath()+"rbutil-themeinfo";
|
infocachedir = QDir::tempPath() + "rbutil-themeinfo";
|
||||||
QDir d = QDir::temp();
|
QDir d = QDir::temp();
|
||||||
d.mkdir("rbutil-themeinfo");
|
d.mkdir("rbutil-themeinfo");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ class ThemesInstallWindow : public QDialog
|
||||||
HttpGet *getter;
|
HttpGet *getter;
|
||||||
HttpGet igetter;
|
HttpGet igetter;
|
||||||
QTemporaryFile themesInfo;
|
QTemporaryFile themesInfo;
|
||||||
int currentItem;
|
|
||||||
void resizeEvent(QResizeEvent*);
|
void resizeEvent(QResizeEvent*);
|
||||||
QByteArray imgData;
|
QByteArray imgData;
|
||||||
ProgressLoggerGui *logger;
|
ProgressLoggerGui *logger;
|
||||||
|
|
@ -64,9 +63,10 @@ class ThemesInstallWindow : public QDialog
|
||||||
private slots:
|
private slots:
|
||||||
void downloadDone(bool);
|
void downloadDone(bool);
|
||||||
void downloadDone(int, bool);
|
void downloadDone(int, bool);
|
||||||
void updateDetails(int);
|
|
||||||
void updateImage(bool);
|
void updateImage(bool);
|
||||||
void abort(void);
|
void abort(void);
|
||||||
|
void updateDetails(QListWidgetItem* cur, QListWidgetItem* prev);
|
||||||
|
void updateSize(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue