Author: kitone
Date: Fri Jan  2 20:46:18 2015
New Revision: 876

URL: http://svn.gna.org/viewcvs/subtitleeditor?rev=876&view=rev
Log:
Fix bug #22508 : Use (at least optionaly) relative paths in subtitle editor xml 
files (and optionally ass and ssa?).

Modified:
    trunk/ChangeLog
    trunk/plugins/actions/wavefrommanagement/waveformmanagement.cc
    trunk/plugins/subtitleformats/subtitleeditorproject/subtitleeditorproject.cc

Modified: trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/subtitleeditor/trunk/ChangeLog?rev=876&r1=875&r2=876&view=diff
==============================================================================
--- trunk/ChangeLog     (original)
+++ trunk/ChangeLog     Fri Jan  2 20:46:18 2015
@@ -1,3 +1,9 @@
+2015-01-02  kitone  <[email protected]>
+
+       * plugins/actions/wavefrommanagement/waveformmanagement.cc:
+       * 
plugins/subtitleformats/subtitleeditorproject/subtitleeditorproject.cc:
+       Fix bug #22508 : Use (at least optionaly) relative paths in subtitle 
editor xml files (and optionally ass and ssa?).
+
 2015-01-01  kitone  <[email protected]>
 
        * plugins/actions/plaintext/plaintext.cc:

Modified: trunk/plugins/actions/wavefrommanagement/waveformmanagement.cc
URL: 
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/actions/wavefrommanagement/waveformmanagement.cc?rev=876&r1=875&r2=876&view=diff
==============================================================================
--- trunk/plugins/actions/wavefrommanagement/waveformmanagement.cc      
(original)
+++ trunk/plugins/actions/wavefrommanagement/waveformmanagement.cc      Fri Jan 
 2 20:46:18 2015
@@ -204,9 +204,6 @@
                wm->signal_waveform_changed().connect(
                                sigc::mem_fun(*this, 
&WaveformManagement::update_ui));
 
-               wm->signal_waveform_changed().connect(
-                               sigc::mem_fun(*this, 
&WaveformManagement::on_waveform_changed));
-
                get_config().signal_changed("waveform").connect(
                                sigc::mem_fun(*this, 
&WaveformManagement::on_config_waveform_changed));
 
@@ -304,6 +301,7 @@
                        {
                                get_waveform_manager()->set_waveform(wf);
                                add_in_recent_manager(wf->get_uri());
+                               update_player_from_waveform();
                        }
                        else
                        {
@@ -312,6 +310,7 @@
                                {
                                        
get_waveform_manager()->set_waveform(wf);
                                        on_save_waveform();
+                                       update_player_from_waveform();
                                }
                        }
                }
@@ -435,7 +434,7 @@
         * Update the video player with the new Waveform
         * only if it's different.
         */
-       void on_waveform_changed()
+       void update_player_from_waveform()
        {
                Glib::RefPtr<Waveform> wf = 
get_waveform_manager()->get_waveform();
                if(wf && get_subtitleeditor_window()->get_player()->get_uri() 
!= wf->m_video_uri)

Modified: 
trunk/plugins/subtitleformats/subtitleeditorproject/subtitleeditorproject.cc
URL: 
http://svn.gna.org/viewcvs/subtitleeditor/trunk/plugins/subtitleformats/subtitleeditorproject/subtitleeditorproject.cc?rev=876&r1=875&r2=876&view=diff
==============================================================================
--- 
trunk/plugins/subtitleformats/subtitleeditorproject/subtitleeditorproject.cc    
    (original)
+++ 
trunk/plugins/subtitleformats/subtitleeditorproject/subtitleeditorproject.cc    
    Fri Jan  2 20:46:18 2015
@@ -21,6 +21,7 @@
  */
 
 #include <extension/subtitleformat.h>
+#include <filereader.h>
 #include <utility.h>
 #include <waveformmanager.h>
 #include <player.h>
@@ -49,6 +50,8 @@
        {
                try
                {
+                       initalize_dirname(file);
+
                        xmlpp::DomParser parser;
                        //parser.set_validate();
                        parser.set_substitute_entities();
@@ -102,6 +105,39 @@
 
        /*
         */
+       void initalize_dirname(Reader &reader)
+       {
+               FileReader *fr = dynamic_cast<FileReader*>(&reader);
+               if(fr != NULL)
+               {
+                       Glib::ustring filename = 
Glib::filename_from_uri(fr->get_uri());
+                       m_project_dirname = Glib::path_get_dirname(filename);
+               }
+       }
+
+       /*
+        */
+       bool test_uri(const Glib::ustring &uri)
+       {
+               return test_filename( Glib::filename_from_uri(uri) );
+       }
+
+       bool test_filename(const Glib::ustring &filename)
+       {
+               return Glib::file_test(filename, Glib::FILE_TEST_EXISTS);
+       }
+
+       /*
+        */
+       Glib::ustring uri_to_project_relative_filename(const Glib::ustring &uri)
+       {
+               Glib::ustring basename = Glib::path_get_basename( 
Glib::filename_from_uri(uri) );
+               Glib::ustring relative = 
Glib::build_filename(m_project_dirname, basename);
+               return Glib::filename_to_uri(relative);
+       }
+
+       /*
+        */
        const xmlpp::Element* get_unique_children(const xmlpp::Node *root, 
const Glib::ustring &name)
        {
                const xmlpp::Node::NodeList children = root->get_children(name);
@@ -122,8 +158,13 @@
 
                Player *pl = SubtitleEditorWindow::get_instance()->get_player();
 
-               if(pl->get_uri() != uri)
-                       pl->open(uri);
+               if(pl->get_uri() == uri)
+                       return;
+
+               if(!test_uri(uri) &&  
test_uri(uri_to_project_relative_filename(uri)) )
+                       uri =  uri_to_project_relative_filename(uri);
+
+               pl->open(uri);
        }
 
        /*
@@ -151,8 +192,13 @@
                        return;
 
                Glib::ustring uri = xml_wf->get_attribute_value("uri");
-               if(!uri.empty())
-                       
SubtitleEditorWindow::get_instance()->get_waveform_manager()->open_waveform(uri);
+               if(uri.empty())
+                       return;
+
+               if(!test_uri(uri) &&  
test_uri(uri_to_project_relative_filename(uri)) )
+                       uri =  uri_to_project_relative_filename(uri);
+
+               
SubtitleEditorWindow::get_instance()->get_waveform_manager()->open_waveform(uri);
        }
 
        /*
@@ -183,10 +229,13 @@
                Glib::ustring uri = xml_kf->get_attribute_value("uri");
                if(uri.empty())
                        return;
+
+               if(!test_uri(uri) &&  
test_uri(uri_to_project_relative_filename(uri)) )
+                       uri =  uri_to_project_relative_filename(uri);
+
                Glib::RefPtr<KeyFrames> kf = KeyFrames::create_from_file(uri);
-               if(!kf)
-                       return;
-               
SubtitleEditorWindow::get_instance()->get_player()->set_keyframes(kf);
+               if(kf)
+                       
SubtitleEditorWindow::get_instance()->get_player()->set_keyframes(kf);
        }
 
        /*
@@ -369,6 +418,9 @@
                        xmlsub->set_attribute("path", selection[i].get("path"));
                }
        }
+
+protected:
+       Glib::ustring m_project_dirname;
 };
 
 class SubtitleEditorProjectPlugin : public SubtitleFormat


_______________________________________________
Subtitleeditor-commits mailing list
[email protected]
https://mail.gna.org/listinfo/subtitleeditor-commits

Reply via email to