Commit 614ba3d8 authored by Jan Möbius's avatar Jan Möbius

Reworked Backup Interface

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9505 383ad7c9-94d9-4d36-a494-682f7c89f535
parent a935fc9e
......@@ -65,38 +65,136 @@
*
*/
class BackupInterface {
//===========================================================================
/** @name Interface definition for general Plugins
* @{ */
//===========================================================================
signals:
/** \brief Tell Backup Plugin to create a backup
*
* Plugins which supports backups can call this function if they want to create backups.\n
* A Backup control Plugin will do the rest.
* @param _objectid Identifier of the object to create the backup
* @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*/) {};
/** \brief Tell Backup Plugin to create a backup but don't get the id of the object ( if you don't care )
*
* Plugins which supports backups can call this function if they want to create backups.\n
* A Backup control Plugin will do the rest.
* @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*/) {};
/** \brief Tell Backup Plugin to restore a backup
*
* Plugins which supports backups can this function if they want to restore backups.\n
* A Backup control Plugin will do the rest.
* @param _objectid Identifier of the object to restore
* @param _internalId The unique identifier of the restore set (-1 for last backup)
*/
virtual void restoreObject( int /*_objectid*/, int _internalId =-1) {};
private slots:
/** \brief Backup for an object requested
*
* This function will be called if a plugin requests a backup. You can
* also react on this event if you reimplement this function in your plugin.
* @param _id Identifier of the object to create the backup
* @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*/) {} ;
/** \brief A given object will be restored.
*
* This function is called before an object is restored from a backup.
* perObjectDatas and the object will be reset to the backup state
* after this function is called for all plugins.
* If you have any pointers or references to the given object you have to
* clean them up here.
* @param _id Identifier of the object which is about to be restored
* @param _name Name of the restore set
* @param _internalId Unique Number of the Restore set
*/
virtual void slotAboutToRestore( int /*_objectid*/ , int /*_internalId*/) {};
/** \brief Restore Object
*
* This function is called after the main object is restored from a backup.
* perObjectDatas and the object have been reset to the backup state.\n
*
* Here you can restore additional data which is not managed in perObjectDatas but
* in your local plugin.\n
*
* @param _objectid Identifier of the object which is about to be restored
* @param _name Name of the restore set
* @param _internalId Unique Number of the Restore set
*/
virtual void slotRestore( int /*_objectid*/ , int /*_internalId*/) {};
/** \brief Object fully restored
*
* This function is called after an object and all data from other plugins
* is restored from a backup.
* perObjectDatas and the object have been reset to the backup state.
* @param _objectid Identifier of the object which is about to be restored
* @param _name Name of the restore set
* @param _internalId Unique Number of the Restore set
*/
virtual void slotRestored( int /*_objectid*/, int /*_internalId*/) {};
signals:
/** Plugins which support backups should call this function if they want to create backups.\n
* A Backup control Plugin will do the rest.
* @param _id 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 /*_id*/ , QString /*_name*/ ) {};
private slots:
/** This function will be called if a plugin requests a backup. You can
* also react on this event.
* @param _id Identifier of the object to create the backup
* @param _name Name of the Backup, to show the user what can be recovered
* @param _backup_id Unique Number of the backup.
*/
virtual void slotBackupRequested( int /*_id*/ , QString /*_name*/ , int /*_backup_id*/) {} ;
/** This function will be called if a plugin requests a backup. You can
* also react on this event.
* @param _id Identifier of the object to create the backup
* @param _name Name of the Backup, to show the user what can be recovered
* @param _backup_id Unique Number of the backup.
*/
virtual void slotRestoreRequested( int /*_id*/ , QString /*_name*/ , int /*_backup_id*/) {};
public :
/// Destructor
virtual ~BackupInterface() {};
//===========================================================================
/** @name Interface definition for Backup Plugins
*
* These signals and slots have to be implemented if you create a plugin managing
* Backups ( A Backup plugin is already provided by OpenFlipper so you don't need
* to use these funcions).
* @{ */
//===========================================================================
signals:
/** \brief Backup Plugin tells other Plugins that a restore will happen
*
*/
virtual void aboutToRestore(int /*_objectid*/ , int /*_internalId*/) {};
/** \brief Backup Plugin tells other Plugins that they should restore their own data
*
*/
virtual void restore(int /*_objectid*/ , int /*_internalId*/) {};
/** \brief Backup Plugin tells other Plugins that a restore has happened
*
*/
virtual void restored( int /*_objectid*/ , int /*_internalId*/) {};
private slots:
/** \brief Restore the core object
*
* 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 _objectId Object to restore
*
*/
virtual void slotRestoreObject(int /*_objectid*/ , QString /*_name*/ , int /*_internalId*/) {}
};
Q_DECLARE_INTERFACE(BackupInterface,"GUI.BackupInterface/0.3")
Q_DECLARE_INTERFACE(BackupInterface,"GUI.BackupInterface/1.0")
#endif // BACKUPPLUGININTERFACE_HH
......@@ -258,7 +258,23 @@ signals:
void saveOnExit( INIFile& _ini );
/// Tell plugins to create a backup
void createBackup( int _id , QString _name , int nextBackupId_);
void createBackup( int _objectId , QString _name , int _internalId);
/// Tell Backup Plugin to restore an object with the given backup id
void restoreObject( int _objectId, int _internalId);
/** \brief Backup Plugin tells other Plugins that a restore will happen
*/
void aboutToRestore(int _objectId , int _internalId);
/** \brief Backup Plugin tells other Plugins that they should restore their own data
*/
void restore(int _objectId , int _internalId);
/** \brief Backup Plugin tells other Plugins that a restore has happened
*/
void restored( int _objectId , int _internalId);
/// Tell the plugins that a file has been opened ( -> Database)
void openedFile( int _id );
......@@ -361,7 +377,13 @@ signals:
void slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures );
/// Called if a backup is requested by the plugins
void backupRequest( int _id , QString _name );
void slotBackup( int _objectId, QString _name, int& _internalId );
/// Called if a backup is requested by the plugins
void slotBackup( int _objectId, QString _name );
/// Called if a backup is requested by the plugins
void slotRestore( int _objectId, int _internalId = -1 );
/// A plugin wants to load a given file
void slotLoad(QString _filename, DataType _type, int& _id);
......
......@@ -331,16 +331,6 @@ void Core::slotGetSubTextures( int _id, QString _multiTextureName, QStringList&
emit getSubTextures( _id, _multiTextureName, _subTextures );
}
//========================================================================================
// === Backup Communication ============================
//========================================================================================
/// Called if a backup is requested by the plugins
void Core::backupRequest( int _id , QString _name ) {
emit createBackup( _id , _name , nextBackupId_);
++nextBackupId_;
}
//========================================================================================
// === Object Manager ============================
//========================================================================================
......
......@@ -1053,13 +1053,82 @@ void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){
if ( backupPlugin ) {
supported = supported + "Backups ";
if ( checkSignal( plugin , "createBackup(int,QString)" ) )
connect(plugin , SIGNAL(createBackup( int , QString )) ,
this , SLOT(backupRequest( int , QString )),Qt::DirectConnection );
if ( checkSlot( plugin , "slotBackupRequested(int,QString,int)" ) )
// 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 );
}
// send to local slot generating backup id and delivers to all other plugins
if ( checkSignal( plugin , "createBackup(int,QString)" ) ) {
connect(plugin , SIGNAL(createBackup( int , QString)) ,
this , SLOT(slotBackup( int , QString)),Qt::DirectConnection );
}
// 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( slotBackupRequested(int,QString,int) ),Qt::DirectConnection);
plugin , SLOT( slotBackup(int,QString,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)) ,
this , SLOT(slotRestore( int , int)),Qt::DirectConnection );
}
// Signal send from core to backup plugin that it should restore the given object
if ( checkSlot( plugin , "slotRestoreObject(int,int)" ) ) {
connect(this , SIGNAL(restoreObject(int,int)) ,
plugin , SLOT( slotRestoreObject(int,int) ),Qt::DirectConnection);
}
//====================================================================================
// Backup PLugin signals for communication with the other plugins about restore state
//====================================================================================
// Stage one : restore will happen soon
if ( checkSignal( plugin , "aboutToRestore(int,int)" ) ) {
connect(this , SIGNAL( aboutToRestore(int,int)) ,
plugin , SIGNAL( aboutToRestore(int,int) ),Qt::DirectConnection);
}
// Stage two: Core restore done, plugins should restore
if ( checkSignal( plugin , "restore(int,int)" ) ) {
connect(this , SIGNAL(restore(int,int)) ,
plugin , SIGNAL( restore(int,int) ),Qt::DirectConnection);
}
// Stage three: Restore complete
if ( checkSignal( plugin , "restored(int,int)" ) ) {
connect(this , SIGNAL(restored(int,int)) ,
plugin , SIGNAL( restored(int,int) ),Qt::DirectConnection);
}
//====================================================================================
// Plugin slots about restore state
//====================================================================================
// Stage one : restore will happen soon
if ( checkSlot( plugin , "slotAboutToRestore(int,int)" ) ) {
connect(this , SIGNAL( aboutToRestore(int,int)) ,
plugin , SLOT( slotAboutToRestore(int,int) ),Qt::DirectConnection);
}
// Stage one : restore will happen soon
if ( checkSlot( plugin , "slotRestore(int,int)" ) ) {
connect(this , SIGNAL( restore(int,int)) ,
plugin , SLOT( slotRestore(int,int) ),Qt::DirectConnection);
}
// Stage one : restore will happen soon
if ( checkSlot( plugin , "slotRestored(int,int)" ) ) {
connect(this , SIGNAL( restored(int,int)) ,
plugin , SLOT( slotRestored(int,int) ),Qt::DirectConnection);
}
}
//Check if the plugin supports LoadSave-Interface
......
......@@ -536,7 +536,8 @@ void Core::slotObjectOpened ( int _id ) {
// ================================================================================
// Create initial backup
// ================================================================================
backupRequest(_id,"Original Object");
int backupId = 0;
slotBackup(_id,"Original Object",backupId);
// ================================================================================
// Add the file to the recent files menu
......@@ -581,7 +582,8 @@ void Core::slotEmptyObjectAdded ( int _id ) {
emit signalObjectUpdated(_id);
emit signalObjectUpdated(_id,UPDATE_ALL);
backupRequest(_id,"Original Object");
int backupId = 0;
slotBackup(_id,"Original Object",backupId);
///@todo : set a default path for new objects
// QString filename = object->path() + OpenFlipper::Options::dirSeparator() + object->name();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment