/* $Id$ */ /* * Cantus Tag Editor * Copyright © 2002-2004 by Samuel Abels * Copyright © 2007 by Tim Huetz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see **/ #ifdef HAVE_CONFIG_H # include #endif #ifndef HAVE_FILEINFO_H #define HAVE_FILEINFO_H class FileInfo; #include #include #include #include #define FILEINFO_HISTORY_LEN 10 typedef gint (*ReadFunc) (const gchar *filename, CantusHash *data); typedef gint (*WriteFunc)(const gchar *filename, CantusHash *data); class FileInfo : public sigc::trackable { protected: // Prevent copies. FileInfo(FileInfo &f) { g_assert_not_reached(); } // Prevent assignments. FileInfo& operator=(FileInfo &s) { g_assert_not_reached(); } public: /* Triggered whenever a file has been read. */ SigC::Signal1 signal_read_finished; /* Triggered whenever a file has been written. */ SigC::Signal1 signal_write_finished; /* The filename is being stored in the real hash and the edited hash as * well. The file is stated on construction. */ FileInfo(std::string filename); ~FileInfo(); /* Forces the file to be re-stated. Returns what stat returns. */ int restat(void); /* Returns the inode number of the file, or < 0 on an error. */ glong get_inode(void); /* Read all file informations into the real hash using the given Input * Plugin. * Returns an errorcode or 0. */ gint read(const ReadFunc func); /* Write all file informations from the real hash to the filesystem, using * the given output plugin. * Returns an errorcode or 0. */ gint write(const WriteFunc func); /* Returns a pointer to the file's "edited_hash". Make sure to "lock()" when * you do this! */ CantusHash *get_edited_hash(void); /* Lock the object from being accessed. */ void lock(void); /* Unlock the object so that it can be accessed. */ void unlock(void); /* Returns the filename from the real hash. Make sure to lock() before you * use this! */ const gchar *get_filename(void); /* Returns the filename from the edited hash. Make sure to lock() before you * use this! */ const gchar *get_edited_filename(void); /* Move the "real hash" onto an "UNDO" stack. Then, copy the edited hash into * the new real hash. Also, clear the "REDO" stack. */ void commit(void); /* Copy the real hash into the edited hash. */ void revert(void); /* Push the edited hash onto the "REDO" stack. Then, pop the last item from * the "UNDO" stack into the edited hash. * Returns FALSE when the "UNDO" list was empty so nothing has been changed. */ gboolean undo(void); /* Push the edited hash onto the "UNDO" stack. Then, pop the last item from * the "REDO" stack into the edited hash. * Returns FALSE when the "REDO" list was empty so nothing has been changed. */ gboolean redo(void); private: /* Push something to the history (for UNDO). */ void history_push(CantusHash *hash); /* Get something from the history (for UNDO). */ CantusHash *history_pop(void); /* Get something to the future (for REDO). */ void future_push(CantusHash *hash); /* Get something from the future (for REDO). */ CantusHash *future_pop(void); /* Clear the future (for REDO). */ void future_clear(void); struct stat filestat; // Cache the stat structure. std::string real_filename; // A copy of the original filename. std::string edited_filename; // A copy of the edited filename. CantusHash *real_hash; // The file's data as on the filesystem. CantusHash *edited_hash; // The file's data as edited. std::list history; // The history of the data for UNDO. std::list future; // The future of the data for REDO. Glib::Mutex mutex; // One mutex to lock the whole object. }; #endif