BackupPlugin.cc 16.5 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper 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 Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
Jan Möbius's avatar
Jan Möbius committed
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
Jan Möbius's avatar
Jan Möbius committed
41
\*===========================================================================*/
Jan Möbius's avatar
   
Jan Möbius committed
42

43
#include "BackupPlugin.hh"
Matthias Möller's avatar
Matthias Möller committed
44
45
46
47
48
49
#if QT_VERSION >= 0x050000 
  #include <QtWidgets>
#else
  #include <QtGui>
#endif

Jan Möbius's avatar
   
Jan Möbius committed
50
51
52
53
#include <iostream>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

Dirk Wilden's avatar
Dirk Wilden committed
54
#include "GroupBackup.hh"
Jan Möbius's avatar
   
Jan Möbius committed
55

56
57
//-----------------------------------------------------------------------------
BackupPlugin::BackupPlugin():
Matthias Möller's avatar
Matthias Möller committed
58
globalBackup_(),
59
60
61
62
63
64
65
backupMenu_(0),
backupsEnabledAction_(0),
undoMenuAction_(0),
redoMenuAction_(0),
undoToolAction_(0),
redoToolAction_(0),
undoContextAction_(0),
Matthias Möller's avatar
Matthias Möller committed
66
67
redoContextAction_(0),
maxBackupSpinBox_(0)
68
69
70
71
{

}

Dirk Wilden's avatar
Dirk Wilden committed
72
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
73

Matthias Möller's avatar
Matthias Möller committed
74
75
76
77
78
79
80
81
void BackupPlugin::initializePlugin()
{
  int maxBackups = OpenFlipperSettings().value("BackupPlugin/MaxBackups",static_cast<unsigned>(globalBackup_.maxBackups())).toInt();
  globalBackup_.setMaxBackups(maxBackups);
}

//-----------------------------------------------------------------------------

Jan Möbius's avatar
   
