static GMenu *open_btn_build_menu() { GMenu *menu; GMenuItem *open_menu_item; GMenuItem *open_loc_menu_item; menu = g_menu_new(); open_menu_item = g_menu_item_new(_("_Open"), "app.open"); open_loc_menu_item = g_menu_item_new(_("Open _Location"), "app.openloc"); g_menu_append_item(menu, open_menu_item); g_menu_append_item(menu, open_loc_menu_item); return menu; }
static void menu_append_hidden (GMenu *menu, const char *label, const char *detailed_action) { GMenuItem *item; item = g_menu_item_new (label, detailed_action); g_menu_item_set_attribute_value (item, "hidden-when", g_variant_new_string ("action-disabled")); g_menu_append_item (menu, item); g_object_unref (item); }
static gboolean mouse_press_handler( GtkWidget *widget, GdkEvent *event, gpointer data ) { GdkEventButton *btn_event = (GdkEventButton *)event; gboolean handled; handled = ( btn_event->type == GDK_BUTTON_PRESS && btn_event->button == 3 ); if(handled) { GMenu *menu; GMenuItem *add_menu_item; GMenuItem *loop_menu_item; GtkWidget *ctx_menu; menu = g_menu_new(); add_menu_item = g_menu_item_new(_("_Add…"), "app.open(true)"); loop_menu_item = g_menu_item_new(_("Loop"), "app.loop"); g_menu_append_item(menu, add_menu_item); g_menu_append_item(menu, loop_menu_item); g_menu_freeze(menu); ctx_menu = gtk_menu_new_from_model(G_MENU_MODEL(menu)); gtk_menu_attach_to_widget(GTK_MENU(ctx_menu), widget, NULL); gtk_widget_show_all(ctx_menu); gtk_menu_popup( GTK_MENU(ctx_menu), NULL, NULL, NULL, NULL, btn_event->button, btn_event->time ); } return handled; }
static GMenu *build_app_menu() { GMenu *menu; GMenu *top_section; GMenu *bottom_section; GMenuItem *pref_menu_item; GMenuItem *about_menu_item; GMenuItem *quit_menu_item; menu = g_menu_new(); top_section = g_menu_new(); bottom_section = g_menu_new(); pref_menu_item = g_menu_item_new(_("_Preferences"), "app.pref"); about_menu_item = g_menu_item_new(_("_About"), "app.about"); quit_menu_item = g_menu_item_new(_("_Quit"), "app.quit"); g_menu_append_section(menu, NULL, G_MENU_MODEL(top_section)); g_menu_append_section(menu, NULL, G_MENU_MODEL(bottom_section)); g_menu_append_item(top_section, pref_menu_item); g_menu_append_item(bottom_section, about_menu_item); g_menu_append_item(bottom_section, quit_menu_item); return menu; }
int main (int argc, char **argv) { IndicatorTestService indicator = { 0 }; GMenuItem *item; GMenu *submenu; GActionEntry entries[] = { { "_header", NULL, NULL, "{'label': <'Test'>," " 'icon': <'indicator-test'>," " 'accessible-desc': <'Test indicator'> }", NULL }, { "show", activate_show, NULL, NULL, NULL } }; GMainLoop *loop; indicator.actions = g_simple_action_group_new (); g_simple_action_group_add_entries (indicator.actions, entries, G_N_ELEMENTS (entries), NULL); submenu = g_menu_new (); g_menu_append (submenu, "Show", "indicator.show"); item = g_menu_item_new (NULL, "indicator._header"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.root"); g_menu_item_set_submenu (item, G_MENU_MODEL (submenu)); indicator.menu = g_menu_new (); g_menu_append_item (indicator.menu, item); g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.test", G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired, NULL, name_lost, &indicator, NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (submenu); g_object_unref (item); g_object_unref (indicator.actions); g_object_unref (indicator.menu); g_object_unref (loop); return 0; }
static void populate_mime_handlers (GMenu *menu, GbProjectFile *project_file) { g_autofree gchar *content_type = NULL; GList *list; GList *iter; GFile *file; g_assert (G_IS_MENU (menu)); g_assert (GB_IS_PROJECT_FILE (project_file)); g_menu_remove_all (menu); file = gb_project_file_get_file (project_file); if (file == NULL) return; content_type = get_content_type (file); if (content_type == NULL) return; list = g_app_info_get_all_for_type (content_type); for (iter = list; iter; iter = iter->next) { g_autoptr(GMenuItem) menu_item = NULL; g_autofree gchar *detailed_action = NULL; GAppInfo *app_info = iter->data; const gchar *display_name; const gchar *app_id; display_name = g_app_info_get_display_name (app_info); app_id = g_app_info_get_id (app_info); detailed_action = g_strdup_printf ("project-tree.open-with('%s')", app_id); menu_item = g_menu_item_new (display_name, detailed_action); g_menu_append_item (menu, menu_item); } g_list_free_full (list, g_object_unref); }
void gw_menumodel_set_links (GMenuModel *menumodel, const gchar *LABEL, const gchar *NEW_LABEL, const gchar *LINK_TYPE, GMenuModel *link) { //Sanity checks g_return_if_fail (menumodel != NULL); g_return_if_fail (LABEL != NULL); g_return_if_fail (LINK_TYPE != NULL); //Declarations gint total_items; gint index; gchar *label; gboolean valid; GMenuItem *menuitem; GMenuModel *sublink; //Initializations total_items = g_menu_model_get_n_items (menumodel); for (index = 0; index < total_items; index++) { valid = g_menu_model_get_item_attribute (menumodel, index, G_MENU_ATTRIBUTE_LABEL, "s", &label, NULL); if (valid == TRUE && label != NULL) { if (label != NULL && strcmp (label, LABEL) == 0) { menuitem = g_menu_item_new (NEW_LABEL, NULL); g_menu_item_set_link (menuitem, LINK_TYPE, link); g_menu_remove (G_MENU (menumodel), index); g_menu_insert_item (G_MENU (menumodel), index, menuitem); g_object_unref (menuitem); menuitem = NULL; } g_free (label); label = NULL; } //Recursive work sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SUBMENU); if (sublink != NULL) gw_menumodel_set_links (sublink, LABEL, NEW_LABEL, LINK_TYPE, link); sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SECTION); if (sublink != NULL) gw_menumodel_set_links (sublink, LABEL, NEW_LABEL, LINK_TYPE, link); } }
static void photos_base_model_refresh (PhotosBaseModel *self) { PhotosBaseModelPrivate *priv = self->priv; GHashTable *objects; GHashTableIter hash_iter; GMenu *section; GObject *object; const gchar *action_id; const gchar *id; const gchar *title; g_menu_remove_all (priv->model); title = photos_base_manager_get_title (priv->mngr); action_id = photos_base_manager_get_action_id (priv->mngr); section = g_menu_new (); g_menu_append_section (priv->model, title, G_MENU_MODEL (section)); objects = photos_base_manager_get_objects (priv->mngr); g_hash_table_iter_init (&hash_iter, objects); while (g_hash_table_iter_next (&hash_iter, (gpointer *) &id, (gpointer *) &object)) { GMenuItem *menu_item; GVariant *target_value; gchar *name; g_object_get (object, "name", &name, NULL); menu_item = g_menu_item_new (name, NULL); target_value = g_variant_new ("s", id); g_menu_item_set_action_and_target_value (menu_item, action_id, target_value); g_menu_append_item (section, menu_item); g_free (name); } g_object_unref (section); }
static void impl_activate (PeasActivatable *plugin) { GtkWindow *window; TotemSkiptoPlugin *pi = TOTEM_SKIPTO_PLUGIN (plugin); TotemSkiptoPluginPrivate *priv = pi->priv; GMenu *menu; GMenuItem *item; priv->totem = g_object_get_data (G_OBJECT (plugin), "object"); priv->handler_id_stream_length = g_signal_connect (G_OBJECT (priv->totem), "notify::stream-length", G_CALLBACK (property_notify_cb), pi); priv->handler_id_seekable = g_signal_connect (G_OBJECT (priv->totem), "notify::seekable", G_CALLBACK (property_notify_cb), pi); /* Key press handler */ window = totem_object_get_main_window (priv->totem); priv->handler_id_key_press = g_signal_connect (G_OBJECT(window), "key-press-event", G_CALLBACK (on_window_key_press_event), pi); g_object_unref (window); /* Install the menu */ priv->action = g_simple_action_new ("skip-to", NULL); g_signal_connect (G_OBJECT (priv->action), "activate", G_CALLBACK (skip_to_action_callback), plugin); g_action_map_add_action (G_ACTION_MAP (priv->totem), G_ACTION (priv->action)); menu = totem_object_get_menu_section (priv->totem, "skipto-placeholder"); item = g_menu_item_new (_("_Skip To…"), "app.skip-to"); g_menu_item_set_attribute (item, "accel", "s", "<Ctrl>K"); g_menu_append_item (G_MENU (menu), item); totem_skipto_update_from_state (priv->totem, pi); }
static void ephy_notebook_rebuild_tab_menu (EphyNotebook *notebook) { GMenuItem *item; const char *text; char *ellipsized_text; int num_pages; GtkWidget *window; GActionGroup *group; GAction *action; gint current_page; g_menu_remove_all (notebook->tab_menu); num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); /* TODO: Add favicon as well. Will have to ditch GMenu. :( */ for (int i = 0; i < num_pages; i++) { text = get_nth_tab_label_text (GTK_NOTEBOOK (notebook), i); ellipsized_text = ellipsize_tab_label (text); item = g_menu_item_new (ellipsized_text, NULL); g_menu_item_set_action_and_target (item, "win.show-tab", "u", (guint)i, NULL); g_menu_append_item (notebook->tab_menu, item); g_free (ellipsized_text); g_object_unref (item); } current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); if (current_page < 0) return; window = gtk_widget_get_toplevel (GTK_WIDGET (notebook)); group = gtk_widget_get_action_group (window, "win"); /* Is window being destroyed? */ if (group == NULL) return; action = g_action_map_lookup_action (G_ACTION_MAP (group), "show-tab"); g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_uint32 ((guint32)current_page)); }
/** * rb_source_search_add_to_menu: * @menu: #GMenu instance to populate * @action_namespace: muxer namespace for the action ("app" or "win") * @action: search action to attach the menu item to * @name: name of the search instance to add * * Adds a registered search instance to a search menu. */ void rb_source_search_add_to_menu (GMenu *menu, const char *action_namespace, GAction *action, const char *name) { GMenuItem *item; RBSourceSearch *search; char *action_name; search = rb_source_search_get_by_name (name); g_assert (search != NULL); if (action_namespace != NULL) { action_name = g_strdup_printf ("%s.%s", action_namespace, g_action_get_name (action)); } else { action_name = g_strdup (g_action_get_name (action)); } item = g_menu_item_new (rb_source_search_get_description (search), NULL); g_menu_item_set_action_and_target (item, action_name, "s", name); g_menu_append_item (menu, item); g_free (action_name); }
static void eog_zoom_entry_populate_free_zoom_section (EogZoomEntry *zoom_entry) { guint i; for (i = 0; i < G_N_ELEMENTS (zoom_levels); i++) { GMenuItem *item; gchar *name; if (zoom_levels[i] > EOG_SCROLL_VIEW_MAX_ZOOM_FACTOR) break; name = eog_zoom_entry_format_zoom_value (zoom_levels[i]); item = g_menu_item_new (name, NULL); g_menu_item_set_action_and_target (item, "win.zoom-set", "d", zoom_levels[i]); g_menu_append_item (G_MENU (zoom_entry->priv->zoom_free_section), item); g_object_unref (item); g_free (name); } }
static void photos_base_model_refresh (PhotosBaseModel *self) { g_autoptr (GMenu) section = NULL; const gchar *action_id; const gchar *title; guint i; guint n_items; g_menu_remove_all (self->model); title = photos_base_manager_get_title (self->mngr); action_id = photos_base_manager_get_action_id (self->mngr); section = g_menu_new (); g_menu_append_section (self->model, title, G_MENU_MODEL (section)); n_items = g_list_model_get_n_items (G_LIST_MODEL (self->mngr)); for (i = 0; i < n_items; i++) { g_autoptr (GMenuItem) menu_item = NULL; g_autoptr (GObject) object = NULL; const gchar *id; g_autofree gchar *name = NULL; object = g_list_model_get_object (G_LIST_MODEL (self->mngr), i); if (!photos_filterable_is_search_criterion (PHOTOS_FILTERABLE (object))) continue; id = photos_filterable_get_id (PHOTOS_FILTERABLE (object)); g_object_get (object, "name", &name, NULL); menu_item = g_menu_item_new (name, NULL); g_menu_item_set_action_and_target (menu_item, action_id, "s", id); g_menu_append_item (section, menu_item); } }
int main (int argc, char **argv) { GtkWidget *window; GtkWidget *button; GtkWidget *grid; GtkWidget *entry; GtkWidget *menu_widget; GtkAccelGroup *accel_group; guint i; GMenu *menu; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_resize (GTK_WINDOW (window), 400, 300); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); accel_group = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); /* Button next to entry */ entry = gtk_entry_new (); gtk_grid_attach (GTK_GRID (grid), entry, 0, 0, 1, 1); button = gtk_menu_button_new (); gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1); /* Button with GtkMenu */ menu_widget = gtk_menu_new (); for (i = 5; i > 0; i--) { GtkWidget *item; if (i == 3) { item = gtk_menu_item_new_with_mnemonic ("_Copy"); } else { char *label; label = g_strdup_printf ("Item _%d", i); item = gtk_menu_item_new_with_mnemonic (label); g_free (label); } gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item), TRUE); gtk_menu_attach (GTK_MENU (menu_widget), item, 0, 1, i - 1, i); } gtk_widget_show_all (menu_widget); button = gtk_menu_button_new (); gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget); gtk_grid_attach (GTK_GRID (grid), button, 1, 1, 1, 1); gtk_widget_show (create_prop_editor (G_OBJECT (button), 0)); /* Button with GMenuModel */ menu = g_menu_new (); for (i = 5; i > 0; i--) { char *label; GMenuItem *item; label = g_strdup_printf ("Item _%d", i); item = g_menu_item_new (label, NULL); if (i == 3) g_menu_item_set_attribute (item, "icon", "s", "preferences-desktop-locale-symbolic"); g_menu_insert_item (menu, i - 1, item); g_object_unref (item); g_free (label); } button = gtk_menu_button_new (); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu)); gtk_grid_attach (GTK_GRID (grid), button, 1, 2, 1, 1); gtk_widget_show_all (window); gtk_main (); return 0; }
static void gdaui_dsn_editor_init (GdauiDsnEditor *config, G_GNUC_UNUSED GdauiDsnEditorClass *klass) { GtkWidget *grid; GtkWidget *label; GtkWidget *exp; gchar *str; g_return_if_fail (GDAUI_IS_DSN_EDITOR (config)); gtk_orientable_set_orientation (GTK_ORIENTABLE (config), GTK_ORIENTATION_VERTICAL); /* allocate private structure */ config->priv = g_new0 (GdauiDsnEditorPrivate, 1); config->priv->dsn_info = g_new0 (GdaDsnInfo, 1); config->priv->no_change_signal = TRUE; /* data source's name and icon */ GtkWidget *hbox_header; hbox_header = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX (config), hbox_header, FALSE, FALSE, 6); config->priv->icon = gtk_image_new (); gtk_widget_set_size_request (config->priv->icon, -1, SUPPORT_ICON_SIZE); gtk_box_pack_start (GTK_BOX (hbox_header), config->priv->icon, FALSE, FALSE, 0); config->priv->wname = gtk_label_new (""); gtk_box_pack_start (GTK_BOX (hbox_header), config->priv->wname, FALSE, FALSE, 10); GtkWidget *menu_button; menu_button = gtk_menu_button_new (); gtk_box_pack_end (GTK_BOX (hbox_header), menu_button, FALSE, FALSE, 0); GtkWidget *menu_icon; menu_icon = gtk_image_new_from_icon_name ("open-menu-symbolic", GTK_ICON_SIZE_MENU); gtk_button_set_image (GTK_BUTTON (menu_button), menu_icon); GMenu *smenu; smenu = g_menu_new (); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_button), G_MENU_MODEL (smenu)); GMenuItem *mitem; mitem = g_menu_item_new ("Test data source", "win.DSNTest"); g_menu_insert_item (smenu, -1, mitem); mitem = g_menu_item_new ("Reset data source's changes", "win.DSNReset"); g_menu_insert_item (smenu, -1, mitem); mitem = g_menu_item_new ("Duplicate data source", "win.DSNCopy"); g_menu_insert_item (smenu, -1, mitem); GtkWindow *win; win = gtk_application_get_active_window (GTK_APPLICATION (g_application_get_default ())); g_action_map_add_action_entries (G_ACTION_MAP (win), win_entries, G_N_ELEMENTS (win_entries), config); /* stack in a scrolled window */ GtkWidget *sw; sw = gtk_scrolled_window_new (NULL, NULL); gtk_widget_set_vexpand (sw, TRUE); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE); gtk_box_pack_start (GTK_BOX (config), sw, TRUE, TRUE, 6); /* Stack */ config->priv->stack = gtk_stack_new (); gtk_stack_set_transition_type (GTK_STACK (config->priv->stack), GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT); gtk_container_add (GTK_CONTAINER (sw), config->priv->stack); /* set up widgets */ grid = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_widget_show (grid); label = gtk_label_new_with_mnemonic (_("_System wide data source:")); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_hexpand (label, FALSE); g_object_set (G_OBJECT (label), "xalign", 0., NULL); gtk_widget_show (label); gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1); config->priv->is_system = gtk_check_button_new (); gtk_widget_show (config->priv->is_system); g_signal_connect (G_OBJECT (config->priv->is_system), "toggled", G_CALLBACK (field_toggled_cb), config); gtk_grid_attach (GTK_GRID (grid), config->priv->is_system, 1, 1, 1, 1); str = g_strdup_printf ("%s <span foreground='red' weight='bold'>*</span>", _("_Provider:")); label = gtk_label_new (""); gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), str); g_free (str); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_hexpand (label, FALSE); g_object_set (G_OBJECT (label), "xalign", 0., NULL); gtk_widget_show (label); gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1); config->priv->wprovider = gdaui_provider_selector_new (); gtk_widget_set_hexpand (config->priv->wprovider, TRUE); gtk_label_set_mnemonic_widget (GTK_LABEL (label), config->priv->wprovider); gtk_widget_show (config->priv->wprovider); g_signal_connect (G_OBJECT (config->priv->wprovider), "changed", G_CALLBACK (field_changed_cb), config); gtk_grid_attach (GTK_GRID (grid), config->priv->wprovider, 1, 2, 1, 1); label = gtk_label_new_with_mnemonic (_("_Description:")); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_hexpand (label, FALSE); g_object_set (G_OBJECT (label), "xalign", 0., NULL); gtk_widget_show (label); gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); config->priv->wdesc = gtk_text_view_new (); gtk_container_add (GTK_CONTAINER (sw), config->priv->wdesc); gtk_text_view_set_editable (GTK_TEXT_VIEW (config->priv->wdesc), TRUE); gtk_widget_set_vexpand (config->priv->wdesc, TRUE); gtk_label_set_mnemonic_widget (GTK_LABEL (label), config->priv->wdesc); g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (config->priv->wdesc)), "changed", G_CALLBACK (field_changed_cb), config); gtk_grid_attach (GTK_GRID (grid), sw, 1, 3, 1, 1); config->priv->warning = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (config->priv->warning), _("<span foreground='red'>The database provider used by this data source is not available,\n" "editing the data source's attributes is disabled</span>")); gtk_widget_set_halign (config->priv->warning, GTK_ALIGN_CENTER); gtk_widget_set_hexpand (config->priv->warning, TRUE); g_object_set (G_OBJECT (config->priv->warning), "xalign", 0.5, NULL); gtk_label_set_justify (GTK_LABEL (config->priv->warning), GTK_JUSTIFY_CENTER); gtk_label_set_line_wrap (GTK_LABEL (config->priv->warning), TRUE); gtk_grid_attach (GTK_GRID (grid), config->priv->warning, 0, 8, 2, 1); gtk_stack_add_named (GTK_STACK (config->priv->stack), grid, PANE_DEFINITION); /* connection's spec */ config->priv->dsn_spec = _gdaui_provider_spec_editor_new (gdaui_provider_selector_get_provider (GDAUI_PROVIDER_SELECTOR (config->priv->wprovider))); g_signal_connect (G_OBJECT (config->priv->dsn_spec), "changed", G_CALLBACK (field_changed_cb), config); gtk_widget_show (config->priv->dsn_spec); gtk_stack_add_named (GTK_STACK (config->priv->stack), config->priv->dsn_spec, PANE_PARAMS); /* connection's authentication */ config->priv->dsn_auth = _gdaui_provider_auth_editor_new (gdaui_provider_selector_get_provider (GDAUI_PROVIDER_SELECTOR (config->priv->wprovider))); g_signal_connect (G_OBJECT (config->priv->dsn_auth), "changed", G_CALLBACK (field_changed_cb), config); gtk_widget_show (config->priv->dsn_auth); gtk_stack_add_named (GTK_STACK (config->priv->stack), config->priv->dsn_auth, PANE_AUTH); config->priv->no_change_signal = FALSE; }
int main (int argc, char **argv) { IndicatorTestService indicator = { 0 }; indicator.action_delay = -1; indicator.change_interval = -1; GMenuItem *item; GMenu *submenu; GActionEntry entries[] = { { "_header", NULL, NULL, "{'title': <'Test'>," " 'label': <'Test'>," " 'visible': <true>," " 'accessible-desc': <'Test indicator'> }", NULL }, { "action.show", activate_show, NULL, NULL, NULL }, { "action.switch", activate_switch, NULL, "true", NULL }, { "action.checkbox", activate_switch, NULL, "true", NULL }, { "action.accessPoint", activate_switch, NULL, "false", NULL }, { "action.slider", NULL, NULL, "0.5", change_slider } }; GMainLoop *loop; int help = 0; if (argc > 1) { int i; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (arg[0] == '-') { switch (arg[1]) { case 't': { arg += 2; if (!arg[0] && i < argc-1) { i++; int delay = -1; if (sscanf(argv[i], "%d", &delay) == 1) { indicator.action_delay = delay; } else { printf("Invalid action delay value: %s\n", argv[i]); help = 1; } } else { printf("Invalid action delay value: %s\n", argv[i]); help = 1; } break; } case 'c': { arg += 2; if (!arg[0] && i < argc-1) { i++; int interval = -1; if (sscanf(argv[i], "%d", &interval) == 1) { indicator.change_interval = interval; } else { printf("Invalid change interval value: %s\n", argv[i]); help = 1; } } else { printf("Invalid change interval value: %s\n", argv[i]); help = 1; } break; } case 'h': help = 1; break; } } } } if (help) { printf("Usage: %s [<options>]\n" " -t DELAY Action activation delay\n" " -c CHANGE_INTERVAL Interval to change action values\n" " -h Show this help text\n" , argv[0]); return 0; } indicator.actions = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (indicator.actions), entries, G_N_ELEMENTS (entries), &indicator); submenu = g_menu_new (); g_menu_append (submenu, "Show", "indicator.action.show"); // Switch item = g_menu_item_new("Switch", "indicator.action.switch"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.switch"); g_menu_append_item(submenu, item); // Checkbox item = g_menu_item_new("Checkbox", "indicator.action.checkbox"); g_menu_append_item(submenu, item); // Slider item = g_menu_item_new("Slider", "indicator.action.slider"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.slider"); g_menu_append_item(submenu, item); // Access Point item = g_menu_item_new("Access Point", "indicator.action.accessPoint"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "unity.widgets.systemsettings.tablet.accesspoint"); g_menu_append_item(submenu, item); item = g_menu_item_new (NULL, "indicator._header"); g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.root"); g_menu_item_set_submenu (item, G_MENU_MODEL (submenu)); indicator.menu = g_menu_new (); g_menu_append_item (indicator.menu, item); g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.mock", G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired, NULL, name_lost, &indicator, NULL); loop = g_main_loop_new (NULL, FALSE); if (indicator.change_interval != -1) { g_timeout_add(indicator.change_interval, change_interval, &indicator); } g_main_loop_run (loop); g_object_unref (submenu); g_object_unref (item); g_object_unref (indicator.actions); g_object_unref (indicator.menu); g_object_unref (loop); return 1; }
GMenu *build_full_menu() { GMenu *menu; GMenu *file_menu; GMenu *edit_menu; GMenu *view_menu; GMenu *help_menu; GMenuItem *file_menu_item; GMenuItem *open_menu_item; GMenuItem *quit_menu_item; GMenuItem *open_loc_menu_item; GMenuItem *save_playlist_menu_item; GMenuItem *edit_menu_item; GMenuItem *load_sub_menu_item; GMenuItem *pref_menu_item; GMenuItem *view_menu_item; GMenuItem *playlist_menu_item; GMenuItem *fullscreen_menu_item; GMenuItem *normal_size_menu_item; GMenuItem *double_size_menu_item; GMenuItem *half_size_menu_item; GMenuItem *help_menu_item; GMenuItem *about_menu_item; menu = g_menu_new(); /* File */ file_menu = g_menu_new(); file_menu_item = g_menu_item_new_submenu (_("_File"), G_MENU_MODEL(file_menu)); open_menu_item = g_menu_item_new(_("_Open"), "app.open(false)"); quit_menu_item = g_menu_item_new(_("_Quit"), "app.quit"); open_loc_menu_item = g_menu_item_new(_("Open _Location"), "app.openloc"); save_playlist_menu_item = g_menu_item_new(_("_Save Playlist"), "app.playlist_save"); /* Edit */ edit_menu = g_menu_new(); edit_menu_item = g_menu_item_new_submenu (_("_Edit"), G_MENU_MODEL(edit_menu)); load_sub_menu_item = g_menu_item_new(_("_Load Subtitle"), "app.loadsub"); pref_menu_item = g_menu_item_new(_("_Preferences"), "app.pref"); /* View */ view_menu = g_menu_new(); view_menu_item = g_menu_item_new_submenu (_("_View"), G_MENU_MODEL(view_menu)); playlist_menu_item = g_menu_item_new(_("_Toggle Playlist"), "app.playlist_toggle"); fullscreen_menu_item = g_menu_item_new(_("_Fullscreen"), "app.fullscreen"); normal_size_menu_item = g_menu_item_new(_("_Normal Size"), "app.normalsize"); double_size_menu_item = g_menu_item_new(_("_Double Size"), "app.doublesize"); half_size_menu_item = g_menu_item_new(_("_Half Size"), "app.halfsize"); /* Help */ help_menu = g_menu_new(); help_menu_item = g_menu_item_new_submenu (_("_Help"), G_MENU_MODEL(help_menu)); about_menu_item = g_menu_item_new(_("_About"), "app.about"); g_menu_append_item(menu, file_menu_item); g_menu_append_item(file_menu, open_menu_item); g_menu_append_item(file_menu, open_loc_menu_item); g_menu_append_item(file_menu, save_playlist_menu_item); g_menu_append_item(file_menu, quit_menu_item); g_menu_append_item(menu, edit_menu_item); g_menu_append_item(edit_menu, load_sub_menu_item); g_menu_append_item(edit_menu, pref_menu_item); g_menu_append_item(menu, view_menu_item); g_menu_append_item(view_menu, playlist_menu_item); g_menu_append_item(view_menu, fullscreen_menu_item); g_menu_append_item(view_menu, normal_size_menu_item); g_menu_append_item(view_menu, double_size_menu_item); g_menu_append_item(view_menu, half_size_menu_item); g_menu_append_item(menu, help_menu_item); g_menu_append_item(help_menu, about_menu_item); return menu; }
static void fill_open_with_menu (GtkTreeView *view, GtkBuilder *builder, GtkTreePath *path) { GtkTreeModel *model = gtk_tree_view_get_model (view); if (!model) { return; } GtkTreeIter iter; if (!gtk_tree_model_get_iter(model, &iter, path)) { return; } DatabaseSearchEntry *entry = (DatabaseSearchEntry *)iter.user_data; if (!entry) { return; } BTreeNode * node = db_search_entry_get_node (entry); GList *app_list = NULL; char *content_type = NULL; if (node->is_dir) { content_type = g_content_type_from_mime_type ("inode/directory"); } else { content_type = g_content_type_guess (node->name, NULL, 0, NULL); } if (!content_type) { goto clean_up; } app_list = g_app_info_get_all_for_type (content_type); if (!app_list) { goto clean_up; } GMenu *menu_mime = G_MENU (gtk_builder_get_object (builder, "fsearch_listview_menu_open_with_mime_section")); for (GList *list_iter = app_list; list_iter; list_iter = list_iter->next) { GAppInfo *app_info = list_iter->data; const char *display_name = g_app_info_get_display_name (app_info); const char *app_id = g_app_info_get_id (app_info); char detailed_action[1024] = ""; snprintf (detailed_action, sizeof (detailed_action), "win.open_with('%s')", app_id); GMenuItem *menu_item = g_menu_item_new (display_name, detailed_action); g_menu_item_set_icon (menu_item, g_app_info_get_icon (app_info)); g_menu_append_item (menu_mime, menu_item); g_object_unref (menu_item); } clean_up: if (content_type) { g_free (content_type); content_type = NULL; } if (app_list) { g_list_free_full (app_list, g_object_unref); app_list = NULL; } }
static void rotation_plugin_real_activate (PeasActivatable* base) { RotationPlugin * self; TotemObject* t = NULL; GObject* _tmp0_ = NULL; GObject* _tmp1_ = NULL; gchar* mrl = NULL; TotemObject* _tmp2_ = NULL; gchar* _tmp3_ = NULL; GMenu* menu = NULL; TotemObject* _tmp4_ = NULL; GMenu* _tmp5_ = NULL; GMenu* _tmp6_ = NULL; TotemObject* _tmp7_ = NULL; GtkWidget* _tmp8_ = NULL; BaconVideoWidget* _tmp9_ = NULL; GSimpleAction* _tmp10_ = NULL; GSimpleAction* _tmp11_ = NULL; TotemObject* _tmp12_ = NULL; GSimpleAction* _tmp13_ = NULL; TotemObject* _tmp14_ = NULL; GSimpleAction* _tmp15_ = NULL; GSimpleAction* _tmp16_ = NULL; TotemObject* _tmp17_ = NULL; GSimpleAction* _tmp18_ = NULL; TotemObject* _tmp19_ = NULL; GMenuItem* item = NULL; const gchar* _tmp20_ = NULL; GMenuItem* _tmp21_ = NULL; GMenuItem* _tmp22_ = NULL; GMenu* _tmp23_ = NULL; GMenuItem* _tmp24_ = NULL; const gchar* _tmp25_ = NULL; GMenuItem* _tmp26_ = NULL; GMenuItem* _tmp27_ = NULL; GMenu* _tmp28_ = NULL; GMenuItem* _tmp29_ = NULL; const gchar* _tmp30_ = NULL; const gchar* _tmp33_ = NULL; TotemObject* _tmp35_ = NULL; TotemObject* _tmp36_ = NULL; self = (RotationPlugin*) base; g_object_get ((PeasActivatable*) self, "object", &_tmp0_, NULL); _tmp1_ = _tmp0_; t = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, totem_object_get_type (), TotemObject); _tmp2_ = t; _tmp3_ = totem_object_get_current_mrl (_tmp2_); mrl = _tmp3_; _tmp4_ = t; _tmp5_ = totem_object_get_menu_section (_tmp4_, "rotation-placeholder"); _tmp6_ = _g_object_ref0 (_tmp5_); menu = _tmp6_; _tmp7_ = t; _tmp8_ = totem_object_get_video_widget (_tmp7_); _tmp9_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp8_, BACON_TYPE_VIDEO_WIDGET) ? ((BaconVideoWidget*) _tmp8_) : NULL; if (_tmp9_ == NULL) { _g_object_unref0 (_tmp8_); } _g_object_unref0 (self->priv->bvw); self->priv->bvw = _tmp9_; _tmp10_ = g_simple_action_new ("rotate-left", NULL); _g_object_unref0 (self->priv->rotate_left_action); self->priv->rotate_left_action = _tmp10_; _tmp11_ = self->priv->rotate_left_action; g_signal_connect_object (_tmp11_, "activate", (GCallback) _rotation_plugin_cb_rotate_left_g_simple_action_activate, self, 0); _tmp12_ = t; _tmp13_ = self->priv->rotate_left_action; g_action_map_add_action ((GActionMap*) _tmp12_, (GAction*) _tmp13_); _tmp14_ = t; gtk_application_add_accelerator ((GtkApplication*) _tmp14_, "<Primary><Shift>R", "app.rotate-left", NULL); _tmp15_ = g_simple_action_new ("rotate-right", NULL); _g_object_unref0 (self->priv->rotate_right_action); self->priv->rotate_right_action = _tmp15_; _tmp16_ = self->priv->rotate_right_action; g_signal_connect_object (_tmp16_, "activate", (GCallback) _rotation_plugin_cb_rotate_right_g_simple_action_activate, self, 0); _tmp17_ = t; _tmp18_ = self->priv->rotate_right_action; g_action_map_add_action ((GActionMap*) _tmp17_, (GAction*) _tmp18_); _tmp19_ = t; gtk_application_add_accelerator ((GtkApplication*) _tmp19_, "<Primary>R", "app.rotate-right", NULL); _tmp20_ = _ ("_Rotate ↷"); _tmp21_ = g_menu_item_new (_tmp20_, "app.rotate-right"); item = _tmp21_; _tmp22_ = item; g_menu_item_set_attribute (_tmp22_, "accel", "s", "<Primary>R", NULL); _tmp23_ = menu; _tmp24_ = item; g_menu_append_item (_tmp23_, _tmp24_); _tmp25_ = _ ("Rotate ↶"); _tmp26_ = g_menu_item_new (_tmp25_, "app.rotate-left"); _g_object_unref0 (item); item = _tmp26_; _tmp27_ = item; g_menu_item_set_attribute (_tmp27_, "accel", "s", "<Primary><Shift>R", NULL); _tmp28_ = menu; _tmp29_ = item; g_menu_append_item (_tmp28_, _tmp29_); _tmp30_ = mrl; if (_tmp30_ == NULL) { GSimpleAction* _tmp31_ = NULL; GSimpleAction* _tmp32_ = NULL; _tmp31_ = self->priv->rotate_right_action; g_simple_action_set_enabled (_tmp31_, FALSE); _tmp32_ = self->priv->rotate_left_action; g_simple_action_set_enabled (_tmp32_, FALSE); } _tmp33_ = mrl; if (_tmp33_ != NULL) { const gchar* _tmp34_ = NULL; _tmp34_ = mrl; rotation_plugin_try_restore_state (self, _tmp34_, ____lambda6__gasync_ready_callback, g_object_ref (self)); } _tmp35_ = t; g_signal_connect_object (_tmp35_, "file-closed", (GCallback) _rotation_plugin_cb_file_closed_totem_object_file_closed, self, 0); _tmp36_ = t; g_signal_connect_object (_tmp36_, "file-opened", (GCallback) _rotation_plugin_cb_file_opened_totem_object_file_opened, self, 0); _g_object_unref0 (item); _g_object_unref0 (menu); _g_free0 (mrl); _g_object_unref0 (t); }
static void impl_constructed (GObject *object) { RBGenericPlayerSource *source; RBGenericPlayerSourcePrivate *priv; RhythmDBEntryType *entry_type; char **playlist_formats; char **output_formats; char *mount_name; RBShell *shell; GFile *root; GFileInfo *info; GError *error = NULL; char *label; char *fullname; char *name; RB_CHAIN_GOBJECT_METHOD (rb_generic_player_source_parent_class, constructed, object); source = RB_GENERIC_PLAYER_SOURCE (object); priv = GET_PRIVATE (source); rb_device_source_set_display_details (RB_DEVICE_SOURCE (source)); g_object_get (source, "shell", &shell, "entry-type", &entry_type, "name", &name, NULL); g_object_get (shell, "db", &priv->db, NULL); priv->import_errors = rb_import_errors_source_new (shell, priv->error_type, entry_type, priv->ignore_type); priv->new_playlist_action_name = g_strdup_printf ("generic-player-%p-playlist-new", source); fullname = g_strdup_printf ("app.%s", priv->new_playlist_action_name); label = g_strdup_printf (_("New Playlist on %s"), name); rb_application_add_plugin_menu_item (RB_APPLICATION (g_application_get_default ()), "display-page-add-playlist", priv->new_playlist_action_name, g_menu_item_new (label, fullname)); g_free (fullname); g_free (label); g_free (name); root = g_mount_get_root (priv->mount); mount_name = g_mount_get_name (priv->mount); info = g_file_query_filesystem_info (root, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, &error); if (error != NULL) { rb_debug ("error querying filesystem info for %s: %s", mount_name, error->message); g_error_free (error); priv->read_only = FALSE; } else { priv->read_only = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY); g_object_unref (info); } g_free (mount_name); g_object_unref (root); g_object_get (priv->device_info, "playlist-formats", &playlist_formats, NULL); if ((priv->read_only == FALSE) && playlist_formats != NULL && g_strv_length (playlist_formats) > 0) { RBDisplayPageModel *model; GMenu *playlist_menu; GMenuModel *playlists; priv->new_playlist_action = g_simple_action_new (priv->new_playlist_action_name, NULL); g_signal_connect (priv->new_playlist_action, "activate", G_CALLBACK (new_playlist_action_cb), source); g_action_map_add_action (G_ACTION_MAP (g_application_get_default ()), G_ACTION (priv->new_playlist_action)); g_object_get (shell, "display-page-model", &model, NULL); playlists = rb_display_page_menu_new (model, RB_DISPLAY_PAGE (source), RB_TYPE_GENERIC_PLAYER_PLAYLIST_SOURCE, "app.playlist-add-to"); g_object_unref (model); playlist_menu = g_menu_new (); g_menu_append (playlist_menu, _("Add to New Playlist"), priv->new_playlist_action_name); g_menu_append_section (playlist_menu, NULL, playlists); g_object_set (source, "playlist-menu", playlist_menu, NULL); } g_strfreev (playlist_formats); g_object_unref (entry_type); g_object_get (priv->device_info, "output-formats", &output_formats, NULL); if (output_formats != NULL) { GstEncodingTarget *target; int i; target = gst_encoding_target_new ("generic-player", "device", "", NULL); for (i = 0; output_formats[i] != NULL; i++) { const char *media_type = rb_gst_mime_type_to_media_type (output_formats[i]); if (media_type != NULL) { GstEncodingProfile *profile; profile = rb_gst_get_encoding_profile (media_type); if (profile != NULL) { gst_encoding_target_add_profile (target, profile); } } } g_object_set (source, "encoding-target", target, NULL); } g_strfreev (output_formats); g_object_unref (shell); }
static GMenu *menu_btn_build_menu() { GMenu *menu; GMenu *playlist_submenu; GMenu *sub_submenu; GMenu *view_submenu; GMenuItem *playlist_section; GMenuItem *sub_section; GMenuItem *view_section; GMenuItem *load_sub_menu_item; GMenuItem *playlist_toggle_menu_item; GMenuItem *playlist_save_menu_item; GMenuItem *fullscreen_menu_item; GMenuItem *normal_size_menu_item; GMenuItem *double_size_menu_item; GMenuItem *half_size_menu_item; menu = g_menu_new(); playlist_submenu = g_menu_new(); sub_submenu = g_menu_new(); view_submenu = g_menu_new(); playlist_section = g_menu_item_new_section(NULL, G_MENU_MODEL(playlist_submenu)); sub_section = g_menu_item_new_section(NULL, G_MENU_MODEL(sub_submenu)); view_section = g_menu_item_new_section(NULL, G_MENU_MODEL(view_submenu)); playlist_toggle_menu_item = g_menu_item_new(_("_Toggle Playlist"), "app.playlist_toggle"); playlist_save_menu_item = g_menu_item_new(_("_Save Playlist"), "app.playlist_save"); load_sub_menu_item = g_menu_item_new(_("_Load Subtitle"), "app.loadsub"); fullscreen_menu_item = g_menu_item_new(_("_Fullscreen"), "app.fullscreen"); normal_size_menu_item = g_menu_item_new(_("_Normal Size"), "app.normalsize"); double_size_menu_item = g_menu_item_new(_("_Double Size"), "app.doublesize"); half_size_menu_item = g_menu_item_new(_("_Half Size"), "app.halfsize"); g_menu_append_item(playlist_submenu, playlist_toggle_menu_item); g_menu_append_item(playlist_submenu, playlist_save_menu_item); g_menu_append_item(sub_submenu, load_sub_menu_item); g_menu_append_item(view_submenu, fullscreen_menu_item); g_menu_append_item(view_submenu, normal_size_menu_item); g_menu_append_item(view_submenu, double_size_menu_item); g_menu_append_item(view_submenu, half_size_menu_item); g_menu_append_item(menu, playlist_section); g_menu_append_item(menu, sub_section); g_menu_append_item(menu, view_section); return menu; }
static void impl_activate (PeasActivatable *plugin) { TotemMoviePropertiesPlugin *pi; TotemObject *totem; GtkWindow *parent; GMenu *menu; GMenuItem *item; pi = TOTEM_MOVIE_PROPERTIES_PLUGIN (plugin); totem = g_object_get_data (G_OBJECT (plugin), "object"); pi->priv->props = bacon_video_widget_properties_new (); gtk_widget_show (pi->priv->props); gtk_widget_set_sensitive (pi->priv->props, FALSE); parent = totem_object_get_main_window (totem); pi->priv->dialog = gtk_dialog_new_with_buttons (_("Properties"), parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR, NULL, GTK_RESPONSE_CLOSE, NULL); g_object_unref (parent); g_signal_connect (pi->priv->dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL); g_signal_connect (pi->priv->dialog, "response", G_CALLBACK (gtk_widget_hide_on_delete), NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (pi->priv->dialog))), pi->priv->props); /* Properties action */ pi->priv->props_action = g_simple_action_new ("properties", NULL); g_signal_connect (G_OBJECT (pi->priv->props_action), "activate", G_CALLBACK (properties_action_cb), pi); g_action_map_add_action (G_ACTION_MAP (totem), G_ACTION (pi->priv->props_action)); gtk_application_add_accelerator (GTK_APPLICATION (totem), "<Primary>p", "app.properties", NULL); /* FIXME: Handle GDK_KEY_View */ /* Install the menu */ menu = totem_object_get_menu_section (totem, "properties-placeholder"); item = g_menu_item_new (_("_Properties"), "app.properties"); g_menu_item_set_attribute (item, "accel", "s", "<Primary>p"); g_menu_append_item (G_MENU (menu), item); g_object_unref (item); g_signal_connect (G_OBJECT (totem), "file-opened", G_CALLBACK (totem_movie_properties_plugin_file_opened), plugin); g_signal_connect (G_OBJECT (totem), "file-closed", G_CALLBACK (totem_movie_properties_plugin_file_closed), plugin); g_signal_connect (G_OBJECT (totem), "metadata-updated", G_CALLBACK (totem_movie_properties_plugin_metadata_updated), plugin); pi->priv->handler_id_stream_length = g_signal_connect (G_OBJECT (totem), "notify::stream-length", G_CALLBACK (stream_length_notify_cb), plugin); }