Debian Codegraph @

gtk/src/recentfilter.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 <gtk/gtk.h>
18
19 #include <glibmm/ustring.h>
20
21 // This Signal Proxy allows the C++ coder to specify a sigc::slot instead of a static function.
22
23 static gboolean SignalProxy_Custom_gtk_callback(const GtkRecentFilterInfo* filter_info, gpointer data)
24 {
25 const auto the_slot = static_cast<Gtk::RecentFilter::SlotCustom*>(data);
26
27 try
28 {
29 // Create a suitable C++ instance to pass to the C++ method:
30 Gtk::RecentFilter::Info cppInfo;
31 cppInfo.contains = (Gtk::RecentFilterFlags)filter_info->contains;
32 cppInfo.uri = Glib::convert_const_gchar_ptr_to_ustring(filter_info->uri);
33 cppInfo.display_name = Glib::convert_const_gchar_ptr_to_ustring(filter_info->display_name);
34 cppInfo.mime_type = Glib::convert_const_gchar_ptr_to_ustring(filter_info->mime_type);
35
36 // Create string lists from char**s.
37
38 for(int i = 0; filter_info->groups[i] != nullptr; ++i)
39 {
40 cppInfo.groups.emplace_back( Glib::convert_const_gchar_ptr_to_ustring(filter_info->groups[i]) );
41 }
42 for(int i = 0; filter_info->applications[i] != nullptr; ++i)
43 {
44 cppInfo.applications.emplace_back( Glib::convert_const_gchar_ptr_to_ustring(filter_info->applications[i]) );
45 }
46
47 cppInfo.age = filter_info->age;
48
49 return (*the_slot)(cppInfo);
50 }
51 catch(...)
52 {
53 Glib::exception_handlers_invoke();
54 return false; // arbitrary default;
55 }
56 }
57
58 static void SignalProxy_Custom_gtk_callback_destroy(void* data)
59 {
60 delete static_cast<Gtk::RecentFilter::SlotCustom*>(data);
61 }
62
63 namespace Gtk
64 {
65
66 RecentFilter::Info::Info()
67 : contains(Gtk::RECENT_FILTER_MIME_TYPE), //arbitrary default
68 age(0)
69 {
70 }
71
72 void RecentFilter::add_custom(RecentFilterFlags needed, const SlotCustom& slot)
73 {
74 // Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
75 // It will be deleted when SignalProxy_Custom_gtk_callback_destroy() is called.
76 auto slot_copy = new SlotCustom(slot);
77
78 gtk_recent_filter_add_custom(gobj(), (GtkRecentFilterFlags)needed,
79 &SignalProxy_Custom_gtk_callback,
80 slot_copy,
81 &SignalProxy_Custom_gtk_callback_destroy);
82 }
83
84 } // namespace Gtk