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

libkonq

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

libkonq

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

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.9.4
This website is maintained by Timothy Pearson.