1
/* ============================================================
2
* Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
6
* Copyright 2004 by Renchi Raju
8
* This program is free software; you can redistribute it
9
* and/or modify it under the terms of the GNU General
10
* Public License as published by the Free Software Foundation;
11
* either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* ============================================================ */
23
#include <kdirlister.h>
27
#include "albummanager.h"
29
#include "albumsettings.h"
31
#include "albumlister.h"
44
KDirLister* dirLister;
50
AlbumLister::AlbumLister()
52
d = new AlbumListerPriv;
53
d->dirLister = new KDirLister;
57
AlbumLister::~AlbumLister()
63
void AlbumLister::openAlbum(Album *album)
67
d->dirLister->disconnect(this);
73
if (album->type() == Album::PHYSICAL)
75
connect(d->dirLister, SIGNAL(newItems(const KFileItemList&)),
76
SLOT(slotNewPhyItems(const KFileItemList&)));
77
connect(d->dirLister, SIGNAL(deleteItem(KFileItem*)),
78
SLOT(slotDeleteItem(KFileItem*)) );
79
connect(d->dirLister, SIGNAL(clear()),
81
connect(d->dirLister, SIGNAL(completed()),
82
SIGNAL(signalCompleted()));
83
connect(d->dirLister, SIGNAL(refreshItems(const KFileItemList&)),
84
SIGNAL(signalRefreshItems(const KFileItemList&)));
86
PAlbum *a = static_cast<PAlbum*>(album);
87
d->dirLister->openURL(a->getKURL(), false, true);
89
else if (album->type() == Album::TAG)
91
//TODO: if the album library path has changed: kill the tags kioslave
92
// by pumping a metadata to it, causing it to reload.
94
connect(d->dirLister, SIGNAL(newItems(const KFileItemList&)),
95
SLOT(slotNewTagItems(const KFileItemList&)));
96
connect(d->dirLister, SIGNAL(deleteItem(KFileItem*)),
97
SLOT(slotDeleteItem(KFileItem*)) );
98
connect(d->dirLister, SIGNAL(clear()),
100
connect(d->dirLister, SIGNAL(completed()),
101
SIGNAL(signalCompleted()));
102
connect(d->dirLister, SIGNAL(refreshItems(const KFileItemList&)),
103
SIGNAL(signalRefreshItems(const KFileItemList&)));
105
TAlbum *a = static_cast<TAlbum*>(album);
106
KURL url(a->getKURL());
107
if (AlbumSettings::instance()->getRecurseTags())
108
url.setQuery("?recurse=yes");
109
d->dirLister->openURL(url, false, true);
117
void AlbumLister::updateDirectory()
122
if (d->currAlbum->type() == Album::PHYSICAL)
124
PAlbum *a = static_cast<PAlbum*>(d->currAlbum);
125
d->dirLister->updateDirectory(a->getKURL());
127
else if (d->currAlbum->type() == Album::TAG)
129
TAlbum *a = static_cast<TAlbum*>(d->currAlbum);
130
KURL url(a->getKURL());
131
if (AlbumSettings::instance()->getRecurseTags())
132
url.setQuery("?recurse=yes");
133
d->dirLister->updateDirectory(url);
137
PAlbum* AlbumLister::findParentAlbum(const KFileItem *item) const
142
return (PAlbum*)item->extraData(this);
145
void AlbumLister::stop()
147
d->dirLister->stop();
150
void AlbumLister::setNameFilter(const QString& nameFilter)
152
d->dirLister->setNameFilter(nameFilter);
155
void AlbumLister::slotNewPhyItems(const KFileItemList& items)
157
if (d->currAlbum && d->currAlbum->type() == Album::PHYSICAL)
159
PAlbum* album = dynamic_cast<PAlbum*>(d->currAlbum);
161
for (KFileItemListIterator it(items); (item = it.current()); ++it)
163
item->setExtraData(this, album);
167
emit signalNewItems(items);
170
void AlbumLister::slotNewTagItems(const KFileItemList& items)
172
KFileItemList filteredItems;
179
AlbumManager* man = AlbumManager::instance();
181
for (KFileItemListIterator it(items); (item = it.current()); ++it)
188
entry = item->entry();
189
for( KIO::UDSEntry::ConstIterator it = entry.begin();
190
it != entry.end(); it++ )
192
if ((*it).m_uds == KIO::UDS_XML_PROPERTIES)
194
id = (*it).m_str.toInt();
195
album = man->findPAlbum(id);
202
kdWarning() << k_funcinfo << "Failed to retrieve dirid from kioslave for "
203
<< item->url().prettyURL() << endl;
207
filteredItems.append(item);
208
item->setExtraData(this, album);
211
emit signalNewItems(filteredItems);
214
void AlbumLister::slotDeleteItem(KFileItem *item)
216
emit signalDeleteItem(item);
217
item->removeExtraData(this);
220
void AlbumLister::slotClear()
225
#include "albumlister.moc"