Commit 9aa34cce authored by Bob Ham's avatar Bob Ham
Browse files

src: Give the Provider to the CallWindow on construction

This allows us to get rid of the signals on the MainWindow and
simplifies things dramatically.
parent 1843d72a
......@@ -97,7 +97,6 @@ activate (GApplication *application)
{
CallsApplication *self = (CallsApplication *)application;
GtkApplication *app = (GtkApplication *)application;
CallsCallWindow *call_window;
GtkWindow *window;
g_assert (GTK_IS_APPLICATION (app));
......@@ -112,12 +111,7 @@ activate (GApplication *application)
* window. In that case, GTK+ frees the resources right.
*/
window = GTK_WINDOW (calls_main_window_new (app, self->provider));
call_window = calls_call_window_new (app);
g_signal_connect_swapped (window, "call-added",
G_CALLBACK (calls_call_window_add_call), call_window);
g_signal_connect_swapped (window, "call-removed",
G_CALLBACK (calls_call_window_remove_call), call_window);
calls_call_window_new (app, self->provider);
}
gtk_window_present (window);
......
......@@ -55,21 +55,15 @@ struct _CallsCallWindow
GtkFlowBox *call_selector;
};
enum {
ORIGIN_STORE_COLUMN_NAME,
ORIGIN_STORE_COLUMN_ORIGIN
};
G_DEFINE_TYPE (CallsCallWindow, calls_call_window, GTK_TYPE_APPLICATION_WINDOW);
CallsCallWindow *
calls_call_window_new (GtkApplication *application)
{
return g_object_new (CALLS_TYPE_CALL_WINDOW,
"application", application,
NULL);
}
enum {
PROP_0,
PROP_PROVIDER,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static void
......@@ -240,8 +234,8 @@ call_selector_child_activated_cb (GtkFlowBox *box,
void
calls_call_window_add_call (CallsCallWindow *self,
CallsCall *call)
add_call (CallsCallWindow *self,
CallsCall *call)
{
CallsCallHolder *holder;
CallsCallDisplay *display;
......@@ -283,9 +277,9 @@ remove_call_holder (CallsCallWindow *self,
}
void
calls_call_window_remove_call (CallsCallWindow *self,
CallsCall *call,
const gchar *reason)
remove_call (CallsCallWindow *self,
CallsCall *call,
const gchar *reason)
{
guint n_items, position;
CallsCallHolder *holder;
......@@ -300,10 +294,6 @@ calls_call_window_remove_call (CallsCallWindow *self,
remove_call_holder (self, n_items, position, holder);
if (!reason)
{
reason = "Call ended for unknown reason";
}
show_message(self, reason, GTK_MESSAGE_INFO);
}
......@@ -326,6 +316,80 @@ remove_calls (CallsCallWindow *self)
}
static void
add_origin_calls (CallsCallWindow *self, CallsOrigin *origin)
{
GList *calls, *node;
calls = calls_origin_get_calls (origin);
for (node = calls; node; node = node->next)
{
add_call (self, CALLS_CALL (node->data));
}
g_list_free (calls);
}
static void
add_origin (CallsCallWindow *self, CallsOrigin *origin)
{
g_signal_connect_swapped (origin, "call-added",
G_CALLBACK (add_call), self);
g_signal_connect_swapped (origin, "call-removed",
G_CALLBACK (remove_call), self);
add_origin_calls (self, origin);
}
static void
add_provider_origins (CallsCallWindow *self, CallsProvider *provider)
{
GList *origins, *node;
origins = calls_provider_get_origins (provider);
for (node = origins; node; node = node->next)
{
add_origin (self, CALLS_ORIGIN (node->data));
}
g_list_free (origins);
}
static void
set_provider (CallsCallWindow *self, CallsProvider *provider)
{
g_signal_connect_swapped (provider, "origin-added",
G_CALLBACK (add_origin), self);
add_provider_origins (self, provider);
}
static void
set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CallsCallWindow *self = CALLS_CALL_WINDOW (object);
switch (property_id)
{
case PROP_PROVIDER:
set_provider (self, CALLS_PROVIDER (g_value_get_object (value)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
constructed (GObject *object)
{
......@@ -375,9 +439,19 @@ calls_call_window_class_init (CallsCallWindowClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->set_property = set_property;
object_class->constructed = constructed;
object_class->dispose = dispose;
props[PROP_PROVIDER] =
g_param_spec_object ("provider",
_("Provider"),
_("An object implementing low-level call-making functionality"),
CALLS_TYPE_PROVIDER,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/calls/ui/call-window.ui");
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, info);
gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, info_label);
......@@ -391,3 +465,14 @@ calls_call_window_class_init (CallsCallWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, show_calls_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, new_call_submitted_cb);
}
CallsCallWindow *
calls_call_window_new (GtkApplication *application,
CallsProvider *provider)
{
return g_object_new (CALLS_TYPE_CALL_WINDOW,
"application", application,
"provider", provider,
NULL);
}
......@@ -30,6 +30,7 @@
#include <gtk/gtk.h>
#include "calls-call.h"
#include "calls-provider.h"
G_BEGIN_DECLS
......@@ -37,9 +38,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (CallsCallWindow, calls_call_window, CALLS, CALL_WINDOW, GtkApplicationWindow);
CallsCallWindow *calls_call_window_new (GtkApplication *application);
void calls_call_window_add_call (CallsCallWindow *self, CallsCall *call);
void calls_call_window_remove_call (CallsCallWindow *self, CallsCall *call, const gchar *reason);
CallsCallWindow *calls_call_window_new (GtkApplication *application,
CallsProvider *provider);
G_END_DECLS
......
......@@ -60,14 +60,6 @@ enum {
static GParamSpec *props[PROP_LAST_PROP];
enum {
SIGNAL_CALL_ADDED,
SIGNAL_CALL_REMOVED,
SIGNAL_LAST_SIGNAL,
};
static guint signals [SIGNAL_LAST_SIGNAL];
static void
about_action (GSimpleAction *action,
GVariant *parameter,
......@@ -175,8 +167,6 @@ info_response_cb (GtkInfoBar *infobar,
static void
add_call (CallsMainWindow *self, CallsCall *call)
{
g_signal_emit (self, signals[SIGNAL_CALL_ADDED], 0, call);
g_signal_connect_swapped (call, "message",
G_CALLBACK (show_message), self);
}
......@@ -188,8 +178,6 @@ remove_call (CallsMainWindow *self, CallsCall *call, const gchar *reason)
g_return_if_fail (CALLS_IS_MAIN_WINDOW (self));
g_return_if_fail (CALLS_IS_CALL (call));
g_signal_emit (self, signals[SIGNAL_CALL_REMOVED], 0, call, reason);
show_message(self, reason, GTK_MESSAGE_INFO);
}
......@@ -345,28 +333,6 @@ calls_main_window_class_init (CallsMainWindowClass *klass)
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
signals[SIGNAL_CALL_ADDED] =
g_signal_new ("call-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
1,
CALLS_TYPE_CALL);
signals[SIGNAL_CALL_REMOVED] =
g_signal_new ("call-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE,
2,
CALLS_TYPE_CALL,
G_TYPE_STRING);
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/calls/ui/main-window.ui");
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, info);
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, info_label);
......
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