Jan Möbius committed
82
83
84
85
86
87
void BackupPlugin::pluginsInitialized() {

  // Create Backup menu
  emit getMenubarMenu(tr("&Backup"), backupMenu_, true );

  if ( OpenFlipper::Options::gui() ) {
Dirk Wilden's avatar
Dirk Wilden committed
88
    //construct the menu
Jan Möbius's avatar
   
Jan Möbius committed
89
90
91
    backupsEnabledAction_ = new QAction("Backups Enabled",0);
    backupsEnabledAction_->setCheckable(true);
    connect (backupsEnabledAction_, SIGNAL(triggered(bool)), this, SLOT(slotEnableDisableBackups()) );
92

Dirk Wilden's avatar
Dirk Wilden committed
93
94
95
96
    undoMenuAction_ = new QAction(tr("&Undo"), this);
    undoMenuAction_->setEnabled(false);
    undoMenuAction_->setStatusTip(tr("Undo the last action."));
    undoMenuAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-undo.png") );
97
    connect(undoMenuAction_, SIGNAL(triggered()), this, SIGNAL( undo() ) );
98

Dirk Wilden's avatar
Dirk Wilden committed
99
100
101
102
    redoMenuAction_ = new QAction(tr("&Redo"), this);
    redoMenuAction_->setEnabled(false);
    redoMenuAction_->setStatusTip(tr("Redo the last action"));
    redoMenuAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-redo.png") );
103
    connect(redoMenuAction_, SIGNAL(triggered()), this, SIGNAL( redo() ) );
Dirk Wilden's avatar
Dirk Wilden committed
104
105
106
107
108

    backupMenu_->addAction(undoMenuAction_);
    backupMenu_->addAction(redoMenuAction_);
    backupMenu_->addSeparator();
    backupMenu_->addAction(backupsEnabledAction_);
Jan Möbius's avatar
   
Jan Möbius committed
109
110
111

    // Add a backup Toolbar
    QToolBar* toolbar = new QToolBar("Backup Toolbar");
112

Jan Möbius's avatar
   
Jan Möbius committed
113
    //Undo
Dirk Wilden's avatar
Dirk Wilden committed
114
115
116
117
    undoToolAction_ = new QAction(tr("&Undo"), this);
    undoToolAction_->setEnabled(false);
    undoToolAction_->setStatusTip(tr("Undo the last action."));
    undoToolAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-undo.png") );
118
    connect(undoToolAction_, SIGNAL(triggered()), this, SIGNAL( undo() ) );
Dirk Wilden's avatar
Dirk Wilden committed
119
    toolbar->addAction(undoToolAction_);
120

Jan Möbius's avatar
   
Jan Möbius committed
121
    //Redo
Dirk Wilden's avatar
Dirk Wilden committed
122
123
124
125
    redoToolAction_ = new QAction(tr("&Redo"), this);
    redoToolAction_->setEnabled(false);
    redoToolAction_->setStatusTip(tr("Redo the last action"));
    redoToolAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-redo.png") );
126
    connect(redoToolAction_, SIGNAL(triggered()), this, SIGNAL( redo() ) );
Dirk Wilden's avatar
Dirk Wilden committed
127
    toolbar->addAction(redoToolAction_);
128

Jan Möbius's avatar
   
Jan Möbius committed
129
    emit addToolbar( toolbar );
130

Jan Möbius's avatar
   
Jan Möbius committed
131
132
133
    //the release event does not contain the modifier
    emit registerKey(Qt::Key_Z,  Qt::ControlModifier, tr("Undo Action"));
    emit registerKey(Qt::Key_Z, (Qt::ControlModifier | Qt::ShiftModifier),   tr("Redo Action"));
134

Dirk Wilden's avatar
Dirk Wilden committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    //add actions for the context menu
    undoContextAction_ = new QAction(tr("&Undo"), this);
    undoContextAction_->setEnabled(false);
    undoContextAction_->setStatusTip(tr("Undo the last action."));
    undoContextAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-undo.png") );
    connect(undoContextAction_, SIGNAL(triggered()), this, SLOT(slotObjectUndo()) );
    emit addContextMenuItem(undoContextAction_, DATA_ALL, CONTEXTOBJECTMENU);

    redoContextAction_ = new QAction(tr("&Redo"), this);
    redoContextAction_->setEnabled(false);
    redoContextAction_->setStatusTip(tr("Redo the last action"));
    redoContextAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-redo.png") );
    connect(redoContextAction_, SIGNAL(triggered()), this, SLOT(slotObjectRedo()) );
    emit addContextMenuItem(redoContextAction_, DATA_ALL, CONTEXTOBJECTMENU);
Matthias Möller's avatar
Matthias Möller committed
149
150
151
152
153

    //update option widget since it is created earlier
    if (maxBackupSpinBox_)
      maxBackupSpinBox_->setValue(globalBackup_.maxBackups());

Jan Möbius's avatar
   
Jan Möbius committed
154
  }
155
156
157
158
159
160

//createBackup(int _objectId, QString _name, UpdateType _type= UPDATE_ALL)
  emit setSlotDescription("createBackup(int,QString)", tr("Creates a backup which can be restored via undo."),
                               QString("objectId,name").split(","), QString("Id of the object,name of the backup").split(","));
  emit setSlotDescription("createBackup(int,QString,UpdateType)", tr("Creates a backup which can be restored via undo."),
                             QString("objectId,name,type").split(","), QString("Id of the object,name of the backup,updatetypes which are changed").split(","));
Jan Möbius's avatar
   
Jan Möbius committed
161
162
}

Dirk Wilden's avatar
Dirk Wilden committed
163
164
//-----------------------------------------------------------------------------

Jan Möbius's avatar
   
Jan Möbius committed
165
void BackupPlugin::slotAllCleared(){
Dirk Wilden's avatar
Dirk Wilden committed
166
167
  globalBackup_.clear();
}
Jan Möbius's avatar
   
Jan Möbius committed
168

Dirk Wilden's avatar
Dirk Wilden committed
169
170
171
//-----------------------------------------------------------------------------

