urllauncher.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <QDesktopServices>
00009 #include <QFileDialog>
00010 #include <QFileInfo>
00011 #include <QMessageBox>
00012 #include <QString>
00013 #include <QStringList>
00014
00015 #include "urllauncher.h"
00016 #include "prefsmanager.h"
00017 #include "scribus.h"
00018 #include "scribuscore.h"
00019 #include "util.h"
00020
00021 UrlLauncher* UrlLauncher::_instance = 0;
00022
00023 UrlLauncher::UrlLauncher() : QObject()
00024 {
00025 }
00026
00027 UrlLauncher::~UrlLauncher()
00028 {
00029 }
00030
00031 UrlLauncher* UrlLauncher::instance()
00032 {
00033 if (_instance == 0)
00034 _instance = new UrlLauncher();
00035
00036 return _instance;
00037 }
00038
00039 void UrlLauncher::deleteInstance()
00040 {
00041 if (_instance)
00042 delete _instance;
00043 _instance = 0;
00044 }
00045
00046 void UrlLauncher::launchUrlExt(const QString& link, QWidget *parent)
00047 {
00048 launchUrlExt(QUrl(link), parent);
00049 }
00050
00051 void UrlLauncher::launchUrlExt(const QUrl& link, QWidget *parent)
00052 {
00053 if (link.scheme()=="http")
00054 {
00055 QWidget *p=parent;
00056 if (p==0)
00057 p=ScCore->primaryMainWindow();
00058 QString extBrowser(PrefsManager::instance()->extBrowserExecutable());
00059 QFileInfo fi(extBrowser);
00060 if (extBrowser.isEmpty())
00061 {
00062 if (!QDesktopServices::openUrl(link))
00063 {
00064 extBrowser = QFileDialog::getOpenFileName(p, tr("Locate your web browser"), QString::null, QString::null);
00065 if (!QFileInfo(extBrowser).exists())
00066 extBrowser="";
00067 PrefsManager::instance()->setExtBrowserExecutable(extBrowser);
00068 }
00069 }
00070 if (!extBrowser.isEmpty())
00071 {
00072 QStringList args;
00073 args << link.toString();
00074 int ret=System(extBrowser, args);
00075 if (ret!=0)
00076 {
00077 QMessageBox::StandardButton sb=QMessageBox::critical(p, tr("External Web Browser Failed to Start"), tr("Scribus was not able to start the external web browser application %1. Please check the setting in Preferences.\nWould you like to start the system's default browser instead?").arg(PrefsManager::instance()->extBrowserExecutable()), QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok);
00078 if (sb==QMessageBox::Ok)
00079 QDesktopServices::openUrl(link);
00080 }
00081 }
00082 }
00083 else
00084 QDesktopServices::openUrl(link);
00085 }