Commit 772f1b88 authored by Mohammed Sadiq's avatar Mohammed Sadiq
Browse files

wip

parent dd053607
Pipeline #57129 failed with stages
in 2 minutes and 56 seconds
......@@ -24,6 +24,7 @@
#include "calls-mm-origin.h"
#include "calls-origin.h"
#include "calls-ussd.h"
#include "calls-mm-call.h"
#include "calls-message-source.h"
......@@ -35,16 +36,21 @@ struct _CallsMMOrigin
GObject parent_instance;
MMObject *mm_obj;
MMModemVoice *voice;
MMModem3gppUssd *ussd;
gulong ussd_handle_id;
gchar *name;
GHashTable *calls;
};
static void calls_mm_origin_message_source_interface_init (CallsOriginInterface *iface);
static void calls_mm_origin_origin_interface_init (CallsOriginInterface *iface);
static void calls_mm_origin_ussd_interface_init (CallsUssdInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsMMOrigin, calls_mm_origin, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_mm_origin_message_source_interface_init)
G_IMPLEMENT_INTERFACE (CALLS_TYPE_USSD,
calls_mm_origin_ussd_interface_init)
G_IMPLEMENT_INTERFACE (CALLS_TYPE_ORIGIN,
calls_mm_origin_origin_interface_init))
......@@ -56,6 +62,52 @@ enum {
static GParamSpec *props[PROP_LAST_PROP];
static void
ussd_initiate_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
MMModem3gppUssd *ussd = (MMModem3gppUssd *)object;
CallsMMOrigin *self;
g_autofree char *response = NULL;
g_autoptr(GError) error = NULL;
self = user_data;
g_assert (CALLS_IS_MM_ORIGIN (self));
g_assert (MM_IS_MODEM_3GPP_USSD (ussd));
response = mm_modem_3gpp_ussd_initiate_finish (ussd, result, &error);
g_warning ("response: %s", response);
if (response)
g_signal_emit_by_name (self, "ussd-added", response);
else
g_signal_emit_by_name (self, "ussd-cancelled");
}
static CallsUssdState
calls_mm_ussd_get_state (CallsUssd *ussd)
{
CallsMMOrigin *self = CALLS_MM_ORIGIN (ussd);
if (!self->ussd)
return CALLS_USSD_STATE_UNKNOWN;
return mm_modem_3gpp_ussd_get_state (self->ussd);
}
static void
calls_mm_ussd_initiate (CallsUssd *ussd,
const char *command)
{
CallsMMOrigin *self = CALLS_MM_ORIGIN (ussd);
if (self->ussd)
mm_modem_3gpp_ussd_initiate (self->ussd, command, NULL,
ussd_initiate_cb, self);
}
static const gchar *
get_name (CallsOrigin *origin)
{
......@@ -427,6 +479,32 @@ modem_get_name (MMModem *modem)
}
static void
call_mm_ussd_state_changed_cb (CallsMMOrigin *self)
{
g_assert (CALLS_IS_MM_ORIGIN (self));
g_object_notify (G_OBJECT (self), "ussd-state");
}
static void
call_mm_ussd_changed_cb (CallsMMOrigin *self)
{
g_assert (CALLS_IS_MM_ORIGIN (self));
if (self->ussd_handle_id)
g_signal_handler_disconnect (self, self->ussd_handle_id);
self->ussd_handle_id = 0;
g_clear_object (&self->ussd);
self->ussd = mm_object_get_modem_3gpp_ussd (self->mm_obj);
if (self->ussd)
self->ussd_handle_id = g_signal_connect_object (self->ussd, "notify::state",
G_CALLBACK (call_mm_ussd_state_changed_cb), self,
G_CONNECT_SWAPPED);
}
static void
constructed (GObject *object)
{
......@@ -435,6 +513,11 @@ constructed (GObject *object)
self->name = modem_get_name (mm_object_get_modem (self->mm_obj));
g_signal_connect_object (self->mm_obj, "notify::modem3gpp-ussd",
G_CALLBACK (call_mm_ussd_changed_cb), self,
G_CONNECT_SWAPPED);
call_mm_ussd_changed_cb (self);
self->voice = mm_object_get_modem_voice (self->mm_obj);
g_assert (self->voice != NULL);
......@@ -460,6 +543,7 @@ dispose (GObject *object)
remove_calls (self, NULL);
g_clear_object (&self->mm_obj);
g_clear_object (&self->ussd);
G_OBJECT_CLASS (calls_mm_origin_parent_class)->dispose (object);
}
......@@ -504,6 +588,16 @@ calls_mm_origin_message_source_interface_init (CallsOriginInterface *iface)
}
static void
calls_mm_origin_ussd_interface_init (CallsUssdInterface *iface)
{
iface->get_state = calls_mm_ussd_get_state;
iface->initiate = calls_mm_ussd_initiate;
/* iface->respond = calls_mm_ussd_respond; */
/* iface->cancel = calls_mm_ussd_cancel; */
}
static void
calls_mm_origin_origin_interface_init (CallsOriginInterface *iface)
{
......
......@@ -24,6 +24,7 @@
#include "calls-main-window.h"
#include "calls-origin.h"
#include "calls-ussd.h"
#include "calls-call-holder.h"
#include "calls-call-selector-item.h"
#include "calls-new-call-box.h"
......@@ -59,6 +60,12 @@ struct _CallsMainWindow
GtkLabel *permanent_error_label;
CallsNewCallBox *new_call;
HdyDialog *ussd_dialog;
GtkLabel *ussd_label;
GtkEntry *ussd_entry;
GtkButton *ussd_cancel_button;
GtkButton *ussd_reply_button;
};
G_DEFINE_TYPE (CallsMainWindow, calls_main_window, GTK_TYPE_APPLICATION_WINDOW);
......@@ -137,6 +144,42 @@ set_switcher_bar_reveal (GBinding *binding,
}
static void
window_ussd_added_cb (CallsMainWindow *self,
CallsUssd *ussd,
char *response)
{
int result;
g_assert (CALLS_IS_MAIN_WINDOW (self));
g_assert (CALLS_IS_USSD (ussd));
if (!response || !*response)
return;
gtk_label_set_label (self->ussd_label, response);
result = gtk_dialog_run (GTK_DIALOG (self->ussd_dialog));
if (result == GTK_RESPONSE_CLOSE)
gtk_window_close (GTK_WINDOW (self->ussd_dialog));
}
static void
window_ussd_entry_changed_cb (CallsMainWindow *self,
GtkEntry *entry)
{
const char *text;
gboolean allow_send;
g_assert (CALLS_IS_MAIN_WINDOW (self));
g_assert (GTK_IS_ENTRY (entry));
text = gtk_entry_get_text (entry);
allow_send = text && *text;
gtk_widget_set_sensitive (GTK_WIDGET (self->ussd_reply_button), allow_send);
}
static void
set_property (GObject *object,
guint property_id,
......@@ -203,6 +246,11 @@ constructed (GObject *object)
G_CALLBACK (calls_in_app_notification_show),
self->in_app_notification);
g_signal_connect_swapped (calls_manager_get_default (),
"ussd-added",
G_CALLBACK (window_ussd_added_cb),
self);
// Add new call box
self->new_call = calls_new_call_box_new ();
widget = GTK_WIDGET (self->new_call);
......@@ -319,6 +367,14 @@ calls_main_window_class_init (CallsMainWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, main_stack);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, permanent_error_revealer);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, permanent_error_label);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, ussd_dialog);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, ussd_label);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, ussd_entry);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, ussd_cancel_button);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, ussd_reply_button);
gtk_widget_class_bind_template_callback (widget_class, window_ussd_entry_changed_cb);
}
......
......@@ -23,6 +23,7 @@
*/
#include "config.h"
#include "calls-ussd.h"
#include "calls-manager.h"
#include "calls-contacts.h"
#include "enum-types.h"
......@@ -61,6 +62,9 @@ enum {
/* TODO: currently this event isn't emitted since the plugins don't give use
* a usable error or error message. */
SIGNAL_ERROR,
USSD_ADDED,
USSD_CANCELLED,
USSD_STATE_CHANGED,
SIGNAL_LAST_SIGNAL,
};
static guint signals [SIGNAL_LAST_SIGNAL];
......@@ -151,6 +155,38 @@ remove_call (CallsManager *self, CallsCall *call, gchar *reason, CallsOrigin *or
g_signal_emit (self, signals[SIGNAL_CALL_REMOVE], 0, call, origin);
}
static void
ussd_added_cb (CallsManager *self,
char *response,
CallsUssd *ussd)
{
g_assert (CALLS_IS_MANAGER (self));
g_assert (CALLS_IS_USSD (ussd));
g_signal_emit (self, signals[USSD_ADDED], 0, ussd, response);
}
static void
ussd_cancelled_cb (CallsManager *self,
CallsUssd *ussd,
char *response)
{
g_assert (CALLS_IS_MANAGER (self));
g_assert (CALLS_IS_USSD (ussd));
g_signal_emit (self, signals[USSD_CANCELLED], 0, ussd);
}
static void
ussd_state_changed_cb (CallsManager *self,
CallsUssd *ussd)
{
g_assert (CALLS_IS_MANAGER (self));
g_assert (CALLS_IS_USSD (ussd));
g_signal_emit (self, signals[USSD_STATE_CHANGED], 0, ussd);
}
static void
add_origin (CallsManager *self, CallsOrigin *origin, CallsProvider *provider)
{
......@@ -163,6 +199,10 @@ add_origin (CallsManager *self, CallsOrigin *origin, CallsProvider *provider)
g_signal_connect_swapped (origin, "call-added", G_CALLBACK (add_call), self);
g_signal_connect_swapped (origin, "call-removed", G_CALLBACK (remove_call), self);
g_signal_connect_swapped (origin, "ussd-added", G_CALLBACK (ussd_added_cb), self);
g_signal_connect_swapped (origin, "ussd-cancelled", G_CALLBACK (ussd_cancelled_cb), self);
g_signal_connect_swapped (origin, "notify::ussd-state", G_CALLBACK (ussd_state_changed_cb), self);
for (c = calls; c != NULL; c = c->next)
{
add_call (self, c->data, origin);
......@@ -380,6 +420,37 @@ calls_manager_class_init (CallsManagerClass *klass)
1,
G_TYPE_STRING);
signals[USSD_ADDED] =
g_signal_new ("ussd-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
2,
CALLS_TYPE_USSD,
G_TYPE_STRING);
signals[USSD_CANCELLED] =
g_signal_new ("ussd-cancelled",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
1,
CALLS_TYPE_USSD);
signals[USSD_STATE_CHANGED] =
g_signal_new ("usdd-state-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
1,
CALLS_TYPE_USSD);
props[PROP_PROVIDER] = g_param_spec_string ("provider",
"provider",
"The name of the currently loaded provider",
......
......@@ -23,6 +23,7 @@
*/
#include "calls-new-call-box.h"
#include "calls-ussd.h"
#include "calls-manager.h"
#include <glib/gi18n.h>
......@@ -292,12 +293,21 @@ void
calls_new_call_box_dial (CallsNewCallBox *self,
const gchar *target)
{
CallsOrigin *origin;
g_autoptr(CallsOrigin) origin = NULL;
g_return_if_fail (CALLS_IS_NEW_CALL_BOX (self));
g_return_if_fail (target != NULL);
origin = get_origin (self);
if (calls_number_is_ussd (target))
{
if (origin)
calls_ussd_initiate (CALLS_USSD (origin), target);
return;
}
if (!origin)
{
// Queue for dialing when an origin appears
......
......@@ -52,6 +52,7 @@ struct _CallsProviderInterface
const gchar * calls_provider_get_name (CallsProvider *self);
gchar * calls_provider_get_status (CallsProvider *self);
GList * calls_provider_get_origins (CallsProvider *self);
GListModel *calls_provider_get_ussd_model (CallsProvider *self);
G_END_DECLS
......
......@@ -66,6 +66,7 @@ calls_vala = static_library (
calls_sources = files(['calls-message-source.c', 'calls-message-source.h',
'calls-call.c',
'calls-ussd.c',
'calls-origin.c', 'calls-origin.h',
'calls-provider.c', 'calls-provider.h',
'calls-party.c', 'calls-party.h',
......@@ -110,7 +111,7 @@ config_h = vcs_tag(
output: 'config.h',
)
calls_enum_headers = files(['calls-call.h', 'calls-manager.h'])
calls_enum_headers = files(['calls-call.h', 'calls-ussd.h', 'calls-manager.h'])
calls_enum_sources = gnome.mkenums_simple('enum-types',
sources : calls_enum_headers)
......
......@@ -115,4 +115,68 @@
</object>
</child>
</template>
<object class="HdyDialog" id="ussd_dialog">
<property name="can-focus">False</property>
<property name="modal">True</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="show-close-button">False</property>
<property name="title" translatable="yes">USSD</property>
<child>
<object class="GtkButton" id="ussd_cancel_button">
<property name="visible">True</property>
<property name="sensitive">True</property>
<property name="has-default">True</property>
<property name="can-default">True</property>
<property name="label" translatable="yes">Cancel</property>
</object>
<packing>
<property name="pack_type">start</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ussd_reply_button">
<property name="label" translatable="yes">Send</property>
<property name="sensitive">False</property>
<property name="visible">True</property>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="visible">True</property>
<property name="expand">True</property>
<property name="margin">18</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="ussd_label">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkEntry" id="ussd_entry">
<property name="visible">False</property>
<signal name="changed" handler="window_ussd_entry_changed_cb" swapped="yes"/>
</object>
</child>
</object>
</child>
<action-widgets>
<action-widget response="cancel">ussd_cancel_button</action-widget>
<action-widget response="ok">ussd_continue_button</action-widget>
</action-widgets>
</object>
</interface>
......@@ -144,6 +144,22 @@ calls_date_time_is_same_year (GDateTime *a,
}
gboolean
calls_number_is_ussd (const char *number)
{
if (!number || *number != '*')
return FALSE;
while (g_ascii_isdigit (*number) || *number == '*')
number++;
if (g_str_equal (number, "#"))
return TRUE;
return FALSE;
}
gboolean
calls_find_in_store (GListModel *list,
gpointer item,
......
......@@ -137,6 +137,7 @@ gboolean calls_date_time_is_yesterday (GDateTime *now,
GDateTime *t);
gboolean calls_date_time_is_same_year (GDateTime *a,
GDateTime *b);
gboolean calls_number_is_ussd (const char *number);
gboolean calls_find_in_store (GListModel *list,
gpointer item,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment