Fix crash on startup if an LV2 plugin has a bad .ttl file.
[ardour.git] / libs / glibmm2 / gio / src / fileenumerator.ccg
1 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
3 /* Copyright (C) 2007 The gtkmm 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/file.h>
22 #include <glibmm/error.h>
23 #include <glibmm/exceptionhandler.h>
24 #include "slot_async.h"
25
26 namespace Gio
27 {
28
29 void
30 FileEnumerator::next_files_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int num_files, int io_priority)
31 {
32   // Create a copy of the slot.
33   // A pointer to it will be passed through the callback's data parameter
34   // and deleted in the callback.
35   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
36
37   g_file_enumerator_next_files_async(gobj(),
38                                      num_files,
39                                      io_priority,
40                                      cancellable->gobj(),
41                                      &SignalProxy_async_callback,
42                                      slot_copy);
43 }
44
45 void
46 FileEnumerator::next_files_async(const SlotAsyncReady& slot, int num_files, int io_priority)
47 {
48   // Create a copy of the slot.
49   // A pointer to it will be passed through the callback's data parameter
50   // and deleted in the callback.
51   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
52
53   g_file_enumerator_next_files_async(gobj(),
54                                      num_files,
55                                      io_priority,
56                                      NULL, // cancellable
57                                      &SignalProxy_async_callback,
58                                      slot_copy);
59 }
60
61 void
62 FileEnumerator::close_async(int io_priority,
63                             const Glib::RefPtr<Cancellable>& cancellable,
64                             const SlotAsyncReady& slot)
65 {
66 // Create a copy of the slot.
67   // A pointer to it will be passed through the callback's data parameter
68   // and deleted in the callback.
69   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
70
71   g_file_enumerator_close_async(gobj(),
72                                 io_priority,
73                                 cancellable->gobj(),
74                                 &SignalProxy_async_callback,
75                                 slot_copy);
76 }
77
78 void
79 FileEnumerator::close_async(int io_priority,
80                             const SlotAsyncReady& slot)
81 {
82   // Create a copy of the slot.
83   // A pointer to it will be passed through the callback's data parameter
84   // and deleted in the callback.
85   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
86
87   g_file_enumerator_close_async(gobj(),
88                                 io_priority,
89                                 NULL, // cancellable
90                                 &SignalProxy_async_callback,
91                                 slot_copy);
92 }
93
94 #ifdef GLIBMM_EXCEPTIONS_ENABLED
95 Glib::RefPtr<FileInfo> FileEnumerator::next_file()
96 #else
97 Glib::RefPtr<FileInfo> FileEnumerator::next_file(std::auto_ptr<Glib::Error>& error)
98 #endif //GLIBMM_EXCEPTIONS_ENABLED
99 {
100   GError* gerror = 0;
101   Glib::RefPtr<FileInfo> retvalue = Glib::wrap(g_file_enumerator_next_file(gobj(), NULL, &(gerror)));
102 #ifdef GLIBMM_EXCEPTIONS_ENABLED
103   if(gerror)
104     ::Glib::Error::throw_exception(gerror);
105 #else
106   if(gerror)
107     error = ::Glib::Error::throw_exception(gerror);
108 #endif //GLIBMM_EXCEPTIONS_ENABLED
109
110   return retvalue;
111 }
112
113 #ifdef GLIBMM_EXCEPTIONS_ENABLED
114 bool FileEnumerator::close()
115 #else
116 bool FileEnumerator::close(std::auto_ptr<Glib::Error>& error)
117 #endif //GLIBMM_EXCEPTIONS_ENABLED
118 {
119   GError* gerror = 0;
120   bool retvalue = g_file_enumerator_close(gobj(), NULL, &(gerror));
121 #ifdef GLIBMM_EXCEPTIONS_ENABLED
122   if(gerror)
123     ::Glib::Error::throw_exception(gerror);
124 #else
125   if(gerror)
126     error = ::Glib::Error::throw_exception(gerror);
127 #endif //GLIBMM_EXCEPTIONS_ENABLED
128
129   return retvalue;
130 }
131
132 } // namespace Gio