Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static QString schemeHandler(const QString &protocol, const QUrl &url)
- {
- // We have up to two sources of data, for protocols not handled by kioslaves (so called "helper") :
- // 1) the exec line of the .protocol file, if there's one
- // 2) the application associated with x-scheme-handler/<protocol> if there's one
- // If both exist, then:
- // A) if the .protocol file says "launch an application", then the new-style handler-app has priority
- // B) but if the .protocol file is for a kioslave (e.g. kio_http) then this has priority over
- // firefox or chromium saying x-scheme-handler/http. Gnome people want to send all HTTP urls
- // to a webbrowser, but we want mimetype-determination-in-calling-application by default
- // (the user can configure a BrowserApplication though)
- QString b_mime_type = QString::fromLatin1("x-scheme-handler/") + protocol;
- QString e_mime_type('');
- QRegExp *regExp = 0;
- QMimeDatabase db;
- foreach (QMimeType mt, db.allMimeTypes()) {
- if (mt.name().startsWith("x-scheme-handler/") && mt.parentMimeTypes().contains(b_mime_type)) {
- if(!regExp) {
- regExp = new QRegExp();
- regExp->setCaseSensitivity(Qt::CaseInsensitive);
- regExp->setMinimal(false);
- regExp->setPatternSyntax(QRegExp::WildcardUnix);
- }
- foreach (QString s, mt.globPatterns()) {
- regExp->setPattern(s);
- if (regExp.isValid() && regExp->exactMatch(url.url())) {
- e_mime_type = mt.name();
- }
- }
- }
- }
- if (regExp)
- delete regExp;
- const KService::Ptr service;
- if (!e_mime_type.isEmpty()) {
- service = KMimeTypeTrader::self()->preferredService(e_mime_type);
- if (service) {
- return service->exec(); // for helper protocols, the handler app has priority over the hardcoded one (see A above)
- }
- }
- service = KMimeTypeTrader::self()->preferredService(b_mime_type);
- if (service) {
- return service->exec(); // for helper protocols, the handler app has priority over the hardcoded one (see A above)
- }
- Q_ASSERT(KProtocolInfo::isHelperProtocol(protocol));
- return KProtocolInfo::exec(protocol);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement