~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to core/utilities/cameragui/views/camerafolderview.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-09-27 21:41:30 UTC
  • mfrom: (1.2.43)
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: package-import@ubuntu.com-20120927214130-i8v3ufr21nesp29i
Tags: 4:3.0.0~beta1a-1
* New upstream release

* Fix "wrongly conflicts phonon-backend-vlc" dropped (Closes: #688142)
* debian/watch include download.kde.org

* digikam 3.0.0 uses features from unreleased kdegraphics >=4.10 & ships 
a private version of the kdegraphics libs - this is not the Debian way :-(
* Unsatisfactory Conflicts: libkipi8, libkexiv2-10, libkdcraw20, libksane0
* Suspend digikam-dbg >130Mb

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        : 2003-01-23
7
 
 * Description : A widget to display a list of camera folders.
8
 
 *
9
 
 * Copyright (C) 2003-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
10
 
 * Copyright (C) 2006-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
 
 *
12
 
 * This program is free software; you can redistribute it
13
 
 * and/or modify it under the terms of the GNU General
14
 
 * Public License as published by the Free Software Foundation;
15
 
 * either version 2, or (at your option)
16
 
 * any later version.
17
 
 *
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * ============================================================ */
24
 
 
25
 
#include "camerafolderview.moc"
26
 
 
27
 
// KDE includes
28
 
 
29
 
#include <kiconloader.h>
30
 
#include <klocale.h>
31
 
#include <kdebug.h>
32
 
 
33
 
// Local includes
34
 
 
35
 
#include "camerafolderitem.h"
36
 
 
37
 
namespace Digikam
38
 
{
39
 
 
40
 
class CameraFolderView::CameraFolderViewPriv
41
 
{
42
 
public:
43
 
 
44
 
    CameraFolderViewPriv() :
45
 
        cameraName("Camera"),
46
 
        virtualFolder(0),
47
 
        rootFolder(0)
48
 
    {
49
 
    }
50
 
 
51
 
    QString           cameraName;
52
 
 
53
 
    CameraFolderItem* virtualFolder;
54
 
    CameraFolderItem* rootFolder;
55
 
};
56
 
 
57
 
CameraFolderView::CameraFolderView(QWidget* parent)
58
 
    : QTreeWidget(parent), d(new CameraFolderViewPriv)
59
 
{
60
 
    setColumnCount(1);
61
 
    setRootIsDecorated(false);
62
 
    setSelectionMode(QAbstractItemView::SingleSelection);
63
 
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
64
 
    setAllColumnsShowFocus(true);
65
 
    setDragEnabled(false);
66
 
    setDropIndicatorShown(false);
67
 
    setAcceptDrops(false);
68
 
    setHeaderLabels(QStringList() << i18n("Camera Folders"));
69
 
 
70
 
    connect(this, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
71
 
            this, SLOT(slotCurrentChanged(QTreeWidgetItem*,int)));
72
 
 
73
 
    connect(this, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
74
 
            this, SLOT(slotCurrentChanged(QTreeWidgetItem*,int)));
75
 
}
76
 
 
77
 
CameraFolderView::~CameraFolderView()
78
 
{
79
 
    delete d;
80
 
}
81
 
 
82
 
void CameraFolderView::addVirtualFolder(const QString& name, const QPixmap& pixmap)
83
 
{
84
 
    d->cameraName    = name;
85
 
    d->virtualFolder = new CameraFolderItem(this, d->cameraName, pixmap);
86
 
    d->virtualFolder->setExpanded(true);
87
 
    d->virtualFolder->setSelected(false);
88
 
    // item is not selectable.
89
 
    d->virtualFolder->setFlags(d->virtualFolder->flags() & (int)!Qt::ItemIsSelectable);
90
 
    d->virtualFolder->setDisabled(false);
91
 
}
92
 
 
93
 
void CameraFolderView::addRootFolder(const QString& folder, int nbItems, const QPixmap& pixmap)
94
 
{
95
 
    d->rootFolder = new CameraFolderItem(d->virtualFolder, folder, folder, pixmap);
96
 
    d->rootFolder->setExpanded(true);
97
 
 
98
 
    if (nbItems != -1)
99
 
    {
100
 
        d->rootFolder->setCount(nbItems);
101
 
    }
102
 
}
103
 
 
104
 
CameraFolderItem* CameraFolderView::addFolder(const QString& folder, const QString& subFolder,
105
 
                                              int nbItems, const QPixmap& pixmap)
106
 
{
107
 
    CameraFolderItem* parentItem = findFolder(folder);
108
 
 
109
 
    kDebug() << "Adding Subfolder " << subFolder
110
 
             << " of folder " << folder;
111
 
 
112
 
    if (parentItem)
113
 
    {
114
 
        QString path(folder);
115
 
 
116
 
        if (!folder.endsWith('/'))
117
 
        {
118
 
            path += '/';
119
 
        }
120
 
 
121
 
        path += subFolder;
122
 
        CameraFolderItem* item = new CameraFolderItem(parentItem, subFolder, path, pixmap);
123
 
 
124
 
        kDebug() << "Added ViewItem with path "
125
 
                 << item->folderPath();
126
 
 
127
 
        item->setCount(nbItems);
128
 
        item->setExpanded(true);
129
 
        return item;
130
 
    }
131
 
    else
132
 
    {
133
 
        kWarning() << "Could not find parent for subFolder "
134
 
                   << subFolder << " of folder " << folder;
135
 
        return 0;
136
 
    }
137
 
}
138
 
 
139
 
CameraFolderItem* CameraFolderView::findFolder(const QString& folderPath)
140
 
{
141
 
    QTreeWidgetItemIterator it(this);
142
 
 
143
 
    while (*it)
144
 
    {
145
 
        CameraFolderItem* lvItem = dynamic_cast<CameraFolderItem*>(*it);
146
 
 
147
 
        if (lvItem && lvItem->folderPath() == folderPath)
148
 
        {
149
 
            return lvItem;
150
 
        }
151
 
 
152
 
        ++it;
153
 
    }
154
 
 
155
 
    return 0;
156
 
}
157
 
 
158
 
void CameraFolderView::slotCurrentChanged(QTreeWidgetItem* item, int)
159
 
{
160
 
    if (!item)
161
 
    {
162
 
        emit signalFolderChanged(0);
163
 
    }
164
 
    else
165
 
    {
166
 
        emit signalFolderChanged(dynamic_cast<CameraFolderItem*>(item));
167
 
    }
168
 
}
169
 
 
170
 
CameraFolderItem* CameraFolderView::virtualFolder() const
171
 
{
172
 
    return d->virtualFolder;
173
 
}
174
 
 
175
 
CameraFolderItem* CameraFolderView::rootFolder() const
176
 
{
177
 
    return d->rootFolder;
178
 
}
179
 
 
180
 
void CameraFolderView::clear()
181
 
{
182
 
    QTreeWidget::clear();
183
 
    d->virtualFolder = 0;
184
 
    d->rootFolder    = 0;
185
 
    emit signalCleared();
186
 
}
187
 
 
188
 
} // namespace Digikam