2018-05-17 13:16:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Purism SPC
|
|
|
|
*
|
|
|
|
* This file is part of Calls.
|
|
|
|
*
|
|
|
|
* Calls is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calls is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Bob Ham <bob.ham@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "calls-main-window.h"
|
|
|
|
#include "calls-origin.h"
|
|
|
|
#include "calls-call-holder.h"
|
|
|
|
#include "calls-call-selector-item.h"
|
2018-08-01 09:41:25 +00:00
|
|
|
#include "calls-new-call-box.h"
|
2019-08-01 13:25:53 +00:00
|
|
|
#include "calls-history-box.h"
|
2020-03-02 18:01:20 +00:00
|
|
|
#include "calls-in-app-notification.h"
|
2020-03-18 10:29:41 +00:00
|
|
|
#include "calls-manager.h"
|
2018-08-30 06:50:37 +00:00
|
|
|
#include "config.h"
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#define HANDY_USE_UNSTABLE_API
|
|
|
|
#include <handy.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct _CallsMainWindow
|
|
|
|
{
|
|
|
|
GtkApplicationWindow parent_instance;
|
|
|
|
|
2019-08-01 13:25:53 +00:00
|
|
|
GListModel *record_store;
|
2019-10-29 10:09:48 +00:00
|
|
|
CallsContacts *contacts;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-03-02 18:01:20 +00:00
|
|
|
CallsInAppNotification *in_app_notification;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2019-07-03 12:34:48 +00:00
|
|
|
HdySqueezer *squeezer;
|
|
|
|
GtkLabel *title_label;
|
|
|
|
HdyViewSwitcher *wide_switcher;
|
|
|
|
HdyViewSwitcher *narrow_switcher;
|
|
|
|
HdyViewSwitcherBar *switcher_bar;
|
2018-05-17 13:16:51 +00:00
|
|
|
GtkStack *main_stack;
|
2019-08-01 13:25:53 +00:00
|
|
|
|
2020-03-19 16:41:08 +00:00
|
|
|
GtkRevealer *permanent_error_revealer;
|
|
|
|
GtkLabel *permanent_error_label;
|
|
|
|
|
2019-08-01 13:25:53 +00:00
|
|
|
CallsNewCallBox *new_call;
|
2018-05-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (CallsMainWindow, calls_main_window, GTK_TYPE_APPLICATION_WINDOW);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2019-08-01 13:25:53 +00:00
|
|
|
PROP_RECORD_STORE,
|
2019-10-29 10:09:48 +00:00
|
|
|
PROP_CONTACTS,
|
2018-05-17 13:16:51 +00:00
|
|
|
PROP_LAST_PROP,
|
|
|
|
};
|
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
|
|
|
|
|
|
|
|
2018-08-30 06:50:37 +00:00
|
|
|
static void
|
|
|
|
about_action (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
CallsMainWindow *self = user_data;
|
|
|
|
|
|
|
|
const gchar *version = NULL;
|
|
|
|
|
|
|
|
static const gchar *authors[] = {
|
|
|
|
"Adrien Plazas <kekun.plazas@laposte.net>",
|
|
|
|
"Bob Ham <rah@settrans.net>",
|
|
|
|
"Guido Günther <agx@sigxcpu.org>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *artists[] = {
|
|
|
|
"Tobias Bernard <tbernard@gnome.org>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *documenters[] = {
|
|
|
|
"Heather Ellsworth <heather.ellsworth@puri.sm>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
version = g_str_equal (VCS_TAG, "") ? PACKAGE_VERSION:
|
|
|
|
PACKAGE_VERSION "-" VCS_TAG;
|
|
|
|
|
|
|
|
gtk_show_about_dialog (GTK_WINDOW (self),
|
|
|
|
"artists", artists,
|
|
|
|
"authors", authors,
|
|
|
|
"copyright", "Copyright © 2018 Purism",
|
|
|
|
"documenters", documenters,
|
|
|
|
"license-type", GTK_LICENSE_GPL_3_0,
|
|
|
|
"logo-icon-name", APP_ID,
|
|
|
|
"program-name", _("Calls"),
|
|
|
|
"translator-credits", _("translator-credits"),
|
|
|
|
"version", version,
|
|
|
|
"website", PACKAGE_URL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const GActionEntry window_entries [] =
|
|
|
|
{
|
|
|
|
{ "about", about_action },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-07-03 12:34:48 +00:00
|
|
|
static gboolean
|
|
|
|
set_switcher_bar_reveal (GBinding *binding,
|
|
|
|
const GValue *from_value,
|
|
|
|
GValue *to_value,
|
|
|
|
gpointer title_label)
|
|
|
|
{
|
|
|
|
g_value_set_boolean (to_value, g_value_get_object (from_value) == title_label);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsMainWindow *self = CALLS_MAIN_WINDOW (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
2019-08-01 13:25:53 +00:00
|
|
|
case PROP_RECORD_STORE:
|
|
|
|
g_set_object (&self->record_store,
|
|
|
|
G_LIST_MODEL (g_value_get_object (value)));
|
2018-05-17 13:16:51 +00:00
|
|
|
break;
|
|
|
|
|
2019-10-29 10:09:48 +00:00
|
|
|
case PROP_CONTACTS:
|
|
|
|
g_set_object (&self->contacts,
|
|
|
|
CALLS_CONTACTS (g_value_get_object (value)));
|
|
|
|
break;
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-19 16:41:08 +00:00
|
|
|
static void
|
|
|
|
state_changed_cb (CallsMainWindow *self,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
CallsManager *manager)
|
|
|
|
{
|
|
|
|
const gchar *error = NULL;
|
|
|
|
switch (calls_manager_get_state (manager))
|
|
|
|
{
|
|
|
|
case CALLS_MANAGER_STATE_READY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALLS_MANAGER_STATE_NO_ORIGIN:
|
|
|
|
error = _("Can't place calls: No SIM card");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALLS_MANAGER_STATE_UNKNOWN:
|
|
|
|
case CALLS_MANAGER_STATE_NO_PROVIDER:
|
|
|
|
error = _("Can't place calls: No backend service");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALLS_MANAGER_STATE_NO_PLUGIN:
|
|
|
|
error = _("Can't place calls: No plugin");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_label_set_text (self->permanent_error_label, error);
|
|
|
|
gtk_revealer_set_reveal_child (self->permanent_error_revealer, error != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-30 06:50:37 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
CallsMainWindow *self = CALLS_MAIN_WINDOW (object);
|
|
|
|
GSimpleActionGroup *simple_action_group;
|
2019-08-01 13:25:53 +00:00
|
|
|
GtkContainer *main_stack = GTK_CONTAINER (self->main_stack);
|
|
|
|
GtkWidget *widget;
|
|
|
|
CallsHistoryBox *history;
|
2018-10-05 11:27:55 +00:00
|
|
|
|
2020-03-18 10:29:41 +00:00
|
|
|
// Show errors in in-app-notification
|
|
|
|
g_signal_connect_swapped (calls_manager_get_default (),
|
|
|
|
"error",
|
|
|
|
G_CALLBACK (calls_in_app_notification_show),
|
|
|
|
self->in_app_notification);
|
2018-10-08 10:46:00 +00:00
|
|
|
|
2019-08-01 13:25:53 +00:00
|
|
|
// Add new call box
|
2020-03-18 10:29:41 +00:00
|
|
|
self->new_call = calls_new_call_box_new ();
|
2019-08-01 13:25:53 +00:00
|
|
|
widget = GTK_WIDGET (self->new_call);
|
|
|
|
gtk_stack_add_titled (self->main_stack, widget,
|
2019-07-03 12:55:09 +00:00
|
|
|
"dial-pad", _("Dial Pad"));
|
2019-08-01 13:25:53 +00:00
|
|
|
gtk_container_child_set (main_stack, widget,
|
2019-07-03 12:34:48 +00:00
|
|
|
"icon-name", "input-dialpad-symbolic",
|
|
|
|
NULL);
|
2018-08-30 06:50:37 +00:00
|
|
|
|
2019-08-01 13:25:53 +00:00
|
|
|
// Add call records
|
|
|
|
history = calls_history_box_new (self->record_store,
|
2020-03-02 12:40:31 +00:00
|
|
|
self->contacts);
|
2019-08-01 13:25:53 +00:00
|
|
|
widget = GTK_WIDGET (history);
|
|
|
|
gtk_stack_add_titled (self->main_stack, widget,
|
|
|
|
"recent", _("Recent"));
|
|
|
|
gtk_container_child_set
|
|
|
|
(main_stack, widget,
|
|
|
|
"icon-name", "document-open-recent-symbolic",
|
|
|
|
"position", 0,
|
|
|
|
NULL);
|
|
|
|
gtk_widget_set_visible (widget, TRUE);
|
|
|
|
gtk_stack_set_visible_child_name (self->main_stack, "recent");
|
|
|
|
|
|
|
|
// Add actions
|
2018-08-30 06:50:37 +00:00
|
|
|
simple_action_group = g_simple_action_group_new ();
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (simple_action_group),
|
|
|
|
window_entries,
|
|
|
|
G_N_ELEMENTS (window_entries),
|
|
|
|
self);
|
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (self),
|
|
|
|
"win",
|
|
|
|
G_ACTION_GROUP (simple_action_group));
|
|
|
|
g_object_unref (simple_action_group);
|
|
|
|
|
2018-10-02 17:19:10 +00:00
|
|
|
|
2019-07-03 12:34:48 +00:00
|
|
|
g_object_bind_property_full (self->squeezer,
|
|
|
|
"visible-child",
|
|
|
|
self->switcher_bar,
|
|
|
|
"reveal",
|
|
|
|
G_BINDING_SYNC_CREATE,
|
|
|
|
set_switcher_bar_reveal,
|
|
|
|
NULL,
|
|
|
|
self->title_label,
|
|
|
|
NULL);
|
2018-08-30 06:50:37 +00:00
|
|
|
|
2020-03-19 16:41:08 +00:00
|
|
|
g_signal_connect_swapped (calls_manager_get_default (),
|
|
|
|
"notify::state",
|
|
|
|
G_CALLBACK (state_changed_cb),
|
|
|
|
self);
|
|
|
|
|
|
|
|
state_changed_cb (self, NULL, calls_manager_get_default ());
|
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_main_window_parent_class)->constructed (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-01 13:25:53 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsMainWindow *self = CALLS_MAIN_WINDOW (object);
|
|
|
|
|
2019-10-29 10:09:48 +00:00
|
|
|
g_clear_object (&self->contacts);
|
2019-08-01 13:25:53 +00:00
|
|
|
g_clear_object (&self->record_store);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_main_window_parent_class)->dispose (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-03 12:34:48 +00:00
|
|
|
static void
|
|
|
|
size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
CallsMainWindow *self = CALLS_MAIN_WINDOW (widget);
|
|
|
|
|
|
|
|
hdy_squeezer_set_child_enabled (self->squeezer,
|
|
|
|
GTK_WIDGET (self->wide_switcher),
|
|
|
|
allocation->width > 600);
|
|
|
|
hdy_squeezer_set_child_enabled (self->squeezer,
|
|
|
|
GTK_WIDGET (self->narrow_switcher),
|
|
|
|
allocation->width > 400);
|
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
GTK_WIDGET_CLASS (calls_main_window_parent_class)->size_allocate (widget, allocation);
|
2019-07-03 12:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_main_window_class_init (CallsMainWindowClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->set_property = set_property;
|
2018-08-30 06:50:37 +00:00
|
|
|
object_class->constructed = constructed;
|
2018-05-17 13:16:51 +00:00
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
2019-08-01 13:25:53 +00:00
|
|
|
props[PROP_RECORD_STORE] =
|
|
|
|
g_param_spec_object ("record-store",
|
|
|
|
_("Record store"),
|
|
|
|
_("The store of call records"),
|
|
|
|
G_TYPE_LIST_MODEL,
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
2019-10-29 10:09:48 +00:00
|
|
|
props[PROP_CONTACTS] =
|
|
|
|
g_param_spec_object ("contacts",
|
|
|
|
_("Contacts"),
|
|
|
|
_("Interface for libfolks"),
|
|
|
|
CALLS_TYPE_CONTACTS,
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
|
|
|
|
|
|
|
|
2019-07-03 12:34:48 +00:00
|
|
|
widget_class->size_allocate = size_allocate;
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/calls/ui/main-window.ui");
|
2020-03-02 18:01:20 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, in_app_notification);
|
2019-07-03 12:34:48 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, squeezer);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, title_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, wide_switcher);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, narrow_switcher);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, switcher_bar);
|
2018-05-17 13:16:51 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, main_stack);
|
2020-03-19 16:41:08 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, permanent_error_revealer);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, permanent_error_label);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
2019-07-03 12:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_main_window_init (CallsMainWindow *self)
|
|
|
|
{
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CallsMainWindow *
|
2019-08-01 13:25:53 +00:00
|
|
|
calls_main_window_new (GtkApplication *application,
|
2019-10-29 10:09:48 +00:00
|
|
|
GListModel *record_store,
|
|
|
|
CallsContacts *contacts)
|
2019-07-03 12:34:48 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
|
2019-08-01 13:25:53 +00:00
|
|
|
g_return_val_if_fail (G_IS_LIST_MODEL (record_store), NULL);
|
2019-10-29 10:09:48 +00:00
|
|
|
g_return_val_if_fail (CALLS_IS_CONTACTS (contacts), NULL);
|
2019-07-03 12:34:48 +00:00
|
|
|
|
|
|
|
return g_object_new (CALLS_TYPE_MAIN_WINDOW,
|
|
|
|
"application", application,
|
2019-08-01 13:25:53 +00:00
|
|
|
"record-store", record_store,
|
2019-10-29 10:09:48 +00:00
|
|
|
"contacts", contacts,
|
2019-07-03 12:34:48 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2019-08-05 10:25:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
calls_main_window_dial (CallsMainWindow *self,
|
|
|
|
const gchar *target)
|
|
|
|
{
|
|
|
|
calls_new_call_box_dial (self->new_call, target);
|
|
|
|
}
|