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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
|
/* dvdisaster: Additional error correction for optical media.
* Copyright (C) 2004-2017 Carsten Gnoerlich.
* Copyright (C) 2019-2021 The dvdisaster development team.
*
* Email: support@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 3 of the License, or
* (at your option) any later version.
*
* 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 dvdisaster. If not, see <http://www.gnu.org/licenses/>.
*/
/*** src type: only GUI code ***/
#ifdef WITH_GUI_YES
#include "dvdisaster.h"
#include "build.h"
/***
*** Online help system for the preferences
***/
/*
* Create a help window
*/
/* Close button response */
static void close_cb(GtkWidget *widget, gpointer data)
{ LabelWithOnlineHelp *lwoh = (LabelWithOnlineHelp*)data;
gtk_widget_hide(lwoh->helpWindow);
}
/* Do not destroy the window when closed via the window manager */
static gboolean delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{ LabelWithOnlineHelp *lwoh = (LabelWithOnlineHelp*)data;
gtk_widget_hide(lwoh->helpWindow);
return TRUE;
}
/*
* Get a new integer variable from the lastSizes array
*/
static int* get_new_int(LabelWithOnlineHelp* lwoh)
{ int *var = g_malloc0(sizeof(int));
if(!lwoh->lastSizes)
lwoh->lastSizes = g_ptr_array_new();
g_ptr_array_add(lwoh->lastSizes, var);
return var;
}
/*
* Callback for the help link
*/
static gint help_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{ GtkWidget *lab = GTK_BIN(widget)->child;
LabelWithOnlineHelp *lwoh = (LabelWithOnlineHelp*)data;
switch(event->type)
{ case GDK_BUTTON_PRESS:
if(!lwoh->inside) return FALSE; /* Defect in certain Gtk versions? */
gtk_widget_show_all(GTK_WIDGET(lwoh->helpWindow));
break;
case GDK_ENTER_NOTIFY:
gtk_label_set_markup(GTK_LABEL(lab), lwoh->highlitText);
lwoh->inside = TRUE;
break;
case GDK_LEAVE_NOTIFY:
gtk_label_set_markup(GTK_LABEL(lab), lwoh->normalText);
lwoh->inside = FALSE;
break;
default: break;
}
return FALSE;
}
/*
* Create a frame labeled with a link to the help system
*/
LabelWithOnlineHelp* GuiCreateLabelWithOnlineHelp(char *title, char *ascii_text)
{ GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *vbox, *hbox, *button;
GtkWidget *ebox = gtk_event_box_new();
LabelWithOnlineHelp *lwoh;
/*** Initialize online help context */
lwoh = g_malloc0(sizeof(LabelWithOnlineHelp));
lwoh->normalLabel = gtk_label_new(NULL);
lwoh->linkLabel = gtk_label_new(NULL);
lwoh->linkBox = ebox;
lwoh->windowTitle = g_locale_to_utf8(title, -1, NULL, NULL, NULL);
GuiSetOnlineHelpLinkText(lwoh, ascii_text);
gtk_label_set_markup(GTK_LABEL(lwoh->normalLabel), lwoh->normalText);
/*** Create the help window */
lwoh->helpWindow = window;
gtk_window_set_title(GTK_WINDOW(window), lwoh->windowTitle);
gtk_window_set_icon(GTK_WINDOW(window), Closure->windowIcon);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
lwoh->outerPadding = 12;
gtk_container_set_border_width(GTK_CONTAINER(window), lwoh->outerPadding);
lwoh->outerPadding *= 2;
/* Connect window with the close button from the window manager */
g_signal_connect(window, "delete_event", G_CALLBACK(delete_cb), lwoh);
/* Create the main layout of the window */
lwoh->vbox = vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(close_cb), lwoh);
gtk_box_pack_end(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 6);
/*** Put link label into an event box */
gtk_widget_set_events(ebox, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(ebox), "button_press_event", G_CALLBACK(help_cb), (gpointer)lwoh);
g_signal_connect(G_OBJECT(ebox), "enter_notify_event", G_CALLBACK(help_cb), (gpointer)lwoh);
g_signal_connect(G_OBJECT(ebox), "leave_notify_event", G_CALLBACK(help_cb), (gpointer)lwoh);
gtk_label_set_markup(GTK_LABEL(lwoh->linkLabel), lwoh->normalText);
gtk_container_add(GTK_CONTAINER(ebox), lwoh->linkLabel);
return lwoh;
}
LabelWithOnlineHelp* GuiCloneLabelWithOnlineHelp(LabelWithOnlineHelp *orig, char *ascii_text)
{ LabelWithOnlineHelp *lwoh;
GtkWidget *ebox = gtk_event_box_new();
/*** Initialize online help context from given one */
lwoh = g_malloc0(sizeof(LabelWithOnlineHelp));
lwoh->helpWindow = orig->helpWindow;
/*** Only replace the labels */
lwoh->normalLabel = gtk_label_new(NULL);
lwoh->linkLabel = gtk_label_new(NULL);
lwoh->linkBox = ebox;
lwoh->windowTitle = g_strdup("ignore");
GuiSetOnlineHelpLinkText(lwoh, ascii_text);
/*** Put link label into an event box */
gtk_widget_set_events(ebox, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(ebox), "button_press_event", G_CALLBACK(help_cb), (gpointer)lwoh);
g_signal_connect(G_OBJECT(ebox), "enter_notify_event", G_CALLBACK(help_cb), (gpointer)lwoh);
g_signal_connect(G_OBJECT(ebox), "leave_notify_event", G_CALLBACK(help_cb), (gpointer)lwoh);
gtk_label_set_markup(GTK_LABEL(lwoh->normalLabel), lwoh->normalText);
gtk_label_set_markup(GTK_LABEL(lwoh->linkLabel), lwoh->normalText);
gtk_container_add(GTK_CONTAINER(ebox), lwoh->linkLabel);
return lwoh;
}
void GuiSetOnlineHelpLinkText(LabelWithOnlineHelp *lwoh, char *ascii_text)
{ char text[strlen(ascii_text)+80];
if(lwoh->normalText) g_free(lwoh->normalText);
if(lwoh->highlitText) g_free(lwoh->highlitText);
lwoh->normalText = g_locale_to_utf8(ascii_text, -1, NULL, NULL, NULL);
g_sprintf(text, "<span underline=\"single\" color=\"blue\">%s</span>", ascii_text);
lwoh->highlitText = g_locale_to_utf8(text, -1, NULL, NULL, NULL);
}
void GuiFreeLabelWithOnlineHelp(LabelWithOnlineHelp *lwoh)
{
if(lwoh->lastSizes)
{ int i;
for(i=0; i<lwoh->lastSizes->len; i++)
{ int *var = g_ptr_array_index(lwoh->lastSizes, i);
g_free(var);
}
g_ptr_array_free(lwoh->lastSizes, FALSE);
}
g_free(lwoh->windowTitle);
g_free(lwoh->normalText);
g_free(lwoh->highlitText);
g_free(lwoh);
}
/*
* Add a paragraph of text to the help window
*/
static gboolean wrapper_fix_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{ int *last_width = (int*)data;
int label_width = widget->allocation.width;
if(*last_width == label_width) /* short circuit expose events */
return FALSE; /* without size changes */
*last_width = label_width;
/* This is a hack. We feed the label its own allocation to make it redraw.
Note that we subtract 4 or else the window would never shrink again. */
if(label_width<0 || label_width>200)
gtk_widget_set_size_request(widget, label_width-4, -1);
return FALSE;
}
void GuiAddHelpParagraph(LabelWithOnlineHelp *lwoh, char *format, ...)
{ GtkWidget *label = gtk_label_new(NULL);
va_list argp;
char *text,*utf;
va_start(argp, format);
text = g_strdup_vprintf(format, argp);
va_end(argp);
utf = g_locale_to_utf8(text, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(label), utf);
g_free(utf);
g_free(text);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(lwoh->vbox), label, FALSE, FALSE, 0);
/* Work around some bugs in the gtk line wrapper code.
By default lines are wrapped at the length of
"This long string gives a good enough length for any line to have."
which is, well, stupid. */
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
g_signal_connect(label, "expose_event", G_CALLBACK(wrapper_fix_cb), get_new_int(lwoh));
}
/*
* Add an item list to the help window.
* The list may be preceeded by an optional paragraph of text.
*/
void GuiAddHelpListItem(LabelWithOnlineHelp *lwoh, char *format, ...)
{ GtkWidget *label = gtk_label_new(NULL);
GtkWidget *bullet = gtk_label_new(" - ");
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
va_list argp;
char *text,*utf;
gtk_box_pack_start(GTK_BOX(lwoh->vbox), hbox, FALSE, FALSE, 0);
gtk_misc_set_alignment(GTK_MISC(bullet), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(hbox), bullet, FALSE, FALSE, 0);
va_start(argp, format);
text = g_strdup_vprintf(format, argp);
va_end(argp);
utf = g_locale_to_utf8(text, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(label), utf);
g_free(utf);
g_free(text);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
/* Work around some bugs in the gtk line wrapper code.
By default lines are wrapped at the length of
"This long string gives a good enough length for any line to have."
which is, well, stupid. */
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
g_signal_connect(label, "expose_event", G_CALLBACK(wrapper_fix_cb), get_new_int(lwoh));
}
/*
* Add a (fully functional!) widget set to the help window
*/
void GuiAddHelpWidget(LabelWithOnlineHelp *lwoh, GtkWidget *widget)
{
gtk_box_pack_start(GTK_BOX(lwoh->vbox), widget, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(lwoh->vbox), gtk_hseparator_new(), FALSE, FALSE, 10);
}
/***
*** The log viewer
***/
static void log_destroy_cb(GtkWidget *widget, gpointer data)
{
/* Avoid race condition with next function */
g_mutex_lock(Closure->logLock);
Closure->logWidget = NULL;
Closure->logScroll = NULL;
Closure->logBuffer = NULL;
g_mutex_unlock(Closure->logLock);
}
static gboolean log_jump_func(gpointer data)
{ GtkAdjustment *a;
GtkTextIter end;
/* Locking is needed as user might destroy the window
while we are updating it */
g_mutex_lock(Closure->logLock);
if(!Closure->logWidget)
{ g_mutex_unlock(Closure->logLock);
return FALSE;
}
gtk_text_buffer_get_end_iter(Closure->logBuffer, &end);
gtk_text_buffer_place_cursor(Closure->logBuffer, &end);
a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Closure->logScroll));
gtk_adjustment_set_value(a, a->upper - a->page_size);
gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(Closure->logScroll), a);
g_mutex_unlock(Closure->logLock);
return FALSE;
}
static gboolean log_idle_func(gpointer data)
{
g_mutex_lock(Closure->logLock);
if(Closure->logBuffer)
gtk_text_buffer_set_text(Closure->logBuffer, Closure->logString->str, Closure->logString->len);
g_mutex_unlock(Closure->logLock);
g_idle_add(log_jump_func, NULL);
return FALSE;
}
void GuiUpdateLog()
{ static int unique_addr;
if(Closure->logWidget)
{ g_idle_remove_by_data(&unique_addr);
g_idle_add(log_idle_func, &unique_addr);
}
}
void GuiShowLog()
{ GtkWidget *w;
if(Closure->logWidget)
{ gtk_widget_show(Closure->logWidget);
return;
}
w = GuiShowTextfile(_("windowtitle|Log data"),
_("<big>Log data</big>\n"
"<i>Protocol of the current or previous action</i>"),
"*LOG*", &Closure->logScroll, &Closure->logBuffer);
g_signal_connect(G_OBJECT(w), "destroy", G_CALLBACK(log_destroy_cb), NULL);
Closure->logWidget = w;
}
/***
*** Specific help dialogs
***/
void GuiShowGPL()
{
GuiShowTextfile(_("windowtitle|GNU General Public License"),
_("<big>GNU General Public License</big>\n"
"<i>The license terms of dvdisaster.</i>"),
"/usr/share/common-licenses/GPL-3", NULL, NULL);
}
/*
* Dialog for displaying text files
*/
char *find_file(char *file, size_t *size, char *lang)
{ char *path;
char lang_suffix[3];
guint64 stat_size;
lang_suffix[0] = lang_suffix[2] = 0;
if(lang)
{
lang_suffix[0] = lang[0];
lang_suffix[1] = lang[1];
}
/* Test for absolute path first. */
if(*file == '/')
{
if(lang)
path = g_strdup_printf("%s.%s", file, lang_suffix);
else
path = g_strdup(file);
if(LargeStat(path, &stat_size))
{
*size = stat_size;
return path;
}
g_free(path);
return NULL;
}
/* Try file in bin dir */
if(Closure->binDir)
{ if(lang)
path = g_strdup_printf("%s/%s.%s",Closure->binDir, file, lang_suffix);
else path = g_strdup_printf("%s/%s",Closure->binDir, file);
if(LargeStat(path, &stat_size))
{ *size = stat_size;
return path;
}
g_free(path);
}
/* Try file in doc dir */
if(Closure->docDir)
{ if(lang)
path = g_strdup_printf("%s/%s.%s",Closure->docDir, file, lang_suffix);
else path = g_strdup_printf("%s/%s",Closure->docDir, file);
if(LargeStat(path, &stat_size))
{ *size = stat_size;
return path;
}
g_free(path);
}
return NULL;
}
GtkWidget* GuiShowTextfile(char *title, char *explanation, char *file,
GtkScrolledWindow **scroll_out, GtkTextBuffer **buffer_out)
{ GtkWidget *dialog, *scroll_win, *vbox, *lab, *sep, *view;
GtkTextBuffer *buffer;
GtkTextIter start;
char *path;
char *utf,*buf;
size_t size = 0;
/*** Read the text file */
if(*file != '*')
{
if( !(path = find_file(file, &size, NULL))
&& !(path = find_file(file, &size, (char*)g_getenv("LANG")))
&& !(path = find_file(file, &size, "en"))
)
{ char *trans = _utf("File\n%s\nnot present");
buf = g_strdup_printf(trans, file);
size = strlen(buf);
}
else
{ FILE *fptr = portable_fopen(path, "rb");
size_t bytes_read;
if(!fptr)
{ char *trans = _utf("File\n%s\nnot accessible");
buf = g_strdup_printf(trans, file);
size = strlen(buf);
}
else
{ buf = g_malloc(size);
bytes_read = fread(buf, 1, size, fptr);
fclose(fptr);
g_free(path);
if(bytes_read < size)
{ char *trans = _utf("\n<- Error: Text file truncated here");
size = bytes_read + strlen(trans);
buf = realloc(buf, size+1);
strcpy(&buf[bytes_read], trans);
}
}
}
}
else
{ g_mutex_lock(Closure->logLock);
buf = Closure->logString->str;
size = Closure->logString->len;
g_mutex_unlock(Closure->logLock);
}
/*** Create the dialog */
utf = g_locale_to_utf8(title, -1, NULL, NULL, NULL);
dialog = gtk_dialog_new_with_buttons(utf, Closure->window, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
g_free(utf);
gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 600);
g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
lab = gtk_label_new(NULL);
utf = g_locale_to_utf8(explanation, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf);
g_free(utf);
gtk_misc_set_alignment(GTK_MISC(lab), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(vbox), lab, FALSE, FALSE, 0);
sep = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
scroll_win = gtk_scrolled_window_new(NULL, NULL);
gtk_box_pack_start(GTK_BOX(vbox), scroll_win, TRUE, TRUE, 5);
if(scroll_out) *scroll_out = GTK_SCROLLED_WINDOW(scroll_win);
view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
if(buffer_out) *buffer_out = buffer;
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);
gtk_text_buffer_set_text(buffer, buf, size);
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_place_cursor(buffer, &start);
gtk_container_add(GTK_CONTAINER(scroll_win), view);
/* Show it */
gtk_widget_show_all(dialog);
if(*file != '*')
g_free(buf);
return dialog;
}
/*
* About dialog
*/
static gint about_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{ GtkWidget *lab = GTK_BIN(widget)->child;
char *label = (char*)data;
char text[strlen(label)+80];
char *utf;
static int inside;
switch(event->type)
{ case GDK_BUTTON_PRESS:
if(!inside) return FALSE; /* Defect in certain Gtk versions? */
if(!strcmp(label,"GPL")) GuiShowGPL();
else GuiShowURL(g_strdup(label));
break;
case GDK_ENTER_NOTIFY:
g_sprintf(text, "<span underline=\"single\" color=\"blue\">%s</span>", label);
utf = g_locale_to_utf8(text, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf);
g_free(utf);
inside = TRUE;
break;
case GDK_LEAVE_NOTIFY:
g_sprintf(text, "<span color=\"blue\">%s</span>", label);
utf = g_locale_to_utf8(text, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf);
g_free(utf);
inside = FALSE;
break;
default: break;
}
return FALSE;
}
void GuiAboutText(GtkWidget *parent, char *format, ...)
{ GtkWidget *lab;
char *tmp, *utf_text;
va_list argp;
va_start(argp, format);
lab = gtk_label_new(NULL);
tmp = g_strdup_vprintf(format, argp);
utf_text = g_locale_to_utf8(tmp, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf_text);
gtk_misc_set_alignment(GTK_MISC(lab), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(parent), lab, FALSE, FALSE, 0);
g_free(tmp);
g_free(utf_text);
va_end(argp);
}
void GuiAboutLink(GtkWidget *parent, char *label, char *action)
{ GtkWidget *ebox,*lab;
char text[strlen(label)+80];
char *label_copy = strdup(label);
char *utf;
ebox = gtk_event_box_new();
gtk_widget_set_events(ebox, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(ebox), "button_press_event", G_CALLBACK(about_cb), (gpointer)action);
g_signal_connect(G_OBJECT(ebox), "enter_notify_event", G_CALLBACK(about_cb), (gpointer)label_copy);
g_signal_connect(G_OBJECT(ebox), "leave_notify_event", G_CALLBACK(about_cb), (gpointer)label_copy);
gtk_box_pack_start(GTK_BOX(parent), ebox, FALSE, FALSE, 0);
lab = gtk_label_new(NULL);
g_sprintf(text, "<span color=\"blue\">%s</span>", label);
utf = g_locale_to_utf8(text, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf);
gtk_container_add(GTK_CONTAINER(ebox), lab);
g_free(utf);
}
void GuiAboutTextWithLink(GtkWidget *parent, char *text, char *action)
{ char *copy,*head,*end_of_line;
char *link_start,*link_end;
char *utf;
head = copy = g_strdup(text);
while(*head)
{ end_of_line = strchr(head, '\n');
if(end_of_line && *end_of_line == '\n')
*end_of_line = 0;
link_start = strchr(head, '[');
link_end = strchr(head, ']');
if(link_start && link_end)
{ GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(parent), hbox, FALSE, FALSE, 0);
*link_start++ = *link_end++ = 0;
if(*head)
{ GtkWidget *lab = gtk_label_new(NULL);
utf = g_locale_to_utf8(head, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf);
gtk_box_pack_start(GTK_BOX(hbox), lab, FALSE, FALSE, 0);
g_free(utf);
}
GuiAboutLink(hbox, link_start, action);
if(*link_end)
{ GtkWidget *lab = gtk_label_new(NULL);
utf = g_locale_to_utf8(link_end, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(lab), utf);
gtk_box_pack_start(GTK_BOX(hbox), lab, FALSE, FALSE, 0);
g_free(utf);
}
}
else GuiAboutText(parent, head);
if(end_of_line) head = end_of_line+1;
else break;
}
g_free(copy);
}
void GuiAboutDialog()
{ GtkWidget *about, *vbox, *sep;
char *text;
/* Create the dialog */
about = gtk_dialog_new_with_buttons(_utf("windowtitle|About dvdisaster"),
Closure->window, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
g_signal_connect_swapped(about, "response", G_CALLBACK(gtk_widget_destroy), about);
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(about)->vbox), vbox, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
/* Insert the labels */
text = g_strdup_printf("<span weight=\"bold\" size=\"xx-large\">dvdisaster</span><i> "
"Version %s</i>",
Closure->cookedVersion);
GuiAboutText(vbox, "%s", text);
g_free(text);
GuiAboutText(vbox, _("Copyright 2004-2017 Carsten Gnoerlich.\nCopyright 2019-2021 The dvdisaster development team."));
sep = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 10);
GuiAboutText(vbox, _("dvdisaster provides a margin of safety against data loss\n"
"on optical media caused by aging or scratches.\n"
"It creates error correction data which is used to recover\n"
"unreadable sectors if the disc becomes damaged later on.\n"));
GuiAboutTextWithLink(vbox, _("This software comes with <b>absolutely no warranty</b>.\n"
"This is free software and you are welcome to redistribute it\n"
"under the conditions of the [GNU General Public License].\n"),
"GPL");
GuiAboutText(vbox, _("\ne-mail: support@dvdisaster.org"));
text = g_strdup_printf("WWW: [%s]", HOMEPAGE);
GuiAboutTextWithLink(vbox, text, HOMEPAGE);
g_free(text);
#ifdef SYS_NETBSD
GuiAboutText(vbox, _("\nNetBSD port: Sergey Svishchev <svs@ropnet.ru>"));
#endif
/* Show it */
gtk_widget_show_all(about);
}
#endif /* WITH_GUI_YES */
|