@@ -40,6 +40,7 @@
|
||||
|
||||
#include <libpeas/peas.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <libebook-contacts/libebook-contacts.h>
|
||||
|
||||
/**
|
||||
* SECTION: calls-application
|
||||
@@ -58,6 +59,8 @@ struct _CallsApplication
|
||||
CallsProvider *provider;
|
||||
CallsRinger *ringer;
|
||||
CallsRecordStore *record_store;
|
||||
CallsMainWindow *main_window;
|
||||
CallsCallWindow *call_window;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsApplication, calls_application, GTK_TYPE_APPLICATION)
|
||||
@@ -215,56 +218,133 @@ load_provider_plugin (CallsApplication *self)
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
start_proper (CallsApplication *self)
|
||||
{
|
||||
GtkApplication *gtk_app;
|
||||
|
||||
if (self->main_window)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gtk_app = GTK_APPLICATION (self);
|
||||
|
||||
// Later we will make provider loading/unloaded a dynamic
|
||||
// process but that will have far-reaching consequences and is
|
||||
// of no use immediately so for now, we just load one provider
|
||||
// at startup. We can't put this in the actual startup() method
|
||||
// though, because we need to be able to set the provider name
|
||||
// from the command line and we use actions to do that, which
|
||||
// depend on the application already being started up.
|
||||
load_provider_plugin (self);
|
||||
if (!self->provider)
|
||||
{
|
||||
g_application_quit (G_APPLICATION (self));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
self->ringer = calls_ringer_new (self->provider);
|
||||
g_assert (self->ringer != NULL);
|
||||
|
||||
self->record_store = calls_record_store_new (self->provider);
|
||||
g_assert (self->record_store != NULL);
|
||||
|
||||
self->main_window = calls_main_window_new
|
||||
(gtk_app,
|
||||
self->provider,
|
||||
G_LIST_MODEL (self->record_store));
|
||||
g_assert (self->main_window != NULL);
|
||||
|
||||
self->call_window = calls_call_window_new
|
||||
(gtk_app, self->provider);
|
||||
g_assert (self->call_window != NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
activate (GApplication *application)
|
||||
{
|
||||
GtkApplication *gtk_app;
|
||||
GtkWindow *window;
|
||||
CallsApplication *self = CALLS_APPLICATION (application);
|
||||
gboolean ok;
|
||||
|
||||
g_assert (GTK_IS_APPLICATION (application));
|
||||
gtk_app = GTK_APPLICATION (application);
|
||||
g_debug ("Activated");
|
||||
|
||||
window = gtk_application_get_active_window (gtk_app);
|
||||
|
||||
if (window == NULL)
|
||||
ok = start_proper (self);
|
||||
if (!ok)
|
||||
{
|
||||
CallsApplication *self = CALLS_APPLICATION (application);
|
||||
|
||||
// Later we will make provider loading/unloaded a dynamic
|
||||
// process but that will have far-reaching consequences and is
|
||||
// of no use immediately so for now, we just load one provider
|
||||
// at startup. We can't put this in the actual startup() method
|
||||
// though, because we need to be able to set the provider name
|
||||
// from the command line and we use actions to do that, which
|
||||
// depend on the application already being started up.
|
||||
if (!self->provider)
|
||||
{
|
||||
load_provider_plugin (self);
|
||||
if (!self->provider)
|
||||
{
|
||||
g_application_quit (application);
|
||||
return;
|
||||
}
|
||||
|
||||
self->ringer = calls_ringer_new (self->provider);
|
||||
g_assert (self->ringer != NULL);
|
||||
|
||||
self->record_store = calls_record_store_new (self->provider);
|
||||
g_assert (self->record_store != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't track the memory created. Ideally, we might have to.
|
||||
* But we assume that the application is closed by closing the
|
||||
* window. In that case, GTK+ frees the resources right.
|
||||
*/
|
||||
window = GTK_WINDOW
|
||||
(calls_main_window_new (gtk_app, self->provider,
|
||||
G_LIST_MODEL (self->record_store)));
|
||||
calls_call_window_new (gtk_app, self->provider);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_window_present (window);
|
||||
gtk_window_present (GTK_WINDOW (self->main_window));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
open_tel_uri (CallsApplication *self,
|
||||
const gchar *uri)
|
||||
{
|
||||
EPhoneNumber *number;
|
||||
GError *error = NULL;
|
||||
gchar *dial_str;
|
||||
|
||||
g_debug ("Opening tel URI `%s'", uri);
|
||||
|
||||
number = e_phone_number_from_string (uri, NULL, &error);
|
||||
if (!number)
|
||||
{
|
||||
g_warning ("Ignoring unparsable tel URI `%s': %s",
|
||||
uri, error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
dial_str = e_phone_number_to_string
|
||||
(number, E_PHONE_NUMBER_FORMAT_E164);
|
||||
e_phone_number_free (number);
|
||||
|
||||
calls_main_window_dial (self->main_window,
|
||||
dial_str);
|
||||
g_free (dial_str);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
app_open (GApplication *application,
|
||||
GFile **files,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
CallsApplication *self = CALLS_APPLICATION (application);
|
||||
gint i;
|
||||
|
||||
g_assert (n_files > 0);
|
||||
|
||||
g_debug ("Opened (%i files)", n_files);
|
||||
|
||||
start_proper (self);
|
||||
|
||||
for (i = 0; i < n_files; ++i)
|
||||
{
|
||||
gchar *uri;
|
||||
if (g_file_has_uri_scheme (files[i], "tel"))
|
||||
{
|
||||
uri = g_file_get_uri (files[i]);
|
||||
|
||||
open_tel_uri (self, uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
uri = g_file_get_parse_name (files[i]);
|
||||
g_warning ("Don't know how to"
|
||||
" open file `%s', ignoring",
|
||||
uri);
|
||||
}
|
||||
|
||||
g_free (uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -289,6 +369,8 @@ dispose (GObject *object)
|
||||
{
|
||||
CallsApplication *self = (CallsApplication *)object;
|
||||
|
||||
g_clear_object (&self->call_window);
|
||||
g_clear_object (&self->main_window);
|
||||
g_clear_object (&self->record_store);
|
||||
g_clear_object (&self->ringer);
|
||||
g_clear_object (&self->provider);
|
||||
@@ -321,6 +403,7 @@ calls_application_class_init (CallsApplicationClass *klass)
|
||||
application_class->handle_local_options = handle_local_options;
|
||||
application_class->startup = startup;
|
||||
application_class->activate = activate;
|
||||
application_class->open = app_open;
|
||||
|
||||
g_type_ensure (CALLS_TYPE_ENCRYPTION_INDICATOR);
|
||||
g_type_ensure (CALLS_TYPE_HISTORY_BOX);
|
||||
@@ -359,6 +442,6 @@ calls_application_new (void)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_APPLICATION,
|
||||
"application-id", APP_ID,
|
||||
"flags", G_APPLICATION_FLAGS_NONE,
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@@ -403,3 +403,11 @@ calls_main_window_new (GtkApplication *application,
|
||||
"record-store", record_store,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_main_window_dial (CallsMainWindow *self,
|
||||
const gchar *target)
|
||||
{
|
||||
calls_new_call_box_dial (self->new_call, target);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ G_DECLARE_FINAL_TYPE (CallsMainWindow, calls_main_window, CALLS, MAIN_WINDOW, Gt
|
||||
CallsMainWindow *calls_main_window_new (GtkApplication *application,
|
||||
CallsProvider *provider,
|
||||
GListModel *record_store);
|
||||
void calls_main_window_dial (CallsMainWindow *self,
|
||||
const gchar *target);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ struct _CallsNewCallBox
|
||||
GtkSearchEntry *number_entry;
|
||||
GtkButton *dial;
|
||||
GtkLabel *status;
|
||||
|
||||
GList *dial_queue;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsNewCallBox, calls_new_call_box, GTK_TYPE_BOX);
|
||||
@@ -58,6 +60,29 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
static CallsOrigin *
|
||||
get_origin (CallsNewCallBox *self)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gboolean ok;
|
||||
CallsOrigin *origin;
|
||||
|
||||
ok = gtk_combo_box_get_active_iter (self->origin_box, &iter);
|
||||
if (!ok)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (self->origin_store),
|
||||
&iter,
|
||||
ORIGIN_STORE_COLUMN_ORIGIN, &origin,
|
||||
-1);
|
||||
g_assert (CALLS_IS_ORIGIN (origin));
|
||||
|
||||
return origin;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dial_pad_symbol_clicked_cb (CallsNewCallBox *self,
|
||||
gchar symbol,
|
||||
@@ -102,6 +127,48 @@ notify_status_cb (CallsNewCallBox *self,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dial_queued_cb (gchar *target,
|
||||
CallsOrigin *origin)
|
||||
{
|
||||
g_debug ("Dialing queued target `%s'", target);
|
||||
calls_origin_dial (origin, target);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
clear_dial_queue (CallsNewCallBox *self)
|
||||
{
|
||||
g_list_free_full (self->dial_queue, g_free);
|
||||
self->dial_queue = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dial_queued (CallsNewCallBox *self)
|
||||
{
|
||||
CallsOrigin *origin;
|
||||
|
||||
if (!self->dial_queue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_debug ("Dialing %u queued targets",
|
||||
g_list_length (self->dial_queue));
|
||||
|
||||
origin = get_origin (self);
|
||||
g_assert (origin != NULL);
|
||||
|
||||
g_list_foreach (self->dial_queue,
|
||||
(GFunc)dial_queued_cb,
|
||||
origin);
|
||||
g_object_unref (origin);
|
||||
|
||||
clear_dial_queue (self);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
update_origin_box (CallsNewCallBox *self)
|
||||
{
|
||||
@@ -125,19 +192,22 @@ update_origin_box (CallsNewCallBox *self)
|
||||
{
|
||||
gtk_combo_box_set_active (self->origin_box, 0);
|
||||
gtk_widget_hide (GTK_WIDGET (self->origin_box));
|
||||
return;
|
||||
}
|
||||
|
||||
/* We know there are multiple origins. */
|
||||
|
||||
if (gtk_combo_box_get_active (self->origin_box) < 0)
|
||||
else
|
||||
{
|
||||
gtk_combo_box_set_active (self->origin_box, 0);
|
||||
/* We know there are multiple origins. */
|
||||
|
||||
if (gtk_combo_box_get_active (self->origin_box) < 0)
|
||||
{
|
||||
gtk_combo_box_set_active (self->origin_box, 0);
|
||||
}
|
||||
|
||||
/* We know there are multiple origins and one is selected. */
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (self->origin_box));
|
||||
}
|
||||
|
||||
/* We know there are multiple origins and one is selected. */
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (self->origin_box));
|
||||
dial_queued (self);
|
||||
}
|
||||
|
||||
|
||||
@@ -244,6 +314,8 @@ dispose (GObject *object)
|
||||
GObjectClass *parent_class = g_type_class_peek (GTK_TYPE_BOX);
|
||||
CallsNewCallBox *self = CALLS_NEW_CALL_BOX (object);
|
||||
|
||||
clear_dial_queue (self);
|
||||
|
||||
if (self->origin_store)
|
||||
{
|
||||
remove_origins (self);
|
||||
@@ -293,28 +365,26 @@ calls_new_call_box_new (CallsProvider *provider)
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_new_call_box_dial (CallsNewCallBox *self,
|
||||
const gchar *target)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gboolean ok;
|
||||
CallsOrigin *origin;
|
||||
|
||||
g_return_if_fail (CALLS_IS_NEW_CALL_BOX (self));
|
||||
g_return_if_fail (target != NULL);
|
||||
|
||||
ok = gtk_combo_box_get_active_iter (self->origin_box, &iter);
|
||||
if (!ok)
|
||||
origin = get_origin (self);
|
||||
if (!origin)
|
||||
{
|
||||
g_debug ("Can't submit call with no origin");
|
||||
// Queue for dialing when an origin appears
|
||||
g_debug ("Can't submit call with no origin, queuing for later");
|
||||
self->dial_queue = g_list_append (self->dial_queue,
|
||||
g_strdup (target));
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (self->origin_store), &iter,
|
||||
ORIGIN_STORE_COLUMN_ORIGIN, &origin,
|
||||
-1);
|
||||
g_assert (CALLS_IS_ORIGIN (origin));
|
||||
|
||||
calls_origin_dial (origin, target);
|
||||
g_object_unref (origin);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ calls_deps = [ dependency('gobject-2.0'),
|
||||
dependency('gsound'),
|
||||
dependency('libpeas-1.0'),
|
||||
dependency('gom-1.0'),
|
||||
dependency('libebook-contacts-1.2'),
|
||||
]
|
||||
|
||||
calls_sources = files(['calls-message-source.c', 'calls-message-source.h',
|
||||
|
||||
Reference in New Issue
Block a user