Debian Codegraph @

gtk/src/recentmanager.ccg

raw
1 /* Copyright (C) 2006 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <glibmm/vectorutils.h>
18
19 #include <gtk/gtk.h>
20
21 namespace Gtk
22 {
23
24 bool RecentManager::add_item(const Glib::ustring& uri, const Data& data)
25 {
26 GtkRecentData c_data;
27 gboolean result;
28
29 // I wonder whether these should be const in the GTK+ API. armin.
30 c_data.display_name = data.display_name.empty() ? nullptr : const_cast<gchar*>(data.display_name.c_str());
31 c_data.description = const_cast<gchar*>(data.description.c_str());
32 c_data.mime_type = const_cast<gchar*>(data.mime_type.c_str());
33 c_data.app_name = const_cast<gchar*>(data.app_name.c_str());
34 c_data.app_exec = const_cast<gchar*>(data.app_exec.c_str());
35
36 c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar*)));
37 for(unsigned int i = 0; i < data.groups.size(); ++ i)
38 c_data.groups[i] = const_cast<gchar*>(data.groups[i].c_str());
39 c_data.groups[data.groups.size()] = nullptr;
40
41 c_data.is_private = data.is_private;
42
43 result = gtk_recent_manager_add_full(gobj(), uri.c_str(), &c_data);
44 g_free(c_data.groups);
45 return result == TRUE;
46 }
47
48 } //namespace Gtk