From 6508a93e86498ebd58f067f89b7d55e8dd17ec56 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 20 Nov 2014 19:35:48 +0000 Subject: [PATCH 01/10] Init checking of the existing sessions --- CMakeLists.txt | 6 +++--- app/main.cpp | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d63fe4..08ec998 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,11 +82,11 @@ ENDIF() IF( NOT USE_QT4 ) SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) - FIND_PACKAGE( Qt5 REQUIRED Core Gui Widgets ) - INCLUDE_DIRECTORIES( ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ) + FIND_PACKAGE( Qt5 REQUIRED Core Gui Widgets DBus ) + INCLUDE_DIRECTORIES( ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) # Add compiler flags for building executables (-fPIE) SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}" ) - LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets ) + LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus ) LIST(APPEND QT_MODULES Core Gui Widgets ) ENDIF() diff --git a/app/main.cpp b/app/main.cpp index d5421fb..b2bc25c 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -22,8 +22,9 @@ * \brief main file */ -#include #include "config.h" +#include +#include #include "plaYUVerApp.h" #include "SubWindowHandle.h" #ifdef USE_FERVOR @@ -38,15 +39,24 @@ using namespace plaYUVer; int main( int argc, char *argv[] ) { - QApplication a( argc, argv ); - QApplication::setApplicationName("PlaYUVer"); - QApplication::setApplicationVersion(PLAYUVER_VERSION_STRING); - QApplication::setOrganizationName("pixlra"); - QApplication::setOrganizationDomain("playuver.pixlra"); - qRegisterMetaType("PlaYUVerStreamInfoVector"); qRegisterMetaTypeStreamOperators("PlaYUVerStreamInfoVector"); + QApplication a( argc, argv ); + QApplication::setApplicationName( "PlaYUVer" ); + QApplication::setApplicationVersion( PLAYUVER_VERSION_STRING ); + QApplication::setOrganizationName( "pixlra" ); + QApplication::setOrganizationDomain( "playuver.pixlra" ); + + /** + * use dbus, if available + * allows for resuse of running Kate instances + */ + if( QDBusConnectionInterface * const sessionBusInterface = QDBusConnection::sessionBus().interface() ) + { + + } + plaYUVerApp w; w.show(); w.parseArgs( argc, argv ); From 069a8c261ceb216027878f527ebd02ad32739330 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 24 Nov 2014 01:18:07 +0000 Subject: [PATCH 02/10] First effort to use DBus to communicate between apps. Enable opening the new sequence in the existing session --- app/CMakeLists.txt | 2 + app/PlaYUVerAppAdaptor.cpp | 70 +++++++++++++++++++ app/PlaYUVerAppAdaptor.h | 83 +++++++++++++++++++++++ app/RunningInstanceInfo.cpp | 83 +++++++++++++++++++++++ app/RunningInstanceInfo.h | 100 +++++++++++++++++++++++++++ app/main.cpp | 130 +++++++++++++++++++++++++++++++++--- app/plaYUVerApp.cpp | 16 ++--- app/plaYUVerApp.h | 7 +- 8 files changed, 470 insertions(+), 21 deletions(-) create mode 100644 app/PlaYUVerAppAdaptor.cpp create mode 100644 app/PlaYUVerAppAdaptor.h create mode 100644 app/RunningInstanceInfo.cpp create mode 100644 app/RunningInstanceInfo.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 232bf33..3fab685 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -15,6 +15,8 @@ set(plaYUver_App_SRCS PlaYUVerAppModuleIf.cpp GridManager.cpp Settings.cpp + PlaYUVerAppAdaptor.cpp + RunningInstanceInfo.cpp # Dialogs AboutDialog.cpp ConfigureFormatDialog.cpp diff --git a/app/PlaYUVerAppAdaptor.cpp b/app/PlaYUVerAppAdaptor.cpp new file mode 100644 index 0000000..065c1b1 --- /dev/null +++ b/app/PlaYUVerAppAdaptor.cpp @@ -0,0 +1,70 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file PlaYUVerAppAdaptor.h + * \brief Define function to manage the interface in DBus + */ + +#include +#include "PlaYUVerAppAdaptor.h" +#include "plaYUVerApp.h" + +namespace plaYUVer +{ + +PlaYUVerAppAdaptor::PlaYUVerAppAdaptor( plaYUVerApp *app ) : + QDBusAbstractAdaptor( app ), + m_app( app ) +{ + // application dbus interface + QDBusConnection::sessionBus().registerObject( QStringLiteral( PLAYUVER_DBUS_PATH ), this, QDBusConnection::ExportAllSlots ); +} + +PlaYUVerAppAdaptor::~PlaYUVerAppAdaptor() +{ + QDBusConnection::sessionBus().unregisterObject( QStringLiteral( PLAYUVER_DBUS_PATH ) ); +} + +void PlaYUVerAppAdaptor::activate() +{ + if( !m_app ) + { + return; + } + + m_app->show(); + //m_app->activateWindow(); + //m_app->raise(); + +} + +QString PlaYUVerAppAdaptor::activeSession() +{ + //return m_app->sessionManager()->activeSession()->name(); + return QString( "PlaYUVer" ); +} + +bool PlaYUVerAppAdaptor::loadFile( QString filename ) +{ + m_app->loadFile( filename ); + return true; +} + +} // NAMESPACE diff --git a/app/PlaYUVerAppAdaptor.h b/app/PlaYUVerAppAdaptor.h new file mode 100644 index 0000000..55a0b23 --- /dev/null +++ b/app/PlaYUVerAppAdaptor.h @@ -0,0 +1,83 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file PlaYUVerAppAdaptor.h + * \brief Define function to manage the interface in DBus + */ + +#ifndef __PlaYUVerAppAdaptor_H__ +#define __PlaYUVerAppAdaptor_H__ + +#include +#include + +namespace plaYUVer +{ + +#define PLAYUVER_DBUS_SESSION_NAME "org.pixlra.PlaYUVer.application" +#define PLAYUVER_DBUS_PATH "/MainApplication" + +class plaYUVerApp; + +class PlaYUVerAppAdaptor: public QDBusAbstractAdaptor +{ +Q_OBJECT +Q_CLASSINFO("D-Bus Interface", PLAYUVER_DBUS_SESSION_NAME) +Q_PROPERTY(QString activeSession READ activeSession) +public: + PlaYUVerAppAdaptor( plaYUVerApp *app ); + ~PlaYUVerAppAdaptor(); + /** + * emit the exiting signal + */ + //void emitExiting(); + //void emitDocumentClosed(const QString &token); +public Q_SLOTS: + /** + * open a file with given url and encoding + * will get view created + * @param url url of the file + * @param encoding encoding name + * @return success + */ + bool loadFile( QString filename ); + + /** + * activate this kate instance + */ + void activate(); + +Q_SIGNALS: + /** + * Notify the world that this kate instance is exiting. + * All apps should stop using the dbus interface of this instance after this signal got emitted. + */ + //void exiting(); + //void documentClosed(const QString &token); +public: + QString activeSession(); +private: + plaYUVerApp *m_app; +}; + +} // NAMESPACE + +#endif // __PlaYUVerAppAdaptor_H__ + diff --git a/app/RunningInstanceInfo.cpp b/app/RunningInstanceInfo.cpp new file mode 100644 index 0000000..c4c4098 --- /dev/null +++ b/app/RunningInstanceInfo.cpp @@ -0,0 +1,83 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file RunningInstanceInfo.cpp + * \brief Control running instances + */ + +#include "RunningInstanceInfo.h" +#include +#include +#include +#include +#include + +namespace plaYUVer +{ + +int RunningInstanceInfo::dummy_session = 0; + +bool fillinRunningAppInstances(RunningInstanceInfoMap *map) +{ + QDBusConnectionInterface *i = QDBusConnection::sessionBus().interface(); + + // look up all running kate instances and there sessions + QDBusReply servicesReply = i->registeredServiceNames(); + QStringList services; + if (servicesReply.isValid()) { + services = servicesReply.value(); + } + + QString serviceName; + + QString my_pid = QString::number(QCoreApplication::applicationPid()); + + foreach(const QString & s, services) { + if (s.startsWith(QStringLiteral("org.pixlra.PlaYUVer"))) { + if (s.contains(my_pid)) { + continue; + } + qDebug() << s ; + RunningInstanceInfo *rii = new RunningInstanceInfo(s); + if (rii->valid) { + if (map->contains(rii->sessionName)) { + return false; //ERROR no two instances may have the same session name + } + map->insert(rii->sessionName, rii); + //std::cerr<sessionName.toUtf8().data()<constBegin(); it != map->constEnd(); ++it) { + delete it.value(); + } + map->clear(); +} + +} // NAMESPACE + + diff --git a/app/RunningInstanceInfo.h b/app/RunningInstanceInfo.h new file mode 100644 index 0000000..26ae16d --- /dev/null +++ b/app/RunningInstanceInfo.h @@ -0,0 +1,100 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file RunningInstanceInfo.h + * \brief Control running instances + */ + +#ifndef _PLAYUVER_RUNNING_INSTANCE_INFO_ +#define _PLAYUVER_RUNNING_INSTANCE_INFO_ + +#include +#include +#include +#include +#include +#include "lib/PlaYUVerDefs.h" +#include "PlaYUVerAppAdaptor.h" + +namespace plaYUVer +{ + +class RunningInstanceInfo: public QObject +{ +Q_OBJECT + +public: + RunningInstanceInfo( const QString &serviceName_ ) : + QObject(), + valid( false ), + serviceName( serviceName_ ), + dbus_if( new QDBusInterface( serviceName_, QStringLiteral( PLAYUVER_DBUS_PATH ), QString(), //I don't know why it does not work if I specify org.pixlra.PlaYUVer.application here + QDBusConnection::sessionBus(), this ) ) + { + if( !dbus_if->isValid() ) + { + std::cerr << qPrintable( QDBusConnection::sessionBus().lastError().message() ) + << std::endl; + } +// QVariant a_s = dbus_if->property( "activeSession" ); +// std::cerr< RunningInstanceInfoMap; + +Q_DECL_EXPORT bool fillinRunningAppInstances( RunningInstanceInfoMap *map ); +Q_DECL_EXPORT void cleanupRunningAppInstanceMap( RunningInstanceInfoMap *map ); + +} // NAMESPACE + +#endif // _PLAYUVER_RUNNING_INSTANCE_INFO_ + diff --git a/app/main.cpp b/app/main.cpp index b2bc25c..fbee25c 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -23,8 +23,14 @@ */ #include "config.h" +#include "lib/PlaYUVerDefs.h" #include +#include #include +#include +#include +#include "PlaYUVerAppAdaptor.h" +#include "RunningInstanceInfo.h" #include "plaYUVerApp.h" #include "SubWindowHandle.h" #ifdef USE_FERVOR @@ -39,10 +45,10 @@ using namespace plaYUVer; int main( int argc, char *argv[] ) { - qRegisterMetaType("PlaYUVerStreamInfoVector"); - qRegisterMetaTypeStreamOperators("PlaYUVerStreamInfoVector"); + qRegisterMetaType( "PlaYUVerStreamInfoVector" ); + qRegisterMetaTypeStreamOperators( "PlaYUVerStreamInfoVector" ); - QApplication a( argc, argv ); + QApplication application( argc, argv ); QApplication::setApplicationName( "PlaYUVer" ); QApplication::setApplicationVersion( PLAYUVER_VERSION_STRING ); QApplication::setOrganizationName( "pixlra" ); @@ -52,17 +58,123 @@ int main( int argc, char *argv[] ) * use dbus, if available * allows for resuse of running Kate instances */ - if( QDBusConnectionInterface * const sessionBusInterface = QDBusConnection::sessionBus().interface() ) + QDBusConnectionInterface * const sessionBusInterface = QDBusConnection::sessionBus().interface(); + if( sessionBusInterface ) { + RunningInstanceInfoMap mapSessionRii; + if( !fillinRunningAppInstances( &mapSessionRii ) ) + { + return 1; + } + QStringList playuverServices; + for( RunningInstanceInfoMap::const_iterator it = mapSessionRii.constBegin(); it != mapSessionRii.constEnd(); ++it ) + { + playuverServices << ( *it )->serviceName; + } + QString serviceName; + //const QStringList urls = parser.positionalArguments(); + + Bool force_new = false; + + //cleanup map + cleanupRunningAppInstanceMap( &mapSessionRii ); + + //if no new instance is forced and no already opened session is requested, + //check if a pid is given, which should be reused. + // two possibilities: pid given or not... +// if( ( !force_new ) && serviceName.isEmpty() ) +// { +// if( /*( parser.isSet( usePidOption ) )*/|| ( !qgetenv( "PLAYUVER_PID" ).isEmpty() ) ) +// { +// QString usePid = ( parser.isSet( usePidOption ) ) ? parser.value( usePidOption ) : QString::fromLocal8Bit( qgetenv( "KATE_PID" ) ); +// +// serviceName = QStringLiteral("org.kde.kate-")+ usePid; +// if( !playuverServices.contains( serviceName ) ) +// { +// serviceName.clear(); +// } +// } +// } + + if( ( !force_new ) && ( serviceName.isEmpty() ) ) + { + if( playuverServices.count() > 0 ) + { + serviceName = playuverServices[0]; + } + } + + //check again if service is still running + bool foundRunningService = false; + if( !serviceName.isEmpty() ) + { + QDBusReply there = sessionBusInterface->isServiceRegistered( serviceName ); + foundRunningService = there.isValid() && there.value(); + } + + if( foundRunningService ) + { + // open given session + QDBusMessage m = QDBusMessage::createMethodCall( serviceName, QStringLiteral( PLAYUVER_DBUS_PATH ), QStringLiteral( PLAYUVER_DBUS_SESSION_NAME ), + QStringLiteral( "activate" ) ); + + QDBusConnection::sessionBus().call( m ); + + // only block, if files to open there.... + bool needToBlock = false; + + QStringList tokens; + + QStringList filenameList; + filenameList.append( QString( argv[1] ) ); + + // open given files... + foreach(const QString & file, filenameList){ + QDBusMessage m = QDBusMessage::createMethodCall(serviceName, + QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); + + QList dbusargs; + + dbusargs.append( file ); + + m.setArguments(dbusargs); + + QDBusMessage res = QDBusConnection::sessionBus().call(m); + if (res.type() == QDBusMessage::ReplyMessage) + { + if (res.arguments().count() == 1) + { + QVariant v = res.arguments()[0]; + if (v.isValid()) + { + QString s = v.toString(); + if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) + { + tokens << s; + } + } + } + } + } + + // this will wait until exiting is emitted by the used instance, if wanted... + return needToBlock ? application.exec() : 0; + } } - plaYUVerApp w; - w.show(); - w.parseArgs( argc, argv ); + /** + * if we arrive here, we need to start a new playuver instance! + */ + plaYUVerApp mainwindow; + mainwindow.show(); + mainwindow.parseArgs( argc, argv ); #ifdef USE_FERVOR - FvUpdater::sharedUpdater()->SetFeedURL("http://192.168.96.201/share/jcarreira.it.pub/plaYUVer/PlaYUVerUpdate.xml"); + FvUpdater::sharedUpdater()->SetFeedURL("http://192.168.96.201/share/pixLRA/plaYUVer/PlaYUVerUpdate.xml"); FvUpdater::sharedUpdater()->SetDependencies(DEPENDENCIES_STRING); #endif - return a.exec(); + + QDBusConnection::sessionBus().registerService( PLAYUVER_DBUS_SESSION_NAME ); + + return application.exec(); } diff --git a/app/plaYUVerApp.cpp b/app/plaYUVerApp.cpp index 8d9dc01..4c3e858 100644 --- a/app/plaYUVerApp.cpp +++ b/app/plaYUVerApp.cpp @@ -22,19 +22,14 @@ * \brief Main definition of the plaYUVerApp app */ -#include "plaYUVerApp.h" -#include "lib/PlaYUVerStream.h" -#include "DialogSubWindowSelector.h" + +#include #ifdef USE_FERVOR #include "fvupdater.h" #endif -#if( QT_VERSION_PLAYUVER == 5 ) -#include -#elif( QT_VERSION_PLAYUVER == 4 ) -#include -#endif -#include +#include "plaYUVerApp.h" +#include "DialogSubWindowSelector.h" #include "WidgetFrameNumber.h" #include "Settings.h" @@ -48,6 +43,9 @@ plaYUVerApp::plaYUVerApp() setWindowModality( Qt::ApplicationModal ); + // dbus + m_pDBusAdaptor = new PlaYUVerAppAdaptor(this); + mdiArea = new PlaYUVerMdiArea; setCentralWidget( mdiArea ); //mdiArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); diff --git a/app/plaYUVerApp.h b/app/plaYUVerApp.h index 9f4cee2..2889253 100644 --- a/app/plaYUVerApp.h +++ b/app/plaYUVerApp.h @@ -26,13 +26,14 @@ #define __PLAYUVERAPP_H__ #include "config.h" -#include "lib/PlaYUVerDefs.h" #if( QT_VERSION_PLAYUVER == 5 ) #include #elif( QT_VERSION_PLAYUVER == 4 ) #include #endif #include +#include "lib/PlaYUVerDefs.h" +#include "PlaYUVerAppAdaptor.h" #include "SubWindowHandle.h" #include "ModulesHandle.h" #include "PropertiesSidebar.h" @@ -52,6 +53,7 @@ Q_OBJECT public: plaYUVerApp(); Void parseArgs( Int argc, Char *argv[] ); + Void loadFile( QString fileName, PlaYUVerStreamInfo* streamInfo = NULL ); protected: Void closeEvent( QCloseEvent *event ); @@ -143,6 +145,7 @@ private: QPixmap m_pixmapLogo; }; + PlaYUVerAppAdaptor* m_pDBusAdaptor; PlaYUVerMdiArea *mdiArea; SubWindowHandle *m_pcCurrentSubWindow; ModulesHandle *m_pcModulesHandle; @@ -153,8 +156,6 @@ private: QTime m_cTimer; UInt m_uiAveragePlayInterval; - Void loadFile( QString fileName, PlaYUVerStreamInfo* streamInfo = NULL ); - Void readRecentFileList(); Void writeRecentFileList(); From 39cb74cccb947a1c1792c155deec71a2d9aa5afc Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 24 Nov 2014 01:25:41 +0000 Subject: [PATCH 03/10] Check all input args --- app/main.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index fbee25c..6f0d5df 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -97,6 +97,16 @@ int main( int argc, char *argv[] ) // } // } + QStringList filenameList; + for( Int i = 1; i < argc; i++ ) + { + filenameList.append( QString( argv[i] ) ); + } + if( filenameList.isEmpty() ) + { + force_new = true; + } + if( ( !force_new ) && ( serviceName.isEmpty() ) ) { if( playuverServices.count() > 0 ) @@ -126,9 +136,6 @@ int main( int argc, char *argv[] ) QStringList tokens; - QStringList filenameList; - filenameList.append( QString( argv[1] ) ); - // open given files... foreach(const QString & file, filenameList){ QDBusMessage m = QDBusMessage::createMethodCall(serviceName, From d5ab0db12b65fb07db9ef29252df4e6b3196609e Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 25 Nov 2014 23:53:26 +0000 Subject: [PATCH 04/10] Clean unused code to handle dbus --- app/CMakeLists.txt | 1 - app/RunningInstanceInfo.cpp | 83 ------------------------------ app/RunningInstanceInfo.h | 100 ------------------------------------ app/main.cpp | 52 ++----------------- 4 files changed, 4 insertions(+), 232 deletions(-) delete mode 100644 app/RunningInstanceInfo.cpp delete mode 100644 app/RunningInstanceInfo.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 3fab685..2ff5b94 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -16,7 +16,6 @@ set(plaYUver_App_SRCS GridManager.cpp Settings.cpp PlaYUVerAppAdaptor.cpp - RunningInstanceInfo.cpp # Dialogs AboutDialog.cpp ConfigureFormatDialog.cpp diff --git a/app/RunningInstanceInfo.cpp b/app/RunningInstanceInfo.cpp deleted file mode 100644 index c4c4098..0000000 --- a/app/RunningInstanceInfo.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * \file RunningInstanceInfo.cpp - * \brief Control running instances - */ - -#include "RunningInstanceInfo.h" -#include -#include -#include -#include -#include - -namespace plaYUVer -{ - -int RunningInstanceInfo::dummy_session = 0; - -bool fillinRunningAppInstances(RunningInstanceInfoMap *map) -{ - QDBusConnectionInterface *i = QDBusConnection::sessionBus().interface(); - - // look up all running kate instances and there sessions - QDBusReply servicesReply = i->registeredServiceNames(); - QStringList services; - if (servicesReply.isValid()) { - services = servicesReply.value(); - } - - QString serviceName; - - QString my_pid = QString::number(QCoreApplication::applicationPid()); - - foreach(const QString & s, services) { - if (s.startsWith(QStringLiteral("org.pixlra.PlaYUVer"))) { - if (s.contains(my_pid)) { - continue; - } - qDebug() << s ; - RunningInstanceInfo *rii = new RunningInstanceInfo(s); - if (rii->valid) { - if (map->contains(rii->sessionName)) { - return false; //ERROR no two instances may have the same session name - } - map->insert(rii->sessionName, rii); - //std::cerr<sessionName.toUtf8().data()<constBegin(); it != map->constEnd(); ++it) { - delete it.value(); - } - map->clear(); -} - -} // NAMESPACE - - diff --git a/app/RunningInstanceInfo.h b/app/RunningInstanceInfo.h deleted file mode 100644 index 26ae16d..0000000 --- a/app/RunningInstanceInfo.h +++ /dev/null @@ -1,100 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * \file RunningInstanceInfo.h - * \brief Control running instances - */ - -#ifndef _PLAYUVER_RUNNING_INSTANCE_INFO_ -#define _PLAYUVER_RUNNING_INSTANCE_INFO_ - -#include -#include -#include -#include -#include -#include "lib/PlaYUVerDefs.h" -#include "PlaYUVerAppAdaptor.h" - -namespace plaYUVer -{ - -class RunningInstanceInfo: public QObject -{ -Q_OBJECT - -public: - RunningInstanceInfo( const QString &serviceName_ ) : - QObject(), - valid( false ), - serviceName( serviceName_ ), - dbus_if( new QDBusInterface( serviceName_, QStringLiteral( PLAYUVER_DBUS_PATH ), QString(), //I don't know why it does not work if I specify org.pixlra.PlaYUVer.application here - QDBusConnection::sessionBus(), this ) ) - { - if( !dbus_if->isValid() ) - { - std::cerr << qPrintable( QDBusConnection::sessionBus().lastError().message() ) - << std::endl; - } -// QVariant a_s = dbus_if->property( "activeSession" ); -// std::cerr< RunningInstanceInfoMap; - -Q_DECL_EXPORT bool fillinRunningAppInstances( RunningInstanceInfoMap *map ); -Q_DECL_EXPORT void cleanupRunningAppInstanceMap( RunningInstanceInfoMap *map ); - -} // NAMESPACE - -#endif // _PLAYUVER_RUNNING_INSTANCE_INFO_ - diff --git a/app/main.cpp b/app/main.cpp index 6f0d5df..ebe080b 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -30,7 +30,6 @@ #include #include #include "PlaYUVerAppAdaptor.h" -#include "RunningInstanceInfo.h" #include "plaYUVerApp.h" #include "SubWindowHandle.h" #ifdef USE_FERVOR @@ -61,42 +60,9 @@ int main( int argc, char *argv[] ) QDBusConnectionInterface * const sessionBusInterface = QDBusConnection::sessionBus().interface(); if( sessionBusInterface ) { - RunningInstanceInfoMap mapSessionRii; - if( !fillinRunningAppInstances( &mapSessionRii ) ) - { - return 1; - } - QStringList playuverServices; - for( RunningInstanceInfoMap::const_iterator it = mapSessionRii.constBegin(); it != mapSessionRii.constEnd(); ++it ) - { - playuverServices << ( *it )->serviceName; - } - QString serviceName; - //const QStringList urls = parser.positionalArguments(); Bool force_new = false; - - //cleanup map - cleanupRunningAppInstanceMap( &mapSessionRii ); - - //if no new instance is forced and no already opened session is requested, - //check if a pid is given, which should be reused. - // two possibilities: pid given or not... -// if( ( !force_new ) && serviceName.isEmpty() ) -// { -// if( /*( parser.isSet( usePidOption ) )*/|| ( !qgetenv( "PLAYUVER_PID" ).isEmpty() ) ) -// { -// QString usePid = ( parser.isSet( usePidOption ) ) ? parser.value( usePidOption ) : QString::fromLocal8Bit( qgetenv( "KATE_PID" ) ); -// -// serviceName = QStringLiteral("org.kde.kate-")+ usePid; -// if( !playuverServices.contains( serviceName ) ) -// { -// serviceName.clear(); -// } -// } -// } - QStringList filenameList; for( Int i = 1; i < argc; i++ ) { @@ -107,26 +73,18 @@ int main( int argc, char *argv[] ) force_new = true; } - if( ( !force_new ) && ( serviceName.isEmpty() ) ) - { - if( playuverServices.count() > 0 ) - { - serviceName = playuverServices[0]; - } - } - //check again if service is still running bool foundRunningService = false; - if( !serviceName.isEmpty() ) + if( !force_new ) { - QDBusReply there = sessionBusInterface->isServiceRegistered( serviceName ); + QDBusReply there = sessionBusInterface->isServiceRegistered( PLAYUVER_DBUS_SESSION_NAME ); foundRunningService = there.isValid() && there.value(); } if( foundRunningService ) { // open given session - QDBusMessage m = QDBusMessage::createMethodCall( serviceName, QStringLiteral( PLAYUVER_DBUS_PATH ), QStringLiteral( PLAYUVER_DBUS_SESSION_NAME ), + QDBusMessage m = QDBusMessage::createMethodCall( PLAYUVER_DBUS_SESSION_NAME, QStringLiteral( PLAYUVER_DBUS_PATH ), QStringLiteral( PLAYUVER_DBUS_SESSION_NAME ), QStringLiteral( "activate" ) ); QDBusConnection::sessionBus().call( m ); @@ -138,13 +96,11 @@ int main( int argc, char *argv[] ) // open given files... foreach(const QString & file, filenameList){ - QDBusMessage m = QDBusMessage::createMethodCall(serviceName, + QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); QList dbusargs; - dbusargs.append( file ); - m.setArguments(dbusargs); QDBusMessage res = QDBusConnection::sessionBus().call(m); From 94d7f0e0fe652632069d4442f3d4d0ec42a6f4cb Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 26 Nov 2014 00:07:01 +0000 Subject: [PATCH 05/10] Format code --- app/main.cpp | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index ebe080b..94ddd34 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -61,7 +61,6 @@ int main( int argc, char *argv[] ) if( sessionBusInterface ) { - Bool force_new = false; QStringList filenameList; for( Int i = 1; i < argc; i++ ) @@ -84,8 +83,8 @@ int main( int argc, char *argv[] ) if( foundRunningService ) { // open given session - QDBusMessage m = QDBusMessage::createMethodCall( PLAYUVER_DBUS_SESSION_NAME, QStringLiteral( PLAYUVER_DBUS_PATH ), QStringLiteral( PLAYUVER_DBUS_SESSION_NAME ), - QStringLiteral( "activate" ) ); + QDBusMessage m = QDBusMessage::createMethodCall( PLAYUVER_DBUS_SESSION_NAME, QStringLiteral( PLAYUVER_DBUS_PATH ), + QStringLiteral( PLAYUVER_DBUS_SESSION_NAME ), QStringLiteral( "activate" ) ); QDBusConnection::sessionBus().call( m ); @@ -95,33 +94,33 @@ int main( int argc, char *argv[] ) QStringList tokens; // open given files... - foreach(const QString & file, filenameList){ - QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, - QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); - - QList dbusargs; - dbusargs.append( file ); - m.setArguments(dbusargs); - - QDBusMessage res = QDBusConnection::sessionBus().call(m); - if (res.type() == QDBusMessage::ReplyMessage) + foreach(const QString & file, filenameList) { - if (res.arguments().count() == 1) + QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, + QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); + + QList dbusargs; + dbusargs.append( file ); + m.setArguments(dbusargs); + + QDBusMessage res = QDBusConnection::sessionBus().call(m); + if (res.type() == QDBusMessage::ReplyMessage) { - QVariant v = res.arguments()[0]; - if (v.isValid()) + if (res.arguments().count() == 1) { - QString s = v.toString(); - if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) + QVariant v = res.arguments()[0]; + if (v.isValid()) { - tokens << s; + QString s = v.toString(); + if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) + { + tokens << s; + } } } } } - } - - // this will wait until exiting is emitted by the used instance, if wanted... + // this will wait until exiting is emitted by the used instance, if wanted... return needToBlock ? application.exec() : 0; } } From e41ca8d9494ef931f6a641ee49e7c4edaf0f28b8 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 2 Dec 2014 20:01:35 +0000 Subject: [PATCH 06/10] Add Qt DBus as optional dependency in order to be compatible with windows --- CMakeLists.txt | 64 ++++++++++++++++++++++++---------------- app/CMakeLists.txt | 5 +++- app/PlaYUVerAppAdaptor.h | 4 +++ app/main.cpp | 13 ++++---- app/plaYUVerApp.cpp | 9 ++++-- app/plaYUVerApp.h | 2 +- config.h.in | 3 ++ 7 files changed, 63 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08ec998..b5ab0c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,44 @@ OPTION( USE_QT4 "Build with QT4" OFF ) ADD_FEATURE_INFO(Fervor USE_FERVOR "Fervor lib includes check for updates feature.") ADD_FEATURE_INFO(WErrors PLAYUVER_WERROR "Warnings as errors" ) +##################################################################################### +# Qt library +###################################################################################### + +IF( USE_QT4 ) + SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT4" ) + FIND_PACKAGE( Qt4 REQUIRED COMPONENTS QtCore QtGui QtNetwork QtWebKit ) + FIND_PACKAGE( Qt4 COMPONENTS QtDBus ) + IF( NOT QT4_FOUND ) + SET(USE_QT4 FALSE) + ELSE() + INCLUDE( ${QT_USE_FILE} ) + ADD_DEFINITIONS( ${QT_DEFINITIONS} ) + SET( QT_LINKER_LIBS ${QT_LIBRARIES} ) + ENDIF() +ENDIF() + +IF( NOT USE_QT4 ) + + SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) + + FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets ) +# # FIND_PACKAGE( Qt5 COMPONENTS DBus ) + + + LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets ) + LIST(APPEND QT_MODULES Core Gui Widgets ) + IF( ${Qt5DBus_FOUND} ) + SET( USE_QTDBUS ${Qt5DBus_FOUND} ) + LIST(APPEND QT_LINKER_LIBS Qt5::DBus ) + LIST(APPEND QT_MODULES DBus ) + ENDIF() + + INCLUDE_DIRECTORIES( ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) + SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}" ) + +ENDIF() + ###################################################################################### # Dependencies ###################################################################################### @@ -64,32 +102,6 @@ IF( WIN32 ) INCLUDE( cmake/Win32.cmake ) ENDIF() -##################################################################################### -# Qt library -###################################################################################### - -IF( USE_QT4 ) - SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT4" ) - FIND_PACKAGE( Qt4 REQUIRED QtCore QtGui QtNetwork QtWebKit ) - IF( NOT QT4_FOUND ) - SET(USE_QT4 FALSE) - ELSE() - INCLUDE( ${QT_USE_FILE} ) - ADD_DEFINITIONS( ${QT_DEFINITIONS} ) - SET( QT_LINKER_LIBS ${QT_LIBRARIES} ) - ENDIF() -ENDIF() - -IF( NOT USE_QT4 ) - SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) - FIND_PACKAGE( Qt5 REQUIRED Core Gui Widgets DBus ) - INCLUDE_DIRECTORIES( ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) - # Add compiler flags for building executables (-fPIE) - SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}" ) - LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus ) - LIST(APPEND QT_MODULES Core Gui Widgets ) -ENDIF() - ###################################################################################### # Configuration ###################################################################################### diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2ff5b94..1ef8d42 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -15,7 +15,6 @@ set(plaYUver_App_SRCS PlaYUVerAppModuleIf.cpp GridManager.cpp Settings.cpp - PlaYUVerAppAdaptor.cpp # Dialogs AboutDialog.cpp ConfigureFormatDialog.cpp @@ -31,6 +30,10 @@ set(plaYUver_App_SRCS WidgetFrameNumber.cpp ) +IF( USE_QTDBUS ) + LIST( APPEND plaYUver_App_SRCS PlaYUVerAppAdaptor.cpp ) +ENDIF() + set(plaYUver_App_UI "" ) set(plaYUver_App_RCC diff --git a/app/PlaYUVerAppAdaptor.h b/app/PlaYUVerAppAdaptor.h index 55a0b23..e85f531 100644 --- a/app/PlaYUVerAppAdaptor.h +++ b/app/PlaYUVerAppAdaptor.h @@ -25,6 +25,10 @@ #ifndef __PlaYUVerAppAdaptor_H__ #define __PlaYUVerAppAdaptor_H__ +#include +#include +#include +#include #include #include diff --git a/app/main.cpp b/app/main.cpp index 94ddd34..274c42e 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -25,13 +25,11 @@ #include "config.h" #include "lib/PlaYUVerDefs.h" #include -#include -#include -#include -#include -#include "PlaYUVerAppAdaptor.h" #include "plaYUVerApp.h" #include "SubWindowHandle.h" +#ifdef USE_QTDBUS +#include "PlaYUVerAppAdaptor.h" +#endif #ifdef USE_FERVOR #include "fvupdater.h" #endif @@ -53,6 +51,7 @@ int main( int argc, char *argv[] ) QApplication::setOrganizationName( "pixlra" ); QApplication::setOrganizationDomain( "playuver.pixlra" ); +#ifdef USE_QTDBUS /** * use dbus, if available * allows for resuse of running Kate instances @@ -128,6 +127,8 @@ int main( int argc, char *argv[] ) /** * if we arrive here, we need to start a new playuver instance! */ + QDBusConnection::sessionBus().registerService( PLAYUVER_DBUS_SESSION_NAME ); +#endif plaYUVerApp mainwindow; mainwindow.show(); mainwindow.parseArgs( argc, argv ); @@ -136,7 +137,7 @@ int main( int argc, char *argv[] ) FvUpdater::sharedUpdater()->SetDependencies(DEPENDENCIES_STRING); #endif - QDBusConnection::sessionBus().registerService( PLAYUVER_DBUS_SESSION_NAME ); + return application.exec(); } diff --git a/app/plaYUVerApp.cpp b/app/plaYUVerApp.cpp index 3269bf0..933ca2e 100644 --- a/app/plaYUVerApp.cpp +++ b/app/plaYUVerApp.cpp @@ -27,6 +27,9 @@ #ifdef USE_FERVOR #include "fvupdater.h" #endif +#ifdef USE_QTDBUS +#include "PlaYUVerAppAdaptor.h" +#endif #include "plaYUVerApp.h" #include "DialogSubWindowSelector.h" @@ -43,13 +46,13 @@ plaYUVerApp::plaYUVerApp() setWindowModality( Qt::ApplicationModal ); - // dbus + // DBus +#ifdef USE_QTDBUS m_pDBusAdaptor = new PlaYUVerAppAdaptor(this); +#endif mdiArea = new PlaYUVerMdiArea; setCentralWidget( mdiArea ); - //mdiArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); - //mdiArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); mdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder ); connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( chageSubWindowSelection() ) ); diff --git a/app/plaYUVerApp.h b/app/plaYUVerApp.h index feb498c..487ab7b 100644 --- a/app/plaYUVerApp.h +++ b/app/plaYUVerApp.h @@ -33,7 +33,6 @@ #endif #include #include "lib/PlaYUVerDefs.h" -#include "PlaYUVerAppAdaptor.h" #include "SubWindowHandle.h" #include "ModulesHandle.h" #include "PropertiesSidebar.h" @@ -45,6 +44,7 @@ namespace plaYUVer { class PlaYUVerStream; +class PlaYUVerAppAdaptor; class plaYUVerApp: public QMainWindow { diff --git a/config.h.in b/config.h.in index 8e7c4a0..fd3f5b0 100644 --- a/config.h.in +++ b/config.h.in @@ -45,6 +45,9 @@ #define QT_VERSION_PLAYUVER 4 #endif +/* QtDBus */ +#cmakedefine USE_QTDBUS + #cmakedefine PLAYUVER_THREADED_MODULES /* OpenCV */ From afbba5c72d0c87b08cc5761fa0e9fdc167804910 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 2 Dec 2014 20:02:59 +0000 Subject: [PATCH 07/10] Update debian dependencies --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5ab0c7..4e7af7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,11 +144,11 @@ SET(CPACK_PACKAGE_ARCHITECTURE "amd64") IF( USE_QT4 ) SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT4" ) - LIST(APPEND CPACK_DEBIAN_PACKAGE_DEPENDS "libqtcore4 (>= 4:4.8.5), libqtgui4 (>= 4:4.8.5)" ) + LIST(APPEND CPACK_DEBIAN_PACKAGE_DEPENDS "libqtcore4 (>= 4:4.8.5), libqtgui4 (>= 4:4.8.5), libqt4-dbus (>= 4:4.8.5)" ) SET( APPEND_VERSION "${APPEND_VERSION}_wQT4" ) ELSE() SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) - LIST(APPEND CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5core5a (>= 5.2.1~), libqt5gui5 (>= 5.2.1~), libqt5widgets5 (>= 5.2.1~)") + LIST(APPEND CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5core5a (>= 5.2.1~), libqt5gui5 (>= 5.2.1~), libqt5widgets5 (>= 5.2.1~), libqt5dbus5 (>= 5.2.1~)") SET( APPEND_VERSION "${APPEND_VERSION}_wQT5" ) ENDIF() From 8c9eddaf8f97187316232d2a26801cc9a6516051 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 2 Dec 2014 20:22:07 +0000 Subject: [PATCH 08/10] Fix minor bugs reagarding qtdbus --- CMakeLists.txt | 6 ++++-- app/plaYUVerApp.cpp | 4 ---- app/plaYUVerApp.h | 3 +++ cmake/Win32.cmake | 2 ++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e7af7c..a1bddf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,9 @@ ADD_FEATURE_INFO(WErrors PLAYUVER_WERROR "Warnings as errors" ) IF( USE_QT4 ) SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT4" ) FIND_PACKAGE( Qt4 REQUIRED COMPONENTS QtCore QtGui QtNetwork QtWebKit ) - FIND_PACKAGE( Qt4 COMPONENTS QtDBus ) + + SET( USE_QTDBUS FALSE ) + IF( NOT QT4_FOUND ) SET(USE_QT4 FALSE) ELSE() @@ -64,7 +66,7 @@ IF( NOT USE_QT4 ) SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets ) -# # FIND_PACKAGE( Qt5 COMPONENTS DBus ) +# FIND_PACKAGE( Qt5 COMPONENTS DBus ) LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets ) diff --git a/app/plaYUVerApp.cpp b/app/plaYUVerApp.cpp index 933ca2e..0a51794 100644 --- a/app/plaYUVerApp.cpp +++ b/app/plaYUVerApp.cpp @@ -27,10 +27,6 @@ #ifdef USE_FERVOR #include "fvupdater.h" #endif -#ifdef USE_QTDBUS -#include "PlaYUVerAppAdaptor.h" -#endif - #include "plaYUVerApp.h" #include "DialogSubWindowSelector.h" #include "WidgetFrameNumber.h" diff --git a/app/plaYUVerApp.h b/app/plaYUVerApp.h index 487ab7b..9d80e1f 100644 --- a/app/plaYUVerApp.h +++ b/app/plaYUVerApp.h @@ -31,6 +31,9 @@ #elif( QT_VERSION_PLAYUVER == 4 ) #include #endif +#ifdef USE_QTDBUS +#include "PlaYUVerAppAdaptor.h" +#endif #include #include "lib/PlaYUVerDefs.h" #include "SubWindowHandle.h" diff --git a/cmake/Win32.cmake b/cmake/Win32.cmake index 4f16659..e15a435 100644 --- a/cmake/Win32.cmake +++ b/cmake/Win32.cmake @@ -2,6 +2,8 @@ # DLLs and Win32 specific code ###################################################################################### +SET( USE_QTDBUS FALSE ) + foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "." ) From febc41719e199537eda57e59774744ac0b3f38e3 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 3 Dec 2014 15:25:59 +0000 Subject: [PATCH 09/10] Change PlaYUVerStream in order to handle different interfaces to read and write streams --- lib/LibAvContextHandle.cpp | 5 ++ lib/PlaYUVerStream.cpp | 112 +++++++++++++++++++++---------------- lib/PlaYUVerStream.h | 8 +++ 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/lib/LibAvContextHandle.cpp b/lib/LibAvContextHandle.cpp index b29ebe4..a813359 100644 --- a/lib/LibAvContextHandle.cpp +++ b/lib/LibAvContextHandle.cpp @@ -191,6 +191,11 @@ Bool LibAvContextHandle::initAvFormat( char* filename, UInt& width, UInt& height break; } } + if( pixel_format == PlaYUVerFrame::NO_FMT ) + { + closeAvFormat(); + return false; + } /* dump input information to stderr */ av_dump_format( fmt_ctx, 0, src_filename, 0 ); diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 59cb8a1..33605be 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -41,7 +41,7 @@ PlaYUVerStream::PlaYUVerStream() m_bIsOpened = false; m_bLoadAll = false; m_iErrorStatus = 0; - + m_uiStreamHandler = 0; m_pFile = NULL; m_uiWidth = 0; m_uiHeight = 0; @@ -70,8 +70,6 @@ PlaYUVerStream::~PlaYUVerStream() Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput ) { - Bool avStatus = false; - if( m_bInit ) { close(); @@ -103,11 +101,15 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ } m_cFormatName = PlaYUVerStream::supportedReadFormatsExt().at( m_iFileFormat ).toUpper(); + if( m_iFileFormat == YUVINPUT ) + { + m_uiStreamHandler = YUV_IO; + } + #ifdef USE_FFMPEG if( m_iFileFormat != YUVINPUT ) { - avStatus = m_cLibAvContext->initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate, m_uiTotalFrameNum ); - m_cCodedName = QString::fromUtf8( m_cLibAvContext->getCodecName() ).toUpper(); + m_uiStreamHandler = FFMPEG; } #endif #if 0 @@ -126,9 +128,21 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ else { m_iFileFormat = YUVOUTPUT; + m_uiStreamHandler = YUV_IO; m_uiFrameBufferSize = 1; } +#ifdef USE_FFMPEG + if( m_uiStreamHandler == FFMPEG ) + { + if( !m_cLibAvContext->initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate, m_uiTotalFrameNum ) ) + { + throw "Cannot open file using FFmpeg libs"; + } + m_cCodedName = QString::fromUtf8( m_cLibAvContext->getCodecName() ).toUpper(); + } +#endif + if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 ) { close(); @@ -136,6 +150,18 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ return m_bInit; } + if( m_uiStreamHandler == YUV_IO ) + { + if( !openFile() ) + { + close(); + throw "[PlaYUVerStream] Cannot open file"; + return m_bInit; + } + m_cFormatName = QString::fromUtf8( "YUV" ); + m_cCodedName = QString::fromUtf8( "Raw Video" ); + } + getMem1D( &m_ppcFrameBuffer, m_uiFrameBufferSize ); for( UInt i = 0; i < m_uiFrameBufferSize; i++ ) { @@ -152,37 +178,21 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); - if( !avStatus ) + if( m_uiStreamHandler == YUV_IO && m_bIsInput ) { - if( !openFile() ) + fseek( m_pFile, 0, SEEK_END ); + UInt64 fileSize = ftell( m_pFile ); +#if 0 + if( fileSize % frame_bytes_input ) { + Int remaining = fileSize % frame_bytes_input; close(); - throw "[PlaYUVerStream] Cannot open file"; + throw "[PlaYUVerStream] Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )"; return m_bInit; } - m_cFormatName = QString::fromUtf8( "YUV" ); - m_cCodedName = QString::fromUtf8( "Raw Video" ); - } - - if( !avStatus && m_iFileFormat == YUVINPUT ) - { - if( m_bIsInput ) - { - fseek( m_pFile, 0, SEEK_END ); - UInt64 fileSize = ftell( m_pFile ); -#if 0 - if( fileSize % frame_bytes_input ) - { - Int remaining = fileSize % frame_bytes_input; - close(); - throw "[PlaYUVerStream] Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )"; - return m_bInit; - } #endif - m_uiTotalFrameNum = fileSize / frame_bytes_input; - fseek( m_pFile, 0, SEEK_SET ); - } - + m_uiTotalFrameNum = fileSize / frame_bytes_input; + fseek( m_pFile, 0, SEEK_SET ); } if( m_bIsInput && m_uiTotalFrameNum <= 0 ) @@ -200,7 +210,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ } m_cStreamInformationString = "[" + m_cFormatName + " / " + m_cCodedName + " / " + PlaYUVerFrame::supportedPixelFormatListNames().at( m_iPixelFormat ) + "] " - + QFileInfo( m_cFilename ).fileName(); + + QFileInfo( m_cFilename ).fileName(); m_iCurrFrameNum = -1; @@ -238,10 +248,12 @@ Void PlaYUVerStream::close() if( !m_bInit ) return; - closeFile(); + if( m_uiStreamHandler == YUV_IO ) + closeFile(); #ifdef USE_FFMPEG - m_cLibAvContext->closeAvFormat(); + if( m_uiStreamHandler == FFMPEG ) + m_cLibAvContext->closeAvFormat(); #endif if( m_ppcFrameBuffer ) @@ -468,7 +480,7 @@ Void PlaYUVerStream::readFrame() } #ifdef USE_FFMPEG - if( m_cLibAvContext->getStatus() ) + if( m_uiStreamHandler == FFMPEG ) { if( !m_cLibAvContext->decodeAvFormat() ) { @@ -477,8 +489,8 @@ Void PlaYUVerStream::readFrame() } m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize ); } - else #endif + if( m_uiStreamHandler == YUV_IO ) { UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame(); UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); @@ -497,24 +509,30 @@ Void PlaYUVerStream::readFrame() Void PlaYUVerStream::writeFrame() { - UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); - m_pcCurrFrame->frameToBuffer( m_pStreamBuffer ); - UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); - if( bytes_read != frame_bytes_input ) + if( m_uiStreamHandler == YUV_IO ) { - m_iErrorStatus = WRITING; + UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); + m_pcCurrFrame->frameToBuffer( m_pStreamBuffer ); + UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); + if( bytes_read != frame_bytes_input ) + { + m_iErrorStatus = WRITING; + } } return; } Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame ) { - UInt64 frame_bytes_input = pcFrame->getBytesPerFrame(); - pcFrame->frameToBuffer( m_pStreamBuffer ); - UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); - if( bytes_read != frame_bytes_input ) + if( m_uiStreamHandler == YUV_IO ) { - m_iErrorStatus = WRITING; + UInt64 frame_bytes_input = pcFrame->getBytesPerFrame(); + pcFrame->frameToBuffer( m_pStreamBuffer ); + UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); + if( bytes_read != frame_bytes_input ) + { + m_iErrorStatus = WRITING; + } } return; } @@ -604,12 +622,12 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num ) return true; } #ifdef USE_FFMPEG - if( m_cLibAvContext->getStatus() ) + if( m_uiStreamHandler == FFMPEG ) { m_cLibAvContext->seekAvFormat( new_frame_num ); } - else #endif + if( m_uiStreamHandler == YUV_IO ) { UInt64 frame_bytes_input = m_ppcFrameBuffer[0]->getBytesPerFrame(); UInt64 nbytes_seek = frame_bytes_input * new_frame_num; diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index 505ad2f..a0e35e4 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -47,6 +47,14 @@ private: Bool m_bLoadAll; Int m_iErrorStatus; + enum PlaYUVerStreamHandlers + { + INVALID_HANDLER = -1, + YUV_IO, + FFMPEG, + TOTAL_HANDLERR + }; + UInt m_uiStreamHandler; LibAvContextHandle* m_cLibAvContext; QString m_cFilename; From 39d70f43413353429afd452198ecd0106add2cb8 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 8 Dec 2014 12:33:11 +0000 Subject: [PATCH 10/10] Fix CMakelists --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1bddf6..534db2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ IF( NOT USE_QT4 ) SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets ) -# FIND_PACKAGE( Qt5 COMPONENTS DBus ) + FIND_PACKAGE( Qt5 COMPONENTS DBus ) LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets )