#include <playlist.h>
Public Member Functions | |
| EditorBackup () | |
| Editor backup - holds all the previous playlists (up to a the maxUndos preference value). | |
| ~EditorBackup () | |
| Destructor for the Editor Backup object. | |
| void | Store (PlayList *, bool isPersisted=true) |
| void | Undo (PlayList *) |
| void | Redo (PlayList *) |
| void | SetAllDirty () |
| Set all the stored backups as dirty other than the current one. | |
| void | Clear () |
| Clear the contents of the editor backup. | |
| bool | Restore (PlayList *) |
Private Attributes | |
| int | maxUndos |
| int | position |
| vector< PlayList * > | backups |
Definition at line 121 of file playlist.h.
|
|
Editor backup - holds all the previous playlists (up to a the maxUndos preference value).
Definition at line 2371 of file playlist.cc. References Preferences::getInstance(), and maxUndos. 02371 : position( -1 ) 02372 { 02373 cerr << ">> Creating undo/redo buffer" << endl; 02374 maxUndos = Preferences::getInstance().maxUndos; 02375 }
|
|
|
Destructor for the Editor Backup object.
Definition at line 2380 of file playlist.cc. References backups. 02381 {
02382 cerr << ">> Destroying undo/redo buffer" << endl;
02383
02384 while ( backups.size() )
02385 {
02386 delete backups[ backups.size() - 1 ];
02387 backups.pop_back();
02388 }
02389 }
|
|
|
Clear the contents of the editor backup.
Definition at line 2548 of file playlist.cc. References backups, and position. Referenced by Restore(). 02549 {
02550 while ( backups.size() )
02551 {
02552 delete backups[ backups.size() - 1 ];
02553 backups.pop_back();
02554 }
02555 position = -1;
02556 }
|
|
|
Definition at line 2512 of file playlist.cc. References backups, PlayList::Delete(), PlayList::GetNumFrames(), PlayList::InsertPlayList(), PlayList::IsDirty(), position, and PlayList::SetDirty(). 02513 {
02514 cerr << ">>> Received request to recover from position " << position + 1 << endl;
02515 if ( ( position + 1 ) < ( int ) backups.size() )
02516 {
02517 position ++;
02518 playlist->Delete( 0, playlist->GetNumFrames() - 1 );
02519 PlayList temp( *( backups[ position ] ) );
02520 playlist->InsertPlayList( temp, 0 );
02521 playlist->SetDirty( temp.IsDirty( ) );
02522 }
02523 else
02524 {
02525 cerr << ">>>> Unable to satisfy request." << endl;
02526 }
02527 }
|
|
|
Definition at line 2567 of file playlist.cc. References Clear(), KINO_AUTOSAVE_DIR, PlayList::LoadPlayList(), position, Store(), and Undo(). 02568 {
02569 string directory = KINO_AUTOSAVE_DIR;
02570 DIR* dir = opendir( directory.c_str( ) );
02571 struct dirent* entry;
02572 bool result = false;
02573
02574 if ( dir )
02575 {
02576 std::vector<int> names;
02577 while ( ( entry = readdir( dir ) ) != NULL )
02578 {
02579 if ( entry->d_name[0] != '.' )
02580 names.push_back( atoi( entry->d_name ) );
02581 }
02582 closedir( dir );
02583
02584 if ( !names.empty() )
02585 {
02586 std::sort( names.begin(), names.end() );
02587 Clear();
02588 PlayList pl;
02589 for ( size_t i = 0; i < names.size(); ++i )
02590 {
02591 ostringstream sb;
02592 sb << directory << "/" << names[i] << ".xml" << ends;
02593 if ( pl.LoadPlayList( const_cast<char*>( sb.str().c_str() ) ) )
02594 Store( &pl, false );
02595 }
02596 ++position;
02597 Undo( playlist );
02598 result = true;
02599 }
02600 }
02601 return result;
02602 }
|
|
|
Set all the stored backups as dirty other than the current one. When a file is saved, the previous copy (which may still be in the editor backup), will be dirty (relative to the current contents of the file) - this method ensures that only the most recent item will be registered as clean. Definition at line 2536 of file playlist.cc. References backups, and position. 02537 {
02538 vector< PlayList *>::iterator n;
02539 for ( n = backups.begin(); n != backups.end(); ++n )
02540 ( **n ).SetDirty( true );
02541 if ( position >= 0 )
02542 backups[ position ] ->SetDirty( false );
02543 }
|
|
||||||||||||
|
Definition at line 2391 of file playlist.cc. References backups, Preferences::getInstance(), PlayList::GetNumFrames(), PlayList::GetPlayList(), PlayList::IsDirty(), KINO_AUTOSAVE_DIR, maxUndos, position, and PlayList::SetDirty(). Referenced by Restore(). 02392 {
02393 cerr << ">>> Received playlist to store at position " << position + 1 << endl;
02394
02395 // Three conditions to check:
02396 //
02397 // 1. The undo position is 1 less than the current size of the vector and less than the max size
02398 // in which case we dump the new playlist at the top of the vector and increment the position
02399 //
02400
02401 if ( ( position + 1 ) == ( int ) backups.size() && ( position < maxUndos || maxUndos == 0 ) )
02402 {
02403 cerr << ">>>> Adding to end" << endl;
02404 position ++;
02405 PlayList *temp = new PlayList;
02406 playlist->GetPlayList( 0, playlist->GetNumFrames() - 1, *temp );
02407 temp->SetDirty( playlist->IsDirty( ) );
02408 backups.push_back( temp );
02409 }
02410
02411 //
02412 // 2. The undo position is not at the end, in which case we need to remove everything from position
02413 // to the end before pushing
02414 //
02415
02416 else if ( ( position + 1 ) < ( int ) backups.size() )
02417 {
02418 cerr << ">>>> Cleaning from " << position + 1 << " to " << backups.size() << endl;
02419 position ++;
02420 while ( position < ( int ) backups.size() )
02421 {
02422 delete backups[ backups.size() - 1 ];
02423 backups.pop_back();
02424 }
02425 PlayList *temp = new PlayList;
02426 playlist->GetPlayList( 0, playlist->GetNumFrames() - 1, *temp );
02427 temp->SetDirty( playlist->IsDirty( ) );
02428 backups.push_back( temp );
02429 }
02430
02431 //
02432 // 3. We're at the top of the stack so we need to remove position 0 and push to the end
02433 //
02434
02435 else if ( position == maxUndos )
02436 {
02437 cerr << ">>>> Removing the earliest playlist to make room" << endl;
02438 delete backups[ 0 ];
02439 backups.erase( backups.begin() );
02440 PlayList *temp = new PlayList;
02441 playlist->GetPlayList( 0, playlist->GetNumFrames() - 1, *temp );
02442 temp->SetDirty( playlist->IsDirty( ) );
02443 backups.push_back( temp );
02444 }
02445
02446 //
02447 // Just in case we missed something...
02448 //
02449
02450 else
02451 {
02452 cerr << ">>>> Unknown condition - position = " << position << " size = " << backups.size() << endl;
02453 }
02454
02455 // Update persistent storage
02456 if ( isPersisted )
02457 {
02458 // First, delete contents of private directory in $HOME
02459 string directory = KINO_AUTOSAVE_DIR;
02460 mkdir( directory.c_str(), 0700 );
02461 DIR* dir = opendir( directory.c_str( ) );
02462 struct dirent* entry;
02463 if ( dir )
02464 {
02465 while ( ( entry = readdir( dir ) ) != NULL )
02466 {
02467 if ( entry->d_name[0] != '.' )
02468 {
02469 ostringstream sb;
02470 sb << directory << "/" << entry->d_name << ends;
02471 unlink( sb.str().c_str() );
02472 }
02473 }
02474 closedir( dir );
02475
02476 // Second, write each dirty backup
02477 // absolute filenames is faster and more appropriate here
02478 bool isRelative = Preferences::getInstance().relativeSave;
02479 Preferences::getInstance().relativeSave = false;
02480 for ( size_t i = 0; i < backups.size(); ++i )
02481 {
02482 if ( backups[i]->IsDirty() )
02483 {
02484 ostringstream sb;
02485 sb << directory << "/" << i << ".xml" << ends;
02486 // save in legacy format for speed
02487 backups[i]->SavePlayList( const_cast<char*>( sb.str().c_str() ), true );
02488 }
02489 }
02490 Preferences::getInstance().relativeSave = isRelative;
02491 }
02492 }
02493 }
|
|
|
Definition at line 2495 of file playlist.cc. References backups, PlayList::Delete(), PlayList::GetNumFrames(), PlayList::InsertPlayList(), PlayList::IsDirty(), position, and PlayList::SetDirty(). Referenced by Restore(). 02496 {
02497 cerr << ">>> Received request to undo from position " << position - 1 << endl;
02498 if ( position > 0 )
02499 {
02500 position --;
02501 playlist->Delete( 0, playlist->GetNumFrames() - 1 );
02502 PlayList temp( *( backups[ position ] ) );
02503 playlist->InsertPlayList( temp, 0 );
02504 playlist->SetDirty( temp.IsDirty( ) );
02505 }
02506 else
02507 {
02508 cerr << ">>>> Unable to satisfy request." << endl;
02509 }
02510 }
|
|
|
Definition at line 126 of file playlist.h. Referenced by Clear(), Redo(), SetAllDirty(), Store(), Undo(), and ~EditorBackup(). |
|
|
Definition at line 124 of file playlist.h. Referenced by EditorBackup(), and Store(). |
|
|
Definition at line 125 of file playlist.h. Referenced by Clear(), Redo(), Restore(), SetAllDirty(), Store(), and Undo(). |
1.4.2