Skip to content

Commit e1a49d7

Browse files
committed
Add initial shell based on GNOME Control Center code.
1 parent 5b8a96f commit e1a49d7

File tree

6 files changed

+441
-0
lines changed

6 files changed

+441
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ compile_commands.json
88
omp
99
PKGBUILD
1010
TODO
11+
/src/clang-format
1112
/subprojects/blueprint-compiler

src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ executable(
3131
'app.c',
3232
'sidebar.c',
3333
'content.c',
34+
'panel.c',
35+
'shell.c',
3436
'appwin.c',
3537
'main.c',
3638
omp_resources,

src/panel.c

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#include "panel.h"
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
#include <gio/gio.h>
7+
#include <gtk/gtk.h>
8+
9+
typedef struct {
10+
OMPShell* shell;
11+
GCancellable* cancellable;
12+
13+
gchar* subpage;
14+
} OMPPanelPrivate;
15+
16+
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
17+
OMPPanel, omp_panel, ADW_TYPE_NAVIGATION_PAGE, G_ADD_PRIVATE (OMPPanel)
18+
)
19+
20+
enum { PROP_0, PROP_SHELL, PROP_PARAMETERS, PROP_SUBPAGE, N_PROPS };
21+
22+
static GParamSpec* properties[N_PROPS];
23+
24+
/* GtkBuildable interface */
25+
26+
/* GObject overrides */
27+
28+
static void
29+
omp_panel_set_property (
30+
GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec
31+
)
32+
{
33+
OMPPanelPrivate* priv = omp_panel_get_instance_private (OMP_PANEL (object));
34+
35+
switch (prop_id) {
36+
case PROP_SHELL:
37+
/* construct only property */
38+
priv->shell = g_value_get_object (value);
39+
break;
40+
41+
case PROP_PARAMETERS: {
42+
g_autoptr (GVariant) v = NULL;
43+
GVariant* parameters;
44+
gsize n_parameters;
45+
46+
parameters = g_value_get_variant (value);
47+
48+
if (parameters == NULL)
49+
return;
50+
51+
n_parameters = g_variant_n_children (parameters);
52+
if (n_parameters == 0)
53+
return;
54+
55+
g_variant_get_child (parameters, 0, "v", &v);
56+
57+
if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) {
58+
g_set_str (&priv->subpage, g_variant_get_string (v, NULL));
59+
g_object_notify_by_pspec (object, properties[PROP_SUBPAGE]);
60+
}
61+
else if (!g_variant_is_of_type (v, G_VARIANT_TYPE_DICTIONARY))
62+
g_warning (
63+
"Wrong type for the first argument GVariant, expected "
64+
"'a{sv}' but got '%s'",
65+
(gchar*)g_variant_get_type (v)
66+
);
67+
else if (g_variant_n_children (v) > 0)
68+
g_warning ("Ignoring additional flags");
69+
70+
if (n_parameters > 1)
71+
g_warning ("Ignoring additional parameters");
72+
73+
break;
74+
}
75+
76+
default:
77+
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
78+
break;
79+
}
80+
}
81+
82+
static void
83+
omp_panel_get_property (
84+
GObject* object, guint prop_id, GValue* value, GParamSpec* pspec
85+
)
86+
{
87+
OMPPanelPrivate* priv = omp_panel_get_instance_private (OMP_PANEL (object));
88+
89+
switch (prop_id) {
90+
case PROP_SHELL:
91+
g_value_set_object (value, priv->shell);
92+
break;
93+
94+
case PROP_SUBPAGE:
95+
g_value_set_string (value, priv->subpage);
96+
break;
97+
98+
default:
99+
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
100+
break;
101+
}
102+
}
103+
104+
static void
105+
omp_panel_finalize (GObject* object)
106+
{
107+
OMPPanelPrivate* priv = omp_panel_get_instance_private (OMP_PANEL (object));
108+
109+
g_cancellable_cancel (priv->cancellable);
110+
g_clear_object (&priv->cancellable);
111+
g_clear_pointer (&priv->subpage, g_free);
112+
113+
G_OBJECT_CLASS (omp_panel_parent_class)->finalize (object);
114+
}
115+
116+
static void
117+
omp_panel_class_init (OMPPanelClass* klass)
118+
{
119+
GObjectClass* object_class = G_OBJECT_CLASS (klass);
120+
121+
object_class->get_property = omp_panel_get_property;
122+
object_class->set_property = omp_panel_set_property;
123+
object_class->finalize = omp_panel_finalize;
124+
125+
properties[PROP_SHELL] = g_param_spec_object (
126+
"shell", "Shell", "Shell the Panel resides in", OMP_TYPE_SHELL,
127+
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS
128+
);
129+
130+
properties[PROP_PARAMETERS] = g_param_spec_variant (
131+
"parameters", "Structured parameters",
132+
"Additional parameters passed externally (ie. command line, D-Bus "
133+
"activation)",
134+
G_VARIANT_TYPE ("av"), NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS
135+
);
136+
137+
properties[PROP_SUBPAGE] = g_param_spec_string (
138+
"subpage", "Subpage parameters",
139+
"Additional parameter extracted from the parameters property to launch "
140+
"a panel subpage",
141+
NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
142+
);
143+
144+
g_object_class_install_properties (object_class, N_PROPS, properties);
145+
}
146+
147+
static void
148+
omp_panel_init (OMPPanel* panel)
149+
{
150+
}
151+
152+
/**
153+
* omp_panel_get_shell:
154+
* @panel: A #OMPPanel
155+
*
156+
* Get the shell that the panel resides in
157+
*
158+
* Returns: a #OMPShell
159+
*/
160+
OMPShell*
161+
omp_panel_get_shell (OMPPanel* panel)
162+
{
163+
OMPPanelPrivate* priv;
164+
165+
g_return_val_if_fail (OMP_IS_PANEL (panel), NULL);
166+
167+
priv = omp_panel_get_instance_private (panel);
168+
169+
return priv->shell;
170+
}
171+
172+
const gchar*
173+
omp_panel_get_help_uri (OMPPanel* panel)
174+
{
175+
OMPPanelClass* class = OMP_PANEL_GET_CLASS (panel);
176+
177+
if (class->get_help_uri)
178+
return class->get_help_uri (panel);
179+
180+
return NULL;
181+
}
182+
183+
GCancellable*
184+
omp_panel_get_cancellable (OMPPanel* panel)
185+
{
186+
OMPPanelPrivate* priv = omp_panel_get_instance_private (panel);
187+
188+
g_return_val_if_fail (OMP_IS_PANEL (panel), NULL);
189+
190+
if (priv->cancellable == NULL)
191+
priv->cancellable = g_cancellable_new ();
192+
193+
return priv->cancellable;
194+
}
195+
196+
void
197+
omp_panel_deactivate (OMPPanel* panel)
198+
{
199+
OMPPanelPrivate* priv = omp_panel_get_instance_private (panel);
200+
201+
g_cancellable_cancel (priv->cancellable);
202+
}

