uploadwidget.cpp

Go to the documentation of this file.
00001 /* ============================================================
00002  * File   : uploadwidget.cpp
00003  * Authors: KIPI team developers (see AUTHORS files for details)
00004  *          
00005  * Date   : 2004-02
00006  * Description :
00007  *
00008  * Copyright 2004 by the KIPI team
00009  *
00010  * This program is free software; you can redistribute it
00011  * and/or modify it under the terms of the GNU Library General
00012  * Public License as published by the Free Software Foundation;
00013  * either version 2, or (at your option)
00014  * any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Library General Public License for more details.
00020  *
00021  * ============================================================ */
00022 
00023 // Qt includes. 
00024   
00025 #include <qlayout.h>
00026 #include <qheader.h>
00027 #include <qlistview.h>
00028 #include <qdir.h>
00029 
00030 // KDE includes
00031 
00032 #include <kdebug.h>
00033 #include <klocale.h>
00034 #include <kio/jobclasses.h>
00035 #include <kmessagebox.h>
00036 
00037 #include <kdeversion.h>
00038 #if KDE_VERSION >= 0x30200
00039 #include <kinputdialog.h>
00040 #else
00041 #include <klineeditdlg.h>
00042 #define KInputDialog KLineEditDlg
00043 #endif
00044 
00045 // Local includes.
00046 
00047 #include "uploadwidget.h"
00048 #include "libkipi/imagecollection.h"
00049 
00050 
00051 struct KIPI::UploadWidget::Private
00052 {
00053     KFileTreeView* m_treeView;
00054     KFileTreeBranch* m_branch;
00055     QStringList m_pendingPath;
00056 };
00057 
00058 
00064 KIPI::UploadWidget::UploadWidget( KIPI::Interface* interface, QWidget* parent, const char* name )
00065                   : QWidget( parent, name )
00066 {
00067     d = new Private;
00068 
00069     QVBoxLayout* layout = new QVBoxLayout( this, 0 );
00070     d->m_treeView = new KFileTreeView( this );
00071     d->m_treeView->setRootIsDecorated( true );
00072     layout->addWidget( d->m_treeView );
00073 
00074     // Fetch the current album, so we can start out there.
00075     KIPI::ImageCollection album = interface->currentAlbum();
00076     
00077     // If no current album selected, get the first album in the list.
00078     if ( !album.isValid() || !album.isDirectory() ) 
00079        album = interface->allAlbums().first();
00080     
00081     d->m_branch = d->m_treeView->addBranch( QDir::cleanDirPath(album.uploadRoot().path()),
00082                                           album.uploadRootName() );
00083     d->m_treeView->setDirOnlyMode( d->m_branch, true );
00084 
00085     d->m_treeView->addColumn( i18n("Folder" ) );
00086 
00087     d->m_treeView->header()->setStretchEnabled( true, 0 );
00088     d->m_treeView->header()->hide();
00089 
00090     QString root = album.uploadRoot().path();
00091     QString uploadPath = album.isDirectory() ? album.uploadPath().path() : root;
00092 
00093     root       = QDir::cleanDirPath(root);
00094     uploadPath = QDir::cleanDirPath(uploadPath);
00095     
00096     if ( !uploadPath.startsWith( root ) ) 
00097     {
00098         kdWarning(51000) << "Error in Host application: uploadPath() should start with uploadRoot()." << endl
00099                          << "uploadPath() = " << album.uploadPath().prettyURL() << endl
00100                          << "uploadRoot() = " << album.uploadRoot().prettyURL() << endl;
00101     }
00102     else
00103     {
00104         uploadPath = uploadPath.mid( root.length() );
00105         
00106         d->m_pendingPath = QStringList::split( "/", uploadPath, false );
00107         
00108         connect( d->m_branch, SIGNAL( populateFinished(KFileTreeViewItem *) ),
00109                  this, SLOT( slotPopulateFinished(KFileTreeViewItem *) ) );
00110 
00111         d->m_branch->setOpen(true);
00112     }
00113     
00114     connect( d->m_treeView, SIGNAL( executed(QListViewItem *) ),
00115              this, SLOT( slotFolderSelected(QListViewItem *) ) );
00116 }
00117 
00118 KIPI::UploadWidget::~UploadWidget()
00119 {
00120     delete d;
00121 }
00122 
00123 KURL KIPI::UploadWidget::path() const
00124 {
00125     return d->m_treeView->currentURL();
00126 }
00127 
00128 void KIPI::UploadWidget::load( )
00129 {
00130     kdWarning() << "KIPI::UploadWidget::load(): This method is obsolete\n";
00131 }
00132 
00133 void KIPI::UploadWidget::slotPopulateFinished( KFileTreeViewItem * parentItem )
00134 {
00135     if ( d->m_pendingPath.isEmpty() ) 
00136     {
00137         disconnect( d->m_branch, SIGNAL( populateFinished(KFileTreeViewItem *) ), 
00138                     this, SLOT( slotPopulateFinished(KFileTreeViewItem *) ) );
00139         return;
00140     }
00141 
00142     QString itemName = d->m_pendingPath.front();
00143 
00144     d->m_pendingPath.pop_front();
00145 
00146     QListViewItem * item;
00147     for ( item = parentItem->firstChild(); item; item = item->nextSibling() )
00148     {
00149         if ( item->text(0) == itemName )
00150         {
00151             break;
00152         }
00153     }
00154     
00155     if ( !item ) 
00156     {
00157         kdDebug( 51000 ) << "Unable to open " << itemName << endl;
00158     }
00159     else
00160     {
00161         item->setOpen( true );
00162         d->m_treeView->setSelected( item, true );
00163         d->m_treeView->ensureItemVisible ( item );
00164         
00165         KFileTreeViewItem * ftvItem = static_cast<KFileTreeViewItem *>( item );
00166         if ( ftvItem->alreadyListed() )
00167             slotPopulateFinished( ftvItem );
00168     }
00169 
00170 }
00171 
00172 void KIPI::UploadWidget::mkdir()
00173 {
00174     if ( !path().isValid() ) 
00175         {
00176         KMessageBox::error( this, i18n("Please select a directory first.") );
00177         return;
00178         }
00179 
00180     bool ok;
00181     QString dir = KInputDialog::getText( i18n("Create Directory"),
00182                                          i18n("<qt>Enter new directory name (to be created as subdir of %1):</qt>")
00183                                         .arg(path().prettyURL()), "", &ok, this);
00184     
00185     if (!ok) return;
00186 
00187     KURL url = path();
00188     url.addPath( dir );
00189 
00190     KIO::SimpleJob* job = KIO::mkdir(url);
00191     
00192     connect(job, SIGNAL(result(KIO::Job*)), 
00193             this, SLOT(slotAlbumCreated(KIO::Job*)));
00194 }
00195 
00196 void KIPI::UploadWidget::slotAlbumCreated(KIO::Job* job)
00197 {
00198     int code = job->error();
00199     
00200     if ( code )
00201         job->showErrorDialog( this );
00202 }
00203 
00204 void KIPI::UploadWidget::slotFolderSelected(QListViewItem *)
00205 {
00206     emit folderItemSelected(d->m_treeView->currentURL());
00207 }
00208 
00209 #include "uploadwidget.moc"

Generated on Tue Sep 25 22:34:22 2007 for libKipi by  doxygen 1.5.3