1.1 --- a/gmyth-dbus/src/gmyth-dbus-server.c Fri Oct 26 23:03:22 2007 +0100
1.2 +++ b/gmyth-dbus/src/gmyth-dbus-server.c Mon Oct 29 19:56:35 2007 +0000
1.3 @@ -26,15 +26,31 @@
1.4 #endif
1.5
1.6
1.7 +#include <glib/gi18n.h>
1.8 #include <gmyth/gmyth.h>
1.9 #include <dbus/dbus-glib-bindings.h>
1.10
1.11 -
1.12 #include "gmyth-dbus-common.h"
1.13 #include "gmyth-dbus-server.h"
1.14
1.15 #define MYTH_DEFAULT_DB "mythconverg"
1.16
1.17 +enum
1.18 +{
1.19 + GMYTH_DBUS_ERROR_MYTHTV,
1.20 + GMYTH_DBUS_ERROR_CONNECTION,
1.21 + GMYTH_DBUS_ERROR_EPG,
1.22 + GMYTH_DBUS_ERROR_SCHEDULE
1.23 +};
1.24 +
1.25 +#define GMYTH_DBUS_ERROR gmyth_dbus_error_quark ()
1.26 +
1.27 +GQuark
1.28 +gmyth_dbus_error_quark (void)
1.29 +{
1.30 + return g_quark_from_static_string ("gmyth-dbus-error-quark");
1.31 +}
1.32 +
1.33 typedef struct _GMythDbusServerPrivate GMythDbusServerPrivate;
1.34
1.35 struct _GMythDbusServerPrivate
1.36 @@ -83,10 +99,11 @@
1.37 gint channel_id,
1.38 const gchar *start_time,
1.39 const gchar *end_time,
1.40 - GPtrArray **program_list);
1.41 + GPtrArray **program_list,
1.42 + GError **error);
1.43 static gboolean gmyth_dbus_server_get_schedule_list (GObject *obj,
1.44 - GPtrArray **schedule_list);
1.45 -
1.46 + GPtrArray **schedule_list,
1.47 + GError **error);
1.48 static gboolean gmyth_dbus_server_connected (GObject *obj,
1.49 gboolean *status,
1.50 GError **error);
1.51 @@ -168,13 +185,20 @@
1.52 }
1.53
1.54 static gboolean
1.55 -gmyth_dbus_server_connect_epg (GMythDbusServer *server)
1.56 +gmyth_dbus_server_connect_epg (GMythDbusServer *server, GError **error)
1.57 {
1.58 GMythDbusServerPrivate *priv;
1.59 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
1.60
1.61 if (!priv->connected)
1.62 + {
1.63 + g_set_error (error,
1.64 + GMYTH_DBUS_ERROR,
1.65 + GMYTH_DBUS_ERROR_CONNECTION,
1.66 + _("Not connected"));
1.67 +
1.68 return FALSE;
1.69 + }
1.70
1.71 if (!priv->myth_epg)
1.72 {
1.73 @@ -183,6 +207,12 @@
1.74 {
1.75 g_object_unref (priv->myth_epg);
1.76 priv->myth_epg = NULL;
1.77 +
1.78 + g_set_error (error,
1.79 + GMYTH_DBUS_ERROR,
1.80 + GMYTH_DBUS_ERROR_EPG,
1.81 + _("Fail to connect with EPG"));
1.82 +
1.83 return FALSE;
1.84 }
1.85 }
1.86 @@ -191,13 +221,21 @@
1.87 }
1.88
1.89 static gboolean
1.90 -gmyth_dbus_server_connect_scheduler (GMythDbusServer *server)
1.91 +gmyth_dbus_server_connect_scheduler (GMythDbusServer *server,
1.92 + GError **error)
1.93 {
1.94 GMythDbusServerPrivate *priv;
1.95 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (server);
1.96
1.97 if (!priv->connected)
1.98 + {
1.99 + g_set_error (error,
1.100 + GMYTH_DBUS_ERROR,
1.101 + GMYTH_DBUS_ERROR_CONNECTION,
1.102 + _("Not connected"));
1.103 +
1.104 return FALSE;
1.105 + }
1.106
1.107 if (!priv->myth_scheduler)
1.108 {
1.109 @@ -207,6 +245,12 @@
1.110 {
1.111 g_object_unref (priv->myth_scheduler);
1.112 priv->myth_scheduler = NULL;
1.113 +
1.114 + g_set_error (error,
1.115 + GMYTH_DBUS_ERROR,
1.116 + GMYTH_DBUS_ERROR_SCHEDULE,
1.117 + _("Fail to connect with Schedule"));
1.118 +
1.119 return FALSE;
1.120 }
1.121 }
1.122 @@ -230,7 +274,7 @@
1.123
1.124 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1.125
1.126 - if (priv->myth_backend)
1.127 + if (priv->connected)
1.128 {
1.129 gmyth_dbus_server_disconnect (obj, NULL);
1.130 }
1.131 @@ -249,10 +293,14 @@
1.132 }
1.133 else
1.134 {
1.135 - g_debug ("FAIL TO CONNECT");
1.136 g_object_unref (priv->myth_backend);
1.137 priv->myth_backend = NULL;
1.138 *result = FALSE;
1.139 +
1.140 + g_set_error (error,
1.141 + GMYTH_DBUS_ERROR,
1.142 + GMYTH_DBUS_ERROR_CONNECTION,
1.143 + _("Fail to connect with backend"));
1.144 }
1.145
1.146 priv->connected = *result;
1.147 @@ -329,6 +377,16 @@
1.148
1.149 socket = gmyth_backend_info_get_connected_socket (priv->myth_backend);
1.150
1.151 + if (!socket)
1.152 + {
1.153 + g_set_error (error,
1.154 + GMYTH_DBUS_ERROR,
1.155 + GMYTH_DBUS_ERROR_MYTHTV,
1.156 + _("MythTv not avaliable"));
1.157 + return FALSE;
1.158 +
1.159 + }
1.160 +
1.161 details = NULL;
1.162 gmyth_util_get_backend_details (socket,
1.163 &details);
1.164 @@ -341,6 +399,13 @@
1.165
1.166 ret = TRUE;
1.167 }
1.168 + else
1.169 + {
1.170 + g_set_error (error,
1.171 + GMYTH_DBUS_ERROR,
1.172 + GMYTH_DBUS_ERROR_MYTHTV,
1.173 + _("Fail to get MythTv details"));
1.174 + }
1.175
1.176 g_object_unref (socket);
1.177
1.178 @@ -375,8 +440,10 @@
1.179
1.180 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
1.181
1.182 - if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj)))
1.183 + if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
1.184 + {
1.185 return FALSE;
1.186 + }
1.187
1.188 ch_type = GMYTH_DBUS_CHANNEL_G_TYPE;
1.189
1.190 @@ -391,6 +458,13 @@
1.191 *info = g_value_get_boxed (&v);
1.192 return TRUE;
1.193 }
1.194 + else
1.195 + {
1.196 + g_set_error (error,
1.197 + GMYTH_DBUS_ERROR,
1.198 + GMYTH_DBUS_ERROR_EPG,
1.199 + _("no channel info avaliable"));
1.200 + }
1.201
1.202 return FALSE;
1.203 }
1.204 @@ -411,7 +485,7 @@
1.205 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1.206
1.207 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
1.208 - if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj)))
1.209 + if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
1.210 return FALSE;
1.211
1.212
1.213 @@ -460,7 +534,8 @@
1.214 gint channel_id,
1.215 const gchar *start_time,
1.216 const gchar *end_time,
1.217 - GPtrArray **programs)
1.218 + GPtrArray **programs,
1.219 + GError **error)
1.220 {
1.221 GList *list;
1.222 GList *walk;
1.223 @@ -474,7 +549,7 @@
1.224 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1.225
1.226 g_return_val_if_fail (priv->myth_backend, FALSE);
1.227 - if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj)))
1.228 + if (!gmyth_dbus_server_connect_epg (GMYTH_DBUS_SERVER (obj), error))
1.229 return FALSE;
1.230
1.231 g_time_val_from_iso8601 (start_time, &start_time_val);
1.232 @@ -574,7 +649,7 @@
1.233
1.234 g_return_val_if_fail (priv->myth_backend, FALSE);
1.235
1.236 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.237 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.238 return FALSE;
1.239
1.240 record_type = GMYTH_DBUS_RECORD_G_TYPE;
1.241 @@ -597,6 +672,14 @@
1.242
1.243 return TRUE;
1.244 }
1.245 + else
1.246 + {
1.247 + g_set_error (error,
1.248 + GMYTH_DBUS_ERROR,
1.249 + GMYTH_DBUS_ERROR_EPG,
1.250 + _("no record info avaliable"));
1.251 +
1.252 + }
1.253
1.254 return FALSE;
1.255 }
1.256 @@ -617,7 +700,7 @@
1.257 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1.258
1.259 g_return_val_if_fail (priv->myth_backend != NULL, FALSE);
1.260 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.261 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.262 return FALSE;
1.263
1.264
1.265 @@ -652,7 +735,8 @@
1.266
1.267 static gboolean
1.268 gmyth_dbus_server_get_schedule_list (GObject *obj,
1.269 - GPtrArray **schedules)
1.270 + GPtrArray **schedules,
1.271 + GError **error)
1.272 {
1.273 GList *list;
1.274 GList *walk;
1.275 @@ -664,7 +748,7 @@
1.276 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1.277
1.278 g_return_val_if_fail (priv->myth_backend, FALSE);
1.279 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.280 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.281 return FALSE;
1.282
1.283
1.284 @@ -733,12 +817,25 @@
1.285 g_return_val_if_fail (priv->myth_backend, FALSE);
1.286
1.287 if (!gmyth_util_file_exists (priv->myth_backend, uri))
1.288 + {
1.289 + g_set_error (error,
1.290 + GMYTH_DBUS_ERROR,
1.291 + GMYTH_DBUS_ERROR_MYTHTV,
1.292 + _("File not exists"));
1.293 +
1.294 goto fail;
1.295 + }
1.296
1.297 file_transfer = gmyth_file_transfer_new (priv->myth_backend);
1.298
1.299 if (!gmyth_file_transfer_open (file_transfer, uri))
1.300 + {
1.301 + g_set_error (error,
1.302 + GMYTH_DBUS_ERROR,
1.303 + GMYTH_DBUS_ERROR_MYTHTV,
1.304 + _("Fail to open file"));
1.305 goto fail;
1.306 + }
1.307
1.308 filesize = gmyth_file_transfer_get_filesize (file_transfer);
1.309 if (filesize <= 0)
1.310 @@ -747,13 +844,27 @@
1.311 *image = g_byte_array_new ();
1.312 result = gmyth_file_transfer_read (file_transfer, *image, filesize, FALSE);
1.313 if (result == GMYTH_FILE_READ_ERROR)
1.314 + {
1.315 + g_set_error (error,
1.316 + GMYTH_DBUS_ERROR,
1.317 + GMYTH_DBUS_ERROR_MYTHTV,
1.318 + _("Fail to read file"));
1.319 +
1.320 goto fail;
1.321 + }
1.322
1.323 gmyth_file_transfer_close (file_transfer);
1.324 g_object_unref (file_transfer);
1.325
1.326 if (filesize > (*image)->len)
1.327 + {
1.328 + g_set_error (error,
1.329 + GMYTH_DBUS_ERROR,
1.330 + GMYTH_DBUS_ERROR_MYTHTV,
1.331 + _("Empty file"));
1.332 +
1.333 goto fail;
1.334 + }
1.335
1.336 return TRUE;
1.337
1.338 @@ -785,12 +896,23 @@
1.339 *icon = NULL;
1.340
1.341 if (channel == NULL)
1.342 + {
1.343 + g_set_error (error,
1.344 + GMYTH_DBUS_ERROR,
1.345 + GMYTH_DBUS_ERROR_MYTHTV,
1.346 + _("Invalid channel"));
1.347 +
1.348 return FALSE;
1.349 + }
1.350
1.351 if (!gmyth_epg_channel_has_icon(priv->myth_epg, channel))
1.352 {
1.353 gmyth_channel_info_free (channel);
1.354 - g_debug("Channel does not have icon available");
1.355 + g_set_error (error,
1.356 + GMYTH_DBUS_ERROR,
1.357 + GMYTH_DBUS_ERROR_MYTHTV,
1.358 + _("Channel does not have icon available"));
1.359 +
1.360 return FALSE;
1.361 }
1.362
1.363 @@ -802,7 +924,11 @@
1.364 &icon_length))
1.365 {
1.366 gmyth_channel_info_free (channel);
1.367 - g_warning("Could not get channel icon for channel id = %u", channel_id);
1.368 + g_set_error (error,
1.369 + GMYTH_DBUS_ERROR,
1.370 + GMYTH_DBUS_ERROR_MYTHTV,
1.371 + _("Could not get channel icon for channel id = %u"),
1.372 + channel_id);
1.373 return FALSE;
1.374 }
1.375
1.376 @@ -828,7 +954,7 @@
1.377 priv = GMYTH_DBUS_SERVER_GET_PRIVATE (obj);
1.378
1.379 g_return_val_if_fail (priv->myth_backend, FALSE);
1.380 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.381 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.382 return FALSE;
1.383
1.384 ret = gmyth_scheduler_stop_recording (priv->myth_scheduler,
1.385 @@ -893,7 +1019,7 @@
1.386
1.387 g_return_val_if_fail (priv->myth_backend, FALSE);
1.388
1.389 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.390 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.391 return FALSE;
1.392
1.393
1.394 @@ -980,7 +1106,7 @@
1.395
1.396 g_return_val_if_fail (priv->myth_backend, FALSE);
1.397
1.398 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.399 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.400 return FALSE;
1.401
1.402 g_time_val_from_iso8601 (start_time, &start_vtime);
1.403 @@ -1020,7 +1146,7 @@
1.404
1.405 g_return_val_if_fail (priv->myth_backend, FALSE);
1.406
1.407 - if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj)))
1.408 + if (!gmyth_dbus_server_connect_scheduler (GMYTH_DBUS_SERVER (obj), error))
1.409 return FALSE;
1.410
1.411 return gmyth_scheduler_delete_schedule (priv->myth_scheduler, schedule_id);