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

📄 hand_book.cpp

📁 Linux平台下的内核及程序调试器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* --------------------------------------------------------------------- * Implementation of HandBook                              hand_book.cpp * Context-sensitive help browser * ---------------------------------------------------------------------  * This file is part of Valkyrie, a front-end for Valgrind * Copyright (c) 2000-2006, OpenWorks LLP <info@open-works.co.uk> * This program is released under the terms of the GNU GPL v.2 * See the file LICENSE.GPL for the full license details. */#include "hand_book.h"#include "tb_handbook_icons.h"#include "vk_config.h"#include "vk_messages.h"#include "vk_utils.h"#include <qcursor.h>#include <qfiledialog.h>#include <qmenubar.h>#include <qpaintdevicemetrics.h>#include <qpainter.h>#include <qprinter.h>#include <qprocess.h>#include <qstatusbar.h>#include <qsimplerichtext.h>#include <qtoolbutton.h>#include <stdlib.h>           // getenv/* class VkTextBrowser ---------------------------------------------- *//* Only used in order to catch 'linkClicked' signal and open a browser   for external links. */VkTextBrowser::VkTextBrowser ( QWidget* parent, const char* name )   : QTextBrowser( parent, name ){   connect( this, SIGNAL(linkClicked(const QString&)),            this, SLOT(doLinkClicked(const QString&)) );}void VkTextBrowser::doLinkClicked ( const QString& link ){   //vkPrint("link: '%s'", link.latin1());   if (link.startsWith("http://")) {      /* just reload same page */      reload();      /* try to launch a browser */      if ( !launch_browser( link ) ) {         vkPrintErr("Error: failed to startup a browser.");         vkError( this, "Browser Startup",                  "<p>Failed to startup a browser.<br> \                   Please set a browser in Options::Valkyrie::Browser</p>" );      }         } else if (link.startsWith("mailto:")) {      reload();   /* just reload same page */      /* try to launch a mail client */      // TODO   }}bool VkTextBrowser::try_launch_browser(QString browser, const QString& link){   browser = browser.simplifyWhiteSpace();   QStringList args;   if (browser.find("%s") != -1) {      /* As per http://www.catb.org/~esr/BROWSER/ */      browser = browser.replace("%s", link);      browser = browser.replace("%%", "%");      /* TODO: this is necessary, but rather inadequate...         - what's the general solution? */      browser = browser.replace("\"", "");      args = QStringList::split(" ", browser );   } else {      args << browser << link;   }//   vkPrint(" args: '%s'\n", args.join(" |").latin1());   QProcess proc( args );   return proc.start();}bool VkTextBrowser::launch_browser(const QString& link){   bool ok = false;   QApplication::setOverrideCursor(Qt::BusyCursor);      /* try config::vk::browser */   QString rc_browser = vkConfig->rdEntry( "browser", "valkyrie" );   if (!rc_browser.isEmpty()) {      ok = try_launch_browser(rc_browser, link);      if (!ok) {         vkPrintErr("Error: Failed to launch browser '%s'",                    rc_browser.latin1());         vkPrintErr(" - trying other browsers.");         vkError( this, "Browser Startup",                  "<p>Failed to startup configured default browser '%s'.<br> \                   Please verify Options::Valkyrie::Browser.<br><br> \                   Going on to try other browsers... </p>",                  rc_browser.latin1() );      }   }   /* either no config val set, or it failed...      try env var $BROWSER */   if (!ok) {      QString env_browser = getenv("BROWSER");      if (!env_browser.isEmpty()) {         QStringList browsers = QStringList::split( ':', env_browser );         QStringList::iterator it;         for (it=browsers.begin(); it != browsers.end(); ++it ) {            if (ok = try_launch_browser(*it, link))               break;         }         if (!ok) {            vkPrintErr("Error: Failed to launch any browser in env var $BROWSER '%s'",                       env_browser.latin1());            vkPrintErr(" - trying other browsers.");         }      }   }   /* still nogo?      last resort: try preset list */   if (!ok) {      QStringList browsers;      browsers << "firefox" << "mozilla" << "konqueror" << "netscape";      QStringList::iterator it;      for (it=browsers.begin(); it != browsers.end(); ++it ) {         if (ok = try_launch_browser(*it, link))            break;      }   }   QApplication::restoreOverrideCursor();   return ok;} /* overloaded to reload _with_ #mark */void VkTextBrowser::reload(){ setSource( source() ); }/* class HandBook --------------------------------------------------- */HandBook::~HandBook(){   /* save history + bookmarks */   save();}HandBook::HandBook( QWidget* parent, const char* name )   : QMainWindow( parent, name, WDestructiveClose ){   caption.sprintf( "%s HandBook", vkConfig->vkName() );   setCaption( caption );   setIcon( QPixmap(help_xpm) );   setRightJustification( true );   setDockEnabled( DockLeft, false );   setDockEnabled( DockRight, false );   browser = new VkTextBrowser( this );   setCentralWidget( browser );   mkMenuToolBars();   browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );   browser->setTextFormat( Qt::RichText );   browser->setLinkUnderline( true );   /* set the list of dirs to search when files are requested */   QStringList paths;   paths << vkConfig->vkdocDir();   browser->mimeSourceFactory()->setFilePath( paths );   connect( browser, SIGNAL( sourceChanged(const QString&) ),            this,    SLOT( sourceChanged(const QString&) ) );   connect( browser,     SIGNAL( highlighted( const QString&) ),            statusBar(), SLOT( message( const QString&)) );   /* default startup is with the index page loaded */   QString home = vkConfig->vkdocDir() + "index.html";   browser->setSource( home );   resize( 500, 600 );   hide();}void HandBook::setBackwardAvailable( bool b){ mainMenu->setItemEnabled( BACKWARD, b ); }void HandBook::setForwardAvailable( bool b){ mainMenu->setItemEnabled( FORWARD, b ); }void HandBook::historyChosen( int i ){   if ( !mapHistory.contains(i) )      return;   browser->setSource( mapHistory[i] );}void HandBook::bookmarkChosen( int i ){   if ( !mapBookmarks.contains(i) )      return;   QString url = mapBookmarks[i];   int len = url.length() - 1;   int pos = url.find('[', 0, false ) + 1;   url = url.mid( pos, len-pos );   browser->setSource( url );}void HandBook::addBookmark(){    /* eg. /home/.../.../.../manual/licenses.html */   QString url   = browser->context();   QString title = browser->documentTitle();   /* just show the page title in the menu */   int id = bookmarkMenu->insertItem( title );   /* stash title[url] in the map */   mapBookmarks[id] = title + "[" + url + "]";}/* the handbook is explicitly killed by MainWindow on exit. */void HandBook::closeEvent( QCloseEvent* ){ hide(); }void HandBook::showYourself(){   if ( !isVisible() ) {      show();   } else if ( isMinimized() ) {      showNormal();   } else {      raise();   }}/* Sets the name of the displayed document to url */void HandBook::openUrl( const QString& url ){ browser->setSource( url ); }

⌨️ 快捷键说明

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