LCOV - code coverage report
Current view: top level - glib/gio/tests - gapplication-example-actions.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 66 0.0 %
Date: 2024-04-23 05:16:05 Functions: 0 6 0.0 %
Branches: 0 22 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include <gio/gio.h>
       2                 :            : #include <stdlib.h>
       3                 :            : #include <string.h>
       4                 :            : 
       5                 :            : static void
       6                 :          0 : activate (GApplication *application)
       7                 :            : {
       8                 :          0 :   g_application_hold (application);
       9                 :          0 :   g_print ("activated\n");
      10                 :          0 :   g_application_release (application);
      11                 :          0 : }
      12                 :            : 
      13                 :            : static void
      14                 :          0 : activate_action (GAction  *action,
      15                 :            :                  GVariant *parameter,
      16                 :            :                  gpointer  data)
      17                 :            : {
      18                 :          0 :   GApplication *application = G_APPLICATION (data);
      19                 :            : 
      20                 :          0 :   g_application_hold (application);
      21                 :          0 :   g_print ("action %s activated\n", g_action_get_name (action));
      22                 :          0 :   g_application_release (application);
      23                 :          0 : }
      24                 :            : 
      25                 :            : static void
      26                 :          0 : activate_toggle_action (GSimpleAction *action,
      27                 :            :                         GVariant      *parameter,
      28                 :            :                         gpointer       data)
      29                 :            : {
      30                 :          0 :   GApplication *application = G_APPLICATION (data);
      31                 :            :   GVariant *state;
      32                 :            :   gboolean b;
      33                 :            : 
      34                 :          0 :   g_print ("action %s activated\n", g_action_get_name (G_ACTION (action)));
      35                 :            : 
      36                 :          0 :   g_application_hold (application);
      37                 :          0 :   state = g_action_get_state (G_ACTION (action));
      38                 :          0 :   b = g_variant_get_boolean (state);
      39                 :          0 :   g_variant_unref (state);
      40                 :          0 :   g_simple_action_set_state (action, g_variant_new_boolean (!b));
      41                 :          0 :   g_print ("state change %d -> %d\n", b, !b);
      42                 :          0 :   g_application_release (application);
      43                 :          0 : }
      44                 :            : 
      45                 :            : static void
      46                 :          0 : add_actions (GApplication *app)
      47                 :            : {
      48                 :            :   GSimpleAction *action;
      49                 :            : 
      50                 :          0 :   action = g_simple_action_new ("simple-action", NULL);
      51                 :          0 :   g_signal_connect (action, "activate", G_CALLBACK (activate_action), app);
      52                 :          0 :   g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
      53                 :          0 :   g_object_unref (action);
      54                 :            : 
      55                 :          0 :   action = g_simple_action_new_stateful ("toggle-action", NULL,
      56                 :            :                                          g_variant_new_boolean (FALSE));
      57                 :          0 :   g_signal_connect (action, "activate", G_CALLBACK (activate_toggle_action), app);
      58                 :          0 :   g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
      59                 :          0 :   g_object_unref (action);
      60                 :          0 : }
      61                 :            : 
      62                 :            : static void
      63                 :          0 : describe_and_activate_action (GActionGroup *group,
      64                 :            :                               const gchar  *name)
      65                 :            : {
      66                 :            :   const GVariantType *param_type;
      67                 :            :   GVariant *state;
      68                 :            :   gboolean enabled;
      69                 :            :   gchar *tmp;
      70                 :            : 
      71                 :          0 :   param_type = g_action_group_get_action_parameter_type (group, name);
      72                 :          0 :   state = g_action_group_get_action_state (group, name);
      73                 :          0 :   enabled = g_action_group_get_action_enabled (group, name);
      74                 :            : 
      75                 :          0 :   g_print ("action name:      %s\n", name);
      76         [ #  # ]:          0 :   tmp = param_type ? g_variant_type_dup_string (param_type) : NULL;
      77         [ #  # ]:          0 :   g_print ("parameter type:   %s\n", tmp ? tmp : "<none>");
      78                 :          0 :   g_free (tmp);
      79         [ #  # ]:          0 :   g_print ("state type:       %s\n",
      80                 :          0 :            state ? g_variant_get_type_string (state) : "<none>");
      81         [ #  # ]:          0 :   tmp = state ? g_variant_print (state, FALSE) : NULL;
      82         [ #  # ]:          0 :   g_print ("state:            %s\n", tmp ? tmp : "<none>");
      83                 :          0 :   g_free (tmp);
      84         [ #  # ]:          0 :   g_print ("enabled:          %s\n", enabled ? "true" : "false");
      85                 :            : 
      86         [ #  # ]:          0 :   if (state != NULL)
      87                 :          0 :     g_variant_unref (state);
      88                 :            : 
      89                 :          0 :   g_action_group_activate_action (group, name, NULL);
      90                 :          0 : }
      91                 :            : 
      92                 :            : int
      93                 :          0 : main (int argc, char **argv)
      94                 :            : {
      95                 :            :   GApplication *app;
      96                 :            :   int status;
      97                 :            : 
      98                 :          0 :   app = g_application_new ("org.gtk.TestApplication", 0);
      99                 :          0 :   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
     100                 :          0 :   g_application_set_inactivity_timeout (app, 10000);
     101                 :            : 
     102                 :          0 :   add_actions (app);
     103                 :            : 
     104   [ #  #  #  # ]:          0 :   if (argc > 1 && strcmp (argv[1], "--simple-action") == 0)
     105                 :            :     {
     106                 :          0 :       g_application_register (app, NULL, NULL);
     107                 :          0 :       describe_and_activate_action (G_ACTION_GROUP (app), "simple-action");
     108                 :          0 :       exit (0);
     109                 :            :     }
     110   [ #  #  #  # ]:          0 :   else if (argc > 1 && strcmp (argv[1], "--toggle-action") == 0)
     111                 :            :     {
     112                 :          0 :       g_application_register (app, NULL, NULL);
     113                 :          0 :       describe_and_activate_action (G_ACTION_GROUP (app), "toggle-action");
     114                 :          0 :       exit (0);
     115                 :            :     }
     116                 :            : 
     117                 :          0 :   status = g_application_run (app, argc, argv);
     118                 :            : 
     119                 :          0 :   g_object_unref (app);
     120                 :            : 
     121                 :          0 :   return status;
     122                 :            : }

Generated by: LCOV version 1.14