Logo Search packages:      
Sourcecode: kmess version File versions

void KMessShared::openBrowser ( const KUrl &  url  )  [static]

Open the given URL respecting the user's preference.

The program which will open the URL is the one selected in the Global Settings

Parameters:
url The URL to open

Definition at line 390 of file kmessshared.cpp.

References KMessConfig::getGlobalConfig().

Referenced by openEmailClient().

{
  // Open the options
  KConfigGroup group = KMessConfig::instance()->getGlobalConfig( "General" );

  QString browser;
  QString fallbackBrowser( group.readEntry( "customBrowser", "konqueror" ) );

  // Obtain the widget of the main KMess window, to correctly link it to the opened browser
  KMessApplication *kmessApp = static_cast<KMessApplication*>( kapp );
  QWidget *mainWindow = kmessApp->getContactListWindow()->window();

  // Read which browser has to be opened
  QString browserChoice( group.readEntry( "useBrowser", "KDE" ) );

#ifdef KMESSDEBUG_SHARED_OPENEXTERNAL
  kDebug() << "Opening URL" << url << "- The setting is" << browserChoice;
#endif

  // If the preference had an invalid choice, use the KDE default browser.
  if( browserChoice != "custom"
  &&  browserChoice != "listed"
  &&  browserChoice != "KDE" )
  {
    kWarning() << "Invalid browser choice:" << browserChoice << ", using KDE default.";

    browserChoice = "KDE";
  }

  // Launch the appropriate browser
  if( browserChoice == "custom" )
  {
    browser = group.readEntry( "customBrowser", fallbackBrowser );
#ifdef KMESSDEBUG_SHARED_OPENEXTERNAL
    kDebug() << "Custom browser selected:" << browser;
#endif
  }
  else if( browserChoice == "listed" )
  {
    browser = group.readEntry( "listedBrowser", fallbackBrowser );
#ifdef KMESSDEBUG_SHARED_OPENEXTERNAL
    kDebug() << "Listed browser selected:" << browser;
#endif
  }

  // If the option isn't valid use the KDE default
  if( browser.isEmpty() )
  {
#ifdef KMESSDEBUG_SHARED_OPENEXTERNAL
    kDebug() << "Invalid browser option, using KDE default.";
#endif
    browserChoice = "KDE";
  }

  if( browserChoice == "KDE" )
  {
#ifdef KMESSDEBUG_SHARED_OPENEXTERNAL
    kDebug() << "KDE default browser selected.";
#endif
    KToolInvocation::invokeBrowser( url.url() );
    return;
  }

  // Replace the %u in the command line with the actual URL, and launch the browser.
  browser.replace( "%u", KShell::quoteArg( url.url() ), Qt::CaseInsensitive );
  KRun::runCommand( browser, mainWindow );
}


Generated by  Doxygen 1.6.0   Back to index