static void
ntf_wm_update_notification (NtfNotification *ntf, MetaWindow *window)
{
  ClutterActor *src_icon;
  ClutterActor *button;
  NtfSource    *src;
  const gchar  *title;
  const gchar  *summary;
  const gchar  *body;

  g_return_if_fail (ntf && window);

  src = ntf_notification_get_source (ntf);

  if ((src_icon = ntf_source_get_icon (src)))
    {
      ClutterActor *icon = clutter_clone_new (src_icon) ;

      ntf_notification_set_icon (ntf, icon);
    }

  title = meta_window_get_title (window);

  if (title)
    summary = title;
  else
    summary = _("Unknown window");

  ntf_notification_set_summary (ntf, summary);

  body = _("is asking for your attention.");

  ntf_notification_set_body (ntf, body);

  ntf_notification_remove_all_buttons (ntf);

  button = mx_button_new ();

  mx_button_set_label (MX_BUTTON (button), _("Activate"));

  g_signal_connect (button, "clicked",
                    G_CALLBACK (ntf_wm_activate_cb),
                    window);

  ntf_notification_add_button (ntf, button, 0);
}
Exemple #2
0
static void
ntf_libnotify_update (NtfNotification *ntf, Notification *details)
{
  ClutterActor *icon = NULL;

  g_return_if_fail (store && ntf && details);

  if (details->summary)
    ntf_notification_set_summary (ntf, details->summary);

  if (details->body)
    ntf_notification_set_body (ntf, details->body);

  if (details->icon_pixbuf)
    {
      GdkPixbuf *pixbuf = details->icon_pixbuf;

      icon = clutter_texture_new ();

      clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (icon),
                                         gdk_pixbuf_get_pixels (pixbuf),
                                         gdk_pixbuf_get_has_alpha (pixbuf),
                                         gdk_pixbuf_get_width (pixbuf),
                                         gdk_pixbuf_get_height (pixbuf),
                                         gdk_pixbuf_get_rowstride (pixbuf),
                                         gdk_pixbuf_get_has_alpha (pixbuf) ?
                                         4 : 3,
                                         0, NULL);
    }
  else if (details->icon_name)
    {
      GtkIconTheme *theme;
      GtkIconInfo  *info;

      theme = gtk_icon_theme_get_default ();
      info = gtk_icon_theme_lookup_icon (theme, details->icon_name, 24, 0);

      if (info)
        {
          icon = clutter_texture_new ();

          clutter_texture_set_from_file (CLUTTER_TEXTURE(icon),
                                         gtk_icon_info_get_filename (info),
                                         NULL);
          gtk_icon_info_free (info);
        }
    }

  if (icon)
    clutter_actor_set_size (icon, 24.0, 24.0);
  ntf_notification_set_icon (ntf, icon);

  if (details->actions)
    {
      GList *action;
      gchar *key, *value;

      ntf_notification_remove_all_buttons (ntf);

      for (action = details->actions; action;)
        {
          /*
           * The action list length is
           * guaranteed to be % 2 and > 0
           */
          key = action->data;
          action = g_list_next (action);
          value = action->data;
          action = g_list_next (action);

          if (strcasecmp(key, "default") != 0)
            {
              ActionData   *data;
              ClutterActor *button;
              KeySym        keysym = 0;

              data = g_slice_new0 (ActionData);
              data->notification = ntf;
              data->action       = g_strdup (key);
              data->id           = details->id;
              data->store        = store;

              button = mx_button_new ();

              mx_button_set_label (MX_BUTTON (button), value);

              g_signal_connect_data (button, "clicked",
                                     G_CALLBACK (ntf_libnotify_action_cb),
                                     data,
                                     (GClosureNotify) free_action_data,
                                     0);

              /*
               * Handle the dawati key shortcut protocol
               */
              if (!strncmp (key, DAWATI_KEY_PREFIX, strlen (DAWATI_KEY_PREFIX)))
                {
                  const char *k = key + strlen (DAWATI_KEY_PREFIX);
                  const char *pfx = strstr (k, "XK_");
                  char       *name;

                  if (pfx)
                    {
                      if (k == pfx)
                        {
                          name = g_strdup (k + 3);
                        }
                      else
                        {
                          name = g_strdup (k);

                          name [pfx - k] = 0;
                          strcat (name, pfx + 3);
                        }

                      keysym = XStringToKeysym (name);

                      if (!keysym)
                        g_warning (G_STRLOC ": no keysym found for %s (%s)",
                                   key, name);

                      g_free (name);

                    }
                  else
                    {
                      g_warning (G_STRLOC ": invalid key %s", key);
                    }
                }

              ntf_notification_add_button (ntf, button, key, keysym);
              mx_stylable_set_style_class (MX_STYLABLE (button),
                                           "Primary");
            }
        }
    }

  ntf_notification_set_urgent (ntf, details->is_urgent);

  ntf_notification_set_timeout (ntf, details->timeout_ms);
}