fileout.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            fileout.c
00003  * 
00004  *  Sun Sep 24 12:10:36 2006
00005  *  Copyright  2006-2007  Neil Williams
00006  *  linux@codehelp.co.uk
00007  ****************************************************************************/
00013 /*
00014     This package is free software; you can redistribute it and/or modify
00015     it under the terms of the GNU General Public License as published by
00016     the Free Software Foundation; either version 3 of the License, or
00017     (at your option) any later version.
00018 
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022     GNU General Public License for more details.
00023 
00024     You should have received a copy of the GNU General Public License
00025     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00026 */
00027 
00028 #include "config.h"
00029 
00030 #include <string.h>
00031 #include <glib.h>
00032 #include <gtk/gtk.h>
00033 #include <glib/gi18n.h>
00034 #include <gtkextra/gtksheet.h>
00035 #include "types.h"
00036 #include "dialog_initial.h"
00037 #include "dim_list_menu.h"
00038 #include "edit.h"
00039 #include "filein.h"
00040 #include "main.h"
00041 #include "report.h"
00042 
00043 typedef enum
00044 {
00046     QL_CLOSE,
00048     QL_QUIT
00049 } QlCloseMode;
00050 
00051 QlCloseMode close_mode;
00052 
00054 GtkSheetRange write_range;      
00055 
00056 typedef enum
00057 {
00059     QL_PRINT_NONE,
00061     QL_PRINT_ALL,
00063     QL_PRINT_LIT,
00065     QL_PRINT_FILTER
00066 } QlPrintType;
00067 
00068 static QlPrintType print_all = QL_PRINT_NONE;
00069 
00070 static void
00071 all_data_clicked (GtkWidget G_GNUC_UNUSED * w, gpointer G_GNUC_UNUSED data)
00072 {
00073     print_all = QL_PRINT_ALL;
00074 }
00075 
00076 static void
00077 filter_data_clicked (GtkWidget G_GNUC_UNUSED * w, gpointer G_GNUC_UNUSED data)
00078 {
00079     print_all = QL_PRINT_FILTER;
00080 }
00081 
00082 static void
00083 highlighted_data_clicked (GtkWidget G_GNUC_UNUSED * w, gpointer G_GNUC_UNUSED data)
00084 {
00085     print_all = QL_PRINT_LIT;
00086 }
00087 
00089 static void
00090 ask_about_all (QlTabData * tab, GtkWidget * chooser)
00091 {
00092     GtkWidget *all_data;
00093     GtkWidget *filter_data;
00094     GtkWidget *highlighted_data;
00095     GtkWidget *hbox;
00096 
00097     print_all = QL_PRINT_ALL;
00098     hbox = gtk_hbox_new (FALSE, 5);
00099     all_data = gtk_radio_button_new_with_label (NULL, _("Entire file"));
00100     gtk_box_pack_start (GTK_BOX (hbox), all_data, FALSE, FALSE, 0);
00101     g_signal_connect (all_data, "clicked",
00102         G_CALLBACK (all_data_clicked), NULL);
00103 
00104     filter_data = gtk_radio_button_new_with_label
00105         (gtk_radio_button_get_group (GTK_RADIO_BUTTON (all_data)),
00106         _("Allowed by filter"));
00107     if (!tab->file->filter_ptr)
00108         gtk_widget_set_sensitive (filter_data, FALSE);
00109     gtk_box_pack_start (GTK_BOX (hbox), filter_data, FALSE, FALSE, 0);
00110     g_signal_connect (filter_data, "clicked",
00111         G_CALLBACK (filter_data_clicked), NULL);
00112 
00113     highlighted_data = gtk_radio_button_new_with_label
00114         (gtk_radio_button_get_group (GTK_RADIO_BUTTON (all_data)),
00115         _("Highlighted cells"));
00116     gtk_box_pack_start (GTK_BOX (hbox), highlighted_data, FALSE, FALSE, 0);
00117     g_signal_connect (highlighted_data, "clicked",
00118         G_CALLBACK (highlighted_data_clicked), NULL);
00119 
00120     /* there can only be a selection if some cells are selected, more than one */
00121     if (tab->view->dialog_mode == MODE_SAVE ||
00122         (tab->view->sel_type == SELECT_ENTRY || 
00123             tab->view->sel_type != SELECT_COLUMN))
00124         gtk_widget_set_sensitive (highlighted_data, FALSE);
00125     gtk_widget_show_all (hbox);
00126     gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(chooser), hbox);
00127 }                               /* end of ask_about_all */
00128 
00134 static void
00135 remove_ql_chars (gchar * text)
00136 {
00137     gchar *linebufp = text;
00138     while (*linebufp)
00139     {
00140         if (*linebufp == '\\')
00141             *linebufp = '/';
00142         linebufp++;
00143     }
00144     linebufp--;                 /* skip back over ending zero */
00145     linebufp = g_strstrip (linebufp); /* removes trailing blanks */
00146 }                               /* end of remove_ql_chars */
00147 
00148 static void
00149 print_field_cb (gpointer G_GNUC_UNUSED field_index, gpointer field_ptr, gpointer user_data)
00150 {
00151     QlFieldInfo * field = (QlFieldInfo*)field_ptr;
00152     FILE * f; 
00153     f = (FILE*)user_data;
00154 
00155     remove_ql_chars (field->name);
00156     fprintf (f, "FIELD %u %u %u %u %u %u %u %u %s\n",
00157         field->type,
00158         field->formatting,
00159         field->decimal_places,
00160         field->justification,
00161         field->sheet_column,
00162         field->width,
00163         field->unused1,
00164         field->unused2, 
00165         field->name);
00166 }
00167 
00170 static void
00171 write_ql_file (QlTabData * tab, FILE *f)
00172 {
00173     gchar *text;
00174     gint32 rowx;
00175     gint16 fieldx = 0;
00176     gint16 sortx = 0;
00177     gint16 filterx = 0;
00178     gint16 subx = 0;
00179     gint16 reportx = 0;
00181     gint16 colx = 0;
00183     gint16 blank_fields;
00185     gboolean got_data;
00186 
00187     g_return_if_fail (tab);
00188     get_window_size_loc (GTK_WIDGET (tab->qlc->parent));
00189 
00190     fprintf (f, "QUICKLIST %s 06/10/99 %u %u %u %u %u %u %u %u\n",
00191         VERSION,
00192         tab->file->last_field + 1,
00193         tab->file->sort_ct,
00194         tab->file->filter_ct,
00195         tab->file->report_ct, tab->view->width, tab->view->height, 
00196         tab->view->x, tab->view->y);
00197     ql_fieldinfo_foreach (tab, print_field_cb, f);
00198 /*
00199     for (fieldx = 0; fieldx <= tab->file->last_field; fieldx++)
00200     {
00201         remove_ql_chars (tab->file->fields[fieldx]->name);
00202         fprintf (f, "FIELD %u %u %u %u %u %u %u %u %s\n",
00203             tab->file->fields[fieldx]->type,
00204             tab->file->fields[fieldx]->formatting,
00205             tab->file->fields[fieldx]->decimal_places,
00206             tab->file->fields[fieldx]->justification,
00207             tab->file->fields[fieldx]->sheet_column,
00208             tab->file->fields[fieldx]->width,
00209             tab->file->fields[fieldx]->unused1,
00210             tab->file->fields[fieldx]->unused2, 
00211             tab->file->fields[fieldx]->name);
00212     }
00213 */
00214     for (sortx = 0; sortx < tab->file->sort_ct; sortx++)
00215     {
00216         remove_ql_chars (tab->file->sorts[sortx].name);
00217         fprintf (f, "SORT %u %u %s\\",
00218             tab->file->sorts[sortx].unused1,
00219             tab->file->sorts[sortx].unused2, 
00220             tab->file->sorts[sortx].name);
00221         for (subx = 0; subx < tab->file->sorts[sortx].line_ct; subx++)
00222             fprintf (f, " %u %u",
00223                 tab->file->sorts[sortx].line[subx].field,
00224                 tab->file->sorts[sortx].line[subx].ascending);
00225         fprintf (f, "\n");
00226     }                           /* end of printing one sort record */
00227 
00228     /* Here we need to write a filter. */
00229     for (filterx = 0; filterx < tab->file->filter_ct; filterx++)
00230     {
00231         remove_ql_chars (tab->file->filters[filterx].name);
00232         fprintf (f, "FILTER %d %d %s",
00233             tab->file->filters[filterx].by_and,
00234             tab->file->filters[filterx].use_nocase,
00235             tab->file->filters[filterx].name);
00236         for (subx = 0; subx < tab->file->filters[filterx].line_ct; subx++)
00237         {
00238             fprintf (f, "\\%u %u",
00239                 tab->file->filters[filterx].line[subx].field,
00240                 tab->file->filters[filterx].line[subx].type);
00241             remove_ql_chars (tab->file->filters[filterx].line[subx].compare);
00242             fprintf (f, " %s", tab->file->filters[filterx].line[subx].compare);
00243         }
00244         fprintf (f, "\n");      /* Finish off the filter */
00245     }
00246 
00247     /* Now a report column */
00248     for (reportx = 0; reportx < tab->file->report_ct; reportx++)
00249     {
00250         for (colx = 0; colx <= tab->file->reports[reportx].last_column; colx++)
00251             fprintf (f, "COLUMN %u %u %u %u %u %u\n",
00252                 tab->file->reports[reportx].column[colx].field,
00253                 tab->file->reports[reportx].column[colx].width,
00254                 tab->file->reports[reportx].column[colx].group,
00255                 tab->file->reports[reportx].column[colx].total,
00256                 tab->file->reports[reportx].column[colx].unused1,
00257                 tab->file->reports[reportx].column[colx].unused2);
00258 
00259         remove_ql_chars (tab->file->reports[reportx].name);
00260         fprintf (f, "REPORT %i %i %u %u %s\\\\\n",
00261             tab->file->reports[reportx].sort,
00262             tab->file->reports[reportx].filter,
00263             tab->file->reports[reportx].width,
00264             tab->file->reports[reportx].height, 
00265             tab->file->reports[reportx].name);
00266 
00267     }                           /* end of writing report columns and report records */
00268     fprintf (f, "DATA 0 0\n");
00269 
00270     /* NOW WRITE THE DATA RECORDS.  Last row is always empty. 
00271        The logic is difficult enough that I use an intermediate variable */
00272     for (rowx = 0; rowx < tab->file->last_row; rowx++)
00273     {
00274         gint last_field;
00275         got_data = FALSE;       /* to not write empty records */
00276         blank_fields = 0;       /* to not write trailing \\\\\ */
00277         last_field = ql_get_last_field (tab);
00278         for (fieldx = 0; fieldx <= last_field; fieldx++)
00279         {
00280             QlFieldInfo * field;
00281             field = ql_get_fieldinfo (tab, fieldx);
00282             colx = field->sheet_column;
00283             text = gtk_sheet_cell_get_text (tab->view->sheet, rowx, colx);
00284             if (text)
00285             {
00286                 while (blank_fields)
00287                 {               /* write the skipped blank fields */
00288                     fprintf (f, "\\");
00289                     blank_fields--;
00290                 }
00291 
00292                 remove_ql_chars (text);
00293                 fprintf (f, "%s\\", text);
00294                 got_data = TRUE;
00295             }
00296             else
00297                 blank_fields++;
00298         }
00299         if (got_data)
00300             fprintf (f, "\n");  /* write nothing if nothing there */
00301     }
00302     fprintf (f, "\n");          /* write nothing if nothing there */
00303     tab->file->changed = FALSE;
00304 }
00305 
00310 static void
00311 write_html (QlTabData * tab, FILE *f)
00312 {
00313     gchar *text;
00314     gint32 rowx;
00315     gint16 fieldx;
00316     gint16 justification;
00317     QlFieldInfo * field;
00318     gint16 colx = 0;            /* indexes into array */
00319 
00320     /* Output Head Info Stuff */
00321     fprintf (f,
00322         "<html>\n"
00323         "<head>\n"
00324         "<title>%s</title>\n"
00325         "<meta name=\"Generator\" content=\"QUICKLIST %s\">\n"
00326         "</head>\n\n"
00327         "<body bgcolor=\"#ffffff\">\n"
00328         "<table width=\"2\">\n" "  <tr>\n", 
00329         tab->file->file_path, VERSION);
00330     for (colx = write_range.col0; colx <= write_range.coli; colx++)
00331     {
00332         fieldx = tab->file->col_to_field[colx];
00333         field = ql_get_fieldinfo (tab, fieldx);
00334         fprintf (f, "    <th>%s</th>\n", field->name);
00335     }
00336     fprintf (f, "  </tr>\n");
00337 
00338     for (rowx = write_range.row0; rowx <= write_range.rowi; rowx++)
00339     {
00340         if (print_all != 'A' && !row_is_visible (tab, rowx))
00341             continue;
00342         fprintf (f, "  <tr>\n");
00343         for (colx = write_range.col0; colx <= write_range.coli; colx++)
00344         {
00345             text = gtk_sheet_cell_get_text (tab->view->sheet, rowx, colx);
00346             fputs ("<td>", f);
00347             if (text)
00348             {
00349                 fieldx = tab->file->col_to_field[colx];
00350                 field = ql_get_fieldinfo (tab, fieldx);
00351                 justification = field->justification;
00352                 if (justification == GTK_JUSTIFY_CENTER)
00353                     fputs ("<center>", f);
00354                 else if (justification == GTK_JUSTIFY_RIGHT)
00355                     fputs ("<right>", f);
00356                 fprintf (f, "%s", text);
00357                 if (justification == GTK_JUSTIFY_CENTER)
00358                     fputs ("</center>", f);
00359                 else if (justification == GTK_JUSTIFY_RIGHT)
00360                     fputs ("</right>", f);
00361             }
00362             fputs ("</td>\n", f);
00363         }
00364         fprintf (f, "  </tr>\n");
00365     }
00366     fprintf (f, "</table>\n</body>\n</html>\n");
00367 }                               /* end of html output */
00368 
00370 static void
00371 write_delimited (QlTabData * tab, FILE * f, gchar separator)
00372 {
00374     gchar linebuf[4096];
00375     gchar *text;
00376     gint32 rowx;
00377     gint16 colx;                /* indexes into array */
00378     gint x, y;
00379     gboolean first_in_row;
00380 
00381     /* NOW WRITE THE DATA RECORDS.  Last row is always empty. */
00382     for (rowx = write_range.row0; rowx < write_range.rowi; rowx++)
00383     {
00384         if (print_all != QL_PRINT_ALL && !row_is_visible (tab, rowx))
00385             continue;
00386         first_in_row = TRUE;
00387         for (colx = write_range.col0; colx <= write_range.coli; colx++)
00388         {
00389             text = gtk_sheet_cell_get_text (tab->view->sheet, rowx, colx);
00390             if (!first_in_row)
00391                 fprintf (f, "%c", separator);
00392             first_in_row = FALSE;
00393             if (text)
00394             {
00395                 x = y = 0;      /* remove separator characters from data */
00396                 do
00397                 {
00398                     if (text[x] != separator)
00399                         linebuf[y++] = text[x];
00400                 }
00401                 while (text[x++]);  /* stop at end of string */
00402                 fprintf (f, "%s", linebuf);
00403             }
00404         }
00405         fprintf (f, "\n");      /* write nothing if nothing there */
00406     }
00407 }                               /* end of write_delimited */
00408 
00410 static void
00411 write_all_types (QlTabData * tab, gchar * name)
00412 {
00413     FILE * f;
00414     gchar * backup_name;
00415     gchar * fullpath;
00416 
00417     g_return_if_fail (tab);
00418     g_return_if_fail (tab->file->file_type > QL_NO_FILE);
00419 
00420     tab->file->file_name = name;
00421     fullpath = tab->file->file_path;
00422 
00423     backup_name = g_strconcat (fullpath, "~", NULL);
00424     rename (fullpath, backup_name);
00425 
00426     /* determine if whole file is to be written */
00427     write_range.row0 = write_range.col0 = 0;
00428     write_range.rowi = tab->file->last_row - 1;
00429     write_range.coli = tab->file->last_field;
00430     if (print_all == QL_PRINT_LIT)      /* highlighted */
00431         write_range = tab->view->sel_range;
00432 
00433     f = NULL;
00434     switch (tab->file->file_type)
00435     {
00436         case QL_OLD_QLF:
00437         {
00438             if (!g_str_has_suffix(fullpath, "qlf"))
00439             {
00440                 fullpath = g_strconcat (fullpath, ".qlf", NULL);
00441             }
00442             if (!(f = fopen (fullpath, "w")))
00443             {
00444                 level1_error (tab, _("Can't write the file.  Strange.")); 
00445                 return;
00446             }
00448             write_ql_file (tab, f);
00449             tab->file->file_name = g_path_get_basename (fullpath);
00450             tab->file->file_path = fullpath;
00451             tab->file->changed = FALSE;
00452             break;
00453         }
00454         case QL_EXPORT_HTML:
00455         {
00456             if (!g_str_has_suffix(name, "html"))
00457             {
00458                 name = g_strconcat (name, ".html", NULL);
00459             }
00460             if (!(f = fopen (name, "w")))
00461             {
00462                 level1_error (tab, _("Can't write the file.  Strange.")); 
00463                 return;
00464             }
00466             write_html (tab, f);
00467             tab->file->file_name = name;
00468             break;
00469         }
00470         case QL_CSV:
00471         {
00472             if (!g_str_has_suffix(name, "csv"))
00473             {
00474                 name = g_strconcat (name, ".csv", NULL);
00475             }
00476             if (!(f = fopen (name, "w")))
00477             {
00478                 level1_error (tab, _("Can't write the file.  Strange.")); 
00479                 return;
00480             }
00482             write_delimited (tab, f, ',');
00483             tab->file->file_name = name;
00484             break;
00485         }
00486         case QL_TSV:
00487         {
00488             if (!g_str_has_suffix(name, "tsv"))
00489             {
00490                 name = g_strconcat (name, ".tsv", NULL);
00491             }
00492             if (!(f = fopen (name, "w")))
00493             {
00494                 level1_error (tab, _("Can't write the file.  Strange.")); 
00495                 return;
00496             }
00498             write_delimited (tab, f, '\t');
00499             tab->file->file_name = name;
00500             break;
00501         }
00502         default:
00503             break;
00504     }
00505     fclose (f);
00506     dim_all_menus (tab->qlc);
00507 }                               /* end of write_all_types */
00508 
00509 static void
00510 update_title (gchar G_GNUC_UNUSED * filename, QlTabData * tab)
00511 {
00512     gint tbindex;
00513     GtkWidget * page;
00514 
00515     tbindex = gtk_notebook_get_current_page (tab->qlc->notebook);
00516     page = gtk_notebook_get_nth_page (tab->qlc->notebook, tbindex);
00517     gtk_notebook_set_tab_label (tab->qlc->notebook,
00518         page, tab_label_box(tab, tab->file->file_name));
00519     gtk_widget_show_all (GTK_WIDGET(tab->qlc->notebook));
00520     tab->view->dialog_mode = MODE_SAVE;
00521 }
00522 
00523 static void
00524 any_save (QlTabData * tab)
00525 {
00526     GtkWidget * chooser;
00527     GtkFileFilter * filter;
00528     gchar * filename;
00529 
00530     filename = NULL;
00531     g_return_if_fail (tab);
00532     if (tab->view->dialog_mode == MODE_SAVE)
00533     {
00534         filename = g_filename_to_utf8 (tab->file->file_path, -1, NULL, NULL, NULL);
00535         write_all_types (tab, filename);
00536         return;
00537     }
00538     if (tab->view->dialog_mode == MODE_NEW)
00539     {
00540         filter = gtk_file_filter_new ();
00541         gtk_file_filter_set_name (filter, _("QuickList files *.qlf"));
00542         gtk_file_filter_add_pattern (filter, "*.qlf");
00543         chooser = gtk_file_chooser_dialog_new ((_("Save this list")),
00544             GTK_WINDOW(tab->qlc->parent), GTK_FILE_CHOOSER_ACTION_SAVE,
00545             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00546             GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
00547         gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser), 
00548             _("Untitled list"));
00549         gtk_file_chooser_set_do_overwrite_confirmation (
00550             GTK_FILE_CHOOSER (chooser), TRUE);
00551         gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(chooser), filter);
00552         if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
00553         {
00554             tab->view->dialog_mode = MODE_SAVE;
00555             filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
00556             tab->file->file_name = g_path_get_basename (filename);
00557             tab->file->file_path = filename;
00558             filename = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
00559             write_all_types (tab, filename);
00560             update_title (tab->file->file_name, tab);
00561         }
00562         gtk_widget_destroy (chooser);
00563     }
00564     if (tab->view->dialog_mode == MODE_EXPORT)
00565     {
00566         chooser = gtk_file_chooser_dialog_new
00567             ((_("Export to a file")), GTK_WINDOW(tab->qlc->parent),
00568             GTK_FILE_CHOOSER_ACTION_SAVE,
00569             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00570             GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT, NULL);
00571         gtk_file_chooser_set_do_overwrite_confirmation (
00572             GTK_FILE_CHOOSER (chooser), TRUE);
00573         ask_about_all (tab, chooser);
00574         file_type_menu (tab, chooser);      /* output file */
00575         tab->file->file_type = QL_EXPORT_HTML;
00576         if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
00577         {
00578             filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
00579             tab->file->file_path = filename;
00580             tab->file->file_name = g_path_get_basename (filename);
00581             filename = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
00582             write_all_types (tab, filename);
00583         }
00584         gtk_widget_destroy (chooser);
00585     }
00586 }
00587 
00596 gboolean
00597 ask_about_save (QlTabData * tab)
00598 {
00599     GtkWidget * ask_dlg;
00600     gboolean ret;
00601     gint result;
00602 
00603     ret = FALSE;
00604     /* no tabs, no data to save */
00605     if (!tab)
00606         return FALSE;
00607     if (gtk_notebook_get_current_page (tab->qlc->notebook) < 0)
00608         return FALSE;
00609     if (!check_if_changed(tab))
00610         return FALSE;
00611     ask_dlg = gtk_message_dialog_new (GTK_WINDOW(tab->qlc->parent),
00612         GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
00613         GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
00614         "%s", _("This file has been changed. "
00615             "Do you want to save it to disk?"));
00616     gtk_dialog_add_buttons (GTK_DIALOG(ask_dlg),
00617         GTK_STOCK_YES, GTK_RESPONSE_YES,
00618         GTK_STOCK_NO,  GTK_RESPONSE_NO,
00619         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
00620     
00621     result = gtk_dialog_run (GTK_DIALOG (ask_dlg));
00622     switch (result)
00623     {
00624         case GTK_RESPONSE_YES:
00625         {
00626             /* if user said Yes, save the file */
00627             any_save (tab);
00628             break;
00629         }
00630         case GTK_RESPONSE_NO:
00631         {
00632             gint tab_index;
00633             tab_index = gtk_notebook_get_current_page (tab->qlc->notebook);
00634             gtk_notebook_remove_page (tab->qlc->notebook, tab_index);
00635             if (tab->file->file_path)
00636                 g_free (tab->file->file_path);
00637             tab->file->file_path = NULL;
00638             break;
00639         }
00640         case GTK_RESPONSE_CANCEL :
00641             ret = TRUE;
00642             break;
00643     }
00644     gtk_widget_destroy (ask_dlg);
00645     return ret;
00646 }                               /* End of ask_about_save */
00647 
00648 void
00649 close_file (GtkAction G_GNUC_UNUSED * w, gpointer data)
00650 {
00651     gint tab_index;
00652     QlContext * qlc;
00653     QlTabData * tab;
00654 
00655     g_return_if_fail (data);
00656     qlc = ql_get_context (GTK_WIDGET(data));
00657     tab = ql_get_tabdata (qlc);
00658     g_return_if_fail (tab);
00659     if (check_if_changed (tab))
00660     {
00661         close_mode = QL_CLOSE;
00662         /* ask_about_save will save or close the tab. */
00663         ask_about_save (tab);
00664         return;
00665     }
00666     tab_index = gtk_notebook_get_current_page (tab->qlc->notebook);
00667     gtk_notebook_remove_page (tab->qlc->notebook, tab_index);
00668     if (tab->file->file_path)
00669         g_free (tab->file->file_path);
00670     tab->file->file_path = NULL;
00671 }                               /* End of close_file callback */
00672 
00673 gboolean
00674 exit_action (GtkAction G_GNUC_UNUSED * a, gpointer data)
00675 {
00676     QlContext * qlc;
00677     QlTabData * tab;
00678     gboolean more;
00679 
00680     qlc = ql_get_context (GTK_WIDGET(data));
00681     tab = ql_get_tabdata (qlc);
00682     close_mode = QL_QUIT;
00683     more = ask_about_save (tab);
00684     if (!more)
00685         gtk_main_quit ();
00686     return TRUE;
00687 }
00688 
00689 gboolean
00690 file_exit (GtkWidget * w, GdkEvent G_GNUC_UNUSED * event, gpointer G_GNUC_UNUSED data)
00691 {
00692     QlContext * qlc;
00693     QlTabData * tab;
00694     gboolean more;
00695 
00696     qlc = ql_get_context (GTK_WIDGET(w));
00697     tab = ql_get_tabdata (qlc);
00698     close_mode = QL_QUIT;
00699     more = ask_about_save (tab);
00700     if (!more)
00701         gtk_main_quit ();
00702     return TRUE;
00703 }                               /* End of exit routine */
00704 
00705 void
00706 file_export (GtkAction G_GNUC_UNUSED * w, gpointer data)
00707 {
00708     QlContext * qlc;
00709     QlTabData * tab;
00710 
00711     qlc = ql_get_context (GTK_WIDGET(data));
00712     tab = ql_get_tabdata (qlc);
00713     tab->view->dialog_mode = MODE_EXPORT;
00714     any_save (tab);
00715 }
00716 
00717 void
00718 save_as (GtkAction G_GNUC_UNUSED * w, gpointer data)
00719 {
00720     QlContext * qlc;
00721     QlTabData * tab;
00722 
00723     g_return_if_fail (data);
00724     qlc = ql_get_context (GTK_WIDGET(data));
00725     tab = ql_get_tabdata (qlc);
00726     print_all = QL_PRINT_ALL;
00727     any_save (tab);
00728 }
00729 
00731 void
00732 save_file (GtkAction G_GNUC_UNUSED * w, gpointer data)
00733 {
00734     QlContext * qlc;
00735     QlTabData * tab;
00736 
00737     qlc = ql_get_context (GTK_WIDGET(data));
00738     tab = ql_get_tabdata (qlc);
00739     print_all = QL_PRINT_ALL;
00740     if ((tab->file->current_file == QL_NO_FILE) ||
00741         (tab->view->dialog_mode == MODE_NEW))
00742     {
00743         tab->file->current_file = tab->file->file_type = QL_OLD_QLF;
00744         tab->view->dialog_mode = MODE_NEW;
00745         any_save (tab);
00746     }
00747     else
00748     {
00749         tab->file->file_type = QL_OLD_QLF;
00750         tab->view->dialog_mode = MODE_SAVE;
00751         save_as (NULL, data);
00752     }
00753 }

Generated on Mon Jan 28 22:02:10 2008 for quicklist by  doxygen 1.5.4