00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00027 #include "give_bluetooth.h"
00028
00029 #include <dbus/dbus.h>
00030 #include <dbus/dbus-glib.h>
00031
00032 #include <conbtdialogs-dbus.h>
00033
00034 typedef struct _give_bluetooth_private give_bluetooth_private;
00035
00036 #define GIVE_BLUETOOTH_GET_PRIVATE(obj) \
00037 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
00038 GIVE_BLUETOOTH_TYPE, \
00039 give_bluetooth_private));
00040
00041
00044 struct _give_bluetooth_private
00045 {
00046 DBusGProxy *dbus_proxy;
00048 };
00049
00050
00055 GType give_bluetooth_get_type (void);
00056 static void give_bluetooth_class_init (give_bluetoothClass *klass);
00057 static void give_bluetooth_init (give_bluetooth *self);
00058 static void give_bluetooth_finalize (GObject* self);
00059
00060
00066 give_bluetooth* give_bluetooth_new(void);
00067 void give_bluetooth_send_file(give_bluetooth *self, gchar **files);
00068
00079 GType
00080 give_bluetooth_get_type (void)
00081 {
00082 g_message(__PRETTY_FUNCTION__);
00083
00084 static GType type = 0;
00085 type = g_type_from_name ("give_bluetooth");
00086
00087 if (type == 0){
00088 static const GTypeInfo info = {
00089 sizeof (give_bluetoothClass),
00090 (GBaseInitFunc) NULL,
00091 (GBaseFinalizeFunc) NULL,
00092 (GClassInitFunc) give_bluetooth_class_init,
00093 NULL,
00094 NULL,
00095 sizeof (give_bluetooth),
00096 0,
00097 (GInstanceInitFunc) give_bluetooth_init
00098 };
00099
00100 type = g_type_register_static ( G_TYPE_OBJECT,
00101 "give_bluetooth",
00102 &info,
00103 0);
00104 }
00105
00106 return type;
00107 }
00108
00115 static void
00116 give_bluetooth_class_init (give_bluetoothClass *klass)
00117 {
00118 g_message(__PRETTY_FUNCTION__);
00119
00120 GObjectClass *object_class;
00121 object_class = (GObjectClass*) klass;
00122
00123 object_class->finalize = give_bluetooth_finalize;
00124
00125 g_type_class_add_private (klass, sizeof (give_bluetooth_private));
00126 }
00127
00135 static void
00136 give_bluetooth_init (give_bluetooth *self)
00137 {
00138 g_message(__PRETTY_FUNCTION__);
00139
00140 give_bluetooth_private *priv;
00141 GError *error = NULL;
00142 DBusGConnection *dbus_connection = NULL;
00143
00144 g_assert(self);
00145 g_assert(GIVE_BLUETOOTH_IS_OBJECT(self));
00146
00147 priv = GIVE_BLUETOOTH_GET_PRIVATE (self);
00148 g_assert (priv);
00149
00150
00151 dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
00152 if (error){
00153 g_critical ("%s: Error getting system dbus: %s",
00154 __PRETTY_FUNCTION__,error->message);
00155 g_error_free(error);
00156 g_assert(dbus_connection);
00157 }
00158
00159
00160 priv->dbus_proxy = dbus_g_proxy_new_for_name(dbus_connection,
00161 CONBTDIALOGS_DBUS_SERVICE,
00162 CONBTDIALOGS_DBUS_PATH,
00163 CONBTDIALOGS_DBUS_INTERFACE);
00164 if (!priv->dbus_proxy){
00165 g_critical ("%s: Error getting dbus proxy connection: %s",
00166 __PRETTY_FUNCTION__,error->message);
00167 g_error_free(error);
00168 g_assert(priv->dbus_proxy);
00169 }
00170 }
00171
00176 static void
00177 give_bluetooth_finalize (GObject* self)
00178 {
00179 g_message(__PRETTY_FUNCTION__);
00180
00181 give_bluetooth_private *priv;
00182
00183 g_assert(self);
00184 g_assert(GIVE_BLUETOOTH_IS_OBJECT(self));
00185
00186 priv = GIVE_BLUETOOTH_GET_PRIVATE (self);
00187 g_assert (priv);
00188
00189
00190 g_object_unref(G_OBJECT(priv->dbus_proxy));
00191 }
00192
00197 give_bluetooth*
00198 give_bluetooth_new(void)
00199 {
00200 g_message(__PRETTY_FUNCTION__);
00201
00202 give_bluetooth *give_bluetooth_object;
00203
00204 give_bluetooth_object = g_object_new(GIVE_BLUETOOTH_TYPE,NULL);
00205 g_assert(give_bluetooth_object);
00206
00207 return give_bluetooth_object;
00208 }
00209
00219 void
00220 give_bluetooth_send_file(give_bluetooth *self, gchar **files)
00221 {
00222 g_message(__PRETTY_FUNCTION__);
00223
00224 GError *error = NULL;
00225 give_bluetooth_private *priv;
00226
00227 g_assert(self);
00228 g_assert(GIVE_BLUETOOTH_IS_OBJECT(self));
00229
00230 priv = GIVE_BLUETOOTH_GET_PRIVATE (self);
00231 g_assert (priv);
00232
00233 g_assert(files);
00234
00235
00236 if (!dbus_g_proxy_call(priv->dbus_proxy, CONBTDIALOGS_SEND_FILE_REQ,
00237 &error,
00238 G_TYPE_STRV, files, G_TYPE_INVALID,
00239 G_TYPE_INVALID))
00240 {
00241 g_warning("%s: Error sending file request to btdialogs: %s",
00242 __PRETTY_FUNCTION__,error->message);
00243 g_error_free(error);
00244 }
00245 }