"Fossies" - the Fresh Open Source Software Archive

Member "gtklp-1.3.4/gtklp/general.c" (1 Nov 2019, 31488 Bytes) of package /linux/privat/gtklp-1.3.4.src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "general.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.3.1.src_vs_1.3.3.src.

    1 /*
    2  GtkLP
    3   graphical Frontends for non-administrative CUPS users.
    4  
    5  Copyright (C) 1998-2004 Tobias Mueller
    6 
    7  This program is free software; you can redistribute it and/or
    8  modify it under the terms of the GNU General Public License
    9  as published by the Free Software Foundation; either version 2
   10  of the License, or (at your option) any later version.
   11 
   12  This program is distributed in the hope that it will be useful,
   13  but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  GNU General Public License for more details.
   16 
   17  You should have received a copy of the GNU General Public License
   18  along with this program; if not, write to the Free Software 
   19  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   20  Boston, MA 02110-1301, USA
   21 
   22 */
   23 
   24 #include <config.h>
   25 
   26 #include "general.h"
   27 
   28 #include <stdio.h>
   29 #include <stdlib.h>
   30 #include <string.h>
   31 #include <ctype.h>
   32 #include <gtk/gtk.h>
   33 #include <cups/ppd.h>
   34 
   35 #include <gettext.h>
   36 #include <libgtklp.h>
   37 
   38 #include "gtklp.h"
   39 #include "gtklp_functions.h"
   40 
   41 GtkWidget *generalTab;
   42 GtkWidget *printerFrame;
   43 GtkWidget *printerFrameCombo, *printerFrameInfoText, *printerFrameLocationText;
   44 GtkWidget *printerNumCopiesFrame, *printerNumField;
   45 GtkWidget *collateCheck;
   46 GtkWidget *printerMediaFrame, *printerMediaSizeCombo, *printerMediaTypeCombo,
   47     *printerMediaSourceCombo;
   48 GtkWidget *MediaTypeFrame, *MediaSizeFrame, *MediaSourceFrame;
   49 GtkWidget *printerDuplexFrame;
   50 GtkWidget *gtklpqFrame;
   51 GtkWidget *CustomMediaSizeFrame;
   52 GtkWidget *customSizeFieldX, *customSizeFieldY, *customSizeCombo;
   53 GSList *DuplexButtons;
   54 
   55 void generalTabSetDefaults(void)
   56 {
   57     GList *mediaSize = NULL, *mediaType = NULL, *mediaSource =
   58         NULL, *customSizeFieldUnit = NULL;
   59     int i1, flg;
   60     ppd_option_t *option;
   61     ppd_choice_t *choice;
   62     char buf[128];
   63 
   64     if (DEBUG)
   65         printf("Get generalTabDefaults\n");
   66 
   67     /* PrinterName */
   68     gtk_list_select_item(GTK_LIST(GTK_COMBO(printerFrameCombo)->list),
   69                  PrinterChoice);
   70     /* PrinterInfo */
   71     gtk_label_set_text(GTK_LABEL(printerFrameInfoText),
   72                str2str(PrinterInfos[PrinterChoice]));
   73     /* PrinterLocation */
   74     snprintf(buf, 128, "%s: %s", str2str(_("Location")),
   75          str2str(PrinterLocations[PrinterChoice]));
   76     gtk_label_set_text(GTK_LABEL(printerFrameLocationText), buf);
   77     /* Number of Copies */
   78     gtk_spin_button_set_value(GTK_SPIN_BUTTON(printerNumField),
   79                   (gfloat) NumberOfCopies);
   80     /* Collate Copies */
   81     if (collate) {
   82         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(collateCheck),
   83                          1);
   84     } else {
   85         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(collateCheck),
   86                          0);
   87     }
   88 
   89     /* Media Types */
   90     if ((ppdFindOption(printerPPD, "PageSize") == NULL) &&
   91         (ppdFindOption(printerPPD, "MediaType") == NULL) &&
   92         (ppdFindOption(printerPPD, "InputSlot") == NULL) &&
   93         (ppdFindOption(printerPPD, "PageRegion") == NULL))
   94         gtk_widget_hide(printerMediaFrame);
   95     else {
   96         gtk_widget_show(printerMediaFrame);
   97 
   98         /* Look if PageSize or PageRegion is marked! */
   99         flg = 0;
  100         if ((option = ppdFindOption(printerPPD, "PageSize")) != NULL) {
  101             for (i1 = option->num_choices, choice = option->choices;
  102                  i1 > 0; i1--, choice++) {
  103                 if (choice->marked)
  104                     flg = 1;
  105             }
  106         }
  107 
  108         if (flg == 0) { /* PageSize should win over PageRegion (PPD-Specs) */
  109             if ((option =
  110                  ppdFindOption(printerPPD, "PageRegion")) != NULL) {
  111                 for (i1 = option->num_choices, choice =
  112                      option->choices; i1 > 0; i1--, choice++) {
  113                     if (choice->marked)
  114                         flg = 2;
  115                 }
  116             }
  117         }
  118 
  119         if (flg != 2) { /* PageSize or nothing is marked, use PageSize */
  120             option = ppdFindOption(printerPPD, "PageSize");
  121             for (i1 = option->num_choices, choice = option->choices;
  122                  i1 > 0; i1--, choice++) {
  123                 mediaSize =
  124                     g_list_append(mediaSize,
  125                           str2str(choice->text));
  126                 if (choice->marked)
  127                     MediaSizeSelected =
  128                         option->num_choices - i1;
  129             }
  130             gtk_combo_set_popdown_strings(GTK_COMBO
  131                               (printerMediaSizeCombo),
  132                               mediaSize);
  133             gtk_list_select_item(GTK_LIST
  134                          (GTK_COMBO(printerMediaSizeCombo)->
  135                           list), MediaSizeSelected);
  136             gtk_entry_set_position(GTK_ENTRY
  137                            (GTK_COMBO
  138                         (printerMediaSizeCombo)->entry),
  139                            0);
  140             gtk_widget_show(MediaSizeFrame);
  141         } else {
  142             if (flg == 2) { /* PageRegion marked, PageSize not */
  143                 option =
  144                     ppdFindOption(printerPPD, "PageRegion");
  145                 for (i1 = option->num_choices, choice =
  146                      option->choices; i1 > 0; i1--, choice++) {
  147                     mediaSize =
  148                         g_list_append(mediaSize,
  149                               str2str(choice->
  150                                   text));
  151                     if (choice->marked)
  152                         MediaSizeSelected =
  153                             option->num_choices - i1;
  154                 }
  155                 gtk_combo_set_popdown_strings(GTK_COMBO
  156                                   (printerMediaSizeCombo),
  157                                   mediaSize);
  158                 gtk_list_select_item(GTK_LIST
  159                              (GTK_COMBO
  160                               (printerMediaSizeCombo)->
  161                               list), MediaSizeSelected);
  162                 gtk_entry_set_position(GTK_ENTRY
  163                                (GTK_COMBO
  164                             (printerMediaSizeCombo)->
  165                             entry), 0);
  166                 gtk_widget_show(MediaSizeFrame);
  167             } else {    /* We dont have PageSize and we dont have PageRegion, broken PPD! */
  168                 gtk_widget_hide(MediaSizeFrame);
  169             }
  170         }
  171         if ((option = ppdFindOption(printerPPD, "MediaType")) != NULL) {
  172             for (i1 = option->num_choices, choice = option->choices;
  173                  i1 > 0; i1--, choice++) {
  174                 mediaType =
  175                     g_list_append(mediaType,
  176                           str2str(choice->text));
  177                 if (choice->marked)
  178                     MediaTypeSelected =
  179                         option->num_choices - i1;
  180             }
  181             gtk_combo_set_popdown_strings(GTK_COMBO
  182                               (printerMediaTypeCombo),
  183                               mediaType);
  184             gtk_list_select_item(GTK_LIST
  185                          (GTK_COMBO(printerMediaTypeCombo)->
  186                           list), MediaTypeSelected);
  187             gtk_entry_set_position(GTK_ENTRY
  188                            (GTK_COMBO
  189                         (printerMediaTypeCombo)->entry),
  190                            0);
  191             gtk_widget_show(MediaTypeFrame);
  192         } else {
  193             gtk_widget_hide(MediaTypeFrame);
  194         }
  195         if ((option = ppdFindOption(printerPPD, "InputSlot")) != NULL) {
  196             for (i1 = option->num_choices, choice = option->choices;
  197                  i1 > 0; i1--, choice++) {
  198                 mediaSource =
  199                     g_list_append(mediaSource,
  200                           str2str(choice->text));
  201                 if (choice->marked)
  202                     MediaSourceSelected =
  203                         option->num_choices - i1;
  204             }
  205             gtk_combo_set_popdown_strings(GTK_COMBO
  206                               (printerMediaSourceCombo),
  207                               mediaSource);
  208             gtk_list_select_item(GTK_LIST
  209                          (GTK_COMBO
  210                           (printerMediaSourceCombo)->list),
  211                          MediaSourceSelected);
  212             gtk_entry_set_position(GTK_ENTRY
  213                            (GTK_COMBO
  214                         (printerMediaSourceCombo)->
  215                         entry), 0);
  216             gtk_widget_show(MediaSourceFrame);
  217         } else {
  218             gtk_widget_hide(MediaSourceFrame);
  219         }
  220     }
  221 
  222     /* Custom Media Type */
  223     customSizeFieldUnit = g_list_append(customSizeFieldUnit, str2str("pt"));
  224     customSizeFieldUnit = g_list_append(customSizeFieldUnit, str2str("in"));
  225     customSizeFieldUnit = g_list_append(customSizeFieldUnit, str2str("cm"));
  226     customSizeFieldUnit = g_list_append(customSizeFieldUnit, str2str("mm"));
  227     gtk_combo_set_popdown_strings(GTK_COMBO(customSizeCombo),
  228                       customSizeFieldUnit);
  229 
  230     /* Duplex */
  231     if ((option = ppdFindOption(printerPPD, "Duplex")) == NULL) {
  232         gtk_widget_hide(printerDuplexFrame);
  233     } else {
  234         choice = ppdFindChoice(option, "None");
  235         if (choice != NULL) {
  236             if (choice->marked) {
  237                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  238                                  (g_slist_nth_data
  239                                   (DuplexButtons,
  240                                    2)), TRUE);
  241             } else {
  242                 choice =
  243                     ppdFindChoice(option, "DuplexNoTumble");
  244                 if (choice != NULL) {
  245                     if (choice->marked) {
  246                         gtk_toggle_button_set_active
  247                             (GTK_TOGGLE_BUTTON
  248                              (g_slist_nth_data
  249                               (DuplexButtons, 1)),
  250                              TRUE);
  251                     } else {
  252                         choice =
  253                             ppdFindChoice(option,
  254                                   "DuplexTumble");
  255                         if (choice != NULL) {
  256                             if (choice->marked)
  257                                 gtk_toggle_button_set_active
  258                                     (GTK_TOGGLE_BUTTON
  259                                      (g_slist_nth_data
  260                                       (DuplexButtons,
  261                                        0)),
  262                                      TRUE);
  263                         }
  264                     }
  265                 }
  266             }
  267         }
  268         gtk_widget_show(printerDuplexFrame);
  269     }
  270 }
  271 
  272 void NumOfCopiesChanged(GtkWidget * widget, gpointer data)
  273 {
  274 #if GTK_MAJOR_VERSION != 1
  275     gtk_spin_button_update(GTK_SPIN_BUTTON(printerNumField));
  276 #endif
  277     NumberOfCopies =
  278         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(printerNumField));
  279     if (DEBUG)
  280         printf("NumberOfCopiesEntry: Value changed: %u\n",
  281                NumberOfCopies);
  282 }
  283 
  284 int customSizeFieldChanged(GtkWidget * widget, gpointer data)
  285 {
  286     char *z1, *z2;
  287     char *text;
  288     int haserror = 0;
  289     int countdigit = 0;
  290 
  291     text = (char *)gtk_entry_get_text(GTK_ENTRY(widget));
  292     z1 = text;
  293     while (*z1 != (uintptr_t) NULL) {
  294         if (*z1 == '.') {
  295             countdigit++;
  296         }
  297         if ((!isdigit(*z1) && *z1 != '.') || countdigit > 1) {
  298             if (*z1 == '.') {
  299                 countdigit--;
  300             }
  301             haserror = 1;
  302             z2 = z1;
  303             while (*z2 != (uintptr_t) NULL) {
  304                 *z2 = *(z2 + 1);
  305                 z2++;
  306             }
  307         }
  308         z1++;
  309     }
  310     z1 = text;
  311     if (*z1 == (uintptr_t) NULL) {
  312         *z1++ = '0';
  313         *z1 = (uintptr_t) NULL;
  314     }
  315     if (haserror == 1) {
  316         gtk_entry_set_text(GTK_ENTRY(widget), text);
  317         gtk_widget_grab_focus(GTK_WIDGET(widget));
  318     }
  319 
  320     return (FALSE);
  321 }
  322 
  323 void wantCollateCheck(GtkWidget * widget, gpointer data)
  324 {
  325     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(collateCheck))) {
  326         collate = 0;
  327     } else {
  328         collate = 1;
  329     }
  330     if (DEBUG)
  331         printf("collate changed: %u\n", collate);
  332 }
  333 
  334 void PrinterChanged(GtkWidget * widget, gpointer data)
  335 {
  336     int i1, strangeerrortrap, ret, merkconflict;
  337     char tmp[DEF_PRN_LEN + 1];
  338 
  339     snprintf(tmp, (size_t) DEF_PRN_LEN, "%s",
  340          gtk_entry_get_text(GTK_ENTRY
  341                     (GTK_COMBO(printerFrameCombo)->entry)));
  342 
  343     if (DEBUG)
  344         printf("Printer changed: %s\n", (char *)tmp);
  345 
  346     if (tmp[0] == (uintptr_t) NULL) {
  347         if (DEBUG)
  348             printf("Skipping emptry selection !\n");
  349         return;
  350     }
  351     if (!strcmp(tmp, "-----")) {
  352         gtk_entry_set_text(GTK_ENTRY
  353                    (GTK_COMBO(printerFrameCombo)->entry),
  354                    PrinterNames[PrinterChoice]);
  355         return;
  356     }
  357 
  358     merkconflict = conflict_active;
  359     conflict_active = 0;
  360     i1 = 0;
  361     strangeerrortrap = 0;
  362     do {
  363         if (strcmp(str2str(PrinterNames[i1]), tmp) == 0) {
  364             lastPrinterChoice = PrinterChoice;
  365             PrinterChoice = i1;
  366             strangeerrortrap = 1;
  367         }
  368         i1++;
  369     }
  370     while (PrinterNames[i1][0] != (uintptr_t) NULL);
  371 
  372     if (strangeerrortrap == 0) {
  373         if (DEBUG)
  374             printf("Damned Combo-Box-Error !\n");
  375         emergency();
  376     }
  377 
  378     hasAskedPWD = 0;
  379     getBannerList(tmp);
  380     getOptions(tmp, -1);    /* Get PrinterOptions without PPD-Opts to have an password if saved. */
  381     ret = getPPDOpts(tmp);
  382     if (ret == -2) {    /* Not Authorized */
  383         gtk_entry_set_text(GTK_ENTRY
  384                    (GTK_COMBO(printerFrameCombo)->entry),
  385                    PrinterNames[lastPrinterChoice]);
  386     } else if (ret == 0) {  /* OK, printer has ppd */
  387         getOptions(tmp, 0);
  388         gtk_widget_hide(tabs);
  389         setDefaults();
  390         gtk_widget_show(tabs);
  391     }
  392     conflict_active = merkconflict;
  393     if (printerPPD != NULL)
  394         constraints(ppdConflicts(printerPPD));
  395 }
  396 
  397 void DuplexChanged(GtkWidget * widget, gpointer data)
  398 {
  399     if (DEBUG)
  400         printf("Duplex toggled: %s\n", (char *)data);
  401 
  402     if (gtk_toggle_button_get_active
  403         (GTK_TOGGLE_BUTTON(g_slist_nth_data(DuplexButtons, 2)))) {
  404         if (strcmp((char *)data, "Button1") != 0)
  405             return;
  406         if (DEBUG)
  407             printf("No Duplex\n");
  408         constraints(ppdMarkOption(printerPPD, "Duplex", "None"));
  409         return;
  410     } else
  411         if (gtk_toggle_button_get_active
  412         (GTK_TOGGLE_BUTTON(g_slist_nth_data(DuplexButtons, 1)))) {
  413         if (DEBUG)
  414             printf("Duplex long edge binding\n");
  415         if (strcmp((char *)data, "Button2") != 0)
  416             return;
  417         constraints(ppdMarkOption
  418                 (printerPPD, "Duplex", "DuplexNoTumble"));
  419         return;
  420     } else
  421         if (gtk_toggle_button_get_active
  422         (GTK_TOGGLE_BUTTON(g_slist_nth_data(DuplexButtons, 0)))) {
  423         if (DEBUG)
  424             printf("Duplex short edge binding\n");
  425         if (strcmp((char *)data, "Button3") != 0)
  426             return;
  427         constraints(ppdMarkOption
  428                 (printerPPD, "Duplex", "DuplexTumble"));
  429         return;
  430     } else {
  431         if (DEBUG)
  432             printf("PROG-ERROR: Whats that for an Duplex mode ?\n");
  433         emergency();
  434     }
  435 }
  436 
  437 void PrinterDuplex(GtkWidget * container)
  438 {
  439 #include "duplex_none.xpm"
  440 #include "duplex_long.xpm"
  441 #include "duplex_short.xpm"
  442     GtkWidget *mainHBox, *vbox, *hbox;
  443     GtkWidget *button1, *button2, *button3;
  444     GtkWidget *lbox1, *lbox2, *lbox3;
  445     GtkWidget *pmw1, *pmw2, *pmw3;
  446     GdkPixmap *pm1, *pm2, *pm3;
  447     GdkBitmap *mask1, *mask2, *mask3;
  448     GtkStyle *style;
  449 
  450     mainHBox = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  451     gtk_box_pack_start(GTK_BOX(container), mainHBox, FALSE, FALSE,
  452                FRAME_SPACING_V);
  453     gtk_widget_show(mainHBox);
  454 
  455     printerDuplexFrame = gtk_frame_new(str2str(_("Duplex Settings")));
  456     gtk_box_pack_start(GTK_BOX(mainHBox), printerDuplexFrame, TRUE, TRUE,
  457                FRAME_SPACING_V);
  458 
  459     /* Box */
  460     hbox = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  461     gtk_container_add(GTK_CONTAINER(printerDuplexFrame), hbox);
  462     gtk_widget_show(hbox);
  463 
  464     vbox = gtk_vbox_new(FALSE, INFRAME_SPACING_V);
  465     gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
  466     gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE,
  467                INFRAME_SPACING_H);
  468     gtk_widget_show(vbox);
  469 
  470     /* CheckBoxes */
  471     lbox1 = gtk_hbox_new(FALSE, 0);
  472     style = gtk_widget_get_style(vbox);
  473     pm1 = gdk_pixmap_create_from_xpm_d(vbox->window, &mask1,
  474                        &style->bg[GTK_STATE_NORMAL],
  475                        duplex_none_xpm);
  476     pmw1 = gtk_pixmap_new(pm1, mask1);
  477     button1 =
  478         gtk_radio_button_new_with_label(DuplexButtons,
  479                         str2str(_("No Duplex")));
  480     gtk_box_pack_start(GTK_BOX(lbox1), pmw1, FALSE, FALSE, 3);
  481     gtk_box_pack_start(GTK_BOX(lbox1), button1, FALSE, FALSE, 3);
  482     gtk_widget_show(pmw1);
  483     gtk_box_pack_start(GTK_BOX(vbox), lbox1, FALSE, FALSE, 0);
  484     DuplexButtons = gtk_radio_button_group(GTK_RADIO_BUTTON(button1));
  485     gtk_widget_show(button1);
  486     gtk_widget_show(lbox1);
  487 
  488     lbox2 = gtk_hbox_new(FALSE, 0);
  489     style = gtk_widget_get_style(vbox);
  490     pm2 = gdk_pixmap_create_from_xpm_d(vbox->window, &mask2,
  491                        &style->bg[GTK_STATE_NORMAL],
  492                        duplex_long_xpm);
  493     pmw2 = gtk_pixmap_new(pm2, mask2);
  494     button2 =
  495         gtk_radio_button_new_with_label(DuplexButtons,
  496                         str2str(_("Long edge binding")));
  497     gtk_box_pack_start(GTK_BOX(lbox2), pmw2, FALSE, FALSE, 3);
  498     gtk_box_pack_start(GTK_BOX(lbox2), button2, FALSE, FALSE, 3);
  499     gtk_widget_show(pmw2);
  500     gtk_box_pack_start(GTK_BOX(vbox), lbox2, FALSE, FALSE, 0);
  501     DuplexButtons = gtk_radio_button_group(GTK_RADIO_BUTTON(button2));
  502     gtk_widget_show(button2);
  503     gtk_widget_show(lbox2);
  504 
  505     lbox3 = gtk_hbox_new(FALSE, 0);
  506     style = gtk_widget_get_style(vbox);
  507     pm3 = gdk_pixmap_create_from_xpm_d(vbox->window, &mask3,
  508                        &style->bg[GTK_STATE_NORMAL],
  509                        duplex_short_xpm);
  510     pmw3 = gtk_pixmap_new(pm3, mask3);
  511     button3 =
  512         gtk_radio_button_new_with_label(DuplexButtons,
  513                         str2str(_("Short edge binding")));
  514     gtk_box_pack_start(GTK_BOX(lbox3), pmw3, FALSE, FALSE, 3);
  515     gtk_box_pack_start(GTK_BOX(lbox3), button3, FALSE, FALSE, 3);
  516     gtk_widget_show(pmw3);
  517     gtk_box_pack_start(GTK_BOX(vbox), lbox3, FALSE, FALSE, 0);
  518     DuplexButtons = gtk_radio_button_group(GTK_RADIO_BUTTON(button3));
  519     gtk_widget_show(button3);
  520     gtk_widget_show(lbox3);
  521 
  522     gtk_signal_connect(GTK_OBJECT(button1), "toggled",
  523                GTK_SIGNAL_FUNC(DuplexChanged), "Button1");
  524     gtk_signal_connect(GTK_OBJECT(button2), "toggled",
  525                GTK_SIGNAL_FUNC(DuplexChanged), "Button2");
  526     gtk_signal_connect(GTK_OBJECT(button3), "toggled",
  527                GTK_SIGNAL_FUNC(DuplexChanged), "Button3");
  528 
  529 }
  530 
  531 void PrinterMedia(GtkWidget * container)
  532 {
  533     GtkWidget *mainHBox, *vbox;
  534     GtkWidget *labelSize, *labelType, *labelSource, *labelSizeX,
  535         *labelSizeSpacing;
  536 
  537     mainHBox = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  538     gtk_box_pack_start(GTK_BOX(container), mainHBox, FALSE, FALSE,
  539                FRAME_SPACING_V);
  540     gtk_widget_show(mainHBox);
  541 
  542     printerMediaFrame = gtk_frame_new(str2str(_("Media Selections")));
  543     gtk_box_pack_start(GTK_BOX(mainHBox), printerMediaFrame, TRUE, TRUE,
  544                FRAME_SPACING_V);
  545 
  546     /* Box */
  547     vbox = gtk_vbox_new(FALSE, INFRAME_SPACING_V);
  548     gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
  549     gtk_container_add(GTK_CONTAINER(printerMediaFrame), vbox);
  550     gtk_widget_show(vbox);
  551 
  552     /* MediaSize */
  553     MediaSizeFrame = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  554     gtk_container_add(GTK_CONTAINER(vbox), MediaSizeFrame);
  555 
  556     labelSize = gtk_label_new(str2str(_("Media Size")));
  557     gtk_misc_set_alignment(GTK_MISC(labelSize), 0, 0.5);
  558     gtk_widget_set_size_request(GTK_WIDGET(labelSize), MEDIA_FIELDLENGTH,
  559                     -1);
  560     gtk_box_pack_start(GTK_BOX(MediaSizeFrame), labelSize, FALSE, FALSE, 0);
  561     gtk_widget_show(labelSize);
  562 
  563     printerMediaSizeCombo = gtk_combo_new();
  564     gtk_list_set_selection_mode(GTK_LIST
  565                     (GTK_COMBO(printerMediaSizeCombo)->list),
  566                     GTK_SELECTION_SINGLE);
  567     gtk_entry_set_editable(GTK_ENTRY
  568                    (GTK_COMBO(printerMediaSizeCombo)->entry),
  569                    FALSE);
  570     gtk_box_pack_start(GTK_BOX(MediaSizeFrame), printerMediaSizeCombo,
  571                FALSE, FALSE, 0);
  572     gtk_widget_show(printerMediaSizeCombo);
  573 
  574     /* Custom Media Size */
  575     CustomMediaSizeFrame = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  576     gtk_container_add(GTK_CONTAINER(vbox), CustomMediaSizeFrame);
  577 
  578     labelSizeSpacing = gtk_label_new("");
  579     gtk_misc_set_alignment(GTK_MISC(labelSizeSpacing), 0, 0.5);
  580     gtk_widget_set_size_request(GTK_WIDGET(labelSizeSpacing),
  581                     MEDIA_FIELDLENGTH, -1);
  582     gtk_box_pack_start(GTK_BOX(CustomMediaSizeFrame), labelSizeSpacing,
  583                FALSE, FALSE, 0);
  584     gtk_widget_show(labelSizeSpacing);
  585 
  586     customSizeFieldX =
  587         gtk_entry_new_with_max_length(MAX_CUSTOM_SIZE_LENGTH);
  588     gtk_widget_set_size_request(customSizeFieldX,
  589                     MAX_CUSTOM_SIZE_FIELD_LENGTH, -1);
  590     gtk_entry_set_text(GTK_ENTRY(customSizeFieldX), "");
  591     gtk_box_pack_start(GTK_BOX(CustomMediaSizeFrame), customSizeFieldX,
  592                FALSE, FALSE, 0);
  593     gtk_widget_show(customSizeFieldX);
  594 
  595     labelSizeX = gtk_label_new(str2str("x"));
  596     gtk_box_pack_start(GTK_BOX(CustomMediaSizeFrame), labelSizeX, FALSE,
  597                FALSE, 0);
  598     gtk_widget_show(labelSizeX);
  599 
  600     customSizeFieldY =
  601         gtk_entry_new_with_max_length(MAX_CUSTOM_SIZE_LENGTH);
  602     gtk_widget_set_size_request(customSizeFieldY,
  603                     MAX_CUSTOM_SIZE_FIELD_LENGTH, -1);
  604     gtk_entry_set_text(GTK_ENTRY(customSizeFieldY), "");
  605     gtk_box_pack_start(GTK_BOX(CustomMediaSizeFrame), customSizeFieldY,
  606                FALSE, FALSE, 0);
  607     gtk_widget_show(customSizeFieldY);
  608 
  609     customSizeCombo = gtk_combo_new();
  610     gtk_list_set_selection_mode(GTK_LIST(GTK_COMBO(customSizeCombo)->list),
  611                     GTK_SELECTION_SINGLE);
  612     gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(customSizeCombo)->entry),
  613                    FALSE);
  614     gtk_box_pack_start(GTK_BOX(CustomMediaSizeFrame), customSizeCombo,
  615                FALSE, FALSE, 0);
  616     gtk_widget_set_size_request(GTK_WIDGET(customSizeCombo), 60, -1);
  617     gtk_widget_show(customSizeCombo);
  618 
  619     /* Signals */
  620     gtk_signal_connect(GTK_OBJECT(GTK_ENTRY(customSizeFieldX)),
  621                "focus-out-event",
  622                GTK_SIGNAL_FUNC(customSizeFieldChanged), NULL);
  623     gtk_signal_connect(GTK_OBJECT(GTK_ENTRY(customSizeFieldY)),
  624                "focus-out-event",
  625                GTK_SIGNAL_FUNC(customSizeFieldChanged), NULL);
  626 
  627     /* MediaType */
  628     MediaTypeFrame = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  629     gtk_container_add(GTK_CONTAINER(vbox), MediaTypeFrame);
  630 
  631     labelType = gtk_label_new(str2str(_("Media Type")));
  632     gtk_misc_set_alignment(GTK_MISC(labelType), 0, 0.5);
  633     gtk_widget_set_size_request(GTK_WIDGET(labelType), MEDIA_FIELDLENGTH,
  634                     -1);
  635     gtk_box_pack_start(GTK_BOX(MediaTypeFrame), labelType, FALSE, FALSE, 0);
  636     gtk_widget_show(labelType);
  637 
  638     printerMediaTypeCombo = gtk_combo_new();
  639     gtk_list_set_selection_mode(GTK_LIST
  640                     (GTK_COMBO(printerMediaTypeCombo)->list),
  641                     GTK_SELECTION_SINGLE);
  642     gtk_entry_set_editable(GTK_ENTRY
  643                    (GTK_COMBO(printerMediaTypeCombo)->entry),
  644                    FALSE);
  645     gtk_box_pack_start(GTK_BOX(MediaTypeFrame), printerMediaTypeCombo,
  646                FALSE, FALSE, 0);
  647     gtk_widget_show(printerMediaTypeCombo);
  648 
  649     /* MediaSource */
  650     MediaSourceFrame = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  651     gtk_container_add(GTK_CONTAINER(vbox), MediaSourceFrame);
  652 
  653     labelSource = gtk_label_new(str2str(_("Media Source")));
  654     gtk_misc_set_alignment(GTK_MISC(labelSource), 0, 0.5);
  655     gtk_widget_set_size_request(GTK_WIDGET(labelSource), MEDIA_FIELDLENGTH,
  656                     -1);
  657     gtk_box_pack_start(GTK_BOX(MediaSourceFrame), labelSource, FALSE, FALSE,
  658                0);
  659     gtk_widget_show(labelSource);
  660 
  661     printerMediaSourceCombo = gtk_combo_new();
  662     gtk_list_set_selection_mode(GTK_LIST
  663                     (GTK_COMBO(printerMediaSourceCombo)->list),
  664                     GTK_SELECTION_SINGLE);
  665     gtk_entry_set_editable(GTK_ENTRY
  666                    (GTK_COMBO(printerMediaSourceCombo)->entry),
  667                    FALSE);
  668     gtk_box_pack_start(GTK_BOX(MediaSourceFrame), printerMediaSourceCombo,
  669                FALSE, FALSE, 0);
  670     gtk_widget_show(printerMediaSourceCombo);
  671 
  672 #if GTK_MAJOR_VERSION == 1
  673     gtk_signal_connect(GTK_OBJECT(GTK_COMBO(printerMediaSizeCombo)->entry),
  674                "changed", PPD_DropDown_changed, "PageSize");
  675     gtk_signal_connect(GTK_OBJECT(GTK_COMBO(printerMediaTypeCombo)->entry),
  676                "changed", PPD_DropDown_changed, "MediaType");
  677     gtk_signal_connect(GTK_OBJECT
  678                (GTK_COMBO(printerMediaSourceCombo)->entry),
  679                "changed", PPD_DropDown_changed, "InputSlot");
  680 #else
  681     gtk_signal_connect(GTK_OBJECT(GTK_COMBO(printerMediaSizeCombo)->entry),
  682                "changed", GTK_SIGNAL_FUNC(PPD_DropDown_changed),
  683                "PageSize");
  684     gtk_signal_connect(GTK_OBJECT(GTK_COMBO(printerMediaTypeCombo)->entry),
  685                "changed", GTK_SIGNAL_FUNC(PPD_DropDown_changed),
  686                "MediaType");
  687     gtk_signal_connect(GTK_OBJECT
  688                (GTK_COMBO(printerMediaSourceCombo)->entry),
  689                "changed", GTK_SIGNAL_FUNC(PPD_DropDown_changed),
  690                "InputSlot");
  691 #endif
  692 
  693 }
  694 
  695 void PrinterNumCopies(GtkWidget * container)
  696 {
  697     GtkWidget *mainHBox, *hbox;
  698     GtkObject *adjust;
  699 
  700     mainHBox = gtk_hbox_new(FALSE, 0);
  701     gtk_box_pack_start(GTK_BOX(container), mainHBox, FALSE, FALSE, 0);
  702     gtk_widget_show(mainHBox);
  703 
  704     printerNumCopiesFrame = gtk_frame_new(str2str(_("Number of Copies")));
  705     gtk_box_pack_start(GTK_BOX(mainHBox), printerNumCopiesFrame, TRUE, TRUE,
  706                FRAME_SPACING_V);
  707 
  708     /* Box */
  709     hbox = gtk_hbox_new(FALSE, 0);
  710     gtk_container_set_border_width(GTK_CONTAINER(hbox), INFRAME_SPACING_H);
  711     gtk_container_add(GTK_CONTAINER(printerNumCopiesFrame), hbox);
  712     gtk_widget_show(hbox);
  713 
  714     /* Spinbutton */
  715     //adjust = gtk_adjustment_new (1.0, 1.0, 999, 1.0, 1.0, 1.0);
  716     adjust = gtk_adjustment_new(1.0, 1.0, 999, 1.0, 1.0, 0);
  717     printerNumField = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1.0, 0);
  718     gtk_widget_set_size_request(printerNumField, 3 * 16, -1);
  719     gtk_box_pack_start(GTK_BOX(hbox), printerNumField, FALSE, FALSE, 0);
  720     gtk_widget_show(printerNumField);
  721 
  722     /* collate Check */
  723     collateCheck =
  724         gtk_check_button_new_with_label(str2str(_("Collate Copies")));
  725     gtk_box_pack_end(GTK_BOX(hbox), collateCheck, FALSE, FALSE, 0);
  726     gtk_widget_show(collateCheck);
  727 
  728     /* Signals */
  729 #if GTK_MAJOR_VERSION == 1
  730     gtk_signal_connect(GTK_OBJECT(GTK_SPIN_BUTTON(printerNumField)),
  731                "changed", GTK_SIGNAL_FUNC(NumOfCopiesChanged),
  732                NULL);
  733 #else
  734     gtk_signal_connect(GTK_OBJECT(GTK_SPIN_BUTTON(printerNumField)),
  735                "value-changed", GTK_SIGNAL_FUNC(NumOfCopiesChanged),
  736                NULL);
  737 #endif
  738     gtk_signal_connect(GTK_OBJECT(collateCheck), "pressed",
  739                GTK_SIGNAL_FUNC(wantCollateCheck), NULL);
  740 
  741     PrinterCallGtklpq(mainHBox);
  742 }
  743 
  744 void callGtkLPQFunc(GtkButton * button, gpointer data)
  745 {
  746     system(GTKLPQCOM);
  747 }
  748 
  749 void recreatePrinterList(void)
  750 {
  751     GList *printerList = NULL;
  752     int i1;
  753 
  754     if (DEBUG)
  755         printf("Recreating printer list\n");
  756     for (i1 = 0; PrinterFavNames[i1][0] != (uintptr_t) NULL; i1++) {
  757         if (DEBUG)
  758             printf("Adding favorite %s to printer list\n",
  759                    PrinterFavNames[i1]);
  760         printerList =
  761             g_list_append(printerList, str2str(PrinterFavNames[i1]));
  762     }
  763     if (PrinterFavNames[0][0] != (uintptr_t) NULL)
  764         printerList = g_list_append(printerList, "-----");
  765     for (i1 = 0; i1 <= PrinterNum; i1++) {
  766         printerList =
  767             g_list_append(printerList, str2str(PrinterNames[i1]));
  768     }
  769     gtk_combo_set_popdown_strings(GTK_COMBO(printerFrameCombo),
  770                       printerList);
  771 }
  772 
  773 void loadFavorites(void)
  774 {
  775     char *home;
  776 
  777     /* load */
  778     home = getenv("HOME");
  779     if (home) {
  780         FILE *file = NULL;
  781         char filepath[MAXPATH + 1];
  782 
  783         snprintf(filepath, (size_t) MAXPATH, "%s/favorites", confdir);
  784         if (PrinterFavNames[0][0] != (uintptr_t) NULL)
  785             memset(PrinterFavNames, 0, sizeof(PrinterFavNames));
  786         if (DEBUG)
  787             printf("Load favorites from %s\n", filepath);
  788         file = fopen(filepath, "r");
  789         if (file) {
  790             int i1 = 0;
  791             while (fscanf(file, "%s", PrinterFavNames[i1]) > 0) {
  792                 if (DEBUG)
  793                     printf("%u: %s\n", i1,
  794                            PrinterFavNames[i1]);
  795                 i1++;
  796             }
  797             fclose(file);
  798             if (DEBUG)
  799                 printf("%u Favorites loaded.\n", i1);
  800             checkFavorites();
  801         } else {
  802             if (DEBUG)
  803                 printf("Could not open favorites file\n");
  804         }
  805     }
  806 }
  807 
  808 void saveFavorites(void)
  809 {
  810     char *home;
  811 
  812     /* save */
  813     home = getenv("HOME");
  814     if (home) {
  815         FILE *file = NULL;
  816         char filepath[MAXPATH + 1];
  817 
  818         snprintf(filepath, (size_t) MAXPATH, "%s/favorites", confdir);
  819         if (DEBUG)
  820             printf("Favorites now:\n");
  821         if (PrinterFavNames[0][0] != (uintptr_t) NULL) {
  822             int i1;
  823 
  824             if (DEBUG)
  825                 printf("Save to %s\n", filepath);
  826             file = fopen(filepath, "w");
  827             i1 = 0;
  828             while (PrinterFavNames[i1][0] != (uintptr_t) NULL) {
  829                 if (DEBUG)
  830                     printf("%u: %s\n", i1,
  831                            PrinterFavNames[i1]);
  832                 if (file)
  833                     fprintf(file, "%s\n",
  834                         PrinterFavNames[i1]);
  835                 i1++;
  836             }
  837             if (file)
  838                 fclose(file);
  839         } else {
  840             if (DEBUG)
  841                 printf("Delete %s\n", filepath);
  842             unlink(filepath);
  843         }
  844     }
  845 }
  846 
  847 void callAddFavFunc(GtkButton * button, gpointer data)
  848 {
  849     int found;
  850     int i1;
  851     char tmp[DEF_PRN_LEN + 1];
  852 
  853     snprintf(tmp, (size_t) DEF_PRN_LEN, "%s",
  854          gtk_entry_get_text(GTK_ENTRY
  855                     (GTK_COMBO(printerFrameCombo)->entry)));
  856     /* Add to favorites, if not yet there */
  857     i1 = 0;
  858     found = 0;
  859     while (PrinterFavNames[i1][0] != (uintptr_t) NULL) {
  860         if (strcmp(tmp, str2str(PrinterFavNames[i1])) == 0) {
  861             if (DEBUG)
  862                 printf("Printer %s already in favorites\n",
  863                        tmp);
  864             found = 1;
  865             break;
  866         }
  867         i1++;
  868     }
  869     if (!found && (i1 < MAX_PRT)) {
  870         strcpy(PrinterFavNames[i1], tmp);
  871         if (DEBUG)
  872             printf("Printer %s added to favorites\n", tmp);
  873         recreatePrinterList();
  874         saveFavorites();
  875     }
  876 }
  877 
  878 void callRmFavFunc(GtkButton * button, gpointer data)
  879 {
  880     int found;
  881     int i1;
  882     char tmp[DEF_PRN_LEN + 1];
  883 
  884     snprintf(tmp, (size_t) DEF_PRN_LEN, "%s",
  885          gtk_entry_get_text(GTK_ENTRY
  886                     (GTK_COMBO(printerFrameCombo)->entry)));
  887     /* Remove from favorites, if there */
  888     i1 = 0;
  889     found = 0;
  890     while (PrinterFavNames[i1][0] != (uintptr_t) NULL) {
  891         if (strcmp(tmp, str2str(PrinterFavNames[i1])) == 0) {
  892             found = 1;
  893             break;
  894         }
  895         i1++;
  896     }
  897     if (found) {
  898         /* find last entry and move here */
  899         unsigned i2;
  900 
  901         if (DEBUG)
  902             printf("Remove %s from favorites\n",
  903                    PrinterFavNames[i1]);
  904         i2 = i1 + 1;
  905         while (PrinterFavNames[i2][0])
  906             i2++;
  907         i2--;
  908         if (i2 != i1) {
  909             strcpy(PrinterFavNames[i1], PrinterFavNames[i2]);
  910         }
  911         PrinterFavNames[i2][0] = 0;
  912         recreatePrinterList();
  913         saveFavorites();
  914     } else {
  915         if (DEBUG)
  916             printf("Printer %s not in favorites\n", tmp);
  917     }
  918 }
  919 
  920 void PrinterCallGtklpq(GtkWidget * container)
  921 {
  922     GtkWidget *hbox, *gtklpqbutton;
  923 
  924     gtklpqFrame = gtk_frame_new(str2str(_("Other actions")));
  925     gtk_box_pack_end(GTK_BOX(container), gtklpqFrame, TRUE, TRUE,
  926              FRAME_SPACING_V);
  927 
  928     /* Box */
  929     hbox = gtk_hbox_new(FALSE, 0);
  930     gtk_container_set_border_width(GTK_CONTAINER(hbox), INFRAME_SPACING_H);
  931     gtk_container_add(GTK_CONTAINER(gtklpqFrame), hbox);
  932     gtk_widget_show(hbox);
  933 
  934     /* Button */
  935     gtklpqbutton = gtk_button_new_with_label(str2str(_("Call GtkLPQ")));
  936     gtk_box_pack_start(GTK_BOX(hbox), gtklpqbutton, FALSE, TRUE, 0);
  937     gtk_widget_show(gtklpqbutton);
  938     gtk_signal_connect(GTK_OBJECT(GTK_BUTTON(gtklpqbutton)), "clicked",
  939                GTK_SIGNAL_FUNC(callGtkLPQFunc), NULL);
  940 
  941 }
  942 
  943 void PrinterFrame(GtkWidget * container)
  944 {
  945     GtkWidget *mainHBox, *hbox, *vbox, *vboxp, *hboxfav, *addfavbutton,
  946         *rmfavbutton;
  947 
  948     loadFavorites();
  949 
  950     mainHBox = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  951     gtk_box_pack_start(GTK_BOX(container), mainHBox, FALSE, FALSE,
  952                FRAME_SPACING_V);
  953     gtk_widget_show(mainHBox);
  954 
  955     printerFrame = gtk_frame_new(str2str(_("Printer")));
  956     gtk_box_pack_start(GTK_BOX(mainHBox), printerFrame, TRUE, TRUE,
  957                FRAME_SPACING_V);
  958 
  959     /* Printer Box */
  960     hbox = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  961     gtk_container_set_border_width(GTK_CONTAINER(hbox), VBOX_BORDER);
  962     gtk_container_add(GTK_CONTAINER(printerFrame), hbox);
  963     gtk_widget_show(hbox);
  964 
  965     /* Printer select vbox */
  966     vboxp = gtk_vbox_new(FALSE, 0);
  967     gtk_box_set_spacing(GTK_BOX(vboxp), 0);
  968     gtk_box_pack_start(GTK_BOX(hbox), vboxp, FALSE, FALSE, 0);
  969     gtk_widget_show(vboxp);
  970 
  971     printerFrameCombo = gtk_combo_new();
  972 
  973     recreatePrinterList();
  974     gtk_combo_set_value_in_list(GTK_COMBO(printerFrameCombo), TRUE, FALSE);
  975     gtk_list_set_selection_mode(GTK_LIST
  976                     (GTK_COMBO(printerFrameCombo)->list),
  977                     GTK_SELECTION_SINGLE);
  978 
  979     gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(printerFrameCombo)->entry),
  980                    FALSE);
  981     gtk_box_pack_start(GTK_BOX(vboxp), printerFrameCombo, FALSE, FALSE, 0);
  982     gtk_widget_show(printerFrameCombo);
  983 
  984     /* Favorites hbox */
  985     hboxfav = gtk_hbox_new(FALSE, INFRAME_SPACING_H);
  986     gtk_box_pack_end(GTK_BOX(vboxp), hboxfav, FALSE, FALSE, 0);
  987     gtk_widget_show(hboxfav);
  988     /* Add Favorites Button */
  989     addfavbutton = gtk_button_new_with_label(str2str(_("Add favorite")));
  990     gtk_box_pack_start(GTK_BOX(hboxfav), addfavbutton, FALSE, TRUE, 0);
  991     gtk_widget_show(addfavbutton);
  992     gtk_signal_connect(GTK_OBJECT(GTK_BUTTON(addfavbutton)), "clicked",
  993                GTK_SIGNAL_FUNC(callAddFavFunc), NULL);
  994 
  995     /* Remove Favorites Button */
  996     rmfavbutton = gtk_button_new_with_label(str2str(_("Remove favorite")));
  997     gtk_box_pack_end(GTK_BOX(hboxfav), rmfavbutton, FALSE, TRUE, 0);
  998     gtk_widget_show(rmfavbutton);
  999     gtk_signal_connect(GTK_OBJECT(GTK_BUTTON(rmfavbutton)), "clicked",
 1000                GTK_SIGNAL_FUNC(callRmFavFunc), NULL);
 1001 
 1002     /* InfoBoxen */
 1003     vbox = gtk_vbox_new(FALSE, 0);
 1004     gtk_box_set_spacing(GTK_BOX(vbox), 0);
 1005     gtk_box_pack_end(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
 1006     gtk_widget_show(vbox);
 1007 
 1008     /* Information */
 1009     printerFrameInfoText = gtk_label_new("");
 1010     gtk_label_set_line_wrap(GTK_LABEL(printerFrameInfoText), TRUE);
 1011     gtk_label_set_justify(GTK_LABEL(printerFrameInfoText),
 1012                   GTK_JUSTIFY_LEFT);
 1013     gtk_widget_set_size_request(printerFrameInfoText,
 1014                     PRINTER_INFO_FIELD_LENGTH, -1);
 1015     gtk_box_pack_start(GTK_BOX(vbox), printerFrameInfoText, FALSE, FALSE,
 1016                0);
 1017     gtk_widget_show(printerFrameInfoText);
 1018 
 1019     /* Location */
 1020     printerFrameLocationText = gtk_label_new("");
 1021     gtk_label_set_line_wrap(GTK_LABEL(printerFrameLocationText), TRUE);
 1022     gtk_label_set_justify(GTK_LABEL(printerFrameLocationText),
 1023                   GTK_JUSTIFY_LEFT);
 1024     gtk_widget_set_size_request(printerFrameLocationText,
 1025                     PRINTER_INFO_FIELD_LENGTH, -1);
 1026     gtk_box_pack_start(GTK_BOX(vbox), printerFrameLocationText, FALSE,
 1027                FALSE, 0);
 1028     gtk_widget_show(printerFrameLocationText);
 1029 
 1030     /* Signals */
 1031     gtk_signal_connect(GTK_OBJECT(GTK_COMBO(printerFrameCombo)->entry),
 1032                "changed", GTK_SIGNAL_FUNC(PrinterChanged), NULL);
 1033 }
 1034 
 1035 void GeneralTab(void)
 1036 {
 1037     generalTab = gtk_vbox_new(FALSE, 0);
 1038     gtk_container_set_border_width(GTK_CONTAINER(generalTab), FRAME_BORDER);
 1039 
 1040     gtk_notebook_append_page(GTK_NOTEBOOK(tabs), generalTab,
 1041                  gtk_label_new(str2str(_("General"))));
 1042 
 1043     PrinterFrame(generalTab);
 1044     PrinterNumCopies(generalTab);
 1045     PrinterMedia(generalTab);
 1046     PrinterDuplex(generalTab);
 1047 }