diff options
Diffstat (limited to 'src/lib/obex_agent.c')
-rw-r--r-- | src/lib/obex_agent.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/lib/obex_agent.c b/src/lib/obex_agent.c index f835f04..b539a77 100644 --- a/src/lib/obex_agent.c +++ b/src/lib/obex_agent.c @@ -41,6 +41,7 @@ struct _ObexAgentPrivate { gchar *root_folder; + gboolean auto_accept; gchar *current_name; guint registration_id; void (*agent_released_callback)(ObexAgent *, gpointer); @@ -54,6 +55,7 @@ G_DEFINE_TYPE_WITH_PRIVATE(ObexAgent, obex_agent, G_TYPE_OBJECT); enum { PROP_0, PROP_ROOT_FOLDER, /* readwrite, construct only */ + PROP_AUTO_ACCPET, /* readwrite, construct only */ }; static const gchar *_obex_agent_introspect_xml = "<node name=\"/org/blueztools/obex\">\n\t<interface name=\"org.bluez.obex.Agent1\">\n\t\t<method name=\"Release\">\n\t\t</method>\n\t\t<method name=\"AuthorizePush\">\n\t\t\t<arg name=\"transfer\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"filepath\" direction=\"out\" type=\"s\"/>\n\t\t</method>\n\t\t<method name=\"Cancel\">\n\t\t</method>\n\t</interface>\n</node>\n"; @@ -112,7 +114,16 @@ static void obex_agent_class_init(ObexAgentClass *klass) /* string RootFolder [readwrite, construct only] */ pspec = g_param_spec_string("RootFolder", "root_folder", "Root folder location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property(gobject_class, PROP_ROOT_FOLDER, pspec); - + + if (pspec) { + g_param_spec_unref(pspec); + pspec = NULL; + } + + /* boolean AutoAccept [readwrite, construct only] */ + pspec = g_param_spec_boolean("AutoAccept", "auto_accept", "Automatically accept incoming files", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property(gobject_class, PROP_AUTO_ACCPET, pspec); + if (pspec) g_param_spec_unref(pspec); } @@ -127,6 +138,7 @@ static void obex_agent_init(ObexAgent *self) self->priv->user_data = NULL; self->priv->agent_approved_callback = NULL; self->priv->approved_user_data = NULL; + self->priv->auto_accept = FALSE; GError *error = NULL; GDBusInterfaceVTable obex_agent_table; @@ -151,6 +163,10 @@ static void _obex_agent_get_property(GObject *object, guint property_id, GValue g_value_set_string(value, self->priv->root_folder); break; + case PROP_AUTO_ACCPET: + g_value_set_boolean(value, self->priv->auto_accept); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; @@ -166,6 +182,10 @@ static void _obex_agent_set_property(GObject *object, guint property_id, const G self->priv->root_folder = g_value_dup_string(value); break; + case PROP_AUTO_ACCPET: + self->priv->auto_accept = g_value_get_boolean(value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; @@ -173,9 +193,9 @@ static void _obex_agent_set_property(GObject *object, guint property_id, const G } /* Constructor */ -ObexAgent *obex_agent_new(const gchar *root_folder) +ObexAgent *obex_agent_new(const gchar *root_folder, const gboolean auto_accept) { - return g_object_new(OBEX_AGENT_TYPE, "RootFolder", root_folder, NULL); + return g_object_new(OBEX_AGENT_TYPE, "RootFolder", root_folder, "AutoAccept", auto_accept, NULL); } /* Methods */ static void _obex_agent_method_call_func(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) @@ -199,12 +219,16 @@ static void _obex_agent_method_call_func(GDBusConnection *connection, const gcha g_object_unref(transfer_t); gchar yn[4] = {0,}; - g_print("Accept (yes/no)? "); - errno = 0; - if (scanf("%3s", yn) == EOF && errno) - { - g_warning("%s\n", strerror(errno)); - } + if (TRUE == self->priv->auto_accept) + yn[0] = 'y'; + else { + g_print("Accept (yes/no)? "); + errno = 0; + if (scanf("%3s", yn) == EOF && errno) + { + g_warning("%s\n", strerror(errno)); + } + } if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) { // IMPORTANT NOTE! |