/* * Broken image fix implemantation * * Authors: * Baptiste Soyer * Vincent Pais * * Released under GNU GPL, read the file 'COPYING' for more information */ #ifndef _RELINK_ #define _RELINK_ #include #include "sp-object.h" //#include "document.h" #include /** * This file is there to relink image whose has a broken link. This happens when a * an image has been moved or deleted, the link is then not valid and an error * is declared. We then asked the user to relink the image. A smart relinker is implemented * has to facilitate the relinking. The smart relinker find all file which maybe a link to a broken file, * and then asked the user if he wants the links to be replaced. * **/ class Relink; /* * A singleton class which register which image in which document has a broken link */ class Data_Relink { public: std::vector< std::vector > unlinked_image; // Set of image with broken link std::vector relink; /* Static variable useful if we relink an image with a path which is not an image readable * by inkscape. */ std::vector last_linked_attribute; std::vector last_linked_image; static Data_Relink * Instance() { static Data_Relink singleton; return &singleton; } static void Kill() { Data_Relink *data = Instance(); delete data; } private: Data_Relink() {}; // Private constructor Data_Relink(const Data_Relink&); // Prevent copy-construction Data_Relink& operator=(const Data_Relink&); // Prevent assignment ~Data_Relink() { unlinked_image.clear(); relink.clear(); last_linked_attribute.clear(); last_linked_image.clear(); } }; class Relink{ /*The attributes*/ private : /* The need to use those id, is that, apart from recoding a lot of function, in sp-image * we can't know from which document the broken image are added. So we declare an unique * id for each Relink instance, and we tell the add_image function to add the image to * the current id, which is declared in document.cpp. */ int id; //the id of the document where the relink object was called static int last_id; //a counter of total open document static int current_id; //the current document being updated SPDocument * doc; // the document from where the relink instance is bool first_opening; //Is it the first time we open the relink dialog /*All the usefull attributes to remember which images is broken, which path must be relink ...*/ std::vector < char *> to_relink_path;//The image path found by the smart_relink function std::vector < char const * > to_relink_image_id;//The id of the corresponding object std::vector < char * > to_free;//Some string to free /*The broken path of the relinked image*/ const char * broken_path; /*Public attribute*/ public : GtkWidget * windows_parent; gchar const* text_data; /*The private methods*/ private : /** \brief the function transform a string to be properly printed \param the string to be fransformed \return the tranformed string */ char * transform_char(char const*); /** \brief the function transform a string to be properly compared \param the string to be fransformed \return the tranformed string */ char * transform_path(char const * path_img); /** \brief a function wich look into a directory for image which can be used to relink the broken link \param the path of the directory \return true if we find anything */ bool smart_relink(gchar const*); /** \brief free the allocated memory in the vector to_relink_path */ void close_path(); /*The public methods*/ public : /** \brief getter for first_opening \return the value of first_opening */ bool is_first_opening() { return first_opening; } /** \brief relink an image \param 1 the position of the image in the vector \param 2 the path to relink to */ void relink_image(std::vector ::iterator, gchar const *); /** \brief a dialog where the user can choose to relink or not the images found with smart_relink function */ void smart_relink_dialog(); /** \brief a dialog box printing a message and closing the relink dialog \param do we want to save the preferences */ void close_with_message (bool save_pref = true); /** \brief the explore dialog to choose the new path of the image */ void explore (); /** \brief a function which close the previous one and calls relink_dialog to relink the broken link */ void continue_relink (); /** \brief a function which close the previous one, relink the image the user selected from the smart_relink_dialopg and calls relink_dialog or close_with_dialog depending if we have finished relinking or not */ void continue_smart_relink (); /** \brief set the current id for updating */ static void set_current_id(int); /** \brief get the last_id \return the id */ static int get_last_id(); /** \brief get the current_id \return the id */ static int get_current_id(); /** \brief get the id of the object \return the id */ int get_id(); /** \return true if an image has been found to be unlinked */ bool isUnlink(); /** \brief This function add a new SPimage to the unlinked_image vector \param The image to add */ static void add_image(SPObject *); /** \brief This function implements the gui of the relink class */ void relink_dialog(); //------------Functions for the image properties dialogue---------- /** \brief this function search for a specific image in the vector \param the pointer for the researched image \return true if the image is broken ie is in the unlinked_image vector */ static bool image_is_broken(SPObject *); /** \brief a function wich look if an object is broken or not \param the pointer for the researched image \return the position of the object in the unlinked_vector if the object is in it, or NULL of not */ static std::vector ::iterator image_is_broken_it(SPObject *); Relink(SPDocument *); ~Relink(); }; /** \brief open a browser to link an image (the fact this image has a broken link or not doesn't matter), and then try to relink the other broken images if they exist \param the pointer for the image we want to link */ void relink_for_img_properties(GtkWidget * widget, SPObject *object); #endif /* Local Variables: mode:c++ c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) indent-tabs-mode:nil fill-column:99 End: */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :