diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index baa4f3675c..9b0ed70dc9 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -147,6 +147,7 @@ struct MainWindowP bool whatsthis; QString whatstext; Assistant* assistant; + QMap > urlHandler; }; class MDITabbar : public QTabBar @@ -1457,10 +1458,27 @@ void MainWindow::insertFromMimeData (const QMimeData * mimeData) } } +void MainWindow::setUrlHandler(const QString &scheme, Gui::UrlHandler* handler) +{ + d->urlHandler[scheme] = handler; +} + +void MainWindow::unsetUrlHandler(const QString &scheme) +{ + d->urlHandler.remove(scheme); +} + void MainWindow::loadUrls(App::Document* doc, const QList& url) { QStringList files; for (QList::ConstIterator it = url.begin(); it != url.end(); ++it) { + QMap >::iterator jt = d->urlHandler.find(it->scheme()); + if (jt != d->urlHandler.end() && !jt->isNull()) { + // delegate the loading to the url handler + (*jt)->openUrl(doc, *it); + continue; + } + QFileInfo info((*it).toLocalFile()); if (info.exists() && info.isFile()) { if (info.isSymLink()) diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h index bd1c1a151c..cc8e00b35c 100644 --- a/src/Gui/MainWindow.h +++ b/src/Gui/MainWindow.h @@ -53,6 +53,19 @@ namespace DockWnd { class HelpView; } //namespace DockWnd +class GuiExport UrlHandler : public QObject +{ + Q_OBJECT + +public: + UrlHandler(QObject* parent = 0) + : QObject(parent){ + } + virtual ~UrlHandler() { + } + virtual void openUrl(App::Document*, const QUrl&) { + } +}; /** * The MainWindow class provides a main window with menu bar, toolbars, dockable windows, @@ -147,8 +160,22 @@ public: /** * Load files from the given URLs into the given document. If the document is 0 * one gets created automatically if needed. + * + * If a url handler is registered that supports its scheme it will be delegated + * to this handler. This mechanism allows to change the default behaviour. */ void loadUrls(App::Document*, const QList&); + /** + * Sets the \a handler for the given \a scheme. + * If setUrlHandler() is used to set a new handler for a scheme which already has a handler, + * the existing handler is simply replaced with the new one. Since MainWindow does not take + * ownership of handlers, no objects are deleted when a handler is replaced. + */ + void setUrlHandler(const QString &scheme, UrlHandler* handler); + /** + * Removes a previously set URL handler for the specified \a scheme. + */ + void unsetUrlHandler(const QString &scheme); //@} public Q_SLOTS: