• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_operations.cc
1 /* This file is part of the KDE project
2  Copyright (C) 2000 David Faure <faure@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include <tqclipboard.h>
20 #include "konq_operations.h"
21 
22 #include <kautomount.h>
23 #include <kinputdialog.h>
24 #include <klocale.h>
25 #include <kmessagebox.h>
26 #include <knotifyclient.h>
27 #include <krun.h>
28 #include <kshell.h>
29 #include <kshortcut.h>
30 
31 #include <kdirnotify_stub.h>
32 
33 #include <dcopclient.h>
34 #include "konq_undo.h"
35 #include "konq_defaults.h"
36 #include "konqbookmarkmanager.h"
37 
38 // For doDrop
39 #include <tqdir.h>//first
40 #include <assert.h>
41 #include <kapplication.h>
42 #include <kipc.h>
43 #include <kdebug.h>
44 #include <kfileitem.h>
45 #include <kdesktopfile.h>
46 #include <kurldrag.h>
47 #include <kglobalsettings.h>
48 #include <kimageio.h>
49 #include <kio/job.h>
50 #include <kio/jobclasses.h>
51 #include <kio/paste.h>
52 #include <kio/netaccess.h>
53 #include <kio/renamedlg.h>
54 #include <konq_drag.h>
55 #include <konq_iconviewwidget.h>
56 #include <kprotocolinfo.h>
57 #include <kprocess.h>
58 #include <kstringhandler.h>
59 #include <tqpopupmenu.h>
60 #include <unistd.h>
61 #include <X11/Xlib.h>
62 
63 KBookmarkManager * KonqBookmarkManager::s_bookmarkManager;
64 
65 KonqOperations::KonqOperations( TQWidget *parent )
66  : TQObject( parent, "KonqOperations" ),
67  m_method( UNKNOWN ), m_info(0L), m_pasteInfo(0L)
68 {
69 }
70 
71 KonqOperations::~KonqOperations()
72 {
73  delete m_info;
74  delete m_pasteInfo;
75 }
76 
77 void KonqOperations::editMimeType( const TQString & mimeType )
78 {
79  TQString keditfiletype = TQString::fromLatin1("keditfiletype");
80  KRun::runCommand( keditfiletype + " " + KProcess::quote(mimeType),
81  keditfiletype, keditfiletype /*unused*/);
82 }
83 
84 void KonqOperations::del( TQWidget * parent, int method, const KURL::List & selectedURLs )
85 {
86  kdDebug(1203) << "KonqOperations::del " << parent->className() << endl;
87  if ( selectedURLs.isEmpty() )
88  {
89  kdWarning(1203) << "Empty URL list !" << endl;
90  return;
91  }
92 
93  KonqOperations * op = new KonqOperations( parent );
94  ConfirmationType confirmation = DEFAULT_CONFIRMATION;
95  op->_del( method, selectedURLs, confirmation );
96 }
97 
98 void KonqOperations::emptyTrash()
99 {
100  KonqOperations *op = new KonqOperations( 0L );
101  op->_del( EMPTYTRASH, KURL("trash:/"), SKIP_CONFIRMATION );
102 }
103 
104 void KonqOperations::restoreTrashedItems( const KURL::List& urls )
105 {
106  KonqOperations *op = new KonqOperations( 0L );
107  op->_restoreTrashedItems( urls );
108 }
109 
110 void KonqOperations::mkdir( TQWidget *parent, const KURL & url )
111 {
112  KIO::Job * job = KIO::mkdir( url );
113  KonqOperations * op = new KonqOperations( parent );
114  op->setOperation( job, MKDIR, KURL::List(), url );
115  (void) new KonqCommandRecorder( KonqCommand::MKDIR, KURL(), url, job ); // no support yet, apparently
116 }
117 
118 void KonqOperations::doPaste( TQWidget * parent, const KURL & destURL )
119 {
120  doPaste(parent, destURL, TQPoint());
121 }
122 
123 void KonqOperations::doPaste( TQWidget * parent, const KURL & destURL, const TQPoint &pos )
124 {
125  // move or not move ?
126  bool move = false;
127  TQMimeSource *data = TQApplication::clipboard()->data();
128  if ( data->provides( "application/x-kde-cutselection" ) ) {
129  move = KonqDrag::decodeIsCutSelection( data );
130  kdDebug(1203) << "move (from clipboard data) = " << move << endl;
131  }
132 
133  KIO::Job *job = KIO::pasteClipboard( destURL, move );
134  if ( job )
135  {
136  KonqOperations * op = new KonqOperations( parent );
137  KIO::CopyJob * copyJob = static_cast<KIO::CopyJob *>(job);
138  KIOPasteInfo * pi = new KIOPasteInfo;
139  pi->mousePos = pos;
140  op->setPasteInfo( pi );
141  op->setOperation( job, move ? MOVE : COPY, copyJob->srcURLs(), copyJob->destURL() );
142  (void) new KonqCommandRecorder( move ? KonqCommand::MOVE : KonqCommand::COPY, KURL::List(), destURL, job );
143  }
144 }
145 
146 void KonqOperations::copy( TQWidget * parent, int method, const KURL::List & selectedURLs, const KURL& destUrl )
147 {
148  kdDebug(1203) << "KonqOperations::copy() " << parent->className() << endl;
149  if ((method!=COPY) && (method!=MOVE) && (method!=LINK))
150  {
151  kdWarning(1203) << "Illegal copy method !" << endl;
152  return;
153  }
154  if ( selectedURLs.isEmpty() )
155  {
156  kdWarning(1203) << "Empty URL list !" << endl;
157  return;
158  }
159 
160  KonqOperations * op = new KonqOperations( parent );
161  KIO::Job* job(0);
162  if (method==LINK)
163  job= KIO::link( selectedURLs, destUrl);
164  else if (method==MOVE)
165  job= KIO::move( selectedURLs, destUrl);
166  else
167  job= KIO::copy( selectedURLs, destUrl);
168 
169  op->setOperation( job, method, selectedURLs, destUrl );
170 
171  if (method==COPY)
172  (void) new KonqCommandRecorder( KonqCommand::COPY, selectedURLs, destUrl, job );
173  else
174  (void) new KonqCommandRecorder( method==MOVE?KonqCommand::MOVE:KonqCommand::LINK, selectedURLs, destUrl, job );
175 }
176 
177 void KonqOperations::_del( int method, const KURL::List & _selectedURLs, ConfirmationType confirmation )
178 {
179  KURL::List selectedURLs;
180  for (KURL::List::ConstIterator it = _selectedURLs.begin(); it != _selectedURLs.end(); ++it)
181  if (KProtocolInfo::supportsDeleting(*it))
182  selectedURLs.append(*it);
183  if (selectedURLs.isEmpty()) {
184  delete this;
185  return;
186  }
187 
188  if ( askDeleteConfirmation( selectedURLs, method, confirmation, parentWidget() ) )
189  {
190  //m_srcURLs = selectedURLs;
191  KIO::Job *job;
192  m_method = method;
193  switch( method )
194  {
195  case TRASH:
196  {
197  job = KIO::trash( selectedURLs );
198  (void) new KonqCommandRecorder( KonqCommand::TRASH, selectedURLs, "trash:/", job );
199  break;
200  }
201  case EMPTYTRASH:
202  {
203  // Same as in ktrash --empty
204  TQByteArray packedArgs;
205  TQDataStream stream( packedArgs, IO_WriteOnly );
206  stream << (int)1;
207  job = KIO::special( "trash:/", packedArgs );
208  KNotifyClient::event(0, "Trash: emptied");
209  break;
210  }
211  case DEL:
212  job = KIO::del( selectedURLs );
213  break;
214  case SHRED:
215  job = KIO::del( selectedURLs, true );
216  break;
217  default:
218  kdWarning() << "Unknown operation: " << method << endl;
219  delete this;
220  return;
221  }
222  connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
223  TQT_SLOT( slotResult( KIO::Job * ) ) );
224  } else
225  delete this;
226 }
227 
228 void KonqOperations::_restoreTrashedItems( const KURL::List& urls )
229 {
230  m_method = RESTORE;
231  KonqMultiRestoreJob* job = new KonqMultiRestoreJob( urls, true );
232  connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
233  TQT_SLOT( slotResult( KIO::Job * ) ) );
234 }
235 
236 bool KonqOperations::askDeleteConfirmation( const KURL::List & selectedURLs, int method, ConfirmationType confirmation, TQWidget* widget )
237 {
238  if ( confirmation == SKIP_CONFIRMATION )
239  return true;
240  TQString keyName;
241  bool ask = ( confirmation == FORCE_CONFIRMATION );
242  if ( !ask )
243  {
244  KConfig config("konquerorrc", true, false);
245  config.setGroup( "Trash" );
246  keyName = ( method == DEL ? "ConfirmDelete" : method == SHRED ? "ConfirmShred" : "ConfirmTrash" );
247  bool defaultValue = ( method == DEL ? DEFAULT_CONFIRMDELETE : method == SHRED ? DEFAULT_CONFIRMSHRED : DEFAULT_CONFIRMTRASH );
248  ask = config.readBoolEntry( keyName, defaultValue );
249  }
250  if ( ask )
251  {
252  KURL::List::ConstIterator it = selectedURLs.begin();
253  TQStringList prettyList;
254  for ( ; it != selectedURLs.end(); ++it ) {
255  if ( (*it).protocol() == "trash" ) {
256  TQString path = (*it).path();
257  // HACK (#98983): remove "0-foo". Note that it works better than
258  // displaying KFileItem::name(), for files under a subdir.
259  prettyList.append( path.remove(TQRegExp("^/[0-9]*-")) );
260  } else
261  prettyList.append( (*it).pathOrURL() );
262  }
263 
264  int result;
265  switch(method)
266  {
267  case DEL:
268  result = KMessageBox::warningContinueCancelList( widget,
269  i18n( "Do you really want to delete this item?", "Do you really want to delete these %n items?", prettyList.count()),
270  prettyList,
271  i18n( "Delete Files" ),
272  KStdGuiItem::del(),
273  keyName, KMessageBox::Dangerous);
274  break;
275 
276  case SHRED:
277  result = KMessageBox::warningContinueCancelList( widget,
278  i18n( "Do you really want to shred this item?", "Do you really want to shred these %n items?", prettyList.count()),
279  prettyList,
280  i18n( "Shred Files" ),
281  KGuiItem( i18n( "Shred" ), "editshred" ),
282  keyName, KMessageBox::Dangerous);
283  break;
284 
285  case MOVE:
286  default:
287  result = KMessageBox::warningContinueCancelList( widget,
288  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()),
289  prettyList,
290  i18n( "Move to Trash" ),
291  KGuiItem( i18n( "Verb", "&Trash" ), "edittrash"),
292  keyName, KMessageBox::Dangerous);
293  }
294  if (!keyName.isEmpty())
295  {
296  // Check kmessagebox setting... erase & copy to konquerorrc.
297  KConfig *config = kapp->config();
298  KConfigGroupSaver saver(config, "Notification Messages");
299  if (!config->readBoolEntry(keyName, true))
300  {
301  config->writeEntry(keyName, true);
302  config->sync();
303  KConfig konq_config("konquerorrc", false);
304  konq_config.setGroup( "Trash" );
305  konq_config.writeEntry( keyName, false );
306  }
307  }
308  return (result == KMessageBox::Continue);
309  }
310  return true;
311 }
312 
313 void KonqOperations::doDrop( const KFileItem * destItem, const KURL & dest, TQDropEvent * ev, TQWidget * parent )
314 {
315  kdDebug(1203) << "doDrop: dest : " << dest.url() << endl;
316  KURL::List lst;
317  TQMap<TQString, TQString> metaData;
318  if ( KURLDrag::decode( ev, lst, metaData ) ) // Are they urls ?
319  {
320  if( lst.count() == 0 )
321  {
322  kdWarning(1203) << "Oooops, no data ...." << endl;
323  ev->accept(false);
324  return;
325  }
326  kdDebug(1203) << "KonqOperations::doDrop metaData: " << metaData.count() << " entries." << endl;
327  TQMap<TQString,TQString>::ConstIterator mit;
328  for( mit = metaData.begin(); mit != metaData.end(); ++mit )
329  {
330  kdDebug(1203) << "metaData: key=" << mit.key() << " value=" << mit.data() << endl;
331  }
332  // Check if we dropped something on itself
333  KURL::List::Iterator it = lst.begin();
334  for ( ; it != lst.end() ; it++ )
335  {
336  kdDebug(1203) << "URL : " << (*it).url() << endl;
337  if ( dest.equals( *it, true /*ignore trailing slashes*/ ) )
338  {
339  // The event source may be the view or an item (icon)
340  // Note: ev->source() can be 0L! (in case of kdesktop) (Simon)
341  if ( !ev->source() || ev->source() != parent && ev->source()->parent() != parent )
342  KMessageBox::sorry( parent, i18n("You cannot drop a folder on to itself") );
343  kdDebug(1203) << "Dropped on itself" << endl;
344  ev->accept(false);
345  return; // do nothing instead of displaying kfm's annoying error box
346  }
347  }
348 
349  // Check the state of the modifiers key at the time of the drop
350  Window root;
351  Window child;
352  int root_x, root_y, win_x, win_y;
353  uint keybstate;
354  XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
355  &root_x, &root_y, &win_x, &win_y, &keybstate );
356 
357  TQDropEvent::Action action = ev->action();
358  // Check for the drop of a bookmark -> we want a Link action
359  if ( ev->provides("application/x-xbel") )
360  {
361  keybstate |= ControlMask | ShiftMask;
362  action = TQDropEvent::Link;
363  kdDebug(1203) << "KonqOperations::doDrop Bookmark -> emulating Link" << endl;
364  }
365 
366  KonqOperations * op = new KonqOperations(parent);
367  op->setDropInfo( new DropInfo( keybstate, lst, metaData, win_x, win_y, action ) );
368 
369  // Ok, now we need destItem.
370  if ( destItem )
371  {
372  op->asyncDrop( destItem ); // we have it already
373  }
374  else
375  {
376  // we need to stat to get it.
377  op->_statURL( dest, op, TQT_SLOT( asyncDrop( const KFileItem * ) ) );
378  }
379  // In both cases asyncDrop will delete op when done
380 
381  ev->acceptAction();
382  }
383  else
384  {
385  //kdDebug(1203) << "Pasting to " << dest.url() << endl;
386  KonqOperations * op = new KonqOperations(parent);
387  KIO::CopyJob* job = KIO::pasteMimeSource( ev, dest,
388  i18n( "File name for dropped contents:" ),
389  parent );
390  if ( job ) // 0 if canceled by user
391  {
392  op->setOperation( job, COPY, KURL::List(), job->destURL() );
393  (void) new KonqCommandRecorder( KonqCommand::COPY, KURL::List(), dest, job );
394  }
395  ev->acceptAction();
396  }
397 }
398 
399 void KonqOperations::asyncDrop( const KFileItem * destItem )
400 {
401  assert(m_info); // setDropInfo should have been called before asyncDrop
402  m_destURL = destItem->url();
403 
404  //kdDebug(1203) << "KonqOperations::asyncDrop destItem->mode=" << destItem->mode() << " url=" << m_destURL << endl;
405  // Check what the destination is
406  if ( destItem->isDir() )
407  {
408  doFileCopy();
409  return;
410  }
411  if ( !m_destURL.isLocalFile() )
412  {
413  // We dropped onto a remote URL that is not a directory!
414  // (e.g. an HTTP link in the sidebar).
415  // Can't do that, but we can't prevent it before stating the dest....
416  kdWarning(1203) << "Cannot drop onto " << m_destURL << endl;
417  delete this;
418  return;
419  }
420  if ( (destItem->mimetype() == "application/x-desktop")
421  || (destItem->mimetype() == "media/builtin-mydocuments")
422  || (destItem->mimetype() == "media/builtin-mycomputer")
423  || (destItem->mimetype() == "media/builtin-mynetworkplaces")
424  || (destItem->mimetype() == "media/builtin-printers")
425  || (destItem->mimetype() == "media/builtin-trash")
426  || (destItem->mimetype() == "media/builtin-webbrowser") )
427  {
428  // Local .desktop file. What type ?
429  KDesktopFile desktopFile( m_destURL.path() );
430  if ( desktopFile.hasApplicationType() )
431  {
432  TQString error;
433  TQStringList stringList;
434  KURL::List lst = m_info->lst;
435  KURL::List::Iterator it = lst.begin();
436  for ( ; it != lst.end() ; it++ )
437  {
438  stringList.append((*it).url());
439  }
440  if ( KApplication::startServiceByDesktopPath( m_destURL.path(), stringList, &error ) > 0 )
441  KMessageBox::error( 0L, error );
442  }
443  else
444  {
445  // Device or Link -> adjust dest
446  if ( desktopFile.hasDeviceType() && desktopFile.hasKey("MountPoint") ) {
447  TQString point = desktopFile.readEntry( "MountPoint" );
448  m_destURL.setPath( point );
449  TQString dev = desktopFile.readDevice();
450  TQString mp = KIO::findDeviceMountPoint( dev );
451  // Is the device already mounted ?
452  if ( !mp.isNull() )
453  doFileCopy();
454  else
455  {
456  bool ro = desktopFile.readBoolEntry( "ReadOnly", false );
457  TQString fstype = desktopFile.readEntry( "FSType" );
458  KAutoMount* am = new KAutoMount( ro, fstype, dev, point, m_destURL.path(), false );
459  connect( am, TQT_SIGNAL( finished() ), this, TQT_SLOT( doFileCopy() ) );
460  }
461  return;
462  }
463  else if ( desktopFile.hasLinkType() && desktopFile.hasKey("URL") ) {
464  m_destURL = desktopFile.readPathEntry("URL");
465  doFileCopy();
466  return;
467  }
468  // else, well: mimetype, service, servicetype or .directory. Can't really drop anything on those.
469  }
470  }
471  else
472  {
473  // Should be a local executable
474  // (If this fails, there is a bug in KFileItem::acceptsDrops)
475  kdDebug(1203) << "KonqOperations::doDrop " << m_destURL.path() << "should be an executable" << endl;
476  Q_ASSERT ( access( TQFile::encodeName(m_destURL.path()), X_OK ) == 0 );
477  KProcess proc;
478  proc << m_destURL.path() ;
479  // Launch executable for each of the files
480  KURL::List lst = m_info->lst;
481  KURL::List::Iterator it = lst.begin();
482  for ( ; it != lst.end() ; it++ )
483  proc << (*it).path(); // assume local files
484  kdDebug(1203) << "starting " << m_destURL.path() << " with " << lst.count() << " arguments" << endl;
485  proc.start( KProcess::DontCare );
486  }
487  delete this;
488 }
489 
490 void KonqOperations::doFileCopy()
491 {
492  assert(m_info); // setDropInfo - and asyncDrop - should have been called before asyncDrop
493  KURL::List lst = m_info->lst;
494  TQDropEvent::Action action = m_info->action;
495  bool isDesktopFile = false;
496  bool itemIsOnDesktop = false;
497  bool allItemsAreFromTrash = true;
498  KURL::List mlst; // list of items that can be moved
499  for (KURL::List::ConstIterator it = lst.begin(); it != lst.end(); ++it)
500  {
501  bool local = (*it).isLocalFile();
502  if ( KProtocolInfo::supportsDeleting( *it ) && (!local || TQFileInfo((*it).directory()).isWritable() ))
503  mlst.append(*it);
504  if ( local && KDesktopFile::isDesktopFile((*it).path()))
505  isDesktopFile = true;
506  if ( local && (*it).path().startsWith(KGlobalSettings::desktopPath()))
507  itemIsOnDesktop = true;
508  if ( local || (*it).protocol() != "trash" )
509  allItemsAreFromTrash = false;
510  }
511 
512  bool linkOnly = false;
513  if (isDesktopFile && !kapp->authorize("run_desktop_files") &&
514  (m_destURL.path(1) == KGlobalSettings::desktopPath()) )
515  {
516  linkOnly = true;
517  }
518 
519  if ( !mlst.isEmpty() && m_destURL.protocol() == "trash" )
520  {
521  if ( itemIsOnDesktop && !kapp->authorize("editable_desktop_icons") )
522  {
523  delete this;
524  return;
525  }
526 
527  m_method = TRASH;
528  if ( askDeleteConfirmation( mlst, TRASH, DEFAULT_CONFIRMATION, parentWidget() ) )
529  action = TQDropEvent::Move;
530  else
531  {
532  delete this;
533  return;
534  }
535  }
536  else if ( allItemsAreFromTrash || m_destURL.protocol() == "trash" ) {
537  // No point in asking copy/move/link when using dnd from or to the trash.
538  action = TQDropEvent::Move;
539  }
540  else if ( (((m_info->keybstate & ControlMask) == 0) && ((m_info->keybstate & ShiftMask) == 0)) ||
541  linkOnly )
542  {
543  // Neither control nor shift are pressed => show popup menu
544  KonqIconViewWidget *iconView = tqt_dynamic_cast<KonqIconViewWidget*>(parent());
545  bool bSetWallpaper = false;
546  if ( iconView && iconView->maySetWallpaper() && lst.count() == 1 )
547  {
548  KURL url = lst.first();
549  KMimeType::Ptr mime = KMimeType::findByURL( url );
550  if ( ( !KImageIO::type(url.path()).isEmpty() ) ||
551  ( KImageIO::isSupported(mime->name(), KImageIO::Reading) ) ||
552  mime->is( "image/svg+xml" ) )
553  {
554  bSetWallpaper = true;
555  }
556  }
557 
558  // Check what the source can do
559  KURL url = lst.first(); // we'll assume it's the same for all URLs (hack)
560  bool sReading = KProtocolInfo::supportsReading( url );
561  bool sDeleting = KProtocolInfo::supportsDeleting( url );
562  bool sMoving = KProtocolInfo::supportsMoving( url );
563  // Check what the destination can do
564  bool dWriting = KProtocolInfo::supportsWriting( m_destURL );
565  if ( !dWriting )
566  {
567  delete this;
568  return;
569  }
570 
571  TQPopupMenu popup;
572  if (!mlst.isEmpty() && (sMoving || (sReading && sDeleting)) && !linkOnly )
573  popup.insertItem(SmallIconSet("goto"), i18n( "&Move Here" ) + "\t" + KKey::modFlagLabel( KKey::SHIFT ), 2 );
574  if ( sReading && !linkOnly)
575  popup.insertItem(SmallIconSet("editcopy"), i18n( "&Copy Here" ) + "\t" + KKey::modFlagLabel( KKey::CTRL ), 1 );
576  popup.insertItem(SmallIconSet("www"), i18n( "&Link Here" ) + "\t" + KKey::modFlagLabel( (KKey::ModFlag)( KKey::CTRL|KKey::SHIFT ) ), 3 );
577  if (bSetWallpaper)
578  popup.insertItem(SmallIconSet("background"), i18n( "Set as &Wallpaper" ), 4 );
579  popup.insertSeparator();
580  popup.insertItem(SmallIconSet("cancel"), i18n( "C&ancel" ) + "\t" + KKey( Qt::Key_Escape ).toString(), 5);
581 
582  int result = popup.exec( m_info->mousePos );
583 
584  switch (result) {
585  case 1 : action = TQDropEvent::Copy; break;
586  case 2 : action = TQDropEvent::Move; break;
587  case 3 : action = TQDropEvent::Link; break;
588  case 4 :
589  {
590  kdDebug(1203) << "setWallpaper iconView=" << iconView << " url=" << lst.first().url() << endl;
591  if (iconView && iconView->isDesktop() ) iconView->setWallpaper(lst.first());
592  delete this;
593  return;
594  }
595  case 5 :
596  default : delete this; return;
597  }
598  }
599 
600  KIO::Job * job = 0;
601  switch ( action ) {
602  case TQDropEvent::Move :
603  job = KIO::move( lst, m_destURL );
604  job->setMetaData( m_info->metaData );
605  setOperation( job, m_method == TRASH ? TRASH : MOVE, lst, m_destURL );
606  (void) new KonqCommandRecorder(
607  m_method == TRASH ? KonqCommand::TRASH : KonqCommand::MOVE,
608  lst, m_destURL, job );
609  return; // we still have stuff to do -> don't delete ourselves
610  case TQDropEvent::Copy :
611  job = KIO::copy( lst, m_destURL );
612  job->setMetaData( m_info->metaData );
613  setOperation( job, COPY, lst, m_destURL );
614  (void) new KonqCommandRecorder( KonqCommand::COPY, lst, m_destURL, job );
615  return;
616  case TQDropEvent::Link :
617  kdDebug(1203) << "KonqOperations::asyncDrop lst.count=" << lst.count() << endl;
618  job = KIO::link( lst, m_destURL );
619  job->setMetaData( m_info->metaData );
620  setOperation( job, LINK, lst, m_destURL );
621  (void) new KonqCommandRecorder( KonqCommand::LINK, lst, m_destURL, job );
622  return;
623  default : kdError(1203) << "Unknown action " << (int)action << endl;
624  }
625  delete this;
626 }
627 
628 void KonqOperations::rename( TQWidget * parent, const KURL & oldurl, const KURL& newurl )
629 {
630  kdDebug(1203) << "KonqOperations::rename oldurl=" << oldurl << " newurl=" << newurl << endl;
631  if ( oldurl == newurl )
632  return;
633 
634  KURL::List lst;
635  lst.append(oldurl);
636  KIO::Job * job = KIO::moveAs( oldurl, newurl, !oldurl.isLocalFile() );
637  KonqOperations * op = new KonqOperations( parent );
638  op->setOperation( job, MOVE, lst, newurl );
639  (void) new KonqCommandRecorder( KonqCommand::MOVE, lst, newurl, job );
640  // if moving the desktop then update config file and emit
641  if ( oldurl.isLocalFile() && oldurl.path(1) == KGlobalSettings::desktopPath() )
642  {
643  kdDebug(1203) << "That rename was the Desktop path, updating config files" << endl;
644  KConfig *globalConfig = KGlobal::config();
645  KConfigGroupSaver cgs( globalConfig, "Paths" );
646  globalConfig->writePathEntry("Desktop" , newurl.path(), true, true );
647  globalConfig->sync();
648  KIPC::sendMessageAll(KIPC::SettingsChanged, KApplication::SETTINGS_PATHS);
649  }
650 }
651 
652 void KonqOperations::setOperation( KIO::Job * job, int method, const KURL::List & /*src*/, const KURL & dest )
653 {
654  m_method = method;
655  //m_srcURLs = src;
656  m_destURL = dest;
657  if ( job )
658  {
659  connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
660  TQT_SLOT( slotResult( KIO::Job * ) ) );
661  KIO::CopyJob *copyJob = tqt_dynamic_cast<KIO::CopyJob*>(job);
662  KonqIconViewWidget *iconView = tqt_dynamic_cast<KonqIconViewWidget*>(parent());
663  if (copyJob && iconView)
664  {
665  connect(copyJob, TQT_SIGNAL(aboutToCreate(KIO::Job *,const TQValueList<KIO::CopyInfo> &)),
666  this, TQT_SLOT(slotAboutToCreate(KIO::Job *,const TQValueList<KIO::CopyInfo> &)));
667  connect(this, TQT_SIGNAL(aboutToCreate(const TQPoint &, const TQValueList<KIO::CopyInfo> &)),
668  iconView, TQT_SLOT(slotAboutToCreate(const TQPoint &, const TQValueList<KIO::CopyInfo> &)));
669  }
670  }
671  else // for link
672  slotResult( 0L );
673 }
674 
675 void KonqOperations::slotAboutToCreate(KIO::Job *, const TQValueList<KIO::CopyInfo> &files)
676 {
677  emit aboutToCreate( m_info ? m_info->mousePos : m_pasteInfo ? m_pasteInfo->mousePos : TQPoint(), files);
678 }
679 
680 void KonqOperations::statURL( const KURL & url, const TQObject *receiver, const char *member )
681 {
682  KonqOperations * op = new KonqOperations( 0L );
683  op->_statURL( url, receiver, member );
684  op->m_method = STAT;
685 }
686 
687 void KonqOperations::_statURL( const KURL & url, const TQObject *receiver, const char *member )
688 {
689  connect( this, TQT_SIGNAL( statFinished( const KFileItem * ) ), receiver, member );
690  KIO::StatJob * job = KIO::stat( url /*, false?*/ );
691  connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
692  TQT_SLOT( slotStatResult( KIO::Job * ) ) );
693 }
694 
695 void KonqOperations::slotStatResult( KIO::Job * job )
696 {
697  if ( job->error())
698  job->showErrorDialog( (TQWidget*)parent() );
699  else
700  {
701  KIO::StatJob * statJob = static_cast<KIO::StatJob*>(job);
702  KFileItem * item = new KFileItem( statJob->statResult(), statJob->url() );
703  emit statFinished( item );
704  delete item;
705  }
706  // If we're only here for a stat, we're done. But not if we used _statURL internally
707  if ( m_method == STAT )
708  delete this;
709 }
710 
711 void KonqOperations::slotResult( KIO::Job * job )
712 {
713  if (job && job->error())
714  job->showErrorDialog( (TQWidget*)parent() );
715  if ( m_method == EMPTYTRASH ) {
716  // Update konq windows opened on trash:/
717  KDirNotify_stub allDirNotify("*", "KDirNotify*");
718  allDirNotify.FilesAdded( "trash:/" ); // yeah, files were removed, but we don't know which ones...
719  }
720  delete this;
721 }
722 
723 void KonqOperations::rename( TQWidget * parent, const KURL & oldurl, const TQString & name )
724 {
725  KURL newurl( oldurl );
726  newurl.setPath( oldurl.directory(false, true) + name );
727  kdDebug(1203) << "KonqOperations::rename("<<name<<") called. newurl=" << newurl << endl;
728  rename( parent, oldurl, newurl );
729 }
730 
731 void KonqOperations::newDir( TQWidget * parent, const KURL & baseURL )
732 {
733  bool ok;
734  TQString name = i18n( "New Folder" );
735  if ( baseURL.isLocalFile() && TQFileInfo( baseURL.path(+1) + name ).exists() )
736  name = KIO::RenameDlg::suggestName( baseURL, i18n( "New Folder" ) );
737 
738  name = KInputDialog::getText ( i18n( "New Folder" ),
739  i18n( "Enter folder name:" ), name, &ok, parent );
740  if ( ok && !name.isEmpty() )
741  {
742  KURL url;
743  if ((name[0] == '/') || (name[0] == '~'))
744  {
745  url.setPath(KShell::tildeExpand(name));
746  }
747  else
748  {
749  name = KIO::encodeFileName( name );
750  url = baseURL;
751  url.addPath( name );
752  }
753  KonqOperations::mkdir( 0L, url );
754  }
755 }
756 
758 
759 KonqMultiRestoreJob::KonqMultiRestoreJob( const KURL::List& urls, bool showProgressInfo )
760  : KIO::Job( showProgressInfo ),
761  m_urls( urls ), m_urlsIterator( m_urls.begin() ),
762  m_progress( 0 )
763 {
764  TQTimer::singleShot(0, this, TQT_SLOT(slotStart()));
765 }
766 
767 void KonqMultiRestoreJob::slotStart()
768 {
769  // Well, it's not a total in bytes, so this would look weird
770  //if ( m_urlsIterator == m_urls.begin() ) // first time: emit total
771  // emit totalSize( m_urls.count() );
772 
773  if ( m_urlsIterator != m_urls.end() )
774  {
775  const KURL& url = *m_urlsIterator;
776 
777  KURL new_url = url;
778  if ( new_url.protocol()=="system"
779  && new_url.path().startsWith("/trash") )
780  {
781  TQString path = new_url.path();
782  path.remove(0, 6);
783  new_url.setProtocol("trash");
784  new_url.setPath(path);
785  }
786 
787  Q_ASSERT( new_url.protocol() == "trash" );
788  TQByteArray packedArgs;
789  TQDataStream stream( packedArgs, IO_WriteOnly );
790  stream << (int)3 << new_url;
791  KIO::Job* job = KIO::special( new_url, packedArgs );
792  addSubjob( job );
793  }
794  else // done!
795  {
796  KDirNotify_stub allDirNotify("*", "KDirNotify*");
797  allDirNotify.FilesRemoved( m_urls );
798  emitResult();
799  }
800 }
801 
802 void KonqMultiRestoreJob::slotResult( KIO::Job *job )
803 {
804  if ( job->error() )
805  {
806  KIO::Job::slotResult( job ); // will set the error and emit result(this)
807  return;
808  }
809  subjobs.remove( job );
810  // Move on to next one
811  ++m_urlsIterator;
812  ++m_progress;
813  //emit processedSize( this, m_progress );
814  emitPercent( m_progress, m_urls.count() );
815  slotStart();
816 }
817 
818 TQWidget* KonqOperations::parentWidget() const
819 {
820  return static_cast<TQWidget *>( parent() );
821 }
822 
823 #include "konq_operations.moc"

libkonq

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

libkonq

Skip menu "libkonq"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for libkonq by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |