• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • @topname@
  • Sitemap
  • Contact Us
 

libkonq

konq_operations.cc

00001 /*  This file is part of the KDE project
00002     Copyright (C) 2000  David Faure <faure@kde.org>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 */
00018 
00019 #include <qclipboard.h>
00020 #include "konq_operations.h"
00021 
00022 #include <kautomount.h>
00023 #include <kinputdialog.h>
00024 #include <klocale.h>
00025 #include <kmessagebox.h>
00026 #include <knotifyclient.h>
00027 #include <krun.h>
00028 #include <kshell.h>
00029 #include <kshortcut.h>
00030 
00031 #include <kdirnotify_stub.h>
00032 
00033 #include <dcopclient.h>
00034 #include "konq_undo.h"
00035 #include "konq_defaults.h"
00036 #include "konqbookmarkmanager.h"
00037 
00038 // For doDrop
00039 #include <qdir.h>//first
00040 #include <assert.h>
00041 #include <kapplication.h>
00042 #include <kipc.h>
00043 #include <kdebug.h>
00044 #include <kfileitem.h>
00045 #include <kdesktopfile.h>
00046 #include <kurldrag.h>
00047 #include <kglobalsettings.h>
00048 #include <kimageio.h>
00049 #include <kio/job.h>
00050 #include <kio/jobclasses.h>
00051 #include <kio/paste.h>
00052 #include <kio/netaccess.h>
00053 #include <kio/renamedlg.h>
00054 #include <konq_drag.h>
00055 #include <konq_iconviewwidget.h>
00056 #include <kprotocolinfo.h>
00057 #include <kprocess.h>
00058 #include <kstringhandler.h>
00059 #include <qpopupmenu.h>
00060 #include <unistd.h>
00061 #include <X11/Xlib.h>
00062 
00063 KBookmarkManager * KonqBookmarkManager::s_bookmarkManager;
00064 
00065 KonqOperations::KonqOperations( QWidget *parent )
00066     : QObject( parent, "KonqOperations" ),
00067       m_method( UNKNOWN ), m_info(0L), m_pasteInfo(0L)
00068 {
00069 }
00070 
00071 KonqOperations::~KonqOperations()
00072 {
00073     delete m_info;
00074     delete m_pasteInfo;
00075 }
00076 
00077 void KonqOperations::editMimeType( const QString & mimeType )
00078 {
00079   QString keditfiletype = QString::fromLatin1("keditfiletype");
00080   KRun::runCommand( keditfiletype + " " + KProcess::quote(mimeType),
00081                     keditfiletype, keditfiletype /*unused*/);
00082 }
00083 
00084 void KonqOperations::del( QWidget * parent, int method, const KURL::List & selectedURLs )
00085 {
00086   kdDebug(1203) << "KonqOperations::del " << parent->className() << endl;
00087   if ( selectedURLs.isEmpty() )
00088   {
00089     kdWarning(1203) << "Empty URL list !" << endl;
00090     return;
00091   }
00092 
00093   KonqOperations * op = new KonqOperations( parent );
00094     ConfirmationType confirmation = DEFAULT_CONFIRMATION;
00095   op->_del( method, selectedURLs, confirmation );
00096 }
00097 
00098 void KonqOperations::emptyTrash()
00099 {
00100   KonqOperations *op = new KonqOperations( 0L );
00101   op->_del( EMPTYTRASH, KURL("trash:/"), SKIP_CONFIRMATION );
00102 }
00103 
00104 void KonqOperations::restoreTrashedItems( const KURL::List& urls )
00105 {
00106   KonqOperations *op = new KonqOperations( 0L );
00107   op->_restoreTrashedItems( urls );
00108 }
00109 
00110 void KonqOperations::mkdir( QWidget *parent, const KURL & url )
00111 {
00112     KIO::Job * job = KIO::mkdir( url );
00113     KonqOperations * op = new KonqOperations( parent );
00114     op->setOperation( job, MKDIR, KURL::List(), url );
00115     (void) new KonqCommandRecorder( KonqCommand::MKDIR, KURL(), url, job ); // no support yet, apparently
00116 }
00117 
00118 void KonqOperations::doPaste( QWidget * parent, const KURL & destURL )
00119 {
00120    doPaste(parent, destURL, QPoint());
00121 }
00122 
00123 void KonqOperations::doPaste( QWidget * parent, const KURL & destURL, const QPoint &pos )
00124 {
00125     // move or not move ?
00126     bool move = false;
00127     QMimeSource *data = QApplication::clipboard()->data();
00128     if ( data->provides( "application/x-kde-cutselection" ) ) {
00129       move = KonqDrag::decodeIsCutSelection( data );
00130       kdDebug(1203) << "move (from clipboard data) = " << move << endl;
00131     }
00132 
00133     KIO::Job *job = KIO::pasteClipboard( destURL, move );
00134     if ( job )
00135     {
00136         KonqOperations * op = new KonqOperations( parent );
00137         KIO::CopyJob * copyJob = static_cast<KIO::CopyJob *>(job);
00138         KIOPasteInfo * pi = new KIOPasteInfo;
00139         pi->mousePos = pos;
00140         op->setPasteInfo( pi );
00141         op->setOperation( job, move ? MOVE : COPY, copyJob->srcURLs(), copyJob->destURL() );
00142         (void) new KonqCommandRecorder( move ? KonqCommand::MOVE : KonqCommand::COPY, KURL::List(), destURL, job );
00143     }
00144 }
00145 
00146 void KonqOperations::copy( QWidget * parent, int method, const KURL::List & selectedURLs, const KURL& destUrl )
00147 {
00148   kdDebug(1203) << "KonqOperations::copy() " << parent->className() << endl;
00149   if ((method!=COPY) && (method!=MOVE) && (method!=LINK))
00150   {
00151     kdWarning(1203) << "Illegal copy method !" << endl;
00152     return;
00153   }
00154   if ( selectedURLs.isEmpty() )
00155   {
00156     kdWarning(1203) << "Empty URL list !" << endl;
00157     return;
00158   }
00159 
00160   KonqOperations * op = new KonqOperations( parent );
00161   KIO::Job* job(0);
00162   if (method==LINK)
00163      job= KIO::link( selectedURLs, destUrl);
00164   else if (method==MOVE)
00165      job= KIO::move( selectedURLs, destUrl);
00166   else
00167      job= KIO::copy( selectedURLs, destUrl);
00168 
00169   op->setOperation( job, method, selectedURLs, destUrl );
00170 
00171   if (method==COPY)
00172      (void) new KonqCommandRecorder( KonqCommand::COPY, selectedURLs, destUrl, job );
00173   else
00174      (void) new KonqCommandRecorder( method==MOVE?KonqCommand::MOVE:KonqCommand::LINK, selectedURLs, destUrl, job );
00175 }
00176 
00177 void KonqOperations::_del( int 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 (KProtocolInfo::supportsDeleting(*it))
00182             selectedURLs.append(*it);
00183     if (selectedURLs.isEmpty()) {
00184         delete this;
00185         return;
00186     }
00187 
00188     if ( 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             (void) new KonqCommandRecorder( KonqCommand::TRASH, selectedURLs, "trash:/", job );
00199             break;
00200         }
00201         case EMPTYTRASH:
00202         {
00203             // Same as in ktrash --empty
00204             QByteArray packedArgs;
00205             QDataStream stream( packedArgs, IO_WriteOnly );
00206             stream << (int)1;
00207             job = KIO::special( "trash:/", packedArgs );
00208             KNotifyClient::event(0, "Trash: emptied");
00209             break;
00210         }
00211         case DEL:
00212             job = KIO::del( selectedURLs );
00213             break;
00214         case SHRED:
00215             job = KIO::del( selectedURLs, true );
00216             break;
00217         default:
00218             kdWarning() << "Unknown operation: " << method << endl;
00219             delete this;
00220             return;
00221         }
00222         connect( job, SIGNAL( result( KIO::Job * ) ),
00223                  SLOT( slotResult( KIO::Job * ) ) );
00224     } else
00225         delete this;
00226 }
00227 
00228 void KonqOperations::_restoreTrashedItems( const KURL::List& urls )
00229 {
00230     m_method = RESTORE;
00231     KonqMultiRestoreJob* job = new KonqMultiRestoreJob( urls, true );
00232     connect( job, SIGNAL( result( KIO::Job * ) ),
00233              SLOT( slotResult( KIO::Job * ) ) );
00234 }
00235 
00236 bool KonqOperations::askDeleteConfirmation( const KURL::List & selectedURLs, int method, ConfirmationType confirmation, QWidget* widget )
00237 {
00238     if ( confirmation == SKIP_CONFIRMATION )
00239         return true;
00240     QString keyName;
00241     bool ask = ( confirmation == FORCE_CONFIRMATION );
00242     if ( !ask )
00243     {
00244         KConfig config("konquerorrc", true, false);
00245         config.setGroup( "Trash" );
00246         keyName = ( method == DEL ? "ConfirmDelete" : method == SHRED ? "ConfirmShred" : "ConfirmTrash" );
00247         bool defaultValue = ( method == DEL ? DEFAULT_CONFIRMDELETE : method == SHRED ? DEFAULT_CONFIRMSHRED : DEFAULT_CONFIRMTRASH );
00248         ask = config.readBoolEntry( keyName, defaultValue );
00249     }
00250     if ( ask )
00251     {
00252       KURL::List::ConstIterator it = selectedURLs.begin();
00253       QStringList prettyList;
00254       for ( ; it != selectedURLs.end(); ++it ) {
00255         if ( (*it).protocol() == "trash" ) {
00256           QString path = (*it).path();
00257           // HACK (#98983): remove "0-foo". Note that it works better than
00258       // displaying KFileItem::name(), for files under a subdir.
00259           prettyList.append( path.remove(QRegExp("^/[0-9]*-")) );
00260         } else
00261           prettyList.append( (*it).pathOrURL() );
00262       }
00263 
00264       int result;
00265       switch(method)
00266       {
00267       case DEL:
00268           result = KMessageBox::warningContinueCancelList( widget,
00269                 i18n( "Do you really want to delete this item?", "Do you really want to delete these %n items?", prettyList.count()),
00270                 prettyList,
00271         i18n( "Delete Files" ),
00272         KStdGuiItem::del(),
00273         keyName, KMessageBox::Dangerous);
00274      break;
00275 
00276       case SHRED:
00277           result = KMessageBox::warningContinueCancelList( widget,
00278                 i18n( "Do you really want to shred this item?", "Do you really want to shred these %n items?", prettyList.count()),
00279                 prettyList,
00280                 i18n( "Shred Files" ),
00281         KGuiItem( i18n( "Shred" ), "editshred" ),
00282         keyName, KMessageBox::Dangerous);
00283         break;
00284 
00285       case MOVE:
00286       default:
00287           result = KMessageBox::warningContinueCancelList( widget,
00288                 i18n( "Do you really want to move this item to the trash?", "Do you really want to move these %n items to the trash?", prettyList.count()),
00289                 prettyList,
00290         i18n( "Move to Trash" ),
00291         KGuiItem( i18n( "Verb", "&Trash" ), "edittrash"),
00292         keyName, KMessageBox::Dangerous);
00293       }
00294       if (!keyName.isEmpty())
00295       {
00296          // Check kmessagebox setting... erase & copy to konquerorrc.
00297          KConfig *config = kapp->config();
00298          KConfigGroupSaver saver(config, "Notification Messages");
00299          if (!config->readBoolEntry(keyName, true))
00300          {
00301             config->writeEntry(keyName, true);
00302             config->sync();
00303             KConfig konq_config("konquerorrc", false);
00304             konq_config.setGroup( "Trash" );
00305             konq_config.writeEntry( keyName, false );
00306          }
00307       }
00308       return (result == KMessageBox::Continue);
00309     }
00310     return true;
00311 }
00312 
00313 void KonqOperations::doDrop( const KFileItem * destItem, const KURL & dest, QDropEvent * ev, QWidget * parent )
00314 {
00315     kdDebug(1203) << "doDrop: dest : " << dest.url() << endl;
00316     KURL::List lst;
00317     QMap<QString, QString> metaData;
00318     if ( KURLDrag::decode( ev, lst, metaData ) ) // Are they urls ?
00319     {
00320         if( lst.count() == 0 )
00321         {
00322             kdWarning(1203) << "Oooops, no data ...." << endl;
00323             ev->accept(false);
00324             return;
00325         }
00326         kdDebug(1203) << "KonqOperations::doDrop metaData: " << metaData.count() << " entries." << endl;
00327         QMap<QString,QString>::ConstIterator mit;
00328         for( mit = metaData.begin(); mit != metaData.end(); ++mit )
00329         {
00330             kdDebug(1203) << "metaData: key=" << mit.key() << " value=" << mit.data() << endl;
00331         }
00332         // Check if we dropped something on itself
00333         KURL::List::Iterator it = lst.begin();
00334         for ( ; it != lst.end() ; it++ )
00335         {
00336             kdDebug(1203) << "URL : " << (*it).url() << endl;
00337             if ( dest.equals( *it, true /*ignore trailing slashes*/ ) )
00338             {
00339                 // The event source may be the view or an item (icon)
00340                 // Note: ev->source() can be 0L! (in case of kdesktop) (Simon)
00341                 if ( !ev->source() || ev->source() != parent && ev->source()->parent() != parent )
00342                     KMessageBox::sorry( parent, i18n("You cannot drop a folder on to itself") );
00343                 kdDebug(1203) << "Dropped on itself" << endl;
00344                 ev->accept(false);
00345                 return; // do nothing instead of displaying kfm's annoying error box
00346             }
00347         }
00348 
00349         // Check the state of the modifiers key at the time of the drop
00350         Window root;
00351         Window child;
00352         int root_x, root_y, win_x, win_y;
00353         uint keybstate;
00354         XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
00355                        &root_x, &root_y, &win_x, &win_y, &keybstate );
00356 
00357         QDropEvent::Action action = ev->action();
00358         // Check for the drop of a bookmark -> we want a Link action
00359         if ( ev->provides("application/x-xbel") )
00360         {
00361             keybstate |= ControlMask | ShiftMask;
00362             action = QDropEvent::Link;
00363             kdDebug(1203) << "KonqOperations::doDrop Bookmark -> emulating Link" << endl;
00364         }
00365 
00366         KonqOperations * op = new KonqOperations(parent);
00367         op->setDropInfo( new DropInfo( keybstate, lst, metaData, win_x, win_y, action ) );
00368 
00369         // Ok, now we need destItem.
00370         if ( destItem )
00371         {
00372             op->asyncDrop( destItem ); // we have it already
00373         }
00374         else
00375         {
00376             // we need to stat to get it.
00377             op->_statURL( dest, op, SLOT( asyncDrop( const KFileItem * ) ) );
00378         }
00379         // In both cases asyncDrop will delete op when done
00380 
00381         ev->acceptAction();
00382     }
00383     else
00384     {
00385         //kdDebug(1203) << "Pasting to " << dest.url() << endl;
00386         KonqOperations * op = new KonqOperations(parent);
00387         KIO::CopyJob* job = KIO::pasteMimeSource( ev, dest,
00388                                                   i18n( "File name for dropped contents:" ),
00389                                                   parent );
00390         if ( job ) // 0 if canceled by user
00391         {
00392             op->setOperation( job, COPY, KURL::List(), job->destURL() );
00393             (void) new KonqCommandRecorder( KonqCommand::COPY, KURL::List(), dest, job );
00394         }
00395         ev->acceptAction();
00396     }
00397 }
00398 
00399 void KonqOperations::asyncDrop( const KFileItem * destItem )
00400 {
00401     assert(m_info); // setDropInfo should have been called before asyncDrop
00402     m_destURL = destItem->url();
00403 
00404     //kdDebug(1203) << "KonqOperations::asyncDrop destItem->mode=" << destItem->mode() << " url=" << m_destURL << endl;
00405     // Check what the destination is
00406     if ( destItem->isDir() )
00407     {
00408         doFileCopy();
00409         return;
00410     }
00411     if ( !m_destURL.isLocalFile() )
00412     {
00413         // We dropped onto a remote URL that is not a directory!
00414         // (e.g. an HTTP link in the sidebar).
00415         // Can't do that, but we can't prevent it before stating the dest....
00416         kdWarning(1203) << "Cannot drop onto " << m_destURL << endl;
00417         delete this;
00418         return;
00419     }
00420     if ( destItem->mimetype() == "application/x-desktop")
00421     {
00422         // Local .desktop file. What type ?
00423         KDesktopFile desktopFile( m_destURL.path() );
00424         if ( desktopFile.hasApplicationType() )
00425         {
00426             QString error;
00427             QStringList stringList;
00428             KURL::List lst = m_info->lst;
00429             KURL::List::Iterator it = lst.begin();
00430             for ( ; it != lst.end() ; it++ )
00431             {
00432                 stringList.append((*it).url());
00433             }
00434             if ( KApplication::startServiceByDesktopPath( m_destURL.path(), stringList, &error ) > 0 )
00435                 KMessageBox::error( 0L, error );
00436         }
00437         else
00438         {
00439             // Device or Link -> adjust dest
00440             if ( desktopFile.hasDeviceType() && desktopFile.hasKey("MountPoint") ) {
00441                 QString point = desktopFile.readEntry( "MountPoint" );
00442                 m_destURL.setPath( point );
00443                 QString dev = desktopFile.readDevice();
00444                 QString mp = KIO::findDeviceMountPoint( dev );
00445                 // Is the device already mounted ?
00446                 if ( !mp.isNull() )
00447                     doFileCopy();
00448                 else
00449                 {
00450                     bool ro = desktopFile.readBoolEntry( "ReadOnly", false );
00451                     QString fstype = desktopFile.readEntry( "FSType" );
00452                     KAutoMount* am = new KAutoMount( ro, fstype, dev, point, m_destURL.path(), false );
00453                     connect( am, SIGNAL( finished() ), this, SLOT( doFileCopy() ) );
00454                 }
00455                 return;
00456             }
00457             else if ( desktopFile.hasLinkType() && desktopFile.hasKey("URL") ) {
00458                 m_destURL = desktopFile.readPathEntry("URL");
00459                 doFileCopy();
00460                 return;
00461             }
00462             // else, well: mimetype, service, servicetype or .directory. Can't really drop anything on those.
00463         }
00464     }
00465     else
00466     {
00467         // Should be a local executable
00468         // (If this fails, there is a bug in KFileItem::acceptsDrops)
00469         kdDebug(1203) << "KonqOperations::doDrop " << m_destURL.path() << "should be an executable" << endl;
00470         Q_ASSERT ( access( QFile::encodeName(m_destURL.path()), X_OK ) == 0 );
00471         KProcess proc;
00472         proc << m_destURL.path() ;
00473         // Launch executable for each of the files
00474         KURL::List lst = m_info->lst;
00475         KURL::List::Iterator it = lst.begin();
00476         for ( ; it != lst.end() ; it++ )
00477             proc << (*it).path(); // assume local files
00478         kdDebug(1203) << "starting " << m_destURL.path() << " with " << lst.count() << " arguments" << endl;
00479         proc.start( KProcess::DontCare );
00480     }
00481     delete this;
00482 }
00483 
00484 void KonqOperations::doFileCopy()
00485 {
00486     assert(m_info); // setDropInfo - and asyncDrop - should have been called before asyncDrop
00487     KURL::List lst = m_info->lst;
00488     QDropEvent::Action action = m_info->action;
00489     bool isDesktopFile = false;
00490     bool itemIsOnDesktop = false;
00491     bool allItemsAreFromTrash = true;
00492     KURL::List mlst; // list of items that can be moved
00493     for (KURL::List::ConstIterator it = lst.begin(); it != lst.end(); ++it)
00494     {
00495         bool local = (*it).isLocalFile();
00496         if ( KProtocolInfo::supportsDeleting( *it ) && (!local || QFileInfo((*it).directory()).isWritable() ))
00497             mlst.append(*it);
00498         if ( local && KDesktopFile::isDesktopFile((*it).path()))
00499             isDesktopFile = true;
00500         if ( local && (*it).path().startsWith(KGlobalSettings::desktopPath()))
00501             itemIsOnDesktop = true;
00502         if ( local || (*it).protocol() != "trash" )
00503             allItemsAreFromTrash = false;
00504     }
00505 
00506     bool linkOnly = false;
00507     if (isDesktopFile && !kapp->authorize("run_desktop_files") &&
00508         (m_destURL.path(1) == KGlobalSettings::desktopPath()) )
00509     {
00510        linkOnly = true;
00511     }
00512 
00513     if ( !mlst.isEmpty() && m_destURL.protocol() == "trash" )
00514     {
00515         if ( itemIsOnDesktop && !kapp->authorize("editable_desktop_icons") )
00516         {
00517             delete this;
00518             return;
00519         }
00520 
00521         m_method = TRASH;
00522         if ( askDeleteConfirmation( mlst, TRASH, DEFAULT_CONFIRMATION, parentWidget() ) )
00523             action = QDropEvent::Move;
00524         else
00525         {
00526             delete this;
00527             return;
00528         }
00529     }
00530     else if ( allItemsAreFromTrash || m_destURL.protocol() == "trash" ) {
00531         // No point in asking copy/move/link when using dnd from or to the trash.
00532         action = QDropEvent::Move;
00533     }
00534     else if ( (((m_info->keybstate & ControlMask) == 0) && ((m_info->keybstate & ShiftMask) == 0)) ||
00535               linkOnly )
00536     {
00537         // Neither control nor shift are pressed => show popup menu
00538         KonqIconViewWidget *iconView = dynamic_cast<KonqIconViewWidget*>(parent());
00539         bool bSetWallpaper = false;
00540         if ( iconView && iconView->maySetWallpaper() && lst.count() == 1 )
00541     {
00542             KURL url = lst.first();
00543             KMimeType::Ptr mime = KMimeType::findByURL( url );
00544             if ( ( !KImageIO::type(url.path()).isEmpty() ) ||
00545                  ( KImageIO::isSupported(mime->name(), KImageIO::Reading) ) ||
00546                  mime->is( "image/svg+xml" ) )
00547             {
00548                 bSetWallpaper = true;
00549             }
00550         }
00551 
00552         // Check what the source can do
00553         KURL url = lst.first(); // we'll assume it's the same for all URLs (hack)
00554         bool sReading = KProtocolInfo::supportsReading( url );
00555         bool sDeleting = KProtocolInfo::supportsDeleting( url );
00556         bool sMoving = KProtocolInfo::supportsMoving( url );
00557         // Check what the destination can do
00558         bool dWriting = KProtocolInfo::supportsWriting( m_destURL );
00559         if ( !dWriting )
00560         {
00561             delete this;
00562             return;
00563         }
00564 
00565         QPopupMenu popup;
00566         if (!mlst.isEmpty() && (sMoving || (sReading && sDeleting)) && !linkOnly )
00567             popup.insertItem(SmallIconSet("goto"), i18n( "&Move Here" ) + "\t" + KKey::modFlagLabel( KKey::SHIFT ), 2 );
00568         if ( sReading && !linkOnly)
00569             popup.insertItem(SmallIconSet("editcopy"), i18n( "&Copy Here" ) + "\t" + KKey::modFlagLabel( KKey::CTRL ), 1 );
00570         popup.insertItem(SmallIconSet("www"), i18n( "&Link Here" ) + "\t" + KKey::modFlagLabel( (KKey::ModFlag)( KKey::CTRL|KKey::SHIFT ) ), 3 );
00571         if (bSetWallpaper)
00572             popup.insertItem(SmallIconSet("background"), i18n( "Set as &Wallpaper" ), 4 );
00573         popup.insertSeparator();
00574         popup.insertItem(SmallIconSet("cancel"), i18n( "C&ancel" ) + "\t" + KKey( Qt::Key_Escape ).toString(), 5);
00575 
00576         int result = popup.exec( m_info->mousePos );
00577 
00578         switch (result) {
00579         case 1 : action = QDropEvent::Copy; break;
00580         case 2 : action = QDropEvent::Move; break;
00581         case 3 : action = QDropEvent::Link; break;
00582         case 4 :
00583         {
00584             kdDebug(1203) << "setWallpaper iconView=" << iconView << " url=" << lst.first().url() << endl;
00585             if (iconView && iconView->isDesktop() ) iconView->setWallpaper(lst.first());
00586             delete this;
00587             return;
00588         }
00589         case 5 :
00590         default : delete this; return;
00591         }
00592     }
00593 
00594     KIO::Job * job = 0;
00595     switch ( action ) {
00596     case QDropEvent::Move :
00597         job = KIO::move( lst, m_destURL );
00598         job->setMetaData( m_info->metaData );
00599         setOperation( job, m_method == TRASH ? TRASH : MOVE, lst, m_destURL );
00600         (void) new KonqCommandRecorder(
00601             m_method == TRASH ? KonqCommand::TRASH : KonqCommand::MOVE,
00602             lst, m_destURL, job );
00603         return; // we still have stuff to do -> don't delete ourselves
00604     case QDropEvent::Copy :
00605         job = KIO::copy( lst, m_destURL );
00606         job->setMetaData( m_info->metaData );
00607         setOperation( job, COPY, lst, m_destURL );
00608         (void) new KonqCommandRecorder( KonqCommand::COPY, lst, m_destURL, job );
00609         return;
00610     case QDropEvent::Link :
00611         kdDebug(1203) << "KonqOperations::asyncDrop lst.count=" << lst.count() << endl;
00612         job = KIO::link( lst, m_destURL );
00613         job->setMetaData( m_info->metaData );
00614         setOperation( job, LINK, lst, m_destURL );
00615         (void) new KonqCommandRecorder( KonqCommand::LINK, lst, m_destURL, job );
00616         return;
00617     default : kdError(1203) << "Unknown action " << (int)action << endl;
00618     }
00619     delete this;
00620 }
00621 
00622 void KonqOperations::rename( QWidget * parent, const KURL & oldurl, const KURL& newurl )
00623 {
00624     kdDebug(1203) << "KonqOperations::rename oldurl=" << oldurl << " newurl=" << newurl << endl;
00625     if ( oldurl == newurl )
00626         return;
00627 
00628     KURL::List lst;
00629     lst.append(oldurl);
00630     KIO::Job * job = KIO::moveAs( oldurl, newurl, !oldurl.isLocalFile() );
00631     KonqOperations * op = new KonqOperations( parent );
00632     op->setOperation( job, MOVE, lst, newurl );
00633     (void) new KonqCommandRecorder( KonqCommand::MOVE, lst, newurl, job );
00634     // if moving the desktop then update config file and emit
00635     if ( oldurl.isLocalFile() && oldurl.path(1) == KGlobalSettings::desktopPath() )
00636     {
00637         kdDebug(1203) << "That rename was the Desktop path, updating config files" << endl;
00638         KConfig *globalConfig = KGlobal::config();
00639         KConfigGroupSaver cgs( globalConfig, "Paths" );
00640         globalConfig->writePathEntry("Desktop" , newurl.path(), true, true );
00641         globalConfig->sync();
00642         KIPC::sendMessageAll(KIPC::SettingsChanged, KApplication::SETTINGS_PATHS);
00643     }
00644 }
00645 
00646 void KonqOperations::setOperation( KIO::Job * job, int method, const KURL::List & /*src*/, const KURL & dest )
00647 {
00648     m_method = method;
00649     //m_srcURLs = src;
00650     m_destURL = dest;
00651     if ( job )
00652     {
00653         connect( job, SIGNAL( result( KIO::Job * ) ),
00654                  SLOT( slotResult( KIO::Job * ) ) );
00655         KIO::CopyJob *copyJob = dynamic_cast<KIO::CopyJob*>(job);
00656         KonqIconViewWidget *iconView = dynamic_cast<KonqIconViewWidget*>(parent());
00657         if (copyJob && iconView)
00658         {
00659             connect(copyJob, SIGNAL(aboutToCreate(KIO::Job *,const QValueList<KIO::CopyInfo> &)),
00660                  this, SLOT(slotAboutToCreate(KIO::Job *,const QValueList<KIO::CopyInfo> &)));
00661             connect(this, SIGNAL(aboutToCreate(const QPoint &, const QValueList<KIO::CopyInfo> &)),
00662                  iconView, SLOT(slotAboutToCreate(const QPoint &, const QValueList<KIO::CopyInfo> &)));
00663         }
00664     }
00665     else // for link
00666         slotResult( 0L );
00667 }
00668 
00669 void KonqOperations::slotAboutToCreate(KIO::Job *, const QValueList<KIO::CopyInfo> &files)
00670 {
00671     emit aboutToCreate( m_info ? m_info->mousePos : m_pasteInfo ? m_pasteInfo->mousePos : QPoint(), files);
00672 }
00673 
00674 void KonqOperations::statURL( const KURL & url, const QObject *receiver, const char *member )
00675 {
00676     KonqOperations * op = new KonqOperations( 0L );
00677     op->_statURL( url, receiver, member );
00678     op->m_method = STAT;
00679 }
00680 
00681 void KonqOperations::_statURL( const KURL & url, const QObject *receiver, const char *member )
00682 {
00683     connect( this, SIGNAL( statFinished( const KFileItem * ) ), receiver, member );
00684     KIO::StatJob * job = KIO::stat( url /*, false?*/ );
00685     connect( job, SIGNAL( result( KIO::Job * ) ),
00686              SLOT( slotStatResult( KIO::Job * ) ) );
00687 }
00688 
00689 void KonqOperations::slotStatResult( KIO::Job * job )
00690 {
00691     if ( job->error())
00692         job->showErrorDialog( (QWidget*)parent() );
00693     else
00694     {
00695         KIO::StatJob * statJob = static_cast<KIO::StatJob*>(job);
00696         KFileItem * item = new KFileItem( statJob->statResult(), statJob->url() );
00697         emit statFinished( item );
00698         delete item;
00699     }
00700     // If we're only here for a stat, we're done. But not if we used _statURL internally
00701     if ( m_method == STAT )
00702         delete this;
00703 }
00704 
00705 void KonqOperations::slotResult( KIO::Job * job )
00706 {
00707     if (job && job->error())
00708         job->showErrorDialog( (QWidget*)parent() );
00709     if ( m_method == EMPTYTRASH ) {
00710         // Update konq windows opened on trash:/
00711         KDirNotify_stub allDirNotify("*", "KDirNotify*");
00712         allDirNotify.FilesAdded( "trash:/" ); // yeah, files were removed, but we don't know which ones...
00713     }
00714     delete this;
00715 }
00716 
00717 void KonqOperations::rename( QWidget * parent, const KURL & oldurl, const QString & name )
00718 {
00719     KURL newurl( oldurl );
00720     newurl.setPath( oldurl.directory(false, true) + name );
00721     kdDebug(1203) << "KonqOperations::rename("<<name<<") called. newurl=" << newurl << endl;
00722     rename( parent, oldurl, newurl );
00723 }
00724 
00725 void KonqOperations::newDir( QWidget * parent, const KURL & baseURL )
00726 {
00727     bool ok;
00728     QString name = i18n( "New Folder" );
00729     if ( baseURL.isLocalFile() && QFileInfo( baseURL.path(+1) + name ).exists() )
00730         name = KIO::RenameDlg::suggestName( baseURL, i18n( "New Folder" ) );
00731 
00732     name = KInputDialog::getText ( i18n( "New Folder" ),
00733         i18n( "Enter folder name:" ), name, &ok, parent );
00734     if ( ok && !name.isEmpty() )
00735     {
00736         KURL url;
00737         if ((name[0] == '/') || (name[0] == '~'))
00738         {
00739            url.setPath(KShell::tildeExpand(name));
00740         }
00741         else
00742         {
00743            name = KIO::encodeFileName( name );
00744            url = baseURL;
00745            url.addPath( name );
00746         }
00747         KonqOperations::mkdir( 0L, url );
00748     }
00749 }
00750 
00752 
00753 KonqMultiRestoreJob::KonqMultiRestoreJob( const KURL::List& urls, bool showProgressInfo )
00754     : KIO::Job( showProgressInfo ),
00755       m_urls( urls ), m_urlsIterator( m_urls.begin() ),
00756       m_progress( 0 )
00757 {
00758   QTimer::singleShot(0, this, SLOT(slotStart()));
00759 }
00760 
00761 void KonqMultiRestoreJob::slotStart()
00762 {
00763     // Well, it's not a total in bytes, so this would look weird
00764     //if ( m_urlsIterator == m_urls.begin() ) // first time: emit total
00765     //    emit totalSize( m_urls.count() );
00766 
00767     if ( m_urlsIterator != m_urls.end() )
00768     {
00769         const KURL& url = *m_urlsIterator;
00770 
00771         KURL new_url = url;
00772         if ( new_url.protocol()=="system"
00773           && new_url.path().startsWith("/trash") )
00774         {
00775             QString path = new_url.path();
00776         path.remove(0, 6);
00777         new_url.setProtocol("trash");
00778         new_url.setPath(path);
00779         }
00780 
00781         Q_ASSERT( new_url.protocol() == "trash" );
00782         QByteArray packedArgs;
00783         QDataStream stream( packedArgs, IO_WriteOnly );
00784         stream << (int)3 << new_url;
00785         KIO::Job* job = KIO::special( new_url, packedArgs );
00786         addSubjob( job );
00787     }
00788     else // done!
00789     {
00790         KDirNotify_stub allDirNotify("*", "KDirNotify*");
00791         allDirNotify.FilesRemoved( m_urls );
00792         emitResult();
00793     }
00794 }
00795 
00796 void KonqMultiRestoreJob::slotResult( KIO::Job *job )
00797 {
00798     if ( job->error() )
00799     {
00800         KIO::Job::slotResult( job ); // will set the error and emit result(this)
00801         return;
00802     }
00803     subjobs.remove( job );
00804     // Move on to next one
00805     ++m_urlsIterator;
00806     ++m_progress;
00807     //emit processedSize( this, m_progress );
00808     emitPercent( m_progress, m_urls.count() );
00809     slotStart();
00810 }
00811 
00812 QWidget* KonqOperations::parentWidget() const
00813 {
00814     return static_cast<QWidget *>( parent() );
00815 }
00816 
00817 #include "konq_operations.moc"

libkonq

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

@topname@

Skip menu "@topname@"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for @topname@ by doxygen 1.5.9
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