~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/digikam/searchresultsview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.3.2 upstream) (37 hardy)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20080717202539-1bw3w3nrsso7yj4z
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ============================================================
2
 
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
3
 
 * Date  : 2005-05-20
4
 
 * Description : 
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2005-05-20
 
7
 * Description : search results view.
5
8
 * 
6
 
 * Copyright 2005 by Renchi Raju
7
 
 
 
9
 * Copyright (C) 2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
 
10
 * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
11
 *
8
12
 * This program is free software; you can redistribute it
9
13
 * and/or modify it under the terms of the GNU General
10
14
 * Public License as published by the Free Software Foundation;
18
22
 * 
19
23
 * ============================================================ */
20
24
 
 
25
// Qt includes.
 
26
 
21
27
#include <qdatastream.h>
 
28
#include <qdict.h>
 
29
#include <qguardedptr.h>
 
30
 
 
31
// KDE includes.
22
32
 
23
33
#include <kio/job.h>
24
34
#include <kfileitem.h>
25
35
#include <kurl.h>
26
36
 
 
37
// Local includes.
 
38
 
 
39
#include "thumbnailjob.h"
27
40
#include "albummanager.h"
28
41
#include "albumsettings.h"
29
42
#include "searchresultsitem.h"
30
43
#include "searchresultsview.h"
 
44
#include "searchresultsview.moc"
 
45
 
 
46
namespace Digikam
 