void BackupPlugin::updateButtons() {
172

Dirk Wilden's avatar
Dirk Wilden committed
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  if ( globalBackup_.undoAvailable() ){
    undoMenuAction_->setText( tr("Undo '%1'").arg( globalBackup_.undoName() ) );
    undoMenuAction_->setEnabled(true);
    undoToolAction_->setText( tr("Undo '%1'").arg( globalBackup_.undoName() ) );
    undoToolAction_->setEnabled(true);
  } else {
    undoMenuAction_->setText( tr("Undo") );
    undoMenuAction_->setEnabled(false);
    undoToolAction_->setText( tr("Undo") );
    undoToolAction_->setEnabled(false);
  }

  if ( globalBackup_.redoAvailable() ){
    redoMenuAction_->setText( tr("Redo '%1'").arg( globalBackup_.redoName() ) );
    redoMenuAction_->setEnabled(true);
    redoToolAction_->setText( tr("Redo '%1'").arg( globalBackup_.redoName() ) );
    redoToolAction_->setEnabled(true);
  } else {
    redoMenuAction_->setText( tr("Redo") );
    redoMenuAction_->setEnabled(false);
    redoToolAction_->setText( tr("Redo") );
    redoToolAction_->setEnabled(false);
  }
Jan Möbius's avatar
   
Jan Möbius committed
196

Dirk Wilden's avatar
Dirk Wilden committed
197
  backupsEnabledAction_->setChecked( OpenFlipper::Options::backupEnabled() );
Jan Möbius's avatar
   
Jan Möbius committed
198
199
}

Dirk Wilden's avatar
Dirk Wilden committed
200
201
//-----------------------------------------------------------------------------

Jan Möbius's avatar
   
Jan Möbius committed
202
203
204
205
void BackupPlugin::slotEnableDisableBackups() {
  OpenFlipper::Options::enableBackup(backupsEnabledAction_->isChecked());
}

Dirk Wilden's avatar
Dirk Wilden committed
206
207
//-----------------------------------------------------------------------------

Jan Möbius's avatar
   
