refactor
[pspp] / src / ui / gui / psppire-window.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2009, 2010, 2011, 2013, 2014, 2020 Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <gl/relocatable.h>
19
20 #include "psppire-window.h"
21 #include "psppire-window-base.h"
22
23 #include <gtk/gtk.h>
24
25 #include <stdlib.h>
26
27 #include <gettext.h>
28 #define _(msgid) gettext (msgid)
29 #define N_(msgid) msgid
30
31 #include "data/any-reader.h"
32 #include "data/file-handle-def.h"
33 #include "data/dataset.h"
34 #include "libpspp/version.h"
35 #include "output/output-item.h"
36 #include "output/pivot-table.h"
37 #include "output/spv/spv.h"
38
39 #include "helper.h"
40 #include "psppire-data-window.h"
41 #include "psppire-encoding-selector.h"
42 #include "psppire-syntax-window.h"
43 #include "psppire-window-register.h"
44
45 static void psppire_window_class_init    (PsppireWindowClass *class);
46 static void psppire_window_init          (PsppireWindow      *window);
47
48 static GObjectClass *parent_class;
49
50 G_DEFINE_ABSTRACT_TYPE (PsppireWindow, psppire_window, PSPPIRE_TYPE_WINDOW_BASE)
51
52 /* Properties */
53 enum
54 {
55   PROP_0,
56   PROP_FILENAME,
57   PROP_DESCRIPTION,
58   PROP_ID
59 };
60
61
62 static void
63 psppire_window_set_title (PsppireWindow *window)
64 {
65   GString *title = g_string_sized_new (80);
66
67   if (window->edited != NULL)
68     g_string_append_c (title, '*');
69
70   if (window->basename || window->id)
71     {
72       if (window->basename)
73         g_string_append_printf (title, "%s ", window->basename);
74
75       if (window->id)
76         g_string_append_printf (title, "[%s] ", window->id);
77
78       g_string_append_unichar (title, 0x2014); /* em dash */
79       g_string_append_c (title, ' '); /* em dash */
80     }
81
82   g_string_append_printf (title, "PSPPIRE %s", window->description);
83
84   int minor = 1;
85   sscanf (bare_version, "%*d.%d.%*d", &minor);
86   if (minor % 2)
87     g_string_append_printf (title, " - Test version! Please report bugs to %s", PACKAGE_BUGREPORT);
88
89   gtk_window_set_title (GTK_WINDOW (window), title->str);
90
91   g_string_free (title, TRUE);
92 }
93
94 static void
95 psppire_window_update_list_name (PsppireWindow *window)
96 {
97   PsppireWindowRegister *reg = psppire_window_register_new ();
98   GString *candidate = g_string_sized_new (80);
99   int n;
100
101   n = 1;
102   do
103     {
104       /* Compose a name. */
105       g_string_truncate (candidate, 0);
106       if (window->filename)
107         {
108           gchar *display_filename = g_filename_display_name (window->filename);
109           g_string_append (candidate, display_filename);
110           g_free (display_filename);
111
112           if (window->id)
113             g_string_append_printf (candidate, " [%s]", window->id);
114         }
115       else if (window->id)
116         g_string_append_printf (candidate, "[%s]", window->id);
117       else
118         g_string_append (candidate, window->description);
119
120       if (n++ > 1)
121         g_string_append_printf (candidate, " #%d", n);
122
123       if (window->list_name && !strcmp (candidate->str, window->list_name))
124         {
125           /* Keep the existing name. */
126           g_string_free (candidate, TRUE);
127           return;
128         }
129     }
130   while (psppire_window_register_lookup (reg, candidate->str));
131
132   if (window->list_name)
133     psppire_window_register_remove (reg, window->list_name);
134
135   g_free (window->list_name);
136   window->list_name = g_string_free (candidate, FALSE);
137
138   psppire_window_register_insert (reg, window, window->list_name);
139 }
140
141 static void
142 psppire_window_name_changed (PsppireWindow *window)
143 {
144   psppire_window_set_title (window);
145   psppire_window_update_list_name (window);
146 }
147
148 static void
149 psppire_window_set_property (GObject         *object,
150                              guint            prop_id,
151                              const GValue    *value,
152                              GParamSpec      *pspec)
153 {
154   PsppireWindow *window = PSPPIRE_WINDOW (object);
155
156   switch (prop_id)
157     {
158     case PROP_DESCRIPTION:
159       g_free (window->description);
160       window->description = g_value_dup_string (value);
161       psppire_window_set_title (window);
162       break;
163     case PROP_FILENAME:
164       g_free (window->filename);
165       window->filename = g_value_dup_string (value);
166       g_free (window->basename);
167       window->basename = (window->filename
168                           ? g_filename_display_basename (window->filename)
169                           : NULL);
170       psppire_window_name_changed (window);
171       break;
172     case PROP_ID:
173       g_free (window->id);
174       window->id = g_value_dup_string (value);
175       psppire_window_name_changed (window);
176       break;
177     default:
178       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
179       break;
180     };
181 }
182
183
184 static void
185 psppire_window_get_property (GObject         *object,
186                              guint            prop_id,
187                              GValue          *value,
188                              GParamSpec      *pspec)
189 {
190   PsppireWindow *window = PSPPIRE_WINDOW (object);
191
192   switch (prop_id)
193     {
194     case PROP_FILENAME:
195       g_value_set_string (value, window->filename);
196       break;
197     case PROP_DESCRIPTION:
198       g_value_set_string (value, window->description);
199       break;
200     case PROP_ID:
201       g_value_set_string (value, window->id);
202       break;
203     default:
204       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205       break;
206     };
207 }
208
209
210 static void
211 psppire_window_finalize (GObject *object)
212 {
213   PsppireWindow *window = PSPPIRE_WINDOW (object);
214
215   PsppireWindowRegister *reg = psppire_window_register_new ();
216
217   if (window->edited)
218     g_date_time_unref (window->edited);
219
220   g_signal_handler_disconnect (reg, window->remove_handler);
221   g_signal_handler_disconnect (reg, window->insert_handler);
222   psppire_window_register_remove (reg, window->list_name);
223   g_free (window->filename);
224   g_free (window->basename);
225   g_free (window->id);
226   g_free (window->description);
227   g_free (window->list_name);
228
229   g_hash_table_destroy (window->menuitem_table);
230
231   if (G_OBJECT_CLASS (parent_class)->finalize)
232     G_OBJECT_CLASS (parent_class)->finalize (object);
233 }
234
235 static void
236 psppire_window_class_init (PsppireWindowClass *class)
237 {
238   GObjectClass *object_class = G_OBJECT_CLASS (class);
239
240   object_class->finalize = psppire_window_finalize;
241
242   GParamSpec *description_spec =
243     null_if_empty_param ("description",
244                        "Description",
245                        "A string describing the usage of the window",
246                          NULL, /*Should be overridden by derived classes */
247                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
248
249   GParamSpec *filename_spec =
250     null_if_empty_param ("filename",
251                        "File name",
252                        "The name of the file associated with this window, if any",
253                          NULL,
254                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
255
256   GParamSpec *id_spec =
257     null_if_empty_param ("id",
258                          "Identifier",
259                          "The PSPP language identifier for the data associated "
260                          "with this window (e.g. dataset name)",
261                          NULL,
262                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
263
264   object_class->set_property = psppire_window_set_property;
265   object_class->get_property = psppire_window_get_property;
266
267   g_object_class_install_property (object_class,
268                                    PROP_DESCRIPTION,
269                                    description_spec);
270
271   g_object_class_install_property (object_class,
272                                    PROP_FILENAME,
273                                    filename_spec);
274
275   g_object_class_install_property (object_class,
276                                    PROP_ID,
277                                    id_spec);
278
279   parent_class = g_type_class_peek_parent (class);
280 }
281
282
283 static void
284 insert_menuitem_into_menu (PsppireWindow *window, gpointer key)
285 {
286   gchar *filename;
287   GtkWidget *item;
288   filename = g_filename_display_name (key);
289   item = gtk_check_menu_item_new_with_label (filename);
290   g_object_ref_sink (item);
291   g_free (filename);
292
293   g_hash_table_insert (window->menuitem_table, key, item);
294 }
295
296 static void
297 insert_item (gpointer key, gpointer value, gpointer data)
298 {
299   PsppireWindow *window = PSPPIRE_WINDOW (data);
300
301   if (NULL != g_hash_table_lookup (window->menuitem_table, key))
302     return;
303
304   insert_menuitem_into_menu (window, key);
305 }
306
307 /* Insert a new item into the window menu */
308 static void
309 insert_menuitem (GObject *reg, const gchar *key, gpointer data)
310 {
311   PsppireWindow *window = PSPPIRE_WINDOW (data);
312
313   insert_menuitem_into_menu (window, (gpointer) key);
314 }
315
316
317 static void
318 remove_menuitem (PsppireWindowRegister *reg, const gchar *key, gpointer data)
319 {
320   PsppireWindow *window = PSPPIRE_WINDOW (data);
321   g_hash_table_remove (window->menuitem_table, key);
322 }
323
324 static void
325 insert_existing_items (PsppireWindow *window)
326 {
327   psppire_window_register_foreach (psppire_window_register_new (), insert_item, window);
328 }
329
330
331 static gboolean
332 on_delete (PsppireWindow *w, GdkEvent *event, gpointer user_data)
333 {
334   PsppireWindowRegister *reg = psppire_window_register_new ();
335
336   if (w->edited != NULL)
337     {
338       gint response = psppire_window_query_save (w);
339
340       switch (response)
341         {
342         default:
343         case GTK_RESPONSE_CANCEL:
344           return TRUE;
345           break;
346         case GTK_RESPONSE_APPLY:
347           psppire_window_save (w);
348           if (w->edited != NULL)
349             {
350               /* Save failed, or user exited Save As dialog with Cancel. */
351               return TRUE;
352             }
353           break;
354         case GTK_RESPONSE_REJECT:
355           break;
356         }
357     }
358
359   if (1 == psppire_window_register_n_items (reg))
360     gtk_main_quit ();
361
362   return FALSE;
363 }
364
365
366 static void
367 psppire_window_init (PsppireWindow *window)
368 {
369   window->filename = NULL;
370   window->basename = NULL;
371   window->id = NULL;
372   window->description = NULL;
373   window->list_name = NULL;
374   window->edited = NULL;
375
376   window->menuitem_table  = g_hash_table_new_full (g_str_hash, g_str_equal,
377                                                    NULL, g_object_unref);
378
379
380   g_signal_connect (window,  "realize", G_CALLBACK (insert_existing_items), NULL);
381
382   PsppireWindowRegister *reg = psppire_window_register_new ();
383   window->insert_handler = g_signal_connect (reg,
384                                              "inserted",
385                                              G_CALLBACK (insert_menuitem),
386                                              window);
387
388   window->remove_handler = g_signal_connect (reg,
389                                              "removed",
390                                              G_CALLBACK (remove_menuitem),
391                                              window);
392
393   window->added_separator = FALSE;
394
395   g_signal_connect_swapped (window, "delete-event", G_CALLBACK (on_delete), window);
396
397   g_object_set (window, "icon-name", "org.gnu.pspp", NULL);
398 }
399
400 /*
401    Ask the user if the buffer should be saved.
402    Return the response.
403 */
404 gint
405 psppire_window_query_save (PsppireWindow *se)
406 {
407   gint response;
408   GtkWidget *dialog;
409   GtkWidget *cancel_button;
410
411   gchar *description;
412
413   GDateTime *now = g_date_time_new_now_utc ();
414   GTimeSpan timespan = g_date_time_difference (now, se->edited);
415   g_date_time_unref (now);
416
417   if (se->filename)
418     description = g_filename_display_basename (se->filename);
419   else if (se->id)
420     description = g_strdup (se->id);
421   else
422     description = g_strdup (se->description);
423   dialog =
424     gtk_message_dialog_new (GTK_WINDOW (se),
425                             GTK_DIALOG_MODAL,
426                             GTK_MESSAGE_WARNING,
427                             GTK_BUTTONS_NONE,
428                             _("Save the changes to `%s' before closing?"),
429                             description);
430   g_free (description);
431
432   g_object_set (dialog, "icon-name", "org.gnu.pspp", NULL);
433
434   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
435                                             _("If you don't save, changes from the last %ld seconds will be permanently lost."),
436                                             (long int) (timespan / G_TIME_SPAN_SECOND));
437
438   gtk_dialog_add_button  (GTK_DIALOG (dialog),
439                           _("Close _without saving"),
440                           GTK_RESPONSE_REJECT);
441
442   cancel_button = gtk_dialog_add_button  (GTK_DIALOG (dialog),
443                                           _("Cancel"),
444                                           GTK_RESPONSE_CANCEL);
445
446   gtk_dialog_add_button  (GTK_DIALOG (dialog),
447                           _("Save"),
448                           GTK_RESPONSE_APPLY);
449
450   gtk_widget_grab_focus (cancel_button);
451
452   response = gtk_dialog_run (GTK_DIALOG (dialog));
453
454   gtk_widget_destroy (dialog);
455
456   return response;
457 }
458
459
460 /* The return value is encoded in the glib filename encoding. */
461 const gchar *
462 psppire_window_get_filename (PsppireWindow *w)
463 {
464   return w->filename;
465 }
466
467
468 /* FILENAME must be encoded in the glib filename encoding. */
469 void
470 psppire_window_set_filename (PsppireWindow *w, const gchar *filename)
471 {
472   g_object_set (w, "filename", filename, NULL);
473 }
474
475 void
476 psppire_window_set_unsaved (PsppireWindow *w)
477 {
478   if (w->edited == NULL)
479     w->edited = g_date_time_new_now_utc ();
480
481   psppire_window_set_title (w);
482 }
483
484 gboolean
485 psppire_window_get_unsaved (PsppireWindow *w)
486 {
487   return w->edited != NULL;
488 }
489
490
491 \f
492
493
494 static void
495 minimise_window (gpointer key, gpointer value, gpointer data)
496 {
497   gtk_window_iconify (GTK_WINDOW (value));
498 }
499
500
501 void
502 psppire_window_minimise_all (void)
503 {
504   PsppireWindowRegister *reg = psppire_window_register_new ();
505
506   g_hash_table_foreach (reg->name_table, minimise_window, NULL);
507 }
508
509
510 \f
511
512 GType
513 psppire_window_model_get_type (void)
514 {
515   static GType window_model_type = 0;
516
517   if (! window_model_type)
518     {
519       static const GTypeInfo window_model_info =
520       {
521         sizeof (PsppireWindowIface), /* class_size */
522         NULL,           /* base_init */
523         NULL,           /* base_finalize */
524         NULL,
525         NULL,           /* class_finalize */
526         NULL,           /* class_data */
527         0,
528         0,              /* n_preallocs */
529         NULL,
530         NULL            /* value_table */
531       };
532
533       window_model_type =
534         g_type_register_static (G_TYPE_INTERFACE, "PsppireWindowModel",
535                                 &window_model_info, 0);
536
537       g_type_interface_add_prerequisite (window_model_type, G_TYPE_OBJECT);
538     }
539
540   return window_model_type;
541 }
542
543
544 void
545 psppire_window_save (PsppireWindow *w)
546 {
547   PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w);
548
549   g_assert (i);
550   g_return_if_fail (i->save);
551
552   if (w->filename == NULL)
553     psppire_window_save_as (w);
554   else
555     {
556       i->save (w);
557       if (w->edited)
558         g_date_time_unref (w->edited);
559       w->edited = NULL;
560
561       psppire_window_set_title (w);
562     }
563 }
564
565 void
566 psppire_window_save_as (PsppireWindow *w)
567 {
568   PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w);
569   gchar *old_filename;
570
571   g_assert (i);
572   g_return_if_fail (i->pick_filename);
573
574   old_filename = w->filename;
575   w->filename = NULL;
576
577   i->pick_filename (w);
578   if (w->filename == NULL)
579     w->filename = old_filename;
580   else
581     {
582       g_free (old_filename);
583       psppire_window_save (w);
584     }
585 }
586
587 static void delete_recent (const char *file_name);
588
589 gboolean
590 psppire_window_load (PsppireWindow *w, const gchar *file,
591                      const gchar *encoding, gpointer hint)
592 {
593   gboolean ok;
594   PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w);
595
596   g_assert (PSPPIRE_IS_WINDOW_MODEL (w));
597
598   g_assert (i);
599
600   g_return_val_if_fail (i->load, FALSE);
601
602   ok = i->load (w, file, encoding, hint);
603
604   if (ok)
605     {
606       psppire_window_set_filename (w, file);
607       if (w->edited)
608         g_date_time_unref (w->edited);
609       w->edited = NULL;
610     }
611   else
612     delete_recent (file);
613
614   return ok;
615 }
616
617
618 GtkWidget *
619 psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
620 {
621   GtkFileFilter *filter = gtk_file_filter_new ();
622   GtkWidget *dialog =
623     gtk_file_chooser_dialog_new (_("Open"),
624                                  GTK_WINDOW (toplevel),
625                                  GTK_FILE_CHOOSER_ACTION_OPEN,
626                                  _("Cancel"), GTK_RESPONSE_CANCEL,
627                                  _("Open"), GTK_RESPONSE_ACCEPT,
628                                  NULL);
629
630   g_object_set (dialog, "local-only", FALSE, NULL);
631
632   gtk_file_filter_set_name (filter, _("Data and Syntax Files"));
633   gtk_file_filter_add_mime_type (filter, "application/x-spss-sav");
634   gtk_file_filter_add_mime_type (filter, "application/x-spss-por");
635   gtk_file_filter_add_mime_type (filter, "application/x-spss-spv");
636   gtk_file_filter_add_pattern (filter, "*.zsav");
637   gtk_file_filter_add_pattern (filter, "*.sps");
638   gtk_file_filter_add_pattern (filter, "*.SPS");
639   gtk_file_filter_add_pattern (filter, "*.spv");
640   gtk_file_filter_add_pattern (filter, "*.SPV");
641   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
642
643   filter = gtk_file_filter_new ();
644   gtk_file_filter_set_name (filter, _("System Files (*.sav, *.zsav)"));
645   gtk_file_filter_add_mime_type (filter, "application/x-spss-sav");
646   gtk_file_filter_add_pattern (filter, "*.zsav");
647   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
648
649   filter = gtk_file_filter_new ();
650   gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
651   gtk_file_filter_add_mime_type (filter, "application/x-spss-por");
652   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
653
654   filter = gtk_file_filter_new ();
655   gtk_file_filter_set_name (filter, _("Syntax Files (*.sps) "));
656   gtk_file_filter_add_pattern (filter, "*.sps");
657   gtk_file_filter_add_pattern (filter, "*.SPS");
658   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
659
660   filter = gtk_file_filter_new ();
661   gtk_file_filter_set_name (filter, _("Output Files (*.spv) "));
662   gtk_file_filter_add_pattern (filter, "*.spv");
663   gtk_file_filter_add_pattern (filter, "*.SPV");
664   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
665
666   filter = gtk_file_filter_new ();
667   gtk_file_filter_set_name (filter, _("All Files"));
668   gtk_file_filter_add_pattern (filter, "*");
669   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
670
671   if (toplevel->filename)
672     {
673       const gchar *filename = toplevel->filename;
674       gchar *dir_name;
675
676       if (! g_path_is_absolute (filename))
677         {
678           gchar *path =
679             g_build_filename (g_get_current_dir (), filename, NULL);
680           dir_name = g_path_get_dirname (path);
681           g_free (path);
682         }
683       else
684         {
685           dir_name = g_path_get_dirname (filename);
686         }
687       gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
688                                            dir_name);
689       free (dir_name);
690     }
691
692     gtk_file_chooser_set_extra_widget (
693       GTK_FILE_CHOOSER (dialog),
694       psppire_encoding_selector_new ("Auto", true));
695
696   return dialog;
697 }
698
699 void
700 read_spv_file (const char *filename)
701 {
702   struct output_item *root;
703   char *error = spv_read (filename, &root, NULL);
704   if (error)
705     {
706       /* XXX */
707       fprintf (stderr, "%s\n", error);
708       return;
709     }
710
711   output_item_submit_children (root);
712 }
713
714 /* Callback for the file_open action.
715    Prompts for a filename and opens it */
716 void
717 psppire_window_open (PsppireWindow *de)
718 {
719   GtkWidget *dialog = psppire_window_file_chooser_dialog (de);
720
721   gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), relocate (examples_dir), NULL);
722
723   switch (gtk_dialog_run (GTK_DIALOG (dialog)))
724     {
725     case GTK_RESPONSE_ACCEPT:
726       {
727         gchar *name =
728           gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
729
730         const gchar **cs = NULL;
731         g_get_filename_charsets (&cs);
732
733         gchar *encoding = psppire_encoding_selector_get_encoding (
734           gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (dialog)));
735
736         struct file_handle *fh = fh_create_file (NULL, name, cs[0], fh_default_properties ());
737
738         int retval = any_reader_detect (fh, NULL);
739         if (retval == 1)
740           open_data_window (de, name, encoding, NULL);
741         else if (retval == 0)
742           {
743             char *error = spv_detect (name);
744             if (!error)
745               read_spv_file (name);
746             else
747               {
748                 free (error);
749                 open_syntax_window (name, encoding);
750               }
751           }
752
753         g_free (encoding);
754         fh_unref (fh);
755         g_free (name);
756       }
757       break;
758     default:
759       break;
760     }
761
762   gtk_widget_destroy (dialog);
763 }
764
765
766 /* Puts FILE_NAME (encoded in the glib file name encoding) into the recent list
767    with associated MIME_TYPE.  If it's already in the list, it moves it to the
768    top. */
769 void
770 add_most_recent (const char *file_name,
771                  const char *mime_type, const char *encoding)
772 {
773   gchar *uri = g_filename_to_uri  (file_name, NULL, NULL);
774   if (uri)
775     {
776       GtkRecentData recent_data;
777       gchar *full_mime_type;
778
779       if (encoding && encoding[0])
780         full_mime_type = g_strdup_printf ("%s; charset=%s",
781                                           mime_type, encoding);
782       else
783         full_mime_type = g_strdup (mime_type);
784
785       recent_data.display_name = NULL;
786       recent_data.description = NULL;
787       recent_data.mime_type = full_mime_type;
788       recent_data.app_name = CONST_CAST (gchar *, g_get_application_name ());
789       recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
790       recent_data.groups = NULL;
791       recent_data.is_private = FALSE;
792
793       gtk_recent_manager_add_full (gtk_recent_manager_get_default (),
794                                    uri, &recent_data);
795
796       g_free (recent_data.app_exec);
797       g_free (full_mime_type);
798     }
799
800   g_free (uri);
801 }
802
803
804
805 /*
806    If FILE_NAME exists in the recent list, then  delete it.
807  */
808 static void
809 delete_recent (const char *file_name)
810 {
811   gchar *uri = g_filename_to_uri  (file_name, NULL, NULL);
812
813   if (uri)
814     gtk_recent_manager_remove_item (gtk_recent_manager_get_default (), uri, NULL);
815
816   g_free (uri);
817 }