summaryrefslogtreecommitdiffstats
path: root/digikam/utilities/cameragui/camerafolderview.cpp
blob: bfa95e8bb8256a37b2551a045e33b4ef7b652041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2003-01-23
 * Description : A widget to display a list of camera folders.
 * 
 * Copyright (C) 2003-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
 * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published bythe Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * ============================================================ */

// KDE includes.

#include <tdelocale.h>
#include <kiconloader.h>

// Local includes.

#include "ddebug.h"
#include "camerafolderitem.h"
#include "camerafolderview.h"
#include "camerafolderview.moc"

namespace Digikam
{

class CameraFolderViewPriv
{
public:

    CameraFolderViewPriv()
    {
        virtualFolder = 0;
        rootFolder    = 0;
        cameraName    = TQString("Camera");
    }

    TQString           cameraName;

    CameraFolderItem *virtualFolder;
    CameraFolderItem *rootFolder;
};

CameraFolderView::CameraFolderView(TQWidget* parent)
                : TQListView(parent)
{
    d = new CameraFolderViewPriv;

    addColumn(i18n("Camera Folders"));
    setColumnWidthMode( 0, TQListView::Maximum );
    setResizeMode( TQListView::AllColumns );
    setSelectionMode(TQListView::Single);

    connect(this, TQT_SIGNAL(currentChanged(TQListViewItem*)),
            this, TQT_SLOT(slotCurrentChanged(TQListViewItem*)));

    connect(this, TQT_SIGNAL(clicked(TQListViewItem*)),
            this, TQT_SLOT(slotCurrentChanged(TQListViewItem*)));
}

CameraFolderView::~CameraFolderView()
{
    delete d;
}

void CameraFolderView::addVirtualFolder(const TQString& name, const TQPixmap& pixmap)
{
    d->cameraName    = name;
    d->virtualFolder = new CameraFolderItem(this, d->cameraName, pixmap);
    d->virtualFolder->setOpen(true);
    d->virtualFolder->setSelected(false);
    d->virtualFolder->setSelectable(false);
}

void CameraFolderView::addRootFolder(const TQString& folder, int nbItems, const TQPixmap& pixmap)
{
    d->rootFolder = new CameraFolderItem(d->virtualFolder, folder, folder, pixmap);
    d->rootFolder->setOpen(true);
    d->rootFolder->setCount(nbItems);
}

CameraFolderItem* CameraFolderView::addFolder(const TQString& folder, const TQString& subFolder,
                                              int nbItems, const TQPixmap& pixmap)
{
    CameraFolderItem *parentItem = findFolder(folder);

    DDebug() << "CameraFolderView: Adding Subfolder " << subFolder
             << " of folder " << folder << endl;

    if (parentItem) 
    {
        TQString path(folder);

        if (!folder.endsWith("/"))
            path += '/';

        path += subFolder;
        CameraFolderItem* item = new CameraFolderItem(parentItem, subFolder, path, pixmap);

        DDebug() << "CameraFolderView: Added ViewItem with path "
                 << item->folderPath() << endl;

        item->setCount(nbItems);
        item->setOpen(true);
        return item;
    }
    else 
    {
        DWarning() << "CameraFolderView: Couldn't find parent for subFolder "
                   << subFolder << " of folder " << folder << endl;
        return 0;
    }
}

CameraFolderItem* CameraFolderView::findFolder(const TQString& folderPath)
{

    TQListViewItemIterator it(this);
    for ( ; it.current(); ++it) 
    {
        CameraFolderItem* item = static_cast<CameraFolderItem*>(it.current());

        if (item->folderPath() == folderPath)
            return item;
    }

    return 0;
}

void CameraFolderView::slotCurrentChanged(TQListViewItem* item)
{
    if (!item) 
        emit signalFolderChanged(0);
    else
        emit signalFolderChanged(static_cast<CameraFolderItem *>(item));
}

CameraFolderItem* CameraFolderView::virtualFolder()
{
    return d->virtualFolder;
}

CameraFolderItem* CameraFolderView::rootFolder()
{
    return d->rootFolder;
}

void CameraFolderView::clear()
{
    TQListView::clear();
    d->virtualFolder = 0;
    d->rootFolder    = 0;
    emit signalCleared();
}

} // namespace Digikam