New upstream version 0.79.5

This commit is contained in:
TANIGUCHI Takaki
2017-02-02 22:24:37 +09:00
parent 2f23ea4b4a
commit 9ad5d25d65
1931 changed files with 104660 additions and 254637 deletions

View File

@@ -1,41 +1,33 @@
/* dvdisaster: Additional error correction for optical media.
* Copyright (C) 2004-2012 Carsten Gnoerlich.
* Project home page: http://www.dvdisaster.com
* Email: carsten@dvdisaster.com -or- cgnoerlich@fsfe.org
* Copyright (C) 2004-2015 Carsten Gnoerlich.
*
* This program is free software; you can redistribute it and/or modify
* Email: carsten@dvdisaster.org -or- cgnoerlich@fsfe.org
* Project homepage: http://www.dvdisaster.org
*
* This file is part of dvdisaster.
*
* dvdisaster 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* dvdisaster 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,
* or direct your browser at http://www.gnu.org.
* along with dvdisaster. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dvdisaster.h"
#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
#include <sys/wait.h>
#endif
#ifdef SYS_MINGW
#include "windows.h"
#include "shellapi.h"
#endif
/***
*** Ask user to specify his browser
*** Ask user to specify his viewer
***/
#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
#define SEARCH_BUTTON 1
typedef struct
@@ -45,21 +37,21 @@ typedef struct
GtkWidget *filesel;
GtkWidget *fileok;
GtkWidget *filecancel;
char *url;
} browser_dialog_info;
char *path;
} viewer_dialog_info;
static void response_cb(GtkWidget *widget, int response, gpointer data)
{ browser_dialog_info *bdi = (browser_dialog_info*)data;
{ viewer_dialog_info *bdi = (viewer_dialog_info*)data;
switch(response)
{ case GTK_RESPONSE_ACCEPT:
if(Closure->browser) g_free(Closure->browser);
Closure->browser = g_strdup(gtk_entry_get_text(GTK_ENTRY(bdi->entry)));
ShowHTML(bdi->url);
if(Closure->viewer) g_free(Closure->viewer);
Closure->viewer = g_strdup(gtk_entry_get_text(GTK_ENTRY(bdi->entry)));
ShowPDF(bdi->path);
break;
case GTK_RESPONSE_REJECT:
if(bdi->url) g_free(bdi->url);
if(bdi->path) g_free(bdi->path);
break;
}
gtk_widget_destroy(widget);
@@ -69,10 +61,10 @@ static void response_cb(GtkWidget *widget, int response, gpointer data)
}
static void search_cb(GtkWidget *widget, gpointer data)
{ browser_dialog_info *bdi = (browser_dialog_info*)data;
{ viewer_dialog_info *bdi = (viewer_dialog_info*)data;
if(widget == bdi->search)
{ bdi->filesel = gtk_file_selection_new(_utf("windowtitle|Choose a browser"));
{ bdi->filesel = gtk_file_selection_new(_utf("windowtitle|Choose a PDF viewer"));
bdi->fileok = GTK_FILE_SELECTION(bdi->filesel)->ok_button;
bdi->filecancel = GTK_FILE_SELECTION(bdi->filesel)->cancel_button;
ReverseCancelOK(GTK_DIALOG(bdi->filesel));
@@ -88,9 +80,9 @@ static void search_cb(GtkWidget *widget, gpointer data)
if(widget == bdi->fileok)
{
if(Closure->browser) g_free(Closure->browser);
Closure->browser = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(bdi->filesel)));
ShowHTML(bdi->url);
if(Closure->viewer) g_free(Closure->viewer);
Closure->viewer = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(bdi->filesel)));
ShowPDF(bdi->path);
gtk_widget_destroy(bdi->filesel);
gtk_widget_destroy(bdi->dialog);
g_free(bdi);
@@ -103,19 +95,19 @@ static void search_cb(GtkWidget *widget, gpointer data)
}
}
static void browser_dialog(char *url)
static void viewer_dialog(char *path)
{ GtkWidget *dialog, *vbox, *hbox, *label, *entry, *button;
browser_dialog_info *bdi = g_malloc0(sizeof(browser_dialog_info));
viewer_dialog_info *bdi = g_malloc0(sizeof(viewer_dialog_info));
/* Create the dialog */
dialog = gtk_dialog_new_with_buttons(_utf("windowtitle|Browser required"),
dialog = gtk_dialog_new_with_buttons(_utf("windowtitle|PDF viewer required"),
Closure->window, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
bdi->dialog = dialog;
if(url)
{ bdi->url = g_strdup(url);
if(path)
{ bdi->path = g_strdup(path);
}
vbox = gtk_vbox_new(FALSE, 0);
@@ -125,10 +117,10 @@ static void browser_dialog(char *url)
/* Insert the contents */
label = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(label), _utf("<b>Could not find a suitable browser.</b>\n\n"
"Which browser would you like to use\n"
gtk_label_set_markup(GTK_LABEL(label), _utf("<b>Could not find a suitable PDF viewer.</b>\n\n"
"Which PDF viewer would you like to use\n"
"for reading the online documentation?\n\n"
"Please enter its name (e.g. mozilla) or\n"
"Please enter its name (e.g. xpdf) or\n"
"use the \"Search\" button for a file dialog.\n")),
gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 10);
@@ -148,59 +140,53 @@ static void browser_dialog(char *url)
gtk_widget_show_all(dialog);
}
#endif /* SYS_ unix-like */
/***
*** Show the manual in an external browser
*** Show the manual in an external viewer
***/
/*
* Check the child processes exit status
* to find whether the browser could be invoked.
* to find whether the viewer could be invoked.
*/
typedef struct
{ pid_t pid;
char *url;
char *path;
GtkWidget *msg;
int seconds;
} browser_info;
} viewer_info;
static void msg_destroy_cb(GtkWidget *widget, gpointer data)
{ browser_info *bi = (browser_info*)data;
{ viewer_info *bi = (viewer_info*)data;
bi->msg = NULL;
}
#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
/*
* The following list of browsers and html wrappers
* The following list of viewers
* will be tried one at a time until one entry succeeds by:
* - returning zero
* - not returning within 60 seconds
*/
static int browser_index;
static void try_browser(browser_info*);
static int viewer_index;
static void try_viewer(viewer_info*);
static char *browsers[] =
{ "user-selection",
"xdg-open",
"gnome-open",
"htmlview",
"firefox",
"mozilla",
"konqueror",
"epiphany",
"opera",
"/Applications/Safari.app/Contents/MacOS/Safari", /* better way to do this? */
static char *viewers[] =
{ "evince",
"xpdf",
"okular",
"gv",
"mupdf",
"pdfcube",
"zathura",
NULL
};
static gboolean browser_timeout_func(gpointer data)
{ browser_info *bi = (browser_info*)data;
static gboolean viewer_timeout_func(gpointer data)
{ viewer_info *bi = (viewer_info*)data;
int status;
waitpid(bi->pid, &status, WNOHANG);
@@ -211,29 +197,29 @@ static gboolean browser_timeout_func(gpointer data)
if(WIFEXITED(status))
{
switch(WEXITSTATUS(status))
{ case 110: /* browser did not execute */
browser_index++;
if(!browsers[browser_index]) /* all browsers from the list failed */
{ browser_dialog(bi->url);
{ case 110: /* viewer did not execute */
viewer_index++;
if(!viewers[viewer_index]) /* all viewers from the list failed */
{ viewer_dialog(bi->path);
if(bi->msg)
gtk_widget_destroy(bi->msg);
if(bi->url)
g_free(bi->url);
if(bi->path)
g_free(bi->path);
g_free(bi);
}
else /* try next browser from list */
else /* try next viewer from list */
{ bi->seconds = 0;
try_browser(bi);
try_viewer(bi);
}
return FALSE;
case 0: /* browser assumed to be successful */
case 0: /* viewer assumed to be successful */
default:
if(bi->msg)
gtk_widget_destroy(bi->msg);
if(bi->url)
g_free(bi->url);
if(bi->path)
g_free(bi->path);
g_free(bi);
return FALSE;
}
@@ -247,34 +233,12 @@ static gboolean browser_timeout_func(gpointer data)
return bi->seconds > 60 ? FALSE : TRUE;
}
#endif /* SYS_ unix-like */
#ifdef SYS_MINGW
static gboolean browser_timeout_func(gpointer data)
{ browser_info *bi = (browser_info*)data;
bi->seconds++;
if(bi->seconds >= 10)
{ if(bi->msg)
{ gtk_widget_destroy(bi->msg);
bi->msg = NULL;
}
if(bi->url) g_free(bi->url);
g_free(bi);
return FALSE;
}
return TRUE;
}
#endif /* SYS_MINGW */
/*
* Invoke the browser
* Invoke the viewer
*/
#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
static void try_browser(browser_info *bi)
static void try_viewer(viewer_info *bi)
{ pid_t pid;
bi->pid = pid = fork();
@@ -284,119 +248,68 @@ static void try_browser(browser_info *bi)
return;
}
/* make the parent remember and wait() for the browser */
/* make the parent remember and wait() for the viewer */
if(pid > 0)
{ g_timeout_add(1000, browser_timeout_func, (gpointer)bi);
{ g_timeout_add(1000, viewer_timeout_func, (gpointer)bi);
if(browser_index)
{ g_free(Closure->browser);
Closure->browser = g_strdup(browsers[browser_index]);
if(viewer_index)
{ g_free(Closure->viewer);
Closure->viewer = g_strdup(viewers[viewer_index]);
}
}
/* try calling the browser */
/* try calling the viewer */
if(pid == 0)
{ char *argv[10];
int argc = 0;
argv[argc++] = browser_index ? browsers[browser_index] : Closure->browser;
argv[argc++] = bi->url;
argv[argc++] = viewer_index ? viewers[viewer_index] : Closure->viewer;
argv[argc++] = bi->path;
argv[argc++] = NULL;
execvp(argv[0], argv);
_exit(110); /* couldn't execute */
}
}
#endif /* SYS_ unix-like */
void ShowPDF(char *target)
{ viewer_info *bi = g_malloc0(sizeof(viewer_info));
guint64 ignore;
void ShowHTML(char *target)
{ browser_info *bi = g_malloc0(sizeof(browser_info));
gint64 ignore;
const char *lang;
char *path = NULL;
int http_url;
/* If no target is given, select between translations of the manual. */
if(!target) target = g_strdup("index.html");
http_url = strlen(target) > 4 && !strncmp(target, "http", 4);
if(!http_url && !strchr(target, '/')) /* create full path */
{
if(!Closure->docDir)
{
CreateMessage(_("Documentation not installed."), GTK_MESSAGE_ERROR);
g_free(bi);
return;
}
lang = g_getenv("LANG");
if(lang)
{ if(!strncmp(lang, "ru", 2))
#ifdef SYS_MINGW
path = g_strdup_printf("%s\\ru\\%s",Closure->docDir,target);
#else
path = g_strdup_printf("%s/ru/%s",Closure->docDir,target);
#endif
else if(!strncmp(lang, "de", 2))
#ifdef SYS_MINGW
path = g_strdup_printf("%s\\de\\%s",Closure->docDir,target);
#else
path = g_strdup_printf("%s/de/%s",Closure->docDir,target);
#endif
}
if(!path)
{
#ifdef SYS_MINGW
path = g_strdup_printf("%s\\en\\%s",Closure->docDir,target);
#else
path = g_strdup_printf("%s/en/%s",Closure->docDir,target);
#endif
}
#ifdef SYS_MINGW
if(!LargeStat(path, &ignore))
{
g_free(path); /* the local dir is Windows specific */
path = g_strdup_printf("%s\\local\\%s",Closure->docDir,target);
}
#endif
g_free(target);
bi->url = path;
}
else bi->url = target;
if(!http_url && !LargeStat(bi->url, &ignore))
if(!Closure->docDir)
{
CreateMessage(_("Documentation file\n%s\nnot found.\n"), GTK_MESSAGE_ERROR, bi->url);
CreateMessage(_("Documentation not installed."), GTK_MESSAGE_ERROR);
g_free(bi);
return;
}
/* If no target is given, show the manual. */
if(!target)
{ bi->path = g_strdup_printf("%s/manual.pdf",Closure->docDir);
}
else
if(*target != '/') bi->path = g_strdup_printf("%s/%s",Closure->docDir, target);
else bi->path = g_strdup(target);
if(!LargeStat(bi->path, &ignore))
{
CreateMessage(_("Documentation file\n%s\nnot found.\n"), GTK_MESSAGE_ERROR, bi->path);
g_free(bi->path);
g_free(bi);
g_free(bi->url);
return;
}
/* Lock the help button and show a message for 10 seconds. */
TimedInsensitive(Closure->helpButton, 10000);
bi->msg = CreateMessage(_("Please hang on until the browser comes up!"), GTK_MESSAGE_INFO);
bi->msg = CreateMessage(_("Please hang on until the viewer comes up!"), GTK_MESSAGE_INFO);
g_signal_connect(G_OBJECT(bi->msg), "destroy", G_CALLBACK(msg_destroy_cb), bi);
#ifdef SYS_MINGW
/* Okay, Billy wins big time here ;-) */
/* Try the first viwer */
ShellExecute(NULL, "open", bi->url, NULL, NULL, SW_SHOWNORMAL);
g_timeout_add(1000, browser_timeout_func, (gpointer)bi);
#endif
#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
/* Try the first browser */
browser_index = 0;
try_browser(bi);
#endif
viewer_index = 0;
try_viewer(bi);
}