Added a beginning of the medialib.
This commit is contained in:
parent
9b5aac622c
commit
b8f4b7acb7
9 changed files with 249 additions and 3 deletions
146
Medialib.cpp
Normal file
146
Medialib.cpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
#include "XMMSHandler.h"
|
||||
#include "Medialib.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QFile>
|
||||
#include <QIODevice>
|
||||
|
||||
MedialibWindow::MedialibWindow (QWidget *parent) : QMainWindow (parent)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
setWindowIcon (QIcon (":icon.png"));
|
||||
#endif
|
||||
|
||||
resize (500, 550);
|
||||
|
||||
m_dummy = new QWidget (parent);
|
||||
setCentralWidget (m_dummy);
|
||||
|
||||
m_vbox = new QVBoxLayout (m_dummy);
|
||||
m_search = new QLineEdit (m_dummy);
|
||||
m_search->setFocusPolicy (Qt::StrongFocus);
|
||||
m_vbox->addWidget (m_search);
|
||||
|
||||
m_tab = new QTabWidget (m_dummy);
|
||||
m_vbox->addWidget (m_tab);
|
||||
|
||||
m_list = new MedialibList (m_tab);
|
||||
m_tab->addTab (new QWidget (m_tab), "Artists");
|
||||
m_tab->addTab (m_list, "Albums");
|
||||
m_tab->addTab (new QWidget (m_tab), "Songs");
|
||||
|
||||
connect (m_search, SIGNAL (textEdited (QString)), m_list, SLOT (search (QString)));
|
||||
}
|
||||
|
||||
MedialibList::MedialibList (QWidget *parent) : QListWidget (parent)
|
||||
{
|
||||
XMMSHandler *xmmsh = XMMSHandler::getInstance ();
|
||||
m_http = new QHttp (this);
|
||||
m_httpmap = new QHash<int, MedialibListItem *>;
|
||||
|
||||
setIconSize (QSize (85, 85));
|
||||
|
||||
xmmsh->medialibQuery ("select distinct m1.value as artist, ifnull(m2.value,'[unknown]') as album, m4.value as image from Media m1 left join Media m2 on m1.id = m2.id and m2.key='album' left join Media m3 on m1.id = m3.id and m3.key='compilation' left join Media m4 on m4.id = m1.id and m4.key='album_front_small' where m1.key='artist' and m3.value is null");
|
||||
|
||||
connect (xmmsh, SIGNAL (medialibResponse (QList<QHash<QString, QString> >)),
|
||||
this, SLOT (queryCallback (QList<QHash<QString, QString> >)));
|
||||
|
||||
connect (m_http, SIGNAL (requestFinished (int, bool)), this,
|
||||
SLOT (httpDone (int, bool)));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
MedialibList::search (QString s)
|
||||
{
|
||||
if (s.length () > 0) {
|
||||
for (int i = 0; i < count (); i++) {
|
||||
MedialibListItem *it = dynamic_cast<MedialibListItem*> (item (i));
|
||||
if (!it->text().contains (s, Qt::CaseInsensitive)) {
|
||||
setItemHidden (it, true);
|
||||
} else if (isItemHidden (it)) {
|
||||
setItemHidden (it, false);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i = 0; i < count (); i++) {
|
||||
MedialibListItem *it = dynamic_cast<MedialibListItem*> (item (i));
|
||||
setItemHidden (it, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
MedialibList::httpDone (int id, bool error)
|
||||
{
|
||||
if (error) {
|
||||
qWarning ("error!");
|
||||
return;
|
||||
}
|
||||
|
||||
MedialibListItem *it = m_httpmap->value (id);
|
||||
|
||||
if (it) {
|
||||
QFile *f = it->getFile ();
|
||||
f->close ();
|
||||
|
||||
QIcon ico (f->fileName ());
|
||||
it->setIcon (ico);
|
||||
|
||||
delete f;
|
||||
m_httpmap->remove (id);
|
||||
}
|
||||
|
||||
update ();
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
MedialibList::queryCallback (QList<QHash<QString, QString> >l)
|
||||
{
|
||||
QFont font;
|
||||
|
||||
font.setPixelSize (14);
|
||||
|
||||
for (int i = 0; i < l.count (); i++) {
|
||||
QHash<QString, QString> h(l.value (i));
|
||||
|
||||
MedialibListItem *item = new MedialibListItem (h.value("artist") + " - " + h.value("album"), this);
|
||||
item->setSizeHint (QSize (90, 90));
|
||||
item->setIcon (QIcon (":nocover.jpg"));
|
||||
item->setFont (font);
|
||||
item->setTextAlignment (Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
|
||||
if (h.contains ("image")) {
|
||||
|
||||
QString name = h.value("artist")+"-"+h.value("album")+".jpg";
|
||||
|
||||
if (!QFile::exists (name)) {
|
||||
QUrl url (h.value("image"));
|
||||
|
||||
m_http->setHost (url.host(), url.port() != -1 ? url.port() : 80);
|
||||
if (!url.userName().isEmpty()) {
|
||||
m_http->setUser (url.userName(), url.password());
|
||||
}
|
||||
|
||||
QFile *file = new QFile (h.value("artist")+"-"+h.value("album")+".jpg");
|
||||
file->open(QIODevice::WriteOnly);
|
||||
|
||||
item->setFile (file);
|
||||
|
||||
int id = m_http->get (url.path(), file);
|
||||
m_httpmap->insert (id, item);
|
||||
} else {
|
||||
QIcon ico (name);
|
||||
item->setIcon (ico);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
59
Medialib.h
Normal file
59
Medialib.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef __MEDIALIB_H__
|
||||
#define __MEDIALIB_H__
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTabWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHttp>
|
||||
#include <QFile>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
class MedialibListItem : public QListWidgetItem
|
||||
{
|
||||
public:
|
||||
MedialibListItem (QString text, QListWidget *parent) : QListWidgetItem (text, parent) {}
|
||||
~MedialibListItem () {}
|
||||
void setFile (QFile *f) { m_file = f; }
|
||||
QFile *getFile (void) { return m_file; }
|
||||
|
||||
private:
|
||||
QFile *m_file;
|
||||
};
|
||||
|
||||
class MedialibList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MedialibList (QWidget *parent);
|
||||
~MedialibList () {}
|
||||
|
||||
public slots:
|
||||
void queryCallback (QList<QHash<QString, QString> >);
|
||||
void httpDone (int, bool);
|
||||
void search (QString);
|
||||
|
||||
private:
|
||||
QHash<int, MedialibListItem*> *m_httpmap;
|
||||
QHttp *m_http;
|
||||
|
||||
};
|
||||
|
||||
class MedialibWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MedialibWindow (QWidget *parent);
|
||||
~MedialibWindow () {}
|
||||
|
||||
|
||||
private:
|
||||
QWidget *m_dummy;
|
||||
QTabWidget *m_tab;
|
||||
QLineEdit *m_search;
|
||||
QVBoxLayout *m_vbox;
|
||||
MedialibList *m_list;
|
||||
};
|
||||
|
||||
#endif
|
13
TitleBar.cpp
13
TitleBar.cpp
|
@ -2,6 +2,7 @@
|
|||
#include "TitleBar.h"
|
||||
#include "Display.h"
|
||||
#include "SkinChooser.h"
|
||||
#include "Medialib.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
|
@ -38,6 +39,11 @@ TitleBar::showMenu (void)
|
|||
|
||||
QAction *a;
|
||||
|
||||
a = new QAction (tr ("Medialib browser"), this);
|
||||
a->setShortcut (tr ("Alt+M"));
|
||||
connect (a, SIGNAL (triggered ()), this, SLOT (showMlib ()));
|
||||
qm.addAction (a);
|
||||
qm.addSeparator ();
|
||||
a = new QAction (tr ("Theme settings"), this);
|
||||
a->setShortcut (tr ("Alt+T"));
|
||||
connect (a, SIGNAL (triggered ()), this, SLOT (showTheme ()));
|
||||
|
@ -58,6 +64,13 @@ TitleBar::showMenu (void)
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
TitleBar::showMlib ()
|
||||
{
|
||||
MedialibWindow *mw = new MedialibWindow (window ());
|
||||
mw->show ();
|
||||
}
|
||||
|
||||
void
|
||||
TitleBar::showTheme ()
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ class TitleBar : public PixWidget
|
|||
void setPixmaps (Skin *skin);
|
||||
void showMenu (void);
|
||||
void showTheme (void);
|
||||
void showMlib (void);
|
||||
|
||||
protected:
|
||||
void mouseDoubleClickEvent (QMouseEvent *event);
|
||||
|
|
|
@ -264,6 +264,26 @@ XMMSHandler::PropDictToQHash (XMMSResultDict *res)
|
|||
return h;
|
||||
}
|
||||
|
||||
void
|
||||
XMMSHandler::medialibQuery (QString q)
|
||||
{
|
||||
XMMSResultDictList *r = m_xmmsc->medialib_select (q.toUtf8 ());
|
||||
r->connect (sigc::mem_fun (this, &XMMSHandler::medialib_select));
|
||||
}
|
||||
|
||||
void
|
||||
XMMSHandler::medialib_select (XMMSResultDictList *res)
|
||||
{
|
||||
QList<QHash<QString, QString> > l;
|
||||
|
||||
for (;res->listValid (); res->listNext()) {
|
||||
QHash<QString, QString> h(DictToQHash (static_cast<XMMSResultDict *>(res)));
|
||||
l.append (h);
|
||||
}
|
||||
|
||||
emit medialibResponse (l);
|
||||
}
|
||||
|
||||
void
|
||||
XMMSHandler::playlist_changed (XMMSResultDict *res)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ class XMMSHandler : public QObject, public sigc::trackable {
|
|||
void playback_status (XMMSResultValue<uint> *res);
|
||||
void playlist_list (XMMSResultValueList<uint> *res);
|
||||
void medialib_entry_changed (XMMSResultValue<uint> *res);
|
||||
void medialib_select (XMMSResultDictList *res);
|
||||
|
||||
void requestMediainfo (uint id);
|
||||
void requestPlaylistList (void);
|
||||
|
@ -30,6 +31,7 @@ class XMMSHandler : public QObject, public sigc::trackable {
|
|||
void playlistClear (void);
|
||||
void playlistRemove (uint pos) { delete m_xmmsc->playlist_remove (pos); }
|
||||
void playlistMove (uint pos, uint newpos) { delete m_xmmsc->playlist_move (pos, newpos); }
|
||||
void medialibQuery (QString);
|
||||
|
||||
const XMMSClient *getXMMS () { return m_xmmsc; }
|
||||
|
||||
|
@ -57,6 +59,7 @@ class XMMSHandler : public QObject, public sigc::trackable {
|
|||
void playlistList (QList<uint>);
|
||||
void currentID (uint);
|
||||
void playlistChanged (QHash<QString, QString>);
|
||||
void medialibResponse (QList<QHash<QString, QString> >);
|
||||
|
||||
private:
|
||||
XmmsQT4 *m_qt4;
|
||||
|
|
BIN
nocover.jpg
Normal file
BIN
nocover.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
|
@ -17,7 +17,8 @@ SOURCES += XmmsQT4.cpp \
|
|||
Playlist.cpp \
|
||||
PlaylistList.cpp \
|
||||
SkinChooser.cpp \
|
||||
PlaylistShade.cpp
|
||||
PlaylistShade.cpp \
|
||||
Medialib.cpp
|
||||
|
||||
HEADERS += XmmsQT4.h \
|
||||
PixWidget.h \
|
||||
|
@ -38,12 +39,14 @@ HEADERS += XmmsQT4.h \
|
|||
Playlist.h \
|
||||
PlaylistList.h \
|
||||
SkinChooser.h \
|
||||
PlaylistShade.h
|
||||
PlaylistShade.h \
|
||||
Medialib.h
|
||||
|
||||
|
||||
RESOURCES = promoe.qrc
|
||||
macx:RC_FILE = promoe.icns
|
||||
|
||||
QT += network
|
||||
CONFIG += link_pkgconfig
|
||||
CXXFLAGS += -g
|
||||
;CONFIG += debug warn_on
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>icon.png</file>
|
||||
<file>nocover.jpg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue