1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * recent.c: gLabels recent files module
8 * Copyright (C) 2001-2006 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <gtk/gtkrecentchoosermenu.h>
35 #define GLABELS_MIME_TYPE "application/x-glabels"
37 static GtkRecentManager *model;
41 /*****************************************************************************/
42 /* Initialize recent files model. */
43 /*****************************************************************************/
47 gl_debug (DEBUG_RECENT, "START");
49 model = gtk_recent_manager_get_default ();
51 gl_debug (DEBUG_RECENT, "END");
55 /*****************************************************************************/
56 /* Get UTF8 filename from GtkRecentInfo structure. */
57 /*****************************************************************************/
59 gl_recent_get_utf8_filename (GtkRecentInfo *item)
63 gchar *utf8_filename = NULL;
65 gl_debug (DEBUG_RECENT, "START");
67 uri = gtk_recent_info_get_uri (item);
69 filename = g_filename_from_uri (uri, NULL, NULL);
70 if ( filename != NULL )
72 utf8_filename = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
77 gl_debug (DEBUG_RECENT, "END");
80 /*****************************************************************************/
81 /* Add file by UTF8 filename to recent model. */
82 /*****************************************************************************/
84 gl_recent_add_utf8_filename (gchar *utf8_filename)
86 GtkRecentData *recent_data;
90 static gchar *groups[2] = {
95 gl_debug (DEBUG_RECENT, "START");
97 recent_data = g_slice_new (GtkRecentData);
99 recent_data->display_name = NULL;
100 recent_data->description = NULL;
101 recent_data->mime_type = GLABELS_MIME_TYPE;
102 recent_data->app_name = (gchar *) g_get_application_name ();
103 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL);
104 recent_data->groups = groups;
105 recent_data->is_private = FALSE;
107 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
108 if ( filename != NULL )
111 uri = g_filename_to_uri (filename, NULL, NULL);
115 gtk_recent_manager_add_full (model, uri, recent_data);
123 g_free (recent_data->app_exec);
124 g_slice_free (GtkRecentData, recent_data);
126 gl_debug (DEBUG_RECENT, "END");
130 /*****************************************************************************/
131 /* Create a menu of recent files. */
132 /*****************************************************************************/
134 gl_recent_create_menu (void)
136 GtkWidget *recent_menu;
137 GtkRecentFilter *recent_filter;
139 gl_debug (DEBUG_RECENT, "START");
142 gtk_recent_chooser_menu_new_for_manager (model);
143 gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), FALSE);
144 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu), TRUE);
145 gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (recent_menu), gl_prefs->max_recents);
146 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu), GTK_RECENT_SORT_MRU);
147 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu), TRUE);
149 recent_filter = gtk_recent_filter_new ();
150 gtk_recent_filter_add_mime_type (recent_filter, GLABELS_MIME_TYPE);
151 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu), recent_filter);
153 gl_debug (DEBUG_RECENT, "END");