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

« back to all changes in this revision

Viewing changes to digikam/digikam/tagfolderview.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
 * Descritpion : tags folder view.
8
8
 * 
9
9
 * Copyright (C) 2005-2006 by Joern Ahrens <joern.ahrens@kdemail.net>
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
43
43
#include "album.h"
44
44
#include "albumdb.h"
45
45
#include "albummanager.h"
 
46
#include "albumsettings.h"
 
47
#include "albumlister.h"
46
48
#include "syncjob.h"
47
 
#include "tagcreatedlg.h"
 
49
#include "tageditdlg.h"
48
50
#include "dragobjects.h"
49
51
#include "folderitem.h"
50
52
#include "dio.h"
66
68
namespace Digikam
67
69
{
68
70
 
69
 
//-----------------------------------------------------------------------------
70
 
// TagFolderViewItem
71
 
//-----------------------------------------------------------------------------
72
 
 
73
71
class TagFolderViewItem : public FolderItem
74
72
{
 
73
 
75
74
public:
76
75
 
77
 
    TagFolderViewItem(QListView *parent, TAlbum *tag);
78
 
    TagFolderViewItem(QListViewItem *parent, TAlbum *tag);
 
76
    TagFolderViewItem(QListView *parent, TAlbum *album);
 
77
    TagFolderViewItem(QListViewItem *parent, TAlbum *album);
79
78
 
80
 
    TAlbum* getTag() const;
81
 
    int id() const;
 
79
    TAlbum* album() const;
 
80
    int     id() const;
 
81
    void    refresh();
 
82
    void    setOpen(bool o);
 
83
    void    setCount(int count);
 
84
    int     count();
82
85
 
83
86
private:
84
87
 
85
 
    TAlbum *m_tag;
 
88
    int     m_count;
 
89
    
 
90
    TAlbum *m_album;
86
91
};
87
92
 
88
 
TagFolderViewItem::TagFolderViewItem(QListView *parent, TAlbum *tag)
89
 
                 : FolderItem(parent, tag->title())
90
 
{
91
 
    setDragEnabled(true);
92
 
    m_tag = tag;
93
 
}
94
 
 
95
 
TagFolderViewItem::TagFolderViewItem(QListViewItem *parent, TAlbum *tag)
96
 
                 : FolderItem(parent, tag->title())
97
 
{
98
 
    setDragEnabled(true);
99
 
    m_tag = tag;
100
 
    /*    setText(0, tag->title() + QString(" (%1)")
101
 
            .arg(AlbumManager::instance()->albumDB()->getItemNamesInAlbum(tag->id()).count()));*/
102
 
}
103
 
 
104
 
TAlbum* TagFolderViewItem::getTag() const
105
 
{
106
 
    return m_tag;
 
93
TagFolderViewItem::TagFolderViewItem(QListView *parent, TAlbum *album)
 
94
                 : FolderItem(parent, album->title())
 
95
{
 
96
    setDragEnabled(true);
 
97
    m_album = album;
 
98
    m_count = 0;
 
99
}
 
100
 
 
101
TagFolderViewItem::TagFolderViewItem(QListViewItem *parent, TAlbum *album)
 
102
                 : FolderItem(parent, album->title())
 
103
{
 
104
    setDragEnabled(true);
 
105
    m_album = album;
 
106
    m_count = 0;
 
107
}
 
108
 
 
109
void TagFolderViewItem::refresh()
 
110
{
 
111
    if (!m_album) return;
 
112
    
 
113
    if (AlbumSettings::instance()->getShowFolderTreeViewItemsCount() &&
 
114
        dynamic_cast<TagFolderViewItem*>(parent()))
 
115
    {
 
116
        if (isOpen())
 
117
            setText(0, QString("%1 (%2)").arg(m_album->title()).arg(m_count));
 
118
        else
 
119
        {
 
120
            int countRecursive = m_count;
 
121
            AlbumIterator it(m_album);
 
122
            while ( it.current() )
 
123
            {
 
124
                TagFolderViewItem *item = (TagFolderViewItem*)it.current()->extraData(listView());
 
125
                if (item)
 
126
                    countRecursive += item->count();
 
127
                ++it;
 
128
            }
 
129
            setText(0, QString("%1 (%2)").arg(m_album->title()).arg(countRecursive));
 
130
        }
 
131
    }
 
132
    else
 
133
    {
 
134
        setText(0, m_album->title());
 
135
    }
 
136
}
 
137
 
 
138
void TagFolderViewItem::setOpen(bool o)
 
139
{
 
140
    QListViewItem::setOpen(o);
 
141
    refresh();
 
142
}
 
143
 
 
144
TAlbum* TagFolderViewItem::album() const
 
145
{
 
146
    return m_album;
107
147
}
108
148
 
109
149
int TagFolderViewItem::id() const
110
150
{
111
 
    return m_tag ? m_tag->id() : 0;
112
 
}
113
 
 
114
 
//-----------------------------------------------------------------------------
115
 
// TagFolderViewPriv
 
151
    return m_album ? m_album->id() : 0;
 
152
}
 
153
 
 
154
void TagFolderViewItem::setCount(int count)
 
155
{
 
156
    m_count = count;
 
157
    refresh();
 
158
}
 
159
 
 
160
int TagFolderViewItem::count()
 
161
{
 
162
    return m_count;
 
163
}
 
164
 
116
165
//-----------------------------------------------------------------------------
117
166
 
118
167
class TagFolderViewPriv
131
180
    AlbumManager *albumMan;
132
181
};
133
182
 
