add url handler to handle certains protocols differently
This commit is contained in:
@@ -147,6 +147,7 @@ struct MainWindowP
|
||||
bool whatsthis;
|
||||
QString whatstext;
|
||||
Assistant* assistant;
|
||||
QMap<QString, QPointer<UrlHandler> > 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<QUrl>& url)
|
||||
{
|
||||
QStringList files;
|
||||
for (QList<QUrl>::ConstIterator it = url.begin(); it != url.end(); ++it) {
|
||||
QMap<QString, QPointer<UrlHandler> >::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())
|
||||
|
||||
@@ -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<QUrl>&);
|
||||
/**
|
||||
* 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:
|
||||
|
||||
Reference in New Issue
Block a user