1 #include "bcdisplayinfo.h"
14 int action; // 1 = update from client, 2 = client closes
19 #define _(String) gettext(String)
20 #define gettext_noop(String) String
21 #define N_(String) gettext_noop (String)
23 #include "empty_svg.h"
27 PLUGIN_THREAD_OBJECT(SvgMain, SvgThread, SvgWin)
34 SvgWin::SvgWin(SvgMain *client, int x, int y)
35 : BC_Window(client->gui_string,
46 this->client = client;
54 int SvgWin::create_objects()
58 // add_tool(new BC_Title(x, y, _("In X:")));
60 // in_x = new SvgCoord(this, client, x, y, &client->config.in_x);
61 // in_x->create_objects();
64 // add_tool(new BC_Title(x, y, _("In Y:")));
66 // in_y = new SvgCoord(this, client, x, y, &client->config.in_y);
67 // in_y->create_objects();
70 // add_tool(new BC_Title(x, y, _("In W:")));
72 // in_w = new SvgCoord(this, client, x, y, &client->config.in_w);
73 // in_w->create_objects();
76 // add_tool(new BC_Title(x, y, _("In H:")));
78 // in_h = new SvgCoord(this, client, x, y, &client->config.in_h);
79 // in_h->create_objects();
85 add_tool(new BC_Title(x, y, _("Out X:")));
87 out_x = new SvgCoord(this, client, x, y, &client->config.out_x);
88 out_x->create_objects();
91 add_tool(new BC_Title(x, y, _("Out Y:")));
93 out_y = new SvgCoord(this, client, x, y, &client->config.out_y);
94 out_y->create_objects();
97 /* add_tool(new BC_Title(x, y, _("Out W:")));
99 out_w = new SvgCoord(this, client, x, y, &client->config.out_w);
100 out_w->create_objects();
103 add_tool(new BC_Title(x, y, _("Out H:")));
105 out_h = new SvgCoord(this, client, x, y, &client->config.out_h);
106 out_h->create_objects();
110 add_tool(new_svg_button = new NewSvgButton(client, this, x, y));
111 add_tool(edit_svg_button = new EditSvgButton(client, this, x+190, y));
112 add_tool(svg_file_title = new BC_Title(x, y+26, client->config.svg_file));
121 int SvgWin::close_event()
127 SvgCoord::SvgCoord(SvgWin *win,
132 : BC_TumbleTextBox(win,
140 //printf("SvgWidth::SvgWidth %f\n", client->config.w);
141 this->client = client;
146 SvgCoord::~SvgCoord()
150 int SvgCoord::handle_event()
152 *value = atof(get_text());
154 client->send_configure_change();
158 NewSvgButton::NewSvgButton(SvgMain *client, SvgWin *window, int x, int y)
159 : BC_GenericButton(x, y, _("New/Open SVG..."))
161 this->client = client;
162 this->window = window;
165 int NewSvgButton::handle_event()
167 window->editing_lock.lock();
168 if (!window->editing)
171 window->editing_lock.unlock();
176 // FIXME - display an error
177 window->editing_lock.unlock();
183 void NewSvgButton::run()
185 // ======================================= get path from user
187 //printf("NewSvgButton::run 1\n");
188 char directory[1024], filename[1024];
192 sprintf(directory, "~");
193 client->defaults->get("DIRECTORY", directory);
195 // Loop until file is chosen
197 NewSvgWindow *new_window;
199 new_window = new NewSvgWindow(client, window, directory);
200 new_window->create_objects();
201 new_window->update_filter("*.svg");
202 result = new_window->run_window();
203 client->defaults->update("DIRECTORY", new_window->get_path(0));
204 strcpy(filename, new_window->get_path(0));
207 // Extend the filename with .svg
208 if(strlen(filename) < 4 ||
209 strcasecmp(&filename[strlen(filename) - 4], ".svg"))
211 strcat(filename, ".svg");
214 // ======================================= try to save it
215 if((filename[0] == 0) || (result == 1)) {
216 window->editing_lock.lock();
218 window->editing_lock.unlock();
219 return; // no filename given
222 if(in = fopen(filename, "rb"))
230 in = fopen(filename, "w+");
232 size = (((unsigned long)empty_svg[0]) << 24) +
233 (((unsigned long)empty_svg[1]) << 16) +
234 (((unsigned long)empty_svg[2]) << 8) +
235 ((unsigned long)empty_svg[3]);
236 printf("in: %p size: %li\n", in, size);
237 // FIXME this is not cool on different arhitectures
239 fwrite(empty_svg+4, size, 1, in);
243 } while(result); // file doesn't exist so repeat
246 window->svg_file_title->update(filename);
248 strcpy(client->config.svg_file, filename);
249 client->need_reconfigure = 1;
250 client->force_raw_render = 1;
251 client->send_configure_change();
254 if(quit_now) window->set_done(0);
255 window->editing_lock.lock();
257 window->editing_lock.unlock();
262 EditSvgButton::EditSvgButton(SvgMain *client, SvgWin *window, int x, int y)
263 : BC_GenericButton(x, y, _("Edit"))
265 this->client = client;
266 this->window = window;
270 EditSvgButton::~EditSvgButton() {
271 struct fifo_struct fifo_buf;
272 fifo_buf.pid = getpid();
275 write (fh_fifo, &fifo_buf, sizeof(fifo_buf)); // break the thread out of reading from fifo
278 int EditSvgButton::handle_event()
281 window->editing_lock.lock();
282 if (!window->editing && client->config.svg_file[0] != 0)
285 window->editing_lock.unlock();
289 // FIXME - display an error
290 window->editing_lock.unlock();
295 void EditSvgButton::run()
297 // ======================================= get path from user
303 char filename_raw[1024];
304 char filename_fifo[1024];
305 struct fifo_struct fifo_buf;
306 SvgSodipodiThread *sodipodi_thread = new SvgSodipodiThread(client, window);
308 strcpy(filename_raw, client->config.svg_file);
309 strcat(filename_raw, ".raw");
310 result = stat (filename_raw, &st_raw);
311 last_update = st_raw.st_mtime;
315 strcpy(filename_fifo, filename_raw);
316 strcat(filename_fifo, ".fifo");
317 if (mkfifo(filename_fifo, S_IRWXU) != 0) {
318 perror("Error while creating fifo file");
320 fh_fifo = open(filename_fifo, O_RDWR);
322 sodipodi_thread->fh_fifo = fh_fifo;
323 sodipodi_thread->start();
324 while (sodipodi_thread->running() && (!quit_now)) {
325 // pausetimer.delay(200); // poll file every 200ms
326 read(fh_fifo, &fifo_buf, sizeof(fifo_buf));
328 if (fifo_buf.action == 1) {
329 result = stat (filename_raw, &st_raw);
330 // Check if PNG is newer then what we have in memory
331 // printf("action1\n");
332 // if (last_update < st_raw.st_mtime) { // FIXME this seems to work odd sometimes when fast-refreshing
333 // printf("newer pict\n");
335 client->config.last_load = 1;
336 client->send_configure_change();
337 last_update = st_raw.st_mtime;
340 if (fifo_buf.action == 2) {
341 printf(_("Sodipodi has exited\n"));
343 if (fifo_buf.action == 3) {
344 printf(_("Plugin window has closed\n"));
345 delete sodipodi_thread;
350 sodipodi_thread->join();
352 window->editing_lock.lock();
354 window->editing_lock.unlock();
358 SvgSodipodiThread::SvgSodipodiThread(SvgMain *client, SvgWin *window)
361 this->client = client;
362 this->window = window;
365 SvgSodipodiThread::~SvgSodipodiThread()
367 // what do we do? kill sodipodi?
371 void SvgSodipodiThread::run()
375 char filename_raw[1024];
376 strcpy(filename_raw, client->config.svg_file);
377 strcat(filename_raw, ".raw");
379 sprintf(command, "sodipodi --cinelerra-export-file=%s %s",
380 filename_raw, client->config.svg_file);
381 printf(_("Running external SVG editor: %s\n"), command);
384 printf(_("External SVG editor finished\n"));
386 struct fifo_struct fifo_buf;
387 fifo_buf.pid = getpid();
389 write (fh_fifo, &fifo_buf, sizeof(fifo_buf));
397 NewSvgWindow::NewSvgWindow(SvgMain *client, SvgWin *window, char *init_directory)
399 BC_WindowBase::get_resources()->filebox_h / 2,
401 _("SVG Plugin: Pick SVG file"),
402 _("Open an existing SVG file or create a new one"))
404 this->window = window;
407 NewSvgWindow::~NewSvgWindow() {}