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

« back to all changes in this revision

Viewing changes to digikam/digikam/tagfilterview.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:
7
7
 * Description : tags filter view
8
8
 *
9
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>
 
10
 * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
11
 *
12
12
 * This program is free software; you can redistribute it
13
13
 * and/or modify it under the terms of the GNU General
46
46
 
47
47
#include "ddebug.h"
48
48
#include "albummanager.h"
 
49
#include "albumsettings.h"
49
50
#include "albumdb.h"
50
51
#include "album.h"
51
52
#include "albumlister.h"
56
57
#include "imageattributeswatch.h"
57
58
#include "imageinfo.h"
58
59
#include "metadatahub.h"
59
 
#include "tagcreatedlg.h"
 
60
#include "tageditdlg.h"
60
61
#include "statusprogressbar.h"
61
62
#include "tagfilterview.h"
62
63
#include "tagfilterview.moc"
76
77
 
77
78
public:
78
79
 
79
 
    TagFilterViewItem(QListView* parent, TAlbum* tag, bool untagged=false)
80
 
        : FolderCheckListItem(parent, tag ? tag->title() : i18n("Not Tagged"),
81
 
                              QCheckListItem::CheckBox/*Controller*/)
82
 
    {
83
 
        m_tag      = tag;
84
 
        m_untagged = untagged;
85
 
        setDragEnabled(!untagged);
86
 
 
87
 
        if (tag)
88
 
            tag->setExtraData(listView(), this);
89
 
    }
90
 
 
91
 
    TagFilterViewItem(QListViewItem* parent, TAlbum* tag)
92
 
        : FolderCheckListItem(parent, tag->title(), 
93
 
                              QCheckListItem::CheckBox/*Controller*/)
94
 
    {
95
 
        m_tag      = tag;
96
 
        m_untagged = false;
97
 
        setDragEnabled(true);
98
 
 
99
 
        if (tag)
100
 
            tag->setExtraData(listView(), this);
101
 
    }
102
 
 
103
 
    virtual void stateChange(bool val)
104
 
    {
105
 
        QCheckListItem::stateChange(val);
106
 
 
107
 
/* NOTE G.Caulier 2007/01/08: this code is now disable because TagFilterViewItem 
108
 
                              have been changed from QCheckListItem::CheckBoxController 
109
 
                              to QCheckListItem::CheckBox.
110
 
 
111
 
        // All TagFilterViewItems are CheckBoxControllers. If they have no children,
112
 
        // they should be of type CheckBox, but that is not possible with our way of adding items.
113
 
        // When clicked, children-less items first change to the NoChange state, and a second
114
 
        // click is necessary to set them to On and make the filter take effect.
115
 
        // So set them to On if the condition is met.
116
 
        if (!firstChild() && state() == NoChange)
117
 
        {
118
 
            setState(On);
119
 
        }
120
 
*/
121
 
 
122
 
        ((TagFilterView*)listView())->stateChanged(this);
123
 
    }
124
 
 
125
 
    int compare(QListViewItem* i, int column, bool ascending) const
126
 
    {
127
 
        if (m_untagged)
128
 
            return 1;
129
 
 
130
 
        TagFilterViewItem* dItem = dynamic_cast<TagFilterViewItem*>(i);
131
 
        if (!dItem)
132
 
            return 0;
133
 
 
134
 
        if (dItem && dItem->m_untagged)
135
 
            return -1;
136
 
 
137
 
        return QListViewItem::compare(i, column, ascending);
138
 
    }
139
 
 
140
 
    void paintCell(QPainter* p, const QColorGroup & cg, int column, int width, int align)
141
 
    {
142
 
        if (!m_untagged)
143
 
        {
144
 
            FolderCheckListItem::paintCell(p, cg, column, width, align);
145
 
            return;
146
 
        }
147
 
 
148
 
        QFont f(listView()->font());
149
 
        f.setBold(true);
150
 
        f.setItalic(true);
151
 
        p->setFont(f);
152
 
 
153
 
        QColorGroup mcg(cg);
154
 
        mcg.setColor(QColorGroup::Text, Qt::darkRed);
155
 
 
156
 
        FolderCheckListItem::paintCell(p, mcg, column, width, align);
157
 
    }
158
 
 
159
 
    TAlbum *m_tag;
 
80
    TagFilterViewItem(QListView* parent, TAlbum* tag, bool untagged=false);
 
81
    TagFilterViewItem(QListViewItem* parent, TAlbum* tag);
 
82
 
 
83
    TAlbum* album() const;
 
84
    int     id() const;
 
85
    bool    untagged() const;
 
86
    void    refresh();
 
87
    void    setOpen(bool o);
 
88
    void    setCount(int count);
 
89
    int     count();
 
90
    int     compare(QListViewItem* i, int column, bool ascending) const;
 
91
 
 
92
private:
 
93
 
 
94
    void    stateChange(bool val);
 
95
    void    paintCell(QPainter* p, const QColorGroup & cg, int column, int width, int align);
 
96
 
 
97
private:
 
98
 
160
99
    bool    m_untagged;
 
100
 
 
101
    int     m_count;
 
102
 
 
103
    TAlbum *m_album;
161
104
};
162
105
 
 
106
TagFilterViewItem::TagFilterViewItem(QListView* parent, TAlbum* album, bool untagged)
 
107
                 : FolderCheckListItem(parent, album ? album->title() : i18n("Not Tagged"),
 
108
                                       QCheckListItem::CheckBox/*Controller*/)
 
109
{
 
110
    m_album    = album;
 
111
    m_untagged = untagged;
 
112
    m_count    = 0;
 
113
    setDragEnabled(!untagged);
 
114
 
 
115
    if (m_album)
 
116
        m_album->setExtraData(listView(), this);
 
117
}
 
118
 
 
119
TagFilterViewItem::TagFilterViewItem(QListViewItem* parent, TAlbum* album)
 
120
                 : FolderCheckListItem(parent, album->title(),
 
121
                                       QCheckListItem::CheckBox/*Controller*/)
 
122
{
 
123
    m_album     = album;
 
124
    m_untagged  = false;
 
125
    m_count     = 0;
 
126
    setDragEnabled(true);
 
127
 
 
128
    if (m_album)
 
129
        m_album->setExtraData(listView(), this);
 
130
}
 
131
 
 
132
void TagFilterViewItem::refresh()
 
133
{
 
134
    if (!m_album) return;
 
135
 
 
136
    if (AlbumSettings::instance()->getShowFolderTreeViewItemsCount())
 
137
    {
 
138
        if (isOpen())
 
139
            setText(0, QString("%1 (%2)").arg(m_album->title()).arg(m_count));
 
140
        else
 
141
        {
 
142
            int countRecursive = m_count;
 
143
            AlbumIterator it(m_album);
 
144
            while ( it.current() )
 
145
            {
 
146
                TagFilterViewItem *item = (TagFilterViewItem*)it.current()->extraData(listView());
 
147
                if (item)
 
148
                    countRecursive += item->count();
 
149
                ++it;
 
150
            }
 
151
            setText(0, QString("%1 (%2)").arg(m_album->title()).arg(countRecursive));
 
152
        }
 
153
    }
 
154
    else
 
155
    {
 
156
        setText(0, m_album->title());
 
157
    }
 
158
}
 
159
 
 
160
void TagFilterViewItem::stateChange(bool val)
 
161
{
 
162
    QCheckListItem::stateChange(val);
 
163
 
 
164
    /* NOTE G.Caulier 2007/01/08: this code is now disable because TagFilterViewItem
 
165
                        have been changed from QCheckListItem::CheckBoxController
 
166
                        to QCheckListItem::CheckBox.
 
167
 
 
168
    // All TagFilterViewItems are CheckBoxControllers. If they have no children,
 
169
    // they should be of type CheckBox, but that is not possible with our way of adding items.
 
170
    // When clicked, children-less items first change to the NoChange state, and a second
 
171
    // click is necessary to set them to On and make the filter take effect.
 
172
    // So set them to On if the condition is met.
 
173
    if (!firstChild() && state() == NoChange)
 
174
    {
 
175
        setState(On);
 
176
    }
 
177
    */
 
178
 
 
179
    ((TagFilterView*)listView())->stateChanged(this);
 
180
}
 
181
 
 
182
int TagFilterViewItem::compare(QListViewItem* i, int column, bool ascending) const
 
183
{
 
184
    if (m_untagged)
 
185
        return 1;
 
186
 
 
187
    TagFilterViewItem* dItem = dynamic_cast<TagFilterViewItem*>(i);
 
188
    if (!dItem)
 
189
        return 0;
 
190
 
 
191
    if (dItem && dItem->m_untagged)
 
192
        return -1;
 
193
 
 
194
    return QListViewItem::compare(i, column, ascending);
 
195
}
 
