Fix crash on startup if an LV2 plugin has a bad .ttl file.
[ardour.git] / libs / glibmm2 / gio / src / loadableicon.ccg
1 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
3 /* Copyright (C) 2007 The giomm Development Team
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include <gio/gio.h>
21 #include <giomm/private/icon_p.h>
22 #include "slot_async.h"
23
24 namespace Gio
25 {
26
27 #ifdef GLIBMM_EXCEPTIONS_ENABLED
28 Glib::RefPtr<InputStream>
29 LoadableIcon::load(int size, Glib::ustring& type, const Glib::RefPtr<Cancellable>& cancellable)
30 #else
31 Glib::RefPtr<InputStream>
32 LoadableIcon::load(int size, Glib::ustring& type, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
33 #endif //GLIBMM_EXCEPTIONS_ENABLED
34 {
35   char* c_type;
36   GError* gerror = 0;
37   Glib::RefPtr<InputStream> retval =
38       Glib::wrap(g_loadable_icon_load(gobj(),
39                  size,
40                  &c_type,
41                  cancellable->gobj(),
42                  &gerror));
43 #ifdef GLIBMM_EXCEPTIONS_ENABLED
44   if(gerror)
45     ::Glib::Error::throw_exception(gerror);
46 #else
47   if(gerror)
48     error = ::Glib::Error::throw_exception(gerror);
49 #endif //GLIBMM_EXCEPTIONS_ENABLED
50
51   type = c_type;
52   g_free(c_type);
53   if(retval)
54     retval->reference(); //The function does not do a ref for us.
55   return retval;
56 }
57
58 #ifdef GLIBMM_EXCEPTIONS_ENABLED
59 Glib::RefPtr<InputStream>
60 LoadableIcon::load(int size, Glib::ustring& type)
61 #else
62 Glib::RefPtr<InputStream>
63 LoadableIcon::load(int size, Glib::ustring& type, std::auto_ptr<Glib::Error>& error)
64 #endif //GLIBMM_EXCEPTIONS_ENABLED
65 {
66   char* c_type;
67   GError* gerror = 0;
68   Glib::RefPtr<InputStream> retval =
69       Glib::wrap(g_loadable_icon_load(gobj(),
70                  size,
71                  &c_type,
72                  NULL,
73                  &gerror));
74 #ifdef GLIBMM_EXCEPTIONS_ENABLED
75   if(gerror)
76     ::Glib::Error::throw_exception(gerror);
77 #else
78   if(gerror)
79     error = ::Glib::Error::throw_exception(gerror);
80 #endif //GLIBMM_EXCEPTIONS_ENABLED
81
82   type = c_type;
83   g_free(c_type);
84   if(retval)
85     retval->reference(); //The function does not do a ref for us.
86   return retval;
87 }
88
89 void
90 LoadableIcon::load_async(int size, const SlotAsyncReady& slot, const
91                          Glib::RefPtr<Cancellable>& cancellable)
92 {
93   // Create a copy of the slot.
94   // A pointer to it will be passed through the callback's data parameter
95   // and deleted in the callback.
96   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
97
98   g_loadable_icon_load_async(gobj(),
99                              size,
100                              cancellable->gobj(),
101                              &SignalProxy_async_callback,
102                              slot_copy);
103 }
104
105 void
106 LoadableIcon::load_async(int size, const SlotAsyncReady& slot)
107 {
108   // Create a copy of the slot.
109   // A pointer to it will be passed through the callback's data parameter
110   // and deleted in the callback.
111   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
112
113   g_loadable_icon_load_async(gobj(),
114                              size,
115                              NULL,
116                              &SignalProxy_async_callback,
117                              slot_copy);
118 }
119
120 } // namespace Gio