/Scribus/scribus/urllauncher.cpp

https://github.com/pvanek/scribus-cuba-1.5.0 · C++ · 85 lines · 69 code · 10 blank · 6 comment · 11 complexity · 0492a0126ab472a9773330e1f88fc315 MD5 · raw file

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. #include <QDesktopServices>
  8. #include <QFileDialog>
  9. #include <QFileInfo>
  10. #include <QMessageBox>
  11. #include <QString>
  12. #include <QStringList>
  13. #include "urllauncher.h"
  14. #include "prefsmanager.h"
  15. #include "scribus.h"
  16. #include "scribuscore.h"
  17. #include "util.h"
  18. UrlLauncher* UrlLauncher::_instance = 0;
  19. UrlLauncher::UrlLauncher() : QObject()
  20. {
  21. }
  22. UrlLauncher::~UrlLauncher()
  23. {
  24. }
  25. UrlLauncher* UrlLauncher::instance()
  26. {
  27. if (_instance == 0)
  28. _instance = new UrlLauncher();
  29. return _instance;
  30. }
  31. void UrlLauncher::deleteInstance()
  32. {
  33. if (_instance)
  34. delete _instance;
  35. _instance = 0;
  36. }
  37. void UrlLauncher::launchUrlExt(const QString& link, QWidget *parent)
  38. {
  39. launchUrlExt(QUrl(link), parent);
  40. }
  41. void UrlLauncher::launchUrlExt(const QUrl& link, QWidget *parent)
  42. {
  43. if (link.scheme()=="http")
  44. {
  45. QWidget *p=parent;
  46. if (p==0)
  47. p=ScCore->primaryMainWindow();
  48. QString extBrowser(PrefsManager::instance()->extBrowserExecutable());
  49. QFileInfo fi(extBrowser);
  50. if (extBrowser.isEmpty())
  51. {
  52. if (!QDesktopServices::openUrl(link))
  53. {
  54. extBrowser = QFileDialog::getOpenFileName(p, tr("Locate your web browser"), QString::null, QString::null);
  55. if (!QFileInfo(extBrowser).exists())
  56. extBrowser="";
  57. PrefsManager::instance()->setExtBrowserExecutable(extBrowser);
  58. }
  59. }
  60. if (!extBrowser.isEmpty())
  61. {
  62. QStringList args;
  63. args << link.toString();
  64. int ret=System(extBrowser, args);
  65. if (ret!=0)
  66. {
  67. 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);
  68. if (sb==QMessageBox::Ok)
  69. QDesktopServices::openUrl(link);
  70. }
  71. }
  72. }
  73. else
  74. QDesktopServices::openUrl(link);
  75. }