From f8c4bc023150ac19c25f8f1c75158c1a5fbe0e61 Mon Sep 17 00:00:00 2001 From: Dirk Wilden Date: Wed, 1 Sep 2010 17:11:20 +0000 Subject: [PATCH] extended backupInterface git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9952 383ad7c9-94d9-4d36-a494-682f7c89f535 --- BasePlugin/BackupInterface.hh | 54 ++++++++++++++++++++++++++++++----- Core/BackupCommunication.cc | 23 +++++++++++++-- Core/Core.cc | 1 + Core/Core.hh | 19 ++++++++++-- Core/PluginLoader.cc | 38 +++++++++++++++++++----- 5 files changed, 117 insertions(+), 18 deletions(-) diff --git a/BasePlugin/BackupInterface.hh b/BasePlugin/BackupInterface.hh index 3540f953..e7293393 100644 --- a/BasePlugin/BackupInterface.hh +++ b/BasePlugin/BackupInterface.hh @@ -74,6 +74,17 @@ class BackupInterface { //=========================================================================== signals: + + /** \brief Tell Backup Plugin to create a backup group + * + * A backup group can be used to combine multiple object backups into + * one backup group and undo all of them at once + * + * @param _name Name of the Backup group, to show the user what can be recovered + * @param _groupId A unique identifier for the created backup group + */ + virtual void createBackupGroup(QString /*_name*/, int& /*_groupId*/) {}; + /** \brief Tell Backup Plugin to create a backup * * Plugins which supports backups can call this function if they want to create backups.\n @@ -82,7 +93,7 @@ class BackupInterface { * @param _name Name of the Backup, to show the user what can be recovered * @param _internalId A unique identifier for the created backup */ - virtual void createBackup( int /*_objectid*/, QString /*_name*/, int& /*_internalId*/) {}; + virtual void createBackup( int /*_objectid*/, QString /*_name*/, int& /*_internalId*/, int /*_groupId*/ = -1) {}; /** \brief Tell Backup Plugin to create a backup but don't get the id of the object ( if you don't care ) * @@ -91,7 +102,7 @@ class BackupInterface { * @param _objectid Identifier of the object to create the backup * @param _name Name of the Backup, to show the user what can be recovered */ - virtual void createBackup( int /*_objectid*/, QString /*_name*/) {}; + virtual void createBackup( int /*_objectid*/, QString /*_name*/) {}; /** \brief Make a backup persistent. @@ -109,7 +120,15 @@ class BackupInterface { * @param _internalId The unique identifier of the restore set (-1 for last backup) */ virtual void restoreObject( int /*_objectid*/, int _internalId =-1) {}; - + + /** \brief Tell Backup Plugin to restore a backup group + * + * Plugins which supports backups can call this function if they want to restore backups.\n + * A Backup control Plugin will do the rest. + * @param _groupId Identifier of the group to restore + */ + virtual void restoreGroup( int /*_groupId*/ ) {}; + private slots: /** \brief Backup for an object requested * @@ -119,7 +138,17 @@ class BackupInterface { * @param _name Name of the Backup, to show the user what can be recovered * @param _internalId Unique identifier of the backup. This number is generated by the core and returned by the original signal. */ - virtual void slotBackup( int /*_objectid*/ , QString /*_name*/ , int /*_internalId*/) {} ; + virtual void slotBackup( int /*_objectid*/ , QString /*_name*/ , int /*_internalId*/, int /*_groupId*/ = -1) {}; + + /** \brief Backup group requested + * + * This function will be called if a plugin requests a backup group. You can + * also react on this event if you reimplement this function in your plugin. + * + * @param _name Name of the Backup group, to show the user what can be recovered + * @param _groupId Unique identifier of the backup group. This number is generated by the core and returned by the original signal. + */ + virtual void slotBackupGroup( QString /*_name*/ , int /*_groupId*/) {}; /** \brief A given object will be restored. * @@ -144,7 +173,7 @@ class BackupInterface { * @param _objectid Identifier of the object which is about to be restored * @param _internalId Unique Number of the Restore set */ - virtual void slotRestore( int /*_objectid*/ , int /*_internalId*/) {}; + virtual void slotRestore( int /*_objectid*/ , int /*_internalId*/) {}; /** \brief Object fully restored * @@ -155,7 +184,7 @@ class BackupInterface { * @param _internalId Unique Number of the Restore set */ virtual void slotRestored( int /*_objectid*/, int /*_internalId*/) {}; - + public : /// Destructor @@ -197,7 +226,18 @@ class BackupInterface { * @param _objectId Object to restore * */ - virtual void slotRestoreObject(int /*_objectid*/ , QString /*_name*/ , int /*_internalId*/) {}; + virtual void slotRestoreObject(int /*_objectid*/, int /*_internalId*/) {}; + + /** \brief Restore the a group + * + * This function has to be implemented in the backup management plugin. Normally + * this function is provided by the default backup plugin and should not be used! + * To restore data in your plugin use the slotRestore above. + * + * @param _groupId group to restore + * + */ + virtual void slotRestoreGroup(int /*_groupid*/) {}; virtual void slotMakeBackupPersistent(int /*_objectid*/, int /*_internalId*/) {}; diff --git a/Core/BackupCommunication.cc b/Core/BackupCommunication.cc index f5f6f882..f2d6bbcc 100644 --- a/Core/BackupCommunication.cc +++ b/Core/BackupCommunication.cc @@ -62,8 +62,23 @@ // === Backup Communication ============================ //======================================================================================== +void Core::slotBackupGroup(QString _name, int& _groupId ) { + if ( sender() != 0 ) { + if ( sender()->metaObject() != 0 ) { + _name = QString(sender()->metaObject()->className()) + ": " + _name; + + if ( OpenFlipper::Options::doSlotDebugging() ) + emit log(LOGINFO,"slotBackupGroup( " + _name + " ) called by " + QString( sender()->metaObject()->className() ) ); + } + } + + _groupId = nextBackupGroupId_; + emit createBackupGroup( _name , nextBackupGroupId_); + ++nextBackupGroupId_; +} + /// Called if a backup is requested by the plugins -void Core::slotBackup( int _objectId, QString _name, int& _internalId ) { +void Core::slotBackup( int _objectId, QString _name, int& _internalId, int _groupId ) { if ( sender() != 0 ) { if ( sender()->metaObject() != 0 ) { _name = QString(sender()->metaObject()->className()) + ": " + _name; @@ -75,7 +90,7 @@ void Core::slotBackup( int _objectId, QString _name, int& _internalId ) { } _internalId = nextBackupId_; - emit createBackup( _objectId , _name , nextBackupId_); + emit createBackup( _objectId , _name , nextBackupId_, _groupId); ++nextBackupId_; } @@ -95,6 +110,10 @@ void Core::slotBackup( int _objectId, QString _name ) { ++nextBackupId_; } +void Core::slotRestoreGroup( int _groupId) { + emit restoreGroup(_groupId); +} + void Core::slotRestore( int _objectId, int _internalId ) { emit restoreObject(_objectId,_internalId); } diff --git a/Core/Core.cc b/Core/Core.cc index 689e39ac..37c50413 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -122,6 +122,7 @@ Core() : capture_(false), processManager_(0), nextBackupId_(0), + nextBackupGroupId_(0), objectRoot_(0), coreWidget_(0) { diff --git a/Core/Core.hh b/Core/Core.hh index b91848a0..fbcf91b9 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -263,12 +263,18 @@ signals: /// This signal is emitted before the core deletes its data and exits void saveOnExit( INIFile& _ini ); + /// Tell plugins to create a backup group + void createBackupGroup( QString _name , int _groupId); + /// Tell plugins to create a backup - void createBackup( int _objectId , QString _name , int _internalId); + void createBackup( int _objectId , QString _name , int _internalId, int groupId = -1); /// Tell Plugins to make a backup persistent void makeBackupPersistent(int _objectid, int _internalId); + /// Tell Backup Plugin to restore a group with the given group id + void restoreGroup( int _groupId); + /// Tell Backup Plugin to restore an object with the given backup id void restoreObject( int _objectId, int _internalId); @@ -385,11 +391,17 @@ signals: ///Called by plugins if a multi-texture's sub textures should be fetched void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ); + /// Called if a backup group is requested by the plugins + void slotBackupGroup(QString _name, int& _groupId ); + /// Called if a backup is requested by the plugins - void slotBackup( int _objectId, QString _name, int& _internalId ); + void slotBackup( int _objectId, QString _name, int& _internalId, int _groupId = -1 ); /// Called if a backup is requested by the plugins void slotBackup( int _objectId, QString _name ); + + /// Called if a group restore is requested by the plugins + void slotRestoreGroup( int _groupId); /// Called if a backup is requested by the plugins void slotRestore( int _objectId, int _internalId = -1 ); @@ -1134,6 +1146,9 @@ private slots: /// Id for the next backup int nextBackupId_; + + /// Id for the next backup group + int nextBackupGroupId_; /// Logger interfaces between plugins and core logger std::vector loggers_; diff --git a/Core/PluginLoader.cc b/Core/PluginLoader.cc index 01b1baee..e20d8fb1 100644 --- a/Core/PluginLoader.cc +++ b/Core/PluginLoader.cc @@ -1060,11 +1060,23 @@ void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){ if ( backupPlugin ) { supported = supported + "Backups "; + // Incoming Signal that a backup group should be created + // send to local slot generating group id and delivers to all other plugins + if ( checkSignal( plugin , "createBackupGroup(QString,int&)" ) ) { + connect(plugin , SIGNAL(createBackupGroup(QString , int&)) , + this , SLOT(slotBackupGroup(QString , int&)),Qt::DirectConnection ); + } + // Signal send from core to plugins that they should create a backup group + if ( checkSlot( plugin , "slotBackupGroup(QString,int)" ) ) { + connect(this , SIGNAL(createBackupGroup(QString,int)) , + plugin , SLOT( slotBackupGroup(QString,int) ),Qt::DirectConnection); + } + // Incoming Signal that a backup should be created // send to local slot generating backup id and delivers to all other plugins - if ( checkSignal( plugin , "createBackup(int,QString,int&)" ) ) { - connect(plugin , SIGNAL(createBackup( int , QString , int&)) , - this , SLOT(slotBackup( int , QString , int&)),Qt::DirectConnection ); + if ( checkSignal( plugin , "createBackup(int,QString,int&,int)" ) ) { + connect(plugin , SIGNAL(createBackup( int , QString , int&, int)) , + this , SLOT(slotBackup( int , QString , int&, int)),Qt::DirectConnection ); } // send to local slot generating backup id and delivers to all other plugins @@ -1074,9 +1086,9 @@ void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){ } // Signal send from core to plugins that they should create a backup - if ( checkSlot( plugin , "slotBackup(int,QString,int)" ) ) { - connect(this , SIGNAL(createBackup(int,QString,int)) , - plugin , SLOT( slotBackup(int,QString,int) ),Qt::DirectConnection); + if ( checkSlot( plugin , "slotBackup(int,QString,int,int)" ) ) { + connect(this , SIGNAL(createBackup(int,QString,int,int)) , + plugin , SLOT( slotBackup(int,QString,int,int) ),Qt::DirectConnection); } // Signal send from plugin to core that a backup should be made persistent @@ -1091,7 +1103,6 @@ void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){ plugin , SLOT( slotMakeBackupPersistent(int,int) ),Qt::DirectConnection); } - // Signal from plugin to restore an object with the given id if ( checkSignal( plugin , "restoreObject(int,int)" ) ) { connect(plugin , SIGNAL(restoreObject(int,int)) , @@ -1103,7 +1114,20 @@ void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){ connect(this , SIGNAL(restoreObject(int,int)) , plugin , SLOT( slotRestoreObject(int,int) ),Qt::DirectConnection); } + + + // Signal from plugin to restore a group with the given id + if ( checkSignal( plugin , "restoreGroup(int)" ) ) { + connect(plugin , SIGNAL(restoreGroup(int)) , + this , SLOT(slotRestoreGroup(int)),Qt::DirectConnection ); + } + // Signal send from core to backup plugin that it should restore the given group + if ( checkSlot( plugin , "slotRestoreGroup(int)" ) ) { + connect(this , SIGNAL(restoreGroup(int)) , + plugin , SLOT( slotRestoreGroup(int) ),Qt::DirectConnection); + } + //==================================================================================== // Backup Plugin signals for communication with the other plugins about restore state //==================================================================================== -- GitLab