X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Fsvg%2Fsvgwin.C;h=028a9307772c470aa2645bcf02f72064bda947ba;hp=702d67b4f5258b09524f476219c9338fb02a9b17;hb=a19a685a46ddc630010788707d9e5b9d2342af46;hpb=c4bf1f625b640ef45136dcf66b639e2a55bd8334 diff --git a/cinelerra-5.1/plugins/svg/svgwin.C b/cinelerra-5.1/plugins/svg/svgwin.C index 702d67b4..028a9307 100644 --- a/cinelerra-5.1/plugins/svg/svgwin.C +++ b/cinelerra-5.1/plugins/svg/svgwin.C @@ -2,26 +2,27 @@ /* * CINELERRA * Copyright (C) 2008 Adam Williams - * + * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * */ #include "svgwin.h" #include "filexml.h" #include "language.h" +#include "mainerror.h" #include #include @@ -29,6 +30,9 @@ #include #include #include +#include +#include + #include #include "empty_svg.h" @@ -105,6 +109,7 @@ void SvgWin::create_objects() int SvgWin::close_event() { + new_svg_button->stop(); edit_svg_button->stop(); set_done(1); return 1; @@ -112,6 +117,7 @@ int SvgWin::close_event() int SvgWin::hide_window(int flush) { + new_svg_button->stop(); edit_svg_button->stop(); return BC_WindowBase::hide_window(flush); } @@ -160,8 +166,14 @@ NewSvgButton::NewSvgButton(SvgMain *client, SvgWin *window, int x, int y) { this->client = client; this->window = window; + new_window = 0; +} +NewSvgButton::~NewSvgButton() +{ + stop(); } + int NewSvgButton::handle_event() { window->editing_lock.lock(); @@ -196,19 +208,18 @@ void NewSvgButton::run() char *cp = getenv("HOME"); if( cp ) strncpy(directory, cp, sizeof(directory)); } - NewSvgWindow *new_window = new NewSvgWindow(client, window, directory); + new_window = new NewSvgWindow(client, window, directory); new_window->create_objects(); new_window->update_filter("*.svg"); result = new_window->run_window(); const char *filepath = new_window->get_path(0); - strcpy(filename, filepath); - delete new_window; - if( result || !filepath || !*filepath ) { - window->editing_lock.lock(); + strcpy(filename, filepath ? filepath : "" ); + delete new_window; new_window = 0; + window->editing_lock.lock(); + if( result || !filename[0] ) window->editing = 0; - window->editing_lock.unlock(); - return; // cancel or no filename given - } + window->editing_lock.unlock(); + if( !window->editing ) return; // cancel or no filename given // Extend the filename with .svg if( strlen(filename) < 4 || @@ -228,11 +239,9 @@ void NewSvgButton::run() } } } while(result); // file doesn't exist so repeat - + strcpy(client->config.svg_file, filename); - struct stat st; - client->config.ms_time = stat(filename, &st) ? 0 : - st.st_mtim.tv_sec*1000 + st.st_mtim.tv_nsec/1000000; + client->config.ms_time = 0; window->update_gui(client->config); client->send_configure_change(); @@ -243,6 +252,14 @@ void NewSvgButton::run() return; } +void NewSvgButton::stop() +{ + if( new_window ) { + new_window->set_done(1); + } + join(); +} + EditSvgButton::EditSvgButton(SvgMain *client, SvgWin *window, int x, int y) : BC_GenericButton(x, y, _("Edit")), Thread(1) { @@ -271,7 +288,7 @@ void EditSvgButton::stop() int EditSvgButton::handle_event() { - + window->editing_lock.lock(); if( !window->editing && client->config.svg_file[0] != 0 ) { window->editing = 1; @@ -294,7 +311,7 @@ void EditSvgButton::run() strcat(filename_png, ".png"); remove(filename_png); strcpy(filename_fifo, filename_png); - strcat(filename_fifo, ".fifo"); + strcat(filename_fifo, ".fifo"); remove(filename_fifo); if( !mkfifo(filename_fifo, S_IRWXU) && (fh_fifo = ::open(filename_fifo, O_RDWR+O_NONBLOCK)) >= 0 ) { @@ -354,15 +371,40 @@ SvgInkscapeThread::~SvgInkscapeThread() join(); } +static int exec_command(char* const*argv) +{ + pid_t pid = vfork(); + if( pid < 0 ) return -1; + if( pid > 0 ) { + int stat = 0; + waitpid(pid, &stat, 0); + if( stat ) { + char msg[BCTEXTLEN]; + sprintf(msg, "%s: error exit status %d", argv[0], stat); + MainError::show_error(msg); + } + return 0; + } + execvp(argv[0], &argv[0]); + return -1; +} + void SvgInkscapeThread::run() { // Runs the inkscape char command[1024]; - sprintf(command, "inkscape --with-gui %s", edit->client->config.svg_file); + snprintf(command, sizeof(command), + "inkscape --with-gui %s", edit->client->config.svg_file); printf(_("Running external SVG editor: %s\n"), command); + char *const argv[] = { + (char*) "inkscape", + (char*)"--with-gui", + edit->client->config.svg_file, + 0, + }; enable_cancel(); - system(command); + exec_command(argv); printf(_("External SVG editor finished\n")); struct fifo_struct fifo_buf; fifo_buf.pid = getpid(); @@ -374,7 +416,6 @@ void SvgInkscapeThread::run() } - NewSvgWindow::NewSvgWindow(SvgMain *client, SvgWin *window, char *init_directory) : BC_FileBox(0, BC_WindowBase::get_resources()->filebox_h / 2,