47
{
 
48
 
 
49
class SearchResultsViewPriv
 
50
{
 
51
public:
 
52
 
 
53
    SearchResultsViewPriv()
 
54
    {
 
55
        listJob  = 0;
 
56
        thumbJob = 0;
 
57
    }
 
58
 
 
59
    QString                   libraryPath;
 
60
    QString                   filter;
 
61
 
 
62
    QDict<QIconViewItem>      itemDict;
 
63
 
 
64
    QGuardedPtr<ThumbnailJob> thumbJob;
 
65
 
 
66
    KIO::TransferJob*         listJob;
 
67
};
31
68
 
32
69
SearchResultsView::SearchResultsView(QWidget* parent)
33
 
    : QIconView(parent)
 
70
                 : QIconView(parent)
34
71
{
35
 
    m_listJob  = 0;
36
 
    m_thumbJob = 0;
37
 
 
38
 
    m_libraryPath = AlbumManager::instance()->getLibraryPath();
39
 
    m_filter      = AlbumSettings::instance()->getAllFileFilter();
 
72
    d = new SearchResultsViewPriv;
 
73
    d->libraryPath = AlbumManager::instance()->getLibraryPath();
 
74
    d->filter      = AlbumSettings::instance()->getAllFileFilter();
40
75
 
41
76
    setAutoArrange(true);
42
77
    setResizeMode(QIconView::Adjust);
44
79
 
45
80
SearchResultsView::~SearchResultsView()
46
81
{
47
 
    if (!m_thumbJob.isNull())
48
 
        m_thumbJob->kill();
49
 
    if (m_listJob)
50
 
        m_listJob->kill();
 
82
    if (!d->thumbJob.isNull())
 
83
        d->thumbJob->kill();
 
84
    if (d->listJob)
 
85
        d->listJob->kill();
 
86
 
 
87
    delete d;
51
88
}
52
89
 
53
90
void SearchResultsView::openURL(const KURL& url)
54
91
{
55
 
    if (m_listJob)
56
 
        m_listJob->kill();
57
 
    m_listJob = 0;
 
92
    if (d->listJob)
 
93
        d->listJob->kill();
 
94
    d->listJob = 0;
58
95
 
59
 
    if (!m_thumbJob.isNull())
60
 
        m_thumbJob->kill();
61
 
    m_thumbJob = 0;
 
96
    if (!d->thumbJob.isNull())
 
97
        d->thumbJob->kill();
 
98
    d->thumbJob = 0;
62
99
    
63
100
    QByteArray ba;
64
101
    QDataStream ds(ba, IO_WriteOnly);
65
 
    ds << m_libraryPath;
 
102
    ds << d->libraryPath;
66
103
    ds << url;
67
 
    ds << m_filter;
 
104
    ds << d->filter;
68
105
    ds << 0; // getting dimensions (not needed here)
 
106
    ds << 0; // recursive sub-album (not needed here)
 
107
    ds << 0; // recursive sub-tags (not needed here)
69
108
    ds << 2; // miniListing (Use 1 for full listing)
70
109
 
71
 
    m_listJob = new KIO::TransferJob(url, KIO::CMD_SPECIAL,
72
 
                                     ba, QByteArray(), false);
73
 
    connect(m_listJob, SIGNAL(result(KIO::Job*)),
74
 
            SLOT(slotResult(KIO::Job*)));
75
 
    connect(m_listJob, SIGNAL(data(KIO::Job*, const QByteArray&)),
76
 
            SLOT(slotData(KIO::Job*, const QByteArray&)));
 
110
    d->listJob = new KIO::TransferJob(url, KIO::CMD_SPECIAL,
 
111
                                      ba, QByteArray(), false);
 
112
 
 
113
    connect(d->listJob, SIGNAL(result(KIO::Job*)),
 
114
            this, SLOT(slotResult(KIO::Job*)));
 
115
 
 
116
    connect(d->listJob, SIGNAL(data(KIO::Job*, const QByteArray&)),
 
117
            this, SLOT(slotData(KIO::Job*, const QByteArray&)));
77
118
}
78
119
 
79
120
void SearchResultsView::clear()
80
121
{
81
 
    if (m_listJob)
82
 
        m_listJob->kill();
83
 
    m_listJob = 0;
84
 
 
85
 
    if (!m_thumbJob.isNull())
86
 
        m_thumbJob->kill();
87
 
    m_thumbJob = 0;
88
 
 
89
 
    m_itemDict.clear();
 
122
    if (d->listJob)
 
123
        d->listJob->kill();
 
124
    d->listJob = 0;
 
125
 
 
126
    if (!d->thumbJob.isNull())
 
127
        d->thumbJob->kill();
 
128
    d->thumbJob = 0;
 
129
 
 
130
    d->itemDict.clear();
90
131
    QIconView::clear();
91
132
}
92
133
 
103
144
    {
104
145
        ds >> path;
105
146
 
106
 
        SearchResultsItem* existingItem = (SearchResultsItem*) m_itemDict.find(path);
 
147
        SearchResultsItem* existingItem = (SearchResultsItem*) d->itemDict.find(path);
107
148
        if (existingItem)
108
149
        {
109
150
            existingItem->m_marked = true;
111
152
        }
112
153
            
113
154
        SearchResultsItem* item = new SearchResultsItem(this, path);
114
 
        m_itemDict.insert(path, item);
 
155
        d->itemDict.insert(path, item);
115
156
 
116
157
        ulist.append(KURL(path));
117
158
    }
123
164
        nextItem = item->nextItem();
124
165
        if (!item->m_marked)
125
166
        {
126
 
            m_itemDict.remove(item->m_path);
 
167
            d->itemDict.remove(item->m_path);
127
168
            delete item;
128
169
        }
129
170
        item = (SearchResultsItem*)nextItem;
130
171
    }
131
172
    arrangeItemsInGrid();
132
173
   
 
174
    bool match = !ulist.isEmpty();
 
175
 
 
176
    emit signalSearchResultsMatch(match);
133
177
    
134
 
    if (!ulist.isEmpty())
 
178
    if (match)
135
179
    {
136
 
        m_thumbJob = new ThumbnailJob(ulist, 128, true, true);
 
180
        d->thumbJob = new ThumbnailJob(ulist, 128, true, true);
137
181
    
138
 
        connect(m_thumbJob, SIGNAL(signalThumbnail(const KURL&, const QPixmap&)),
 
182
        connect(d->thumbJob, SIGNAL(signalThumbnail(const KURL&, const QPixmap&)),
139
183
                this, SLOT(slotGotThumbnail(const KURL&, const QPixmap&)));
140
184
   
141
 
        connect(m_thumbJob, SIGNAL(signalFailed(const KURL&)),
 
185
        connect(d->thumbJob, SIGNAL(signalFailed(const KURL&)),
142
186
                this, SLOT(slotFailedThumbnail(const KURL&)));     
143
187
    }
144
188
}
147
191
{
148
192
    if (job->error())
149
193
        job->showErrorDialog(this);
150
 
    m_listJob = 0;
 
194
    d->listJob = 0;
151
195
}
152
196
 
153
 
 
154
197
void SearchResultsView::slotGotThumbnail(const KURL& url, const QPixmap& pix)
155
198
{
156
 
    QIconViewItem* i = m_itemDict.find(url.path());
 
199
    QIconViewItem* i = d->itemDict.find(url.path());
157
200
    if (i)
158
201
        i->setPixmap(pix);
159
202
    
160
 
    m_thumbJob = 0;
 
203
    d->thumbJob = 0;
161
204
}
162
205
 
163
206
void SearchResultsView::slotFailedThumbnail(const KURL&)
164
207
{
165
 
    m_thumbJob = 0;    
 
208
    d->thumbJob = 0;    
166
209
}
167
210
 
168
 
#include "searchresultsview.moc"
169
 
 
 
211
}  // namespace Digikam