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

📄 panelfunc.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	QString arcFile;	if ( destURL.isLocalFile() )		arcFile = destURL.path();	else if( destURL.protocol() == "virt" ) {		KMessageBox::error( krApp, i18n( "Cannot pack files onto a virtual destination!" ) );		return;                	}        	else {		tempDestFile = new KTempFile( QString::null, "." + PackGUI::type );		tempDestFile->setAutoDelete( true );		arcFile = tempDestFile->name();		QFile::remove			( arcFile );	}	if (  QFileInfo( arcFile ).exists() ) {		QString msg = i18n( "<qt><p>The archive <b>%1.%2</b> already exists. Do you want to overwrite it?</p><p>All data in the previous archive will be lost!</p></qt>").arg(PackGUI::filename).arg(PackGUI::type);		if( PackGUI::type == "zip" ) {			msg = i18n( "<qt><p>The archive <b>%1.%2</b> already exists. Do you want to overwrite it?</p><p>Zip will replace identically named entries in the zip archive or add entries for new names.</p></qt>").arg(PackGUI::filename).arg(PackGUI::type);		}		if ( KMessageBox::warningContinueCancel( krApp,msg,QString::null,i18n( "&Overwrite" ))		        == KMessageBox::Cancel )			return ; // stop operation	}	// tell the user to wait	krApp->startWaiting( i18n( "Counting files to pack" ), 0, true );	// get the files to be packed:	files() ->vfs_getFiles( &fileNames );	KIO::filesize_t totalSize = 0;	unsigned long totalDirs = 0, totalFiles = 0;	if( !calcSpace( fileNames, totalSize, totalFiles, totalDirs ) )		return;	// download remote URL-s if necessary	QString arcDir;	KTempDir *tempDir = 0;	if ( files() ->vfs_getOrigin().isLocalFile() )		arcDir = files() ->vfs_workingDir();	else {		tempDir = new KTempDir();		tempDir->setAutoDelete( true );		arcDir = tempDir->name();		KURL::List *urlList = files() ->vfs_getFiles( &fileNames );		KIO::NetAccess::dircopy( *urlList, vfs::fromPathOrURL( arcDir ), 0 );		delete urlList;	}	// pack the files	// we must chdir() first because we supply *names* not URL's	QString save = getcwd( 0, 0 );	chdir( arcDir.local8Bit() );	KRarcHandler::pack( fileNames, PackGUI::type, arcFile, totalFiles + totalDirs, PackGUI::extraProps );	chdir( save.local8Bit() );	// delete the temporary directory if created	if ( tempDir )		delete tempDir;	// copy from the temp file to it's right place	if ( tempDestFile ) {		KIO::NetAccess::file_move( vfs::fromPathOrURL( arcFile ), destURL );		delete tempDestFile;	}	if ( packToOtherPanel )		panel->otherPanel->func->refresh();}void ListPanelFunc::testArchive() {	QString arcName = panel->getCurrentName();	if ( arcName.isNull() )		return ;	if ( arcName == ".." )		return ; // safety	KURL arcURL = files() ->vfs_getFile( arcName );	QString url = QString::null;	// download the file if it's on a remote filesystem	if ( !arcURL.isLocalFile() ) {		url = locateLocal( "tmp", QString( arcName ) );		if ( !KIO::NetAccess::download( arcURL, url, 0 ) ) {			KMessageBox::sorry( krApp, i18n( "Krusader is unable to download: " ) + arcURL.fileName() );			return ;		}	} else		url = arcURL.path( -1 );	QString mime = files() ->vfs_search( arcName ) ->vfile_getMime();	bool encrypted = false;	QString type = KRarcHandler::getType( encrypted, url, mime );		// check we that archive is supported	if ( !KRarcHandler::arcSupported( type ) ) {		KMessageBox::sorry( krApp, i18n( "%1, unknown archive type." ).arg( arcName ) );		return ;	}		QString password = encrypted ? KRarcHandler::getPassword( url ) : QString::null;		// test the archive	if ( KRarcHandler::test( url, type, password ) )		KMessageBox::information( krApp, i18n( "%1, test passed." ).arg( arcName ) );	else		KMessageBox::error( krApp, i18n( "%1, test failed!" ).arg( arcName ) );	// remove the downloaded file if necessary	if ( url != arcURL.path( -1 ) )		QFile( url ).remove();}void ListPanelFunc::unpack() {	QStringList fileNames;	panel->getSelectedNames( &fileNames );	if ( fileNames.isEmpty() )		return ;  // safety	QString s;  if(fileNames.count() == 1)    s = i18n("Unpack %1 to:").arg(fileNames[0]);  else    s = i18n("Unpack %n file to:", "Unpack %n files to:", fileNames.count());	// ask the user for the copy dest	KURL dest = KChooseDir::getDir(s, panel->otherPanel->virtualPath(), panel->virtualPath());	if ( dest.isEmpty() ) return ; // the user canceled	bool packToOtherPanel = ( dest.equals( panel->otherPanel->virtualPath(), true ) );	for ( unsigned int i = 0; i < fileNames.count(); ++i ) {		QString arcName = fileNames[ i ];		if ( arcName.isNull() )			return ;		if ( arcName == ".." )			return ; // safety		// download the file if it's on a remote filesystem		KURL arcURL = files() ->vfs_getFile( arcName );		QString url = QString::null;		if ( !arcURL.isLocalFile() ) {			url = locateLocal( "tmp", QString( arcName ) );			if ( !KIO::NetAccess::download( arcURL, url, 0 ) ) {				KMessageBox::sorry( krApp, i18n( "Krusader is unable to download: " ) + arcURL.fileName() );				continue;			}		} else			url = arcURL.path( -1 );		// if the destination is in remote directory use temporary one instead		dest.adjustPath(1);		KURL originalDestURL;		KTempDir *tempDir = 0;		if ( !dest.isLocalFile() ) {			originalDestURL = dest;			tempDir = new KTempDir();			tempDir->setAutoDelete( true );			dest = tempDir->name();		}		// determining the type		QString mime = files() ->vfs_search( arcName ) ->vfile_getMime();		bool encrypted = false;		QString type = KRarcHandler::getType( encrypted, url, mime );		// check we that archive is supported		if ( !KRarcHandler::arcSupported( type ) ) {			KMessageBox::sorry( krApp, i18n( "%1, unknown archive type" ).arg( arcName ) );			continue;		}				QString password = encrypted ? KRarcHandler::getPassword( url ) : QString::null;				// unpack the files		KRarcHandler::unpack( url, type, password, dest.path( -1 ) );		// remove the downloaded file if necessary		if ( url != arcURL.path( -1 ) )			QFile( url ).remove();		// copy files to the destination directory at remote files		if ( tempDir ) {			QStringList nameList = QDir( dest.path( -1 ) ).entryList();			KURL::List urlList;			for ( unsigned int i = 0; i != nameList.count(); i++ )				if ( nameList[ i ] != "." && nameList[ i ] != ".." )					urlList.append( vfs::fromPathOrURL( dest.path( 1 ) + nameList[ i ] ) );			if ( urlList.count() > 0 )				KIO::NetAccess::dircopy( urlList, originalDestURL, 0 );			delete tempDir;		}	}	if ( packToOtherPanel )		panel->otherPanel->func->refresh();}// a small ugly function, used to prevent duplication of EVERY line of// code (maybe except 3) from createChecksum and matchChecksumstatic void checksum_wrapper(ListPanel *panel, QStringList& args, bool &folders) {	KrViewItemList items;	panel->view->getSelectedKrViewItems( &items );	if ( items.isEmpty() ) return ; // nothing to do	// determine if we need recursive mode (md5deep)	folders=false;	for ( KrViewItemList::Iterator it = items.begin(); it != items.end(); ++it ) {		if (panel->func->getVFile(*it)->vfile_isDir()) {			folders = true;			args << (*it)->name();		} else args << (*it)->name();	}}void ListPanelFunc::createChecksum() {	QStringList args;	bool folders;	checksum_wrapper(panel, args, folders);	CreateChecksumDlg dlg(args, folders, panel->realPath());}void ListPanelFunc::matchChecksum() {	QStringList args;	bool folders;	checksum_wrapper(panel, args, folders);	QValueList<vfile*> checksumFiles = files()->vfs_search(		KRQuery(MatchChecksumDlg::checksumTypesFilter)	);	MatchChecksumDlg dlg(args, folders, panel->realPath(), 		(checksumFiles.size()==1 ? checksumFiles[0]->vfile_getUrl().prettyURL() : QString::null));}void ListPanelFunc::calcSpace() {	QStringList items;	panel->view->getSelectedItems( &items );	if ( items.isEmpty() ) {		panel->view->selectAllIncludingDirs();		panel->view->getSelectedItems( &items );		if ( items.isEmpty() )			return ; // nothing to do	}	KrCalcSpaceDialog calc( krApp, panel, items, false );	calc.exec();	for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it ) {		KrViewItem *viewItem = panel->view->findItemByName( *it );		if ( viewItem )			panel->view->updateItem(viewItem);	}	panel->slotUpdateTotals();}bool ListPanelFunc::calcSpace( const QStringList & items, KIO::filesize_t & totalSize, unsigned long & totalFiles, unsigned long & totalDirs ) {	KrCalcSpaceDialog calc( krApp, panel, items, true );	calc.exec();	totalSize = calc.getTotalSize();	totalFiles = calc.getTotalFiles();	totalDirs = calc.getTotalDirs();	return !calc.wasCanceled();}void ListPanelFunc::FTPDisconnect() {	// you can disconnect only if connected !	if ( files() ->vfs_getType() == vfs::FTP ) {		krFTPDiss->setEnabled( false );		panel->view->setNameToMakeCurrent( QString::null );		openUrl( panel->realPath() ); // open the last local URL	}}void ListPanelFunc::newFTPconnection() {	KURL url = KRSpWidgets::newFTP();	// if the user canceled - quit	if ( url.isEmpty() )		return ;	krFTPDiss->setEnabled( true );	openUrl( url );}void ListPanelFunc::properties() {	QStringList names;	panel->getSelectedNames( &names );	if ( names.isEmpty() )		return ;  // no names...	KFileItemList fi;	fi.setAutoDelete( true );	for ( unsigned int i = 0 ; i < names.count() ; ++i ) {		vfile* vf = files() ->vfs_search( names[ i ] );		if ( !vf )			continue;		KURL url = files()->vfs_getFile( names[i] );		fi.append( new KFileItem( vf->vfile_getEntry(), url ) );	}	if ( fi.isEmpty() )		return ;	// Show the properties dialog	KPropertiesDialog *dlg = new KPropertiesDialog( fi );	connect( dlg, SIGNAL( applied() ), SLOTS, SLOT( refresh() ) );}void ListPanelFunc::refreshActions() {	vfs::VFS_TYPE vfsType = files() ->vfs_getType();	//  set up actions	krMultiRename->setEnabled( vfsType == vfs::NORMAL );  // batch rename	//krProperties ->setEnabled( vfsType == vfs::NORMAL || vfsType == vfs::FTP ); // file properties	krFTPDiss ->setEnabled( vfsType == vfs::FTP );     // disconnect an FTP session	krCreateCS->setEnabled( vfsType == vfs::NORMAL );	/*	  krUnpack->setEnabled(true);                            // unpack archive	  krTest->setEnabled(true);                              // test archive	  krSelect->setEnabled(true);                            // select a group by filter	  krSelectAll->setEnabled(true);                         // select all files	  krUnselect->setEnabled(true);                          // unselect by filter	  krUnselectAll->setEnabled( true);                      // remove all selections	  krInvert->setEnabled(true);                            // invert the selection	  krFTPConnect->setEnabled(true);                        // connect to an ftp	  krFTPNew->setEnabled(true);                            // create a new connection	  krAllFiles->setEnabled(true);                          // show all files in list	  krCustomFiles->setEnabled(true);                       // show a custom set of files	  krBack->setEnabled(func->canGoBack());                 // go back	  krRoot->setEnabled(true);                              // go all the way up	      krExecFiles->setEnabled(true);                         // show only executables	*/}ListPanelFunc::~ListPanelFunc() {	if( !vfsP ) {		if( vfsP->vfs_canDelete() )			delete vfsP;		else {			connect( vfsP, SIGNAL( deleteAllowed() ), vfsP, SLOT( deleteLater() ) );			vfsP->vfs_requestDelete();		}	}	vfsP = 0;}vfs* ListPanelFunc::files() {	if ( !vfsP )		vfsP = KrVfsHandler::getVfs( "/", panel, 0 );	return vfsP;}void ListPanelFunc::copyToClipboard( bool move ) {	if( files()->vfs_getOrigin().equals( KURL("virt:/"), true ) ) {		if( move )			KMessageBox::error( krApp, i18n( "Cannot cut a virtual URL collection to the clipboard!" ) );		else			KMessageBox::error( krApp, i18n( "Cannot copy a virtual URL collection onto the clipboard!" ) );		return;	}		QStringList fileNames;	panel->getSelectedNames( &fileNames );	if ( fileNames.isEmpty() )		return ;  // safety	KURL::List* fileUrls = files() ->vfs_getFiles( &fileNames );	if ( fileUrls ) {		KRDrag * urlData = KRDrag::newDrag( *fileUrls, move, krApp->mainView, "krusader" );		QApplication::clipboard() ->setData( urlData );				if( move && files()->vfs_getType() == vfs::VIRT )			( static_cast<virt_vfs*>( files() ) )->vfs_removeFiles( &fileNames );				delete fileUrls;	}}void ListPanelFunc::pasteFromClipboard() {	QClipboard * cb = QApplication::clipboard();	QMimeSource * data = cb->data();	KURL::List urls;	if ( KURLDrag::canDecode( data ) ) {		KURLDrag::decode( data, urls );		bool cutSelection = KRDrag::decodeIsCutSelection( data );		KURL destUrl = panel->virtualPath();		files()->vfs_addFiles( &urls, cutSelection ? KIO::CopyJob::Move : KIO::CopyJob::Copy, otherFunc()->files(),			"", PM_DEFAULT );	}}#include "panelfunc.moc"

⌨️ 快捷键说明

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