196
 
 
197
void TagFilterViewItem::paintCell(QPainter* p, const QColorGroup & cg, int column, int width, int align)
 
198
{
 
199
    if (!m_untagged)
 
200
    {
 
201
        FolderCheckListItem::paintCell(p, cg, column, width, align);
 
202
        return;
 
203
    }
 
204
 
 
205
    QFont f(listView()->font());
 
206
    f.setBold(true);
 
207
    f.setItalic(true);
 
208
    p->setFont(f);
 
209
 
 
210
    QColorGroup mcg(cg);
 
211
    mcg.setColor(QColorGroup::Text, Qt::darkRed);
 
212
 
 
213
    FolderCheckListItem::paintCell(p, mcg, column, width, align);
 
214
}
 
215
 
 
216
void TagFilterViewItem::setOpen(bool o)
 
217
{
 
218
    QListViewItem::setOpen(o);
 
219
    refresh();
 
220
}
 
221
 
 
222
TAlbum* TagFilterViewItem::album() const
 
223
{
 
224
    return m_album;
 
225
}
 
226
 
 
227
int TagFilterViewItem::id() const
 
228
{
 
229
    return m_album ? m_album->id() : 0;
 
230
}
 
231
 
 
232
void TagFilterViewItem::setCount(int count)
 
233
{
 
234
    m_count = count;
 
235
    refresh();
 
236
}
 
237
 
 
238
int TagFilterViewItem::count()
 
239
{
 
240
    return m_count;
 
241
}
 
242
 
 
243
bool TagFilterViewItem::untagged() const
 
244
{
 
245
    return m_untagged;
 
246
}
 
247
 
163
248
// ---------------------------------------------------------------------
164
249
 
165
250
class TagFilterViewPrivate
169
254
 
170
255
    TagFilterViewPrivate()
171
256
    {
172
 
        dragItem       = 0;
173
257
        ABCMenu        = 0;
174
258
        timer          = 0;
175
259
        toggleAutoTags = TagFilterView::NoToggleAuto;
178
262
 
179
263
    QTimer                         *timer;
180
264
 
181
 
    QPoint                          dragStartPos;    
182
 
 
183
265
    QPopupMenu                     *ABCMenu;
184
266
 
185
267
    TagFilterView::ToggleAutoTags   toggleAutoTags;
186
268
 
187
269
    AlbumLister::MatchingCondition  matchingCond;
188
 
    
189
 
    TagFilterViewItem              *dragItem;
190
270
};
191
271
 
192
 
 
193
272
TagFilterView::TagFilterView(QWidget* parent)
194
273
             : FolderView(parent)
195
274
{
206
285
    TagFilterViewItem* notTaggedItem = new TagFilterViewItem(this, 0, true);
207
286
    notTaggedItem->setPixmap(0, AlbumThumbnailLoader::instance()->getStandardTagIcon());
208
287
 
209
 
    // -- setup slots ---------------------------------------------------------
 
288
    // ------------------------------------------------------------------------
 
289
 
 
290
    connect(AlbumManager::instance(), SIGNAL(signalTAlbumsDirty(const QMap<int, int>&)),
 
291
            this, SLOT(slotRefresh(const QMap<int, int>&)));
210
292
 
211
293
    connect(AlbumManager::instance(), SIGNAL(signalAlbumAdded(Album*)),
212
294
            this, SLOT(slotTagAdded(Album*)));
226
308
    connect(AlbumManager::instance(), SIGNAL(signalTAlbumMoved(TAlbum*, TAlbum*)),
227
309
            this, SLOT(slotTagMoved(TAlbum*, TAlbum*)));
228
310
 
 
311
    // ------------------------------------------------------------------------
 
312
 
229
313
    AlbumThumbnailLoader *loader = AlbumThumbnailLoader::instance();
230
314
 
231
315
    connect(loader, SIGNAL(signalThumbnail(Album *, const QPixmap&)),
243
327
    connect(d->timer, SIGNAL(timeout()),
244
328
            this, SLOT(slotTimeOut()));
245
329
 
246
 
    // -- read config ---------------------------------------------------------
 
330
    // ------------------------------------------------------------------------
247
331
 
248
332
    KConfig* config = kapp->config();
249
333
    config->setGroup("Tag Filters View");
265
349
    delete d;
266
350
}
267
351
 
268
 
void TagFilterView::slotTagFilterChanged(const QString& filter)
 
352
void TagFilterView::slotTextTagFilterChanged(const QString& filter)
269
353
{
270
354
    QString search = filter.lower();
271
355
 
311
395
                ++it;
312
396
            }
313
397
        }