134
 
//-----------------------------------------------------------------------------
135
 
// TagFolderView
136
 
//-----------------------------------------------------------------------------
137
 
 
138
183
TagFolderView::TagFolderView(QWidget *parent)
139
184
             : FolderView(parent, "TagFolderView")
140
185
{
147
192
    setAcceptDrops(true);
148
193
    viewport()->setAcceptDrops(true);
149
194
 
150
 
    // -- setup slots ---------------------------------------------------------
 
195
    // ------------------------------------------------------------------------
151
196
 
 
197
    connect(d->albumMan, SIGNAL(signalTAlbumsDirty(const QMap<int, int>&)),
 
198
            this, SLOT(slotRefresh(const QMap<int, int>&)));
 
199
            
152
200
    connect(d->albumMan, SIGNAL(signalAlbumAdded(Album*)),
153
201
            this, SLOT(slotAlbumAdded(Album*)));
154
202
 
167
215
    connect(d->albumMan, SIGNAL(signalTAlbumMoved(TAlbum*, TAlbum*)),
168
216
            this, SLOT(slotAlbumMoved(TAlbum*, TAlbum*)));
169
217
 
 
218
    // ------------------------------------------------------------------------
 
219
 
170
220
    AlbumThumbnailLoader *loader = AlbumThumbnailLoader::instance();
171
221
 
172
222
    connect(loader, SIGNAL(signalThumbnail(Album *, const QPixmap&)),
190
240
    delete d;
191
241
}
192
242
 
193
 
void TagFolderView::slotTagFilterChanged(const QString& filter)
 
243
void TagFolderView::slotTextTagFilterChanged(const QString& filter)
194
244
{
195
245
    QString search = filter.lower();
196
246
 
255
305
        }
256
306
    }
257
307
 
258
 
    emit signalTagFilterMatch(atleastOneMatch);
 
308
    emit signalTextTagFilterMatch(atleastOneMatch);
259
309
}
260
310
 
261
311
void TagFolderView::slotAlbumAdded(Album *album)
360
410
 
361
411
    TagFolderViewItem* item = (TagFolderViewItem*)(tag->extraData(this));
362
412
    if (item)
363
 
    {
364
 
        item->setText(0, tag->title());
365
 
    }
 
413
        item->refresh();
366
414
}
367
415
 
368
416
void TagFolderView::setTagThumbnail(TAlbum *album)
464
512
        return;
465
513
    }
466
514
 
467
 
    d->albumMan->setCurrentAlbum(tagitem->getTag());
 
515
    d->albumMan->setCurrentAlbum(tagitem->album());
468
516
}
469
517
 
470
518
void TagFolderView::slotContextMenu(QListViewItem *item, const QPoint &, int)
510
558
        case 13:
511
559
        {
512
560
            QString errMsg;
513
 
            d->albumMan->updateTAlbumIcon(tag->getTag(), QString("tag"), 0, errMsg);
 
561
            d->albumMan->updateTAlbumIcon(tag->album(), QString("tag"), 0, errMsg);
514
562
            break;
515
563
        }
516
564
        default:
569
617
    if(!item)
570
618
        parent = d->albumMan->findTAlbum(0);
