3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels 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.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
32 #define GLABELS_MIME_TYPE "application/x-glabels"
34 static GtkRecentManager *model;
37 /*****************************************************************************/
38 /* Initialize recent files model. */
39 /*****************************************************************************/
43 gl_debug (DEBUG_RECENT, "START");
45 model = gtk_recent_manager_get_default ();
47 gl_debug (DEBUG_RECENT, "END");
51 /*****************************************************************************/
52 /* Get UTF8 filename from GtkRecentInfo structure. */
53 /*****************************************************************************/
55 gl_recent_get_utf8_filename (GtkRecentInfo *item)
59 gchar *utf8_filename = NULL;
61 gl_debug (DEBUG_RECENT, "START");
63 uri = gtk_recent_info_get_uri (item);
65 filename = g_filename_from_uri (uri, NULL, NULL);
66 if ( filename != NULL )
68 utf8_filename = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
73 gl_debug (DEBUG_RECENT, "END");
77 /*****************************************************************************/
78 /* Add file by UTF8 filename to recent model. */
79 /*****************************************************************************/
81 gl_recent_add_utf8_filename (gchar *utf8_filename)
83 GtkRecentData *recent_data;
87 static gchar *groups[2] = {
92 gl_debug (DEBUG_RECENT, "START");
94 recent_data = g_slice_new (GtkRecentData);
96 recent_data->display_name = NULL;
97 recent_data->description = NULL;
98 recent_data->mime_type = GLABELS_MIME_TYPE;
99 recent_data->app_name = (gchar *) g_get_application_name ();
100 recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL);
101 recent_data->groups = groups;
102 recent_data->is_private = FALSE;
104 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
105 if ( filename != NULL )
108 uri = g_filename_to_uri (filename, NULL, NULL);
112 gtk_recent_manager_add_full (model, uri, recent_data);
120 g_free (recent_data->app_exec);
121 g_slice_free (GtkRecentData, recent_data);
123 gl_debug (DEBUG_RECENT, "END");
127 /*****************************************************************************/
128 /* Create a menu of recent files. */
129 /*****************************************************************************/
131 gl_recent_create_menu (void)
133 GtkWidget *recent_menu;
134 GtkRecentFilter *recent_filter;
136 gl_debug (DEBUG_RECENT, "START");
139 gtk_recent_chooser_menu_new_for_manager (model);
140 gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_menu), FALSE);
141 gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (recent_menu), TRUE);
142 gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (recent_menu),
143 gl_prefs_model_get_max_recents (gl_prefs));
144 gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_menu), GTK_RECENT_SORT_MRU);
145 gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_menu), TRUE);
147 recent_filter = gtk_recent_filter_new ();
148 gtk_recent_filter_add_mime_type (recent_filter, GLABELS_MIME_TYPE);
149 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu), recent_filter);
151 gl_debug (DEBUG_RECENT, "END");
159 * Local Variables: -- emacs
161 * c-basic-offset: 8 -- emacs
162 * tab-width: 8 -- emacs
163 * indent-tabs-mode: nil -- emacs