⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 panelfunc.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		return ;	}	KrViewer::edit( files() ->vfs_getFile( name ) );}void ListPanelFunc::moveFiles() {	PreserveMode pmode = PM_DEFAULT;	QStringList fileNames;	panel->getSelectedNames( &fileNames );	if ( fileNames.isEmpty() )		return ;  // safety	KURL dest = panel->otherPanel->virtualPath();	KURL virtualBaseURL;	QString destProtocol = dest.protocol();	if ( destProtocol == "krarc" || destProtocol == "tar" || destProtocol == "zip" ) {		KMessageBox::sorry( krApp, i18n( "Moving into archive is disabled" ) );		return ;	}	krConfig->setGroup( "Advanced" );	if ( krConfig->readBoolEntry( "Confirm Move", _ConfirmMove ) ) {		bool preserveAttrs = krConfig->readBoolEntry( "PreserveAttributes", _PreserveAttributes );		QString s;  if( fileNames.count() == 1 )    s = i18n("Move %1 to:").arg(fileNames.first());  else    s = i18n("Move %n file to:", "Move %n files to:", fileNames.count());		// ask the user for the copy dest		virtualBaseURL = getVirtualBaseURL();		dest = KChooseDir::getDir(s, dest, panel->virtualPath(), preserveAttrs, virtualBaseURL);		if ( dest.isEmpty() ) return ; // the user canceled		if( preserveAttrs )			pmode = PM_PRESERVE_ATTR;		else			pmode = PM_NONE;	}	if ( fileNames.isEmpty() )		return ; // nothing to copy	KURL::List* fileUrls = files() ->vfs_getFiles( &fileNames );	// after the delete return the cursor to the first unmarked	// file above the current item;	panel->prepareToDelete();	if( !virtualBaseURL.isEmpty() ) {		// keep the directory structure for virtual paths		VirtualCopyJob *vjob = new VirtualCopyJob( &fileNames, files(), dest, virtualBaseURL, pmode, KIO::CopyJob::Move, false, true );		connect( vjob, SIGNAL( result( KIO::Job* ) ), this, SLOT( refresh() ) );		if ( dest.equals( panel->otherPanel->virtualPath(), true ) )			connect( vjob, SIGNAL( result( KIO::Job* ) ), panel->otherPanel->func, SLOT( refresh() ) );	}	// if we are not moving to the other panel :	else if ( !dest.equals( panel->otherPanel->virtualPath(), true ) ) {		// you can rename only *one* file not a batch,		// so a batch dest must alwayes be a directory		if ( fileNames.count() > 1 ) dest.adjustPath(1);		KIO::Job* job = PreservingCopyJob::createCopyJob( pmode, *fileUrls, dest, KIO::CopyJob::Move, false, true );		job->setAutoErrorHandlingEnabled( true );		// refresh our panel when done		connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( refresh() ) );		// and if needed the other panel as well		if ( dest.equals( panel->otherPanel->virtualPath(), true ) )			connect( job, SIGNAL( result( KIO::Job* ) ), panel->otherPanel->func, SLOT( refresh() ) );	} else { // let the other panel do the dirty job		//check if copy is supported		if ( !otherFunc() ->files() ->vfs_isWritable() ) {			KMessageBox::sorry( krApp, i18n( "You can't move files to this file system" ) );			return ;		}		// finally..		otherFunc() ->files() ->vfs_addFiles( fileUrls, KIO::CopyJob::Move, files(), "", pmode );	}}// called from SLOTS to begin the renaming processvoid ListPanelFunc::rename() {	panel->view->renameCurrentItem();}// called by signal itemRenamed() from the view to complete the renaming processvoid ListPanelFunc::rename( const QString &oldname, const QString &newname ) {	if ( oldname == newname )		return ; // do nothing	panel->view->setNameToMakeCurrentIfAdded( newname );	// as always - the vfs do the job	files() ->vfs_rename( oldname, newname );}void ListPanelFunc::mkdir() {	// ask the new dir name..	bool ok = false;	QString dirName =	    KInputDialog::getText( i18n( "New directory" ), i18n( "Directory's name:" ), "", &ok, krApp );	// if the user canceled - quit	if ( !ok || dirName.isEmpty() )		return ;	QStringList dirTree = QStringList::split( "/", dirName );	for ( QStringList::Iterator it = dirTree.begin(); it != dirTree.end(); ++it ) {		// check if the name is already taken		if ( files() ->vfs_search( *it ) ) {			// if it is the last dir to be created - quit			if ( *it == dirTree.last() ) {				KMessageBox::sorry( krApp, i18n( "A directory or a file with this name already exists." ) );				return ;			}			// else go into this dir			else {				immediateOpenUrl( *it );				continue;			}		}		panel->view->setNameToMakeCurrent( *it );		// as always - the vfs do the job		files() ->vfs_mkdir( *it );		if ( dirTree.count() > 1 )			immediateOpenUrl( *it );	} // for}KURL ListPanelFunc::getVirtualBaseURL() {	if( files()->vfs_getType() != vfs::VIRT || otherFunc()->files()->vfs_getType() == vfs::VIRT )		return KURL();		QStringList fileNames;	panel->getSelectedNames( &fileNames );		KURL::List* fileUrls = files() ->vfs_getFiles( &fileNames );	if( fileUrls->count() == 0 )		return KURL();		KURL base = (*fileUrls)[ 0 ].upURL();		if( base.protocol() == "virt" ) // is it a virtual subfolder?		return KURL();          // --> cannot keep the directory structure		for( unsigned i=1; i < fileUrls->count(); i++ ) {		if( base.isParentOf( (*fileUrls)[ i ] ) )			continue;		if( base.protocol() != (*fileUrls)[ i ].protocol() )			return KURL();				do {			KURL oldBase = base;			base = base.upURL();			if( oldBase.equals( base, true ) )				return KURL();			if( base.isParentOf( (*fileUrls)[ i ] ) )				break;		}while( true );	}	return base;}void ListPanelFunc::copyFiles() {	PreserveMode pmode = PM_DEFAULT;	QStringList fileNames;	panel->getSelectedNames( &fileNames );	if ( fileNames.isEmpty() )		return ;  // safety	KURL dest = panel->otherPanel->virtualPath();	KURL virtualBaseURL;	// confirm copy	krConfig->setGroup( "Advanced" );	if ( krConfig->readBoolEntry( "Confirm Copy", _ConfirmCopy ) ) {		bool preserveAttrs = krConfig->readBoolEntry( "PreserveAttributes", _PreserveAttributes );		QString s;  if( fileNames.count() == 1 )    s = i18n("Copy %1 to:").arg(fileNames.first());  else    s = i18n("Copy %n file to:", "Copy %n files to:", fileNames.count());		// ask the user for the copy dest		virtualBaseURL = getVirtualBaseURL();		dest = KChooseDir::getDir(s, dest, panel->virtualPath(), preserveAttrs, virtualBaseURL );		if ( dest.isEmpty() ) return ; // the user canceled		if( preserveAttrs )			pmode = PM_PRESERVE_ATTR;		else			pmode = PM_NONE;	}	KURL::List* fileUrls = files() ->vfs_getFiles( &fileNames );	if( !virtualBaseURL.isEmpty() ) {		// keep the directory structure for virtual paths		VirtualCopyJob *vjob = new VirtualCopyJob( &fileNames, files(), dest, virtualBaseURL, pmode, KIO::CopyJob::Copy, false, true );		connect( vjob, SIGNAL( result( KIO::Job* ) ), this, SLOT( refresh() ) );		if ( dest.equals( panel->otherPanel->virtualPath(), true ) )			connect( vjob, SIGNAL( result( KIO::Job* ) ), panel->otherPanel->func, SLOT( refresh() ) );	}	// if we are  not copying to the other panel :	else if ( !dest.equals( panel->otherPanel->virtualPath(), true ) ) {		// you can rename only *one* file not a batch,		// so a batch dest must alwayes be a directory		if ( fileNames.count() > 1 ) dest.adjustPath(1);		KIO::Job* job = PreservingCopyJob::createCopyJob( pmode, *fileUrls, dest, KIO::CopyJob::Copy, false, true );		job->setAutoErrorHandlingEnabled( true );		if ( dest.equals( panel->virtualPath(), true ) ||			dest.upURL().equals( panel->virtualPath(), true ) )			// refresh our panel when done			connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( refresh() ) );	// let the other panel do the dirty job	} else {		//check if copy is supported		if ( !otherFunc() ->files() ->vfs_isWritable() ) {			KMessageBox::sorry( krApp, i18n( "You can't copy files to this file system" ) );			return ;		}		// finally..		otherFunc() ->files() ->vfs_addFiles( fileUrls, KIO::CopyJob::Copy, 0, "", pmode );	}}void ListPanelFunc::deleteFiles(bool reallyDelete) {	// check that the you have write perm	if ( !files() ->vfs_isWritable() ) {		KMessageBox::sorry( krApp, i18n( "You do not have write permission to this directory" ) );		return ;	}	// first get the selected file names list	QStringList fileNames;	panel->getSelectedNames( &fileNames );	if ( fileNames.isEmpty() )		return ;	krConfig->setGroup( "General" );	bool trash = krConfig->readBoolEntry( "Move To Trash", _MoveToTrash );	// now ask the user if he want to delete:	krConfig->setGroup( "Advanced" );	if ( krConfig->readBoolEntry( "Confirm Delete", _ConfirmDelete ) ) {		QString s, b;		if ( !reallyDelete && trash && files() ->vfs_getType() == vfs::NORMAL ) {			s = i18n( "Do you really want to move this item to the trash?", "Do you really want to move these %n items to the trash?", fileNames.count() );			b = i18n( "&Trash" );		} else if( files() ->vfs_getType() == vfs::VIRT && files()->vfs_getOrigin().equals( KURL("virt:/"), true ) ) {			s = i18n( "Do you really want to delete this virtual item (physical files stay untouched)?", "Do you really want to delete these virtual items (physical files stay untouched)?", fileNames.count() );			b = i18n( "&Delete" );		} else if( files() ->vfs_getType() == vfs::VIRT ) {			s = i18n( "<qt>Do you really want to delete this item <b>physically</b> (not just removing it from the virtual items)?</qt>", "<qt>Do you really want to delete these %n items <b>physically</b> (not just removing them from the virtual items)?</qt>", fileNames.count() );			b = i18n( "&Delete" );		} else {			s = i18n( "Do you really want to delete this item?", "Do you really want to delete these %n items?", fileNames.count() );			b = i18n( "&Delete" );		}		// show message		// note: i'm using continue and not yes/no because the yes/no has cancel as default button		if ( KMessageBox::warningContinueCancelList( krApp, s, fileNames,                                                     i18n( "Warning" ), b ) != KMessageBox::Continue )			return ;	}	//we want to warn the user about non empty dir	// and files he don't have permission to delete	krConfig->setGroup( "Advanced" );	bool emptyDirVerify = krConfig->readBoolEntry( "Confirm Unempty Dir", _ConfirmUnemptyDir );	emptyDirVerify = ( ( emptyDirVerify ) && ( files() ->vfs_getType() == vfs::NORMAL ) );	QDir dir;	for ( QStringList::Iterator name = fileNames.begin(); name != fileNames.end(); ) {		vfile * vf = files() ->vfs_search( *name );		// verify non-empty dirs delete... (only for normal vfs)		if ( emptyDirVerify && vf->vfile_isDir() && !vf->vfile_isSymLink() ) {			dir.setPath( panel->virtualPath().path() + "/" + ( *name ) );			if ( dir.entryList(QDir::All | QDir::System | QDir::Hidden ).count() > 2 ) {				switch ( KMessageBox::warningYesNoCancel( krApp,																		i18n( "<qt><p>Directory <b>%1</b> is not empty!</p><p>Skip this one or Delete All?</p></qt>" ).arg(*name),																		QString::null, i18n( "&Skip" ), i18n( "&Delete All" ) ) ) {						case KMessageBox::Cancel :						return ;						case KMessageBox::No :						emptyDirVerify = false;						break;						case KMessageBox::Yes :						name = fileNames.remove( name );						continue;				}			}		}		++name;	}	if ( fileNames.count() == 0 )		return ;  // nothing to delete	// after the delete return the cursor to the first unmarked	// file above the current item;	panel->prepareToDelete();	// let the vfs do the job...	if (reallyDelete) {		// if reallyDelete, then make sure nothing gets moved to trash		krConfig->setGroup("General");		krConfig->writeEntry( "Move To Trash", false );	}	files() ->vfs_delFiles( &fileNames );	if (reallyDelete) {		krConfig->setGroup("General");		krConfig->writeEntry( "Move To Trash", trash);	}}// this is done when you double click on a filevoid ListPanelFunc::execute( QString& name ) {	if ( name == ".." ) {		dirUp();		return ;	}	vfile *vf = files() ->vfs_search( name );	if ( vf == 0 )		return ;		KURL origin = files() ->vfs_getOrigin();	QString protocol = origin.isLocalFile() ? KrServices::registerdProtocol( vf->vfile_getMime() ) : "";	if ( protocol == "tar" || protocol == "krarc" ) {		bool encrypted;		QString type = KRarcHandler::getType( encrypted, vf->vfile_getUrl().path(), vf->vfile_getMime(), false );		if ( !KRarcHandler::arcHandled( type ) )   // if the specified archive is disabled delete the protocol			protocol = "";	}	if ( vf->vfile_isDir() ) {		origin = files() ->vfs_getFile( name );		panel->view->setNameToMakeCurrent( QString::null );		openUrl( origin );	} else if ( !protocol.isEmpty() ) {		KURL path = files() ->vfs_getFile( vf->vfile_getName() );		path.setProtocol( protocol );		openUrl( path );	} else {		KURL url = files() ->vfs_getFile( name );		KFileItem kfi( vf->vfile_getEntry(), url,true );		kfi.run();		}}void ListPanelFunc::dirUp() {	openUrl( files() ->vfs_getOrigin().upURL(), files() ->vfs_getOrigin().fileName() );}void ListPanelFunc::pack() {	QStringList fileNames;	panel->getSelectedNames( &fileNames );	if ( fileNames.isEmpty() )		return ;  // safety	if ( fileNames.count() == 0 )		return ; // nothing to pack	// choose the default name	QString defaultName = panel->virtualPath().fileName();	if ( defaultName == "" )		defaultName = "pack";	if ( fileNames.count() == 1 )		defaultName = fileNames.first();	// ask the user for archive name and packer	new PackGUI( defaultName, vfs::pathOrURL( panel->otherPanel->virtualPath(), -1 ), fileNames.count(), fileNames.first() );	if ( PackGUI::type == QString::null )		return ; // the user canceled	// check for partial URLs		if( !PackGUI::destination.contains(":/") && !PackGUI::destination.startsWith("/") ){		PackGUI::destination = panel->virtualPath().prettyURL()+"/"+PackGUI::destination;	}		QString destDir = PackGUI::destination;	if( !destDir.endsWith( "/" ) )		destDir += "/";		bool packToOtherPanel = ( destDir == panel->otherPanel->virtualPath().prettyURL(1) );	// on remote URL-s first pack into a temp file then copy to its right place	KURL destURL = vfs::fromPathOrURL( destDir + PackGUI::filename + "." + PackGUI::type );	KTempFile *tempDestFile = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -