• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libkonq

konq_operations.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright 2000-2007  David Faure <faure@kde.org>
00003     Copyright 2003       Waldo Bastian <bastian@kde.org>
00004     Copyright 2002       Michael Brade <brade@kde.org>
00005     Copyright 2001-2002  Alexander Neundorf <neundorf@kde.org>
00006     Copyright 2000-2001  Simon Hausmann <hausmann@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) version 3.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 */
00022 
00023 #include "konq_operations.h"
00024 #include "konqmimedata.h"
00025 
00026 #include <ktoolinvocation.h>
00027 #include <kautomount.h>
00028 #include <kmountpoint.h>
00029 #include <kinputdialog.h>
00030 #include <klocale.h>
00031 #include <kmessagebox.h>
00032 #include <knotification.h>
00033 #include <krun.h>
00034 #include <kshell.h>
00035 #include <kprocess.h>
00036 #include <kshortcut.h>
00037 #include <kprotocolmanager.h>
00038 #include <kio/deletejob.h>
00039 #include <kio/fileundomanager.h>
00040 #include <kio/job.h>
00041 #include <kio/jobuidelegate.h>
00042 #include <kio/jobclasses.h>
00043 #include <kio/copyjob.h>
00044 #include <kio/paste.h>
00045 #include <kio/renamedialog.h>
00046 #include <kdirnotify.h>
00047 #include <kuiserverjobtracker.h>
00048 // For doDrop
00049 #include <kauthorized.h>
00050 #include <kglobal.h>
00051 #include <kglobalsettings.h>
00052 #include <kdebug.h>
00053 #include <kfileitem.h>
00054 #include <kdesktopfile.h>
00055 
00056 //#include <konq_iconviewwidget.h>
00057 #include <QtDBus/QtDBus>
00058 #include <QMenu>
00059 #include <QApplication>
00060 #include <QClipboard>
00061 #include <QDropEvent>
00062 #include <QList>
00063 #include <QDir>
00064 
00065 #include <assert.h>
00066 #include <unistd.h>
00067 #include <kconfiggroup.h>
00068 
00069 KonqOperations::KonqOperations( QWidget *parent )
00070     : QObject( parent ),
00071       m_method( UNKNOWN ), m_info(0), m_pasteInfo(0)
00072 {
00073     setObjectName( "KonqOperations" );
00074 }
00075 
00076 KonqOperations::~KonqOperations()
00077 {
00078     delete m_info;
00079     delete m_pasteInfo;
00080 }
00081 
00082 void KonqOperations::editMimeType( const QString & mimeType, QWidget* parent )
00083 {
00084     QString keditfiletype = QLatin1String("keditfiletype");
00085     KRun::runCommand( keditfiletype
00086                       + " --parent " + QString::number( (long)parent->winId())
00087                       + ' ' + KShell::quoteArg(mimeType),
00088                       keditfiletype, keditfiletype /*unused*/, parent );
00089 }
00090 
00091 void KonqOperations::del( QWidget * parent, Operation method, const KUrl::List & selectedUrls )
00092 {
00093     kDebug(1203) << "KonqOperations::del " << parent->metaObject()->className();
00094     if ( selectedUrls.isEmpty() )
00095     {
00096         kWarning(1203) << "Empty URL list !" ;
00097         return;
00098     }
00099 
00100     KonqOperations * op = new KonqOperations( parent );
00101     ConfirmationType confirmation = DEFAULT_CONFIRMATION;
00102     op->_del( method, selectedUrls, confirmation );
00103 }
00104 
00105 void KonqOperations::emptyTrash( QWidget* parent )
00106 {
00107     KonqOperations *op = new KonqOperations( parent );
00108     op->_del( EMPTYTRASH, KUrl("trash:/"), SKIP_CONFIRMATION );
00109 }
00110 
00111 void KonqOperations::restoreTrashedItems( const KUrl::List& urls, QWidget* parent )
00112 {
00113     KonqOperations *op = new KonqOperations( parent );
00114     op->_restoreTrashedItems( urls );
00115 }
00116 
00117 KIO::SimpleJob* KonqOperations::mkdir( QWidget *parent, const KUrl & url )
00118 {
00119     KIO::SimpleJob * job = KIO::mkdir(url);
00120     job->ui()->setWindow(parent);
00121     job->ui()->setAutoErrorHandlingEnabled(true);
00122     KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Mkdir, KUrl(), url, job );
00123     return job;
00124 }
00125 
00126 void KonqOperations::doPaste( QWidget * parent, const KUrl & destUrl, const QPoint &pos )
00127 {
00128     // move or not move ?
00129     bool move = false;
00130     const QMimeData *data = QApplication::clipboard()->mimeData();
00131     if ( data->hasFormat( "application/x-kde-cutselection" ) ) {
00132       move = KonqMimeData::decodeIsCutSelection( data );
00133       kDebug(1203) << "move (from clipboard data) = " << move;
00134     }
00135 
00136     KIO::Job *job = KIO::pasteClipboard( destUrl, parent, move );
00137     if ( job )
00138     {
00139         KonqOperations * op = new KonqOperations( parent );
00140         KIO::CopyJob * copyJob = static_cast<KIO::CopyJob *>(job);
00141         KIOPasteInfo * pi = new KIOPasteInfo;
00142         pi->mousePos = pos;
00143         op->setPasteInfo( pi );
00144         op->setOperation( job, move ? MOVE : COPY, copyJob->destUrl() );
00145         KIO::FileUndoManager::self()->recordJob( move ? KIO::FileUndoManager::Move : KIO::FileUndoManager::Copy, KUrl::List(), destUrl, job );
00146     }
00147 }
00148 
00149 void KonqOperations::copy( QWidget * parent, Operation method, const KUrl::List & selectedUrls, const KUrl& destUrl )
00150 {
00151     kDebug(1203) << "KonqOperations::copy() " << parent->metaObject()->className();
00152     if ((method!=COPY) && (method!=MOVE) && (method!=LINK))
00153     {
00154         kWarning(1203) << "Illegal copy method !" ;
00155         return;
00156     }
00157     if ( selectedUrls.isEmpty() )
00158     {
00159         kWarning(1203) << "Empty URL list !" ;
00160         return;
00161     }
00162 
00163     KonqOperations * op = new KonqOperations( parent );
00164     KIO::CopyJob* job;
00165     if (method == LINK)
00166         job = KIO::link( selectedUrls, destUrl );
00167     else if (method == MOVE)
00168         job = KIO::move( selectedUrls, destUrl );
00169     else
00170         job = KIO::copy( selectedUrls, destUrl );
00171 
00172     op->setOperation( job, method, destUrl );
00173 
00174     KIO::FileUndoManager::self()->recordCopyJob(job);
00175 }
00176 
00177 void KonqOperations::_del( Operation method, const KUrl::List & _selectedUrls, ConfirmationType confirmation )
00178 {
00179     KUrl::List selectedUrls;
00180     for (KUrl::List::ConstIterator it = _selectedUrls.begin(); it != _selectedUrls.end(); ++it)
00181         if (KProtocolManager::supportsDeleting(*it))
00182             selectedUrls.append(*it);
00183     if (selectedUrls.isEmpty()) {
00184         delete this;
00185         return;
00186     }
00187 
00188     if ( confirmation == SKIP_CONFIRMATION || askDeleteConfirmation( selectedUrls, method, confirmation, parentWidget() ) )
00189     {
00190         //m_srcUrls = selectedUrls;
00191         KIO::Job *job;
00192         m_method = method;
00193         switch( method )
00194         {
00195         case TRASH:
00196         {
00197             job = KIO::trash( selectedUrls );
00198             KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Trash, selectedUrls, KUrl("trash:/"), job );
00199             break;
00200         }
00201         case EMPTYTRASH:
00202         {
00203             // Same as in ktrash --empty
00204             QByteArray packedArgs;
00205             QDataStream stream( &packedArgs, QIODevice::WriteOnly );
00206             stream << (int)1;
00207             job = KIO::special( KUrl("trash:/"), packedArgs );
00208             KNotification::event("Trash: emptied", QString() , QPixmap() , 0l, KNotification::DefaultEvent );
00209             break;
00210         }
00211         case DEL:
00212             job = KIO::del( selectedUrls );
00213             break;
00214         default:
00215             kWarning() << "Unknown operation: " << method ;
00216             delete this;
00217             return;
00218         }
00219         job->ui()->setWindow(parentWidget());
00220         connect( job, SIGNAL( result( KJob * ) ),
00221                  SLOT( slotResult( KJob * ) ) );
00222     } else
00223         delete this;
00224 }
00225 
00226 void KonqOperations::_restoreTrashedItems( const KUrl::List& urls )
00227 {
00228     m_method = RESTORE;
00229     KonqMultiRestoreJob* job = new KonqMultiRestoreJob( urls );
00230     job->ui()->setWindow(parentWidget());
00231     KIO::getJobTracker()->registerJob(job);
00232     connect( job, SIGNAL( result( KJob * ) ),
00233              SLOT( slotResult( KJob * ) ) );
00234 }
00235 
00236 bool KonqOperations::askDeleteConfirmation( const KUrl::List & selectedUrls, int method, ConfirmationType confirmation, QWidget* widget )
00237 {
00238     KIO::JobUiDelegate::DeletionType deletionType = method == DEL ? KIO::JobUiDelegate::Delete : KIO::JobUiDelegate::Trash;
00239     KIO::JobUiDelegate::ConfirmationType confirmationType = confirmation == FORCE_CONFIRMATION ? KIO::JobUiDelegate::ForceConfirmation : KIO::JobUiDelegate::DefaultConfirmation;
00240     KIO::JobUiDelegate uiDelegate;
00241     uiDelegate.setWindow(widget);
00242     return uiDelegate.askDeleteConfirmation(selectedUrls, deletionType, confirmationType);
00243 }
00244 
00245 void KonqOperations::doDrop( const KFileItem & destItem, const KUrl & dest, QDropEvent * ev, QWidget * parent )
00246 {
00247     kDebug(1203) << "doDrop: dest:" << dest;
00248     QMap<QString, QString> metaData;
00249     const KUrl::List lst = KUrl::List::fromMimeData(ev->mimeData(), &metaData);
00250     if (!lst.isEmpty()) { // Are they urls ?
00251         //kDebug(1203) << "metaData:" << metaData.count() << "entries.";
00252         //QMap<QString,QString>::ConstIterator mit;
00253         //for( mit = metaData.begin(); mit != metaData.end(); ++mit ) {
00254         //    kDebug(1203) << "metaData: key=" << mit.key() << "value=" << mit.value();
00255         //}
00256         // Check if we dropped something on itself
00257         KUrl::List::ConstIterator it = lst.begin();
00258         for (; it != lst.end() ; it++) {
00259             kDebug(1203) << "URL:" << (*it);
00260             if (dest.equals(*it, KUrl::CompareWithoutTrailingSlash)) {
00261                 // The event source may be the view or an item (icon)
00262                 // Note: ev->source() can be 0L! (in case of kdesktop) (Simon)
00263                 if ( !ev->source() || ev->source() != parent && ev->source()->parent() != parent )
00264                     KMessageBox::sorry( parent, i18n("You cannot drop a folder on to itself") );
00265                 kDebug(1203) << "Dropped on itself";
00266                 ev->setAccepted( false );
00267                 return; // do nothing instead of displaying kfm's annoying error box
00268             }
00269         }
00270 
00271         // Check the state of the modifiers key at the time of the drop
00272         Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
00273 
00274         Qt::DropAction action = ev->dropAction();
00275         // Check for the drop of a bookmark -> we want a Link action
00276         if ( ev->provides("application/x-xbel") )
00277         {
00278             modifiers |= Qt::ControlModifier | Qt::ShiftModifier;
00279             action = Qt::LinkAction;
00280             kDebug(1203) << "KonqOperations::doDrop Bookmark -> emulating Link";
00281         }
00282 
00283         KonqOperations * op = new KonqOperations(parent);
00284         op->setDropInfo( new DropInfo( modifiers, lst, metaData, ev->pos(), action ) );
00285 
00286         // Ok, now we need destItem.
00287         if ( !destItem.isNull() )
00288         {
00289             op->asyncDrop( destItem ); // we have it already
00290         }
00291         else
00292         {
00293             // we need to stat to get it.
00294             op->_statUrl( dest, op, SLOT( asyncDrop( const KFileItem & ) ) );
00295         }
00296         // In both cases asyncDrop will delete op when done
00297 
00298         ev->acceptProposedAction();
00299     }
00300     else
00301     {
00302         //kDebug(1203) << "Pasting to " << dest.url();
00303         KonqOperations * op = new KonqOperations(parent);
00304         KIO::CopyJob* job = KIO::pasteMimeSource( ev->mimeData(), dest,
00305                                                   i18n( "File name for dropped contents:" ),
00306                                                   parent );
00307         if ( job ) // 0 if canceled by user
00308         {
00309             op->setOperation( job, COPY, job->destUrl() );
00310             KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Copy, KUrl::List(), dest, job );
00311         }
00312         ev->acceptProposedAction();
00313     }
00314 }
00315 
00316 void KonqOperations::asyncDrop( const KFileItem & destItem )
00317 {
00318     assert(m_info); // setDropInfo should have been called before asyncDrop
00319     m_destUrl = destItem.url();
00320 
00321     //kDebug(1203) << "KonqOperations::asyncDrop destItem->mode=" << destItem->mode() << " url=" << m_destUrl;
00322     // Check what the destination is
00323     if ( destItem.isDir() )
00324     {
00325         doDropFileCopy();
00326         return;
00327     }
00328     if ( !m_destUrl.isLocalFile() )
00329     {
00330         // We dropped onto a remote URL that is not a directory!
00331         // (e.g. an HTTP link in the sidebar).
00332         // Can't do that, but we can't prevent it before stating the dest....
00333         kWarning(1203) << "Cannot drop onto " << m_destUrl ;
00334         delete this;
00335         return;
00336     }
00337     if ( destItem.mimetype() == "application/x-desktop")
00338     {
00339         // Local .desktop file. What type ?
00340         KDesktopFile desktopFile( m_destUrl.path() );
00341         KConfigGroup desktopGroup = desktopFile.desktopGroup();
00342         if ( desktopFile.hasApplicationType() )
00343         {
00344             QString error;
00345             const QStringList urlStrList = m_info->urls.toStringList();
00346             if ( KToolInvocation::startServiceByDesktopPath( m_destUrl.path(), urlStrList, &error ) > 0 )
00347                 KMessageBox::error( parentWidget(), error );
00348         }
00349         else
00350         {
00351             // Device or Link -> adjust dest
00352             if ( desktopFile.hasDeviceType() && desktopGroup.hasKey("MountPoint") ) {
00353                 QString point = desktopGroup.readEntry( "MountPoint" );
00354                 m_destUrl.setPath( point );
00355                 QString dev = desktopFile.readDevice();
00356                 KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByDevice( dev );
00357                 // Is the device already mounted ?
00358                 if ( mp ) {
00359                     doDropFileCopy();
00360                 }
00361 #ifndef Q_WS_WIN
00362                 else
00363                 {
00364                     const bool ro = desktopGroup.readEntry( "ReadOnly", false );
00365                     const QByteArray fstype = desktopGroup.readEntry( "FSType" ).toLatin1();
00366                     KAutoMount* am = new KAutoMount( ro, fstype, dev, point, m_destUrl.path(), false );
00367                     connect( am, SIGNAL( finished() ), this, SLOT( doDropFileCopy() ) );
00368                 }
00369 #endif
00370                 return;
00371             }
00372             else if ( desktopFile.hasLinkType() && desktopGroup.hasKey("URL") ) {
00373                 m_destUrl = desktopGroup.readPathEntry("URL", QString());
00374                 doDropFileCopy();
00375                 return;
00376             }
00377             // else, well: mimetype, service, servicetype or .directory. Can't really drop anything on those.
00378         }
00379     }
00380     else
00381     {
00382         // Should be a local executable
00383         // (If this fails, there is a bug in KFileItem::acceptsDrops / KDirModel::flags)
00384         kDebug(1203) << "KonqOperations::doDrop " << m_destUrl.path() << "should be an executable";
00385         Q_ASSERT ( access( QFile::encodeName(m_destUrl.path()), X_OK ) == 0 );
00386         // Launch executable for each of the files
00387         QStringList args;
00388         KUrl::List lst = m_info->urls;
00389         KUrl::List::Iterator it = lst.begin();
00390         for ( ; it != lst.end() ; it++ )
00391             args << (*it).path(); // assume local files
00392         kDebug(1203) << "starting " << m_destUrl.path() << " with " << lst.count() << " arguments";
00393         KProcess::startDetached( m_destUrl.path(), args );
00394     }
00395     delete this;
00396 }
00397 
00398 void KonqOperations::doDropFileCopy()
00399 {
00400     assert(m_info); // setDropInfo - and asyncDrop - should have been called before asyncDrop
00401     const KUrl::List lst = m_info->urls;
00402     Qt::DropAction action = m_info->action;
00403     bool isDesktopFile = false;
00404     bool itemIsOnDesktop = false;
00405     bool allItemsAreFromTrash = true;
00406     KUrl::List mlst; // list of items that can be moved
00407     for (KUrl::List::ConstIterator it = lst.begin(); it != lst.end(); ++it)
00408     {
00409         bool local = (*it).isLocalFile();
00410         if ( KProtocolManager::supportsDeleting( *it ) && (!local || QFileInfo((*it).directory()).isWritable() ))
00411             mlst.append(*it);
00412         if ( local && KDesktopFile::isDesktopFile((*it).path()))
00413             isDesktopFile = true;
00414         if ( local && (*it).path().startsWith(KGlobalSettings::desktopPath()))
00415             itemIsOnDesktop = true;
00416         if ( local || (*it).protocol() != "trash" )
00417             allItemsAreFromTrash = false;
00418     }
00419 
00420     bool linkOnly = false;
00421     if (isDesktopFile && !KAuthorized::authorizeKAction("run_desktop_files") &&
00422         (m_destUrl.path( KUrl::AddTrailingSlash ) == KGlobalSettings::desktopPath()) )
00423     {
00424        linkOnly = true;
00425     }
00426 
00427     if ( !mlst.isEmpty() && m_destUrl.protocol() == "trash" )
00428     {
00429         if ( itemIsOnDesktop && !KAuthorized::authorizeKAction("editable_desktop_icons") )
00430         {
00431             delete this;
00432             return;
00433         }
00434 
00435         m_method = TRASH;
00436         if ( askDeleteConfirmation( mlst, TRASH, DEFAULT_CONFIRMATION, parentWidget() ) )
00437             action = Qt::MoveAction;
00438         else
00439         {
00440             delete this;
00441             return;
00442         }
00443     }
00444     else if ( allItemsAreFromTrash || m_destUrl.protocol() == "trash" ) {
00445         // No point in asking copy/move/link when using dnd from or to the trash.
00446         action = Qt::MoveAction;
00447     }
00448     else if ( (
00449         ((m_info->keyboardModifiers & Qt::ControlModifier) == 0) &&
00450         ((m_info->keyboardModifiers & Qt::ShiftModifier) == 0) &&
00451         ((m_info->keyboardModifiers & Qt::AltModifier) == 0) ) || linkOnly )
00452     {
00453         // Neither control, shift or alt are pressed => show popup menu
00454 
00455         // TODO move this code out somehow. Allow user of KonqOperations to add his own actions...
00456 #if 0
00457         KonqIconViewWidget *iconView = dynamic_cast<KonqIconViewWidget*>(parent());
00458         bool bSetWallpaper = false;
00459         if ( iconView && iconView->maySetWallpaper() && lst.count() == 1 )
00460     {
00461             KUrl url = lst.first();
00462             KMimeType::Ptr mime = KMimeType::findByUrl( url );
00463             if ( mime && ( ( KImageIO::isSupported(mime->name(), KImageIO::Reading) ) ||
00464                  mime->is( "image/svg+xml" ) ) )
00465             {
00466                 bSetWallpaper = true;
00467             }
00468         }
00469 #endif
00470 
00471         // Check what the source can do
00472         KUrl url = lst.first(); // we'll assume it's the same for all URLs (hack)
00473         bool sReading = KProtocolManager::supportsReading( url );
00474         bool sDeleting = KProtocolManager::supportsDeleting( url );
00475         bool sMoving = KProtocolManager::supportsMoving( url );
00476         // Check what the destination can do
00477         bool dWriting = KProtocolManager::supportsWriting( m_destUrl );
00478         if ( !dWriting )
00479         {
00480             delete this;
00481             return;
00482         }
00483 
00484         QMenu popup;
00485         QString seq = QKeySequence( Qt::ShiftModifier ).toString();
00486         seq.chop(1); // chop superfluous '+'
00487         QAction* popupMoveAction = new QAction(i18n( "&Move Here" ) + '\t' + seq, this);
00488         popupMoveAction->setIcon(KIcon("go-jump"));
00489         seq = QKeySequence( Qt::ControlModifier ).toString();
00490         seq.chop(1);
00491         QAction* popupCopyAction = new QAction(i18n( "&Copy Here" ) + '\t' + seq, this);
00492         popupCopyAction->setIcon(KIcon("edit-copy"));
00493         seq = QKeySequence( Qt::ControlModifier + Qt::ShiftModifier ).toString();
00494         seq.chop(1);
00495         QAction* popupLinkAction = new QAction(i18n( "&Link Here" ) + '\t' + seq, this);
00496         popupLinkAction->setIcon(KIcon("edit-link"));
00497         QAction* popupWallAction = new QAction( i18n( "Set as &Wallpaper" ), this );
00498         popupWallAction->setIcon(KIcon("preferences-desktop-wallpaper"));
00499         QAction* popupCancelAction = new QAction(i18n( "C&ancel" ) + '\t' + QKeySequence( Qt::Key_Escape ).toString(), this);
00500         popupCancelAction->setIcon(KIcon("process-stop"));
00501 
00502         if (!mlst.isEmpty() && (sMoving || (sReading && sDeleting)) && !linkOnly )
00503             popup.addAction(popupMoveAction);
00504 
00505         if ( sReading && !linkOnly)
00506             popup.addAction(popupCopyAction);
00507 
00508         popup.addAction(popupLinkAction);
00509 
00510 #if 0
00511         if (bSetWallpaper)
00512             popup.addAction(popupWallAction);
00513 #endif
00514 
00515         popup.addSeparator();
00516         popup.addAction(popupCancelAction);
00517 
00518         QAction* result = popup.exec( m_info->mousePos );
00519 
00520         if(result == popupCopyAction)
00521             action = Qt::CopyAction;
00522         else if(result == popupMoveAction)
00523             action = Qt::MoveAction;
00524         else if(result == popupLinkAction)
00525             action = Qt::LinkAction;
00526         else if(result == popupCancelAction || !result)
00527         {
00528             delete this;
00529             return;
00530         }
00531     }
00532 
00533     KIO::CopyJob * job = 0;
00534     switch ( action ) {
00535     case Qt::MoveAction :
00536         job = KIO::move( lst, m_destUrl );
00537         job->setMetaData( m_info->metaData );
00538         setOperation( job, m_method == TRASH ? TRASH : MOVE, m_destUrl );
00539         KIO::FileUndoManager::self()->recordJob(
00540             m_method == TRASH ? KIO::FileUndoManager::Trash : KIO::FileUndoManager::Move,
00541             lst, m_destUrl, job );
00542         return; // we still have stuff to do -> don't delete ourselves
00543     case Qt::CopyAction :
00544         job = KIO::copy( lst, m_destUrl );
00545         job->setMetaData( m_info->metaData );
00546         setOperation( job, COPY, m_destUrl );
00547         KIO::FileUndoManager::self()->recordCopyJob(job);
00548         return;
00549     case Qt::LinkAction :
00550         kDebug(1203) << "KonqOperations::asyncDrop lst.count=" << lst.count();
00551         job = KIO::link( lst, m_destUrl );
00552         job->setMetaData( m_info->metaData );
00553         setOperation( job, LINK, m_destUrl );
00554         KIO::FileUndoManager::self()->recordCopyJob(job);
00555         return;
00556     default : kError(1203) << "Unknown action " << (int)action << endl;
00557     }
00558     delete this;
00559 }
00560 
00561 void KonqOperations::rename( QWidget * parent, const KUrl & oldurl, const KUrl& newurl )
00562 {
00563     kDebug(1203) << "KonqOperations::rename oldurl=" << oldurl << " newurl=" << newurl;
00564     if ( oldurl == newurl )
00565         return;
00566 
00567     KUrl::List lst;
00568     lst.append(oldurl);
00569     KIO::Job * job = KIO::moveAs( oldurl, newurl, oldurl.isLocalFile() ? KIO::HideProgressInfo : KIO::DefaultFlags );
00570     KonqOperations * op = new KonqOperations( parent );
00571     op->setOperation( job, MOVE, newurl );
00572     KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Rename, lst, newurl, job );
00573     // if moving the desktop then update config file and emit
00574     if ( oldurl.isLocalFile() && oldurl.path( KUrl::AddTrailingSlash ) == KGlobalSettings::desktopPath() )
00575     {
00576         kDebug(1203) << "That rename was the Desktop path, updating config files";
00577         KSharedConfig::Ptr globalConfig = KGlobal::config();
00578         KConfigGroup cgs( globalConfig, "Paths" );
00579         cgs.writePathEntry("Desktop" , newurl.path(), KConfigBase::Persistent|KConfigBase::Global );
00580         cgs.sync();
00581         KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_PATHS);
00582     }
00583 }
00584 
00585 void KonqOperations::setOperation( KIO::Job * job, Operation method, const KUrl & dest )
00586 {
00587     m_method = method;
00588     m_destUrl = dest;
00589     if ( job )
00590     {
00591         job->ui()->setWindow(parentWidget());
00592         connect( job, SIGNAL( result( KJob * ) ),
00593                  SLOT( slotResult( KJob * ) ) );
00594 #if 0
00595         KIO::CopyJob *copyJob = dynamic_cast<KIO::CopyJob*>(job);
00596         KonqIconViewWidget *iconView = dynamic_cast<KonqIconViewWidget*>(parent());
00597         if (copyJob && iconView)
00598         {
00599             connect(copyJob, SIGNAL(aboutToCreate(KIO::Job *,const QList<KIO::CopyInfo> &)),
00600                  this, SLOT(slotAboutToCreate(KIO::Job *,const QList<KIO::CopyInfo> &)));
00601             // TODO move this connect into the iconview!
00602             connect(this, SIGNAL(aboutToCreate(const QPoint &, const QList<KIO::CopyInfo> &)),
00603                  iconView, SLOT(slotAboutToCreate(const QPoint &, const QList<KIO::CopyInfo> &)));
00604         }
00605 #endif
00606     }
00607     else // for link
00608         slotResult( 0L );
00609 }
00610 
00611 void KonqOperations::slotAboutToCreate(KIO::Job *, const QList<KIO::CopyInfo> &files)
00612 {
00613     emit aboutToCreate( m_info ? m_info->mousePos : m_pasteInfo ? m_pasteInfo->mousePos : QPoint(), files);
00614 }
00615 
00616 void KonqOperations::statUrl( const KUrl & url, const QObject *receiver, const char *member, QWidget* parent )
00617 {
00618     KonqOperations * op = new KonqOperations( parent );
00619     op->m_method = STAT;
00620     op->_statUrl( url, receiver, member );
00621 }
00622 
00623 void KonqOperations::_statUrl( const KUrl & url, const QObject *receiver, const char *member )
00624 {
00625     connect( this, SIGNAL( statFinished( const KFileItem & ) ), receiver, member );
00626     KIO::StatJob * job = KIO::stat( url /*, KIO::HideProgressInfo?*/ );
00627     job->ui()->setWindow(parentWidget());
00628     connect( job, SIGNAL( result( KJob * ) ),
00629              SLOT( slotStatResult( KJob * ) ) );
00630 }
00631 
00632 void KonqOperations::slotStatResult( KJob * job )
00633 {
00634     if ( job->error())
00635     {
00636         static_cast<KIO::Job*>( job )->ui()->showErrorMessage();
00637     }
00638     else
00639     {
00640         KIO::StatJob * statJob = static_cast<KIO::StatJob*>(job);
00641         KFileItem item( statJob->statResult(), statJob->url() );
00642         emit statFinished( item );
00643     }
00644     // If we're only here for a stat, we're done. But not if we used _statUrl internally
00645     if ( m_method == STAT )
00646         delete this;
00647 }
00648 
00649 void KonqOperations::slotResult( KJob * job )
00650 {
00651     if (job && job->error())
00652     {
00653         static_cast<KIO::Job*>( job )->ui()->showErrorMessage();
00654     }
00655     if ( m_method == EMPTYTRASH ) {
00656         // Update konq windows opened on trash:/
00657         org::kde::KDirNotify::emitFilesAdded( "trash:/" ); // yeah, files were removed, but we don't know which ones...
00658     }
00659     deleteLater();
00660 }
00661 
00662 void KonqOperations::rename( QWidget * parent, const KUrl & oldurl, const QString & name )
00663 {
00664     KUrl newurl( oldurl );
00665     newurl.setPath( oldurl.directory( KUrl::AppendTrailingSlash ) + name );
00666     kDebug(1203) << "KonqOperations::rename("<<name<<") called. newurl=" << newurl;
00667     rename( parent, oldurl, newurl );
00668 }
00669 
00670 KIO::SimpleJob* KonqOperations::newDir( QWidget * parent, const KUrl & baseUrl )
00671 {
00672     bool ok;
00673     QString name = i18n( "New Folder" );
00674     if ( baseUrl.isLocalFile() && QFileInfo( baseUrl.path( KUrl::AddTrailingSlash ) + name ).exists() )
00675         name = KIO::RenameDialog::suggestName( baseUrl, i18n( "New Folder" ) );
00676 
00677     name = KInputDialog::getText ( i18n( "New Folder" ),
00678         i18n( "Enter folder name:" ), name, &ok, parent );
00679     if ( ok && !name.isEmpty() )
00680     {
00681         KUrl url;
00682         if ((name[0] == '/') || (name[0] == '~'))
00683         {
00684            url.setPath(KShell::tildeExpand(name));
00685         }
00686         else
00687         {
00688            name = KIO::encodeFileName( name );
00689            url = baseUrl;
00690            url.addPath( name );
00691         }
00692         return KonqOperations::mkdir( parent, url );
00693     }
00694     return 0;
00695 }
00696 
00698 
00699 KonqMultiRestoreJob::KonqMultiRestoreJob( const KUrl::List& urls )
00700     : KIO::Job(),
00701       m_urls( urls ), m_urlsIterator( m_urls.begin() ),
00702       m_progress( 0 )
00703 {
00704     QTimer::singleShot(0, this, SLOT(slotStart()));
00705     setUiDelegate(new KIO::JobUiDelegate);
00706 }
00707 
00708 void KonqMultiRestoreJob::slotStart()
00709 {
00710     if ( m_urlsIterator == m_urls.begin() ) // first time: emit total
00711         setTotalAmount( KJob::Files, m_urls.count() );
00712 
00713     if ( m_urlsIterator != m_urls.end() )
00714     {
00715         const KUrl& url = *m_urlsIterator;
00716 
00717         KUrl new_url = url;
00718         if ( new_url.protocol()=="system"
00719           && new_url.path().startsWith("/trash") )
00720         {
00721             QString path = new_url.path();
00722         path.remove(0, 6);
00723         new_url.setProtocol("trash");
00724         new_url.setPath(path);
00725         }
00726 
00727         Q_ASSERT( new_url.protocol() == "trash" );
00728         QByteArray packedArgs;
00729         QDataStream stream( &packedArgs, QIODevice::WriteOnly );
00730         stream << (int)3 << new_url;
00731         KIO::Job* job = KIO::special( new_url, packedArgs, KIO::HideProgressInfo );
00732         addSubjob( job );
00733         setProcessedAmount(KJob::Files, processedAmount(KJob::Files) + 1);
00734     }
00735     else // done!
00736     {
00737         org::kde::KDirNotify::emitFilesRemoved(m_urls.toStringList() );
00738         emitResult();
00739     }
00740 }
00741 
00742 void KonqMultiRestoreJob::slotResult( KJob *job )
00743 {
00744     if ( job->error() )
00745     {
00746         KIO::Job::slotResult( job ); // will set the error and emit result(this)
00747         return;
00748     }
00749     removeSubjob(job);
00750     // Move on to next one
00751     ++m_urlsIterator;
00752     ++m_progress;
00753     //emit processedSize( this, m_progress );
00754     emitPercent( m_progress, m_urls.count() );
00755     slotStart();
00756 }
00757 
00758 QWidget* KonqOperations::parentWidget() const
00759 {
00760     return static_cast<QWidget *>( parent() );
00761 }
00762 
00763 #include "konq_operations.moc"

libkonq

Skip menu "libkonq"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal