Document support for Linguist on Mac.
authorEike Ziller <eike.ziller@nokia.com>
Wed, 27 Jul 2011 11:47:17 +0000 (13:47 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 27 Jul 2011 14:30:02 +0000 (16:30 +0200)
Fixes dragging documents on Linguist dock icon, double clicking document
in Finder, and the "open" terminal command.
(cherry-picked from 80c5ea1a99e0c7794245e53175c949597315c96f)

Task-number: QTBUG-20194
Change-Id: Ice077ca397c6274f48e6911434a71c9934e42142
Reviewed-by: Oswald Buddenhagen
Reviewed-on: http://codereview.qt.nokia.com/2282
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
src/linguist/linguist/Info_mac.plist
src/linguist/linguist/main.cpp

index b11f493..b37a43b 100644 (file)
        <string>????</string>
        <key>CFBundleExecutable</key>
        <string>Linguist</string>
+
+        <key>CFBundleDocumentTypes</key>
+        <array>
+            <dict>
+                <key>CFBundleTypeRole</key>
+                <string>Editor</string>
+                <key>CFBundleTypeIconFile</key>
+                <string>linguist.icns</string>
+                <key>CFBundleTypeExtensions</key>
+                <array>
+                    <string>qph</string>
+                </array>
+                <key>CFBundleTypeName</key>
+                <string>Qt Linguist 'Phrase Book'</string>
+                <key>LSHandlerRank</key>
+                <string>Default</string>
+            </dict>
+            <dict>
+                <key>CFBundleTypeRole</key>
+                <string>Editor</string>
+                <key>CFBundleTypeIconFile</key>
+                <string>linguist.icns</string>
+                <key>CFBundleTypeExtensions</key>
+                <array>
+                    <string>ts</string>
+                </array>
+                <key>CFBundleTypeName</key>
+                <string>Qt Translation Source</string>
+                <key>LSHandlerRank</key>
+                <string>Default</string>
+            </dict>
+            <dict>
+                <key>CFBundleTypeRole</key>
+                <string>Editor</string>
+                <key>CFBundleTypeIconFile</key>
+                <string>linguist.icns</string>
+                <key>CFBundleTypeExtensions</key>
+                <array>
+                    <string>po</string>
+                </array>
+                <key>CFBundleTypeName</key>
+                <string>GNU Gettext Localization File</string>
+                <key>LSHandlerRank</key>
+                <string>Default</string>
+            </dict>
+            <dict>
+                <key>CFBundleTypeRole</key>
+                <string>Editor</string>
+                <key>CFBundleTypeIconFile</key>
+                <string>linguist.icns</string>
+                <key>CFBundleTypeExtensions</key>
+                <array>
+                    <string>xlf</string>
+                </array>
+                <key>CFBundleTypeName</key>
+                <string>XLIFF Localization File</string>
+                <key>LSHandlerRank</key>
+                <string>Default</string>
+            </dict>
+        </array>
 </dict>
 </plist>
index a137f36..ba45613 100644 (file)
 #include <QtGui/QPixmap>
 #include <QtGui/QSplashScreen>
 
+#ifdef Q_WS_MAC
+#include <QtCore/QUrl>
+#include <QtGui/QFileOpenEvent>
+#endif // Q_WS_MAC
+
 QT_USE_NAMESPACE
 
+#ifdef Q_WS_MAC
+class ApplicationEventFilter : public QObject
+{
+    Q_OBJECT
+
+public:
+    ApplicationEventFilter()
+        : m_mainWindow(0)
+    {
+    }
+
+    void setMainWindow(MainWindow *mw)
+    {
+        m_mainWindow = mw;
+        if (!m_filesToOpen.isEmpty() && m_mainWindow) {
+            m_mainWindow->openFiles(m_filesToOpen);
+            m_filesToOpen.clear();
+        }
+    }
+
+protected:
+    bool eventFilter(QObject *object, QEvent *event)
+    {
+        if (object == qApp && event->type() == QEvent::FileOpen) {
+            QFileOpenEvent *e = static_cast<QFileOpenEvent*>(event);
+            QString file = e->url().toLocalFile();
+            if (!m_mainWindow)
+                m_filesToOpen << file;
+            else
+                m_mainWindow->openFiles(QStringList() << file);
+            return true;
+        }
+        return QObject::eventFilter(object, event);
+    }
+
+private:
+    MainWindow *m_mainWindow;
+    QStringList m_filesToOpen;
+};
+#endif // Q_WS_MAC
+
 int main(int argc, char **argv)
 {
     Q_INIT_RESOURCE(linguist);
@@ -63,6 +109,11 @@ int main(int argc, char **argv)
     QApplication app(argc, argv);
     QApplication::setOverrideCursor(Qt::WaitCursor);
 
+#ifdef Q_WS_MAC
+    ApplicationEventFilter eventFilter;
+    app.installEventFilter(&eventFilter);
+#endif // Q_WS_MAC
+
     QStringList files;
     QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
     QStringList args = app.arguments();
@@ -111,6 +162,9 @@ int main(int argc, char **argv)
     splash->show();
 
     MainWindow mw;
+#ifdef Q_WS_MAC
+    eventFilter.setMainWindow(&mw);
+#endif // Q_WS_MAC
     mw.show();
     splash->finish(&mw);
     QApplication::restoreOverrideCursor();
@@ -119,3 +173,7 @@ int main(int argc, char **argv)
 
     return app.exec();
 }
+
+#ifdef Q_WS_MAC
+#include "main.moc"
+#endif // Q_WS_MAC