314
 
    
 
398
 
315
399
        TagFilterViewItem* viewItem = (TagFilterViewItem*) talbum->extraData(this);
316
400
 
317
401
        if (match)
330
414
        }
331
415
    }
332
416
 
333
 
    emit signalTagFilterMatch(atleastOneMatch);
 
417
    emit signalTextTagFilterMatch(atleastOneMatch);
334
418
}
335
419
 
336
420
void TagFilterView::stateChanged(TagFilterViewItem* item)
337
421
{
338
 
    ToggleAutoTags oldAutoTags = d->toggleAutoTags;            
 
422
    ToggleAutoTags oldAutoTags = d->toggleAutoTags;
339
423
 
340
424
    switch(d->toggleAutoTags)
341
425
    {
367
451
    d->timer->start(50, true);
368
452
}
369
453
 
370
 
void TagFilterView::contentsMouseMoveEvent(QMouseEvent *e)
371
 
{
372
 
    QListView::contentsMouseMoveEvent(e);
373
 
 
374
 
    if(e->state() == NoButton)
375
 
    {
376
 
        if(KGlobalSettings::changeCursorOverIcon())
377
 
        {
378
 
            QPoint vp = contentsToViewport(e->pos());
379
 
            QListViewItem *item = itemAt(vp);
380
 
            if (mouseInItemRect(item, vp.x()))
381
 
                setCursor(KCursor::handCursor());
382
 
            else
383
 
                unsetCursor();
384
 
        }
385
 
        return;
386
 
    }
387
 
    
388
 
    if(d->dragItem && 
389
 
       (d->dragStartPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
390
 
    {
391
 
        QPoint vp = contentsToViewport(e->pos());
392
 
        TagFilterViewItem *item = dynamic_cast<TagFilterViewItem*>(itemAt(vp));
393
 
        if(!item)
394
 
        {
395
 
            d->dragItem = 0;
396
 
            return;
397
 
        }
398
 
    }    
399
 
}
400
 
 
401
 
void TagFilterView::contentsMousePressEvent(QMouseEvent *e)
402
 
{
403
 
    QPoint vp = contentsToViewport(e->pos());
404
 
    TagFilterViewItem *item = dynamic_cast<TagFilterViewItem*>(itemAt(vp));
405
 
 
406
 
    if(item && e->button() == RightButton) 
407
 
    {
408
 
        bool isOn = item->isOn();
409
 
        QListView::contentsMousePressEvent(e);
410
 
        // Restore the status of checkbox. 
411
 
        item->setOn(isOn);
412
 
        return;
413
 
    }
414
 
 
415
 
    QListView::contentsMousePressEvent(e);
416
 
 
417
 
    if(item && e->button() == LeftButton) 
418
 
    {
419
 
        d->dragStartPos = e->pos();
420
 
        d->dragItem     = item;
421
 
    }
422
 
}
423
 
 
424
 
void TagFilterView::contentsMouseReleaseEvent(QMouseEvent *e)
425
 
{
426
 
    QListView::contentsMouseReleaseEvent(e);
427
 
 
428
 
    d->dragItem = 0;
429
 
}
430
 
 
431
454
QDragObject* TagFilterView::dragObject()
432
455
{
433
456
    TagFilterViewItem *item = dynamic_cast<TagFilterViewItem*>(dragItem());
434
457
    if(!item)
435
458
        return 0;
436
459
 
437
 
    TagDrag *t = new TagDrag(item->m_tag->id(), this);
 
460
    TagDrag *t = new TagDrag(item->id(), this);
438
461
    t->setPixmap(*item->pixmap(0));
439
462
 
440
463
    return t;
441
464
}
442
465
 
443
 
TagFilterViewItem* TagFilterView::dragItem() const
444
 
{
445
 
    return d->dragItem;
446
 
}
447
 
 
448
466
bool TagFilterView::acceptDrop(const QDropEvent *e) const
449
467
{
450
468
    QPoint vp = contentsToViewport(e->pos());
458
476
            return true;
459
477
 
460
478
        // Do not allow dragging at the "Not Tagged" item.
461
 
        if (itemDrop->m_untagged)
 
479
        if (itemDrop->untagged())
462
480
            return false;
463
481
 
464
482
        // Dragging an item on itself makes no sense
466
484
            return false;
467
485
 
468
486
        // Dragging a parent on its child makes no sense
469
 
        if(itemDrag && itemDrag->m_tag->isAncestorOf(itemDrop->m_tag))
 
487
        if(itemDrag && itemDrag->album()->isAncestorOf(itemDrop->album()))
470
488
            return false;
471
489
 
472
490
        return true;
473
491
    }
474
492
 
475
 
    if (ItemDrag::canDecode(e) && itemDrop && !itemDrop->m_untagged)
 
493
    if (ItemDrag::canDecode(e) && itemDrop && !itemDrop->untagged())
476
494
    {
477
 
        TAlbum *tag = itemDrop->m_tag;
478
 
        
 
495
        TAlbum *tag = itemDrop->album();
 
496
 
479
497
        if (tag)
480
498
        {
481
499
            if (tag->parent())
482
 
            {         
 
500
            {
483
501
                // Only other possibility is image items being dropped
484
502
                // And allow this only if there is a Tag to be dropped
485
503
                // on and also the Tag is not root or "Not Tagged" item.
501
519
    QPoint vp = contentsToViewport(e->pos());
502
520
    TagFilterViewItem *itemDrop = dynamic_cast<TagFilterViewItem*>(itemAt(vp));
503
521
 
504
 
    if (!itemDrop || itemDrop->m_untagged)
 
522
    if (!itemDrop || itemDrop->untagged())
505
523
        return;
506
524
 
507
525
    if(TagDrag::canDecode(e))
516
534
 
517
535
        if(!talbum)
518
536
            return;
519
 
        
520
 
        if (talbum == itemDrop->m_tag)
 
537
 
 
538
        if (talbum == itemDrop->album())
521
539
            return;
522
540
 
523
541
        KPopupMenu popMenu(this);
540
558
            else
541
559
            {
542
560
                // move dragItem as child of dropItem
543
 
                newParentTag = itemDrop->m_tag;
 
561
                newParentTag = itemDrop->album();
544
562
            }
545
563
 
546
564
            QString errMsg;
558
576
 
559
577
    if (ItemDrag::canDecode(e))
560
578
    {
561
 
        TAlbum *destAlbum = itemDrop->m_tag;
 
579
        TAlbum *destAlbum = itemDrop->album();
562
580
 
563
581
        KURL::List      urls;
564
582
        KURL::List      kioURLs;
604
622
            emit signalProgressBarMode(StatusProgressBar::ProgressBarMode, 
605
623
                                       i18n("Assigning image tags. Please wait..."));
606
624
 
 
625
            AlbumLister::instance()->blockSignals(true);
607
626
            AlbumManager::instance()->albumDB()->beginTransaction();
608
627
            int i=0;
609
628
            for (QValueList<int>::const_iterator it = imageIDs.begin();
621
640
                emit signalProgressValue((int)((i++/(float)imageIDs.count())*100.0));
622
641
                kapp->processEvents();
623
642
            }
 
643
            AlbumLister::instance()->blockSignals(false);
624
644
            AlbumManager::instance()->albumDB()->commitTransaction();
625
645
 
626
646
            ImageAttributesWatch::instance()->imagesChanged(destAlbum->id());
676
696
 
677
697
    TagFilterViewItem* item = (TagFilterViewItem*)(tag->extraData(this));
678
698
    if (item)
679
 
    {
680
 
        item->setText(0, tag->title());
681
 
    }
 
699
        item->refresh();
682
700
}
683
701
 
684
702
void TagFilterView::slotTagMoved(TAlbum* tag, TAlbum* newParent)
727
745
    if (!item)
728
746
        return;
729
747
 
 
748
    // NOTE: see B.K.O #158558: unselected tag filter and all childrens before to delete it.
 
749
    toggleChildTags(item, false);
 
750
    item->setOn(false);
 
751
 
730
752
    album->removeExtraData(this);
731
753
    delete item;
732
754
}
818
840
    while (it.current())
819
841
    {
820
842
        TagFilterViewItem* item = (TagFilterViewItem*)it.current();
821
 
        if (item->m_tag)
822
 
            filterTags.append(item->m_tag->id());
823
 
        else if (item->m_untagged)
 
843
        if (item->album())
 
844
            filterTags.append(item->album()->id());
 
845
        else if (item->untagged())
824
846
            showUnTagged = true;
825
847
        ++it;
826
848
    }
831
853
void TagFilterView::slotContextMenu(QListViewItem* it, const QPoint&, int)
832
854
{
833
855
    TagFilterViewItem *item = dynamic_cast<TagFilterViewItem*>(it);
834
 
    if (item && item->m_untagged)
 
856
    if (item && item->untagged())
835
857
        return;
836
858
 
837
859
    d->ABCMenu = new QPopupMenu;
838
 
    
 
860
 
839
861
    connect(d->ABCMenu, SIGNAL( aboutToShow() ),
840
862
            this, SLOT( slotABCContextMenu() ));
841
863
 
894
916
    matchingCongMenu.setItemChecked((d->matchingCond == AlbumLister::OrCondition) ? 25 : 26, true);
895
917
    popmenu.insertItem(i18n("Matching Condition"), &matchingCongMenu);
896
918
 
897
 
    ToggleAutoTags oldAutoTags = d->toggleAutoTags;            
 
919
    ToggleAutoTags oldAutoTags = d->toggleAutoTags;
898
920
 
899
921
    int choice = popmenu.exec((QCursor::pos()));
900
922
    switch( choice )
917
939
        case 13:    // Reset Tag Icon.
918
940
        {
919
941
            QString errMsg;
920
 
            AlbumManager::instance()->updateTAlbumIcon(item->m_tag, QString("tag"), 0, errMsg);
 
942
            AlbumManager::instance()->updateTAlbumIcon(item->album(), QString("tag"), 0, errMsg);
921
943
            break;
922
 
        }        
 
944
        }
923
945
        case 14:    // Select All Tags.
924
946
        {
925
947
            d->toggleAutoTags = TagFilterView::NoToggleAuto;
929
951
                TagFilterViewItem* item = (TagFilterViewItem*)it.current();
930
952
 
931
953
                // Ignore "Not Tagged" tag filter.
932
 
                if (!item->m_untagged)
 
954
                if (!item->untagged())
933
955
                    item->setOn(true);
934
956
 
935
957
                ++it;
947
969
                TagFilterViewItem* item = (TagFilterViewItem*)it.current();
948
970
 
949
971
                // Ignore "Not Tagged" tag filter.
950
 
                if (!item->m_untagged)
 
972
                if (!item->untagged())
951
973
                    item->setOn(false);
952
974
 
953
975
                ++it;
965
987
                TagFilterViewItem* item = (TagFilterViewItem*)it.current();
966
988
 
967
989
                // Ignore "Not Tagged" tag filter.
968
 
                if (!item->m_untagged)
 
990
                if (!item->untagged())
969
991
                    item->setOn(!item->isOn());
970
992
 
971
993
                ++it;
978
1000
        {
979
1001
            d->toggleAutoTags = TagFilterView::NoToggleAuto;
980
1002
            toggleChildTags(item, true);
981
 
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->m_tag->extraData(this);
982
 
            tItem->setOn(true);            
 
1003
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->album()->extraData(this);
 
1004
            tItem->setOn(true);
983
1005
            d->toggleAutoTags = oldAutoTags;
984
1006
            break;
985
1007
        }
987
1009
        {
988
1010
            d->toggleAutoTags = TagFilterView::NoToggleAuto;
989
1011
            toggleChildTags(item, false);
990
 
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->m_tag->extraData(this);
991
 
            tItem->setOn(false);            
 
1012
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->album()->extraData(this);
 
1013
            tItem->setOn(false);
992
1014
            d->toggleAutoTags = oldAutoTags;
993
1015
            break;
994
1016
        }
996
1018
        {
997
1019
            d->toggleAutoTags = TagFilterView::NoToggleAuto;
998
1020
            toggleParentTags(item, true);
999
 
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->m_tag->extraData(this);
1000
 
            tItem->setOn(true);            
 
1021
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->album()->extraData(this);
 
1022
            tItem->setOn(true);
1001
1023
            d->toggleAutoTags = oldAutoTags;
1002
1024
            break;
1003
1025
        }
1005
1027
        {
1006
1028
            d->toggleAutoTags = TagFilterView::NoToggleAuto;
1007
1029
            toggleParentTags(item, false);
1008
 
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->m_tag->extraData(this);
1009
 
            tItem->setOn(false);            
 
1030
            TagFilterViewItem *tItem = (TagFilterViewItem*)item->album()->extraData(this);
 
1031
            tItem->setOn(false);
1010
1032
            d->toggleAutoTags = oldAutoTags;
1011
1033
            break;
1012
1034
        }
1093
1115
    if (!item)
1094
1116
        parent = man->findTAlbum(0);
1095
1117
    else
1096
 
        parent = item->m_tag;
 
1118
        parent = item->album();
1097
1119
 
1098
1120
    if (title.isNull())
1099
1121
    {
1100
 
        if (!TagCreateDlg::tagCreate(kapp->activeWindow(), parent, title, icon))
 
1122
        if (!TagEditDlg::tagCreate(kapp->activeWindow(), parent, title, icon))
1101
1123
            return;
1102
1124
    }
1103
1125
 
1104
 
    QString errMsg;
1105
 
    TAlbum* newAlbum = man->createTAlbum(parent, title, icon, errMsg);
 
1126
    QMap<QString, QString> errMap;
 
1127
    AlbumList tList = TagEditDlg::createTAlbum(parent, title, icon, errMap);
 
1128
    TagEditDlg::showtagsListCreationError(kapp->activeWindow(), errMap);
1106
1129
 
1107
 
    if( !newAlbum )
1108
 
    {
1109
 
        KMessageBox::error(0, errMsg);
1110
 
    }
1111
 
    else
1112
 
    {
1113
 
        TagFilterViewItem *item = (TagFilterViewItem*)newAlbum->extraData(this);
1114
 
        if ( item )
 
1130
    for (AlbumList::iterator it = tList.begin(); it != tList.end(); ++it)
 
1131
    {
 
1132
        TagFilterViewItem* item = (TagFilterViewItem*)(*it)->extraData(this);
 
1133
        if (item)
1115
1134
        {
1116
1135
            clearSelection();
1117
1136
            setSelected(item, true);
1118
1137
            setCurrentItem(item);
1119
 
            ensureItemVisible( item );
 
1138
            ensureItemVisible(item);
1120
1139
        }
1121
1140
    }
1122
1141
}
1126
1145
    if (!item)
1127
1146
        return;
1128
1147
 
1129
 
    TAlbum *tag = item->m_tag;
 
1148
    TAlbum *tag = item->album();
1130
1149
    if (!tag)
1131
1150
        return;
1132
1151
 
1144
1163
        if(!man->renameTAlbum(tag, title, errMsg))
1145
1164
            KMessageBox::error(0, errMsg);
1146
1165
        else
1147
 
            item->setText(0, title);
 
1166
            item->refresh();
1148
1167
    }
1149
1168
 
1150
1169
    if (tag->icon() != icon)
1162
1181
    if (!item)
1163
1182
        return;
1164
1183
 
1165
 
    TAlbum *tag = item->m_tag;
 
1184
    TAlbum *tag = item->album();
1166
1185
    if (!tag || tag->isRoot())
1167
1186
        return;
1168
1187
 
1188
1207
                          "Deleting this will also delete "
1189
1208
                          "the subtags. "
1190
1209
                          "Do you want to continue?",
1191
 
                          children).arg(tag->title()),
1192
 
                          i18n("Delete Tag"),
1193
 
                          KGuiItem(i18n("Delete"),"editdelete"));
1194
 
 
1195
 
        if(result == KMessageBox::Continue)
1196
 
        {
1197
 
            QString errMsg;
1198
 
            if (!man->deleteTAlbum(tag, errMsg))
1199
 
                KMessageBox::error(0, errMsg);
1200
 
        }
 
1210
                          children).arg(tag->title()));
 
1211
 
 
1212
        if(result != KMessageBox::Continue)
 
1213
            return;
 
1214
    }
 
1215
 
 
1216
    QString message;
 
1217
    LLongList assignedItems = man->albumDB()->getItemIDsInTag(tag->id());
 
1218
    if (!assignedItems.isEmpty())
 
1219
    {
 
1220
        message = i18n("Tag '%1' is assigned to one item. "
 
1221
                        "Do you want to continue?",
 
1222
                        "Tag '%1' is assigned to %n items. "
 
1223
                        "Do you want to continue?",
 
1224
                        assignedItems.count()).arg(tag->title());
1201
1225
    }
1202
1226
    else
1203
1227
    {
1204
 
        int result = KMessageBox::warningContinueCancel(0, i18n("Delete '%1' tag?")
1205
 
                                                        .arg(tag->title()),i18n("Delete Tag"),
1206
 
                                                        KGuiItem(i18n("Delete"), "editdelete"));
1207
 
 
1208
 
        if (result == KMessageBox::Continue)
1209
 
        {
1210
 
            QString errMsg;
1211
 
            if (!man->deleteTAlbum(tag, errMsg))
1212
 
                KMessageBox::error(0, errMsg);
1213
 
        }
 
1228
        message = i18n("Delete '%1' tag?").arg(tag->title());
 
1229
    }
 
1230
 
 
1231
    int result = KMessageBox::warningContinueCancel(0, message, 
 
1232
                                                    i18n("Delete Tag"),
 
1233
                                                    KGuiItem(i18n("Delete"),
 
1234
                                                    "editdelete"));
 
1235
 
 
1236
    if (result == KMessageBox::Continue)
 
1237
    {
 
1238
        QString errMsg;
 
1239
        if (!man->deleteTAlbum(tag, errMsg))
 
1240
            KMessageBox::error(0, errMsg);
1214
1241
    }
1215
1242
}
1216
1243
 
