home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / user_install.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  41.1 KB  |  1,332 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  * Copyright (C) 2000 Michael Natterer and Sven Neumann
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  */
  19.  
  20. #include "config.h"
  21.  
  22. #include <glib.h>
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #ifdef HAVE_UNISTD_H
  29. #include <unistd.h>
  30. #endif
  31.  
  32. #include "apptypes.h"
  33.  
  34. #include "appenv.h"
  35. #include "gdisplay_ops.h"
  36. #include "gimprc.h"
  37. #include "gimpui.h"
  38. #include "resolution_calibrate.h"
  39. #include "unitrc.h"
  40. #include "user_install.h"
  41. #include "libgimp/gimpenv.h"
  42. #include "libgimp/gimplimits.h"
  43. #include "libgimp/gimpmath.h"
  44.  
  45. #include "libgimp/gimpintl.h"
  46.  
  47. #include "pixmaps/eek.xpm"
  48. #include "pixmaps/folder.xpm"
  49. #include "pixmaps/new.xpm"
  50. #include "pixmaps/wilber.xpm"
  51.  
  52. #ifndef G_OS_WIN32
  53. #  ifndef __EMX__
  54. #  define USER_INSTALL "user_install"
  55. #  else
  56. #  include <process.h>
  57. #  define USER_INSTALL "user_install.cmd"
  58. #  endif
  59. #else
  60. #  define STRICT
  61. #  include <windows.h>
  62. #  define USER_INSTALL "user_install.bat"
  63. #endif
  64.  
  65. #define NUM_PAGES    6
  66. #define EEK_PAGE     (NUM_PAGES - 1)
  67. #define WILBER_WIDTH 62
  68.  
  69. #define PAGE_STYLE(widget)  gtk_widget_set_style (widget, page_style)
  70. #define TITLE_STYLE(widget) gtk_widget_set_style (widget, title_style)
  71.  
  72. static void     user_install_dialog_create     (UserInstallCallback);
  73. static void     user_install_continue_callback (GtkWidget *widget, gpointer data);
  74. static void     user_install_cancel_callback   (GtkWidget *widget, gpointer data);
  75.  
  76. static gboolean user_install_run               (void);
  77. static void     user_install_tuning            (void);
  78. static void     user_install_tuning_done       (void);
  79. static void     user_install_resolution        (void);
  80. static void     user_install_resolution_done   (void);
  81.  
  82.  
  83. void
  84. user_install_verify (UserInstallCallback user_install_callback)
  85. {
  86.   gboolean properly_installed = TRUE;
  87.   gchar *filename;
  88.   struct stat stat_buf;
  89.  
  90.   /* gimp_directory now always returns something */
  91.   filename = gimp_directory ();
  92.  
  93.   if (stat (filename, &stat_buf) != 0)
  94.     properly_installed = FALSE;
  95.  
  96.   /*  If there is already a proper installation, invoke the callback  */
  97.   if (properly_installed)
  98.     {
  99.       (* user_install_callback) ();
  100.     }
  101.   /*  Otherwise, prepare for installation  */
  102.   else if (no_interface)
  103.     {
  104.       g_print (_("The GIMP is not properly installed for the current user\n"));
  105.       g_print (_("User installation was skipped because the '--nointerface' flag was encountered\n"));
  106.       g_print (_("To perform user installation, run the GIMP without the '--nointerface' flag\n"));
  107.  
  108.       (* user_install_callback) ();
  109.     }
  110.   else
  111.     {
  112.       user_install_dialog_create (user_install_callback);
  113.     }
  114. }
  115.  
  116. /*  private stuff  */
  117.  
  118. static GtkWidget *user_install_dialog = NULL;
  119.  
  120. static GtkWidget *notebook = NULL;
  121.  
  122. static GtkWidget *title_pixmap = NULL;
  123.  
  124. static GtkWidget *title_label  = NULL;
  125. static GtkWidget *footer_label = NULL;
  126.  
  127. static GtkWidget *log_page        = NULL;
  128. static GtkWidget *tuning_page     = NULL;
  129. static GtkWidget *resolution_page = NULL;
  130.  
  131. static GtkWidget *continue_button = NULL;
  132. static GtkWidget *cancel_button   = NULL;
  133.  
  134. static GtkStyle *title_style = NULL;
  135.  
  136. static GtkStyle    *page_style = NULL;
  137. static GdkColormap *colormap   = NULL;
  138.  
  139. static GdkGC *white_gc = NULL;
  140.  
  141. static GdkColor black_color;
  142. static GdkColor white_color;
  143. static GdkColor title_color;
  144.  
  145. static struct
  146. {
  147.   gboolean  directory;
  148.   gchar    *text;
  149.   gchar    *description;
  150. }
  151. tree_items[] =
  152. {
  153.   {
  154.     FALSE, "gimprc",
  155.     N_("The gimprc is used to store personal preferences\n"
  156.        "that affect GIMP's default behavior.\n"
  157.        "Paths to search for brushes, palettes, gradients,\n"
  158.        "patterns, plug-ins and modules can also configured\n"
  159.        "here.")
  160.   },
  161.   {
  162.     FALSE, "gtkrc",
  163.     N_("GIMP uses an additional gtkrc file so you can\n"
  164.        "configure it to look differently than other GTK apps.")
  165.   },
  166.   {
  167.     FALSE, "pluginrc",
  168.     N_("Plug-ins and extensions are external programs run\n"
  169.        "by the GIMP which provide additional functionality.\n"
  170.        "These programs are searched for at run-time and\n"
  171.        "information about their functionality and mod-times\n"
  172.        "is cached in this file.  This file is intended to\n"
  173.        "be GIMP-readable only, and should not be edited.")
  174.   },
  175.   {
  176.     FALSE, "menurc",
  177.     N_("Key shortcuts can be dynamically redefined in The GIMP.\n"
  178.        "The menurc is a dump of your configuration so it can.\n"
  179.        "be remembered for the next session.  You may edit this\n"
  180.        "file if you wish, but it is much easier to define the\n"
  181.        "keys from within The GIMP.  Deleting this file will\n"
  182.        "restore the default shortcuts.")
  183.   },
  184.   {
  185.     FALSE, "sessionrc",
  186.     N_("The sessionrc is used to store what dialog windows were\n"
  187.        "open the last time you quit The GIMP.  You can configure\n"
  188.        "The GIMP to reopen these dialogs at the saved position.")
  189.   },
  190.   {
  191.     FALSE, "unitrc",
  192.     N_("The unitrc is used to store your user units database.\n"
  193.        "You can define additional units and use them just\n"
  194.        "like you use the built-in units inches, millimeters,\n"
  195.        "points and picas.  This file is overwritten each time\n"
  196.        "you quit the GIMP.")
  197.   },
  198.   {
  199.     TRUE, "brushes",
  200.     N_("This is a subdirectory which can be used to store\n"
  201.        "user defined brushes.  The default gimprc file\n"
  202.        "checks this subdirectory in addition to the system-\n"
  203.        "wide GIMP brushes installation when searching for\n"
  204.        "brushes.")
  205.   },
  206.   {
  207.     TRUE, "generated_brushes",
  208.     N_("This is a subdirectory which is used to store brushes\n"
  209.        "that are created with the brush editor.  The default\n"
  210.        "gimprc file checks this subdirectory when searching\n"
  211.        "for generated brushes.")
  212.   },
  213.   {
  214.     TRUE, "gradients",
  215.     N_("This is a subdirectory which can be used to store\n"
  216.        "user defined gradients.  The default gimprc file\n"
  217.        "checks this subdirectory in addition to the system-\n"
  218.        "wide GIMP gradients installation when searching\n"
  219.        "for gradients.")
  220.   },
  221.   {
  222.     TRUE, "palettes",
  223.     N_("This is a subdirectory which can be used to store\n"
  224.        "user defined palettes.  The default gimprc file\n"
  225.        "checks only this subdirectory (not the system-wide\n"
  226.        "installation) when searching for palettes.  During\n"
  227.        "installation, the system palettes will be copied\n"
  228.        "here.  This is done to allow modifications made to\n"
  229.        "palettes during GIMP execution to persist across\n"
  230.        "sessions.")
  231.   },
  232.   {
  233.     TRUE, "patterns",
  234.     N_("This is a subdirectory which can be used to store\n"
  235.        "user defined patterns.  The default gimprc file\n"
  236.        "checks this subdirectory in addition to the system-\n"
  237.        "wide GIMP patterns installation when searching for\n"
  238.        "patterns.")
  239.   },
  240.   {
  241.     TRUE, "plug-ins",
  242.     N_("This is a subdirectory which can be used to store\n"
  243.        "user created, temporary, or otherwise non-system-\n"
  244.        "supported plug-ins.  The default gimprc file checks\n"
  245.        "this subdirectory in addition to the systemwide\n"
  246.        "GIMP plug-in directories when searching for plug-ins.")
  247.   },
  248.   {
  249.     TRUE, "modules",
  250.     N_("This subdirectory can be used to store user created,\n"
  251.        "temporary, or otherwise non-system-supported DLL\n"
  252.        "modules.  The default gimprc file checks this subdirectory\n"
  253.        "in addition to the system-wide GIMP module directory\n"
  254.        "when searching for modules to load when initializing.")
  255.   },
  256.   {
  257.     TRUE, "scripts",
  258.     N_("This subdirectory is used by the GIMP to store user\n"
  259.        "created and installed scripts.  The default gimprc file\n"
  260.        "checks this subdirectory in addition to the systemwide\n"
  261.        "GIMP scripts subdirectory when searching for scripts")
  262.   },
  263.   {
  264.     TRUE, "tmp",
  265.     N_("This subdirectory is used by the GIMP to temporarily\n"
  266.        "store undo buffers to reduce memory usage.  If GIMP is\n"
  267.        "unceremoniously killed, files may persist in this directory\n"
  268.        "of the form: gimp<#>.<#>.  These files are useless across\n"
  269.        "GIMP sessions and can be destroyed with impunity.")
  270.   },
  271.   {
  272.     TRUE, "curves",
  273.     N_("This subdirectory is used to store parameter files for\n"
  274.        "the Curves tool.")
  275.   },
  276.   {
  277.     TRUE, "levels",
  278.     N_("This subdirectory is used to store parameter files for\n"
  279.        "the Levels tool.")
  280.   },
  281.   {
  282.     TRUE, "fractalexplorer",
  283.     N_("This is a subdirectory which can be used to store\n"
  284.        "user defined fractals to be used by the FractalExplorer\n"
  285.        "plug-in.  The default gimprc file checks this subdirectory\n"
  286.        "in addition to the systemwide GIMP FractalExplorer\n" 
  287.        "installation when searching for fractals.")
  288.   },  
  289.   {
  290.     TRUE, "gfig",
  291.     N_("This is a subdirectory which can be used to store\n"
  292.        "user defined figures to be used by the GFig plug-in.\n"
  293.        "The default gimprc file checks this subdirectory in\n"
  294.        "addition to the systemwide GIMP GFig installation\n"
  295.        "when searching for gfig figures.")
  296.   },
  297.   {
  298.     TRUE, "gflare",
  299.     N_("This is a subdirectory which can be used to store\n"
  300.        "user defined gflares to be used by the GFlare plug-in.\n"
  301.        "The default gimprc file checks this subdirectory in\n"
  302.        "addition to the systemwide GIMP GFlares installation\n"
  303.        "when searching for gflares.")
  304.   },
  305.   {
  306.     TRUE, "gimpressionist",
  307.     N_("This is a subdirectory which can be used to store\n"
  308.        "user defined data to be used by the Gimpressionist\n"
  309.        "plug-in.  The default gimprc file checks this subdirectory\n"
  310.        "in addition to the systemwide GIMP Gimpressionist\n"
  311.        "installation when searching for data.")    
  312.   }  
  313. };
  314. static gint num_tree_items = sizeof (tree_items) / sizeof (tree_items[0]);
  315.  
  316. static void
  317. user_install_notebook_set_page (GtkNotebook *notebook,
  318.                 gint         index)
  319. {
  320.   gchar *title;
  321.   gchar *footer;
  322.   GtkWidget *page;
  323.   
  324.   page = gtk_notebook_get_nth_page (notebook, index);
  325.   
  326.   title  = gtk_object_get_data (GTK_OBJECT (page), "title");
  327.   footer = gtk_object_get_data (GTK_OBJECT (page), "footer");
  328.  
  329.   gtk_label_set_text (GTK_LABEL (title_label), title);
  330.   gtk_label_set_text (GTK_LABEL (footer_label), footer);
  331.  
  332.   if (index == EEK_PAGE)
  333.     {
  334.       gtk_widget_set_usize (title_pixmap, 
  335.                 title_pixmap->allocation.width,
  336.                 title_pixmap->allocation.height);
  337.       gimp_pixmap_set (GIMP_PIXMAP (title_pixmap), eek_xpm);
  338.     }
  339.   
  340.   gtk_notebook_set_page (notebook, index);
  341. }
  342.  
  343. static void
  344. user_install_continue_callback (GtkWidget *widget,
  345.                 gpointer   data)
  346. {
  347.   static gint notebook_index = 0;
  348.   UserInstallCallback callback;
  349.  
  350.   callback = (UserInstallCallback) data;
  351.  
  352.   switch (notebook_index)
  353.     {
  354.     case 0:
  355.       break;
  356.       
  357.     case 1:
  358.       /*  Creatring the directories can take some time on NFS, so inform
  359.        *  the user and set the buttons insensitive
  360.        */
  361.       gtk_widget_set_sensitive (continue_button, FALSE);
  362.       gtk_widget_set_sensitive (cancel_button, FALSE);
  363.       gtk_label_set_text (GTK_LABEL (footer_label),
  364.               _("Please wait while your personal\n"
  365.                 "GIMP directory is being created..."));
  366.  
  367.       while (gtk_events_pending ())
  368.     gtk_main_iteration ();
  369.  
  370.       if (user_install_run ())
  371.     gtk_widget_set_sensitive (continue_button, TRUE);
  372.  
  373.       gtk_widget_set_sensitive (cancel_button, TRUE);
  374.       break;
  375.  
  376.     case 2:
  377. #ifdef G_OS_WIN32
  378.       FreeConsole ();
  379. #endif
  380.       parse_buffers_init ();
  381.       parse_unitrc ();
  382.       parse_gimprc ();
  383.       user_install_tuning ();
  384.       break;
  385.  
  386.     case 3:
  387.       user_install_tuning_done ();
  388.       user_install_resolution ();
  389.       break;
  390.  
  391.     case 4:
  392.       user_install_resolution_done ();
  393.  
  394.       gtk_widget_destroy (user_install_dialog);
  395.       gdk_gc_unref (white_gc);
  396.       gtk_style_unref (title_style);
  397.       gtk_style_unref (page_style);
  398.  
  399.       (* callback) ();
  400.       return;
  401.       break;
  402.  
  403.     case EEK_PAGE:
  404.     default:
  405.       g_assert_not_reached ();
  406.     }
  407.  
  408.   if (notebook_index < NUM_PAGES - 1)
  409.     user_install_notebook_set_page (GTK_NOTEBOOK (notebook), ++notebook_index);
  410. }
  411.  
  412.  
  413. static void
  414. user_install_cancel_callback (GtkWidget *widget,
  415.                   gpointer   data)
  416. {
  417.   static gint timeout = 0;
  418.  
  419.   if (timeout)
  420.     gtk_exit (0);
  421.  
  422.   gtk_widget_destroy (continue_button);
  423.   user_install_notebook_set_page (GTK_NOTEBOOK (notebook), EEK_PAGE);
  424.   timeout = gtk_timeout_add (1024, (GtkFunction)gtk_exit, (gpointer)0);
  425. }
  426.  
  427. static gint
  428. user_install_corner_expose (GtkWidget      *widget,
  429.                 GdkEventExpose *eevent,
  430.                 gpointer        data)
  431. {
  432.   switch ((GtkCornerType) data)
  433.     {
  434.     case GTK_CORNER_TOP_LEFT:
  435.       gdk_draw_arc (widget->window,
  436.             white_gc,
  437.             TRUE,
  438.             0, 0,
  439.             widget->allocation.width * 2,
  440.             widget->allocation.height * 2,
  441.             90 * 64,
  442.             180 * 64);
  443.       break;
  444.       
  445.     case GTK_CORNER_BOTTOM_LEFT:
  446.       gdk_draw_arc (widget->window,
  447.             white_gc,
  448.             TRUE,
  449.             0, -widget->allocation.height,
  450.             widget->allocation.width * 2,
  451.             widget->allocation.height * 2,
  452.             180 * 64,
  453.             270 * 64);
  454.       break;
  455.       
  456.     case GTK_CORNER_TOP_RIGHT:
  457.       gdk_draw_arc (widget->window,
  458.             white_gc,
  459.             TRUE,
  460.             -widget->allocation.width, 0,
  461.             widget->allocation.width * 2,
  462.             widget->allocation.height * 2,
  463.             0 * 64,
  464.             90 * 64);
  465.       break;
  466.       
  467.     case GTK_CORNER_BOTTOM_RIGHT:
  468.       gdk_draw_arc (widget->window,
  469.             white_gc,
  470.             TRUE,
  471.             -widget->allocation.width, -widget->allocation.height,
  472.             widget->allocation.width * 2,
  473.             widget->allocation.height * 2,
  474.             270 * 64,
  475.             360 * 64);
  476.       break;
  477.       
  478.     default:
  479.       return FALSE;
  480.     }
  481.  
  482.   return TRUE;
  483. }
  484.  
  485. static GtkWidget *
  486. user_install_notebook_append_page (GtkNotebook *notebook,
  487.                    gchar       *title,
  488.                    gchar       *footer)
  489. {
  490.   GtkWidget *page;
  491.   
  492.   page = gtk_vbox_new (FALSE, 6);
  493.   gtk_object_set_data (GTK_OBJECT (page), "title", title);
  494.   gtk_object_set_data (GTK_OBJECT (page), "footer", footer);
  495.   gtk_notebook_append_page (notebook, page, NULL);
  496.   gtk_widget_show (page);
  497.  
  498.   return page;
  499. }
  500.  
  501. static void
  502. add_label (GtkBox   *box,
  503.        gchar    *text)
  504. {
  505.   GtkWidget *label;
  506.  
  507.   label = gtk_label_new (text);
  508.   PAGE_STYLE (label);
  509.   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
  510.  
  511.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  512.   gtk_box_pack_start (box, label, FALSE, FALSE, 0);
  513.   
  514.   gtk_widget_show (label);
  515. }
  516.  
  517. static void
  518. user_install_ctree_select_row (GtkWidget      *widget,
  519.                    gint            row, 
  520.                    gint            column, 
  521.                    GdkEventButton *bevent,
  522.                    gpointer        data)
  523. {
  524.   GtkNotebook *notebook;
  525.  
  526.   notebook = (GtkNotebook*) data;
  527.  
  528.   gtk_notebook_set_page (notebook, row);
  529. }
  530.  
  531. void
  532. user_install_dialog_create (UserInstallCallback callback)
  533. {
  534.   GtkWidget *dialog;
  535.   GtkWidget *vbox;
  536.   GtkWidget *hbox;
  537.   GtkWidget *ebox;
  538.   GtkWidget *table;
  539.   GtkWidget *darea;
  540.   GtkWidget *page;
  541.   GtkWidget *sep;
  542.   GdkFont   *large_font;
  543.  
  544.   dialog = user_install_dialog =
  545.     gimp_dialog_new (_("GIMP User Installation"), "user_installation",
  546.              NULL, NULL,
  547.              GTK_WIN_POS_CENTER,
  548.              FALSE, FALSE, FALSE,
  549.  
  550.              _("Continue"), user_install_continue_callback,
  551.              callback, NULL, &continue_button, TRUE, FALSE,
  552.              _("Cancel"), user_install_cancel_callback,
  553.              callback, 1, &cancel_button, FALSE, TRUE,
  554.  
  555.              NULL);
  556.  
  557.   gimp_dialog_set_icon (GTK_WINDOW (dialog));
  558.  
  559.   gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 8);
  560.  
  561.   /*  hide the separator between the dialog's vbox and the action area  */
  562.   gtk_widget_destroy (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_BIN (dialog)->child)), 0)));
  563.  
  564.   gtk_widget_realize (dialog);
  565.  
  566.   /*  B/W Style for the page contents  */
  567.   page_style = gtk_style_copy (gtk_widget_get_default_style ());
  568.   colormap = gtk_widget_get_colormap (dialog);
  569.  
  570.   gdk_color_black (colormap, &black_color);
  571.   gdk_color_white (colormap, &white_color);
  572.  
  573.   page_style->fg[GTK_STATE_NORMAL]   = black_color;
  574.   page_style->text[GTK_STATE_NORMAL] = black_color;
  575.   page_style->bg[GTK_STATE_NORMAL]   = white_color;
  576.  
  577.   gdk_font_unref (page_style->font);
  578.   page_style->font = dialog->style->font;
  579.   gdk_font_ref (page_style->font);
  580.  
  581.   /*  B/Colored Style for the page title  */
  582.   title_style = gtk_style_copy (page_style);
  583.  
  584.   if (gdk_color_parse ("dark orange", &title_color) &&
  585.       gdk_colormap_alloc_color (colormap, &title_color, FALSE, TRUE))
  586.     {
  587.       title_style->bg[GTK_STATE_NORMAL] = title_color;
  588.     }
  589.  
  590.   /*  this is a fontset, e.g. multiple comma-separated font definitions  */
  591.   large_font = gdk_fontset_load (_("-*-helvetica-bold-r-normal-*-*-240-*-*-*-*-*-*,*"));
  592.  
  593.   if (large_font)
  594.     {
  595.       gdk_font_unref (title_style->font);
  596.       title_style->font = large_font;
  597.       gdk_font_ref (title_style->font);
  598.     }
  599.  
  600.   /*  W/W GC for the corner  */
  601.   white_gc = gdk_gc_new (dialog->window);
  602.   gdk_gc_set_foreground (white_gc, &white_color);
  603.  
  604.   TITLE_STYLE (dialog);
  605.  
  606.   footer_label = gtk_label_new (NULL);
  607.   PAGE_STYLE (footer_label);
  608.   gtk_label_set_justify (GTK_LABEL (footer_label), GTK_JUSTIFY_RIGHT);
  609.   gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), footer_label,
  610.             FALSE, FALSE, 8);
  611.   gtk_widget_show (footer_label);
  612.  
  613.   vbox = gtk_vbox_new (FALSE, 0);
  614.   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
  615.  
  616.   ebox = gtk_event_box_new ();
  617.   TITLE_STYLE (ebox);
  618.   gtk_widget_set_events (ebox, GDK_EXPOSURE_MASK);
  619.   gtk_widget_set_usize (ebox, WILBER_WIDTH + 16, -1);
  620.   gtk_box_pack_start (GTK_BOX (vbox), ebox, FALSE, FALSE, 0);
  621.   gtk_widget_show (ebox);
  622.  
  623.   hbox = gtk_hbox_new (FALSE, 8);
  624.   gtk_container_set_border_width (GTK_CONTAINER (hbox), 8);
  625.   gtk_container_add (GTK_CONTAINER (ebox), hbox);
  626.   gtk_widget_show (hbox);
  627.  
  628.   title_pixmap = gimp_pixmap_new (wilber_xpm);
  629.   gtk_box_pack_start (GTK_BOX (hbox), title_pixmap, FALSE, FALSE, 8);
  630.   gtk_widget_show (title_pixmap);
  631.  
  632.   title_label = gtk_label_new (NULL);
  633.   TITLE_STYLE (title_label);  
  634.   gtk_label_set_justify (GTK_LABEL (title_label), GTK_JUSTIFY_LEFT);
  635.   gtk_box_pack_start (GTK_BOX (hbox), title_label, FALSE, FALSE, 0);
  636.   gtk_widget_show (title_label);
  637.  
  638.   hbox = gtk_hbox_new (FALSE, 0);
  639.   gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
  640.   gtk_widget_show (hbox);
  641.  
  642.   ebox = gtk_event_box_new ();
  643.   TITLE_STYLE (ebox);  
  644.   gtk_widget_set_usize (ebox, 16, -1);
  645.   gtk_box_pack_start (GTK_BOX (hbox), ebox, FALSE, FALSE, 0);
  646.   gtk_widget_show (ebox);
  647.  
  648.   ebox = gtk_event_box_new ();
  649.   PAGE_STYLE (ebox);  
  650.   gtk_box_pack_start (GTK_BOX (hbox), ebox, TRUE, TRUE, 0);
  651.   gtk_widget_show (ebox);
  652.  
  653.   table = gtk_table_new (3, 3, FALSE);
  654.   gtk_table_set_col_spacing (GTK_TABLE (table), 1, 8);
  655.   gtk_container_add (GTK_CONTAINER (ebox), table);
  656.   gtk_widget_show (table);
  657.  
  658.   darea = gtk_drawing_area_new ();
  659.   TITLE_STYLE (darea);  
  660.   gtk_drawing_area_size (GTK_DRAWING_AREA (darea), 16, 16);
  661.   gtk_signal_connect_after (GTK_OBJECT (darea), "expose_event",
  662.                 GTK_SIGNAL_FUNC (user_install_corner_expose),
  663.                 (gpointer) GTK_CORNER_TOP_LEFT);
  664.   gtk_table_attach (GTK_TABLE (table), darea, 0, 1, 0, 1,
  665.             GTK_SHRINK, GTK_SHRINK, 0, 0);
  666.   gtk_widget_show (darea);
  667.  
  668.   darea = gtk_drawing_area_new ();
  669.   TITLE_STYLE (darea);  
  670.   gtk_drawing_area_size (GTK_DRAWING_AREA (darea), 16, 16);
  671.   gtk_signal_connect_after (GTK_OBJECT (darea), "expose_event",
  672.                 GTK_SIGNAL_FUNC (user_install_corner_expose),
  673.                 (gpointer) GTK_CORNER_BOTTOM_LEFT);
  674.   gtk_table_attach (GTK_TABLE (table), darea, 0, 1, 2, 3,
  675.             GTK_SHRINK, GTK_SHRINK, 0, 0);
  676.   gtk_widget_show (darea);
  677.  
  678.   notebook = gtk_notebook_new ();
  679.   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
  680.   gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
  681.   gtk_table_attach_defaults (GTK_TABLE (table), notebook, 1, 2, 1, 2);
  682.   gtk_widget_show (notebook);
  683.  
  684.   gtk_widget_show (vbox);
  685.  
  686.   /*  Page 1  */
  687.   page = user_install_notebook_append_page (GTK_NOTEBOOK (notebook),
  688.                         _("Welcome to\n"
  689.                           "The GIMP User Installation"),
  690.                         _("Click \"Continue\" to enter "
  691.                           "the GIMP user installation."));
  692.  
  693.   add_label (GTK_BOX (page),
  694.          _("The GIMP - GNU Image Manipulation Program\n"
  695.            "Copyright (C) 1995-2000\n"
  696.            "Spencer Kimball, Peter Mattis and the GIMP Development Team."));
  697.  
  698.   sep = gtk_hseparator_new ();
  699.   gtk_box_pack_start (GTK_BOX (page), sep, FALSE, FALSE, 2);
  700.   gtk_widget_show (sep);
  701.  
  702.   add_label (GTK_BOX (page),
  703.          _("This program is free software; you can redistribute it and/or modify\n"
  704.            "it under the terms of the GNU General Public License as published by\n"
  705.            "the Free Software Foundation; either version 2 of the License, or\n"
  706.            "(at your option) any later version."));
  707.   add_label (GTK_BOX (page),
  708.          _("This program is distributed in the hope that it will be useful,\n"
  709.            "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  710.            "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
  711.            "See the GNU General Public License for more details."));
  712.   add_label (GTK_BOX (page),
  713.          _("You should have received a copy of the GNU General Public License\n"
  714.            "along with this program; if not, write to the Free Software\n"
  715.            "Foundation, Inc., 59 Temple Place - Suite 330, Boston,\n"
  716.            "MA 02111-1307, USA."));
  717.  
  718.   /*  Page 2  */
  719.   {
  720.     GtkWidget *hbox;
  721.     GtkWidget *vbox;
  722.     GtkWidget *ctree;
  723.     GtkWidget *notebook2;
  724.     GtkWidget *page2;
  725.     GtkWidget *label;
  726.     GtkCTreeNode *main_node = NULL;
  727.     GtkCTreeNode *sub_node = NULL;
  728.     GdkPixmap *file_pixmap;
  729.     GdkBitmap *file_mask;
  730.     GdkPixmap *folder_pixmap;
  731.     GdkBitmap *folder_mask;
  732.     gchar     *str;
  733.  
  734.     gint i;
  735.  
  736.     gchar *node[1];
  737.     
  738.     page = user_install_notebook_append_page (GTK_NOTEBOOK (notebook),
  739.                           _("Personal GIMP Directory"),
  740.                           _("Click \"Continue\" to create "
  741.                         "your personal GIMP directory."));
  742.  
  743.     hbox = gtk_hbox_new (FALSE, 8);
  744.     gtk_box_pack_start (GTK_BOX (page), hbox, FALSE, FALSE, 0);
  745.     gtk_widget_show (hbox);
  746.  
  747.     ctree = gtk_ctree_new (1, 0);
  748.     PAGE_STYLE (ctree);
  749.     gtk_ctree_set_indent (GTK_CTREE (ctree), 12);
  750.     gtk_clist_set_shadow_type (GTK_CLIST (ctree), GTK_SHADOW_NONE);
  751.     gtk_clist_set_selection_mode (GTK_CLIST (ctree), GTK_SELECTION_BROWSE);
  752.     gtk_box_pack_start (GTK_BOX (hbox), ctree, FALSE, FALSE, 0);
  753.     gtk_widget_show (ctree);
  754.  
  755.     vbox = gtk_vbox_new (FALSE, 6);
  756.     gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
  757.     gtk_widget_show (vbox);
  758.  
  759.     str = g_strdup_printf (_("For a proper GIMP installation, a subdirectory named\n"
  760.                  "%s needs to be created."), gimp_directory ());
  761.     add_label (GTK_BOX (vbox), str);
  762.     g_free (str);
  763.  
  764.     add_label (GTK_BOX (vbox),
  765.            _("This subdirectory will contain a number of important files.\n"
  766.          "Click on one of the files or subdirectories in the tree\n"
  767.          "to get more information about the selected item."));
  768.  
  769.     notebook2 = gtk_notebook_new ();
  770.     gtk_container_set_border_width (GTK_CONTAINER (notebook2), 8);
  771.     gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook2), FALSE);
  772.     gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook2), FALSE);
  773.     gtk_box_pack_start (GTK_BOX (vbox), notebook2, TRUE, TRUE, 0);
  774.     gtk_widget_show (notebook2);
  775.  
  776.     /*  empty page  */
  777.     page2 = gtk_vbox_new (FALSE, 0);
  778.     gtk_widget_show (page2);
  779.     gtk_notebook_append_page (GTK_NOTEBOOK (notebook2), page2, NULL);
  780.  
  781.     node[0] = gimp_directory ();
  782.  
  783.     main_node = gtk_ctree_insert_node (GTK_CTREE (ctree), NULL, NULL,
  784.                        node, 4,
  785.                        NULL, NULL, NULL, NULL,
  786.                        FALSE, TRUE);      
  787.  
  788.     gtk_signal_connect (GTK_OBJECT (ctree), "select_row",
  789.             GTK_SIGNAL_FUNC (user_install_ctree_select_row),
  790.             notebook2);
  791.  
  792.     file_pixmap = gdk_pixmap_create_from_xpm_d (dialog->window,
  793.                         &file_mask,
  794.                         &page_style->bg[GTK_STATE_NORMAL],
  795.                         new_xpm);
  796.     folder_pixmap = gdk_pixmap_create_from_xpm_d (dialog->window,
  797.                           &folder_mask,
  798.                           &page_style->bg[GTK_STATE_NORMAL],
  799.                           folder_xpm);
  800.  
  801.     for (i = 0; i < num_tree_items; i++)
  802.       {
  803.     node[0] = tree_items[i].text;
  804.  
  805.     if (tree_items[i].directory)
  806.       {
  807.         sub_node = gtk_ctree_insert_node (GTK_CTREE (ctree), main_node, NULL,
  808.                           node, 4,
  809.                           folder_pixmap, folder_mask,
  810.                           folder_pixmap, folder_mask,
  811.                           FALSE, TRUE);      
  812.       }
  813.     else
  814.       {
  815.         sub_node = gtk_ctree_insert_node (GTK_CTREE (ctree), main_node, NULL,
  816.                           node, 4,
  817.                           file_pixmap, file_mask,
  818.                           file_pixmap, file_mask,
  819.                           FALSE, TRUE);
  820.       }
  821.  
  822.     page2 = gtk_vbox_new (FALSE, 0);
  823.     label = gtk_label_new (gettext (tree_items[i].description));
  824.     PAGE_STYLE (label);
  825.     PAGE_STYLE (label);
  826.     gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
  827.     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  828.     gtk_box_pack_start (GTK_BOX (page2), label, TRUE, TRUE, 0);
  829.     gtk_widget_show (label);
  830.     gtk_widget_show (page2);
  831.  
  832.     gtk_notebook_append_page (GTK_NOTEBOOK (notebook2), page2, NULL);
  833.       }
  834.  
  835.     gtk_clist_set_column_width (GTK_CLIST (ctree), 0,
  836.                 gtk_clist_optimal_column_width (GTK_CLIST (ctree), 0));
  837.  
  838.     gtk_widget_set_usize (ctree, -1, ctree->requisition.height);
  839.  
  840.     gdk_pixmap_unref (file_pixmap);
  841.     gdk_bitmap_unref (file_mask);
  842.     gdk_pixmap_unref (folder_pixmap);
  843.     gdk_bitmap_unref (folder_mask);
  844.   }
  845.   
  846.   /*  Page 3  */
  847.   page = log_page =
  848.     user_install_notebook_append_page (GTK_NOTEBOOK (notebook),
  849.                        _("User Installation Log"),
  850.                        NULL);
  851.  
  852.   /*  Page 4  */
  853.   page = tuning_page = 
  854.     user_install_notebook_append_page (GTK_NOTEBOOK (notebook),
  855.                        _("GIMP Performance Tuning"),
  856.                        _("Click \"Continue\" to accept the settings above."));
  857.   
  858.   add_label (GTK_BOX (page),
  859.          _("For optimal GIMP performance, some settings may have to be adjusted."));
  860.  
  861.   sep = gtk_hseparator_new ();
  862.   gtk_box_pack_start (GTK_BOX (page), sep, FALSE, FALSE, 2);
  863.   gtk_widget_show (sep);
  864.  
  865.   /*  Page 5  */
  866.   page = resolution_page = 
  867.     user_install_notebook_append_page (GTK_NOTEBOOK (notebook),
  868.                        _("Monitor Resolution"),
  869.                        _("Click \"Continue\" to start The GIMP."));
  870.   
  871.   add_label (GTK_BOX (resolution_page),
  872.          _("To display images in their natural size, "
  873.            "GIMP needs to know your monitor resolution."));
  874.  
  875.   sep = gtk_hseparator_new ();
  876.   gtk_box_pack_start (GTK_BOX (page), sep, FALSE, FALSE, 2);
  877.   gtk_widget_show (sep);
  878.  
  879.   /*  EEK page  */
  880.   page = user_install_notebook_append_page (GTK_NOTEBOOK (notebook),
  881.                         _("Aborting Installation..."),
  882.                         NULL);
  883.  
  884.   user_install_notebook_set_page (GTK_NOTEBOOK (notebook), 0);
  885.  
  886.   gtk_widget_show (dialog);
  887. }
  888.  
  889.  
  890. /*********************/
  891. /*  Local functions  */
  892.  
  893. #ifdef G_OS_WIN32
  894.  
  895. char *
  896. quote_spaces (char *string)
  897. {
  898.   int nspaces = 0;
  899.   char *p = string, *q, *new;
  900.  
  901.   while (*p)
  902.     {
  903.       if (*p == ' ')
  904.     nspaces++;
  905.       p++;
  906.     }
  907.  
  908.   if (nspaces == 0)
  909.     return g_strdup (string);
  910.  
  911.   new = g_malloc (strlen (string) + nspaces*2 + 1);
  912.  
  913.   p = string;
  914.   q = new;
  915.   while (*p)
  916.     {
  917.       if (*p == ' ')
  918.     {
  919.       *q++ = '"';
  920.       *q++ = ' ';
  921.       *q++ = '"';
  922.     }
  923.       else
  924.     *q++ = *p;
  925.       p++;
  926.     }
  927.   *q = '\0';
  928.  
  929.   return new;
  930. }
  931.  
  932. #endif
  933.  
  934. static gboolean
  935. user_install_run (void)
  936. {
  937.   FILE *pfp;
  938.   gchar buffer[2048];
  939.   struct stat stat_buf;
  940.   gint err;
  941.   gboolean executable = TRUE;
  942.  
  943.   /*  Generate output  */
  944.   g_snprintf (buffer, sizeof (buffer), "%s" G_DIR_SEPARATOR_S USER_INSTALL,
  945.           gimp_data_directory ());
  946.   if ((err = stat (buffer, &stat_buf)) != 0)
  947.     {
  948.       gchar *str;
  949.       
  950.       str = g_strdup_printf ("%s\n%s", buffer,
  951.                  _("does not exist.  Cannot install."));
  952.       add_label (GTK_BOX (log_page), str);
  953.       g_free (str);
  954.  
  955.       executable = FALSE;
  956.     }
  957. #ifdef S_IXUSR
  958.   else if (! (S_IXUSR & stat_buf.st_mode) || ! (S_IRUSR & stat_buf.st_mode))
  959.     {
  960.       gchar *str;
  961.       
  962.       str = g_strdup_printf ("%s\n%s", buffer,
  963.                  _("has invalid permissions.  Cannot install."));
  964.       add_label (GTK_BOX (log_page), str);
  965.       g_free (str);
  966.  
  967.       executable = FALSE;
  968.     }
  969. #endif
  970.  
  971.   if (executable)
  972.     {
  973. #ifdef G_OS_WIN32
  974.       char *quoted_data_dir, *quoted_user_dir, *quoted_sysconf_dir;
  975.  
  976.       /* On Windows, it is common for the GIMP data directory
  977.        * to have spaces in it ("c:\Program Files\GIMP"). Put spaces in quotes.
  978.        */
  979.       quoted_data_dir = quote_spaces (gimp_data_directory ());
  980.       quoted_user_dir = quote_spaces (gimp_directory ());
  981.       quoted_sysconf_dir = quote_spaces (gimp_sysconf_directory ());
  982.  
  983.       /* The Microsoft _popen doesn't work in Windows applications, sigh.
  984.        * Do the installation by calling system(). The user_install.bat
  985.        * ends with a pause command, so the user has to press enter in
  986.        * the console window to continue, and thus has a chance to read
  987.        * at the window contents.
  988.        */
  989.  
  990.       AllocConsole ();
  991.       g_snprintf (buffer, sizeof(buffer), "%s" G_DIR_SEPARATOR_S USER_INSTALL " %s %s %s",
  992.           quoted_data_dir, quoted_data_dir,
  993.           quoted_user_dir, quoted_sysconf_dir);
  994.  
  995.       if (system (buffer) == -1)
  996.     executable = FALSE;
  997.       g_free (quoted_data_dir);
  998.       g_free (quoted_user_dir);
  999.       g_free (quoted_sysconf_dir);
  1000.  
  1001.       if (executable)
  1002.     add_label (GTK_BOX (log_page),
  1003.            _("Did you notice any error messages in the console window?\n"
  1004.              "If not, installation was successful!\n"
  1005.              "Otherwise, quit and investigate the possible reason..."));
  1006. #else
  1007. #ifndef __EMX__
  1008.       g_snprintf (buffer, sizeof(buffer), "%s" G_DIR_SEPARATOR_S USER_INSTALL " %s %s %s %s",
  1009.           gimp_data_directory (),
  1010.           "2>&1",
  1011.           gimp_data_directory(), gimp_directory (), gimp_sysconf_directory());
  1012. #else
  1013.       g_snprintf (buffer, sizeof(buffer), "cmd.exe /c %s" G_DIR_SEPARATOR_S USER_INSTALL " %s %s %s",
  1014.           gimp_data_directory (), gimp_data_directory(),
  1015.           gimp_directory (), gimp_sysconf_directory());
  1016.       {
  1017.     char *s = buffer + 10;
  1018.     while (*s)
  1019.       {
  1020.         if (*s == '/') *s = '\\';
  1021.         s++;
  1022.       }
  1023.       }
  1024. #endif
  1025.  
  1026.       /* urk - should really use something better than popen(), since
  1027.        * we can't tell if the installation script failed --austin */
  1028.       if ((pfp = popen (buffer, "r")) != NULL)
  1029.     {
  1030.       GtkWidget *table;
  1031.       GtkWidget *log_text;
  1032.       GtkWidget *vsb;
  1033.       GtkAdjustment *vadj;
  1034.  
  1035.       table = gtk_table_new (1, 2, FALSE);
  1036.       gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
  1037.       gtk_box_pack_start (GTK_BOX (log_page), table, TRUE, TRUE, 0);
  1038.  
  1039.       vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
  1040.       vsb  = gtk_vscrollbar_new (vadj);
  1041.       log_text = gtk_text_new (NULL, vadj);
  1042.  
  1043.       gtk_table_attach (GTK_TABLE (table), vsb, 1, 2, 0, 1,
  1044.                 GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  1045.       gtk_table_attach (GTK_TABLE (table), log_text, 0, 1, 0, 1,
  1046.                 GTK_EXPAND | GTK_SHRINK | GTK_FILL,
  1047.                 GTK_EXPAND | GTK_SHRINK | GTK_FILL,
  1048.                 0, 0);
  1049.  
  1050.       gtk_widget_show (vsb);
  1051.       gtk_widget_show (log_text);
  1052.       gtk_widget_show (table);
  1053.  
  1054.       while (fgets (buffer, sizeof (buffer), pfp))
  1055.         gtk_text_insert (GTK_TEXT (log_text), NULL, NULL, NULL, buffer, -1);
  1056.       pclose (pfp);
  1057.  
  1058.       add_label (GTK_BOX (log_page),
  1059.              _("Did you notice any error messages in the lines above?\n"
  1060.                "If not, installation was successful!\n"
  1061.                "Otherwise, quit and investigate the possible reason..."));
  1062.     }
  1063.       else
  1064.     executable = FALSE;
  1065. #endif /* !G_OS_WIN32 */
  1066.     }
  1067.  
  1068.   if (executable)
  1069.     {
  1070.       gtk_object_set_data (GTK_OBJECT (log_page), "footer",
  1071.            _("Click \"Continue\" to complete GIMP installation."));
  1072.     }
  1073.   else
  1074.     {
  1075.       add_label (GTK_BOX (log_page),
  1076.          _("Installation failed.  Contact system administrator."));
  1077.     }
  1078.  
  1079.   return executable;
  1080. }
  1081.  
  1082. static GtkObject *tile_cache_adj    = NULL;
  1083. static GtkWidget *swap_path_filesel = NULL;
  1084. static GtkWidget *xserver_toggle    = NULL;
  1085. static GtkWidget *resolution_entry  = NULL;
  1086.  
  1087. static void
  1088. user_install_tuning (void)
  1089. {
  1090.   GtkWidget *hbox;
  1091.   GtkWidget *sep;
  1092.   GtkWidget *label;
  1093.   GtkWidget *memsize;
  1094.  
  1095.   /*  tile cache size  */
  1096.   add_label (GTK_BOX (tuning_page),
  1097.          _("GIMP uses a limited amount of memory to store image data, the so-called\n"
  1098.            "\"Tile Cache\". You should adjust its size to fit into memory. Consider\n"
  1099.            "the amount of memory used by other running processes."));
  1100.  
  1101.   hbox = gtk_hbox_new (FALSE, 8);
  1102.   gtk_box_pack_start (GTK_BOX (tuning_page), hbox, FALSE, FALSE, 0);
  1103.   gtk_widget_show (hbox);
  1104.   
  1105.   tile_cache_adj = gtk_adjustment_new (tile_cache_size, 
  1106.                        0, (4069.0 * 1024 * 1024), 1.0, 1.0, 0.0);
  1107.   memsize = gimp_mem_size_entry_new (GTK_ADJUSTMENT (tile_cache_adj));
  1108.   gtk_box_pack_end (GTK_BOX (hbox), memsize, FALSE, FALSE, 0);
  1109.   gtk_widget_show (memsize);
  1110.  
  1111.   label = gtk_label_new (_("Tile Cache Size:"));
  1112.   PAGE_STYLE (label);
  1113.   gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  1114.   gtk_widget_show (label);
  1115.   
  1116.   sep = gtk_hseparator_new ();
  1117.   gtk_box_pack_start (GTK_BOX (tuning_page), sep, FALSE, FALSE, 2);
  1118.   gtk_widget_show (sep);
  1119.  
  1120.   /*  swap file location  */
  1121.   add_label (GTK_BOX (tuning_page),
  1122.          _("All image and undo data which doesn't fit into the Tile Cache will be\n"
  1123.            "written to a swap file. This file should be located on a local filesystem\n"
  1124.            "with enough free space (several hundred MB). On a UNIX system, you\n"
  1125.            "may want to use the system-wide temp-dir (\"/tmp\" or \"/var/tmp\")."));
  1126.  
  1127.   hbox = gtk_hbox_new (FALSE, 8);
  1128.   gtk_box_pack_start (GTK_BOX (tuning_page), hbox, FALSE, FALSE, 0);
  1129.   gtk_widget_show (hbox);
  1130.   
  1131.   swap_path_filesel = gimp_file_selection_new (_("Select Swap Dir"), swap_path,
  1132.                            TRUE, TRUE);
  1133.   gtk_box_pack_end (GTK_BOX (hbox), swap_path_filesel, FALSE, FALSE, 0);
  1134.   gtk_widget_show (swap_path_filesel);
  1135.  
  1136.   label = gtk_label_new (_("Swap Directory:"));
  1137.   PAGE_STYLE (label);
  1138.   gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  1139.   gtk_widget_show (label);
  1140. }
  1141.  
  1142. static void
  1143. user_install_tuning_done (void)
  1144. {
  1145. }
  1146.  
  1147. static void
  1148. user_install_resolution_calibrate (GtkWidget *button,
  1149.                    gpointer   data)
  1150. {
  1151.   resolution_calibrate_dialog (resolution_entry, 
  1152.                    title_style, page_style,
  1153.                    GTK_SIGNAL_FUNC (user_install_corner_expose));
  1154. }
  1155.  
  1156. static void
  1157. user_install_resolution (void)
  1158. {
  1159.   GtkWidget *hbox;
  1160.   GtkWidget *sep;
  1161.   GimpChainButton *chain;
  1162.   GtkWidget *button;
  1163.   GList     *list; 
  1164.   gchar     *pixels_per_unit;
  1165.   gdouble    xres, yres;
  1166.   gchar     *str;
  1167.  
  1168.   gdisplay_xserver_resolution (&xres, &yres);
  1169.  
  1170.   add_label (GTK_BOX (resolution_page),
  1171.          _("GIMP can obtain this information from the windowing system.\n"
  1172.            "However, usually this does not give useful values."));
  1173.   
  1174.   hbox = gtk_hbox_new (FALSE, 0);
  1175.   gtk_box_pack_start (GTK_BOX (resolution_page), hbox, FALSE, FALSE, 0);
  1176.   gtk_widget_show (hbox);
  1177.  
  1178.   str = g_strdup_printf (_("Get Resolution from windowing system (Currently %d x %d dpi)"),
  1179.              ROUND (xres), ROUND (yres));
  1180.   xserver_toggle = gtk_check_button_new_with_label (str);
  1181.   g_free (str);
  1182.  
  1183.   PAGE_STYLE (GTK_BIN (xserver_toggle)->child);
  1184.   gtk_box_pack_end (GTK_BOX (hbox), xserver_toggle, FALSE, FALSE, 0);
  1185.   gtk_widget_show (xserver_toggle);
  1186.  
  1187.   sep = gtk_hseparator_new ();
  1188.   gtk_box_pack_start (GTK_BOX (resolution_page), sep, FALSE, FALSE, 2);
  1189.   gtk_widget_show (sep);
  1190.  
  1191.   add_label (GTK_BOX (resolution_page),
  1192.          _("Alternatively, you can set the monitor resolution manually."));
  1193.  
  1194.   hbox = gtk_hbox_new (FALSE, 0);
  1195.   gtk_box_pack_start (GTK_BOX (resolution_page), hbox, FALSE, FALSE, 0);
  1196.   gtk_widget_show (hbox);
  1197.   
  1198.   pixels_per_unit = g_strconcat (_("Pixels"), "/%s", NULL);
  1199.   resolution_entry =
  1200.     gimp_coordinates_new (GIMP_UNIT_INCH, pixels_per_unit,
  1201.               FALSE, FALSE, 75,
  1202.               GIMP_SIZE_ENTRY_UPDATE_RESOLUTION,
  1203.               abs (monitor_xres - monitor_yres) < GIMP_MIN_RESOLUTION,
  1204.               FALSE,
  1205.               _("Monitor Resolution X:"),
  1206.               monitor_xres,
  1207.               1.0,
  1208.               GIMP_MIN_RESOLUTION,
  1209.               GIMP_MAX_RESOLUTION,
  1210.               0, 0,
  1211.               _("Y:"),
  1212.               monitor_yres,
  1213.               1.0,
  1214.               GIMP_MIN_RESOLUTION,
  1215.               GIMP_MAX_RESOLUTION,
  1216.               0, 0);
  1217.   g_free (pixels_per_unit);
  1218.  
  1219.   chain = GIMP_COORDINATES_CHAINBUTTON (resolution_entry);
  1220.   PAGE_STYLE (GTK_WIDGET (chain->line1));
  1221.   PAGE_STYLE (GTK_WIDGET (chain->line2));
  1222.   gtk_object_set_data (GTK_OBJECT (resolution_entry), "chain_button", chain);
  1223.  
  1224.   for (list = GTK_TABLE (resolution_entry)->children;
  1225.        list;
  1226.        list = g_list_next (list))
  1227.     {
  1228.       GtkTableChild *child = (GtkTableChild *) list->data;
  1229.  
  1230.       if (child && GTK_IS_LABEL (child->widget))
  1231.     PAGE_STYLE (GTK_WIDGET (child->widget));
  1232.     }
  1233.  
  1234.   gtk_box_pack_end (GTK_BOX (hbox), resolution_entry, FALSE, FALSE, 0);
  1235.   gtk_widget_show (resolution_entry);
  1236.  
  1237.   sep = gtk_hseparator_new ();
  1238.   gtk_box_pack_start (GTK_BOX (resolution_page), sep, FALSE, FALSE, 2);
  1239.   gtk_widget_show (sep);
  1240.  
  1241.   add_label (GTK_BOX (resolution_page),
  1242.          _("You can also press the \"Calibrate\" button to open a window\n"
  1243.            "which lets you determine your monitor resolution interactively."));
  1244.  
  1245.   hbox = gtk_hbox_new (FALSE, 0);
  1246.   gtk_box_pack_start (GTK_BOX (resolution_page), hbox, FALSE, FALSE, 0);
  1247.   gtk_widget_show (hbox);
  1248.  
  1249.   button = gtk_button_new_with_label (_("Calibrate"));
  1250.   gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 4, 0);
  1251.   gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  1252.   gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1253.               GTK_SIGNAL_FUNC (user_install_resolution_calibrate),
  1254.               NULL);
  1255.   gtk_widget_show (button);
  1256.   
  1257.   gtk_object_set_data (GTK_OBJECT (xserver_toggle), "inverse_sensitive",
  1258.                resolution_entry);
  1259.   gtk_object_set_data (GTK_OBJECT (resolution_entry), "inverse_sensitive",
  1260.                button);
  1261.   gtk_signal_connect (GTK_OBJECT (xserver_toggle), "toggled",
  1262.               GTK_SIGNAL_FUNC (gimp_toggle_button_sensitive_update),
  1263.               NULL);
  1264.   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (xserver_toggle),
  1265.                 using_xserver_resolution);
  1266. }
  1267.  
  1268. static void
  1269. user_install_resolution_done (void)
  1270. {
  1271.   GList *update = NULL;
  1272.   GList *remove = NULL;
  1273.  
  1274.   gint      new_tile_cache_size;
  1275.   gchar    *new_swap_path;
  1276.   gboolean  new_using_xserver_resolution;
  1277.   gdouble   new_monitor_xres;
  1278.   gdouble   new_monitor_yres;
  1279.   
  1280.   new_tile_cache_size = GTK_ADJUSTMENT (tile_cache_adj)->value;
  1281.   new_swap_path =
  1282.     gimp_file_selection_get_filename (GIMP_FILE_SELECTION (swap_path_filesel));
  1283.   new_using_xserver_resolution =
  1284.     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (xserver_toggle));
  1285.   new_monitor_xres =
  1286.     gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (resolution_entry), 0);
  1287.   new_monitor_yres =
  1288.     gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (resolution_entry), 1);
  1289.  
  1290.   if (tile_cache_size != new_tile_cache_size)
  1291.     {
  1292.       tile_cache_size = new_tile_cache_size;
  1293.       update = g_list_append (update, "tile-cache-size");
  1294.     }
  1295.   if (swap_path && new_swap_path && 
  1296.       strcmp (swap_path, new_swap_path))
  1297.     {
  1298.       g_free (swap_path);      swap_path = new_swap_path;
  1299.       update = g_list_append (update, "swap-path");
  1300.     }
  1301.   if (using_xserver_resolution != new_using_xserver_resolution ||
  1302.       ABS (monitor_xres - new_monitor_xres) > GIMP_MIN_RESOLUTION)
  1303.     {
  1304.       monitor_xres = new_monitor_xres;
  1305.       update = g_list_append (update, "monitor-xresolution");
  1306.     }
  1307.   if (using_xserver_resolution != new_using_xserver_resolution ||
  1308.       ABS (monitor_yres - new_monitor_yres) > GIMP_MIN_RESOLUTION)
  1309.     {
  1310.       monitor_yres = new_monitor_yres;
  1311.       update = g_list_append (update, "monitor-yresolution");
  1312.     }
  1313.  
  1314.   using_xserver_resolution = new_using_xserver_resolution;
  1315.  
  1316.   if (using_xserver_resolution)
  1317.     {
  1318.       /* special value of 0 for either x or y res in the gimprc file
  1319.        * means use the xserver's current resolution */
  1320.       monitor_xres = 0.0;
  1321.       monitor_yres = 0.0;
  1322.     }
  1323.  
  1324.   save_gimprc (&update, &remove);
  1325.  
  1326.   if (using_xserver_resolution)
  1327.     gdisplay_xserver_resolution (&monitor_xres, &monitor_yres);
  1328.  
  1329.   g_list_free (update);
  1330.   g_list_free (remove);
  1331. }
  1332.