First effort to use DBus to communicate between apps. Enable opening the new sequence in the existing session

This commit is contained in:
jfmcarreira committed 2014-11-24 01:18:07 +00:00
1 parent 6508a93e86
commit 069a8c261c
8 files changed
+470 -21

No files matched your search

+121 -9
View File
@@ -23,8 +23,14 @@
*/
#include "config.h"
#include "lib/PlaYUVerDefs.h"
#include <QApplication>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusReply>
#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>("PlaYUVerStreamInfoVector");
qRegisterMetaTypeStreamOperators<PlaYUVerStreamInfoVector>("PlaYUVerStreamInfoVector");
qRegisterMetaType<PlaYUVerStreamInfoVector>( "PlaYUVerStreamInfoVector" );
qRegisterMetaTypeStreamOperators<PlaYUVerStreamInfoVector>( "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<bool> 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<QVariant> 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();
}