Commit 2d314588 authored by Mohammed Sadiq's avatar Mohammed Sadiq
Browse files

wwan: Add new panel for modem management

parent ce081784
......@@ -211,6 +211,10 @@ config_h.set('BUILD_NETWORK', host_is_linux,
description: 'Define to 1 to build the Network panel')
config_h.set('HAVE_NETWORK_MANAGER', host_is_linux,
description: 'Define to 1 if NetworkManager is available')
config_h.set('BUILD_WWAN', host_is_linux,
description: 'Define to 1 to build the WWan panel')
config_h.set('HAVE_WWAN', host_is_linux,
description: 'Define to 1 if WWan is available')
if host_is_linux_not_s390
# gnome-bluetooth
......
......@@ -19,7 +19,8 @@ panels = [
'sharing',
'sound',
'universal-access',
'user-accounts'
'user-accounts',
'wwan',
]
if host_is_linux
......
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* cc-wwan-apn-dialog.c
*
* Copyright 2019 Purism SPC
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author(s):
* Mohammed Sadiq <sadiq@sadiqpk.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "cc-wwan-apn-dialog"
#include <config.h>
#include <glib/gi18n.h>
#include <libmm-glib.h>
#include "cc-wwan-device.h"
#include "cc-wwan-data.h"
#include "list-box-helper.h"
#include "cc-wwan-apn-dialog.h"
#include "cc-wwan-resources.h"
/**
* @short_description: Dialog to manage Internet Access Points
*/
struct _CcWwanApnDialog
{
HdyDialog parent_instance;
CcWwanDevice *device;
CcWwanData *wwan_data;
GCancellable *cancellable;
GtkWidget *back_button;
GtkWidget *apn_settings_stack;
GtkWidget *apn_list;
GtkWidget *selected_row;
gboolean enable_data;
gboolean enable_roaming;
};
G_DEFINE_TYPE (CcWwanApnDialog, cc_wwan_apn_dialog, HDY_TYPE_DIALOG)
enum {
PROP_0,
PROP_DEVICE,
N_PROPS
};
static GParamSpec *properties[N_PROPS];
static void
cc_wwan_apn_back_clicked_cb (CcWwanApnDialog *self)
{
const gchar *current;
g_assert (CC_IS_WWAN_APN_DIALOG (self));
current = gtk_stack_get_visible_child_name (GTK_STACK (self->apn_settings_stack));
g_assert (current != NULL);
if (g_str_equal (current, "apn-list"))
gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_CANCEL);
else
gtk_stack_set_visible_child_name (GTK_STACK (self->apn_settings_stack), "apn-list");
}
static void
cc_wwan_apn_activated_cb (CcWwanApnDialog *self,
GtkListBoxRow *row)
{
CcWwanDataAPN *apn;
GtkWidget *image;
g_assert (CC_IS_WWAN_APN_DIALOG (self));
g_assert (GTK_IS_LIST_BOX_ROW (row));
if (GTK_WIDGET (row) == self->selected_row)
return;
image = g_object_get_data (G_OBJECT (row), "image");
gtk_widget_show (image);
apn = g_object_get_data (G_OBJECT (row), "apn");
cc_wwan_data_set_default_apn (self->wwan_data, apn);
cc_wwan_data_save_settings (self->wwan_data, NULL, NULL, NULL);
if (self->selected_row)
{
image = g_object_get_data (G_OBJECT (self->selected_row), "image");
gtk_widget_hide (image);
}
self->selected_row = GTK_WIDGET (row);
}
static GtkWidget *
cc_wwan_apn_dialog_row_new (CcWwanApnDialog *self,
CcWwanDataAPN *apn)
{
GtkWidget *row, *grid, *name_label, *apn_label, *image;
GtkStyleContext *context;
g_assert (CC_IS_WWAN_APN_DIALOG (self));
g_assert (apn != NULL);
row = gtk_list_box_row_new ();
g_object_set_data (G_OBJECT (row), "apn", apn);
grid = gtk_grid_new ();
g_object_set (grid,
"margin-top", 6,
"margin-bottom", 6,
"margin-start", 18,
"margin-end", 18,
NULL);
name_label = gtk_label_new (cc_wwan_data_apn_get_name (apn));
gtk_widget_set_halign (name_label, GTK_ALIGN_START);
gtk_widget_set_hexpand (name_label, TRUE);
gtk_grid_attach (GTK_GRID (grid), name_label, 0, 0, 1, 1);
apn_label = gtk_label_new (cc_wwan_data_apn_get_apn (apn));
gtk_widget_set_halign (apn_label, GTK_ALIGN_START);
context = gtk_widget_get_style_context (apn_label);
gtk_style_context_add_class (context, "dim-label");
gtk_grid_attach (GTK_GRID (grid), apn_label, 0, 1, 1, 1);
gtk_container_add (GTK_CONTAINER (row), grid);
gtk_widget_show_all (row);
/* image should be hidden by default */
image = gtk_image_new_from_icon_name ("emblem-ok-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_grid_attach (GTK_GRID (grid), image, 1, 0, 1, 2);
g_object_set_data (G_OBJECT (row), "image", image);
if (cc_wwan_data_get_default_apn (self->wwan_data) == apn)
{
gtk_widget_show (image);
self->selected_row = row;
}
return row;
}
static void
cc_wwan_apn_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
CcWwanApnDialog *self = (CcWwanApnDialog *)object;
switch (prop_id)
{
case PROP_DEVICE:
self->device = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
cc_wwan_apn_dialog_constructed (GObject *object)
{
CcWwanApnDialog *self = (CcWwanApnDialog *)object;
GSList *apn_list, *l;
GtkWidget *apn_row;
gboolean lock_enabled;
G_OBJECT_CLASS (cc_wwan_apn_dialog_parent_class)->constructed (object);
self->cancellable = g_cancellable_new ();
self->wwan_data = cc_wwan_device_get_data (self->device);
apn_list = cc_wwan_data_get_apn_list (self->wwan_data);
for (l = apn_list; l; l = l->next)
{
apn_row = cc_wwan_apn_dialog_row_new (self, l->data);
gtk_container_add (GTK_CONTAINER (self->apn_list), apn_row);
}
/* is_auto = cc_wwan_device_is_auto_network (self->device); */
/* self->no_update_network = TRUE; */
/* gtk_switch_set_active (GTK_SWITCH (self->automatic_switch), is_auto); */
/* gtk_widget_set_sensitive (self->operator_list_box, !is_auto); */
/* /\* g_cancellable_reset (self->search_cancellable); *\/ */
/* cc_wwan_apn_dialog_update_current (self); */
}
static void
cc_wwan_apn_dialog_finalize (GObject *object)
{
CcWwanApnDialog *self = (CcWwanApnDialog *)object;
g_clear_object (&self->device);
G_OBJECT_CLASS (cc_wwan_apn_dialog_parent_class)->finalize (object);
}
static void
cc_wwan_apn_dialog_show (GtkWidget *widget)
{
CcWwanApnDialog *self = (CcWwanApnDialog *)widget;
g_assert (CC_IS_WWAN_APN_DIALOG (widget));
/* XXX: bad idea? */
g_cancellable_reset (self->cancellable);
GTK_WIDGET_CLASS (cc_wwan_apn_dialog_parent_class)->show (widget);
}
static void
cc_wwan_apn_dialog_response (GtkDialog *dialog,
gint response_id)
{
CcWwanApnDialog *self = CC_WWAN_APN_DIALOG (dialog);
g_assert (CC_IS_WWAN_APN_DIALOG (self));
/* self->enable_data = FALSE; */
/* self->enable_roaming = FALSE; */
if (response_id != GTK_RESPONSE_APPLY)
return;
}
static void
cc_wwan_apn_dialog_class_init (CcWwanApnDialogClass *klass)
{
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = cc_wwan_apn_dialog_set_property;
object_class->constructed = cc_wwan_apn_dialog_constructed;
object_class->finalize = cc_wwan_apn_dialog_finalize;
widget_class->show = cc_wwan_apn_dialog_show;
dialog_class->response = cc_wwan_apn_dialog_response;
properties[PROP_DEVICE] =
g_param_spec_object ("device",
"Device",
"The WWAN Device",
CC_TYPE_WWAN_DEVICE,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/wwan/cc-wwan-apn-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, CcWwanApnDialog, back_button);
gtk_widget_class_bind_template_child (widget_class, CcWwanApnDialog, apn_settings_stack);
gtk_widget_class_bind_template_child (widget_class, CcWwanApnDialog, apn_list);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_apn_back_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_apn_activated_cb);
}
static void
cc_wwan_apn_dialog_init (CcWwanApnDialog *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
gtk_list_box_set_header_func (GTK_LIST_BOX (self->apn_list),
cc_list_box_update_header_func,
NULL, NULL);
}
GtkWidget *
cc_wwan_apn_dialog_new (GtkWindow *parent_window,
CcWwanDevice *device)
{
g_return_val_if_fail (GTK_IS_WINDOW (parent_window), NULL);
g_return_val_if_fail (CC_IS_WWAN_DEVICE (device), NULL);
return g_object_new (CC_TYPE_WWAN_APN_DIALOG,
"transient-for", parent_window,
"use-header-bar", 1,
"device", device,
NULL);
}
/* void */
/* cc_wwan_apn_dialog_enable_data (CcWwanApnDialog *self) */
/* { */
/* g_return_if_fail (CC_IS_WWAN_APN_DIALOG (self)); */
/* self->enable_data = TRUE; */
/* } */
/* void */
/* cc_wwan_apn_dialog_enable_roaming (CcWwanApnDialog *self) */
/* { */
/* g_return_if_fail (CC_IS_WWAN_APN_DIALOG (self)); */
/* self->enable_roaming = TRUE; */
/* } */
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* cc-wwan-apn-dialog.h
*
* Copyright 2019 Purism SPC
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author(s):
* Mohammed Sadiq <sadiq@sadiqpk.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#define HANDY_USE_UNSTABLE_API 1
#include <handy.h>
#include <shell/cc-panel.h>
#include "cc-wwan-device.h"
G_BEGIN_DECLS
#define CC_TYPE_WWAN_APN_DIALOG (cc_wwan_apn_dialog_get_type())
G_DECLARE_FINAL_TYPE (CcWwanApnDialog, cc_wwan_apn_dialog, CC, WWAN_APN_DIALOG, HdyDialog)
GtkWidget *cc_wwan_apn_dialog_new (GtkWindow *parent_window,
CcWwanDevice *device);
/* void cc_wwan_apn_dialog_enable_data (CcWwanApnDialog *self); */
/* void cc_wwan_apn_dialog_enable_roaming (CcWwanApnDialog *self); */
G_END_DECLS
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="CcWwanApnDialog" parent="HdyDialog">
<property name="title" translatable="yes">Access Points</property>
<property name="default-height">480</property>
<property name="default-width">360</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">1</property>
<child>
<object class="GtkButton" id="back_button">
<property name="visible">1</property>
<property name="use-underline">1</property>
<signal name="clicked" handler="cc_wwan_apn_back_clicked_cb" object="CcWwanApnDialog" swapped="yes" />
<child internal-child="accessible">
<object class="AtkObject">
<property name="accessible-name" translatable="yes">Back</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="icon-name">go-previous-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="pack-type">start</property>
</packing>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="visible">1</property>
<property name="border-width">0</property>
<property name="width-request">340</property>
<property name="height-request">360</property>
<child>
<object class="HdyColumn">
<property name="visible">1</property>
<property name="maximum-width">600</property>
<property name="linear-growth-width">400</property>
<property name="margin-top">32</property>
<property name="margin-bottom">32</property>
<property name="margin-start">18</property>
<property name="margin-end">18</property>
<child>
<object class="GtkStack" id="apn_settings_stack">
<property name="visible">1</property>
<property name="transition-type">slide-left</property>
<!-- Access Point List -->
<child>
<object class="GtkListBox" id="apn_list">
<property name="visible">1</property>
<property name="selection-mode">none</property>
<signal name="row-activated" handler="cc_wwan_apn_activated_cb" object="CcWwanApnDialog" swapped="yes" />
<style>
<class name="frame" />
</style>
</object>
<packing>
<property name="name">apn-list</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">1</property>
<property name="orientation">vertical</property>
<property name="expand">1</property>
<property name="valign">center</property>
<property name="halign">center</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">128</property>
<property name="icon-name">dialog-password-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">apn-edit</property>
</packing>
</child>
</object> <!-- ./GtkStack apn_settings_stack -->
</child>
</object>
</child>
</object>
</child> <!-- ./internal-child -->
</template>
</interface>
This diff is collapsed.
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* cc-wwan-data.h
*
* Copyright 2019 Purism SPC
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author(s):
* Mohammed Sadiq <sadiq@sadiqpk.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <glib-object.h>
#include <libmm-glib.h>
#include <NetworkManager.h>
G_BEGIN_DECLS
typedef struct _CcWwanDataAPN CcWwanDataAPN;
#define CC_TYPE_WWAN_DATA (cc_wwan_data_get_type())
G_DECLARE_FINAL_TYPE (CcWwanData, cc_wwan_data, CC, WWAN_DATA, GObject)
CcWwanData *cc_wwan_data_new (MMObject *mm_object,
NMClient *nm_client);
GError *cc_wwan_data_get_error (CcWwanData *self);
gchar *cc_wwan_data_get_simple_html_error (CcWwanData *self);
GSList *cc_wwan_data_get_apn_list (CcWwanData *self);
void cc_wwan_data_save_apn (CcWwanData *self,
CcWwanDataAPN *apn,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
CcWwanDataAPN *cc_wwan_data_save_apn_finish (CcWwanData *self,
GAsyncResult *result,
GError **error);
void cc_wwan_data_save_settings (CcWwanData *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean cc_wwan_data_save_settings_finish (CcWwanData *self,
GAsyncResult *result,
GError **error);
gboolean cc_wwan_data_delete_apn (CcWwanData *self,
CcWwanDataAPN *apn,
GCancellable *cancellable,
GError **error);
void cc_wwan_data_set_default_apn (CcWwanData *self,
CcWwanDataAPN *apn);
CcWwanDataAPN *cc_wwan_data_get_default_apn (CcWwanData *self);
gboolean cc_wwan_data_get_enabled (CcWwanData *self);
void cc_wwan_data_set_enabled (CcWwanData *self,
gboolean enabled);
gboolean cc_wwan_data_get_roaming_enabled (CcWwanData *self);
void cc_wwan_data_set_roaming_enabled (CcWwanData *self,
gboolean enable_roaming);
const gchar *cc_wwan_data_apn_get_name (CcWwanDataAPN *apn);
void cc_wwan_data_apn_set_name (CcWwanDataAPN *apn,
const gchar *name);
const gchar *cc_wwan_data_apn_get_apn (CcWwanDataAPN *apn);
void cc_wwan_data_apn_set_apn (CcWwanDataAPN *apn,
const gchar *apn_name);
G_END_DECLS
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* cc-wwan-device-page.c
*
* Copyright 2019 Purism SPC
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author(s):
* Mohammed Sadiq <sadiq@sadiqpk.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "cc-wwan-device-page"
#include <config.h>
#include <glib/gi18n.h>
#include <libmm-glib.h>
#include "list-box-helper.h"
#include "cc-wwan-data.h"
#include "cc-wwan-mode-dialog.h"
#include "cc-wwan-network-dialog.h"
#include "cc-wwan-sim-lock-dialog.h"
#include "cc-wwan-apn-dialog.h"
#include "cc-wwan-device-page.h"
#include "cc-wwan-resources.h"
#include "shell/cc-application.h"