~centralelyon2010/inkscape/imagelinks2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
 * 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 <vector>
#include "sp-object.h"
//#include "document.h"
#include <gtk-2.0/gtk/gtk.h>


/**

 * 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 <SPObject *> > unlinked_image; // Set of image with broken link
	std::vector<Relink *> relink;

	/* Static variable useful if we relink an image with a path which is not an image readable
	 * by inkscape.
	*/
	std::vector<char const *> last_linked_attribute;
	std::vector<SPObject *> 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 <SPObject *>::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 <SPObject *>::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 :