571
619
    else
572
 
        parent = item->getTag();
 
620
        parent = item->album();
573
621
 
574
622
    if (title.isNull())
575
623
    {
576
 
        if(!TagCreateDlg::tagCreate(kapp->activeWindow(), parent, title, icon))
 
624
        if(!TagEditDlg::tagCreate(kapp->activeWindow(), parent, title, icon))
577
625
            return;
578
626
    }
579
627
 
580
 
    QString errMsg;
581
 
    TAlbum* newAlbum = d->albumMan->createTAlbum(parent, title, icon, errMsg);
 
628
    QMap<QString, QString> errMap;
 
629
    AlbumList tList = TagEditDlg::createTAlbum(parent, title, icon, errMap);
 
630
    TagEditDlg::showtagsListCreationError(kapp->activeWindow(), errMap);
582
631
 
583
 
    if( !newAlbum )
584
 
        KMessageBox::error(0, errMsg);
585
 
    else
 
632
    for (AlbumList::iterator it = tList.begin(); it != tList.end(); ++it)
586
633
    {
587
 
        TagFolderViewItem *item = (TagFolderViewItem*)newAlbum->extraData(this);
588
 
        if ( item )
589
 
            ensureItemVisible( item );
 
634
        TagFolderViewItem* item = (TagFolderViewItem*)(*it)->extraData(this);
 
635
        if (item)
 
636
            ensureItemVisible(item);
590
637
    }
591
638
}
592
639
 
601
648
    if(!item)
602
649
        return;
603
650
 
604
 
    TAlbum *tag = item->getTag();
 
651
    TAlbum *tag = item->album();
605
652
    if(!tag)
606
653
        return;
607
654
 
608
655
    QString title, icon;
609
656
    if(!TagEditDlg::tagEdit(kapp->activeWindow(), tag, title, icon))
610
 
    {
611
657
        return;
612
 
    }
613
658
 
614
659
    if(tag->title() != title)
615
660
    {
617
662
        if(!d->albumMan->renameTAlbum(tag, title, errMsg))
618
663
            KMessageBox::error(0, errMsg);
619
664
        else
620
 
            item->setText(0, title);
 
665
            item->refresh();
621
666
    }
622
667
 
623
668
    if(tag->icon() != icon)
641
686
    if(!item)
642
687
        return;
643
688
 
644
 
    TAlbum *tag = item->getTag();
 
689
    TAlbum *tag = item->album();
645
690
    if (!tag || tag->isRoot())
646
691
        return;
647
692
 
665
710
                            "Deleting this will also delete "
666
711
                            "the subtags. "
667
712
                            "Do you want to continue?",
668
 
                            children).arg(tag->title()),
669
 
                            i18n("Delete Tag"), KGuiItem(i18n("Delete"),
670
 
                            "editdelete"));
671
 
 
672
 
        if(result == KMessageBox::Continue)
673
 
        {
674
 
            QString errMsg;
675
 
            if (!d->albumMan->deleteTAlbum(tag, errMsg))
676
 
                KMessageBox::error(0, errMsg);
677
 
        }
 
713
                            children).arg(tag->title()));
 
714
 
 
715
        if(result != KMessageBox::Continue)
 
716
            return;
 
717
    }
 
718
 
 
719
    QString message;
 
720
    LLongList assignedItems = d->albumMan->albumDB()->getItemIDsInTag(tag->id());
 
721
    if (!assignedItems.isEmpty())
 
722
    {
 
723
        message = i18n("Tag '%1' is assigned to one item. "
 
724
                        "Do you want to continue?",
 
725
                        "Tag '%1' is assigned to %n items. "
 
726
                        "Do you want to continue?",
 
727
                        assignedItems.count()).arg(tag->title());
678
728
    }
679
729
    else
680
730
    {
681
 
        int result =
682
 
            KMessageBox::warningContinueCancel(0, i18n("Delete '%1' tag?")
683
 
                                               .arg(tag->title()), i18n("Delete Tag"),
684
 
                                               KGuiItem(i18n("Delete"), "editdelete"));
685
 
 
686
 
        if(result == KMessageBox::Continue)
687
 
        {
688
 
            QString errMsg;
689
 
            if (!d->albumMan->deleteTAlbum(tag, errMsg))
690
 
                KMessageBox::error(0, errMsg);
691
 
        }
 
731
        message = i18n("Delete '%1' tag?").arg(tag->title());
 
732
    }
 
