Skip to content

Commit

Permalink
examples: osx file associate
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Dec 25, 2014
1 parent ab45d04 commit ca9639e
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 13 deletions.
3 changes: 2 additions & 1 deletion examples/QMLPlayer/QMLPlayer.pro
Original file line number Diff line number Diff line change
@@ -1,3 1,4 @@
VERSION = 1.4.2
*maemo*: DEFINES = Q_OS_MAEMO
# Add more folders to ship with the application, here
folder_01.source = qml/QMLPlayer
Expand Down Expand Up @@ -33,7 34,7 @@ desktopfile.path = /usr/share/applications
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

!*msvc*: QMAKE_LFLAGS = -u __link_hack
#!*msvc*: QMAKE_LFLAGS = -u __link_hack
isEmpty(PROJECTROOT): PROJECTROOT = $$PWD/../..
STATICLINK = 0
include($${PROJECTROOT}/examples/common/libcommon.pri)
Expand Down
10 changes: 8 additions & 2 deletions examples/QMLPlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 40,9 @@ int main(int argc, char *argv[])
r = 1.0;
#endif
float sr = options.value("scale").toFloat();
#if defined(Q_OS_ANDROID)
sr = r;
#endif
if (qFuzzyIsNull(sr))
sr = r;
viewer.engine()->rootContext()->setContextProperty("scaleRatio", sr);
Expand Down Expand Up @@ -75,9 78,12 @@ int main(int argc, char *argv[])
json.replace("\\", "/"); //FIXME
QMetaObject::invokeMethod(viewer.rootObject(), "init", Q_ARG(QVariant, json));
//#else
QObject *player = viewer.rootObject()->findChild<QObject*>("player");
if (player) {
AppEventFilter *ae = new AppEventFilter(player, player);
qApp->installEventFilter(ae);
}
if (app.arguments().size() > 1) {
qDebug("arguments > 1");
QObject *player = viewer.rootObject()->findChild<QObject*>("player");
QString file = options.value("file").toString();
if (file.isEmpty()) {
if (argc > 1 && !app.arguments().last().startsWith('-') && !app.arguments().at(argc-2).startsWith('-'))
Expand Down
220 changes: 220 additions & 0 deletions examples/common/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>AAC</string>
<string>AC3</string>
<string>AIFF</string>
<string>M4A</string>
<string>MKA</string>
<string>MP3</string>
<string>OGG</string>
<string>PCM</string>
<string>VAW</string>
<string>WAV</string>
<string>WAW</string>
<string>WMA</string>
<string>aac</string>
<string>ac3</string>
<string>aiff</string>
<string>m4a</string>
<string>mka</string>
<string>mp3</string>
<string>ogg</string>
<string>pcm</string>
<string>vaw</string>
<string>wav</string>
<string>waw</string>
<string>wma</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>document.icns</string>
<key>CFBundleTypeName</key>
<string>Audio file</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
<string>*</string>
<string>3GP</string>
<string>3IV</string>
<string>3gp</string>
<string>3iv</string>
<string>ASF</string>
<string>AVI</string>
<string>CPK</string>
<string>DAT</string>
<string>DIVX</string>
<string>DV</string>
<string>FLAC</string>
<string>FLI</string>
<string>FLV</string>
<string>H264</string>
<string>I263</string>
<string>M2TS</string>
<string>M4V</string>
<string>MKV</string>
<string>MOV</string>
<string>MP2</string>
<string>MP4</string>
<string>MPEG</string>
<string>MPG</string>
<string>MPG2</string>
<string>MPG4</string>
<string>NSV</string>
<string>NUT</string>
<string>NUV</string>
<string>OGG</string>
<string>OGM</string>
<string>QT</string>
<string>RM</string>
<string>RMVB</string>
<string>VCD</string>
<string>VFW</string>
<string>VOB</string>
<string>WEBM</string>
<string>WMV</string>
<string>asf</string>
<string>avi</string>
<string>cpk</string>
<string>dat</string>
<string>divx</string>
<string>dv</string>
<string>flac</string>
<string>fli</string>
<string>flv</string>
<string>h264</string>
<string>i263</string>
<string>m2ts</string>
<string>m4v</string>
<string>mkv</string>
<string>mov</string>
<string>mp2</string>
<string>mp4</string>
<string>mpeg</string>
<string>mpg</string>
<string>mpg2</string>
<string>mpg4</string>
<string>nsv</string>
<string>nut</string>
<string>nuv</string>
<string>ogg</string>
<string>ogm</string>
<string>qt</string>
<string>rm</string>
<string>rmvb</string>
<string>vcd</string>
<string>vfw</string>
<string>vob</string>
<string>webm</string>
<string>wmv</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>document.icns</string>
<key>CFBundleTypeName</key>
<string>Movie file</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>AQT</string>
<string>ASS</string>
<string>JSS</string>
<string>RT</string>
<string>SMI</string>
<string>SRT</string>
<string>SSA</string>
<string>SUB</string>
<string>TXT</string>
<string>UTF</string>
<string>aqt</string>
<string>ass</string>
<string>jss</string>
<string>rt</string>
<string>smi</string>
<string>srt</string>
<string>ssa</string>
<string>sub</string>
<string>txt</string>
<string>utf</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>document.icns</string>
<key>CFBundleTypeName</key>
<string>Subtitles file</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>player</string>
<key>CFBundleIconFile</key>
<string>QtAV.icns</string>
<key>CFBundleIdentifier</key>
<string>com.qtav.@EXECUTABLE@</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>QtAV @EXECUTABLE@</string>
<key>CFBundleDisplayName</key>
<string>QtAV @EXECUTABLE@</string>
<key>LSMinimumSystemVersionByArchitecture</key>
<dict>
<key>x86_64</key>
<string>10.6.0</string>
</dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>@SHORT_VERSION@</string>
<key>CFBundleVersion</key>
<string>@FULL_VERSION@</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Streaming Protocol</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mms</string>
<string>mmst</string>
<string>http</string>
<string>httpproxy</string>
<string>rtp</string>
<string>rtsp</string>
<string>ftp</string>
<string>udp</string>
<string>smb</string>
</array>
</dict>
</array>
</dict>
</plist>
23 changes: 18 additions & 5 deletions examples/common/common.cpp
Original file line number Diff line number Diff line change
@@ -1,15 1,11 @@
#include "common.h"

#include <QFileOpenEvent>
#include <QtCore/QLocale>
#include <QtCore/QTranslator>
#include <QtCore/QCoreApplication>
#include <QtDebug>

void _link_hack()
{

}

QOptions get_common_options()
{
static QOptions ops = QOptions().addDescription("Options for QtAV players")
Expand Down Expand Up @@ -78,3 74,20 @@ void set_opengl_backend(const QString& glopt, const QString &appname)
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
#endif
}

AppEventFilter::AppEventFilter(QObject *player, QObject *parent)
: QObject(parent)
, m_player(player)
{}

bool AppEventFilter::eventFilter(QObject *obj, QEvent *ev)
{
if (obj != qApp)
return false;
if (ev->type() != QEvent::FileOpen)
return false;
QFileOpenEvent *foe = static_cast<QFileOpenEvent*>(ev);
if (m_player)
QMetaObject::invokeMethod(m_player, "play", Q_ARG(QUrl, QUrl(foe->url())));
return true;
}
16 changes: 12 additions & 4 deletions examples/common/common.h
Original file line number Diff line number Diff line change
@@ -1,18 1,26 @@
#ifndef COMMON_H
#define COMMON_H

#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include "qoptions.h"
#include "Config.h"
#include "ScreenSaver.h"

extern "C" {
COMMON_EXPORT void _link_hack();
}

QOptions COMMON_EXPORT get_common_options();
void COMMON_EXPORT load_qm(const QStringList& names, const QString &lang = "system");
// if appname ends with 'desktop', 'es', 'angle', software', 'sw', set by appname. otherwise set by command line option glopt
void COMMON_EXPORT set_opengl_backend(const QString& glopt = "auto", const QString& appname = QString());

class COMMON_EXPORT AppEventFilter : public QObject
{
public:
AppEventFilter(QObject *player = 0, QObject* parent = 0);
QUrl url() const;
virtual bool eventFilter(QObject *obj, QEvent *ev);
private:
QObject *m_player;
};

#endif // COMMON_H
1 change: 1 addition & 0 deletions examples/common/libcommon.pri
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 155,4 @@ unset(PROJECT_SRCPATH)
unset(PROJECT_LIBDIR)
unset(PROJECT_TARGETNAME)

QMAKE_INFO_PLIST = $$PWD/Info.plist
5 changes: 5 additions & 0 deletions examples/player/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 725,11 @@ void MainWindow::play(const QString &name)
mpPlayer->play(name);
}

void MainWindow::play(const QUrl &url)
{
play(QUrl::fromPercentEncoding(url.toEncoded()));
}

void MainWindow::setVideoDecoderNames(const QStringList &vd)
{
QStringList vdnames;
Expand Down
2 changes: 2 additions & 0 deletions examples/player/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,7 @@
#define MAINWINDOW_H

#include <QWidget>
#include <QUrl>

class QWidgetAction;
namespace QtAV {
Expand Down Expand Up @@ -61,6 62,7 @@ class MainWindow : public QWidget

public slots:
void play(const QString& name);
void play(const QUrl& url);
void openFile();
void togglePlayPause();
void showNextOSD();
Expand Down
4 changes: 3 additions & 1 deletion examples/player/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,6 @@
#include <cstdio>
#include <cstdlib>
#include <QApplication>

#include <QtDebug>
#include <QtCore/QDir>
#include <QMessageBox>
Expand Down Expand Up @@ -148,6 147,9 @@ int main(int argc, char *argv[])
renderer->setOutAspectRatioMode(VideoRenderer::VideoAspectRatio);

MainWindow window;
AppEventFilter ae(&window);
qApp->installEventFilter(&ae);

window.show();
window.setWindowTitle(title);
window.setRenderer(renderer);
Expand Down
1 change: 1 addition & 0 deletions examples/player/player.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@ TEMPLATE = app
QT = opengl
greaterThan(QT_MAJOR_VERSION, 4): QT = widgets
TRANSLATIONS = res/player_zh_CN.ts
VERSION = 1.4.2

STATICLINK = 0
PROJECTROOT = $$PWD/../..
Expand Down

0 comments on commit ca9639e

Please sign in to comment.