libKipi
uploadwidget.cpp
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of kipi-plugins project
4 * http://www.kipi-plugins.org
5 *
6 * Date : 2004-02-01
7 * Description : a widget to upload item.
8 *
9 * Copyright (C) 2004-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * Copyright (C) 2004-2005 by Renchi Raju <renchi.raju at kdemail.net>
11 * Copyright (C) 2004-2005 by Jesper K. Pedersen <blackie at kde.org>
12 * Copyright (C) 2004-2005 by Aurelien Gateau <aurelien dot gateau at free.fr>
13 *
14 * This program is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General
16 * Public License as published by the Free Software Foundation;
17 * either version 2, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * ============================================================ */
25
26// Qt includes.
27
28#include <qlayout.h>
29#include <qheader.h>
30#include <qlistview.h>
31#include <qdir.h>
32
33// KDE includes
34
35#include <kdebug.h>
36#include <klocale.h>
37#include <kio/jobclasses.h>
38#include <kmessagebox.h>
39
40#include <kdeversion.h>
41#if KDE_VERSION >= 0x30200
42#include <kinputdialog.h>
43#else
44#include <klineeditdlg.h>
45#define KInputDialog KLineEditDlg
46#endif
47
48// Local includes.
49
51#include "uploadwidget.h"
52#include "uploadwidget.moc"
53
55{
56 KFileTreeView* m_treeView;
57 KFileTreeBranch* m_branch;
58 QStringList m_pendingPath;
59};
60
65KIPI::UploadWidget::UploadWidget( KIPI::Interface* interface, QWidget* parent, const char* name )
66 : QWidget( parent, name )
67{
68 d = new Private;
69
70 QVBoxLayout* layout = new QVBoxLayout( this, 0 );
71 d->m_treeView = new KFileTreeView( this );
72 d->m_treeView->setRootIsDecorated( true );
73 layout->addWidget( d->m_treeView );
74
75 // Fetch the current album, so we can start out there.
76 KIPI::ImageCollection album = interface->currentAlbum();
77
78 // If no current album selected, get the first album in the list.
79 if ( !album.isValid() || !album.isDirectory() )
80 album = interface->allAlbums().first();
81
82 d->m_branch = d->m_treeView->addBranch( QDir::cleanDirPath(album.uploadRoot().path()),
83 album.uploadRootName() );
84 d->m_treeView->setDirOnlyMode( d->m_branch, true );
85
86 d->m_treeView->addColumn( i18n("Folder" ) );
87
88 d->m_treeView->header()->setStretchEnabled( true, 0 );
89 d->m_treeView->header()->hide();
90
91 QString root = album.uploadRoot().path();
92 QString uploadPath = album.isDirectory() ? album.uploadPath().path() : root;
93
94 root = QDir::cleanDirPath(root);
95 uploadPath = QDir::cleanDirPath(uploadPath);
96
97 if ( !uploadPath.startsWith( root ) )
98 {
99 kdWarning(51000) << "Error in Host application: uploadPath() should start with uploadRoot()." << endl
100 << "uploadPath() = " << album.uploadPath().prettyURL() << endl
101 << "uploadRoot() = " << album.uploadRoot().prettyURL() << endl;
102 }
103 else
104 {
105 uploadPath = uploadPath.mid( root.length() );
106
107 d->m_pendingPath = QStringList::split( "/", uploadPath, false );
108
109 connect( d->m_branch, SIGNAL( populateFinished(KFileTreeViewItem *) ),
110 this, SLOT( slotPopulateFinished(KFileTreeViewItem *) ) );
111
112 d->m_branch->setOpen(true);
113 }
114
115 connect( d->m_treeView, SIGNAL( executed(QListViewItem *) ),
116 this, SLOT( slotFolderSelected(QListViewItem *) ) );
117}
118
120{
121 delete d;
122}
123
125{
126 return d->m_treeView->currentURL();
127}
128
130{
131 kdWarning() << "KIPI::UploadWidget::load(): This method is obsolete\n";
132}
133
134void KIPI::UploadWidget::slotPopulateFinished( KFileTreeViewItem * parentItem )
135{
136 if ( d->m_pendingPath.isEmpty() )
137 {
138 disconnect( d->m_branch, SIGNAL( populateFinished(KFileTreeViewItem *) ),
139 this, SLOT( slotPopulateFinished(KFileTreeViewItem *) ) );
140 return;
141 }
142
143 QString itemName = d->m_pendingPath.front();
144
145 d->m_pendingPath.pop_front();
146
147 QListViewItem * item;
148 for ( item = parentItem->firstChild(); item; item = item->nextSibling() )
149 {
150 if ( item->text(0) == itemName )
151 {
152 break;
153 }
154 }
155
156 if ( !item )
157 {
158 kdDebug( 51000 ) << "Unable to open " << itemName << endl;
159 }
160 else
161 {
162 item->setOpen( true );
163 d->m_treeView->setSelected( item, true );
164 d->m_treeView->ensureItemVisible ( item );
165
166 KFileTreeViewItem * ftvItem = static_cast<KFileTreeViewItem *>( item );
167 if ( ftvItem->alreadyListed() )
168 slotPopulateFinished( ftvItem );
169 }
170}
171
173{
174 if ( !path().isValid() )
175 {
176 KMessageBox::error( this, i18n("Please select a directory first.") );
177 return;
178 }
179
180 bool ok;
181 QString dir = KInputDialog::getText( i18n("Create Directory"),
182 i18n("<qt>Enter new directory name (to be created as subdir of %1):</qt>")
183 .arg(path().prettyURL()), "", &ok, this);
184
185 if (!ok) return;
186
187 KURL url = path();
188 url.addPath( dir );
189
190 KIO::SimpleJob* job = KIO::mkdir(url);
191
192 connect(job, SIGNAL(result(KIO::Job*)),
193 this, SLOT(slotAlbumCreated(KIO::Job*)));
194}
195
197{
198 int code = job->error();
199
200 if ( code )
201 job->showErrorDialog( this );
202}
203
205{
206 emit folderItemSelected(d->m_treeView->currentURL());
207}
KDStream & endl(KDStream &stream)
Definition KDStream.cpp:264
Definition imagecollection.h:53
bool isDirectory() const
Definition imagecollection.cpp:234
bool isValid() const
Definition imagecollection.cpp:244
QString uploadRootName() const
Definition imagecollection.cpp:219
KURL uploadRoot() const
Definition imagecollection.cpp:204
KURL uploadPath() const
Definition imagecollection.cpp:179
Definition interface.h:64
virtual ImageCollection currentAlbum()=0
Definition interface.cpp:184
virtual QValueList< ImageCollection > allAlbums()=0
Definition interface.cpp:204
void mkdir()
Definition uploadwidget.cpp:172
UploadWidget(KIPI::Interface *interface, QWidget *parent, const char *name=0)
Definition uploadwidget.cpp:65
void load()
Definition uploadwidget.cpp:129
void folderItemSelected(const KURL &url)
void slotFolderSelected(QListViewItem *)
Definition uploadwidget.cpp:204
void slotAlbumCreated(KIO::Job *job)
Definition uploadwidget.cpp:196
KURL path() const
Definition uploadwidget.cpp:124
~UploadWidget()
Definition uploadwidget.cpp:119
Definition uploadwidget.cpp:55
KFileTreeBranch * m_branch
Definition uploadwidget.cpp:57
KFileTreeView * m_treeView
Definition uploadwidget.cpp:56
QStringList m_pendingPath
Definition uploadwidget.cpp:58