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

+2
View File
@@ -15,6 +15,8 @@ set(plaYUver_App_SRCS
PlaYUVerAppModuleIf.cpp
GridManager.cpp
Settings.cpp
PlaYUVerAppAdaptor.cpp
RunningInstanceInfo.cpp
# Dialogs
AboutDialog.cpp
ConfigureFormatDialog.cpp
+70
View File
@@ -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 <QDBusAbstractAdaptor>
#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
+83
View File
@@ -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 <QtDBus>
#include <QtCore>
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__
+83
View File
@@ -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 <QDBusReply>
#include <QStringList>
#include <QCoreApplication>
#include <QDBusConnectionInterface>
#include <QDebug>
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<QStringList> 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<<qPrintable(s)<<"running instance:"<< rii->sessionName.toUtf8().data()<<std::endl;
} else {
delete rii;
}
}
}
return true;
}
void cleanupRunningAppInstanceMap(RunningInstanceInfoMap *map)
{
for (RunningInstanceInfoMap::const_iterator it = map->constBegin(); it != map->constEnd(); ++it) {
delete it.value();
}
map->clear();
}
} // NAMESPACE
+100
View File
@@ -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 <iostream>
#include <QMap>
#include <QDBusInterface>
#include <QDBusConnection>
#include <QVariant>
#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<<a_s.isValid()<<std::endl;
// std::cerr<<"property:"<<qPrintable(a_s.toString())<<std::endl;
// std::cerr<<qPrintable(QDBusConnection::sessionBus().lastError().message())<<std::endl;
// if( !a_s.isValid() )
// {
// sessionName = QString::fromLatin1( "___NO_SESSION_OPENED__%1" ).arg( dummy_session++ );
// valid = false;
// }
// else
{
// if( a_s.toString().isEmpty() )
// {
sessionName = QString::fromLatin1( "___DEFAULT_CONSTRUCTED_SESSION__%1" ).arg( dummy_session++ );
// }
// else
// {
// sessionName = a_s.toString();
// }
valid = true;
}
}
;
virtual ~RunningInstanceInfo()
{
delete dbus_if;
}
Bool valid;
const QString serviceName;
QDBusInterface *dbus_if;
QString sessionName;
private:
static Int dummy_session;
};
typedef QMap<QString, RunningInstanceInfo *> RunningInstanceInfoMap;
Q_DECL_EXPORT bool fillinRunningAppInstances( RunningInstanceInfoMap *map );
Q_DECL_EXPORT void cleanupRunningAppInstanceMap( RunningInstanceInfoMap *map );
} // NAMESPACE
#endif // _PLAYUVER_RUNNING_INSTANCE_INFO_
+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();
}
+7 -9
View File
@@ -22,19 +22,14 @@
* \brief Main definition of the plaYUVerApp app
*/
#include "plaYUVerApp.h"
#include "lib/PlaYUVerStream.h"
#include "DialogSubWindowSelector.h"
#include <QtDebug>
#ifdef USE_FERVOR
#include "fvupdater.h"
#endif
#if( QT_VERSION_PLAYUVER == 5 )
#include <QtWidgets>
#elif( QT_VERSION_PLAYUVER == 4 )
#include <QtGui>
#endif
#include <QtDebug>
#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 );
+4 -3
View File
@@ -26,13 +26,14 @@
#define __PLAYUVERAPP_H__
#include "config.h"
#include "lib/PlaYUVerDefs.h"
#if( QT_VERSION_PLAYUVER == 5 )
#include <QtWidgets>
#elif( QT_VERSION_PLAYUVER == 4 )
#include <QtGui>
#endif
#include <QMainWindow>
#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();