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

« back to all changes in this revision

Viewing changes to digikam/digikam/timelinefolderview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.2.15 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080717202539-6n7dtirbkoo7qvhd
Tags: 2:0.9.4-1
* 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
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2008-01-14
 
7
 * Description : Searches dates folder view used by timeline
 
8
 *
 
9
 * Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 * 
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
// Qt includes.
 
25
 
 
26
#include <qfont.h>
 
27
#include <qpainter.h>
 
28
#include <qstyle.h>
 
29
#include <qcursor.h>
 
30
 
 
31
// KDe includes.
 
32
 
 
33
#include <kpopupmenu.h>
 
34
#include <klocale.h>
 
35
#include <kglobal.h>
 
36
#include <kiconloader.h>
 
37
#include <kmessagebox.h>
 
38
 
 
39
// Local includes.
 
40
 
 
41
#include "album.h"
 
42
#include "albummanager.h"
 
43
#include "albumsettings.h"
 
44
#include "folderitem.h"
 
45
#include "timelinefolderview.h"
 
46
#include "timelinefolderview.moc"
 
47
 
 
48
namespace Digikam
 
49
{
 
50
 
 
51
class TimeLineFolderItem : public FolderItem
 
52
{
 
53
 
 
54
public:
 
55
 
 
56
    TimeLineFolderItem(QListView* parent, SAlbum* album)
 
57
        : FolderItem(parent, album->title()),
 
58
          m_album(album)
 
59
    {
 
60
        m_album->setExtraData(parent, this);
 
61
    }
 
62
 
 
63
    ~TimeLineFolderItem()
 
64
    {
 
65
        m_album->removeExtraData(listView());
 
66
    }
 
67
 
 
68
    int compare(QListViewItem* i, int , bool ) const
 
69
    {
 
70
        if (!i)
 
71
            return 0;
 
72
 
 
73
        return text(0).localeAwareCompare(i->text(0));
 
74
    }
 
75
 
 
76
    int id() const
 
77
    {
 
78
        return m_album ? m_album->id() : 0;
 
79
    }
 
80
 
 
81
    SAlbum* album() const
 
82
    {
 
83
        return m_album;
 
84
    }
 
85
 
 
86
private:
 
87
 
 
88
    SAlbum *m_album;
 
89
};
 
90
 
 
91
TimeLineFolderView::TimeLineFolderView(QWidget* parent)
 
92
                  : FolderView(parent, "TimeLineFolderView")
 
93
{
 
94
    m_currentTimeLineSearchName = QString("_Current_Time_Line_Search_");
 
95
    addColumn(i18n("My Date Searches"));
 
96
    setResizeMode(QListView::LastColumn);
 
97
    setRootIsDecorated(false);
 
98
 
 
99
    connect(AlbumManager::instance(), SIGNAL(signalAlbumAdded(Album*)),
 
100
            this, SLOT(slotAlbumAdded(Album*)));
 
101
 
 
102
    connect(AlbumManager::instance(), SIGNAL(signalAlbumDeleted(Album*)),
 
103
            this, SLOT(slotAlbumDeleted(Album*)));
 
104
 
 
105
    connect(AlbumManager::instance(), SIGNAL(signalAlbumsCleared()),
 
106
            this, SLOT(clear()));
 
107
 
 
108
    connect(AlbumManager::instance(), SIGNAL(signalAlbumRenamed(Album*)),
 
109
        this, SLOT(slotAlbumRenamed(Album*)));
 
110
 
 
111
    connect(this, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)),
 
112
            this, SLOT(slotContextMenu(QListViewItem*, const QPoint&, int)));
 
113
 
 
114
    connect(this, SIGNAL(selectionChanged()),
 
115
            this, SLOT(slotSelectionChanged()));
 
116
}
 
117
 
 
118
TimeLineFolderView::~TimeLineFolderView()
 
119
{
 
120
}
 
121
 
 
122
QString TimeLineFolderView::currentTimeLineSearchName() const
 
123
{
 
124
    return m_currentTimeLineSearchName;
 
125
}
 
126
 
 
127
void TimeLineFolderView::slotTextSearchFilterChanged(const QString& filter)
 
128
{
 
129
    QString search = filter.lower();
 
130
 
 
131
    bool atleastOneMatch = false;
 
132
 
 
133
    AlbumList sList = AlbumManager::instance()->allSAlbums();
 
134
    for (AlbumList::iterator it = sList.begin(); it != sList.end(); ++it)
 
135
    {
 
136
        SAlbum* salbum               = (SAlbum*)(*it);
 
137
        TimeLineFolderItem* viewItem = (TimeLineFolderItem*) salbum->extraData(this);
 
138
 
 
139
        // Check if a special url query exist to identify a SAlbum dedicaced to Date Search
 
140
        // used with TimeLine.
 
141
        KURL url     = salbum->kurl();
 
142
        QString type = url.queryItem("type");
 
143
 
 
144
        if (salbum->title().lower().contains(search) &&
 
145
            type == QString("datesearch") && 
 
146
            salbum->title() != currentTimeLineSearchName())
 
147
        {
 
148
            atleastOneMatch = true;
 
149
 
 
150
            if (viewItem)
 
151
                viewItem->setVisible(true);
 
152
        }
 
153
        else
 
154
        {
 
155
            if (viewItem)
 
156
            {
 
157
                viewItem->setVisible(false);
 
158
            }
 
159
        }
 
160
    }
 
161
 
 
162
    emit signalTextSearchFilterMatch(atleastOneMatch);
 
163
}
 
164
 
 
165
void TimeLineFolderView::searchDelete(SAlbum* album)
 
166
{
 
167
    if (!album)
 
168
        return;
 
169
 
 
170
    // Make sure that a complicated search is not deleted accidentally
 
171
    int result = KMessageBox::warningYesNo(this, i18n("Are you sure you want to "
 
172
                                                      "delete the selected Date Search "
 
173
                                                      "\"%1\"?")
 
174
                                           .arg(album->title()),
 
175
                                           i18n("Delete Date Search?"),
 
176
                                           i18n("Delete"),
 
177
                                           KStdGuiItem::cancel());
 
178
 
 
179
    if (result != KMessageBox::Yes)
 
180
        return;
 
181
 
 
182
    AlbumManager::instance()->deleteSAlbum(album);
 
183
}
 
184
 
 
185
void TimeLineFolderView::slotAlbumAdded(Album* a)
 
186
{
 
187
    if (!a || a->type() != Album::SEARCH)
 
188
        return;
 
189
 
 
190
    SAlbum *salbum  = dynamic_cast<SAlbum*>(a);
 
191
    if (!salbum) return;
 
192
 
 
193
    // Check if a special url query exist to identify a SAlbum dedicaced to Date Search
 
194
    KURL url = salbum->kurl();
 
195
    QMap<QString, QString> queries = url.queryItems();
 
196
    if (queries.isEmpty()) return;
 
197
 
 
198
    QString type = url.queryItem("type");
 
199
    if (type != QString("datesearch")) return;
 
200
 
 
201
    // We will ignore the internal Dates Search Album used to perform selection from timeline.
 
202
    QString name = url.queryItem("name");
 
203
    if (name == currentTimeLineSearchName()) return;
 
204
 
 
205
    TimeLineFolderItem* item = new TimeLineFolderItem(this, salbum);
 
206
    item->setPixmap(0, SmallIcon("find", AlbumSettings::instance()->getDefaultTreeIconSize()));
 
207
}
 
208
 
 
209
void TimeLineFolderView::slotAlbumDeleted(Album* a)
 
210
{
 
211
    if (!a || a->type() != Album::SEARCH)
 
212
        return;
 
213
 
 
214
    SAlbum* album = (SAlbum*)a;
 
215
 
 
216
    TimeLineFolderItem* item = (TimeLineFolderItem*) album->extraData(this);
 
217
    if (item)
 
218
        delete item;
 
219
}
 
220
 
 
221
void TimeLineFolderView::slotAlbumRenamed(Album* album)
 
222
{
 
223
    if (!album)
 
224
        return;
 
225
 
 
226
    SAlbum* salbum = dynamic_cast<SAlbum*>(album);
 
227
    if (!salbum)
 
228
        return;
 
229
 
 
230
    TimeLineFolderItem* item = (TimeLineFolderItem*)(salbum->extraData(this));
 
231
    if (item)
 
232
        item->setText(0, item->album()->title());
 
233
}
 
234
 
 
235
void TimeLineFolderView::slotSelectionChanged()
 
236
{
 
237
    QListViewItem* selItem = 0;
 
238
 
 
239
    QListViewItemIterator it( this );
 
240
    while (it.current())
 
241
    {
 
242
        if (it.current()->isSelected())
 
243
        {
 
244
            selItem = it.current();
 
245
            break;
 
246
        }
 
247
        ++it;
 
248
    }
 
249
 
 
250
    if (!selItem)
 
251
    {
 
252
        emit signalAlbumSelected(0);
 
253
        return;
 
254
    }
 
255
 
 
256
    TimeLineFolderItem* searchItem = dynamic_cast<TimeLineFolderItem*>(selItem);
 
257
 
 
258
    if (!searchItem || !searchItem->album())
 
259
        emit signalAlbumSelected(0);
 
260
    else
 
261
        emit signalAlbumSelected(searchItem->album());
 
262
}
 
263
 
 
264
void TimeLineFolderView::slotContextMenu(QListViewItem* item, const QPoint&, int)
 
265
{
 
266
    if (!item) return;
 
267
 
 
268
    TimeLineFolderItem* sItem = dynamic_cast<TimeLineFolderItem*>(item);
 
269
 
 
270
    KPopupMenu popmenu(this);
 
271
    popmenu.insertTitle(SmallIcon("digikam"), i18n("My Date Searches"));
 
272
    popmenu.insertItem(SmallIcon("pencil"), i18n("Rename..."), 10);
 
273
    popmenu.insertItem(SmallIcon("editdelete"), i18n("Delete"), 11);
 
274
 
 
275
    switch (popmenu.exec(QCursor::pos()))
 
276
    {
 
277
        case 10:
 
278
        {
 
279
            emit signalRenameAlbum(sItem->album());
 
280
            break;
 
281
        }
 
282
        case 11:
 
283
        {
 
284
            searchDelete(sItem->album());
 
285
            break;
 
286
        }
 
287
        default:
 
288
            break;
 
289
    }
 
290
}
 
291
 
 
292
void TimeLineFolderView::selectItem(int id)
 
293
{
 
294
    SAlbum *album = AlbumManager::instance()->findSAlbum(id);
 
295
    if(!album)
 
296
        return;
 
297
 
 
298
    TimeLineFolderItem *item = (TimeLineFolderItem*)album->extraData(this);
 
299
    if(item)
 
300
    {
 
301
        setSelected(item, true);
 
302
        ensureItemVisible(item);
 
303
    }
 
304
}
 
305
 
 
306
}  // namespace Digikam