Jan Möbius committed
208
209
210
211
212
void BackupPlugin::slotKeyEvent( QKeyEvent* _event ){
   switch (_event->key())
   {
      case Qt::Key_Z :
         if ( _event->modifiers() == Qt::ControlModifier )
Dirk Wilden's avatar
Dirk Wilden committed
213
           emit undo();
Jan Möbius's avatar
   
Jan Möbius committed
214
         else if ( _event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) )
Dirk Wilden's avatar
Dirk Wilden committed
215
           emit redo();
Jan Möbius's avatar
   
Jan Möbius committed
216
217
218
219
220
221
         break;
      default:
         break;
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
222
223
//-----------------------------------------------------------------------------

Jan Möbius's avatar
   
Jan Möbius committed
224
225
226
void BackupPlugin::objectDeleted(int _objectid) {
}

Dirk Wilden's avatar
Dirk Wilden committed
227
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
228

Dirk Wilden's avatar
Dirk Wilden committed
229
void BackupPlugin::slotUpdateContextMenu( int _objectId ){
Jan Möbius's avatar
   
Jan Möbius committed
230

Dirk Wilden's avatar
Dirk Wilden committed
231
232
233
234
235
  //disable everything
  undoContextAction_->setText( tr("Undo") );
  undoContextAction_->setEnabled(false);
  redoContextAction_->setText( tr("Redo") );
  redoContextAction_->setEnabled(false);
Jan Möbius's avatar
   
Jan Möbius committed
236

Dirk Wilden's avatar
Dirk Wilden committed
237
238
239
  //get backup data
  BaseObjectData* object = 0;
  PluginFunctions::getObject(_objectId, object);
Jan Möbius's avatar
   
Jan Möbius committed
240

Dirk Wilden's avatar
Dirk Wilden committed
241
  if ( object != 0 ){
Jan Möbius's avatar
   
Jan Möbius committed
242

Dirk Wilden's avatar
Dirk Wilden committed
243
    if ( object->hasObjectData( OBJECT_BACKUPS ) ){
Jan Möbius's avatar
Jan Möbius committed
244
245
246

      //get backup object data
      BackupData* backupData = dynamic_cast< BackupData* >(object->objectData(OBJECT_BACKUPS));
Jan Möbius's avatar
   
Jan Möbius committed
247

Dirk Wilden's avatar
Dirk Wilden committed
248
249
250
251
252
      if ( backupData->undoAvailable() ){
        undoContextAction_->setData(_objectId);
        undoContextAction_->setText( tr("Undo '%1'").arg( backupData->undoName() ) );
        undoContextAction_->setEnabled( !backupData->undoBlocked() );
      }
Jan Möbius's avatar
   
Jan Möbius committed
253

Dirk Wilden's avatar
Dirk Wilden committed
254
255
256
257
      if ( backupData->redoAvailable() ){
        redoContextAction_->setData(_objectId);
        redoContextAction_->setText( tr("Redo '%1'").arg( backupData->redoName() ) );
        redoContextAction_->setEnabled( !backupData->redoBlocked() );
Jan Möbius's avatar
   
Jan Möbius committed
258
259
260
      }
    }
  }
Dirk Wilden's avatar
Dirk Wilden committed
261

Jan Möbius's avatar
   
Jan Möbius committed
262
263
}

Dirk Wilden's avatar
Dirk Wilden committed
264
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
265

Dirk Wilden's avatar
Dirk Wilden committed
266
void BackupPlugin::slotObjectUndo(){
267

Dirk Wilden's avatar
Dirk Wilden committed
268
269
  int id = undoContextAction_->data().toInt();
  emit undo(id);
Jan Möbius's avatar
   
Jan Möbius committed
270
271
}

Dirk Wilden's avatar
Dirk Wilden committed
272
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
273

Dirk Wilden's avatar
Dirk Wilden committed
274
void BackupPlugin::slotObjectRedo(){
275

Dirk Wilden's avatar
Dirk Wilden committed
276
277
278
  int id = undoContextAction_->data().toInt();
  emit redo(id);
}
Jan Möbius's avatar
   
Jan Möbius committed
279

Dirk Wilden's avatar
Dirk Wilden committed
280
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
281

Dirk Wilden's avatar
Dirk Wilden committed
282
void BackupPlugin::slotCreateBackup( int _objectid, QString _name, UpdateType _type){
283

Dirk Wilden's avatar
Dirk Wilden committed
284
285
  if ( !OpenFlipper::Options::backupEnabled() )
    return;
Jan Möbius's avatar
   
Jan Möbius committed
286

Dirk Wilden's avatar
Dirk Wilden committed
287
  BaseObjectData* object;
Jan Möbius's avatar
   
Jan Möbius committed
288

Dirk Wilden's avatar
Dirk Wilden committed
289
290
291
292
  if ( !PluginFunctions::getObject(_objectid,object) ){
    emit log(LOGWARN,"Unable to find backup object with id " + QString::number(_objectid));
    return;
  }
Jan Möbius's avatar
   
Jan Möbius committed
293

Dirk Wilden's avatar
Dirk Wilden committed
294
295
  //tell TypePlugin to Backup
  emit generateBackup( _objectid, _name, _type );
Jan Möbius's avatar
   
Jan Möbius committed
296

Dirk Wilden's avatar
Dirk Wilden committed
297
298
299
  //add global backup
  IdList groupIds;
  groupIds.push_back( _objectid );
Jan Möbius's avatar
   
Jan Möbius committed
300

Dirk Wilden's avatar
Dirk Wilden committed
301
  bool skipBackup = false;
Jan Möbius's avatar
   
Jan Möbius committed
302

Dirk Wilden's avatar
Dirk Wilden committed
303
304
305
  if ( globalBackup_.undoAvailable() ){
    //skip 'Original Object' Backups in global view
    BackupData* backupData = dynamic_cast< BackupData* >(object->objectData(OBJECT_BACKUPS));
Jan Möbius's avatar
   
Jan Möbius committed
306

Dirk Wilden's avatar
Dirk Wilden committed
307
308
309
    if ( backupData != 0 )
      skipBackup = !backupData->undoAvailable();
  }
Jan Möbius's avatar
   
Jan Möbius committed
310

Dirk Wilden's avatar
Dirk Wilden committed
311
312
313
314
  if ( !skipBackup ){
    GroupBackup* backup = new GroupBackup(groupIds, _name);
    globalBackup_.storeBackup( backup );
  }
Jan Möbius's avatar
   
Jan Möbius committed
315

Dirk Wilden's avatar
Dirk Wilden committed
316
317
318
  updateButtons();
  emit log(LOGOUT,"Created backup for " + QString::number(_objectid)+ " , Name : '" + _name + "'" );
}
Jan Möbius's avatar
   
Jan Möbius committed
319

Dirk Wilden's avatar
Dirk Wilden committed
320
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
321

Dirk Wilden's avatar
Dirk Wilden committed
322
void BackupPlugin::slotCreateBackup( IdList _objectids , QString _name, std::vector<UpdateType> _types){
Jan Möbius's avatar
   
Jan Möbius committed
323

Dirk Wilden's avatar
Dirk Wilden committed
324
325
  if ( !OpenFlipper::Options::backupEnabled() )
    return;
Jan Möbius's avatar
   
Jan Möbius committed
326

Dirk Wilden's avatar
Dirk Wilden committed
327
  IdList groupIds;
328

Dirk Wilden's avatar
Dirk Wilden committed
329
330
  if ( _objectids.size() != _types.size() ){
    emit log(LOGWARN,"Unable to create backup sizes of ids and updateTypes do not match!");
Jan Möbius's avatar
   
Jan Möbius committed
331
332
333
    return;
  }

Dirk Wilden's avatar
Dirk Wilden committed
334
335
  //generate backups on all objects
  for (unsigned int i=0; i < _objectids.size(); ++i){
Jan Möbius's avatar
   
Jan Möbius committed
336

Dirk Wilden's avatar
Dirk Wilden committed
337
    BaseObjectData* object;
Jan Möbius's avatar
   
Jan Möbius committed
338

Dirk Wilden's avatar
Dirk Wilden committed
339
340
341
342
    if ( !PluginFunctions::getObject(_objectids[i],object) ){
      emit log(LOGWARN,"Unable to find backup object with id " + QString::number(_objectids[i]));
      continue;
    }
Jan Möbius's avatar
   
Jan Möbius committed
343

Dirk Wilden's avatar
Dirk Wilden committed
344
345
346
347
    //tell TypePlugin to generate a backup
    emit generateBackup( _objectids[i], _name, _types[i] );
    groupIds.push_back(  _objectids[i] );
  }
Jan Möbius's avatar
   
Jan Möbius committed
348

Dirk Wilden's avatar
Dirk Wilden committed
349
  //add global backup
Jan Möbius's avatar
Typo    
Jan Möbius committed
350
  if ( ! groupIds.empty() ){
351

Dirk Wilden's avatar
Dirk Wilden committed
352
353
    GroupBackup* backup = new GroupBackup(groupIds, _name);
    globalBackup_.storeBackup( backup );
Jan Möbius's avatar
   
Jan Möbius committed
354

Dirk Wilden's avatar
Dirk Wilden committed
355
356
    updateButtons();
    emit log(LOGOUT,"Created grouped backup, Name : '" + _name + "'" );
Jan Möbius's avatar
   
Jan Möbius committed
357
358
359
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
360
//-----------------------------------------------------------------------------
361

Dirk Wilden's avatar
Dirk Wilden committed
362
void BackupPlugin::slotUndo(int _objectid){
363

364
  emit aboutToRestore(_objectid);
Dirk Wilden's avatar
Dirk Wilden committed
365
  globalBackup_.undo(_objectid);
366
  emit restored(_objectid);
Dirk Wilden's avatar
Dirk Wilden committed
367
  emit updatedObject(_objectid, UPDATE_ALL);
368

Dirk Wilden's avatar
Dirk Wilden committed
369
  updateButtons();
Jan Möbius's avatar
   
Jan Möbius committed
370
371
}

Dirk Wilden's avatar
Dirk Wilden committed
372
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
373

Dirk Wilden's avatar
Dirk Wilden committed
374
void BackupPlugin::slotUndo(){
375
376
  GroupBackup* group = dynamic_cast< GroupBackup* >( globalBackup_.currentState() );

Isaak Lim's avatar
Isaak Lim committed
377
378
379
380
381
  if (group) {
    IdList ids = group->objectIDs();
    IdList::const_iterator it, end;
    for (it = ids.begin(), end = ids.end(); it != end; ++it)
      emit aboutToRestore(*it);
382

Isaak Lim's avatar
Isaak Lim committed
383
    globalBackup_.undo();
Jan Möbius's avatar
   
Jan Möbius committed
384

Dirk Wilden's avatar
Dirk Wilden committed
385
386
    for (unsigned int i=0; i < group->objectIDs().size(); i++)
      emit updatedObject(group->objectIDs()[i], UPDATE_ALL);
Jan Möbius's avatar
   
Jan Möbius committed
387

Isaak Lim's avatar
Isaak Lim committed
388
389
390
    updateButtons();
  } else
    emit log(LOGWARN,"Unable to find the current GroupBackup");
Dirk Wilden's avatar
Dirk Wilden committed
391
}
Jan Möbius's avatar
   
Jan Möbius committed
392

Dirk Wilden's avatar
Dirk Wilden committed
393
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
394

Dirk Wilden's avatar
Dirk Wilden committed
395
void BackupPlugin::slotRedo(int _objectid){
Jan Möbius's avatar
   
Jan Möbius committed
396

397
  emit aboutToRestore(_objectid);
Dirk Wilden's avatar
Dirk Wilden committed
398
  globalBackup_.redo(_objectid);
399
  emit restored(_objectid);
Dirk Wilden's avatar
Dirk Wilden committed
400
  emit updatedObject(_objectid, UPDATE_ALL);
Jan Möbius's avatar
   
Jan Möbius committed
401

Dirk Wilden's avatar
Dirk Wilden committed
402
  updateButtons();
Jan Möbius's avatar
   
Jan Möbius committed
403
404
}

Dirk Wilden's avatar
Dirk Wilden committed
405
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
406

Dirk Wilden's avatar
Dirk Wilden committed
407
408
void BackupPlugin::slotRedo(){
  globalBackup_.redo();
Jan Möbius's avatar
   
Jan Möbius committed
409

Dirk Wilden's avatar
Dirk Wilden committed
410
  GroupBackup* group = dynamic_cast< GroupBackup* >( globalBackup_.currentState() );
Jan Möbius's avatar
   
Jan Möbius committed
411

Dirk Wilden's avatar
Dirk Wilden committed
412
413
414
  if ( group != 0)
    for (unsigned int i=0; i < group->objectIDs().size(); i++)
      emit updatedObject(group->objectIDs()[i], UPDATE_ALL);
Jan Möbius's avatar
   
Jan Möbius committed
415

Dirk Wilden's avatar
Dirk Wilden committed
416
  updateButtons();
Jan Möbius's avatar
   
Jan Möbius committed
417
418
}

Dirk Wilden's avatar
Dirk Wilden committed
419
//-----------------------------------------------------------------------------
Jan Möbius's avatar
   
Jan Möbius committed
420

421
422
423
424
425
426
427
void BackupPlugin::createBackup(int _objectId, QString _name, UpdateType _type)
{
  slotCreateBackup(_objectId,_name,_type);
}

//-----------------------------------------------------------------------------

Matthias Möller's avatar
Matthias Möller committed
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
bool BackupPlugin::initializeOptionsWidget(QWidget*& _widget)
{
  QLabel* maxBackupLabel = new QLabel();
  maxBackupLabel->setText(tr("Max. saved backups: "));
  maxBackupSpinBox_ = new QSpinBox();
  maxBackupSpinBox_->setValue(globalBackup_.maxBackups());
  maxBackupSpinBox_->setRange(0,100);

  QHBoxLayout* layout = new QHBoxLayout();
  layout->addWidget(maxBackupLabel);
  layout->addWidget(maxBackupSpinBox_);

  QWidget* baseWidget = new QWidget();
  baseWidget->setLayout(layout);
  _widget = baseWidget;

  return true;
}

//-----------------------------------------------------------------------------

void BackupPlugin::applyOptions()
{
  int maxBackups = maxBackupSpinBox_->value();
  globalBackup_.setMaxBackups(maxBackups);
  OpenFlipperSettings().setValue("BackupPlugin/MaxBackups", maxBackups);
}

Matthias Möller's avatar
Matthias Möller committed
456
#if QT_VERSION < 0x050000
Jan Möbius's avatar
   
Jan Möbius committed
457
Q_EXPORT_PLUGIN2( backupplugin , BackupPlugin );
Matthias Möller's avatar
Matthias Möller committed
458
#endif
Jan Möbius's avatar
   
Jan Möbius committed
459