1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : a dialog to select a camera folders.
9
* Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
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)
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.
22
* ============================================================ */
33
#include <kiconloader.h>
34
#include <kapplication.h>
39
#include "cameraiconview.h"
40
#include "camerafolderitem.h"
41
#include "camerafolderview.h"
42
#include "camerafolderdialog.h"
43
#include "camerafolderdialog.moc"
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)
55
setHelp("camerainterface.anchor", "digikam");
56
enableButtonOK(false);
58
m_rootPath = rootPath;
60
QFrame *page = makeMainWidget();
61
QGridLayout* grid = new QGridLayout(page, 2, 1, 0, spacingHint());
63
m_folderView = new CameraFolderView(page);
64
QLabel *logo = new QLabel(page);
65
QLabel *message = new QLabel(page);
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>"));
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);
77
m_folderView->addVirtualFolder(cameraName);
78
m_folderView->addRootFolder("/", cameraView->countItemsByFolder(rootPath));
80
for (QStringList::const_iterator it = cameraFolderList.begin();
81
it != cameraFolderList.end(); ++it)
84
if (folder.startsWith(rootPath) && rootPath != QString("/"))
85
folder.remove(0, rootPath.length());
87
if (folder != QString("/") && !folder.isEmpty())
89
QString root = folder.section( '/', 0, -2 );
90
if (root.isEmpty()) root = QString("/");
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;
98
connect(m_folderView, SIGNAL(signalFolderChanged(CameraFolderItem*)),
99
this, SLOT(slotFolderPathSelectionChanged(CameraFolderItem*)));
104
CameraFolderDialog::~CameraFolderDialog()
108
QString CameraFolderDialog::selectedFolderPath()
110
QListViewItem *item = m_folderView->currentItem();
111
if (!item) return QString();
113
CameraFolderItem *folderItem = static_cast<CameraFolderItem *>(item);
114
if (folderItem->isVirtualFolder())
115
return QString(m_rootPath);
117
// Case of Gphoto2 cameras. No need to duplicate root '/'.
118
if (m_rootPath == QString("/"))
119
return(folderItem->folderPath());
121
return(m_rootPath + folderItem->folderPath());
124
void CameraFolderDialog::slotFolderPathSelectionChanged(CameraFolderItem* item)
128
enableButtonOK(true);
129
DDebug() << "Camera folder path: " << selectedFolderPath() << endl;
133
enableButtonOK(false);
137
} // namespace Digikam