Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c3d95145 authored by Scott Wheeler's avatar Scott Wheeler

Got the "add to playlist" working the way that it should. This involved

adding some properties (ok, a lot of properties) to FileListItem, but it
does nice things now like allowing parent and sibling relationships to
other FileListItems.  This comes in handy because this means that now when
a tag is updated in the tagger the changes update the entry in the playlist
through a sibling relationship.

Also, I added a new constructor to FileListItem that accepts a pointer to
a FileListItem instead of a QFileInfo.  When this constructor is used, it
automatically creates a "parent" relationship to the invocing FileListItem.
In this mode the tag and header information are shared via a pointer.
However, this meant doing some signal/slot programming to make sure that
when the parent deletes it's members that dangling references won't be
left in the child.  See the destroyed() signal and the parentDestroyed()
slot for more details.

svn path=/trunk/kdemultimedia/juk/; revision=143397
parent 52fe7a8d
####### kdevelop will overwrite this part!!! (begin)##########
bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp MPEGHeader.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.cpp juk.cpp main.cpp
juk_LDADD = -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
......
......@@ -227,7 +227,6 @@ x_includes = @x_includes@
x_libraries = @x_libraries@
bin_PROGRAMS = juk
juk_SOURCES = genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp MPEGHeader.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.cpp juk.cpp main.cpp
juk_LDADD = -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
......@@ -273,7 +272,7 @@ juk_nofinal_OBJECTS = genrelistreader.$(OBJEXT) genrelistlist.$(OBJEXT) \
filelist.$(OBJEXT) customaction.$(OBJEXT) playlistwidget.$(OBJEXT) \
slideraction.$(OBJEXT) taggerwidget.$(OBJEXT) juk.$(OBJEXT) \
main.$(OBJEXT)\
slideraction.moc.o customaction.moc.o juk.moc.o taggerwidget.moc.o \
slideraction.moc.o filelistitem.moc.o customaction.moc.o juk.moc.o taggerwidget.moc.o \
juk_meta_unload.o
@KDE_USE_FINAL_FALSE@juk_OBJECTS = $(juk_nofinal_OBJECTS)
@KDE_USE_FINAL_TRUE@juk_OBJECTS = $(juk_final_OBJECTS)
......@@ -304,13 +303,13 @@ GZIP_ENV = --best
#>- .deps/player.P .deps/playlistwidget.P .deps/slideraction.P .deps/tag.P \
#>- .deps/taggerwidget.P
#>+ 12
@KDE_USE_FINAL_TRUE@DEP_FILES = $(DEPDIR)/slideraction.moc.P $(DEPDIR)/customaction.moc.P $(DEPDIR)/juk.moc.P $(DEPDIR)/taggerwidget.moc.P $(DEPDIR)/juk_meta_unload.P $(DEPDIR)/juk.all_cpp.P \
@KDE_USE_FINAL_TRUE@DEP_FILES = $(DEPDIR)/slideraction.moc.P $(DEPDIR)/filelistitem.moc.P $(DEPDIR)/customaction.moc.P $(DEPDIR)/juk.moc.P $(DEPDIR)/taggerwidget.moc.P $(DEPDIR)/juk_meta_unload.P $(DEPDIR)/juk.all_cpp.P \
.deps/MPEGHeader.P .deps/customaction.P .deps/filelist.P \
.deps/filelistitem.P .deps/genre.P .deps/genrelist.P \
.deps/genrelistlist.P .deps/genrelistreader.P .deps/juk.P .deps/main.P \
.deps/player.P .deps/playlistwidget.P .deps/slideraction.P .deps/tag.P \
.deps/taggerwidget.P
@KDE_USE_FINAL_FALSE@DEP_FILES = $(DEPDIR)/slideraction.moc.P $(DEPDIR)/customaction.moc.P $(DEPDIR)/juk.moc.P $(DEPDIR)/taggerwidget.moc.P $(DEPDIR)/juk_meta_unload.P .deps/MPEGHeader.P .deps/customaction.P .deps/filelist.P \
@KDE_USE_FINAL_FALSE@DEP_FILES = $(DEPDIR)/slideraction.moc.P $(DEPDIR)/filelistitem.moc.P $(DEPDIR)/customaction.moc.P $(DEPDIR)/juk.moc.P $(DEPDIR)/taggerwidget.moc.P $(DEPDIR)/juk_meta_unload.P .deps/MPEGHeader.P .deps/customaction.P .deps/filelist.P \
.deps/filelistitem.P .deps/genre.P .deps/genrelist.P \
.deps/genrelistlist.P .deps/genrelistreader.P .deps/juk.P .deps/main.P \
.deps/player.P .deps/playlistwidget.P .deps/slideraction.P .deps/tag.P \
......@@ -714,6 +713,10 @@ messages: rc.cpp
slideraction.moc.cpp: $(srcdir)/slideraction.h
$(MOC) $(srcdir)/slideraction.h -o slideraction.moc.cpp
#>+ 3
filelistitem.moc.cpp: $(srcdir)/filelistitem.h
$(MOC) $(srcdir)/filelistitem.h -o filelistitem.moc.cpp
#>+ 3
customaction.moc.cpp: $(srcdir)/customaction.h
$(MOC) $(srcdir)/customaction.h -o customaction.moc.cpp
......@@ -728,7 +731,7 @@ taggerwidget.moc.cpp: $(srcdir)/taggerwidget.h
#>+ 3
clean-metasources:
-rm -f slideraction.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp
-rm -f slideraction.moc.cpp filelistitem.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp
#>+ 2
docs-am:
......@@ -754,12 +757,12 @@ force-reedit:
#>+ 12
juk_meta_unload.cpp: slideraction.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp
juk_meta_unload.cpp: slideraction.moc.cpp customaction.moc.cpp filelistitem.moc.cpp juk.moc.cpp taggerwidget.moc.cpp
@echo 'creating juk_meta_unload.cpp'
@-rm -f juk_meta_unload.cpp
@if test ${kde_qtver} = 2; then \
echo 'static const char * _metalist_juk[] = {' > juk_meta_unload.cpp ;\
cat slideraction.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp | grep 'char.*className' | sed -e 's/.*[^A-Za-z0-9_:]\([A-Za-z0-9_:]*\)::className.*$$/\"\1\",/' | sort | uniq >> juk_meta_unload.cpp ;\
cat slideraction.moc.cpp customaction.moc.cpp filelistitem.moc.cpp juk.moc.cpp taggerwidget.moc.cpp | grep 'char.*className' | sed -e 's/.*[^A-Za-z0-9_:]\([A-Za-z0-9_:]*\)::className.*$$/\"\1\",/' | sort | uniq >> juk_meta_unload.cpp ;\
echo '0};' >> juk_meta_unload.cpp ;\
echo '#include <kunload.h>' >> juk_meta_unload.cpp ;\
echo '_UNLOAD(juk)' >> juk_meta_unload.cpp ;\
......@@ -771,11 +774,11 @@ clean-moc-classes:
-rm -f juk_meta_unload.cpp
#>+ 11
juk.all_cpp.cpp: $(srcdir)/Makefile.in $(srcdir)/genrelistreader.cpp $(srcdir)/genrelistlist.cpp $(srcdir)/genrelist.cpp $(srcdir)/genre.cpp $(srcdir)/player.cpp $(srcdir)/MPEGHeader.cpp $(srcdir)/filelistitem.cpp $(srcdir)/tag.cpp $(srcdir)/filelist.cpp $(srcdir)/customaction.cpp $(srcdir)/playlistwidget.cpp $(srcdir)/slideraction.cpp $(srcdir)/taggerwidget.cpp $(srcdir)/juk.cpp $(srcdir)/main.cpp juk_meta_unload.cpp slideraction.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp
juk.all_cpp.cpp: $(srcdir)/Makefile.in $(srcdir)/genrelistreader.cpp $(srcdir)/genrelistlist.cpp $(srcdir)/genrelist.cpp $(srcdir)/genre.cpp $(srcdir)/player.cpp $(srcdir)/MPEGHeader.cpp $(srcdir)/filelistitem.cpp $(srcdir)/tag.cpp $(srcdir)/filelist.cpp $(srcdir)/customaction.cpp $(srcdir)/playlistwidget.cpp $(srcdir)/slideraction.cpp $(srcdir)/taggerwidget.cpp $(srcdir)/juk.cpp $(srcdir)/main.cpp juk_meta_unload.cpp slideraction.moc.cpp filelistitem.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp
@echo 'creating juk.all_cpp.cpp ...'; \
rm -f juk.all_cpp.files juk.all_cpp.final; \
echo "#define KDE_USE_FINAL 1" >> juk.all_cpp.final; \
for file in genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp MPEGHeader.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.cpp juk.cpp main.cpp juk_meta_unload.cpp slideraction.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp; do \
for file in genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp MPEGHeader.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.cpp juk.cpp main.cpp juk_meta_unload.cpp slideraction.moc.cpp filelistitem.moc.cpp customaction.moc.cpp juk.moc.cpp taggerwidget.moc.cpp; do \
echo "#include \"$$file\"" >> juk.all_cpp.files; \
test ! -f $(srcdir)/$$file || egrep '^#pragma +implementation' $(srcdir)/$$file >> juk.all_cpp.final; \
done; \
......
......@@ -21,6 +21,7 @@
#include <qdir.h>
#include <qtimer.h>
#include <qapplication.h>
#include <qptrlist.h>
#include "filelist.h"
......@@ -66,13 +67,19 @@ void FileList::append(QStringList *items)
void FileList::append(FileListItem *item)
{
if(item && members.contains(item->absFilePath()) == 0) {
members.append(item->absFilePath());
(void) new FileListItem(item, this);
}
}
void FileList::append(QPtrList<QListViewItem> *items)
{
// for(QPtrListIterator it = items->begin(); it != items->end(); ++it)
// append(QString((*it)));
QPtrListIterator<QListViewItem> it(*items);
while(it.current()) {
append(dynamic_cast<FileListItem *>(it.current()));
++it;
}
}
FileListItem *FileList::getSelectedItem()
......
......@@ -23,15 +23,28 @@
// public methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : KListViewItem(parent), QFileInfo(*file)
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : QObject(parent), KListViewItem(parent), QFileInfo(*file)
{
header = 0;
// fileInfo = file;
tag = new Tag(filePath());
refresh();
}
FileListItem::FileListItem(FileListItem *item, KListView *parent) : QObject(parent), KListViewItem(parent), QFileInfo(*item)
{
// kdDebug() << "FileListItem(FileListItem *item, KListView *parent)" << endl;
if(item) {
tag = item->getTag();
header = item->getHeader();
connect(item, SIGNAL(destroyed(FileListItem *)), this, SLOT(parentDestroyed(FileListItem *)));
addSibling(item);
refresh();
}
}
FileListItem::~FileListItem()
{
if(tag)
......@@ -39,16 +52,24 @@ FileListItem::~FileListItem()
if(header)
delete(header);
emit(destroyed(this));
}
Tag *FileListItem::getTag()
{
if(!tag) {
if(!tag)
tag = new Tag(filePath());
}
return(tag);
}
/*
void FileListItem::setTag(Tag *itemTag)
{
tag = itemTag;
}
*/
MPEGHeader *FileListItem::getHeader()
{
if(!header) {
......@@ -57,6 +78,13 @@ MPEGHeader *FileListItem::getHeader()
return(header);
}
/*
void FileListItem::setHeader(MPEGHeader *itemHeader)
{
header = itemHeader;
}
*/
void FileListItem::setFile(QString fileName)
{
setFile(fileName);
......@@ -73,13 +101,31 @@ void FileListItem::setFile(QString fileName)
void FileListItem::refresh()
{
setText(0, tag->getTrack());
setText(1, tag->getArtist());
setText(2, tag->getAlbum());
setText(3, tag->getTrackNumberString());
setText(4, tag->getGenre());
setText(5, tag->getYearString());
setText(0, getTag()->getTrack());
setText(1, getTag()->getArtist());
setText(2, getTag()->getAlbum());
setText(3, getTag()->getTrackNumberString());
setText(4, getTag()->getGenre());
setText(5, getTag()->getYearString());
setText(6, filePath());
emit(refreshed());
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
void FileListItem::addSibling(FileListItem *sibling)
{
connect(sibling, SIGNAL(refreshed()), this, SLOT(refresh()));
connect(sibling, SIGNAL(destroyed(FileListItem *)), this, SLOT(removeSibling(FileListItem *)));
}
void FileListItem::removeSibling(FileListItem *sibling)
{
disconnect(sibling, SIGNAL(refreshed()), this, SLOT(refresh()));
disconnect(sibling, SIGNAL(destroyed(FileListItem *)), this, SLOT(removeSibling(FileListItem *)));
}
////////////////////////////////////////////////////////////////////////////////
......@@ -130,3 +176,14 @@ int FileListItem::compare(FileListItem *firstItem, FileListItem *secondItem, int
return(firstItem->key(column, ascending).compare(secondItem->key(column, ascending)));
}
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void FileListItem::parentDestroyed(FileListItem *parent)
{
header = 0;
tag = 0;
disconnect(parent, SIGNAL(destroyed(FileListItem *)), this, SLOT(parentDestroyed(FileListItem *)));
}
......@@ -19,30 +19,46 @@
#define FILELISTITEM_H
#include <klistview.h>
#include <qfileinfo.h>
#include <qobject.h>
#include "tag.h"
#include "MPEGHeader.h"
class FileListItem : public KListViewItem, public QFileInfo {
class FileListItem : public QObject, public KListViewItem, public QFileInfo {
Q_OBJECT
public:
FileListItem(QFileInfo *file, KListView *parent);
FileListItem(FileListItem *item, KListView *parent);
~FileListItem();
Tag *getTag();
// void setTag(Tag *itemTag);
MPEGHeader *getHeader();
// void setHeader(MPEGHeader *itemHeader);
void setFile(QString fileName);
public slots:
void refresh();
void addSibling(FileListItem *sibling);
void removeSibling(FileListItem *sibling);
protected:
signals:
void refreshed();
void destroyed(FileListItem *);
private:
int compare(QListViewItem *item, int column, bool ascending) const;
int compare(FileListItem *firstItem, FileListItem *secondItem, int column, bool ascending) const;
QFileInfo *fileInfo;
Tag *tag;
MPEGHeader *header;
private slots:
void parentDestroyed(FileListItem *parent);
};
#endif
......@@ -186,6 +186,15 @@ void JuK::showPlaylist()
// player menu
////////////////////////////////////////////////////////////////////////////////
void JuK::addToPlaylist()
{
playlist->add(tagger->getSelectedItems());
}
void JuK::removeFromPlaylist()
{
}
void JuK::playFile()
{
......
......@@ -75,6 +75,9 @@ private slots:
void showPlaylist();
// player menu
void addToPlaylist();
void removeFromPlaylist();
void playFile();
void pauseFile();
void stopFile();
......
......@@ -61,6 +61,11 @@ FileListItem *TaggerWidget::getSelectedItem()
return(0);
}
QPtrList<QListViewItem> *TaggerWidget::getSelectedItems()
{
return(new QPtrList<QListViewItem>(taggerList->selectedItems()));
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......
......@@ -24,6 +24,8 @@
#include <knuminput.h>
#include <keditcl.h>
#include <qptrlist.h>
#include "filelist.h"
#include "filelistitem.h"
#include "genrelist.h"
......@@ -39,6 +41,7 @@ public:
void add(QStringList *items);
FileListItem *getSelectedItem();
QPtrList<QListViewItem> *getSelectedItems();
public slots:
void save();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment