From c72d222e84938c630afde114b3cce83528974e53 Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Thu, 10 Sep 2009 16:01:12 +0530 Subject: [PATCH] Action Copy/Paste support This patch adds support fot copy/paste supports of action lists to solang. An user will be able to copy a set of applied actions from one photo and paste it onto others. --- data/solang-editor.ui | 20 ++++++----------- data/solang.ui | 12 ++------- src/edit-engine/Makefile.am | 6 +---- src/edit-engine/buffer.cpp | 6 ++-- src/edit-engine/edit-engine.cpp | 5 ++- src/edit-engine/edit-engine.h | 3 +- src/edit-engine/operation.cpp | 15 ++++++++---- src/edit-engine/operation.h | 3 +- src/editor/desaturate.cpp | 6 +++++ src/editor/desaturate.h | 3 ++ src/editor/edit-action-history.cpp | 9 ++++++- src/editor/edit-action.h | 2 + src/editor/editable-photo.h | 9 +++++++ src/editor/editor.cpp | 38 ++++++++++++++++++++++++++++++++ src/editor/flip.cpp | 6 +++++ src/editor/flip.h | 3 ++ src/editor/gegl-operation.cpp | 12 ++++++++- src/editor/gegl-operation.h | 3 ++ src/editor/rotate.cpp | 6 +++++ src/editor/rotate.h | 3 ++ src/editor/scale.cpp | 6 +++++ src/editor/scale.h | 3 ++ src/importer/flickr-chooser-dialog.cpp | 2 +- src/importer/flickr-source.cpp | 2 +- 24 files changed, 138 insertions(+), 45 deletions(-) diff --git a/data/solang-editor.ui b/data/solang-editor.ui index 8853cda..5fd7794 100644 --- a/data/solang-editor.ui +++ b/data/solang-editor.ui @@ -6,19 +6,10 @@ - + + + + @@ -29,6 +20,9 @@ + + + diff --git a/data/solang.ui b/data/solang.ui index bf1de18..79bfa38 100644 --- a/data/solang.ui +++ b/data/solang.ui @@ -24,12 +24,8 @@ - - - + - - @@ -49,15 +45,13 @@ + + - - - - diff --git a/src/edit-engine/Makefile.am b/src/edit-engine/Makefile.am index 55e4fde..2115d05 100644 --- a/src/edit-engine/Makefile.am +++ b/src/edit-engine/Makefile.am @@ -12,14 +12,10 @@ libeditengine_la_SOURCES = \ edit-engine.cpp \ filter.cpp \ filter.h \ - flip-operation.cpp \ - flip-operation.h \ load-file.cpp \ load-file.h \ operation.cpp \ - operation.h \ - scale-operation.cpp \ - scale-operation.h + operation.h AM_CPPFLAGS = \ -DPACKAGE_LOCALE_DIR=\""${datadir}/locale"\" \ diff --git a/src/edit-engine/buffer.cpp b/src/edit-engine/buffer.cpp index 1854a32..b43ed31 100644 --- a/src/edit-engine/buffer.cpp +++ b/src/edit-engine/buffer.cpp @@ -115,7 +115,7 @@ Buffer::get_pixbuf() throw() context->set_source( surface, 0, 0 ); context->paint(); #endif - std::cout<<"Here"<(dataBuffer), //buffer @@ -153,7 +153,7 @@ Buffer::open_image_file( const Glib::ustring &path, refresh_.emit(); return; } - std::cout<<"Open: "<get_root_node(), "operation", "gegl:load", @@ -178,7 +178,7 @@ Buffer::open_image_file( const Glib::ustring &path, while ( gegl_processor_work (processor, &progress) ) { obs->set_current_events( progress * 100.0 ); - std::cout<<"Prog: "<apply( observer_ ); + return op->apply( observer_, buffer ); } catch(Error &e) { diff --git a/src/edit-engine/edit-engine.h b/src/edit-engine/edit-engine.h index 684ff41..b44ea9a 100644 --- a/src/edit-engine/edit-engine.h +++ b/src/edit-engine/edit-engine.h @@ -38,7 +38,8 @@ class EditEngine init(const ProgressObserverPtr &observer) throw(); BufferPtr - apply( OperationPtr &op ) throw(Error); + apply( const OperationPtr &op, + const BufferPtr &buffer ) throw(Error); BufferPtr revert( OperationPtr &op ) throw(Error); diff --git a/src/edit-engine/operation.cpp b/src/edit-engine/operation.cpp index a814f38..badb17c 100644 --- a/src/edit-engine/operation.cpp +++ b/src/edit-engine/operation.cpp @@ -38,7 +38,7 @@ Operation::Operation( const BufferPtr &buffer ) :engine_( engine ), filter_( filter ), - original_( buffer ) + original_( ) { } @@ -48,10 +48,15 @@ Operation::~Operation() throw() BufferPtr Operation::apply( - const ProgressObserverPtr &observer) throw(Error) + const ProgressObserverPtr &observer, + const BufferPtr &original ) throw(Error) { +#ifdef SS_LATER + original_ = original; +#endif + GeglBufferPtr pBuf = gegl_buffer_dup( - original_->get_buffer() ); + original->get_buffer() ); GeglNodePtr pRoot = engine_->get_root_node(); if( !pRoot ) { @@ -82,7 +87,7 @@ Operation::apply( { observer->set_current_events( progress * 100.0 ); observer->progress().emit(); - std::cout<<"Done:"<set_root_node( NULL ); - //original_.reset(); + original_.reset(); return BufferPtr( new Buffer( pOutBuf ) ); diff --git a/src/edit-engine/operation.h b/src/edit-engine/operation.h index 5b50b76..32459a0 100644 --- a/src/edit-engine/operation.h +++ b/src/edit-engine/operation.h @@ -38,7 +38,8 @@ class Operation ~Operation() throw(); BufferPtr - apply( const ProgressObserverPtr &observer) throw(Error); + apply( const ProgressObserverPtr &observer, + const BufferPtr &buffer) throw(Error); BufferPtr revert( const ProgressObserverPtr &observer) throw(Error); diff --git a/src/editor/desaturate.cpp b/src/editor/desaturate.cpp index 949df33..198b760 100644 --- a/src/editor/desaturate.cpp +++ b/src/editor/desaturate.cpp @@ -85,4 +85,10 @@ Desaturate::reverse( EditablePhoto &photo ) throw(Error) } +EditActionPtr +Desaturate::clone() +{ + return EditActionPtr( new Desaturate( fraction_ ) ); +} + } //namespace Solang diff --git a/src/editor/desaturate.h b/src/editor/desaturate.h index 03970b4..0f98541 100644 --- a/src/editor/desaturate.h +++ b/src/editor/desaturate.h @@ -37,6 +37,9 @@ class Desaturate : virtual void reverse( EditablePhoto &photo) throw(Error); + virtual EditActionPtr + clone(); + private: double fraction_; PixbufPtr oldBuf_; diff --git a/src/editor/edit-action-history.cpp b/src/editor/edit-action-history.cpp index 029e804..4f63842 100644 --- a/src/editor/edit-action-history.cpp +++ b/src/editor/edit-action-history.cpp @@ -124,8 +124,13 @@ EditActionHistory::redo_actions( size_type steps ) EditActionList EditActionHistory::get_actions_for_copy() const throw() { - EditActionList actions( actions_.begin(), actions_.end() ); - return actions; + EditActionList copiedActions; + for( EditActionList::const_iterator it = actions_.begin(); + it != actions_.end(); it++ ) + { + copiedActions.push_back( (*it)->clone() ); + } + return copiedActions; } } //namespace Solang diff --git a/src/editor/edit-action.h b/src/editor/edit-action.h index 7275023..fd25eeb 100644 --- a/src/editor/edit-action.h +++ b/src/editor/edit-action.h @@ -40,6 +40,8 @@ class EditAction : virtual void reverse( EditablePhoto &photo) throw(Error) = 0; + + virtual EditActionPtr clone() = 0; }; } //namespace Solang diff --git a/src/editor/editable-photo.h b/src/editor/editable-photo.h index 63c439f..49360fc 100644 --- a/src/editor/editable-photo.h +++ b/src/editor/editable-photo.h @@ -97,6 +97,9 @@ class EditablePhoto void redo_last_action( ) throw(Error); + inline const EditActionHistory & + get_history() const throw(); + private: void @@ -150,5 +153,11 @@ EditablePhoto::get_to_save() const throw() return toSave_; } +inline const EditActionHistory & +EditablePhoto::get_history() const throw() +{ + return appliedActions_; +} + } //namespace Solang #endif diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index 930df9f..2c30b90 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -132,6 +132,24 @@ Editor::Editor( ) Gtk::AccelKey("y"), sigc::mem_fun(*this, &Editor::on_action_redo)); + actionGroup_->add( + Gtk::Action::create( + "ActionCopyHistory", + Gtk::Stock::COPY, + _("Copy Actions"), + _("Copy actions applied to this photo")), + Gtk::AccelKey("c"), + sigc::mem_fun(*this, &Editor::on_action_copy_actions)); + + actionGroup_->add( + Gtk::Action::create( + "ActionPasteHistory", + Gtk::Stock::PASTE, + _("Paste Actions"), + _("Paste copied actions")), + Gtk::AccelKey("v"), + sigc::mem_fun(*this, &Editor::on_action_paste_actions)); + #if 0 actionGroup_->add( @@ -366,7 +384,9 @@ void Editor::apply_action( const EditActionPtr &action, const EditablePhotoPtr &photo ) throw() { + static Glib::Mutex lock; CursorChanger tmp( application_->get_main_window() ); + Glib::Mutex::Lock l(lock); apply( action, photo ); } @@ -456,4 +476,22 @@ Editor::on_action_redo() throw() actionPerformed_.emit(); } +void +Editor::on_action_copy_actions() throw() +{ + copiedActions_ = currentPhoto_->get_history() + .get_actions_for_copy(); +} + +void +Editor::on_action_paste_actions() throw() +{ + for( EditActionList::iterator it = copiedActions_.begin(); + it != copiedActions_.end(); it++ ) + { + apply( *it ); + } +} + + } // namespace Solang diff --git a/src/editor/flip.cpp b/src/editor/flip.cpp index 7c19369..fd6f685 100644 --- a/src/editor/flip.cpp +++ b/src/editor/flip.cpp @@ -81,4 +81,10 @@ Flip::reverse( EditablePhoto &photo) throw(Error) } } +EditActionPtr +Flip::clone() +{ + return EditActionPtr( new Flip( horizontal_ ) ); +} + } //namespace Solang diff --git a/src/editor/flip.h b/src/editor/flip.h index a2058fa..84e7424 100644 --- a/src/editor/flip.h +++ b/src/editor/flip.h @@ -37,6 +37,9 @@ class Flip : virtual void reverse( EditablePhoto &photo) throw(Error); + virtual EditActionPtr + clone(); + private: bool horizontal_; }; diff --git a/src/editor/gegl-operation.cpp b/src/editor/gegl-operation.cpp index 79d4216..5c4519b 100644 --- a/src/editor/gegl-operation.cpp +++ b/src/editor/gegl-operation.cpp @@ -52,11 +52,12 @@ GeglOperation::execute( EditablePhoto &photo) throw(Error) if( !newBuf_ ) { oldBuf_ = photo.get_buffer(); - BufferPtr geglBuf = operation_->apply( observer_ ); + BufferPtr geglBuf = operation_->apply( observer_, + photo.get_edit_buffer() ); //photo.set_edit_buffer( newBuf ); PixbufPtr outBuf = geglBuf->get_pixbuf(); newBuf_ = outBuf; - operation_.reset(); + //operation_.reset(); } photo.set_buffer( newBuf_, false ); PixbufPtr thumb = photo.get_photo()->get_thumbnail_buffer(); @@ -91,4 +92,11 @@ GeglOperation::reverse( EditablePhoto &photo) throw(Error) } } +EditActionPtr +GeglOperation::clone() +{ + return EditActionPtr( new GeglOperation( operation_, observer_ ) ); +} + + } //namespace Solang diff --git a/src/editor/gegl-operation.h b/src/editor/gegl-operation.h index 8620bec..74fa490 100644 --- a/src/editor/gegl-operation.h +++ b/src/editor/gegl-operation.h @@ -39,6 +39,9 @@ class GeglOperation : virtual void reverse( EditablePhoto &photo) throw(Error); + virtual EditActionPtr + clone(); + private: OperationPtr operation_; PixbufPtr oldBuf_; diff --git a/src/editor/rotate.cpp b/src/editor/rotate.cpp index 4623de6..a51591f 100644 --- a/src/editor/rotate.cpp +++ b/src/editor/rotate.cpp @@ -83,6 +83,12 @@ Rotate::reverse( EditablePhoto &photo ) throw(Error) } } +EditActionPtr +Rotate::clone() +{ + return EditActionPtr( new Rotate( direction_ ) ); +} + void Rotate::rotatePhoto( EditablePhoto &photo, Direction direction ) throw(Error) diff --git a/src/editor/rotate.h b/src/editor/rotate.h index ae1dbaf..e95b3e8 100644 --- a/src/editor/rotate.h +++ b/src/editor/rotate.h @@ -44,6 +44,9 @@ class Rotate : virtual void reverse( EditablePhoto &photo) throw(Error); + virtual EditActionPtr + clone(); + private: void rotatePhoto( EditablePhoto &photo, Direction direction ) throw(Error); diff --git a/src/editor/scale.cpp b/src/editor/scale.cpp index 4084db3..2ada0fe 100644 --- a/src/editor/scale.cpp +++ b/src/editor/scale.cpp @@ -67,4 +67,10 @@ Scale::reverse( EditablePhoto &photo ) throw(Error) return; } +EditActionPtr +Scale::clone() +{ + return EditActionPtr( new Scale( fraction_ ) ); +} + } //namespace Solang diff --git a/src/editor/scale.h b/src/editor/scale.h index 400ca41..51fa051 100644 --- a/src/editor/scale.h +++ b/src/editor/scale.h @@ -37,6 +37,9 @@ class Scale : virtual void reverse( EditablePhoto &photo) throw(Error); + virtual EditActionPtr + clone(); + private: double fraction_; PixbufPtr oldBuf_; diff --git a/src/importer/flickr-chooser-dialog.cpp b/src/importer/flickr-chooser-dialog.cpp index b784622..96a8008 100644 --- a/src/importer/flickr-chooser-dialog.cpp +++ b/src/importer/flickr-chooser-dialog.cpp @@ -449,7 +449,7 @@ FlickrChooserDialog::on_read_flickr_progress() throw() = photos_[current_]; SoupMessage * soup_message = soup_message_new( - SOUP_METHOD_GET, + "GET", uris_[current_].c_str()); SoupSessionCBData * const data = new SoupSessionCBData(); diff --git a/src/importer/flickr-source.cpp b/src/importer/flickr-source.cpp index 5bce91e..70f3454 100644 --- a/src/importer/flickr-source.cpp +++ b/src/importer/flickr-source.cpp @@ -499,7 +499,7 @@ FlickrSource::download_photos(PhotoList & files, } SoupMessage * soup_message = soup_message_new( - SOUP_METHOD_GET, + "GET", iter->c_str()); const guint status = soup_session_send_message(soup_session, -- 1.6.0.4