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

📄 krviewer.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return;			manager.removePart(pvb->part());		pvb->closeURL();		tabBar.removePage(w);	if( tabBar.count() <= 0 ){		if( returnFocusToThisWidget ){ 			returnFocusToThisWidget->raise();			returnFocusToThisWidget->setActiveWindow();		}		else {			krApp->raise();			krApp->setActiveWindow();		}		delete this;		return;	} else if( tabBar.count() == 1 ){		//no point in detaching only one tab..		viewerMenu->setItemEnabled(detachActionIndex,false);	}	if( returnFocusToThisWidget ){ 		returnFocusToThisWidget->raise();		returnFocusToThisWidget->setActiveWindow();	}}void KrViewer::tabCloseRequest(){	tabCloseRequest( tabBar.currentPage() ); }bool KrViewer::queryClose() {	for( int i=0; i != tabBar.count(); i++ ) {		PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.page( i ) );		if( !pvb )			continue;				tabBar.setCurrentPage( i );				if( !pvb->queryClose() )			return false;	}	return true;}bool KrViewer::queryExit() {	return true; // don't let the reference counter reach zero}void KrViewer::viewGeneric(){	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;	PanelViewerBase* viewerWidget = new PanelViewer(&tabBar);	KParts::Part* part = viewerWidget->openURL(pvb->url(),Generic);	addTab(viewerWidget,i18n("Viewing"),VIEW_ICON,part);}void KrViewer::viewText(){	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;	PanelViewerBase* viewerWidget = new PanelViewer(&tabBar);	KParts::Part* part = viewerWidget->openURL(pvb->url(),Text);	addTab(viewerWidget,i18n("Viewing"),VIEW_ICON,part);}void KrViewer::viewHex(){	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;	PanelViewerBase* viewerWidget = new PanelViewer(&tabBar);	KParts::Part* part = viewerWidget->openURL(pvb->url(),Hex);	addTab(viewerWidget,i18n("Viewing"),VIEW_ICON,part);}void KrViewer::editText(){	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;	PanelViewerBase* editWidget = new PanelEditor(&tabBar);	KParts::Part* part = editWidget->openURL(pvb->url(),Text);	addTab(editWidget,i18n("Editing"),EDIT_ICON,part);}void KrViewer::checkModified(){	QTimer::singleShot( 1000, this, SLOT(checkModified()) );	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;	if( !pvb->part()->url().equals( pvb->url(), true ) ) {		pvb->setUrl( pvb->part()->url() );	}	// add a * to modified files.	if( pvb->isModified() ){		QString label = tabBar.tabLabel(pvb);		if( !label.startsWith("*" + pvb->part()->url().fileName() ) ){			label.prepend("*");			QIconSet icon = QIconSet(krLoader->loadIcon(MODIFIED_ICON,KIcon::Small));			tabBar.changeTab(pvb,icon,label);		}	}	// remove the * from previously modified files.	else {		QString label = tabBar.tabLabel(pvb);		if( label.startsWith("*" + pvb->part()->url().fileName() ) ){			label = label.mid( 1 );			QIconSet icon = QIconSet(krLoader->loadIcon(EDIT_ICON,KIcon::Small));			tabBar.changeTab(pvb,icon,label);		}			}}void KrViewer::nextTab(){	int index = (tabBar.currentPageIndex()+1)%tabBar.count();	tabBar.setCurrentPage( index );}void KrViewer::prevTab(){	int index = (tabBar.currentPageIndex()-1)%tabBar.count();	while( index < 0 ) index+=tabBar.count();	tabBar.setCurrentPage( index );}void KrViewer::detachTab(){	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;	KrViewer* viewer = getViewer(true);	manager.removePart(pvb->part());	tabBar.removePage(pvb);		if( tabBar.count() == 1 ) {		//no point in detaching only one tab..		viewerMenu->setItemEnabled(detachActionIndex,false);	}		pvb->reparent(&viewer->tabBar,QPoint(0,0));	if( pvb->isEditor() )		viewer->addTab(pvb,i18n( "Editing" ),EDIT_ICON,pvb->part());	else		viewer->addTab(pvb,i18n( "Viewing" ),VIEW_ICON,pvb->part());}void KrViewer::windowActivationChange ( bool /* oldActive */ ) {	if( isActiveWindow() )		if( viewers.remove( this ) ) viewers.prepend( this ); // move to first}void KrViewer::print() {	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;		KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( pvb->part() );	if( ext && ext->isActionEnabled( "print" ) )		Invoker( ext, SLOT( print() ) ).invoke();}void KrViewer::copy() {	PanelViewerBase* pvb = static_cast<PanelViewerBase*>( tabBar.currentPage() );	if( !pvb ) return;		KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( pvb->part() );	if( ext && ext->isActionEnabled( "copy" ) )		Invoker( ext, SLOT( copy() ) ).invoke();}PanelViewerBase * KrViewer::getPanelViewerBase( KParts::Part * part ) {	for( int i=0; i != tabBar.count(); i++ ) {		PanelViewerBase *pvb = static_cast<PanelViewerBase*>( tabBar.page( i ) );		if( pvb && pvb->part() == part )			return pvb;	}	return 0;}void KrViewer::updateActions( PanelViewerBase * pvb ) {	if( pvb->isEditor() ) {		printAction->unplugAll();		copyAction->unplugAll();	}	else {		if( !printAction->isPlugged( toolBar() ) )			printAction->plug( toolBar(), 0 );		if( !copyAction->isPlugged( toolBar() ) )			copyAction->plug( toolBar(), 1 );	}}#if 0bool KrViewer::editGeneric( QString mimetype, KURL _url ) {	KParts::ReadWritePart * kedit_part = 0L;	KLibFactory *factory = 0;	KTrader::OfferList offers = KTrader::self() ->query( mimetype );	// in theory, we only care about the first one.. but let's try all	// offers just in case the first can't be loaded for some reason	KTrader::OfferList::Iterator it( offers.begin() );	for ( ; it != offers.end(); ++it ) {		KService::Ptr ptr = ( *it );		// we now know that our offer can handle mimetype and is a part.		// since it is a part, it must also have a library... let's try to		// load that now		factory = KLibLoader::self() ->factory( ptr->library().latin1() );		if ( factory ) {			kedit_part = static_cast<KParts::ReadWritePart *>( factory->create( this,			             ptr->name().latin1(), "KParts::ReadWritePart" ) );			if ( kedit_part )				if ( kedit_part->openURL( _url ) ) break;				else {					delete kedit_part;					kedit_part = 0L;				}		}	}	if ( !kedit_part ) {		KMessageBox::error( this, i18n( "Sorry, can't find internal editor" ) );		return false;	}	setCentralWidget( kedit_part->widget() );	createGUI( kedit_part );	kedit_part->widget() ->show();	return true;}bool KrViewer::editText( bool create ) {	if ( !editor_part ) {		editor_part = static_cast<KParts::ReadWritePart*>( getPart( url, "text/plain", false, create ) );		if ( !editor_part ) return false;		manager.addPart( editor_part, this );	}	manager.setActivePart( editor_part );	tabBar.addTab(editor_part->widget(),url.fileName());	return true;}bool KrViewer::viewGeneric() {	QString mimetype = KMimeType::findByURL( url ) ->name();	// ugly hack: don't try to get a part for an XML file, it usually don't work	if ( mimetype == "text/xml" ) return false;	if ( url.prettyURL().startsWith( "man:" ) ) mimetype = "text/html";	if ( mimetype == "text/plain" )		viewerMenu->setItemEnabled( 1, false );	if ( !generic_part ) {		if ( mimetype.contains( "html" ) ) {			KHTMLPart * p = new KHTMLPart( this, 0, 0, 0, KHTMLPart::BrowserViewGUI );			connect( p->browserExtension(), SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs & ) ),			         this, SLOT( handleOpenURLRequest( const KURL &, const KParts::URLArgs & ) ) );			/* At JavaScript self.close() the KHTMLPart destroys itself.  */			/* After destruction, just close the window */			connect( p, SIGNAL( destroyed() ), this, SLOT( close() ) );			p-> openURL( url );			generic_part = p;		} else {			generic_part = static_cast<KParts::ReadOnlyPart*>( getPart( url, mimetype, true ) );		}		if ( generic_part ) manager.addPart( generic_part, this );				else return false;	}	manager.setActivePart( generic_part );	tabBar.addTab(generic_part->widget(),url.fileName());	return true;}bool KrViewer::viewText() {	if ( !text_part ) {		text_part = static_cast<KParts::ReadOnlyPart*>( getPart( url, "text/plain", true ) );		if ( !text_part ) return false;		manager.addPart( text_part, this );	}	manager.setActivePart( text_part );	tabBar.addTab(text_part->widget(),url.fileName());	return true;}void KrViewer::viewHex() {	if ( !hex_part ) {		QString file;		// files that are not local must first be downloaded		if ( !url.isLocalFile() ) {			if ( !KIO::NetAccess::download( url, file ) ) {				KMessageBox::sorry( this, i18n( "KrViewer is unable to download: " ) + url.url() );				return ;			}		} else file = url.path();		// create a hex file		QFile f_in( file );		f_in.open( IO_ReadOnly );		QDataStream in( &f_in );		FILE *out = KDE_fopen( tmpFile.name().local8Bit(), "w" );		KIO::filesize_t fileSize = f_in.size();		KIO::filesize_t address = 0;		char buf[ 16 ];		unsigned int* pBuff = ( unsigned int* ) buf;		while ( address < fileSize ) {			memset( buf, 0, 16 );			int bufSize = ( ( fileSize - address ) > 16 ) ? 16 : ( fileSize - address );			in.readRawBytes( buf, bufSize );			fprintf( out, "0x%8.8llx: ", address );			for ( int i = 0; i < 4; ++i ) {				if ( i < ( bufSize / 4 ) ) fprintf( out, "%8.8x ", pBuff[ i ] );				else fprintf( out, "         " );			}			fprintf( out, "| " );			for ( int i = 0; i < bufSize; ++i ) {				if ( buf[ i ] > ' ' && buf[ i ] < '~' ) fputc( buf[ i ], out );				else fputc( '.', out );			}			fputc( '\n', out );			address += 16;		}		// clean up		f_in.close();		fclose( out );		if ( !url.isLocalFile() )			KIO::NetAccess::removeTempFile( file );		hex_part = static_cast<KParts::ReadOnlyPart*>( getPart( tmpFile.name(), "text/plain", true ) );		if ( !hex_part ) return ;		manager.addPart( hex_part, this );	}	manager.setActivePart( hex_part );	tabBar.addTab(hex_part->widget(),url.fileName());}#endif#include "krviewer.moc"

⌨️ 快捷键说明

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