1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : Searches dates folder view used by timeline
9
* Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
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)
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.
22
* ============================================================ */
33
#include <kpopupmenu.h>
36
#include <kiconloader.h>
37
#include <kmessagebox.h>
42
#include "albummanager.h"
43
#include "albumsettings.h"
44
#include "folderitem.h"
45
#include "timelinefolderview.h"
46
#include "timelinefolderview.moc"
51
class TimeLineFolderItem : public FolderItem
56
TimeLineFolderItem(QListView* parent, SAlbum* album)
57
: FolderItem(parent, album->title()),
60
m_album->setExtraData(parent, this);
65
m_album->removeExtraData(listView());
68
int compare(QListViewItem* i, int , bool ) const
73
return text(0).localeAwareCompare(i->text(0));
78
return m_album ? m_album->id() : 0;
91
TimeLineFolderView::TimeLineFolderView(QWidget* parent)
92
: FolderView(parent, "TimeLineFolderView")
94
m_currentTimeLineSearchName = QString("_Current_Time_Line_Search_");
95
addColumn(i18n("My Date Searches"));
96
setResizeMode(QListView::LastColumn);
97
setRootIsDecorated(false);
99
connect(AlbumManager::instance(), SIGNAL(signalAlbumAdded(Album*)),
100
this, SLOT(slotAlbumAdded(Album*)));
102
connect(AlbumManager::instance(), SIGNAL(signalAlbumDeleted(Album*)),
103
this, SLOT(slotAlbumDeleted(Album*)));
105
connect(AlbumManager::instance(), SIGNAL(signalAlbumsCleared()),
106
this, SLOT(clear()));
108
connect(AlbumManager::instance(), SIGNAL(signalAlbumRenamed(Album*)),
109
this, SLOT(slotAlbumRenamed(Album*)));
111
connect(this, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)),
112
this, SLOT(slotContextMenu(QListViewItem*, const QPoint&, int)));
114
connect(this, SIGNAL(selectionChanged()),
115
this, SLOT(slotSelectionChanged()));
118
TimeLineFolderView::~TimeLineFolderView()
122
QString TimeLineFolderView::currentTimeLineSearchName() const
124
return m_currentTimeLineSearchName;
127
void TimeLineFolderView::slotTextSearchFilterChanged(const QString& filter)
129
QString search = filter.lower();
131
bool atleastOneMatch = false;
133
AlbumList sList = AlbumManager::instance()->allSAlbums();
134
for (AlbumList::iterator it = sList.begin(); it != sList.end(); ++it)
136
SAlbum* salbum = (SAlbum*)(*it);
137
TimeLineFolderItem* viewItem = (TimeLineFolderItem*) salbum->extraData(this);
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");
144
if (salbum->title().lower().contains(search) &&
145
type == QString("datesearch") &&
146
salbum->title() != currentTimeLineSearchName())
148
atleastOneMatch = true;
151
viewItem->setVisible(true);
157
viewItem->setVisible(false);
162
emit signalTextSearchFilterMatch(atleastOneMatch);
165
void TimeLineFolderView::searchDelete(SAlbum* album)
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 "
174
.arg(album->title()),
175
i18n("Delete Date Search?"),
177
KStdGuiItem::cancel());
179
if (result != KMessageBox::Yes)
182
AlbumManager::instance()->deleteSAlbum(album);
185
void TimeLineFolderView::slotAlbumAdded(Album* a)
187
if (!a || a->type() != Album::SEARCH)
190
SAlbum *salbum = dynamic_cast<SAlbum*>(a);
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;
198
QString type = url.queryItem("type");
199
if (type != QString("datesearch")) return;
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;
205
TimeLineFolderItem* item = new TimeLineFolderItem(this, salbum);
206
item->setPixmap(0, SmallIcon("find", AlbumSettings::instance()->getDefaultTreeIconSize()));
209
void TimeLineFolderView::slotAlbumDeleted(Album* a)
211
if (!a || a->type() != Album::SEARCH)
214
SAlbum* album = (SAlbum*)a;
216
TimeLineFolderItem* item = (TimeLineFolderItem*) album->extraData(this);
221
void TimeLineFolderView::slotAlbumRenamed(Album* album)
226
SAlbum* salbum = dynamic_cast<SAlbum*>(album);
230
TimeLineFolderItem* item = (TimeLineFolderItem*)(salbum->extraData(this));
232
item->setText(0, item->album()->title());
235
void TimeLineFolderView::slotSelectionChanged()
237
QListViewItem* selItem = 0;
239
QListViewItemIterator it( this );
242
if (it.current()->isSelected())
244
selItem = it.current();
252
emit signalAlbumSelected(0);
256
TimeLineFolderItem* searchItem = dynamic_cast<TimeLineFolderItem*>(selItem);
258
if (!searchItem || !searchItem->album())
259
emit signalAlbumSelected(0);
261
emit signalAlbumSelected(searchItem->album());
264
void TimeLineFolderView::slotContextMenu(QListViewItem* item, const QPoint&, int)
268
TimeLineFolderItem* sItem = dynamic_cast<TimeLineFolderItem*>(item);
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);
275
switch (popmenu.exec(QCursor::pos()))
279
emit signalRenameAlbum(sItem->album());
284
searchDelete(sItem->album());
292
void TimeLineFolderView::selectItem(int id)
294
SAlbum *album = AlbumManager::instance()->findSAlbum(id);
298
TimeLineFolderItem *item = (TimeLineFolderItem*)album->extraData(this);
301
setSelected(item, true);
302
ensureItemVisible(item);
306
} // namespace Digikam