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

« back to all changes in this revision

Viewing changes to digikam/utilities/cameragui/camerafolderdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.3.2 upstream) (37 hardy)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20080717202539-1bw3w3nrsso7yj4z
* 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:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2006-07-24
 
7
 * Description : a dialog to select a camera folders.
 
8
 * 
 
9
 * Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
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)
 
15
 * any later version.
 
16
 * 
 
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.
 
21
 * 
 
22
 * ============================================================ */
 
23
 
 
24
// Qt includes.
 
25
 
 
26
#include <qlabel.h>
 
27
#include <qlayout.h>
 
28
#include <qframe.h>
 
29
 
 
30
// KDE includes.
 
31
 
 
32
#include <klocale.h>
 
33
#include <kiconloader.h>
 
34
#include <kapplication.h>
 
35
 
 
36
// Local includes.
 
37
 
 
38
#include "ddebug.h"
 
39
#include "cameraiconview.h"
 
40
#include "camerafolderitem.h"
 
41
#include "camerafolderview.h"
 
42
#include "camerafolderdialog.h"
 
43
#include "camerafolderdialog.moc"
 
44
 
 
45
namespace Digikam
 
46
{
 
47
 
 
48
CameraFolderDialog::CameraFolderDialog(QWidget *parent, CameraIconView *cameraView, 
 
49
                                       const QStringList& cameraFolderList,
 
50
                                       const QString& cameraName, const QString& rootPath)
 
51
                  : KDialogBase(parent, 0, true,
 
52
                                i18n("%1 - Select Camera Folder").arg(cameraName), 
 
53
                                Help|Ok|Cancel, Ok, true)
 
54
{
 
55
    setHelp("camerainterface.anchor", "digikam");
 
56
    enableButtonOK(false);
 
57
 
 
58
    m_rootPath = rootPath;
 
59
 
 
60
    QFrame *page      = makeMainWidget();
 
61
    QGridLayout* grid = new QGridLayout(page, 2, 1, 0, spacingHint());
 
62
    
 
63
    m_folderView    = new CameraFolderView(page);
 
64
    QLabel *logo    = new QLabel(page);
 
65
    QLabel *message = new QLabel(page);
 
66
 
 
67
    KIconLoader* iconLoader = KApplication::kApplication()->iconLoader();
 
68
    logo->setPixmap(iconLoader->loadIcon("digikam", KIcon::NoGroup, 128, KIcon::DefaultState, 0, true));    
 
69
    message->setText(i18n("<p>Please select the camera folder "
 
70
                          "where you want to upload the images.</p>"));
 
71
 
 
72
    grid->addMultiCellWidget(logo, 0, 0, 0, 0);
 
73
    grid->addMultiCellWidget(message, 1, 1, 0, 0);
 
74
    grid->addMultiCellWidget(m_folderView, 0, 2, 1, 1);
 
75
    grid->setRowStretch(2, 10);
 
76
 
 
77
    m_folderView->addVirtualFolder(cameraName);
 
78
    m_folderView->addRootFolder("/", cameraView->countItemsByFolder(rootPath));
 
79
 
 
80
    for (QStringList::const_iterator it = cameraFolderList.begin();
 
81
         it != cameraFolderList.end(); ++it)
 
82
    {
 
83
        QString folder(*it);
 
84
        if (folder.startsWith(rootPath) && rootPath != QString("/"))
 
85
            folder.remove(0, rootPath.length());
 
86
 
 
87
        if (folder != QString("/") && !folder.isEmpty())
 
88
        {
 
89
            QString root = folder.section( '/', 0, -2 );
 
90
            if (root.isEmpty()) root = QString("/");
 
91
 
 
92
            QString sub = folder.section( '/', -1 );
 
93
            m_folderView->addFolder(root, sub, cameraView->countItemsByFolder(*it));
 
94
            DDebug() << "Camera folder: '" << folder << "' (root='" << root << "', sub='" <<sub <<"')" << endl;
 
95
        }
 
96
    }
 
97
 
 
98
    connect(m_folderView, SIGNAL(signalFolderChanged(CameraFolderItem*)),
 
99
            this, SLOT(slotFolderPathSelectionChanged(CameraFolderItem*)));
 
100
 
 
101
    resize(500, 500);
 
102
}
 
103
 
 
104
CameraFolderDialog::~CameraFolderDialog()
 
105
{
 
106
}
 
107
 
 
108
QString CameraFolderDialog::selectedFolderPath()
 
109
{
 
110
    QListViewItem *item = m_folderView->currentItem();
 
111
    if (!item) return QString();
 
112
 
 
113
    CameraFolderItem *folderItem = static_cast<CameraFolderItem *>(item);
 
114
    if (folderItem->isVirtualFolder())
 
115
        return QString(m_rootPath);
 
116
 
 
117
    // Case of Gphoto2 cameras. No need to duplicate root '/'.
 
118
    if (m_rootPath == QString("/"))
 
119
        return(folderItem->folderPath());
 
120
 
 
121
    return(m_rootPath + folderItem->folderPath());
 
122
}
 
123
 
 
124
void CameraFolderDialog::slotFolderPathSelectionChanged(CameraFolderItem* item)
 
125
{
 
126
    if (item) 
 
127
    {
 
128
        enableButtonOK(true);
 
129
        DDebug() << "Camera folder path: " << selectedFolderPath() << endl;
 
130
    }
 
131
    else
 
132
    {
 
133
        enableButtonOK(false);
 
134
    }
 
135
}
 
136
 
 
137
}  // namespace Digikam
 
138