root/trunk/libtinymailui/tny-platform-factory.c
| Revision 3666 (checked in by jdapena, 7 months ago) |
|---|
| Line | |
|---|---|
| 1 | /* libtinymailui - The Tiny Mail user interface library |
| 2 | * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with self library; if not, write to the |
| 16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | /* The reason why this type is defined in libtinymailui rather than libtinymail |
| 21 | is because the factory also returns types defined in libtinymailui */ |
| 22 | |
| 23 | /** |
| 24 | * TnyPlatformFactory: |
| 25 | * |
| 26 | * A factory that creates some instances |
| 27 | * |
| 28 | * free-function: g_object_unref |
| 29 | **/ |
| 30 | |
| 31 | #include <config.h> |
| 32 | |
| 33 | #include <tny-platform-factory.h> |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * tny_platform_factory_new_msg: |
| 38 | * @self: a TnyPlatformFactory |
| 39 | * |
| 40 | * Create a new #TnyMsg instance. The returned instance must be |
| 41 | * unreferenced after use. |
| 42 | * |
| 43 | * returns: (caller-owns): a #TnyMsg instance |
| 44 | * since: 1.0 |
| 45 | * audience: application-developer, type-implementer |
| 46 | **/ |
| 47 | TnyMsg* |
| 48 | tny_platform_factory_new_msg (TnyPlatformFactory *self) |
| 49 | { |
| 50 | #ifdef DEBUG |
| 51 | if (!TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_msg) |
| 52 | g_critical ("You must implement tny_platform_factory_new_msg\n"); |
| 53 | #endif |
| 54 | |
| 55 | return TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_msg(self); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * tny_platform_factory_new_password_getter: |
| 61 | * @self: a TnyPlatformFactory |
| 62 | * |
| 63 | * Create a new #TnyPasswordGetter instance. The returned instance must be |
| 64 | * unreferenced after use. |
| 65 | * |
| 66 | * returns: (caller-owns): a #TnyPasswordGetter instance |
| 67 | * since: 1.0 |
| 68 | * audience: application-developer, type-implementer |
| 69 | **/ |
| 70 | TnyPasswordGetter* |
| 71 | tny_platform_factory_new_password_getter (TnyPlatformFactory *self) |
| 72 | { |
| 73 | #ifdef DEBUG |
| 74 | if (!TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_password_getter) |
| 75 | g_critical ("You must implement tny_platform_factory_new_password_getter\n"); |
| 76 | #endif |
| 77 | |
| 78 | return TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_password_getter(self); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * tny_platform_factory_new_mime_part: |
| 83 | * @self: a TnyPlatformFactory |
| 84 | * |
| 85 | * Create a new #TnyMimePart instance. The returned instance must be |
| 86 | * unreferenced after use. |
| 87 | * |
| 88 | * returns: (caller-owns): a #TnyMimePart instance |
| 89 | * since: 1.0 |
| 90 | * audience: application-developer, type-implementer |
| 91 | **/ |
| 92 | TnyMimePart* |
| 93 | tny_platform_factory_new_mime_part (TnyPlatformFactory *self) |
| 94 | { |
| 95 | #ifdef DEBUG |
| 96 | if (!TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_mime_part) |
| 97 | g_critical ("You must implement tny_platform_factory_new_mime_part\n"); |
| 98 | #endif |
| 99 | |
| 100 | return TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_mime_part(self); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * tny_platform_factory_new_account_store: |
| 106 | * @self: a TnyPlatformFactory |
| 107 | * |
| 108 | * Create a new #TnyAccountStore instance. The returned instance must be |
| 109 | * unreferenced after use. |
| 110 | * |
| 111 | * When implementing a platform-specific library, return a new #TnyAccountStore |
| 112 | * instance. It's allowed to reuse one instance, just make sure that you add a |
| 113 | * reference. |
| 114 | * |
| 115 | * returns: (caller-owns): a #TnyAccountStore instance |
| 116 | * since: 1.0 |
| 117 | * audience: application-developer, type-implementer |
| 118 | **/ |
| 119 | TnyAccountStore* |
| 120 | tny_platform_factory_new_account_store (TnyPlatformFactory *self) |
| 121 | { |
| 122 | #ifdef DEBUG |
| 123 | if (!TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_account_store) |
| 124 | g_critical ("You must implement tny_platform_factory_new_account_store\n"); |
| 125 | #endif |
| 126 | |
| 127 | return TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_account_store(self); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * tny_platform_factory_new_device: |
| 132 | * @self: a TnyPlatformFactory |
| 133 | * |
| 134 | * Create a new #TnyDevice instance. The returned instance must be |
| 135 | * unreferenced after use. |
| 136 | * |
| 137 | * When implementing a platform-specific library, return a new #TnyDevice instance. |
| 138 | * It's allowed to reuse one instance, just make sure that you add a reference. |
| 139 | * |
| 140 | * returns: (caller-owns): a #TnyDevice instance |
| 141 | * since: 1.0 |
| 142 | * audience: application-developer, type-implementer |
| 143 | **/ |
| 144 | TnyDevice* |
| 145 | tny_platform_factory_new_device (TnyPlatformFactory *self) |
| 146 | { |
| 147 | #ifdef DEBUG |
| 148 | if (!TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_device) |
| 149 | g_critical ("You must implement tny_platform_factory_new_device\n"); |
| 150 | #endif |
| 151 | |
| 152 | return TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_device(self); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * tny_platform_factory_new_msg_view: |
| 157 | * @self: a TnyPlatformFactory |
| 158 | * |
| 159 | * Create a new #TnyMsgView instance. The returned instance must be |
| 160 | * unreferenced after use. |
| 161 | * |
| 162 | * When implementing a platform-specific library, return a new #TnyMsgView instance. |
| 163 | * It's allowed to reuse one instance, just make sure that you add a reference. |
| 164 | * |
| 165 | * returns: (caller-owns): a #TnyMsgView instance |
| 166 | * since: 1.0 |
| 167 | * audience: application-developer, type-implementer |
| 168 | **/ |
| 169 | TnyMsgView* |
| 170 | tny_platform_factory_new_msg_view (TnyPlatformFactory *self) |
| 171 | { |
| 172 | #ifdef DEBUG |
| 173 | if (!TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_msg_view) |
| 174 | g_warning ("You must implement tny_platform_factory_new_msg_view\n"); |
| 175 | #endif |
| 176 | |
| 177 | return TNY_PLATFORM_FACTORY_GET_IFACE (self)->new_msg_view(self); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | static void |
| 182 | tny_platform_factory_base_init (gpointer g_class) |
| 183 | { |
| 184 | static gboolean initialized = FALSE; |
| 185 | |
| 186 | if (!initialized) |
| 187 | initialized = TRUE; |
| 188 | } |
| 189 | |
| 190 | static gpointer |
| 191 | tny_platform_factory_register_type (gpointer notused) |
| 192 | { |
| 193 | GType type = 0; |
| 194 | |
| 195 | static const GTypeInfo info = |
| 196 | { |
| 197 | sizeof (TnyPlatformFactoryIface), |
| 198 | tny_platform_factory_base_init, /* base_init */ |
| 199 | NULL, /* base_finalize */ |
| 200 | NULL, /* class_init */ |
| 201 | NULL, /* class_finalize */ |
| 202 | NULL, /* class_data */ |
| 203 | 0, |
| 204 | 0, /* n_preallocs */ |
| 205 | NULL /* instance_init */ |
| 206 | }; |
| 207 | type = g_type_register_static (G_TYPE_INTERFACE, |
| 208 | "TnyPlatformFactory", &info, 0); |
| 209 | |
| 210 | g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); |
| 211 | |
| 212 | return GUINT_TO_POINTER (type); |
| 213 | } |
| 214 | |
| 215 | GType |
| 216 | tny_platform_factory_get_type (void) |
| 217 | { |
| 218 | static GOnce once = G_ONCE_INIT; |
| 219 | g_once (&once, tny_platform_factory_register_type, NULL); |
| 220 | return GPOINTER_TO_UINT (once.retval); |
| 221 | } |
Note: See TracBrowser for help on using the browser.
