summaryrefslogtreecommitdiffstats
path: root/tests/network/cc-test-window.c
blob: 3e27fa90c73958035f7d030d1cbaaf7002275452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Copyright (c) 2009, 2010 Intel, Inc.
 * Copyright (c) 2010, 2018 Red Hat, Inc.
 * Copyright (c) 2016 Endless, Inc.
 *
 * The Control Center 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 2 of the License, or (at your
 * option) any later version.
 *
 * The Control Center 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 the Control Center; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author: Benjamin Berg <bberg@redhat.com>
 */

#define G_LOG_DOMAIN "cc-test-window"

#include <config.h>

#include "cc-test-window.h"

#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>

#include "shell/cc-panel.h"
#include "shell/cc-shell.h"
#include "cc-util.h"


struct _CcTestWindow
{
  GtkWindow    parent;

  GtkWidget   *main_box;

  GtkWidget  *header;
  CcPanel    *active_panel;
};

static void     cc_shell_iface_init         (CcShellInterface      *iface);

G_DEFINE_TYPE_WITH_CODE (CcTestWindow, cc_test_window, GTK_TYPE_WINDOW,
                         G_IMPLEMENT_INTERFACE (CC_TYPE_SHELL, cc_shell_iface_init))

enum
{
  PROP_0,
  PROP_ACTIVE_PANEL
};



static void
set_active_panel (CcTestWindow *shell,
                  CcPanel      *panel)
{
  g_assert (CC_IS_SHELL (shell));
  g_assert (CC_IS_PANEL (panel));

  /* Only allow setting to a non NULL value once. */
  g_assert (shell->active_panel == NULL);

  if (panel)
    {
      shell->active_panel = g_object_ref (panel);
      gtk_box_append (GTK_BOX (shell->main_box), GTK_WIDGET (panel));
    }
}

/* CcShell implementation */
static gboolean
cc_test_window_set_active_panel_from_id (CcShell      *shell,
                                         const gchar  *start_id,
                                         GVariant     *parameters,
                                         GError      **error)
{
  /* Not implemented */
  g_assert_not_reached ();
}

static GtkWidget *
cc_test_window_get_toplevel (CcShell *shell)
{
  return GTK_WIDGET (shell);
}

static void
cc_shell_iface_init (CcShellInterface *iface)
{
  iface->set_active_panel_from_id = cc_test_window_set_active_panel_from_id;
  iface->get_toplevel = cc_test_window_get_toplevel;
}

/* GObject Implementation */
static void
cc_test_window_get_property (GObject    *object,
                             guint       property_id,
                             GValue     *value,
                             GParamSpec *pspec)
{
  CcTestWindow *self = CC_TEST_WINDOW (object);

  switch (property_id)
    {
    case PROP_ACTIVE_PANEL:
      g_value_set_object (value, self->active_panel);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static void
cc_test_window_set_property (GObject      *object,
                             guint         property_id,
                             const GValue *value,
                             GParamSpec   *pspec)
{
  CcTestWindow *shell = CC_TEST_WINDOW (object);

  switch (property_id)
    {
    case PROP_ACTIVE_PANEL:
      set_active_panel (shell, g_value_get_object (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static void
cc_test_window_dispose (GObject *object)
{
  CcTestWindow *self = CC_TEST_WINDOW (object);

  g_clear_object (&self->active_panel);

  G_OBJECT_CLASS (cc_test_window_parent_class)->dispose (object);
}

static void
cc_test_window_class_init (CcTestWindowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->get_property = cc_test_window_get_property;
  object_class->set_property = cc_test_window_set_property;
  object_class->dispose = cc_test_window_dispose;

  g_object_class_override_property (object_class, PROP_ACTIVE_PANEL, "active-panel");
}

static void
cc_test_window_init (CcTestWindow *self)
{
  gtk_widget_set_size_request (GTK_WIDGET (self), 500, 800);

  self->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);

  gtk_window_set_child (GTK_WINDOW (self), self->main_box);
}

CcTestWindow *
cc_test_window_new (void)
{
  return g_object_new (CC_TYPE_TEST_WINDOW,
                       "resizable", TRUE,
                       "title", "Test Settings",
                       NULL);
}