733
 
 
734
    int result = KMessageBox::warningContinueCancel(0, message, 
 
735
                                                    i18n("Delete Tag"),
 
736
                                                    KGuiItem(i18n("Delete"),
 
737
                                                    "editdelete"));
 
738
 
 
739
    if(result == KMessageBox::Continue)
 
740
    {
 
741
        QString errMsg;
 
742
        if (!d->albumMan->deleteTAlbum(tag, errMsg))
 
743
            KMessageBox::error(0, errMsg);
692
744
    }
693
745
}
694
746
 
701
753
    if(!item->parent())
702
754
        return 0;
703
755
 
704
 
    TagDrag *t = new TagDrag(item->getTag()->id(), this);
 
756
    TagDrag *t = new TagDrag(item->album()->id(), this);
705
757
    t->setPixmap(*item->pixmap(0));
706
758
 
707
759
    return t;
724
776
            return false;
725
777
 
726
778
        // Dragging a parent on its child makes no sense
727
 
        if(itemDrag && itemDrag->getTag()->isAncestorOf(itemDrop->getTag()))
 
779
        if(itemDrag && itemDrag->album()->isAncestorOf(itemDrop->album()))
728
780
            return false;
729
781
 
730
782
        return true;
766
818
        if(!talbum)
767
819
            return;
768
820
        
769
 
        if (talbum == itemDrop->getTag())
 
821
        if (talbum == itemDrop->album())
770
822
            return;
771
823
 
772
824
        KPopupMenu popMenu(this);
789
841
            else
790
842
            {
791
843
                // move dragItem as child of dropItem
792
 
                newParentTag = itemDrop->getTag();
 
844
                newParentTag = itemDrop->album();
793
845
            }
794
846
 
795
847
            QString errMsg;
807
859
 
808
860
    if (ItemDrag::canDecode(e))
809
861
    {
810
 
        TAlbum *destAlbum = itemDrop->getTag();
 
862
        TAlbum *destAlbum = itemDrop->album();
811
863
        TAlbum *srcAlbum;
812
864
 
813
865
        KURL::List      urls;
893
945
            emit signalProgressBarMode(StatusProgressBar::ProgressBarMode, 
894
946
                                       i18n("Assigning image tags. Please wait..."));
895
947
 
 
948
            AlbumLister::instance()->blockSignals(true);
896
949
            d->albumMan->albumDB()->beginTransaction();
897
950
            int i=0;
898
951
            for (QValueList<int>::const_iterator it = imageIDs.begin();
910
963
                emit signalProgressValue((int)((i++/(float)imageIDs.count())*100.0));
911
964
                kapp->processEvents();
912
965
            }
 
966
            AlbumLister::instance()->blockSignals(false);
913
967
            d->albumMan->albumDB()->commitTransaction();
914
968
 
915
969
            ImageAttributesWatch::instance()->imagesChanged(destAlbum->id());
934
988
    }
935
989
}
936
990
 
 
991
void TagFolderView::refresh()
 
992
{
 
993
    QListViewItemIterator it(this);
 
994
    
 
995
    while (it.current())
 
996
    {
 
997
        TagFolderViewItem* item = dynamic_cast<TagFolderViewItem*>(*it);
 
998
        if (item)
 
999
            item->refresh();
 
1000
        ++it;
 
1001
    }
 
1002
}
 
1003
 
 
1004
void TagFolderView::slotRefresh(const QMap<int, int>& tagsStatMap)
 
1005
{
 
1006
    QListViewItemIterator it(this);
 
1007
    
 
1008
    while (it.current())
 
1009
    {
 
1010
        TagFolderViewItem* item = dynamic_cast<TagFolderViewItem*>(*it);
 
1011
        if (item)
 
1012
        {
 
1013
            if (item->album())
 
1014
            {
 
1015
                int id = item->id();
 
1016
                QMap<int, int>::const_iterator it2 = tagsStatMap.find(id);
 
1017
                if ( it2 != tagsStatMap.end() )
 
1018
                    item->setCount(it2.data());
 
1019
            }
 
1020
        }
 
1021
        ++it;
 
1022
    }
 
1023
 
 
1024
    refresh();
 
1025
}
 
1026
 
937
1027
}  // namespace Digikam
938