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];
189 sprintf(directory, "~");
190 client->defaults->get("DIRECTORY", directory);
193 // Loop until file is chosen
195 NewSvgWindow *new_window;
197 new_window = new NewSvgWindow(client, window, directory);
198 new_window->create_objects();
199 new_window->update_filter("*.svg");
200 result = new_window->run_window();
201 client->defaults->update("DIRECTORY", new_window->get_path(0));
202 strcpy(filename, new_window->get_path(0));
205 // Extend the filename with .svg
206 if(strlen(filename) < 4 ||
207 strcasecmp(&filename[strlen(filename) - 4], ".svg"))
209 strcat(filename, ".svg");
212 // ======================================= try to save it
213 if((filename[0] == 0) || (result == 1)) {
214 window->editing_lock.lock();
216 window->editing_lock.unlock();
217 return; // no filename given
220 if(in = fopen(filename, "rb"))
228 in = fopen(filename, "w+");
230 size = (((unsigned long)empty_svg[0]) << 24) +
231 (((unsigned long)empty_svg[1]) << 16) +
232 (((unsigned long)empty_svg[2]) << 8) +
233 ((unsigned long)empty_svg[3]);
234 printf("in: %p size: %li\n", in, size);
235 // FIXME this is not cool on different arhitectures
237 fwrite(empty_svg+4, size, 1, in);
241 } while(result); // file doesn't exist so repeat
244 window->svg_file_title->update(filename);
246 strcpy(client->config.svg_file, filename);
247 client->need_reconfigure = 1;
248 client->force_raw_render = 1;
249 client->send_configure_change();
252 if(quit_now) window->set_done(0);
253 window->editing_lock.lock();
255 window->editing_lock.unlock();
260 EditSvgButton::EditSvgButton(SvgMain *client, SvgWin *window, int x, int y)
261 : BC_GenericButton(x, y, _("Edit"))
263 this->client = client;
264 this->window = window;
268 EditSvgButton::~EditSvgButton() {
269 struct fifo_struct fifo_buf;
270 fifo_buf.pid = getpid();
273 write (fh_fifo, &fifo_buf, sizeof(fifo_buf)); // break the thread out of reading from fifo
276 int EditSvgButton::handle_event()
279 window->editing_lock.lock();
280 if (!window->editing && client->config.svg_file[0] != 0)
283 window->editing_lock.unlock();
287 // FIXME - display an error
288 window->editing_lock.unlock();
293 void EditSvgButton::run()
295 // ======================================= get path from user
301 char filename_raw[1024];
302 char filename_fifo[1024];
303 struct fifo_struct fifo_buf;
304 SvgInkscapeThread *inkscape_thread = new SvgInkscapeThread(client, window);
306 strcpy(filename_raw, client->config.svg_file);
307 strcat(filename_raw, ".raw");
308 result = stat (filename_raw, &st_raw);
309 last_update = st_raw.st_mtime;
313 strcpy(filename_fifo, filename_raw);
314 strcat(filename_fifo, ".fifo");
315 if (mkfifo(filename_fifo, S_IRWXU) != 0) {
316 perror("Error while creating fifo file");
318 fh_fifo = open(filename_fifo, O_RDWR);
320 inkscape_thread->fh_fifo = fh_fifo;
321 inkscape_thread->start();
322 while (inkscape_thread->running() && (!quit_now)) {
323 // pausetimer.delay(200); // poll file every 200ms
324 read(fh_fifo, &fifo_buf, sizeof(fifo_buf));
326 if (fifo_buf.action == 1) {
327 result = stat (filename_raw, &st_raw);
328 // Check if PNG is newer then what we have in memory
329 // printf("action1\n");
330 // if (last_update < st_raw.st_mtime) { // FIXME this seems to work odd sometimes when fast-refreshing
331 // printf("newer pict\n");
333 client->config.last_load = 1;
334 client->send_configure_change();
335 last_update = st_raw.st_mtime;
338 if (fifo_buf.action == 2) {
339 printf(_("Inkscape has exited\n"));
341 if (fifo_buf.action == 3) {
342 printf(_("Plugin window has closed\n"));
343 delete inkscape_thread;
348 inkscape_thread->join();
350 window->editing_lock.lock();
352 window->editing_lock.unlock();
356 SvgInkscapeThread::SvgInkscapeThread(SvgMain *client, SvgWin *window)
359 this->client = client;
360 this->window = window;
363 SvgInkscapeThread::~SvgInkscapeThread()
365 // what do we do? kill inkscape?
369 void SvgInkscapeThread::run()
373 char filename_raw[1024];
374 strcpy(filename_raw, client->config.svg_file);
375 strcat(filename_raw, ".raw");
377 sprintf(command, "inkscape --cinelerra-export-file=%s %s",
378 filename_raw, client->config.svg_file);
379 printf(_("Running external SVG editor: %s\n"), command);
382 printf(_("External SVG editor finished\n"));
384 struct fifo_struct fifo_buf;
385 fifo_buf.pid = getpid();
387 write (fh_fifo, &fifo_buf, sizeof(fifo_buf));
395 NewSvgWindow::NewSvgWindow(SvgMain *client, SvgWin *window, char *init_directory)
397 BC_WindowBase::get_resources()->filebox_h / 2,
399 _("SVG Plugin: Pick SVG file"),
400 _("Open an existing SVG file or create a new one"))
402 this->window = window;
405 NewSvgWindow::~NewSvgWindow() {}