[KDE/Mac] new year's resolution: opening files "the Mac way" (TM)

René J.V. Bertin rjvbertin at gmail.com
Sat Jan 2 18:21:35 UTC 2016


Hi,


I have gotten a bit further. As I thought it is critical to have a correct Info.plist (or else the event is never sent), and it isn't trivial to edit that file "in place" and have the system recognise its new content (easiest way is to copy the entire app bundle in the Finder).

You also need to set a flag (LSMultipleInstancesProhibited) in the Info.plist to avoid launching multiple copies; for some reason the mechanism that is in place to prevent that doesn't work when you drop a document on Kate's app icon in the Finder (or the Dock). So:

     <key>NSPrincipalClass</key>
     <string>NSApplication</string>
     <key>NSSupportsAutomaticGraphicsSwitching</key>
     <true/>
     <key>LSMultipleInstancesProhibited</key>
     <true/>
     <key>CFBundleDocumentTypes</key>
     <array>
          <dict>
               <key>CFBundleTypeExtensions</key>
               <array>
                    <string>*</string>
               </array>
               <key>CFBundleTypeName</key>
               <string>NSStringPboardType</string>
               <key>CFBundleTypeRole</key>
               <string>Editor</string>
          </dict>
     </array>

(The NSSupportsAutomaticGraphicsSwitching comes from QtCreator; I haven't check what it does exactly but it shouldn't harm).

With this, I see the events arrive in kate's main.cpp when I add the following:

#include <QFileOpenEvent>
class FileOpenHandler : public QObject
{
    Q_OBJECT
public:
    FileOpenHandler(QObject *parent=Q_NULLPTR)
        : QObject(parent)
    {}
    bool eventFilter(QObject *obj, QEvent *event)
    {
        if (event->type() == QEvent::FileOpen) {
            QFileOpenEvent *foe = static_cast<QFileOpenEvent*>(event);
            qDebug() << Q_FUNC_INFO << "FileOpen event" << foe;
            // call KateApp::openUrl(foe->url() ...) from here
            return true;
        } else {
            return QObject::eventFilter(obj, event);
        }
    }
};

and then just before starting the main loop:

#ifdef Q_OS_OSX
    FileOpenHandler *fileOpenHandler = new FileOpenHandler(qApp);
    qApp->installEventFilter(fileOpenHandler);
#endif

Question is: what about the encoding parameter?

Also, for a local/MacPorts KDE4 implementation of this : if I add a signal to the KApplication class, do I need to rebuild all dependents to avoid ABI-related crashing, or only those that are modified to connect to the new signal?
(IOW, can you add a signal to a class without breaking backwards compatibility?)


R.


More information about the Kde-frameworks-devel mailing list