1219
1246
    if (!tItem)
1220
1247
        return;
1221
1248
 
1222
 
    TAlbum *album = tItem->m_tag; 
 
1249
    TAlbum *album = tItem->album();
1223
1250
    if (!album)
1224
1251
        return;
1225
1252
 
1229
1256
        TAlbum *ta              = (TAlbum*)it.current();
1230
1257
        TagFilterViewItem *item = (TagFilterViewItem*)ta->extraData(this);
1231
1258
        if (item)
 
1259
        {
1232
1260
            if (item->isVisible())
1233
1261
                item->setOn(b);
 
1262
        }
1234
1263
        ++it;
1235
1264
    }
1236
1265
}
1240
1269
    if (!tItem)
1241
1270
        return;
1242
1271
 
1243
 
    TAlbum *album = tItem->m_tag; 
 
1272
    TAlbum *album = tItem->album();
1244
1273
    if (!album)
1245
1274
        return;
1246
1275
 
1250
1279
        TagFilterViewItem* item = dynamic_cast<TagFilterViewItem*>(it.current());
1251
1280
        if (item->isVisible())
1252
1281
        {
1253
 
            Album *a = dynamic_cast<Album*>(item->m_tag);
 
1282
            Album *a = dynamic_cast<Album*>(item->album());
1254
1283
            if (a)
1255
1284
            {
1256
1285
                if (a == album->parent())
1264
1293
    }
1265
1294
}
1266
1295
 
 
1296
void TagFilterView::refresh()
 
1297
{
 
1298
    QListViewItemIterator it(this);
 
1299
 
 
1300
    while (it.current())
 
1301
    {
 
1302
        TagFilterViewItem* item = dynamic_cast<TagFilterViewItem*>(*it);
 
1303
        if (item)
 
1304
            item->refresh();
 
1305
        ++it;
 
1306
    }
 
1307
}
 
1308
 
 
1309
void TagFilterView::slotRefresh(const QMap<int, int>& tagsStatMap)
 
1310
{
 
1311
    QListViewItemIterator it(this);
 
1312
 
 
1313
    while (it.current())
 
1314
    {
 
1315
        TagFilterViewItem* item = dynamic_cast<TagFilterViewItem*>(*it);
 
1316
        if (item)
 
1317
        {
 
1318
            if (item->album())
 
1319
            {
 
1320
                int id = item->id();
 
1321
                QMap<int, int>::const_iterator it2 = tagsStatMap.find(id);
 
1322
                if ( it2 != tagsStatMap.end() )
 
1323
                    item->setCount(it2.data());
 
1324
            }
 
1325
        }
 
1326
        ++it;
 
1327
    }
 
1328
 
 
1329
    refresh();
 
1330
}
 
1331
 
 
1332
void TagFilterView::slotResetTagFilters()
 
1333
{
 
1334
    QListViewItemIterator it(this);
 
1335
 
 
1336
    while (it.current())
 
1337
    {
 
1338
        TagFilterViewItem* item = dynamic_cast<TagFilterViewItem*>(*it);
 
1339
        if (item && item->isOn())
 
1340
            item->setOn(false);
 
1341
        ++it;
 
1342
    }
 
1343
}
 
1344
 
1267
1345
}  // namespace Digikam
1268