src/panel.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
#include <adwaita.h>
4+
5+
/**
6+
* Utility macro used to register panels
7+
*
8+
* use: OMP_PANEL_REGISTER (PluginName, plugin_name)
9+
*/
10+
#define OMP_PANEL_REGISTER(PluginName, plugin_name) \
11+
G_DEFINE_TYPE (PluginName, plugin_name, OMP_TYPE_PANEL)
12+
13+
/**
14+
* OMPPanelStaticInitFunc:
15+
*
16+
* Function that statically allocates resources and initializes
17+
* any data that the panel will make use of during runtime.
18+
*
19+
* If panels represent hardware that can potentially not exist,
20+
* e.g. the Wi-Fi panel, these panels can use this function to
21+
* show or hide themselves without needing to have an instance
22+
* created and running.
23+
*/
24+
typedef void (*OMPPanelStaticInitFunc) (void);
25+
26+
#define OMP_TYPE_PANEL (omp_panel_get_type ())
27+
G_DECLARE_DERIVABLE_TYPE (OMPPanel, omp_panel, OMP, PANEL, AdwNavigationPage)
28+
29+
/**
30+
* OMPPanelVisibility:
31+
*
32+
* @OMP_PANEL_HIDDEN: Panel is hidden from search and sidebar, and not
33+
* reachable.
34+
* @OMP_PANEL_VISIBLE_IN_SEARCH: Panel is hidden from main view, but can be
35+
* aompessed from search.
36+
* @OMP_PANEL_VISIBLE: Panel is visible everywhere.
37+
*/
38+
typedef enum {
39+
OMP_PANEL_HIDDEN,
40+
OMP_PANEL_VISIBLE_IN_SEARCH,
41+
OMP_PANEL_VISIBLE,
42+
} OMPPanelVisibility;
43+
44+
/* omp-shell.h requires OMPPanel, so make sure it is defined first */
45+
#include "shell.h"
46+
47+
G_BEGIN_DECLS
48+
49+
/**
50+
* OMPPanelClass:
51+
*
52+
* The contents of this struct are private and should not be aompessed directly.
53+
*/
54+
struct _OMPPanelClass {
55+
/*< private >*/
56+
AdwNavigationPageClass parent_class;
57+
58+
const gchar* (*get_help_uri) (OMPPanel* panel);
59+
};
60+
61+
OMPShell* omp_panel_get_shell (OMPPanel* panel);
62+
63+
GPermission* omp_panel_get_permission (OMPPanel* panel);
64+
65+
const gchar* omp_panel_get_help_uri (OMPPanel* panel);
66+
67+
GCancellable* omp_panel_get_cancellable (OMPPanel* panel);
68+
69+
void omp_panel_deactivate (OMPPanel* panel);
70+
71+
G_END_DECLS

0 commit comments

Comments
 (0)