]> git.lyx.org Git - lyx.git/blobdiff - src/EmbeddedFiles.h
Continue working on the embedding feature. An additional parameter updateFile is...
[lyx.git] / src / EmbeddedFiles.h
index 07c522a931e9ffe12c5123bfcb60f4e75ee93674..42b02f39c7142da43709ac3e949d7a79d8853783 100644 (file)
@@ -102,7 +102,27 @@ public:
                std::string const & buffer_path = std::string());
        
        /// set filename and inzipName.
+       /**
+        * NOTE: inzip_name_ is not unique across operation systems and is not 
+        * guaranteed to be the same across different versions of lyx.
+        * inzip_name_ will be saved to the lyx file, and is used to indicate 
+        * whether or not a file is embedded, and where the embedded file is in
+        * the bundled file. However, the embedded file will be renamed to the 
+        * name set here when an EmbeddedFile is enabled. It is therefore
+        * safe to change the naming scheme here.
+        *
+        * NOTE that this treatment does not welcome an UUID solution because
+        * all embedded files will have to be renamed when an embedded file is
+        * opened. It is of course possible to use saved inzipname, but that is
+        * not easy. For example, when a new EmbeddedFile is created with the same
+        * file as an old one, it needs to be synced to the old inzipname...
+       **/
        void set(std::string const & filename, std::string const & buffer_path);
+       /** Set the inzip name of an EmbeddedFile, which should be the name
+        *  of an actual embedded file on disk. When an EmbeddedFile is enabled,
+        *  this file will be renamed to the default inzipName if needed. 
+        */
+       void setInzipName(std::string const & name);
 
        /// filename in the zip file, which is the relative path
        std::string inzipName() const { return inzip_name_; }
@@ -121,14 +141,13 @@ public:
 
        /// embedding status of this file
        bool embedded() const { return embedded_; }
-       /// set embedding status. updateFromExternal() should be called before this
-       /// to copy or sync the embedded file with external one.
+       /// set embedding status. 
        void setEmbed(bool embed);
 
        /// whether or not embedding is enabled in the current buffer
        bool enabled() const { return temp_path_ != ""; }
        /// enable embedding of this file
-       void enable(bool flag, Buffer const * buf);
+       void enable(bool flag, Buffer const * buf, bool updateFile);
 
        /// extract file, does not change embedding status
        bool extract() const;
@@ -140,13 +159,20 @@ public:
        /// embedded file instead of external file. To make sure inset pointers 
        /// are up to date, please make sure there is no modification to the
        /// document between EmbeddedFiles::update() and this function.
-       void updateInsets(Buffer const * buf) const;
+       void updateInsets() const;
 
        /// Check readability of availableFile
        bool isReadableFile() const;
        /// Calculate checksum of availableFile
        unsigned long checksum() const;
 
+private:
+       // calculate inzip_name_ from filename
+       std::string calcInzipName(std::string const & buffer_path);
+       // move an embedded disk file with an existing inzip_name_ to 
+       // an calculated inzip_name_
+       void syncInzipFile(std::string const & buffer_path);
+       
 private:
        /// filename in zip file
        std::string inzip_name_;
@@ -167,11 +193,11 @@ bool operator==(EmbeddedFile const & lhs, EmbeddedFile const & rhs);
 bool operator!=(EmbeddedFile const & lhs, EmbeddedFile const & rhs);
 
 
-class EmbeddedFiles : public std::vector<EmbeddedFile> {
+class EmbeddedFileList : public std::vector<EmbeddedFile> {
 public:
        /// set buffer params embedded flag. Files will be updated or extracted
        /// if such an operation fails, enable will fail.
-       void enable(bool flag, Buffer & buffer);
+       void enable(bool flag, Buffer & buffer, bool updateFile);
 
        /// add a file item.
        /* \param file Embedded file to add