/[xlog]/xlog/src/callbacks_otherdialogs.c
ViewVC logotype

Diff of /xlog/src/callbacks_otherdialogs.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by pa4tu, Mon Dec 16 18:15:25 2002 UTC revision 1.2 by pa4tu, Fri Jan 3 00:44:56 2003 UTC
# Line 31  Line 31 
31  #include <libgen.h>  #include <libgen.h>
32  #include <gtk/gtk.h>  #include <gtk/gtk.h>
33    
34  #include "callbacks.h"  #include "callbacks_otherdialogs.h"
35  #include "interface.h"  #include "interface.h"
36  #include "support.h"  #include "support.h"
37  #include "types.h"  #include "types.h"
# Line 43  Line 43 
43    
44  extern GtkWidget *mainwindow;  extern GtkWidget *mainwindow;
45  extern GtkWidget *mainnotebook;  extern GtkWidget *mainnotebook;
 extern gchar *xlogdir;  
46  extern preferencestype preferences;  extern preferencestype preferences;
47  extern statetype state;  extern statetype state;
 extern GtkWidget *printdialog;  
48  extern GtkWidget *b4dialog;  extern GtkWidget *b4dialog;
49  extern GList *searchhistory;  extern GList *searchhistory;
50  extern GList *logwindowlist;  extern GList *logwindowlist;
# Line 105  on_savedialog_delete_event (GtkWidget * Line 103  on_savedialog_delete_event (GtkWidget *
103    return FALSE;    return FALSE;
104  }  }
105    
 /* PRINT DIALOG */  
 void  
 on_printokbutton_clicked (GtkButton * button, gpointer user_data)  
 {  
   GtkWidget *printallradiobutton, *printrangeradiobutton, *printlowentry,  
     *printhighentry, *sizecomboentry, *pointcomboentry,  
     *conteststyleradiobutton, *normalstyleradiobutton,  
     *filedestinationradiobutton, *printerdestinationradiobutton, *endhbox,  
     *qslhbox, *powerhbox, *namehbox, *qthhbox, *locatorhbox, *unknown1hbox,  
     *unknown2hbox, *remarksvbox;  
   gchar *temp, *texpoint, *texorientation, *texsize, *texfile, *printstring =  
     NULL, **item;  
   FILE *fp;  
   gint i, j, k = 0, printhigh, printlow;  
   gboolean printok = FALSE;  
   logtype *logwindow;  
   
   printallradiobutton = lookup_widget (printdialog, "printallradiobutton");  
   printrangeradiobutton =  
     lookup_widget (printdialog, "printrangeradiobutton");  
   printlowentry = lookup_widget (printdialog, "printlowentry");  
   printhighentry = lookup_widget (printdialog, "printhighentry");  
   sizecomboentry = lookup_widget (printdialog, "sizecomboentry");  
   pointcomboentry = lookup_widget (printdialog, "pointcomboentry");  
   filedestinationradiobutton = lookup_widget (printdialog,  
                                               "filedestinationradiobutton");  
   printerdestinationradiobutton = lookup_widget (printdialog,  
                                                  "printerdestinationradiobutton");  
   normalstyleradiobutton =  
     lookup_widget (printdialog, "normalstyleradiobutton");  
   conteststyleradiobutton =  
     lookup_widget (printdialog, "conteststyleradiobutton");  
   
   /* save settings of the print dialog */  
   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (printallradiobutton)))  
     preferences.printall = 0;  
   else  
     preferences.printall = 1;  
   temp = gtk_editable_get_chars (GTK_EDITABLE (printlowentry), 0, -1);  
   printlow = atoi (temp);  
   temp = gtk_editable_get_chars (GTK_EDITABLE (printhighentry), 0, -1);  
   printhigh = atoi (temp);  
   temp = gtk_editable_get_chars (GTK_EDITABLE (sizecomboentry), 0, -1);  
   if (g_strcasecmp (temp, "a4") == 0)  
     preferences.printsize = 0;  
   else  
     preferences.printsize = 1;  
   temp = gtk_editable_get_chars (GTK_EDITABLE (pointcomboentry), 0, -1);  
   if (g_strcasecmp (temp, "10") == 0)  
     preferences.printpoint = 0;  
   else if (g_strcasecmp (temp, "11") == 0)  
     preferences.printpoint = 1;  
   else if (g_strcasecmp (temp, "12") == 0)  
     preferences.printpoint = 2;  
   if (gtk_toggle_button_get_active  
       (GTK_TOGGLE_BUTTON (printerdestinationradiobutton)))  
     preferences.printdestination = 0;  
   else  
     preferences.printdestination = 1;  
   if (gtk_toggle_button_get_active  
       (GTK_TOGGLE_BUTTON (normalstyleradiobutton)))  
     preferences.printstyle = 0;  
   else  
     preferences.printstyle = 1;  
   
   /* tex strings that may differ */  
   if (preferences.printsize == 0)  
     texsize = g_strdup ("a4paper");  
   else  
     texsize = g_strdup ("letterpaper");  
   if (preferences.printstyle == 0)  
     texorientation = g_strdup ("landscape");  
   else  
     texorientation = g_strdup ("portrait");  
   if (preferences.printpoint == 0)  
     texpoint = g_strdup ("10pt");  
   else if (preferences.printpoint == 1)  
     texpoint = g_strdup ("11pt");  
   else  
     texpoint = g_strdup ("12pt");  
   
   logwindow = g_list_nth_data (logwindowlist,  
                                gtk_notebook_get_current_page (GTK_NOTEBOOK  
                                                               (mainnotebook)));  
   gtk_clist_freeze (GTK_CLIST (logwindow->clist));  
   
   item = g_new0 (gchar *, QSO_FIELDS);  
   texfile = g_strconcat (xlogdir, G_DIR_SEPARATOR_S, "log.tex", NULL);  
   fp = fopen (texfile, "w");  
   if (fp)  
     {                           /* widgets which may be visible */  
       endhbox = lookup_widget (mainwindow, "endhbox");  
       qslhbox = lookup_widget (mainwindow, "qslhbox");  
       powerhbox = lookup_widget (mainwindow, "powerhbox");  
       namehbox = lookup_widget (mainwindow, "namehbox");  
       qthhbox = lookup_widget (mainwindow, "qthhbox");  
       locatorhbox = lookup_widget (mainwindow, "locatorhbox");  
       unknown1hbox = lookup_widget (mainwindow, "unknown1hbox");  
       unknown2hbox = lookup_widget (mainwindow, "unknown2hbox");  
       remarksvbox = lookup_widget (mainwindow, "remarksvbox");  
   
       fprintf (fp, "\\documentclass[%s,%s,%s]{article}\n", texsize,  
                texorientation, texpoint);  
       fprintf (fp, "\\pagestyle{empty}\n");  
       fprintf (fp,  
                "\\usepackage[%s,left=15mm,right=15mm,top=10mm,bottom=10mm]{geometry}\n",  
                texsize);  
       fprintf (fp, "\\begin{document}\n");  
       if (preferences.printstyle == 0)  
         {  
           fprintf (fp, "\\begin{tabular}{||l|l|l");     /* nr, date, gmt */  
           if (GTK_WIDGET_VISIBLE (endhbox))  
             fprintf (fp, "|l"); /* gmtend */  
           fprintf (fp, "|l|l|l|l|l");   /* call band mode rst myrst */  
           if (GTK_WIDGET_VISIBLE (qslhbox))  
             fprintf (fp, "|c|c");       /* qslin, qslout */  
           if (GTK_WIDGET_VISIBLE (powerhbox))  
             fprintf (fp, "|l"); /* power */  
           if (GTK_WIDGET_VISIBLE (namehbox))  
             fprintf (fp, "|l"); /* name */  
           if (GTK_WIDGET_VISIBLE (qthhbox))  
             fprintf (fp, "|l"); /* qth */  
           if (GTK_WIDGET_VISIBLE (locatorhbox))  
             fprintf (fp, "|l"); /* locator */  
           if (GTK_WIDGET_VISIBLE (unknown1hbox))  
             fprintf (fp, "|l"); /* unknown1 */  
           if (GTK_WIDGET_VISIBLE (unknown2hbox))  
             fprintf (fp, "|l"); /* unknown2 */  
           if (GTK_WIDGET_VISIBLE (remarksvbox))  
             fprintf (fp, "|l"); /*remarks */  
           fprintf (fp, "||}\n");  
         }  
       else  
         fprintf (fp, "\\begin{tabular}{||l|l|l|l|l|l|l|l||l|l||}\n");  
       fprintf (fp, "\\hline\n");  
       if (preferences.printstyle == 0)  
         {  
           fprintf (fp, "\\textbf{Nr} &\\textbf{Date} &\\textbf{GMT}");  
           if (GTK_WIDGET_VISIBLE (endhbox))  
             fprintf (fp, "&\\textbf{END}");  
           fprintf (fp,  
                    "&\\textbf{Callsign} &\\textbf{MHz} &\\textbf{Mode} &\\textbf{TX} &\\textbf{RX}");  
           if (GTK_WIDGET_VISIBLE (qslhbox))  
             fprintf (fp, "&\\textbf{Out} &\\textbf{In}");  
           if (GTK_WIDGET_VISIBLE (powerhbox))  
             fprintf (fp, "&\\textbf{Pwr}");  
           if (GTK_WIDGET_VISIBLE (namehbox))  
             fprintf (fp, "&\\textbf{Name}");  
           if (GTK_WIDGET_VISIBLE (qthhbox))  
             fprintf (fp, "&\\textbf{QTH}");  
           if (GTK_WIDGET_VISIBLE (locatorhbox))  
             fprintf (fp, "&\\textbf{Locator}");  
           if (GTK_WIDGET_VISIBLE (unknown1hbox))  
             {  
               fprintf (fp, "&\\textbf{");  
               fprintf (fp, preferences.freefield1);  
               fprintf (fp, "}");  
             }  
           if (GTK_WIDGET_VISIBLE (unknown2hbox))  
             {  
               fprintf (fp, "&\\textbf{");  
               fprintf (fp, preferences.freefield2);  
               fprintf (fp, "}");  
             }  
           if (GTK_WIDGET_VISIBLE (remarksvbox))  
             fprintf (fp, "&\\textbf{Remarks}");  
           fprintf (fp, "\\\\\n");  
         }  
       else  
         fprintf (fp,  
                  "\\textbf{Nr} &\\textbf{Date} &\\textbf{GMT} &\\textbf{Callsign} &\\textbf{MHz} &\\textbf{Mode} &\\textbf{TX} &\\textbf{RX} &\\textbf{Multiplier} &\\textbf{Points}\\\\\n");  
       fprintf (fp, "\\hline\n");  
       fprintf (fp, "\\hline\n");  
   
       if (preferences.printall == 0)  
         {  
           printlow = 1;  
           printhigh = logwindow->qsos;  
         }  
   
       if (GTK_CLIST (logwindow->clist)->rows > 0)  
         {  
           for (i = GTK_CLIST (logwindow->clist)->rows - printlow;  
                i >= GTK_CLIST (logwindow->clist)->rows - printhigh; i--)  
             {  
               for (j = 0; j < QSO_FIELDS; j++)  
                 gtk_clist_get_text (GTK_CLIST (logwindow->clist), i, j,  
                                     &item[j]);  
               if (preferences.printstyle == 0)  
                 {  
                   fprintf (fp, "%s&%s&%s", item[NR], item[DATE], item[GMT]);  
                   if (GTK_WIDGET_VISIBLE (endhbox))  
                     fprintf (fp, "&%s", item[GMTEND]);  
                   fprintf (fp, "&\\textbf{%s}&%s&%s&%s&%s",  
                            item[CALL], item[BAND], item[MODE], item[RST],  
                            item[MYRST]);  
                   if (GTK_WIDGET_VISIBLE (qslhbox))  
                     fprintf (fp, "&%s&%s", item[QSLOUT], item[QSLIN]);  
                   if (GTK_WIDGET_VISIBLE (powerhbox))  
                     fprintf (fp, "&%s", item[POWER]);  
                   if (GTK_WIDGET_VISIBLE (namehbox))  
                     fprintf (fp, "&%s", item[NAME]);  
                   if (GTK_WIDGET_VISIBLE (qthhbox))  
                     fprintf (fp, "&%s", item[QTH]);  
                   if (GTK_WIDGET_VISIBLE (locatorhbox))  
                     fprintf (fp, "&%s", item[LOCATOR]);  
                   if (GTK_WIDGET_VISIBLE (unknown1hbox))  
                     fprintf (fp, "&%s", item[U1]);  
                   if (GTK_WIDGET_VISIBLE (unknown2hbox))  
                     fprintf (fp, "&%s", item[U2]);  
                   if (GTK_WIDGET_VISIBLE (remarksvbox))  
                     {           /* escape # for latex, TODO: &, _, %, $, \, {, }, ^ */  
                       if (strstr (item[REMARKS], "#"))  
                         temp = strreplace (item[REMARKS], "#", "\\#");  
                       fprintf (fp, "&%s", temp);  
                     }  
                   fprintf (fp, "\\\\\n");  
                 }  
               else  
                 fprintf (fp, "%d&%s&%s&\\textbf{%s}&%s&%s&%s&%s&~&~\\\\\n",  
                          k + 1, item[DATE], item[GMT], item[CALL], item[BAND],  
                          item[MODE], item[RST], item[MYRST]);  
               k++;  
               if ((k % 30 == 0 && preferences.printstyle == 0  
                    && k != printhigh - printlow + 1) || (k % 50 == 0  
                                                          && preferences.  
                                                          printstyle == 1  
                                                          && k !=  
                                                          printhigh -  
                                                          printlow + 1))  
                 {  
                   fprintf (fp, "\\hline\n");  
                   fprintf (fp, "\\end{tabular}\n");  
                   fprintf (fp, "\\begin{center}\n");  
                   fprintf (fp, "\\emph{Printed by xlog version %s}\n",  
                            VERSION);  
                   fprintf (fp, "\\end{center}\n");  
                   fprintf (fp, "\\newpage\n");  
                   if (preferences.printstyle == 0)  
                     fprintf (fp,  
                              "\\begin{tabular}{||l|l|l|l|l|l|l|l||l|c|c||}\n");  
                   else  
                     fprintf (fp,  
                              "\\begin{tabular}{||l|l|l|l|l|l|l|l||l|l||}\n");  
                   fprintf (fp, "\\hline\n");  
                   if (preferences.printstyle == 0)  
                     {  
                       fprintf (fp,  
                                "\\textbf{Nr} &\\textbf{Date} &\\textbf{GMT}");  
                       if (GTK_WIDGET_VISIBLE (endhbox))  
                         fprintf (fp, "&\\textbf{END}");  
                       fprintf (fp,  
                                "&\\textbf{Callsign} &\\textbf{MHz} &\\textbf{Mode} &\\textbf{TX} &\\textbf{RX}");  
                       if (GTK_WIDGET_VISIBLE (qslhbox))  
                         fprintf (fp, "&\\textbf{Out} &\\textbf{In} ");  
                       if (GTK_WIDGET_VISIBLE (powerhbox))  
                         fprintf (fp, "&\\textbf{Pwr}");  
                       if (GTK_WIDGET_VISIBLE (namehbox))  
                         fprintf (fp, "&\\textbf{Name}");  
                       if (GTK_WIDGET_VISIBLE (qthhbox))  
                         fprintf (fp, "&\\textbf{QTH}");  
                       if (GTK_WIDGET_VISIBLE (locatorhbox))  
                         fprintf (fp, "&\\textbf{Locator}");  
                       if (GTK_WIDGET_VISIBLE (unknown1hbox))  
                         {  
                           fprintf (fp, "&\\textbf{");  
                           fprintf (fp, preferences.freefield1);  
                           fprintf (fp, "}");  
                         }  
                       if (GTK_WIDGET_VISIBLE (unknown2hbox))  
                         {  
                           fprintf (fp, "&\\textbf{");  
                           fprintf (fp, preferences.freefield2);  
                           fprintf (fp, "}");  
                         }  
                       if (GTK_WIDGET_VISIBLE (remarksvbox))  
                         fprintf (fp, "&\\textbf{Remarks}");  
                       fprintf (fp, "\\\\\n");  
                     }  
                   else  
                     fprintf (fp,  
                              "\\textbf{Nr} &\\textbf{Date} &\\textbf{GMT} &\\textbf{Callsign} &\\textbf{MHz} &\\textbf{Mode} &\\textbf{TX} &\\textbf{RX} &\\textbf{Multiplier} &\\textbf{Points}\\\\\n");  
                   fprintf (fp, "\\hline\n");  
                   fprintf (fp, "\\hline\n");  
                 }  
             }  
         }  
   
       fprintf (fp, "\\hline\n");  
       fprintf (fp, "\\end{tabular}\n");  
       fprintf (fp, "\\begin{center}\n");  
       fprintf (fp, "\\emph{Printed by xlog version %s}\n", VERSION);  
       fprintf (fp, "\\end{center}\n");  
       fprintf (fp, "\\end{document}\n");  
       fclose (fp);  
     }  
   
   gtk_clist_thaw (GTK_CLIST (logwindow->clist));  
   g_free (item);  
   
   if ((printok = latexavailable ()) == FALSE)  
     {  
       update_statusbar (_  
                         ("Latex is not available, install the tetex package"));  
     }  
   
   if (printok)  
     {  
       if (preferences.printdestination == 0 && preferences.printstyle == 0)  
         printstring =  
           g_strdup_printf  
           ("cd %s; latex -interaction=nonstopmode log.tex; dvips -t landscape log.dvi",  
            xlogdir);  
       else if (preferences.printdestination == 1  
                && preferences.printstyle == 0)  
         printstring =  
           g_strdup_printf  
           ("cd %s; latex -interaction=nonstopmode log.tex; dvips -t landscape -o log.ps log.dvi",  
            xlogdir);  
       else if (preferences.printdestination == 0  
                && preferences.printstyle == 1)  
         printstring =  
           g_strdup_printf  
           ("cd %s; latex -interaction=nonstopmode log.tex; dvips log.dvi",  
            xlogdir);  
       else if (preferences.printdestination == 1  
                && preferences.printstyle == 1)  
         printstring =  
           g_strdup_printf  
           ("cd %s; latex -interaction=nonstopmode log.tex; dvips -o log.ps log.dvi",  
            xlogdir);  
       if (preferences.printdestination == 0)  
         temp = g_strdup_printf (_("Log send to printer"));  
       else  
         temp =  
           g_strdup_printf (_("Log printed to %s%slog.ps"), xlogdir, G_DIR_SEPARATOR_S);  
       system (printstring);  
       update_statusbar (temp);  
       g_free (printstring);  
     }  
   
   g_free (texsize);  
   g_free (texorientation);  
   g_free (texpoint);  
   g_free (texfile);  
   g_free (temp);  
   
   gtk_widget_set_sensitive (mainwindow, 1);  
   gtk_widget_destroy (gtk_widget_get_toplevel (GTK_WIDGET (button)));  
 }  
   
 /* cancel clicked, nothing printed */  
 void  
 on_printcancelbutton_clicked (GtkButton * button, gpointer user_data)  
 {  
   gtk_widget_set_sensitive (mainwindow, 1);  
   gtk_widget_destroy (gtk_widget_get_toplevel (GTK_WIDGET (button)));  
 }  
   
 /* print dialog is deleted */  
 gboolean  
 on_printdialog_delete_event (GtkWidget * widget, GdkEvent * event,  
                              gpointer user_data)  
 {  
   gtk_widget_set_sensitive (mainwindow, 1);  
   return FALSE;  
 }  
   
 /* set sensitivity of range widgets in print dialog */  
 void  
 on_printradiobutton_toggled (GtkToggleButton * togglebutton,  
                              gpointer user_data)  
 {  
   GtkWidget *printlowentry, *printrangelabel, *printhighentry;  
   
   printlowentry = lookup_widget (printdialog, "printlowentry");  
   printhighentry = lookup_widget (printdialog, "printhighentry");  
   printrangelabel = lookup_widget (printdialog, "printrangelabel");  
   switch (atoi (user_data))  
     {  
     case 1:  
       gtk_widget_set_sensitive (printlowentry, 0);  
       gtk_widget_set_sensitive (printhighentry, 0);  
       gtk_widget_set_sensitive (printrangelabel, 0);  
       break;  
     case 2:  
       gtk_widget_set_sensitive (printlowentry, 1);  
       gtk_widget_set_sensitive (printhighentry, 1);  
       gtk_widget_set_sensitive (printrangelabel, 1);  
       break;  
     }  
 }  
   
106    
107  /* SEARCH DIALOG */  /* SEARCH DIALOG */
108  void  void

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26