New system tray for Ubuntu ( ApplicationIndicators)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Atlante
User
User
Posts: 22
Joined: Mon Jun 27, 2011 1:39 pm
Location: FRANCE

New system tray for Ubuntu ( ApplicationIndicators)

Post by Atlante »

System tray doesn't work on Ubuntu (removed), now it's ApplicationIndicators.
Is it possible to have an update?
See the below code in C.

Code: Select all

   1 #include <gtk/gtk.h>
   2 #include <libappindicator/app-indicator.h>
   3 
   4 static void activate_action (GtkAction *action);
   5 
   6 static GtkActionEntry entries[] = {
   7   { "FileMenu", NULL, "_File" },
   8   { "New",      "document-new", "_New", "<control>N",
   9     "Create a new file", G_CALLBACK (activate_action) },
  10   { "Open",     "document-open", "_Open", "<control>O",
  11     "Open a file", G_CALLBACK (activate_action) },
  12   { "Save",     "document-save", "_Save", "<control>S",
  13     "Save file", G_CALLBACK (activate_action) },
  14   { "Quit",     "application-exit", "_Quit", "<control>Q",
  15     "Exit the application", G_CALLBACK (gtk_main_quit) },
  16 };
  17 static guint n_entries = G_N_ELEMENTS (entries);
  18 
  19 static const gchar *ui_info =
  20 "<ui>"
  21 "  <menubar name='MenuBar'>"
  22 "    <menu action='FileMenu'>"
  23 "      <menuitem action='New'/>"
  24 "      <menuitem action='Open'/>"
  25 "      <menuitem action='Save'/>"
  26 "      <separator/>"
  27 "      <menuitem action='Quit'/>"
  28 "    </menu>"
  29 "  </menubar>"
  30 "  <popup name='IndicatorPopup'>"
  31 "    <menuitem action='New' />"
  32 "    <menuitem action='Open' />"
  33 "    <menuitem action='Save' />"
  34 "    <menuitem action='Quit' />"
  35 "  </popup>"
  36 "</ui>";
  37 
  38 static void
  39 activate_action (GtkAction *action)
  40 {
  41         const gchar *name = gtk_action_get_name (action);
  42         GtkWidget *dialog;
  43 
  44         dialog = gtk_message_dialog_new (NULL,
  45                                          GTK_DIALOG_DESTROY_WITH_PARENT,
  46                                          GTK_MESSAGE_INFO,
  47                                          GTK_BUTTONS_CLOSE,
  48                                          "You activated action: \"%s\"",
  49                                          name);
  50 
  51         g_signal_connect (dialog, "response",
  52                           G_CALLBACK (gtk_widget_destroy), NULL);
  53 
  54         gtk_widget_show (dialog);
  55 }
  56 
  57 int main (int argc, char **argv)
  58 {
  59   GtkWidget *window;
  60   GtkWidget *menubar;
  61   GtkWidget *table;
  62   GtkWidget *sw;
  63   GtkWidget *contents;
  64   GtkWidget *statusbar;
  65   GtkWidget *indicator_menu;
  66   GtkActionGroup *action_group;
  67   GtkUIManager *uim;
  68   AppIndicator *indicator;
  69   GError *error = NULL;
  70 
  71   gtk_init (&argc, &argv);
  72 
  73   /* main window */
  74   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  75   gtk_window_set_title (GTK_WINDOW (window), "Indicator Demo");
  76   gtk_window_set_icon_name (GTK_WINDOW (window), "indicator-messages-new");
  77   g_signal_connect (G_OBJECT (window),
  78                     "destroy",
  79                     G_CALLBACK (gtk_main_quit),
  80                     NULL);
  81 
  82   table = gtk_table_new (1, 5, FALSE);
  83   gtk_container_add (GTK_CONTAINER (window), table);
  84 
  85   /* Menus */
  86   action_group = gtk_action_group_new ("AppActions");
  87   gtk_action_group_add_actions (action_group,
  88                                 entries, n_entries,
  89                                 window);
  90 
  91   uim = gtk_ui_manager_new ();
  92   g_object_set_data_full (G_OBJECT (window),
  93                           "ui-manager", uim,
  94                           g_object_unref);
  95   gtk_ui_manager_insert_action_group (uim, action_group, 0);
  96   gtk_window_add_accel_group (GTK_WINDOW (window),
  97                               gtk_ui_manager_get_accel_group (uim));
  98 
  99   if (!gtk_ui_manager_add_ui_from_string (uim, ui_info, -1, &error))
 100     {
 101       g_message ("Failed to build menus: %s\n", error->message);
 102       g_error_free (error);
 103       error = NULL;
 104     }
 105 
 106   menubar = gtk_ui_manager_get_widget (uim, "/ui/MenuBar");
 107   gtk_widget_show (menubar);
 108   gtk_table_attach (GTK_TABLE (table),
 109                     menubar,
 110                     0, 1,                    0, 1,
 111                     GTK_EXPAND | GTK_FILL,   0,
 112                     0,                       0);
 113 
 114   /* Document */
 115   sw = gtk_scrolled_window_new (NULL, NULL);
 116 
 117   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
 118                                   GTK_POLICY_AUTOMATIC,
 119                                   GTK_POLICY_AUTOMATIC);
 120 
 121   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
 122                                        GTK_SHADOW_IN);
 123 
 124   gtk_table_attach (GTK_TABLE (table),
 125                     sw,
 126                     /* X direction */       /* Y direction */
 127                     0, 1,                   3, 4,
 128                     GTK_EXPAND | GTK_FILL,  GTK_EXPAND | GTK_FILL,
 129                     0,                      0);
 130 
 131   gtk_window_set_default_size (GTK_WINDOW (window),
 132                                200, 200);
 133 
 134   contents = gtk_text_view_new ();
 135   gtk_widget_grab_focus (contents);
 136 
 137   gtk_container_add (GTK_CONTAINER (sw),
 138                      contents);
 139 
 140 
 141   /* Create statusbar */
 142   statusbar = gtk_statusbar_new ();
 143   gtk_table_attach (GTK_TABLE (table),
 144                     statusbar,
 145                     /* X direction */       /* Y direction */
 146                     0, 1,                   4, 5,
 147                     GTK_EXPAND | GTK_FILL,  0,
 148                     0,                      0);
 149 
 150   /* Show the window */
 151   gtk_widget_show_all (window);
 152 
 153   /* Indicator */
 154   indicator = app_indicator_new ("example-simple-client",
 155                                  "indicator-messages",
 156                                  APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
 157 
 158   indicator_menu = gtk_ui_manager_get_widget (uim, "/ui/IndicatorPopup");
 159 
 160   app_indicator_set_status (indicator, APP_INDICATOR_STATUS_ACTIVE);
 161   app_indicator_set_attention_icon (indicator, "indicator-messages-new");
 162 
 163   app_indicator_set_menu (indicator, GTK_MENU (indicator_menu));
 164 
 165   gtk_main ();
 166 
 167   return 0;
 168 }
Devops Engineer
PB French Moderator
http://www.purebasic.fr/french/