Blame clients/tui/nmt-page-dsl.c

Packit Service 87a54e
/* SPDX-License-Identifier: GPL-2.0-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2014 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * SECTION:nmt-page-dsl
Packit 5756e2
 * @short_description: The editor page for DSL connections
Packit 5756e2
 */
Packit 5756e2
Packit Service 2bceb2
#include "libnm/nm-default-client.h"
Packit 5756e2
Packit 5756e2
#include "nmt-page-dsl.h"
Packit 5756e2
#include "nmt-page-ethernet.h"
Packit 5756e2
#include "nmt-page-ppp.h"
Packit 5756e2
#include "nmt-password-fields.h"
Packit 5756e2
Packit Service a1bd4f
G_DEFINE_TYPE(NmtPageDsl, nmt_page_dsl, NMT_TYPE_EDITOR_PAGE_DEVICE)
Packit 5756e2
Packit Service a1bd4f
#define NMT_PAGE_DSL_GET_PRIVATE(o) \
Packit Service a1bd4f
    (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_PAGE_DSL, NmtPageDslPrivate))
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NmtEditorPage *ethernet_page, *ppp_page;
Packit 5756e2
Packit 5756e2
} NmtPageDslPrivate;
Packit 5756e2
Packit 5756e2
NmtEditorPage *
Packit Service a1bd4f
nmt_page_dsl_new(NMConnection *conn, NmtDeviceEntry *deventry)
Packit 5756e2
{
Packit Service a1bd4f
    return g_object_new(NMT_TYPE_PAGE_DSL, "connection", conn, "device-entry", deventry, NULL);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_dsl_init(NmtPageDsl *dsl)
Packit Service a1bd4f
{}
Packit 5756e2
Packit 5756e2
static NmtEditorSection *
Packit Service a1bd4f
build_dsl_section(NmtPageDsl *dsl, NMSettingPppoe *s_pppoe)
Packit 5756e2
{
Packit Service a1bd4f
    NmtEditorSection *section;
Packit Service a1bd4f
    NmtEditorGrid *   grid;
Packit Service a1bd4f
    NmtNewtWidget *   widget;
Packit Service a1bd4f
Packit Service a1bd4f
    section = nmt_editor_section_new(_("DSL"), NULL, TRUE);
Packit Service a1bd4f
    grid    = nmt_editor_section_get_body(section);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_new(40, 0);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Username"), widget, NULL);
Packit Service a1bd4f
    g_object_bind_property(s_pppoe,
Packit Service a1bd4f
                           NM_SETTING_PPPOE_USERNAME,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_password_fields_new(40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
Packit Service a1bd4f
    g_object_bind_property(s_pppoe,
Packit Service a1bd4f
                           NM_SETTING_PPPOE_PASSWORD,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "password",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Password"), widget, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_new(40, 0);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Service"), widget, NULL);
Packit Service a1bd4f
    g_object_bind_property(s_pppoe,
Packit Service a1bd4f
                           NM_SETTING_PPPOE_SERVICE,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
Packit Service a1bd4f
Packit Service a1bd4f
    return section;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_dsl_constructed(GObject *object)
Packit 5756e2
{
Packit Service a1bd4f
    NmtPageDsl *       dsl  = NMT_PAGE_DSL(object);
Packit Service a1bd4f
    NmtPageDslPrivate *priv = NMT_PAGE_DSL_GET_PRIVATE(dsl);
Packit Service a1bd4f
    NMConnection *     conn;
Packit Service a1bd4f
    NMSettingPppoe *   s_pppoe;
Packit Service a1bd4f
    NmtEditorSection * section;
Packit Service a1bd4f
    const GSList *     sections, *iter;
Packit Service a1bd4f
Packit Service a1bd4f
    conn    = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(dsl));
Packit Service a1bd4f
    s_pppoe = nm_connection_get_setting_pppoe(conn);
Packit Service a1bd4f
    if (!s_pppoe) {
Packit Service a1bd4f
        nm_connection_add_setting(conn, nm_setting_pppoe_new());
Packit Service a1bd4f
        s_pppoe = nm_connection_get_setting_pppoe(conn);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    section = build_dsl_section(dsl, s_pppoe);
Packit Service a1bd4f
    nmt_editor_page_add_section(NMT_EDITOR_PAGE(dsl), section);
Packit Service a1bd4f
Packit Service a1bd4f
    priv->ethernet_page =
Packit Service a1bd4f
        nmt_page_ethernet_new(conn,
Packit Service a1bd4f
                              nmt_editor_page_device_get_device_entry(NMT_EDITOR_PAGE_DEVICE(dsl)));
Packit Service a1bd4f
    sections = nmt_editor_page_get_sections(priv->ethernet_page);
Packit Service a1bd4f
    for (iter = sections; iter; iter = iter->next)
Packit Service a1bd4f
        nmt_editor_page_add_section(NMT_EDITOR_PAGE(dsl), iter->data);
Packit Service a1bd4f
Packit Service a1bd4f
    priv->ppp_page = nmt_page_ppp_new(conn);
Packit Service a1bd4f
    sections       = nmt_editor_page_get_sections(priv->ppp_page);
Packit Service a1bd4f
    for (iter = sections; iter; iter = iter->next)
Packit Service a1bd4f
        nmt_editor_page_add_section(NMT_EDITOR_PAGE(dsl), iter->data);
Packit Service a1bd4f
Packit Service a1bd4f
    G_OBJECT_CLASS(nmt_page_dsl_parent_class)->constructed(object);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_dsl_finalize(GObject *object)
Packit 5756e2
{
Packit Service a1bd4f
    NmtPageDsl *       dsl  = NMT_PAGE_DSL(object);
Packit Service a1bd4f
    NmtPageDslPrivate *priv = NMT_PAGE_DSL_GET_PRIVATE(dsl);
Packit 5756e2
Packit Service a1bd4f
    g_clear_object(&priv->ethernet_page);
Packit Service a1bd4f
    g_clear_object(&priv->ppp_page);
Packit 5756e2
Packit Service a1bd4f
    G_OBJECT_CLASS(nmt_page_dsl_parent_class)->finalize(object);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_dsl_class_init(NmtPageDslClass *dsl_class)
Packit 5756e2
{
Packit Service a1bd4f
    GObjectClass *object_class = G_OBJECT_CLASS(dsl_class);
Packit 5756e2
Packit Service a1bd4f
    g_type_class_add_private(object_class, sizeof(NmtPageDslPrivate));
Packit 5756e2
Packit Service a1bd4f
    object_class->constructed = nmt_page_dsl_constructed;
Packit Service a1bd4f
    object_class->finalize    = nmt_page_dsl_finalize;
Packit 5756e2
}