bool TrashImpl::move( const TQString& src, const TQString& dest ) { if ( directRename( src, dest ) ) { // This notification is done by TDEIO::moveAs when using the code below // But if we do a direct rename we need to do the notification ourselves KDirNotify_stub allDirNotify( "*", "KDirNotify*" ); KURL urlDest; urlDest.setPath( dest ); urlDest.setPath( urlDest.directory() ); allDirNotify.FilesAdded( urlDest ); return true; } if ( m_lastErrorCode != TDEIO::ERR_UNSUPPORTED_ACTION ) return false; KURL urlSrc, urlDest; urlSrc.setPath( src ); urlDest.setPath( dest ); kdDebug() << k_funcinfo << urlSrc << " -> " << urlDest << endl; TDEIO::CopyJob* job = TDEIO::moveAs( urlSrc, urlDest, false ); #ifdef TDEIO_COPYJOB_HAS_SETINTERACTIVE job->setInteractive( false ); #endif connect( job, TQT_SIGNAL( result(TDEIO::Job *) ), this, TQT_SLOT( jobFinished(TDEIO::Job *) ) ); tqApp->eventLoop()->enterLoop(); return m_lastErrorCode == 0; }
void KonqSidebarTree::addURL(KonqSidebarTreeTopLevelItem* item, const KURL & url) { QString path; if (item) path = item->path(); else path = m_dirtreeDir.dir.path(); KURL destUrl; if (url.isLocalFile() && url.fileName().endsWith(".desktop")) { QString filename = findUniqueFilename(path, url.fileName()); destUrl.setPath(filename); KIO::NetAccess::copy(url, destUrl, this); } else { QString name = url.host(); if (name.isEmpty()) name = url.fileName(); QString filename = findUniqueFilename(path, name); destUrl.setPath(filename); KDesktopFile cfg(filename); cfg.writeEntry("Encoding", "UTF-8"); cfg.writeEntry("Type","Link"); cfg.writeEntry("URL", url.url()); QString icon = "folder"; if (!url.isLocalFile()) icon = KMimeType::favIconForURL(url); if (icon.isEmpty()) icon = KProtocolInfo::icon( url.protocol() ); cfg.writeEntry("Icon", icon); cfg.writeEntry("Name", name); cfg.writeEntry("Open", false); cfg.sync(); } KDirNotify_stub allDirNotify( "*", "KDirNotify*" ); destUrl.setPath( destUrl.directory() ); allDirNotify.FilesAdded( destUrl ); if (item) item->setOpen(true); }
int main(int argc, char *argv[]) { TDEApplication::disableAutoDcopRegistration(); TDECmdLineArgs::init( argc, argv, "ktrash", I18N_NOOP( "ktrash" ), I18N_NOOP( "Helper program to handle the TDE trash can\n" "Note: to move files to the trash, do not use ktrash, but \"kfmclient move 'url' trash:/\"" ), TDE_VERSION_STRING ); TDECmdLineArgs::addCmdLineOptions( options ); TDEApplication app; TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs(); if ( args->isSet( "empty" ) ) { // We use a tdeio job instead of linking to TrashImpl, for a smaller binary // (and the possibility of a central service at some point) TQByteArray packedArgs; TQDataStream stream( packedArgs, IO_WriteOnly ); stream << (int)1; TDEIO::Job* job = TDEIO::special( "trash:/", packedArgs ); (void)TDEIO::NetAccess::synchronousRun( job, 0 ); // Update konq windows opened on trash:/ KDirNotify_stub allDirNotify("*", "KDirNotify*"); allDirNotify.FilesAdded( "trash:/" ); // yeah, files were removed, but we don't know which ones... return 0; } #if 0 // This is only for testing. KDesktop handles it automatically. if ( args->isSet( "migrate" ) ) { TQByteArray packedArgs; TQDataStream stream( packedArgs, IO_WriteOnly ); stream << (int)2; TDEIO::Job* job = TDEIO::special( "trash:/", packedArgs ); (void)TDEIO::NetAccess::synchronousRun( job, 0 ); return 0; } #endif TQCString restoreArg = args->getOption( "restore" ); if ( !restoreArg.isEmpty() ) { if (restoreArg.find("system:/trash")==0) { restoreArg.remove(0, 13); restoreArg.prepend("trash:"); } KURL trashURL( restoreArg ); if ( !trashURL.isValid() || trashURL.protocol() != "trash" ) { kdError() << "Invalid URL for restoring a trashed file:" << trashURL << endl; return 1; } TQByteArray packedArgs; TQDataStream stream( packedArgs, IO_WriteOnly ); stream << (int)3 << trashURL; TDEIO::Job* job = TDEIO::special( trashURL, packedArgs ); bool ok = TDEIO::NetAccess::synchronousRun( job, 0 ); if ( !ok ) kdError() << TDEIO::NetAccess::lastErrorString() << endl; return 0; } return 0; }