Medialib now works a bit better and has a very nice status bar.
This commit is contained in:
parent
44de5fb428
commit
b0f7061f84
2 changed files with 65 additions and 12 deletions
41
Medialib.cpp
41
Medialib.cpp
|
@ -26,10 +26,18 @@ MedialibWindow::MedialibWindow (QWidget *parent) : QMainWindow (parent)
|
||||||
m_tab = new QTabWidget (m_dummy);
|
m_tab = new QTabWidget (m_dummy);
|
||||||
m_vbox->addWidget (m_tab);
|
m_vbox->addWidget (m_tab);
|
||||||
|
|
||||||
|
m_progress = new QProgressBar (m_dummy);
|
||||||
|
statusBar ()->addPermanentWidget (m_progress, 1);
|
||||||
|
m_progress->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
|
||||||
|
|
||||||
|
m_status = new QLabel (tr ("Idle"), statusBar ());
|
||||||
|
m_status->setFrameStyle (QFrame::NoFrame);
|
||||||
|
statusBar ()->addPermanentWidget (m_status, 2);
|
||||||
|
|
||||||
m_list = new MedialibList (m_tab);
|
m_list = new MedialibList (m_tab);
|
||||||
m_tab->addTab (new QWidget (m_tab), "Artists");
|
m_tab->addTab (new QWidget (m_tab), tr ("Artists"));
|
||||||
m_tab->addTab (m_list, "Albums");
|
m_tab->addTab (m_list, tr ("Albums"));
|
||||||
m_tab->addTab (new QWidget (m_tab), "Songs");
|
m_tab->addTab (new QWidget (m_tab), tr ("Songs"));
|
||||||
|
|
||||||
connect (m_search, SIGNAL (textEdited (QString)), m_list, SLOT (search (QString)));
|
connect (m_search, SIGNAL (textEdited (QString)), m_list, SLOT (search (QString)));
|
||||||
}
|
}
|
||||||
|
@ -39,8 +47,10 @@ MedialibList::MedialibList (QWidget *parent) : QListWidget (parent)
|
||||||
XMMSHandler *xmmsh = XMMSHandler::getInstance ();
|
XMMSHandler *xmmsh = XMMSHandler::getInstance ();
|
||||||
m_http = new QHttp (this);
|
m_http = new QHttp (this);
|
||||||
m_httpmap = new QHash<int, MedialibListItem *>;
|
m_httpmap = new QHash<int, MedialibListItem *>;
|
||||||
|
m_win = dynamic_cast<MedialibWindow*>(window ());
|
||||||
|
|
||||||
setIconSize (QSize (85, 85));
|
setIconSize (QSize (85, 85));
|
||||||
|
setDragEnabled (true);
|
||||||
|
|
||||||
QDir dir (QDir::homePath ()+"/.xmms2/clients/generic/art/");
|
QDir dir (QDir::homePath ()+"/.xmms2/clients/generic/art/");
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
|
@ -55,6 +65,8 @@ MedialibList::MedialibList (QWidget *parent) : QListWidget (parent)
|
||||||
connect (m_http, SIGNAL (requestFinished (int, bool)), this,
|
connect (m_http, SIGNAL (requestFinished (int, bool)), this,
|
||||||
SLOT (httpDone (int, bool)));
|
SLOT (httpDone (int, bool)));
|
||||||
|
|
||||||
|
m_win->setBusy (true);
|
||||||
|
m_win->setStatusText ("Loading album view");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -94,7 +106,6 @@ MedialibList::httpDone (int id, bool error)
|
||||||
f->close ();
|
f->close ();
|
||||||
|
|
||||||
QString newname (QDir::homePath()+"/.xmms2/clients/generic/art/"+(f->fileName ().section("/", -1)));
|
QString newname (QDir::homePath()+"/.xmms2/clients/generic/art/"+(f->fileName ().section("/", -1)));
|
||||||
qDebug ("new path %s", qPrintable (newname));
|
|
||||||
f->rename (newname);
|
f->rename (newname);
|
||||||
f->setFileName (newname);
|
f->setFileName (newname);
|
||||||
|
|
||||||
|
@ -102,12 +113,18 @@ MedialibList::httpDone (int id, bool error)
|
||||||
if (!ico.isNull()) {
|
if (!ico.isNull()) {
|
||||||
it->setIcon (ico);
|
it->setIcon (ico);
|
||||||
} else {
|
} else {
|
||||||
qDebug ("removing %s", qPrintable (f->fileName()));
|
|
||||||
f->remove ();
|
f->remove ();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete f;
|
delete f;
|
||||||
m_httpmap->remove (id);
|
m_httpmap->remove (id);
|
||||||
|
if (m_httpmap->count () == 0) {
|
||||||
|
m_win->setBusy (false);
|
||||||
|
m_win->setStatusText ("idle");
|
||||||
|
} else {
|
||||||
|
m_win->setBusy (m_httpmap->count ());
|
||||||
|
m_win->setStatusText ("Got art for: " + it->text());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update ();
|
update ();
|
||||||
|
@ -121,6 +138,9 @@ MedialibList::queryCallback (QList<QHash<QString, QString> >l)
|
||||||
|
|
||||||
font.setPixelSize (14);
|
font.setPixelSize (14);
|
||||||
|
|
||||||
|
m_win->setBusy (false);
|
||||||
|
m_win->setStatusText ("idle");
|
||||||
|
|
||||||
for (int i = 0; i < l.count (); i++) {
|
for (int i = 0; i < l.count (); i++) {
|
||||||
QHash<QString, QString> h(l.value (i));
|
QHash<QString, QString> h(l.value (i));
|
||||||
|
|
||||||
|
@ -128,12 +148,12 @@ MedialibList::queryCallback (QList<QHash<QString, QString> >l)
|
||||||
item->setSizeHint (QSize (90, 90));
|
item->setSizeHint (QSize (90, 90));
|
||||||
item->setIcon (QIcon (":nocover.jpg"));
|
item->setIcon (QIcon (":nocover.jpg"));
|
||||||
item->setFont (font);
|
item->setFont (font);
|
||||||
item->setTextAlignment (Qt::AlignHCenter | Qt::AlignVCenter);
|
item->setTextAlignment (Qt::AlignVCenter);
|
||||||
|
|
||||||
if (h.contains ("image")) {
|
if (h.contains ("image")) {
|
||||||
|
|
||||||
QString name = qtMD5 ((h.value("artist").toLower()+"-"+h.value("album").toLower()).toUtf8());
|
QString name = qtMD5 ((h.value("artist").toLower()+"-"+h.value("album").toLower()).toUtf8());
|
||||||
QString fname (QDir::homePath () +"/.xmms2/clients/generic/art/"+name+".jpg");
|
QString fname (QDir::homePath () +"/.xmms2/clients/generic/art/"+name+"_small.jpg");
|
||||||
|
|
||||||
if (!QFile::exists (fname)) {
|
if (!QFile::exists (fname)) {
|
||||||
QUrl url (h.value("image"));
|
QUrl url (h.value("image"));
|
||||||
|
@ -143,7 +163,7 @@ MedialibList::queryCallback (QList<QHash<QString, QString> >l)
|
||||||
m_http->setUser (url.userName(), url.password());
|
m_http->setUser (url.userName(), url.password());
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile *file = new QFile ("/tmp/"+name+".jpg");
|
QFile *file = new QFile ("/tmp/"+name+"_small.jpg");
|
||||||
file->open(QIODevice::WriteOnly);
|
file->open(QIODevice::WriteOnly);
|
||||||
|
|
||||||
item->setFile (file);
|
item->setFile (file);
|
||||||
|
@ -160,5 +180,10 @@ MedialibList::queryCallback (QList<QHash<QString, QString> >l)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_httpmap->count() > 0) {
|
||||||
|
m_win->setBusy (0, m_httpmap->count ());
|
||||||
|
m_win->setStatusText ("Loading album art");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
Medialib.h
36
Medialib.h
|
@ -1,14 +1,19 @@
|
||||||
#ifndef __MEDIALIB_H__
|
#ifndef __MEDIALIB_H__
|
||||||
#define __MEDIALIB_H__
|
#define __MEDIALIB_H__
|
||||||
|
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
#include <QProgressBar>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QTabWidget>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QTabWidget>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QLabel>
|
||||||
#include <QHttp>
|
#include <QHttp>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QListWidgetItem>
|
|
||||||
|
class MedialibWindow;
|
||||||
|
|
||||||
class MedialibListItem : public QListWidgetItem
|
class MedialibListItem : public QListWidgetItem
|
||||||
{
|
{
|
||||||
|
@ -37,6 +42,8 @@ class MedialibList : public QListWidget
|
||||||
private:
|
private:
|
||||||
QHash<int, MedialibListItem*> *m_httpmap;
|
QHash<int, MedialibListItem*> *m_httpmap;
|
||||||
QHttp *m_http;
|
QHttp *m_http;
|
||||||
|
MedialibWindow *m_win;
|
||||||
|
int m_httpr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,12 +54,33 @@ class MedialibWindow : public QMainWindow
|
||||||
MedialibWindow (QWidget *parent);
|
MedialibWindow (QWidget *parent);
|
||||||
~MedialibWindow () {}
|
~MedialibWindow () {}
|
||||||
|
|
||||||
|
void setBusy (bool b) {
|
||||||
|
if (b) {
|
||||||
|
m_progress->setMaximum (0);
|
||||||
|
m_progress->setMinimum (0);
|
||||||
|
} else {
|
||||||
|
m_progress->setMaximum (1);
|
||||||
|
m_progress->reset ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void setBusy (int min, int max) {
|
||||||
|
m_progress->setMaximum (max);
|
||||||
|
m_progress->setMinimum (min);
|
||||||
|
}
|
||||||
|
void setBusy (int cur) {
|
||||||
|
m_progress->setValue (cur);
|
||||||
|
}
|
||||||
|
void setStatusText (QString s) {
|
||||||
|
m_status->setText (s);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_dummy;
|
QWidget *m_dummy;
|
||||||
QTabWidget *m_tab;
|
QTabWidget *m_tab;
|
||||||
QLineEdit *m_search;
|
QLineEdit *m_search;
|
||||||
QVBoxLayout *m_vbox;
|
QVBoxLayout *m_vbox;
|
||||||
|
QProgressBar *m_progress;
|
||||||
|
QLabel *m_status;
|
||||||
MedialibList *m_list;
|
MedialibList *m_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue