static void cc_privacy_panel_init (CcPrivacyPanel *self) { GError *error; GtkWidget *widget; GtkWidget *frame; guint res; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, CC_TYPE_PRIVACY_PANEL, CcPrivacyPanelPrivate); g_resources_register (cc_privacy_get_resource ()); self->priv->cancellable = g_cancellable_new (); self->priv->builder = gtk_builder_new (); error = NULL; res = gtk_builder_add_from_resource (self->priv->builder, "/org/gnome/control-center/privacy/privacy.ui", &error); if (res == 0) { g_warning ("Could not load interface file: %s", (error != NULL) ? error->message : "unknown error"); g_clear_error (&error); return; } self->priv->recent_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recent_dialog")); self->priv->screen_lock_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "screen_lock_dialog")); self->priv->location_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "location_dialog")); self->priv->trash_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "trash_dialog")); self->priv->software_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "software_dialog")); self->priv->abrt_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "abrt_dialog")); frame = WID ("frame"); widget = gtk_list_box_new (); gtk_list_box_set_selection_mode (GTK_LIST_BOX (widget), GTK_SELECTION_NONE); gtk_container_add (GTK_CONTAINER (frame), widget); self->priv->list_box = widget; gtk_widget_show (widget); self->priv->location_apps_list_box = WID ("location_apps_list_box"); gtk_list_box_set_header_func (GTK_LIST_BOX (self->priv->location_apps_list_box), cc_list_box_update_header_func, NULL, NULL); self->priv->location_apps_frame = WID ("location_apps_frame"); self->priv->location_apps_label = WID ("location_apps_label"); self->priv->location_icon_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); g_signal_connect_swapped (widget, "row-activated", G_CALLBACK (activate_row), self); gtk_list_box_set_header_func (GTK_LIST_BOX (widget), cc_list_box_update_header_func, NULL, NULL); self->priv->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown"); self->priv->lock_settings = g_settings_new ("org.gnome.desktop.screensaver"); self->priv->privacy_settings = g_settings_new ("org.gnome.desktop.privacy"); self->priv->notification_settings = g_settings_new ("org.gnome.desktop.notifications"); self->priv->location_settings = g_settings_new ("org.gnome.system.location"); add_screen_lock (self); add_location (self); add_usage_history (self); add_trash_temp (self); add_software (self); add_abrt (self); g_signal_connect (self->priv->lockdown_settings, "changed", G_CALLBACK (on_lockdown_settings_changed), self); update_lock_screen_sensitivity (self); widget = WID ("privacy_vbox"); gtk_container_add (GTK_CONTAINER (self), widget); }
static void gst_gio_base_src_init (GstGioBaseSrc * src) { src->cancel = g_cancellable_new (); }
void dlg_cover_chooser (GooWindow *window, const char *album, const char *artist) { DialogData *data; GtkListStore *model; GtkCellRenderer *renderer; data = g_new0 (DialogData, 1); data->window = window; data->builder = _gtk_builder_new_from_resource ("cover-chooser.ui"); data->album = g_strdup (album); data->artist = g_strdup (artist); data->cancellable = g_cancellable_new (); /* Get the widgets. */ data->dialog = GET_WIDGET ("cover_chooser_dialog"); model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF); data->icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); renderer = gtk_cell_renderer_pixbuf_new (); g_object_set (renderer, "follow-state", TRUE, NULL); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->icon_view), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (data->icon_view), renderer, "pixbuf", IMAGE_COLUMN, NULL); gtk_widget_show (data->icon_view); gtk_container_add (GTK_CONTAINER (GET_WIDGET ("icon_view_scrolledwindow")), data->icon_view); /* Set widgets data. */ backup_cover_image (data); gtk_widget_set_sensitive (GET_WIDGET ("ok_button"), FALSE); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect_swapped (GET_WIDGET ("cancel_button"), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("revert_button"), "clicked", G_CALLBACK (revert_button_clicked_cb), data); g_signal_connect (G_OBJECT (data->icon_view), "selection-changed", G_CALLBACK (icon_view_selection_changed_cb), data); g_signal_connect (G_OBJECT (data->icon_view), "item-activated", G_CALLBACK (icon_view_item_activated_cb), data); g_signal_connect (GET_WIDGET ("cancel_search_button"), "clicked", G_CALLBACK (cancel_search_button_clicked_cb), data); /* run dialog. */ gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); start_searching (data); }
static void prv_process_async_task(dld_task_t *task) { dld_async_task_t *async_task = (dld_async_task_t *)task; DLEYNA_LOG_DEBUG("Enter"); async_task->cancellable = g_cancellable_new(); switch (task->type) { case DLD_TASK_GET_PROP: dld_upnp_get_prop(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_GET_ALL_PROPS: dld_upnp_get_all_props(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_GET_ICON: dld_upnp_get_icon(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_MANAGER_GET_PROP: dld_manager_get_prop(g_context.manager, g_context.settings, task, prv_async_task_complete); break; case DLD_TASK_MANAGER_GET_ALL_PROPS: dld_manager_get_all_props(g_context.manager, g_context.settings, task, prv_async_task_complete); break; case DLD_TASK_MANAGER_SET_PROP: dld_manager_set_prop(g_context.manager, g_context.settings, task, prv_async_task_complete); break; case DLD_TASK_GET_TEST_INFO: dld_upnp_get_test_info(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_CANCEL_TEST: dld_upnp_cancel_test(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_PING: dld_upnp_ping(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_GET_PING_RESULT: dld_upnp_get_ping_result(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_NSLOOKUP: dld_upnp_nslookup(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_GET_NSLOOKUP_RESULT: dld_upnp_get_nslookup_result(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_TRACEROUTE: dld_upnp_traceroute(g_context.upnp, task, prv_async_task_complete); break; case DLD_TASK_GET_TRACEROUTE_RESULT: dld_upnp_get_traceroute_result(g_context.upnp, task, prv_async_task_complete); break; default: break; } DLEYNA_LOG_DEBUG("Exit"); }
int main(void) { NiceAgent *lagent = NULL, *ragent = NULL; GThread *stun_thread = NULL; NiceAddress baseaddr; GSource *src; int sock; g_type_init(); global_cancellable = g_cancellable_new (); src = g_cancellable_source_new (global_cancellable); g_source_set_dummy_callback (src); g_source_attach (src, NULL); g_source_unref (src); sock = listen_socket (&stun_port); if (sock == -1) { g_assert_not_reached (); } #if !GLIB_CHECK_VERSION(2,31,8) g_thread_init (NULL); stun_thread = g_thread_create (stun_thread_func, GINT_TO_POINTER (sock), TRUE, NULL); stun_mutex_ptr = g_mutex_new (); stun_signal_ptr = g_cond_new (); #else stun_thread = g_thread_new ("listen for STUN requests", stun_thread_func, GINT_TO_POINTER (sock)); #endif // Once the the thread is forked, we want to listen for a signal // that the socket was opened successfully g_mutex_lock (stun_thread_mutex_ptr); g_cond_wait (stun_thread_signal_ptr, stun_thread_mutex_ptr); lagent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245); ragent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245); g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL); g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL); g_object_set (G_OBJECT (lagent), "upnp", USE_UPNP, NULL); g_object_set (G_OBJECT (ragent), "upnp", USE_UPNP, NULL); g_object_set (G_OBJECT (lagent), "stun-server", "127.0.0.1", NULL); g_object_set (G_OBJECT (lagent), "stun-server-port", stun_port, NULL); g_object_set_data (G_OBJECT (lagent), "other-agent", ragent); g_object_set_data (G_OBJECT (ragent), "other-agent", lagent); g_assert (nice_address_set_from_string (&baseaddr, "127.0.0.1")); nice_agent_add_local_address (lagent, &baseaddr); nice_agent_add_local_address (ragent, &baseaddr); g_signal_connect(G_OBJECT(lagent), "candidate-gathering-done", G_CALLBACK(cb_candidate_gathering_done), LEFT_AGENT); g_signal_connect(G_OBJECT(ragent), "candidate-gathering-done", G_CALLBACK(cb_candidate_gathering_done), RIGHT_AGENT); g_signal_connect(G_OBJECT(lagent), "component-state-changed", G_CALLBACK(cb_component_state_changed), LEFT_AGENT); g_signal_connect(G_OBJECT(ragent), "component-state-changed", G_CALLBACK(cb_component_state_changed), RIGHT_AGENT); standard_test (lagent, ragent); bad_credentials_test (lagent, ragent); bad_candidate_test (lagent, ragent); new_candidate_test (lagent, ragent); // Do this to make sure the STUN thread exits exit_stun_thread = TRUE; drop_stun_packets = TRUE; send_dummy_data (); g_object_unref (lagent); g_object_unref (ragent); g_thread_join (stun_thread); #if !GLIB_CHECK_VERSION(2,31,8) g_mutex_free (stun_mutex_ptr); g_cond_free (stun_signal_ptr); #endif g_object_unref (global_cancellable); return 0; }
static void stdin_read_complete(GObject *src, GAsyncResult *res, gpointer data) { char *s, *ep; GError *err = NULL; gsize len; s = g_data_input_stream_read_line_finish(G_DATA_INPUT_STREAM(src), res, &len, &err); if (!s) { if (err) { FATAL_ERROR("Reading from stdin: %s\n", err->message); g_error_free(err); return; } switch (state) { case STATE_WAITING_FOR_BUS_N_DEV: FATAL_ERROR("EOF while waiting for bus and device num\n"); break; case STATE_WAITING_FOR_POL_KIT: ERROR("Cancelled while waiting for authorization\n"); break; case STATE_WAITING_FOR_STDIN_EOF: cleanup(); break; } return; } switch (state) { case STATE_WAITING_FOR_BUS_N_DEV: busnum = strtol(s, &ep, 10); if (!isspace(*ep)) { FATAL_ERROR("Invalid busnum / devnum: %s\n", s); break; } devnum = strtol(ep, &ep, 10); if (*ep != '\0') { FATAL_ERROR("Invalid busnum / devnum: %s\n", s); break; } /* * The set_facl() call is a no-op for root, so no need to ask PolKit * and then if ok call set_facl(), when called by a root process. */ if (getuid() != 0) { polkit_cancellable = g_cancellable_new(); polkit_authority_check_authorization( authority, subject, "org.spice-space.lowlevelusbaccess", NULL, POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, polkit_cancellable, (GAsyncReadyCallback)check_authorization_cb, NULL); state = STATE_WAITING_FOR_POL_KIT; } else { fprintf(stdout, "SUCCESS\n"); fflush(stdout); state = STATE_WAITING_FOR_STDIN_EOF; } g_data_input_stream_read_line_async(stdin_stream, G_PRIORITY_DEFAULT, NULL, stdin_read_complete, NULL); break; default: FATAL_ERROR("Unexpected extra input in state %d: %s\n", state, s); } g_free(s); }
static void bg_pictures_source_init (BgPicturesSource *self) { const gchar *pictures_path; BgPicturesSourcePrivate *priv; GFile *dir; char *cache_path; GtkListStore *store; priv = self->priv = PICTURES_SOURCE_PRIVATE (self); priv->cancellable = g_cancellable_new (); priv->known_items = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL); pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES); dir = g_file_new_for_path (pictures_path); g_file_enumerate_children_async (dir, ATTRIBUTES, G_FILE_QUERY_INFO_NONE, G_PRIORITY_LOW, priv->cancellable, dir_enum_async_ready, self); priv->picture_dir_monitor = g_file_monitor_directory (dir, G_FILE_MONITOR_NONE, priv->cancellable, NULL); if (priv->picture_dir_monitor) g_signal_connect (priv->picture_dir_monitor, "changed", G_CALLBACK (files_changed_cb), self); g_object_unref (dir); cache_path = bg_pictures_source_get_cache_path (); dir = g_file_new_for_path (cache_path); g_file_enumerate_children_async (dir, ATTRIBUTES, G_FILE_QUERY_INFO_NONE, G_PRIORITY_LOW, priv->cancellable, dir_enum_async_ready, self); priv->cache_dir_monitor = g_file_monitor_directory (dir, G_FILE_MONITOR_NONE, priv->cancellable, NULL); if (priv->cache_dir_monitor) g_signal_connect (priv->cache_dir_monitor, "changed", G_CALLBACK (files_changed_cb), self); g_object_unref (dir); priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE); store = bg_source_get_liststore (BG_SOURCE (self)); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), 1, (GtkTreeIterCompareFunc)sort_func, self, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 1, GTK_SORT_ASCENDING); }
void fileops_copy (GFile* file_list[], guint num, GFile* dest_dir) { g_copy_response = NULL; g_debug ("fileops_copy: Begin copying files"); GCancellable* copy_cancellable = g_cancellable_new (); TDData* data = g_malloc0 (sizeof (TDData)); data->cancellable = copy_cancellable; guint i; for (i = 0; i < num; i++) { GFile* src = file_list[i]; #if 1 char* src_uri= g_file_get_uri (src); char* dest_dir_uri = g_file_get_uri (dest_dir); g_debug ("fileops_copy: file %d: %s to dest_dir: %s", i, src_uri, dest_dir_uri); g_free (src_uri); #endif //make sure dest_dir is a directory before proceeding. GFileType type = g_file_query_file_type (dest_dir, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL); if (type != G_FILE_TYPE_DIRECTORY) { //TODO: how to handle symbolic links return; } // here ,we should first check the src directory is the same as the dest directory // if is same , we should change the copy_dest_file by changing src_basename char* src_basename = g_file_get_basename (src); char* name = g_strdup(src_basename); GFile* child = g_file_get_child(dest_dir, name); const char* name_add_before = _("Untitled"); GFile* parent = g_file_get_parent(src); char* parent_uri = g_file_get_uri(parent); g_object_unref(parent); if(0 == g_strcmp0(parent_uri,dest_dir_uri)) { for (int i=0; g_file_query_exists(child, NULL) && (i<500); i++) { g_object_unref(child); g_free(name); name = g_strdup_printf("%s(%d)%s",name_add_before, i,src_basename); child = g_file_get_child(dest_dir, name); } } g_free (dest_dir_uri); g_free (src_basename); g_free(name); g_free(parent_uri); data->dest_file = child; traverse_directory (src, _copy_files_async, _dummy_func, data); g_object_unref (data->dest_file); } g_object_unref (data->cancellable); g_free (data); fileops_response_free (g_copy_response); g_debug ("fileops_copy: End copying files"); }
static void dlg_photo_importer (GthBrowser *browser, GFile *source, DlgImporterSourceType selector_type) { DialogData *data; GtkCellRenderer *renderer; GthFileDataSort *sort_type; GList *tests, *scan; char *general_filter; int i, active_filter; int i_general; if (gth_browser_get_dialog (browser, "photo_importer") != NULL) { gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "photo_importer"))); return; } data = g_new0 (DialogData, 1); data->browser = browser; data->builder = gtk_builder_new_from_resource ("/org/gnome/gThumb/photo_importer/data/ui/photo-importer.ui"); data->settings = g_settings_new (GTHUMB_PHOTO_IMPORTER_SCHEMA); data->selector_type = selector_type; data->source = _g_object_ref (source); data->cancellable = g_cancellable_new (); data->vfs_source = g_object_new (GTH_TYPE_FILE_SOURCE_VFS, NULL); gth_file_source_monitor_entry_points (GTH_FILE_SOURCE (data->vfs_source)); /* Get the widgets. */ data->dialog = _gtk_builder_get_widget (data->builder, "photo_importer_dialog"); _gtk_window_resize_to_fit_screen_height (data->dialog, 580); gth_browser_set_dialog (browser, "photo_importer", data->dialog); g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data); if (data->selector_type == DLG_IMPORTER_SOURCE_TYPE_DEVICE) { gtk_window_set_title (GTK_WINDOW (data->dialog), _("Import from Removable Device")); data->device_list_store = gtk_list_store_new (SOURCE_LIST_COLUMNS, G_TYPE_OBJECT, G_TYPE_ICON, G_TYPE_STRING); data->device_chooser = gtk_combo_box_new_with_model (GTK_TREE_MODEL (data->device_list_store)); gtk_widget_show (data->device_chooser); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("source_box")), data->device_chooser, TRUE, TRUE, 0); gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("source_label")), data->device_chooser); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->device_chooser), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (data->device_chooser), renderer, "gicon", SOURCE_LIST_COLUMN_ICON, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->device_chooser), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (data->device_chooser), renderer, "text", SOURCE_LIST_COLUMN_NAME, NULL); g_object_unref (data->device_list_store); } else { if (data->source == NULL) { if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) data->source = _g_object_ref (gth_browser_get_location (browser)); if (data->source == NULL) data->source = g_file_new_for_uri (get_home_uri ()); } gtk_window_set_title (GTK_WINDOW (data->dialog), _("Import from Folder")); data->folder_chooser = gtk_file_chooser_button_new (_("Choose a folder"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("source_label")), data->folder_chooser); gtk_file_chooser_set_file (GTK_FILE_CHOOSER (data->folder_chooser), data->source, NULL); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (data->folder_chooser), FALSE); gtk_widget_show (data->folder_chooser); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("source_box")), data->folder_chooser, TRUE, TRUE, 0); } data->file_list = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NORMAL, FALSE); sort_type = gth_main_get_sort_type ("file::mtime"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->file_list), sort_type->cmp_func, FALSE); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->file_list), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->file_list), TRUE); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->file_list), 128); gth_file_list_set_caption (GTH_FILE_LIST (data->file_list), "standard::display-name,gth::file::display-size"); gtk_widget_show (data->file_list); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("filelist_box")), data->file_list, TRUE, TRUE, 0); tests = gth_main_get_registered_objects_id (GTH_TYPE_TEST); general_filter = "file::type::is_media"; /* default value */ active_filter = 0; data->filter_combobox = gtk_combo_box_text_new (); for (i = 0, i_general = -1, scan = tests; scan; scan = scan->next, i++) { const char *registered_test_id = scan->data; GthTest *test; if (strncmp (registered_test_id, "file::type::", 12) != 0) continue; i_general += 1; test = gth_main_get_registered_object (GTH_TYPE_TEST, registered_test_id); if (strcmp (registered_test_id, general_filter) == 0) { active_filter = i_general; gth_file_list_set_filter (GTH_FILE_LIST (data->file_list), test); } data->general_tests = g_list_prepend (data->general_tests, g_strdup (gth_test_get_id (test))); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->filter_combobox), gth_test_get_display_name (test)); g_object_unref (test); } data->general_tests = g_list_reverse (data->general_tests); gtk_combo_box_set_active (GTK_COMBO_BOX (data->filter_combobox), active_filter); gtk_widget_show (data->filter_combobox); gtk_container_add (GTK_CONTAINER (GET_WIDGET ("filter_box")), data->filter_combobox); gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("filter_label")), data->filter_combobox); gtk_label_set_use_underline (GTK_LABEL (GET_WIDGET ("filter_label")), TRUE); _g_string_list_free (tests); data->tags_entry = gth_tags_entry_new (GTH_TAGS_ENTRY_MODE_POPUP); gtk_widget_show (data->tags_entry); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("tags_entry_box")), data->tags_entry, TRUE, TRUE, 0); gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("tags_label")), data->tags_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("delete_checkbutton")), g_settings_get_boolean (data->settings, PREF_PHOTO_IMPORTER_DELETE_FROM_DEVICE)); data->preferences_dialog = gth_import_preferences_dialog_new (); gtk_window_set_transient_for (GTK_WINDOW (data->preferences_dialog), GTK_WINDOW (data->dialog)); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("destination_button_box")), gth_import_destination_button_new (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog)), TRUE, TRUE, 0); gtk_widget_show_all (GET_WIDGET ("destination_button_box")); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "delete-event", G_CALLBACK (dialog_delete_event_cb), data); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_clicked_cb), data); g_signal_connect (GET_WIDGET ("cancel_button"), "clicked", G_CALLBACK (close_dialog), data); if (data->selector_type == DLG_IMPORTER_SOURCE_TYPE_DEVICE) g_signal_connect (data->device_chooser, "changed", G_CALLBACK (device_chooser_changed_cb), data); else g_signal_connect (data->folder_chooser, "selection-changed", G_CALLBACK (folder_chooser_file_set_cb), data); g_signal_connect (data->filter_combobox, "changed", G_CALLBACK (filter_combobox_changed_cb), data); g_signal_connect (gth_file_view_get_model (GTH_FILE_VIEW (gth_file_list_get_view (GTH_FILE_LIST (data->file_list)))), "visibility_changed", G_CALLBACK (file_store_changed_cb), data); g_signal_connect (gth_file_list_get_view (GTH_FILE_LIST (data->file_list)), "file-selection-changed", G_CALLBACK (file_view_selection_changed_cb), data); data->entry_points_changed_id = g_signal_connect (gth_main_get_default_monitor (), "entry-points-changed", G_CALLBACK (entry_points_changed_cb), data); g_signal_connect_after (GET_WIDGET ("event_entry"), "changed", G_CALLBACK (event_entry_changed_cb), data); /* Run dialog. */ gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); gth_import_preferences_dialog_set_event (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog), gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("event_entry")))); if (data->selector_type == DLG_IMPORTER_SOURCE_TYPE_DEVICE) update_device_source_list (data); else load_file_list (data); }
static void cc_wacom_panel_init (CcWacomPanel *self) { CcWacomPanelPrivate *priv; GtkNotebook *notebook; GtkWidget *widget; GList *devices, *l; GError *error = NULL; char *objects[] = { "main-box", NULL }; priv = self->priv = WACOM_PANEL_PRIVATE (self); g_resources_register (cc_wacom_get_resource ()); priv->builder = gtk_builder_new (); gtk_builder_add_objects_from_resource (priv->builder, "/org/gnome/control-center/wacom/gnome-wacom-properties.ui", objects, &error); if (error != NULL) { g_warning ("Error loading UI file: %s", error->message); g_object_unref (priv->builder); g_error_free (error); return; } priv->cancellable = g_cancellable_new (); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.gnome.SettingsDaemon.Wacom", "/org/gnome/SettingsDaemon/Wacom", "org.gnome.SettingsDaemon.Wacom", priv->cancellable, got_wacom_proxy_cb, self); /* Notebook */ notebook = GTK_NOTEBOOK (gtk_notebook_new ()); priv->notebook = GTK_WIDGET (notebook); gtk_notebook_set_show_tabs (notebook, FALSE); gtk_notebook_set_show_border (notebook, FALSE); gtk_widget_set_vexpand (GTK_WIDGET (notebook), TRUE); gtk_container_set_border_width (GTK_CONTAINER (notebook), 0); g_object_set (G_OBJECT (notebook), "margin-top", 6, "margin-end", 30, "margin-start", 30, "margin-bottom", 30, NULL); gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (notebook)); gtk_widget_show (priv->notebook); /* No tablets page */ widget = WID ("main-box"); enbiggen_label (GTK_LABEL (WID ("advice-label1"))); gtk_notebook_append_page (notebook, widget, NULL); g_signal_connect (G_OBJECT (WID ("linkbutton")), "activate-link", G_CALLBACK (link_activated), self); priv->devices = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); priv->pages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); priv->manager = gdk_display_get_device_manager (gdk_display_get_default ()); priv->device_added_id = g_signal_connect (G_OBJECT (priv->manager), "device-added", G_CALLBACK (device_added_cb), self); priv->device_removed_id = g_signal_connect (G_OBJECT (priv->manager), "device-removed", G_CALLBACK (device_removed_cb), self); devices = gdk_device_manager_list_devices (priv->manager, GDK_DEVICE_TYPE_SLAVE); for (l = devices; l ; l = l->next) add_known_device (self, l->data); g_list_free (devices); update_current_page (self); }
static void prv_process_async_task(dls_task_t *task) { dls_async_task_t *async_task = (dls_async_task_t *)task; dls_client_t *client; const gchar *client_name; DLEYNA_LOG_DEBUG("Enter"); async_task->cancellable = g_cancellable_new(); client_name = dleyna_task_queue_get_source(task->atom.queue_id); client = g_hash_table_lookup(g_context.watchers, client_name); switch (task->type) { case DLS_TASK_MANAGER_GET_PROP: dls_manager_get_prop(g_context.manager, g_context.settings, task, prv_async_task_complete); break; case DLS_TASK_MANAGER_GET_ALL_PROPS: dls_manager_get_all_props(g_context.manager, g_context.settings, task, prv_async_task_complete); break; case DLS_TASK_MANAGER_SET_PROP: dls_manager_set_prop(g_context.manager, g_context.settings, task, prv_async_task_complete); break; case DLS_TASK_GET_CHILDREN: dls_upnp_get_children(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_GET_PROP: dls_upnp_get_prop(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_GET_ALL_PROPS: dls_upnp_get_all_props(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_SEARCH: dls_upnp_search(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_BROWSE_OBJECTS: dls_upnp_browse_objects(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_GET_RESOURCE: dls_upnp_get_resource(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_UPLOAD_TO_ANY: dls_upnp_upload_to_any(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_UPLOAD: dls_upnp_upload(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_DELETE_OBJECT: dls_upnp_delete_object(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_CREATE_CONTAINER: dls_upnp_create_container(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_CREATE_CONTAINER_IN_ANY: dls_upnp_create_container_in_any(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_UPDATE_OBJECT: dls_upnp_update_object(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_GET_OBJECT_METADATA: dls_upnp_get_object_metadata(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_CREATE_REFERENCE: dls_upnp_create_reference(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_GET_ICON: dls_upnp_get_icon(g_context.upnp, client, task, prv_async_task_complete); break; case DLS_TASK_WAKE: dls_upnp_wake(g_context.upnp, client, task, prv_async_task_complete); break; default: break; } DLEYNA_LOG_DEBUG("Exit"); }
int main (int argc, char *argv[]) { GSocket *socket; GSocketAddress *src_address; GSocketAddress *address; GSocketType socket_type; GSocketFamily socket_family; GError *error = NULL; GOptionContext *context; GCancellable *cancellable; GSocketAddressEnumerator *enumerator; GSocketConnectable *connectable; g_thread_init (NULL); g_type_init (); context = g_option_context_new (" <hostname>[:port] - Test GSocket client stuff"); g_option_context_add_main_entries (context, cmd_entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("%s: %s\n", argv[0], error->message); return 1; } if (argc != 2) { g_printerr ("%s: %s\n", argv[0], "Need to specify hostname / unix socket name"); return 1; } if (cancel_timeout) { cancellable = g_cancellable_new (); g_thread_create (cancel_thread, cancellable, FALSE, NULL); } else { cancellable = NULL; } loop = g_main_loop_new (NULL, FALSE); if (use_udp) socket_type = G_SOCKET_TYPE_DATAGRAM; else socket_type = G_SOCKET_TYPE_STREAM; if (unix_socket) socket_family = G_SOCKET_FAMILY_UNIX; else socket_family = G_SOCKET_FAMILY_IPV4; socket = g_socket_new (socket_family, socket_type, 0, &error); if (socket == NULL) { g_printerr ("%s: %s\n", argv[0], error->message); return 1; } if (read_timeout) g_socket_set_timeout (socket, read_timeout); if (unix_socket) { GSocketAddress *addr; addr = socket_address_from_string (argv[1]); if (addr == NULL) { g_printerr ("%s: Could not parse '%s' as unix socket name\n", argv[0], argv[1]); return 1; } connectable = G_SOCKET_CONNECTABLE (addr); } else { connectable = g_network_address_parse (argv[1], 7777, &error); if (connectable == NULL) { g_printerr ("%s: %s\n", argv[0], error->message); return 1; } } enumerator = g_socket_connectable_enumerate (connectable); while (TRUE) { address = g_socket_address_enumerator_next (enumerator, cancellable, &error); if (address == NULL) { if (error == NULL) g_printerr ("%s: No more addresses to try\n", argv[0]); else g_printerr ("%s: %s\n", argv[0], error->message); return 1; } if (g_socket_connect (socket, address, cancellable, &error)) break; g_printerr ("%s: Connection to %s failed: %s, trying next\n", argv[0], socket_address_to_string (address), error->message); g_error_free (error); error = NULL; g_object_unref (address); } g_object_unref (enumerator); g_object_unref (connectable); g_print ("Connected to %s\n", socket_address_to_string (address)); /* TODO: Test non-blocking connect */ if (non_blocking) g_socket_set_blocking (socket, FALSE); src_address = g_socket_get_local_address (socket, &error); if (!src_address) { g_printerr ("Error getting local address: %s\n", error->message); return 1; } g_print ("local address: %s\n", socket_address_to_string (src_address)); g_object_unref (src_address); while (TRUE) { gchar buffer[4096]; gssize size; gsize to_send; if (fgets (buffer, sizeof buffer, stdin) == NULL) break; to_send = strlen (buffer); while (to_send > 0) { ensure_condition (socket, "send", cancellable, G_IO_OUT); if (use_udp) size = g_socket_send_to (socket, address, buffer, to_send, cancellable, &error); else size = g_socket_send (socket, buffer, to_send, cancellable, &error); if (size < 0) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { g_print ("socket send would block, handling\n"); g_error_free (error); error = NULL; continue; } else { g_printerr ("Error sending to socket: %s\n", error->message); return 1; } } g_print ("sent %" G_GSSIZE_FORMAT " bytes of data\n", size); if (size == 0) { g_printerr ("Unexpected short write\n"); return 1; } to_send -= size; } ensure_condition (socket, "receive", cancellable, G_IO_IN); if (use_udp) size = g_socket_receive_from (socket, &src_address, buffer, sizeof buffer, cancellable, &error); else size = g_socket_receive (socket, buffer, sizeof buffer, cancellable, &error); if (size < 0) { g_printerr ("Error receiving from socket: %s\n", error->message); return 1; } if (size == 0) break; g_print ("received %" G_GSSIZE_FORMAT " bytes of data", size); if (use_udp) g_print (" from %s", socket_address_to_string (src_address)); g_print ("\n"); if (verbose) g_print ("-------------------------\n" "%.*s" "-------------------------\n", (int)size, buffer); } g_print ("closing socket\n"); if (!g_socket_close (socket, &error)) { g_printerr ("Error closing master socket: %s\n", error->message); return 1; } g_object_unref (G_OBJECT (socket)); g_object_unref (G_OBJECT (address)); return 0; }
static gboolean gst_net_client_internal_clock_start (GstNetClientInternalClock * self) { GSocketAddress *servaddr; GSocketAddress *myaddr; GSocketAddress *anyaddr; GInetAddress *inetaddr; GSocket *socket; GError *error = NULL; GSocketFamily family; GPollFD dummy_pollfd; GResolver *resolver = NULL; GError *err = NULL; g_return_val_if_fail (self->address != NULL, FALSE); g_return_val_if_fail (self->servaddr == NULL, FALSE); /* create target address */ inetaddr = g_inet_address_new_from_string (self->address); if (inetaddr == NULL) { GList *results; resolver = g_resolver_get_default (); results = g_resolver_lookup_by_name (resolver, self->address, NULL, &err); if (!results) goto failed_to_resolve; inetaddr = G_INET_ADDRESS (g_object_ref (results->data)); g_resolver_free_addresses (results); g_object_unref (resolver); } family = g_inet_address_get_family (inetaddr); servaddr = g_inet_socket_address_new (inetaddr, self->port); g_object_unref (inetaddr); g_assert (servaddr != NULL); GST_DEBUG_OBJECT (self, "will communicate with %s:%d", self->address, self->port); socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &error); if (socket == NULL) goto no_socket; GST_DEBUG_OBJECT (self, "binding socket"); inetaddr = g_inet_address_new_any (family); anyaddr = g_inet_socket_address_new (inetaddr, 0); g_socket_bind (socket, anyaddr, TRUE, &error); g_object_unref (anyaddr); g_object_unref (inetaddr); if (error != NULL) goto bind_error; /* check address we're bound to, mostly for debugging purposes */ myaddr = g_socket_get_local_address (socket, &error); if (myaddr == NULL) goto getsockname_error; GST_DEBUG_OBJECT (self, "socket opened on UDP port %d", g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (myaddr))); g_object_unref (myaddr); self->cancel = g_cancellable_new (); self->made_cancel_fd = g_cancellable_make_pollfd (self->cancel, &dummy_pollfd); self->socket = socket; self->servaddr = G_SOCKET_ADDRESS (servaddr); self->thread = g_thread_try_new ("GstNetClientInternalClock", gst_net_client_internal_clock_thread, self, &error); if (error != NULL) goto no_thread; return TRUE; /* ERRORS */ no_socket: { GST_ERROR_OBJECT (self, "socket_new() failed: %s", error->message); g_error_free (error); return FALSE; } bind_error: { GST_ERROR_OBJECT (self, "bind failed: %s", error->message); g_error_free (error); g_object_unref (socket); return FALSE; } getsockname_error: { GST_ERROR_OBJECT (self, "get_local_address() failed: %s", error->message); g_error_free (error); g_object_unref (socket); return FALSE; } failed_to_resolve: { GST_ERROR_OBJECT (self, "resolving '%s' failed: %s", self->address, err->message); g_clear_error (&err); g_object_unref (resolver); return FALSE; } no_thread: { GST_ERROR_OBJECT (self, "could not create thread: %s", error->message); g_object_unref (self->servaddr); self->servaddr = NULL; g_object_unref (self->socket); self->socket = NULL; g_error_free (error); return FALSE; } }
GIOServiceServer::GIOServiceServer(const string & address) throw(CommunicationModuleException){ cancelable = g_cancellable_new(); this->address = address; }
static void cc_background_panel_init (CcBackgroundPanel *self) { CcBackgroundPanelPrivate *priv; gchar *objects[] = {"background-panel", NULL }; GError *err = NULL; GtkWidget *widget; priv = self->priv = BACKGROUND_PANEL_PRIVATE (self); priv->connection = g_application_get_dbus_connection (g_application_get_default ()); g_resources_register (cc_background_get_resource ()); priv->builder = gtk_builder_new (); gtk_builder_add_objects_from_resource (priv->builder, "/org/gnome/control-center/background/background.ui", objects, &err); if (err) { g_warning ("Could not load ui: %s", err->message); g_error_free (err); return; } priv->settings = g_settings_new (WP_PATH_ID); g_settings_delay (priv->settings); priv->lock_settings = g_settings_new (WP_LOCK_PATH_ID); g_settings_delay (priv->lock_settings); /* add the top level widget */ widget = WID ("background-panel"); gtk_container_add (GTK_CONTAINER (self), widget); gtk_widget_show_all (GTK_WIDGET (self)); /* setup preview area */ widget = WID ("background-desktop-drawingarea"); g_signal_connect (widget, "draw", G_CALLBACK (on_preview_draw), self); widget = WID ("background-lock-drawingarea"); g_signal_connect (widget, "draw", G_CALLBACK (on_lock_preview_draw), self); priv->copy_cancellable = g_cancellable_new (); priv->capture_cancellable = g_cancellable_new (); priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE); /* Load the backgrounds */ reload_current_bg (self, priv->settings); update_preview (priv, priv->settings, NULL); reload_current_bg (self, priv->lock_settings); update_preview (priv, priv->lock_settings, NULL); /* Background settings */ g_signal_connect (priv->settings, "changed", G_CALLBACK (on_settings_changed), self); g_signal_connect (priv->lock_settings, "changed", G_CALLBACK (on_settings_changed), self); /* Background buttons */ widget = WID ("background-set-button"); g_signal_connect (widget, "clicked", G_CALLBACK (on_background_button_clicked), self); widget = WID ("background-lock-set-button"); g_signal_connect (widget, "clicked", G_CALLBACK (on_lock_button_clicked), self); }
static void grl_raitv_source_resolve (GrlSource *source, GrlSourceResolveSpec *rs) { gchar *urltarget; GrlRaitvSource *self = GRL_RAITV_SOURCE (source); RaitvOperation *op; RaitvMediaType mediatype; GRL_DEBUG ("Starting resolve source: url=%s",grl_media_get_url (rs->media)); if (!GRL_IS_MEDIA_VIDEO (rs->media) && !GRL_IS_MEDIA_BOX (rs->media)) { rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL); return; } mediatype = classify_media_id (grl_media_get_id (rs->media)); switch (mediatype) { case RAITV_MEDIA_TYPE_ROOT: rs->media = produce_container_from_directory (rs->media, NULL, 0, mediatype); break; case RAITV_MEDIA_TYPE_POPULARS: rs->media = produce_container_from_directory (rs->media, root_dir, ROOT_DIR_POPULARS_INDEX, mediatype); break; case RAITV_MEDIA_TYPE_RECENTS: rs->media = produce_container_from_directory (rs->media, root_dir, ROOT_DIR_RECENTS_INDEX, mediatype); break; case RAITV_MEDIA_TYPE_POPULAR_THEME: case RAITV_MEDIA_TYPE_RECENT_THEME: rs->media = produce_container_from_directory (rs->media, themes_dir, get_theme_index_from_id (grl_media_get_id (rs->media)), mediatype); break; case RAITV_MEDIA_TYPE_VIDEO: op = g_slice_new0 (RaitvOperation); op->source = g_object_ref (source); op->cancellable = g_cancellable_new (); op->operation_id = rs->operation_id; op->resolveCb = rs->callback; op->user_data = rs->user_data; op->media = rs->media; grl_operation_set_data (rs->operation_id, op); urltarget = g_strdup_printf ("http://www.rai.tv/dl/RaiTV/programmi/media/%s.html", grl_media_get_id(rs->media)); GRL_DEBUG ("Opening '%s'", urltarget); grl_net_wc_request_async (self->priv->wc, urltarget, op->cancellable, proxy_call_resolve_grlnet_async_cb, op); g_free(urltarget); return; } rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL); return; if ( grl_media_get_url (rs->media) != NULL) { rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL); return; } op = g_slice_new0 (RaitvOperation); op->source = g_object_ref (source); op->cancellable = g_cancellable_new (); op->operation_id = rs->operation_id; op->resolveCb = rs->callback; op->user_data = rs->user_data; op->media = rs->media; grl_operation_set_data (rs->operation_id, op); urltarget = g_strdup_printf("%s/%s.html","http://www.rai.tv/dl/RaiTV/programmi/media",grl_media_get_id(rs->media)); GRL_DEBUG ("Opening '%s'", urltarget); grl_net_wc_request_async (self->priv->wc, urltarget, op->cancellable, proxy_call_resolve_grlnet_async_cb, op); g_free(urltarget); }
/** * e_file_replace_contents_async: * @file: input #GFile * @contents: string of contents to replace the file with * @length: the length of @contents in bytes * @etag: a new entity tag for the @file, or %NULL * @make_backup: %TRUE if a backup should be created * @flags: a set of #GFileCreateFlags * @callback: a #GAsyncReadyCallback to call when the request is satisfied * @user_data: the data to pass to the callback function * * This is a wrapper for g_file_replace_contents_async() that also returns * an #EActivity to track the file operation. Cancelling the activity will * cancel the file operation. See g_file_replace_contents_async() for more * details. * * Returns: an #EActivity for the file operation **/ EActivity * e_file_replace_contents_async (GFile *file, const gchar *contents, gsize length, const gchar *etag, gboolean make_backup, GFileCreateFlags flags, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *simple; GCancellable *cancellable; AsyncContext *context; const gchar *format; gchar *description; gchar *basename; gchar *filename; gchar *hostname; gchar *uri; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (contents != NULL, NULL); uri = g_file_get_uri (file); filename = g_filename_from_uri (uri, &hostname, NULL); if (filename != NULL) basename = g_filename_display_basename (filename); else basename = g_strdup (_("(Unknown Filename)")); if (hostname == NULL) { /* Translators: The string value is the basename of a file. */ format = _("Writing \"%s\""); description = g_strdup_printf (format, basename); } else { /* Translators: The first string value is the basename of a * remote file, the second string value is the hostname. */ format = _("Writing \"%s\" to %s"); description = g_strdup_printf (format, basename, hostname); } cancellable = g_cancellable_new (); context = g_slice_new0 (AsyncContext); context->activity = e_activity_new (); e_activity_set_text (context->activity, description); e_activity_set_cancellable (context->activity, cancellable); simple = g_simple_async_result_new ( G_OBJECT (file), callback, user_data, e_file_replace_contents_async); g_simple_async_result_set_op_res_gpointer ( simple, context, (GDestroyNotify) async_context_free); g_file_replace_contents_async ( file, contents, length, etag, make_backup, flags, cancellable, (GAsyncReadyCallback) file_replace_contents_cb, simple); g_object_unref (cancellable); g_free (description); g_free (basename); g_free (filename); g_free (hostname); g_free (uri); return context->activity; }
static void cockpit_fslist_prepare (CockpitChannel *channel) { CockpitFslist *self = COCKPIT_FSLIST (channel); const gchar *problem = "protocol-error"; JsonObject *options; GError *error = NULL; GFile *file = NULL; gboolean watch; COCKPIT_CHANNEL_CLASS (cockpit_fslist_parent_class)->prepare (channel); options = cockpit_channel_get_options (channel); if (!cockpit_json_get_string (options, "path", NULL, &self->path)) { g_warning ("invalid \"path\" option for fslist1 channel"); goto out; } if (self->path == NULL || *(self->path) == 0) { g_warning ("missing \"path\" option for fslist1 channel"); goto out; } if (!cockpit_json_get_bool (options, "watch", TRUE, &watch)) { g_warning ("invalid \"watch\" option for fslist1 channel"); goto out; } self->cancellable = g_cancellable_new (); file = g_file_new_for_path (self->path); if (watch) { self->monitor = g_file_monitor_directory (file, 0, NULL, &error); if (self->monitor == NULL) { g_message ("%s: couldn't monitor directory: %s", self->path, error->message); options = cockpit_channel_close_options (channel); json_object_set_string_member (options, "message", error->message); problem = "internal-error"; goto out; } self->sig_changed = g_signal_connect (self->monitor, "changed", G_CALLBACK (on_changed), self); } g_file_enumerate_children_async (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, self->cancellable, on_enumerator_ready, self); problem = NULL; out: g_clear_error (&error); if (file) g_object_unref (file); if (problem) cockpit_channel_close (channel, problem); }
void dlg_import_from_picasaweb (GthBrowser *browser) { DialogData *data; GthThumbLoader *thumb_loader; data = g_new0 (DialogData, 1); data->browser = browser; data->builder = _gtk_builder_new_from_file ("import-from-picasaweb.ui", "picasaweb"); data->cancellable = g_cancellable_new (); data->dialog = g_object_new (GTK_TYPE_DIALOG, "title", _("Import from Picasa Web Album"), "transient-for", GTK_WINDOW (browser), "modal", FALSE, "use-header-bar", _gtk_settings_get_dialogs_use_header (), NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))), _gtk_builder_get_widget (data->builder, "dialog_content")); gtk_dialog_add_buttons (GTK_DIALOG (data->dialog), _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL, _("_Import"), GTK_RESPONSE_OK, NULL); _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("album_combobox")); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", ALBUM_NAME_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", ALBUM_SIZE_COLUMN, NULL); } _gtk_window_resize_to_fit_screen_height (data->dialog, 500); /* Set the widget data */ data->file_list = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NORMAL, FALSE); thumb_loader = gth_file_list_get_thumb_loader (GTH_FILE_LIST (data->file_list)); gth_thumb_loader_set_use_cache (thumb_loader, FALSE); gth_thumb_loader_set_loader_func (thumb_loader, picasa_web_thumbnail_loader); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->file_list), PICASA_WEB_THUMB_SIZE_SMALL); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->file_list), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->file_list), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->file_list), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->file_list), picasa_web_photo_position_func, FALSE); gth_file_list_clear (GTH_FILE_LIST (data->file_list), _("No album selected")); gtk_widget_show (data->file_list); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->file_list, TRUE, TRUE, 0); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("album_liststore")), ALBUM_NAME_COLUMN, GTK_SORT_ASCENDING); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, FALSE); data->preferences_dialog = gth_import_preferences_dialog_new (); gtk_window_set_transient_for (GTK_WINDOW (data->preferences_dialog), GTK_WINDOW (data->dialog)); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("destination_button_box")), gth_import_destination_button_new (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog)), TRUE, TRUE, 0); gtk_widget_show_all (GET_WIDGET ("destination_button_box")); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (import_dialog_destroy_cb), data); g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (import_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("album_combobox"), "changed", G_CALLBACK (album_combobox_changed_cb), data); g_signal_connect (G_OBJECT (gth_file_list_get_view (GTH_FILE_LIST (data->file_list))), "file-selection-changed", G_CALLBACK (file_list_selection_changed_cb), data); update_selection_status (data); gth_import_preferences_dialog_set_event (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog), ""); data->service = picasa_web_service_new (data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (service_account_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (service_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service), GTH_TASK_FLAGS_DEFAULT); web_service_autoconnect (WEB_SERVICE (data->service)); }
static void cc_power_panel_init (CcPowerPanel *self) { GError *error; GtkWidget *widget; gint value; char *text; self->priv = POWER_PANEL_PRIVATE (self); self->priv->builder = gtk_builder_new (); gtk_builder_set_translation_domain (self->priv->builder, GETTEXT_PACKAGE); error = NULL; gtk_builder_add_from_file (self->priv->builder, CINNAMONCC_UI_DIR "/power.ui", &error); if (error != NULL) { g_warning ("Could not load interface file: %s", error->message); g_error_free (error); return; } /* Make sure to set liststores (glade likes removing them from Gtk.ComboBoxText items in the .ui file....) */ gtk_combo_box_set_model (GTK_COMBO_BOX(SWID("combobox_display_ac")), LS("liststore_display")); gtk_combo_box_set_model (GTK_COMBO_BOX(SWID("combobox_display_battery")), LS("liststore_display")); gtk_combo_box_set_model (GTK_COMBO_BOX(SWID("combobox_sleep_ac")), LS("liststore_suspend")); gtk_combo_box_set_model (GTK_COMBO_BOX(SWID("combobox_sleep_battery")), LS("liststore_suspend")); /* add levelbar */ self->priv->levelbar_primary = SWID("levelbar_primary"); self->priv->cancellable = g_cancellable_new (); /* get initial icon state */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.cinnamon.SettingsDaemon", "/org/cinnamon/SettingsDaemon/Power", "org.cinnamon.SettingsDaemon.Power", self->priv->cancellable, got_power_proxy_cb, self); /* find out if there are any battery or UPS devices attached * and setup UI accordingly */ self->priv->up_client = up_client_new (); set_ac_battery_ui_mode (self); self->priv->csd_settings = g_settings_new ("org.cinnamon.settings-daemon.plugins.power"); self->priv->session_settings = g_settings_new ("org.cinnamon.desktop.session"); /* auto-display-off time */ value = g_settings_get_int (self->priv->csd_settings, "sleep-display-ac"); widget = SWID("combobox_display_ac"); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "sleep-display-ac"); g_signal_connect (widget, "changed", G_CALLBACK (combo_time_changed_cb), self); value = g_settings_get_int (self->priv->csd_settings, "sleep-display-battery"); widget = SWID("combobox_display_battery"); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "sleep-display-battery"); g_signal_connect (widget, "changed", G_CALLBACK (combo_time_changed_cb), self); /* auto-sleep time */ value = g_settings_get_int (self->priv->csd_settings, "sleep-inactive-ac-timeout"); widget = SWID("combobox_sleep_ac"); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "sleep-inactive-ac-timeout"); g_signal_connect (widget, "changed", G_CALLBACK (combo_time_changed_cb), self); value = g_settings_get_int (self->priv->csd_settings, "sleep-inactive-battery-timeout"); widget = SWID("combobox_sleep_battery"); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "sleep-inactive-battery-timeout"); g_signal_connect (widget, "changed", G_CALLBACK (combo_time_changed_cb), self); /* actions */ value = g_settings_get_enum (self->priv->csd_settings, "critical-battery-action"); widget = SWID("combobox_critical"); disable_unavailable_combo_items (self, GTK_COMBO_BOX (widget)); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "critical-battery-action"); g_signal_connect (widget, "changed", G_CALLBACK (combo_enum_changed_cb), self); value = g_settings_get_enum (self->priv->csd_settings, "lid-close-ac-action"); widget = SWID("combobox_lid_ac"); disable_unavailable_combo_items (self, GTK_COMBO_BOX (widget)); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "lid-close-ac-action"); g_signal_connect (widget, "changed", G_CALLBACK (combo_enum_changed_cb), self); value = g_settings_get_enum (self->priv->csd_settings, "lid-close-battery-action"); widget = SWID("combobox_lid_battery"); disable_unavailable_combo_items (self, GTK_COMBO_BOX (widget)); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT(widget), "_gsettings_key", "lid-close-battery-action"); g_signal_connect (widget, "changed", G_CALLBACK (combo_enum_changed_cb), self); widget = SWID ("vbox_power"); gtk_widget_reparent (widget, (GtkWidget *) self); value = g_settings_get_enum (self->priv->csd_settings, "button-power"); widget = SWID ("combobox_power_button"); disable_unavailable_combo_items (self, GTK_COMBO_BOX (widget)); set_value_for_combo (GTK_COMBO_BOX (widget), value); g_object_set_data (G_OBJECT (widget), "_gsettings_key", "button-power"); g_signal_connect (widget, "changed", G_CALLBACK (combo_enum_changed_cb), self); }
static void query_progress_cb (GDataEntry *entry, guint entry_key, guint entry_count, QueryData *data) { GList *thumbnails; GDataMediaThumbnail *thumbnail = NULL; gint delta = G_MININT; GtkTreeIter iter; const gchar *title, *id; GtkProgressBar *progress_bar; TotemYouTubePlugin *self = data->plugin; /* Add the entry to the tree view */ title = gdata_entry_get_title (entry); id = gdata_youtube_video_get_video_id (GDATA_YOUTUBE_VIDEO (entry)); gtk_list_store_append (self->list_store[data->tree_view], &iter); gtk_list_store_set (self->list_store[data->tree_view], &iter, 0, NULL, /* the thumbnail will be downloaded asynchronously and added to the tree view later */ 1, title, 2, NULL, /* the video URI will be resolved asynchronously and added to the tree view later */ 3, entry, -1); g_debug ("Added entry %s to tree view (title: \"%s\")", id, title); /* Update the progress bar; we have three steps for each entry in the results: the entry, its thumbnail, and its t parameter */ g_assert (entry_count > 0); progress_bar = self->progress_bar[data->tree_view]; self->progress_bar_increment[data->tree_view] = 1.0 / (entry_count * 3.0); g_debug ("Setting progress_bar_increment to 1.0 / (%u * 3.0) = %f", entry_count, self->progress_bar_increment[data->tree_view]); gtk_progress_bar_set_fraction (progress_bar, gtk_progress_bar_get_fraction (progress_bar) + self->progress_bar_increment[data->tree_view]); /* Resolve the t parameter for the video, which is required before it can be played */ /* This will be cancelled if the main query is cancelled, in query_finished_cb() */ data->t_param_cancellable = g_cancellable_new (); resolve_t_param (self, entry, &iter, data->tree_view, data->t_param_cancellable); /* Download the entry's thumbnail, ready for adding it to the tree view. * Find the thumbnail size which is closest to the wanted size (THUMBNAIL_WIDTH), so that we: * a) avoid fuzzy images due to scaling up, and * b) avoid downloading too much just to scale down by a factor of 10. */ thumbnails = gdata_youtube_video_get_thumbnails (GDATA_YOUTUBE_VIDEO (entry)); for (; thumbnails != NULL; thumbnails = thumbnails->next) { gint new_delta; GDataMediaThumbnail *current_thumb = (GDataMediaThumbnail*) thumbnails->data; g_debug ("%u pixel wide thumbnail available for entry %s", gdata_media_thumbnail_get_width (current_thumb), id); new_delta = gdata_media_thumbnail_get_width (current_thumb) - THUMBNAIL_WIDTH; if (delta == 0) { break; } else if ((delta == G_MININT) || (delta < 0 && new_delta > delta) || (delta > 0 && new_delta > 0 && new_delta < delta)) { delta = new_delta; thumbnail = current_thumb; g_debug ("Choosing a %u pixel wide thumbnail (delta: %i) for entry %s", gdata_media_thumbnail_get_width (current_thumb), new_delta, id); } } if (thumbnail != NULL) { GFile *thumbnail_file; ThumbnailData *t_data; t_data = g_slice_new (ThumbnailData); t_data->plugin = g_object_ref (self); t_data->path = gtk_tree_model_get_path (GTK_TREE_MODEL (self->list_store[data->tree_view]), &iter); t_data->tree_view = data->tree_view; /* We can use the same cancellable for reading the file and making a pixbuf out of it, as they're consecutive operations */ /* This will be cancelled if the main query is cancelled, in query_finished_cb() */ data->thumbnail_cancellable = g_cancellable_new (); t_data->cancellable = g_object_ref (data->thumbnail_cancellable); g_debug ("Starting thumbnail download for entry %s", id); thumbnail_file = g_file_new_for_uri (gdata_media_thumbnail_get_uri (thumbnail)); g_file_read_async (thumbnail_file, G_PRIORITY_DEFAULT, data->thumbnail_cancellable, (GAsyncReadyCallback) thumbnail_opened_cb, t_data); g_object_unref (thumbnail_file); } }
static gboolean gst_split_file_src_start (GstBaseSrc * basesrc) { GstSplitFileSrc *src = GST_SPLIT_FILE_SRC (basesrc); GCancellable *cancel; gboolean ret = FALSE; guint64 offset; GError *err = NULL; gchar *basename = NULL; gchar *dirname = NULL; gchar **files; guint i; GST_OBJECT_LOCK (src); if (src->location != NULL && src->location[0] != '\0') { basename = g_path_get_basename (src->location); dirname = g_path_get_dirname (src->location); } GST_OBJECT_UNLOCK (src); files = gst_split_file_src_find_files (src, dirname, basename, &err); if (files == NULL || *files == NULL) goto no_files; src->num_parts = g_strv_length (files); src->parts = g_new0 (GstFilePart, src->num_parts); cancel = src->cancellable; offset = 0; for (i = 0; i < src->num_parts; ++i) { GFileInputStream *stream; GFileInfo *info; goffset size; GFile *file; file = g_file_new_for_path (files[i]); stream = g_file_read (file, cancel, &err); g_object_unref (file); if (err != NULL) goto open_read_error; info = g_file_input_stream_query_info (stream, "standard::*", NULL, &err); if (err != NULL) { g_object_unref (stream); goto query_info_error; } size = g_file_info_get_size (info); g_object_unref (info); src->parts[i].stream = stream; src->parts[i].path = g_strdup (files[i]); src->parts[i].start = offset; src->parts[i].stop = offset + size - 1; GST_DEBUG ("[%010" G_GUINT64_FORMAT "-%010" G_GUINT64_FORMAT "] %s", src->parts[i].start, src->parts[i].stop, src->parts[i].path); offset += size; } GST_INFO ("Successfully opened %u file parts for reading", src->num_parts); src->cur_part = 0; src->cancellable = g_cancellable_new (); ret = TRUE; done: if (err != NULL) g_error_free (err); g_strfreev (files); g_free (basename); g_free (dirname); return ret; /* ERRORS */ no_files: { if (err->code == G_IO_ERROR_CANCELLED) goto cancelled; GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("%s", err->message), ("Failed to find files in '%s' for pattern '%s'", GST_STR_NULL (dirname), GST_STR_NULL (basename))); goto done; } open_read_error: { if (err->code == G_IO_ERROR_CANCELLED) goto cancelled; GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("%s", err->message), ("Failed to open file '%s' for reading", files[i])); goto done; } query_info_error: { if (err->code == G_IO_ERROR_CANCELLED) goto cancelled; GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("%s", err->message), ("Failed to query info for file '%s'", files[i])); goto done; } cancelled: { GST_DEBUG_OBJECT (src, "I/O operation cancelled from another thread"); goto done; } }
gboolean gimp_gradient_save_pov (GimpGradient *gradient, GFile *file, GError **error) { GOutputStream *output; GString *string; GimpGradientSegment *seg; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar color_buf[4][G_ASCII_DTOSTR_BUF_SIZE]; GError *my_error = NULL; g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, error)); if (! output) return FALSE; string = g_string_new ("/* color_map file created by GIMP */\n" "/* https://www.gimp.org/ */\n" "color_map {\n"); for (seg = gradient->segments; seg; seg = seg->next) { /* Left */ g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left); g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.r); g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.g); g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.b); g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", 1.0 - seg->left_color.a); g_string_append_printf (string, "\t[%s color rgbt <%s, %s, %s, %s>]\n", buf, color_buf[0], color_buf[1], color_buf[2], color_buf[3]); /* Middle */ g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->middle); g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", (seg->left_color.r + seg->right_color.r) / 2.0); g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", (seg->left_color.g + seg->right_color.g) / 2.0); g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", (seg->left_color.b + seg->right_color.b) / 2.0); g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", 1.0 - (seg->left_color.a + seg->right_color.a) / 2.0); g_string_append_printf (string, "\t[%s color rgbt <%s, %s, %s, %s>]\n", buf, color_buf[0], color_buf[1], color_buf[2], color_buf[3]); /* Right */ g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right); g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.r); g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.g); g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.b); g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", 1.0 - seg->right_color.a); g_string_append_printf (string, "\t[%s color rgbt <%s, %s, %s, %s>]\n", buf, color_buf[0], color_buf[1], color_buf[2], color_buf[3]); } g_string_append_printf (string, "} /* color_map */\n"); if (! g_output_stream_write_all (output, string->str, string->len, NULL, NULL, &my_error)) { GCancellable *cancellable = g_cancellable_new (); g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE, _("Writing POV file '%s' failed: %s"), gimp_file_get_utf8_name (file), my_error->message); g_clear_error (&my_error); g_string_free (string, TRUE); /* Cancel the overwrite initiated by g_file_replace(). */ g_cancellable_cancel (cancellable); g_output_stream_close (output, cancellable, NULL); g_object_unref (cancellable); g_object_unref (output); return FALSE; } g_string_free (string, TRUE); g_object_unref (output); return TRUE; }
static void grl_optical_media_source_browse (GrlSource *source, GrlSourceBrowseSpec *bs) { GList *mounts, *l; GrlOpticalMediaSourcePrivate *priv = GRL_OPTICAL_MEDIA_SOURCE (source)->priv; BrowseData *data; GList *media_list; GRL_DEBUG ("%s", __FUNCTION__); g_list_free_full (priv->list, g_object_unref); media_list = NULL; /* Look for loopback-mounted ISO images and discs */ mounts = g_volume_monitor_get_mounts (priv->monitor); for (l = mounts; l != NULL; l = l->next) { GMount *mount = l->data; if (!ignore_mount (mount)) { GrlMedia *media; media = create_media_from_mount (mount); if (media) media_list = g_list_prepend (media_list, media); } g_object_unref (mount); } g_list_free (mounts); /* Got nothing? */ if (media_list == NULL) { /* Tell the caller we're done */ bs->callback (bs->source, bs->operation_id, NULL, 0, bs->user_data, NULL); return; } media_list = g_list_reverse (media_list); /* And go to resolve all those devices */ data = g_new0 (BrowseData, 1); data->source = source; data->bs = bs; data->media_list = media_list; data->cancellable = g_cancellable_new (); grl_operation_set_data (bs->operation_id, data->cancellable); data->parser = totem_pl_parser_new (); g_object_set (data->parser, "recurse", FALSE, NULL); g_signal_connect (G_OBJECT (data->parser), "entry-parsed", G_CALLBACK (entry_parsed_cb), &data->media); resolve_disc_urls (data); }
/** * main: **/ int main (int argc, char *argv[]) { gboolean ret; PkCnfPolicyConfig *config = NULL; guint i; guint len; gchar *text; const gchar *possible; gchar **parts; guint retval = EXIT_COMMAND_NOT_FOUND; _cleanup_ptrarray_unref_ GPtrArray *array = NULL; _cleanup_strv_free_ gchar **package_ids = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 31) if (! g_thread_supported ()) g_thread_init (NULL); #endif #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35) g_type_init (); #endif /* don't show debugging, unless VERBOSE is specified */ pk_debug_add_log_domain (G_LOG_DOMAIN); /* no input */ if (argv[1] == NULL) goto out; /* do stuff on ctrl-c */ signal (SIGINT, pk_cnf_sigint_handler); /* get policy config */ config = pk_cnf_get_config (); task = PK_TASK(pk_task_text_new ()); g_object_set (task, "cache-age", G_MAXUINT, "interactive", FALSE, "background", FALSE, NULL); cancellable = g_cancellable_new (); /* get length */ len = strlen (argv[1]); if (len < 1) goto out; if (argv[1][0] == '.') goto out; /* TRANSLATORS: the prefix of all the output telling the user * why it's not executing. NOTE: this is lowercase to mimic * the style of bash itself -- apologies */ g_printerr ("bash: %s: %s...\n", argv[1], _("command not found")); /* user is not allowing CNF to do anything useful */ if (!config->software_source_search && !config->similar_name_search) { goto out; } /* generate swizzles */ if (config->similar_name_search) array = pk_cnf_find_alternatives (argv[1], len); /* one exact possibility */ if (array != NULL && array->len == 1) { possible = g_ptr_array_index (array, 0); if (config->single_match == PK_CNF_POLICY_WARN) { /* TRANSLATORS: tell the user what we think the command is */ g_printerr ("%s '%s'\n", _("Similar command is:"), possible); goto out; } /* run */ if (config->single_match == PK_CNF_POLICY_RUN) { retval = pk_cnf_spawn_command (possible, &argv[2]); goto out; } /* ask */ if (config->single_match == PK_CNF_POLICY_ASK) { /* TRANSLATORS: Ask the user if we should run the similar command */ text = g_strdup_printf ("%s %s", _("Run similar command:"), possible); ret = pk_console_get_prompt (text, TRUE); if (ret) retval = pk_cnf_spawn_command (possible, &argv[2]); g_free (text); } goto out; /* multiple choice */ } else if (array != NULL && array->len > 1) { if (config->multiple_match == PK_CNF_POLICY_WARN) { /* TRANSLATORS: show the user a list of commands that they could have meant */ g_printerr ("%s:\n", _("Similar commands are:")); for (i = 0; i < array->len; i++) { possible = g_ptr_array_index (array, i); g_printerr ("'%s'\n", possible); } /* ask */ } else if (config->multiple_match == PK_CNF_POLICY_ASK) { /* TRANSLATORS: show the user a list of commands we could run */ g_printerr ("%s:\n", _("Similar commands are:")); for (i = 0; i < array->len; i++) { possible = g_ptr_array_index (array, i); g_printerr ("%i\t'%s'\n", i+1, possible); } /* TRANSLATORS: ask the user to choose a file to run */ i = pk_console_get_number (_("Please choose a command to run"), array->len); /* run command */ possible = g_ptr_array_index (array, i); retval = pk_cnf_spawn_command (possible, &argv[2]); } goto out; /* only search using PackageKit if configured to do so */ } else if (config->software_source_search) { package_ids = pk_cnf_find_available (argv[1], config->max_search_time); if (package_ids == NULL) goto out; len = g_strv_length (package_ids); if (len == 1) { parts = pk_package_id_split (package_ids[0]); if (config->single_install == PK_CNF_POLICY_WARN) { /* TRANSLATORS: tell the user what package provides the command */ g_printerr ("%s '%s'\n", _("The package providing this file is:"), parts[PK_PACKAGE_ID_NAME]); goto out; } /* ask */ if (config->single_install == PK_CNF_POLICY_ASK) { /* TRANSLATORS: as the user if we want to install a package to provide the command */ text = g_strdup_printf (_("Install package '%s' to provide command '%s'?"), parts[PK_PACKAGE_ID_NAME], argv[1]); ret = pk_console_get_prompt (text, FALSE); g_free (text); if (ret) { ret = pk_cnf_install_package_id (package_ids[0]); if (ret) retval = pk_cnf_spawn_command (argv[1], &argv[2]); } g_print ("\n"); goto out; } /* install */ if (config->single_install == PK_CNF_POLICY_INSTALL) { ret = pk_cnf_install_package_id (package_ids[0]); if (ret) retval = pk_cnf_spawn_command (argv[1], &argv[2]); } g_strfreev (parts); goto out; } else if (len > 1) { if (config->multiple_install == PK_CNF_POLICY_WARN) { /* TRANSLATORS: Show the user a list of packages that provide this command */ g_printerr ("%s\n", _("Packages providing this file are:")); for (i = 0; package_ids[i] != NULL; i++) { parts = pk_package_id_split (package_ids[i]); g_printerr ("'%s'\n", parts[PK_PACKAGE_ID_NAME]); g_strfreev (parts); } /* ask */ } else if (config->multiple_install == PK_CNF_POLICY_ASK) { /* TRANSLATORS: Show the user a list of packages that they can install to provide this command */ g_printerr ("%s:\n", _("Suitable packages are:")); for (i = 0; package_ids[i] != NULL; i++) { parts = pk_package_id_split (package_ids[i]); g_printerr ("%i\t'%s'\n", i+1, parts[PK_PACKAGE_ID_NAME]); g_strfreev (parts); } /* TRANSLATORS: ask the user to choose a file to install */ i = pk_console_get_number (_("Please choose a package to install"), len); if (i == 0) { g_printerr ("%s\n", _("User aborted selection")); goto out; } /* run command */ ret = pk_cnf_install_package_id (package_ids[i - 1]); if (ret) retval = pk_cnf_spawn_command (argv[1], &argv[2]); } goto out; } } out: if (task != NULL) g_object_unref (task); if (cancellable != NULL) g_object_unref (cancellable); if (config != NULL) { g_strfreev (config->locations); g_free (config); } return retval; }
void mm_port_probe_run (MMPortProbe *self, MMPortProbeFlag flags, guint64 at_send_delay, gboolean at_remove_echo, const MMPortProbeAtCommand *at_custom_probe, const MMAsyncMethod *at_custom_init, GAsyncReadyCallback callback, gpointer user_data) { PortProbeRunTask *task; guint32 i; gchar *probe_list_str; g_return_if_fail (MM_IS_PORT_PROBE (self)); g_return_if_fail (flags != MM_PORT_PROBE_NONE); g_return_if_fail (callback != NULL); /* Shouldn't schedule more than one probing at a time */ g_assert (self->priv->task == NULL); task = g_new0 (PortProbeRunTask, 1); task->at_send_delay = at_send_delay; task->at_remove_echo = at_remove_echo; task->flags = MM_PORT_PROBE_NONE; task->at_custom_probe = at_custom_probe; task->at_custom_init = at_custom_init ? (MMPortProbeAtCustomInit)at_custom_init->async : NULL; task->at_custom_init_finish = at_custom_init ? (MMPortProbeAtCustomInitFinish)at_custom_init->finish : NULL; task->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, mm_port_probe_run); /* Check if we already have the requested probing results. * We will fix here the 'task->flags' so that we only request probing * for the missing things. */ for (i = MM_PORT_PROBE_AT; i <= MM_PORT_PROBE_QMI; i = (i << 1)) { if ((flags & i) && !(self->priv->flags & i)) { task->flags += i; } } /* Store as current task. We need to keep it internally, as it will be * freed during _finish() when the operation is completed. */ self->priv->task = task; /* All requested probings already available? If so, we're done */ if (!task->flags) { port_probe_run_task_complete (task, TRUE, NULL); return; } /* Setup internal cancellable */ task->cancellable = g_cancellable_new (); probe_list_str = mm_port_probe_flag_build_string_from_mask (task->flags); mm_info ("(%s/%s) launching port probing: '%s'", g_udev_device_get_subsystem (self->priv->port), g_udev_device_get_name (self->priv->port), probe_list_str); g_free (probe_list_str); /* If any AT probing is needed, start by opening as AT port */ if (task->flags & MM_PORT_PROBE_AT || task->flags & MM_PORT_PROBE_AT_VENDOR || task->flags & MM_PORT_PROBE_AT_PRODUCT || task->flags & MM_PORT_PROBE_AT_ICERA) { task->at_probing_cancellable = g_cancellable_new (); task->source_id = g_idle_add ((GSourceFunc)serial_open_at, self); return; } /* If QCDM probing needed, start by opening as QCDM port */ if (task->flags & MM_PORT_PROBE_QCDM) { task->source_id = g_idle_add ((GSourceFunc)serial_probe_qcdm, self); return; } /* If QMI probing needed, start by opening as a QMI port */ if (task->flags & MM_PORT_PROBE_QMI) { task->source_id = g_idle_add ((GSourceFunc)wdm_probe_qmi, self); return; } /* Shouldn't happen */ g_assert_not_reached (); }
SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient& client) : SocketStreamHandleBase(url, client) , m_cancellable(adoptGRef(g_cancellable_new())) { LOG(Network, "SocketStreamHandle %p new client %p", this, &m_client); }
static inline void newQueryCancellable(WlDictQuery * query) { cancelQuery(query); query->cancel = g_cancellable_new(); }
void GThreadSafeMainLoopSource::schedule(const char* name, std::function<void ()> function, int priority, std::function<void ()> destroyFunction, GMainContext* context) { GMutexLocker<GRecMutex> locker(m_mutex); GMainLoopSource::schedule(name, function, priority, destroyFunction, context); m_context.cancellable = adoptGRef(g_cancellable_new()); }
int main (int argc, char **argv) { State *state = NULL; GOptionContext *context = NULL; static char **args = NULL; static gboolean run_script = FALSE; static gboolean allow_remote_connections = FALSE; gboolean debug = FALSE; gboolean ret; int exit_status = EX_OK; static GOptionEntry entries [] = { { "run-script", 'r', 0, G_OPTION_ARG_NONE, &run_script, N_("Run program through /etc/gdm/Xsession wrapper script"), NULL }, { "allow-remote-connections", 'a', 0, G_OPTION_ARG_NONE, &allow_remote_connections, N_("Listen on TCP socket"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, "", "" }, { NULL } }; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); setlocale (LC_ALL, ""); gdm_log_init (); context = g_option_context_new (_("GNOME Display Manager X Session Launcher")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); if (args == NULL || args[0] == NULL || args[1] != NULL) { g_warning ("gdm-x-session takes one argument (the session)"); exit_status = EX_USAGE; goto out; } init_state (&state); state->session_command = args[0]; state->settings = gdm_settings_new (); ret = gdm_settings_direct_init (state->settings, DATADIR "/gdm/gdm.schemas", "/"); if (!ret) { g_printerr ("Unable to initialize settings\n"); exit_status = EX_DATAERR; goto out; } gdm_settings_direct_get_boolean (GDM_KEY_DEBUG, &debug); state->debug_enabled = debug; gdm_log_set_debug (debug); state->main_loop = g_main_loop_new (NULL, FALSE); state->cancellable = g_cancellable_new (); g_unix_signal_add (SIGTERM, (GSourceFunc) on_sigterm, state); ret = spawn_x_server (state, allow_remote_connections, state->cancellable); if (!ret) { g_printerr ("Unable to run X server\n"); exit_status = EX_SOFTWARE; goto out; } ret = spawn_bus (state, state->cancellable); if (!ret) { g_printerr ("Unable to run session message bus\n"); exit_status = EX_SOFTWARE; goto out; } import_environment (state, state->cancellable); ret = update_bus_environment (state, state->cancellable); if (!ret) { g_printerr ("Unable to update bus environment\n"); exit_status = EX_SOFTWARE; goto out; } ret = register_display (state, state->cancellable); if (!ret) { g_printerr ("Unable to register display with display manager\n"); exit_status = EX_SOFTWARE; goto out; } ret = spawn_session (state, run_script, state->cancellable); if (!ret) { g_printerr ("Unable to run session\n"); exit_status = EX_SOFTWARE; goto out; } g_main_loop_run (state->main_loop); /* Only use exit status of session if we're here because it exit */ if (state->session_subprocess == NULL) { exit_status = state->session_exit_status; } out: signal_subprocesses (state); wait_on_subprocesses (state); clear_state (&state); return exit_status; }