~ubuntu-branches/ubuntu/feisty/digikam/feisty

« back to all changes in this revision

Viewing changes to digikam/digikam/albumlister.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Achim Bohnet
  • Date: 2005-03-10 02:39:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050310023902-023nymfst5mg696c
Tags: 0.7.2-2
* debian/TODO: clean
* digikam manpage: better --detect-camera description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
 
3
 * Date  : 2004-06-26
 
4
 * Description : 
 
5
 * 
 
6
 * Copyright 2004 by Renchi Raju
 
7
 
 
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)
 
12
 * any later version.
 
13
 * 
 
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.
 
18
 * 
 
19
 * ============================================================ */
 
20
 
 
21
#include <qstring.h>
 
22
 
 
23
#include <kdirlister.h>
 
24
#include <kdebug.h>
 
25
 
 
26
#include "album.h"
 
27
#include "albummanager.h"
 
28
#include "albumdb.h"
 
29
#include "albumsettings.h"
 
30
 
 
31
#include "albumlister.h"
 
32
 
 
33
extern "C"
 
34
{
 
35
#include <sys/time.h>
 
36
#include <time.h>
 
37
#include <stdio.h>
 
38
}
 
39
 
 
40
class AlbumListerPriv
 
41
{
 
42
public:
 
43
 
 
44
    KDirLister* dirLister;
 
45
 
 
46
    Album*      currAlbum;
 
47
    AlbumDB*    db;
 
48
};
 
49
    
 
50
AlbumLister::AlbumLister()
 
51
{
 
52
    d = new AlbumListerPriv;
 
53
    d->dirLister = new KDirLister;
 
54
    d->currAlbum = 0;
 
55
}
 
56
 
 
57
AlbumLister::~AlbumLister()
 
58
{
 
59
    delete d->dirLister;
 
60
    delete d;
 
61
}
 
62
 
 
63
void AlbumLister::openAlbum(Album *album)
 
64
{
 
65
    d->dirLister->stop();
 
66
 
 
67
    d->dirLister->disconnect(this);
 
68
    
 
69
    d->currAlbum = album;
 
70
    if (!album)
 
71
        return;
 
72
 
 
73
    if (album->type() == Album::PHYSICAL)
 
74
    {
 
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()),
 
80
                SLOT(slotClear()));
 
81
        connect(d->dirLister, SIGNAL(completed()),
 
82
                SIGNAL(signalCompleted()));
 
83
        connect(d->dirLister, SIGNAL(refreshItems(const KFileItemList&)),
 
84
                SIGNAL(signalRefreshItems(const KFileItemList&)));
 
85
 
 
86
        PAlbum *a = static_cast<PAlbum*>(album);
 
87
        d->dirLister->openURL(a->getKURL(), false, true);
 
88
    }
 
89
    else if (album->type() == Album::TAG)
 
90
    {
 
91
        //TODO: if the album library path has changed: kill the tags kioslave
 
92
        // by pumping a metadata to it, causing it to reload.
 
93
        
 
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()),
 
99
                SLOT(slotClear()));
 
100
        connect(d->dirLister, SIGNAL(completed()),
 
101
                SIGNAL(signalCompleted()));
 
102
        connect(d->dirLister, SIGNAL(refreshItems(const KFileItemList&)),
 
103
                SIGNAL(signalRefreshItems(const KFileItemList&)));
 
104
 
 
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);
 
110
    }
 
111
    else
 
112
    {
 
113
        emit signalClear();
 
114
    }
 
115
}
 
116
 
 
117
void AlbumLister::updateDirectory()
 
118
{
 
119
    if (!d->currAlbum)
 
120
        return;
 
121
 
 
122
    if (d->currAlbum->type() == Album::PHYSICAL)
 
123
    {
 
124
        PAlbum *a = static_cast<PAlbum*>(d->currAlbum);
 
125
        d->dirLister->updateDirectory(a->getKURL());
 
126
    }
 
127
    else if (d->currAlbum->type() == Album::TAG)
 
128
    {
 
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);
 
134
    }        
 
135
}
 
136
 
 
137
PAlbum* AlbumLister::findParentAlbum(const KFileItem *item) const
 
138
{
 
139
    if (!item)
 
140
        return 0;
 
141
    
 
142
    return (PAlbum*)item->extraData(this);
 
143
}
 
144
 
 
145
void AlbumLister::stop()
 
146
{
 
147
    d->dirLister->stop();
 
148
}
 
149
 
 
150
void AlbumLister::setNameFilter(const QString& nameFilter)
 
151
{
 
152
    d->dirLister->setNameFilter(nameFilter);    
 
153
}
 
154
 
 
155
void AlbumLister::slotNewPhyItems(const KFileItemList& items)
 
156
{
 
157
    if (d->currAlbum && d->currAlbum->type() == Album::PHYSICAL)
 
158
    {
 
159
        PAlbum* album = dynamic_cast<PAlbum*>(d->currAlbum);
 
160
        KFileItem* item;
 
161
        for (KFileItemListIterator it(items); (item = it.current()); ++it)
 
162
        {
 
163
            item->setExtraData(this, album);
 
164
        }
 
165
    }
 
166
 
 
167
    emit signalNewItems(items);
 
168
}
 
169
 
 
170
void AlbumLister::slotNewTagItems(const KFileItemList& items)
 
171
{
 
172
    KFileItemList filteredItems;
 
173
    
 
174
    KIO::UDSEntry entry;
 
175
    PAlbum*       album;
 
176
    int           id;
 
177
    KFileItem*    item;
 
178
 
 
179
    AlbumManager* man = AlbumManager::instance();
 
180
    
 
181
    for (KFileItemListIterator it(items); (item = it.current()); ++it)
 
182
    {
 
183
        if (item->isDir())
 
184
            continue;
 
185
        
 
186
        album = 0;
 
187
        
 
188
        entry = item->entry();
 
189
        for( KIO::UDSEntry::ConstIterator it = entry.begin();
 
190
             it != entry.end(); it++ )
 
191
        {
 
192
            if ((*it).m_uds == KIO::UDS_XML_PROPERTIES)
 
193
            {
 
194
                id = (*it).m_str.toInt();
 
195
                album = man->findPAlbum(id);
 
196
                break;
 
197
            }
 
198
        }
 
199
 
 
200
        if (!album)
 
201
        {
 
202
            kdWarning() << k_funcinfo << "Failed to retrieve dirid from kioslave for "
 
203
                        << item->url().prettyURL() << endl;
 
204
            continue;
 
205
        }
 
206
 
 
207
        filteredItems.append(item);
 
208
        item->setExtraData(this, album);
 
209
    }
 
210
 
 
211
    emit signalNewItems(filteredItems);
 
212
}
 
213
 
 
214
void AlbumLister::slotDeleteItem(KFileItem *item)
 
215
{
 
216
    emit signalDeleteItem(item);
 
217
    item->removeExtraData(this);
 
218
}
 
219
 
 
220
void AlbumLister::slotClear()
 
221
{
 
222
    emit signalClear();
 
223
}
 
224
 
 
225
#include "albumlister.moc"
 
226