File: notify-blocks.c

package info (click to toggle)
phosh 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 9,868 kB
  • sloc: ansic: 83,377; xml: 3,981; python: 717; sh: 449; makefile: 34; lisp: 22; javascript: 6
file content (132 lines) | stat: -rw-r--r-- 4,981 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright © 2020 Zander Brown <zbrown@gnome.org>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Zander Brown <zbrown@gnome.org>
 *
 * Static notification blocks for experimenting with styles
 *
 * For testing the notification server (rather than widget style) see
 * notify-server-standalone
 */

#include <gtk/gtk.h>
#include <gio/gdesktopappinfo.h>
#include <notifications/notification-frame.h>
#include <notifications/notification.h>


static void
empty (PhoshNotificationFrame *self, GtkWidget *box)
{
  gtk_container_remove (GTK_CONTAINER (box), GTK_WIDGET (self));
}


int
main (int argc, char **argv)
{
  GtkWidget *window = NULL;
  GtkWidget *scrolled = NULL;
  GtkWidget *box = NULL;
  GtkWidget *frame = NULL;
  GDesktopAppInfo *app = NULL;
  GStrv actions = (char *[]) { "ok", "Okay", NULL };
  GIcon *image = NULL;
  PhoshNotification *notification = NULL;
  GtkCssProvider *provider = NULL;
  GFile *file = NULL;
  GError *error = NULL;
  g_autoptr (GDateTime) now = g_date_time_new_now_local ();

  gtk_init (&argc, &argv);

  provider = gtk_css_provider_new ();
  file = g_file_new_for_uri ("resource:///mobi/phosh/stylesheet/adwaita-dark.css");

  if (!gtk_css_provider_load_from_file (provider, file, &error)) {
    g_warning ("Failed to load CSS file: %s", error->message);
    g_clear_error (&error);
    return 1;
  }
  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                             GTK_STYLE_PROVIDER (provider),
                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  g_object_set (gtk_settings_get_default (),
                "gtk-application-prefer-dark-theme", TRUE,
                NULL);

  window = g_object_new (GTK_TYPE_WINDOW,
                         "visible", TRUE,
                         "default-height", 640,
                         "default-width", 360,
                         "height-request", 640,
                         "width-request", 360,
                         "title", "PhoshNotificationFrame Demo",
                         NULL);
  g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);

  scrolled = g_object_new (GTK_TYPE_SCROLLED_WINDOW,
                           "vscrollbar-policy", GTK_POLICY_NEVER,
                           "visible", TRUE,
                           NULL);
  gtk_container_add (GTK_CONTAINER (window), scrolled);

  box = g_object_new (GTK_TYPE_BOX,
                      "margin-start", 6,
                      "margin-top", 6,
                      "margin-end", 6,
                      "margin-bottom", 6,
                      "orientation", GTK_ORIENTATION_VERTICAL,
                      "visible", TRUE,
                      NULL);
  gtk_container_add (GTK_CONTAINER (scrolled), box);

  app = g_desktop_app_info_new ("org.gnome.Calculator.desktop");
  notification = phosh_notification_new (0,
                                         "Not Shown",
                                         G_APP_INFO (app),
                                         "2 + 2",
                                         "= 4",
                                         NULL,
                                         NULL,
                                         PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                         actions,
                                         FALSE,
                                         FALSE,
                                         NULL,
                                         NULL,
                                         now);
  frame = phosh_notification_frame_new (TRUE, NULL);
  phosh_notification_frame_bind_notification (PHOSH_NOTIFICATION_FRAME (frame),
                                              notification);
  g_signal_connect (frame, "empty", G_CALLBACK (empty), box);
  gtk_container_add (GTK_CONTAINER (box), frame);

  image = g_themed_icon_new ("org.gnome.Software");
  notification = phosh_notification_new (1,
                                         "Some App",
                                         NULL,
                                         "2 + 2",
                                         "= 4",
                                         NULL,
                                         image,
                                         PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                         NULL,
                                         FALSE,
                                         FALSE,
                                         NULL,
                                         NULL,
                                         now);
  frame = phosh_notification_frame_new (TRUE, NULL);
  phosh_notification_frame_bind_notification (PHOSH_NOTIFICATION_FRAME (frame),
                                              notification);
  g_signal_connect (frame, "empty", G_CALLBACK (empty), box);
  gtk_container_add (GTK_CONTAINER (box), frame);

  gtk_main ();

  return 0;
}