/** * ldap_favorite_selector_new * * Returns: a new #GtkWidget */ GtkWidget * ldap_favorite_selector_new (TConnection *tcnc) { LdapFavoriteSelector *fsel; GdaTreeManager *manager; gchar *signame; g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL); fsel = LDAP_FAVORITE_SELECTOR (g_object_new (LDAP_FAVORITE_SELECTOR_TYPE, NULL)); fsel->priv->tcnc = g_object_ref (tcnc); signame = g_strdup_printf ("favorites-changed::%s", t_favorites_type_to_string (T_FAVORITES_LDAP_DN)); g_signal_connect (t_connection_get_favorites (fsel->priv->tcnc), signame, G_CALLBACK (favorites_changed_cb), fsel); g_free (signame); signame = g_strdup_printf ("favorites-changed::%s", t_favorites_type_to_string (T_FAVORITES_LDAP_CLASS)); g_signal_connect (t_connection_get_favorites (fsel->priv->tcnc), signame, G_CALLBACK (favorites_changed_cb), fsel); g_free (signame); /* create tree managers */ fsel->priv->tree = gda_tree_new (); manager = mgr_favorites_new (tcnc, T_FAVORITES_LDAP_DN, ORDER_KEY_LDAP); gda_tree_add_manager (fsel->priv->tree, manager); g_object_unref (manager); manager = mgr_favorites_new (tcnc, T_FAVORITES_LDAP_CLASS, ORDER_KEY_LDAP); gda_tree_add_manager (fsel->priv->tree, manager); g_object_unref (manager); /* update the tree's contents */ if (! gda_tree_update_all (fsel->priv->tree, NULL)) { if (fsel->priv->idle_update_favorites == 0) fsel->priv->idle_update_favorites = g_idle_add ((GSourceFunc) idle_update_favorites, fsel); } /* header */ GtkWidget *label; gchar *str; str = g_strdup_printf ("<b>%s</b>", _("Favorites")); label = gdaui_bar_new (str); g_free (str); gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), ui_get_pixbuf_icon (UI_ICON_BOOKMARK)); gtk_box_pack_start (GTK_BOX (fsel), label, FALSE, FALSE, 0); gtk_widget_show (label); /* tree model & tree view */ GtkTreeModel *model; GtkWidget *treeview; GtkCellRenderer *renderer; GtkTreeViewColumn *column; model = gdaui_tree_store_new (fsel->priv->tree, COLUMN_LAST, G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME, G_TYPE_STRING, MGR_FAVORITES_CONTENTS_ATT_NAME, G_TYPE_OBJECT, "icon", G_TYPE_STRING, "markup", G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME, G_TYPE_STRING, "descr", G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME); treeview = ui_make_tree_view (model); fsel->priv->treeview = treeview; g_object_unref (model); g_signal_connect (G_OBJECT (treeview), "row-activated", G_CALLBACK (selection_changed_cb), fsel); g_signal_connect (G_OBJECT (treeview), "key-press-event", G_CALLBACK (key_press_event_cb), fsel); g_signal_connect (G_OBJECT (treeview), "popup-menu", G_CALLBACK (popup_menu_cb), fsel); g_signal_connect (G_OBJECT (treeview), "button-press-event", G_CALLBACK (button_press_event_cb), fsel); /* icon */ column = gtk_tree_view_column_new (); renderer = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_add_attribute (column, renderer, "pixbuf", COLUMN_ICON); g_object_set ((GObject*) renderer, "yalign", 0., NULL); /* text */ renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer, TRUE); gtk_tree_view_column_add_attribute (column, renderer, "markup", COLUMN_MARKUP); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); /* scrolled window packing */ GtkWidget *sw; 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_NEVER, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), treeview); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); gtk_box_pack_start (GTK_BOX (fsel), sw, TRUE, TRUE, 0); gtk_widget_show_all (sw); /* DnD */ gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (treeview), dbo_table, G_N_ELEMENTS (dbo_table), GDK_ACTION_COPY); gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview), GDK_BUTTON1_MASK, dbo_table, G_N_ELEMENTS (dbo_table), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect (model, "drag-drop", G_CALLBACK (tree_store_drag_drop_cb), fsel); g_signal_connect (model, "drag-can-drag", G_CALLBACK (tree_store_drag_can_drag_cb), fsel); g_signal_connect (model, "drag-get", G_CALLBACK (tree_store_drag_get_cb), fsel); return (GtkWidget*) fsel; }
static void setup_commit_passwd1 (GVariant *parameters, GDBusMethodInvocation *invocation) { const gchar *mechanism; GVariant *transferred = NULL; const gchar **lines; GHashTable *users = NULL; GHashTable *groups = NULL; GString *chpasswd = NULL; GString *newusers = NULL; CommitAdmin1 *context; CockpitPipe *pipe; gsize length, i, j; gchar **parts; GBytes *bytes; GVariant *pwdata = NULL; GVariant *grdata = NULL; GHashTable *usermod; gchar **memlist; GString *string; gboolean user_exists; /* We are getting crypted passwords so we need to use * --crypt-method=NONE with newusers and chpasswd so that the string * is installed unchanged. Unfortunately, newusers might or might * not support the --crypt-method option, depending on whether it * was compiled with or without PAM. When the option is missing, we * fix up the password afterwards via chpasswd. * * However, newusers needs some valid password to create new users. * Thus, we need a good random string that passes all password * quality criteria, and we just use the crpyted password for that. */ const gchar *argv[] = { cockpit_bridge_path_newusers, "--crypt-method=NONE", NULL }; if (!cockpit_bridge_have_newusers_crypt_method) argv[1] = NULL; g_variant_get (parameters, "(&sv)", &mechanism, &transferred); if (!g_str_equal (mechanism, "passwd1")) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED, "Unsupported setup mechanism: %s", mechanism); goto out; } if (!g_variant_is_of_type (transferred, G_VARIANT_TYPE ("(asas)"))) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Bad data passed for passwd1 mechanism"); goto out; } users = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); if (!fgetpwent_callback (add_name_to_hashtable, users) || !fgetgrent_callback (add_group_to_hashtable, groups)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, _("Couldn't list local users")); goto out; } g_debug ("starting setup synchronization"); g_variant_get (transferred, "(@as@as)", &pwdata, &grdata); chpasswd = g_string_new (""); newusers = g_string_new (""); usermod = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, string_free); lines = g_variant_get_strv (pwdata, &length); for (i = 0; i < length; i++) { parts = g_strsplit(lines[i], ":", 3); user_exists = (g_hash_table_lookup (users, parts[0]) != NULL); if (!user_exists) { g_string_append (newusers, lines[i]); g_string_append_c (newusers, '\n'); } if (user_exists || !cockpit_bridge_have_newusers_crypt_method) { g_string_append_printf (chpasswd, "%s:%s\n", parts[0], parts[1]); } g_strfreev (parts); } g_free (lines); lines = g_variant_get_strv (grdata, &length); for (i = 0; i < length; i++) { parts = g_strsplit(lines[i], ":", 4); if (g_hash_table_lookup (groups, parts[0])) { memlist = g_strsplit (parts[3], ",", -1); for (j = 0; memlist[j] != NULL; j++) { string = g_hash_table_lookup (usermod, memlist[j]); if (!string) { string = g_string_new (""); g_hash_table_insert (usermod, g_strdup (memlist[j]), string); } if (string->len > 0) g_string_append_c (string, ','); g_string_append (string, parts[0]); } g_strfreev (memlist); } g_strfreev (parts); } g_free (lines); context = g_new0 (CommitAdmin1, 1); context->invocation = g_object_ref (invocation); context->chpasswd = g_string_free_to_bytes (chpasswd); context->usermod = usermod; g_debug ("batch creating new users"); bytes = g_string_free_to_bytes (newusers); pipe = cockpit_pipe_spawn (argv, NULL, NULL, COCKPIT_PIPE_FLAGS_NONE); g_signal_connect (pipe, "close", G_CALLBACK (on_newusers_close), context); cockpit_pipe_write (pipe, bytes); cockpit_pipe_close (pipe, NULL); g_bytes_unref (bytes); out: if (users) g_hash_table_unref (users); if (groups) g_hash_table_unref (groups); if (pwdata) g_variant_unref (pwdata); if (grdata) g_variant_unref (grdata); g_variant_unref (transferred); }
static void cockpit_polkit_agent_initiate_authentication (PolkitAgentListener *listener, const gchar *action_id, const gchar *message, const gchar *icon_name, PolkitDetails *details, const gchar *cookie, GList *identities, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { CockpitPolkitAgent *self = COCKPIT_POLKIT_AGENT (listener); PolkitIdentity *identity = NULL; GSimpleAsyncResult *result = NULL; GString *unsupported = NULL; ReauthorizeCaller *caller; gchar *string; uid_t uid; GList *l; const gchar *argv[] = { PACKAGE_LIBEXEC_DIR "/cockpit-polkit", cookie, NULL, }; g_debug ("polkit is requesting authentication"); result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, cockpit_polkit_agent_initiate_authentication); uid = getuid (); unsupported = g_string_new (""); for (l = identities; l != NULL; l = g_list_next (l)) { if (POLKIT_IS_UNIX_USER (l->data)) { if (polkit_unix_user_get_uid (l->data) == uid) { identity = g_object_ref (l->data); break; } } string = polkit_identity_to_string (l->data); g_string_append_printf (unsupported, "%s ", string); g_free (string); } if (!identity) { g_message ("cannot reauthorize identity(s): %s", unsupported->str); g_simple_async_result_set_error (result, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Reauthorization not supported for identity"); g_simple_async_result_complete_in_idle (result); goto out; } string = polkit_identity_to_string (identity); g_message ("Reauthorizing %s", string); g_free (string); caller = g_new0 (ReauthorizeCaller, 1); caller->cookie = g_strdup (cookie); caller->helper = cockpit_pipe_spawn (argv, NULL, NULL, COCKPIT_PIPE_FLAGS_NONE); caller->read_sig = g_signal_connect (caller->helper, "read", G_CALLBACK (on_helper_read), caller); caller->close_sig = g_signal_connect (caller->helper, "close", G_CALLBACK (on_helper_close), caller); caller->cancellable = g_object_ref (cancellable); caller->cancel_sig = g_cancellable_connect (cancellable, G_CALLBACK (on_cancelled), caller, NULL); caller->result = g_object_ref (result); caller->self = self; g_hash_table_replace (self->callers, caller->cookie, caller); g_debug ("cockpit-polkit helper starting"); out: if (unsupported) g_string_free (unsupported, TRUE); g_object_unref (result); if (identity) g_object_unref (identity); }
static GSocketConnectable * parse_address (CockpitChannel *self, gchar **possible_name, gboolean *local_address) { GSocketConnectable *connectable = NULL; const gchar *unix_path; const gchar *internal; const gchar *address; JsonObject *options; gboolean local = FALSE; GError *error = NULL; const gchar *host; gint64 port; gchar *name = NULL; gboolean open = FALSE; options = self->priv->open_options; if (!cockpit_json_get_string (options, "unix", NULL, &unix_path)) { cockpit_channel_fail (self, "protocol-error", "invalid \"unix\" option in channel"); goto out; } if (!cockpit_json_get_int (options, "port", G_MAXINT64, &port)) { cockpit_channel_fail (self, "protocol-error", "invalid \"port\" option in channel"); goto out; } if (!cockpit_json_get_string (options, "internal", NULL, &internal)) { cockpit_channel_fail (self, "protocol-error", "invalid \"internal\" option in channel"); goto out; } if (!cockpit_json_get_string (options, "address", NULL, &address)) { cockpit_channel_fail (self, "protocol-error", "invalid \"address\" option in channel"); goto out; } if (port != G_MAXINT64 && unix_path) { cockpit_channel_fail (self, "protocol-error", "cannot specify both \"port\" and \"unix\" options"); goto out; } else if (port != G_MAXINT64) { if (port <= 0 || port > 65535) { cockpit_channel_fail (self, "protocol-error", "received invalid \"port\" option"); goto out; } if (address) { connectable = g_network_address_new (address, port); host = address; /* This isn't perfect, but matches the use case. Specify address => non-local */ local = FALSE; } else if (cockpit_bridge_local_address) { connectable = g_network_address_parse (cockpit_bridge_local_address, port, &error); host = cockpit_bridge_local_address; local = TRUE; } else { connectable = cockpit_loopback_new (port); host = "localhost"; local = TRUE; } if (error != NULL) { cockpit_channel_fail (self, "internal-error", "couldn't parse local address: %s: %s", host, error->message); goto out; } else { name = g_strdup_printf ("%s:%d", host, (gint)port); } } else if (unix_path) { name = g_strdup (unix_path); connectable = G_SOCKET_CONNECTABLE (g_unix_socket_address_new (unix_path)); local = FALSE; } else if (internal) { gboolean reg = lookup_internal (internal, &connectable); if (!connectable) { if (reg) cockpit_channel_close (self, "not-found"); else cockpit_channel_fail (self, "not-found", "couldn't find internal address: %s", internal); goto out; } name = g_strdup (internal); connectable = g_object_ref (connectable); local = FALSE; } else { cockpit_channel_fail (self, "protocol-error", "no \"port\" or \"unix\" or other address option for channel"); goto out; } open = TRUE; out: g_clear_error (&error); if (open) { if (possible_name) *possible_name = g_strdup (name); if (local_address) *local_address = local; } else { if (connectable) g_object_unref (connectable); connectable = NULL; } g_free (name); return connectable; }
/* Stores information about actually shown component and * returns whether component in the preview changed */ static gboolean update_comp_info (ECalComponentPreview *preview, ECalClient *client, ECalComponent *comp, icaltimezone *zone, gboolean use_24_hour_format) { ECalComponentPreviewPrivate *priv; gboolean changed; g_return_val_if_fail (preview != NULL, TRUE); g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), TRUE); priv = preview->priv; if (!E_IS_CAL_COMPONENT (comp) || !E_IS_CAL_CLIENT (client)) { changed = !priv->cal_uid; clear_comp_info (preview); } else { ESource *source; const gchar *uid; gchar *cal_uid; gchar *comp_uid; struct icaltimetype comp_last_modified, *itm = NULL; gint *sequence = NULL; gint comp_sequence; source = e_client_get_source (E_CLIENT (client)); cal_uid = g_strdup (e_source_get_uid (source)); e_cal_component_get_uid (comp, &uid); comp_uid = g_strdup (uid); e_cal_component_get_last_modified (comp, &itm); if (itm) { comp_last_modified = *itm; e_cal_component_free_icaltimetype (itm); } else comp_last_modified = icaltime_null_time (); e_cal_component_get_sequence (comp, &sequence); if (sequence) { comp_sequence = *sequence; e_cal_component_free_sequence (sequence); } else comp_sequence = 0; changed = !priv->cal_uid || !priv->comp_uid || !cal_uid || !comp_uid || !g_str_equal (priv->cal_uid, cal_uid) || !g_str_equal (priv->comp_uid, comp_uid) || priv->comp_sequence != comp_sequence || icaltime_compare (priv->comp_last_modified, comp_last_modified) != 0; clear_comp_info (preview); priv->cal_uid = cal_uid; priv->comp_uid = comp_uid; priv->comp_sequence = comp_sequence; priv->comp_last_modified = comp_last_modified; priv->comp = g_object_ref (comp); priv->client = g_object_ref (client); priv->timezone = icaltimezone_copy (zone); priv->use_24_hour_format = use_24_hour_format; } return changed; }
static void inf_tcp_connection_io(InfNativeSocket* socket, InfIoEvent events, gpointer user_data) { InfTcpConnection* connection; InfTcpConnectionPrivate* priv; socklen_t len; int errcode; GError* error; connection = INF_TCP_CONNECTION(user_data); priv = INF_TCP_CONNECTION_PRIVATE(connection); g_object_ref(G_OBJECT(connection)); g_assert(priv->status != INF_TCP_CONNECTION_CLOSED); if(events & INF_IO_ERROR) { len = sizeof(int); #ifdef G_OS_WIN32 getsockopt(priv->socket, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len); #else getsockopt(priv->socket, SOL_SOCKET, SO_ERROR, &errcode, &len); #endif /* On Windows, we get INF_IO_ERROR on disconnection (at least with the * InfGtkIo, because FD_CLOSE is mapped to G_IO_HUP) with errcode * being 0. */ /* TODO: Maybe we should change this by mapping G_IO_HUP to * INF_IO_INCOMING, hoping recv() does the right thing then. */ if(errcode != 0) { error = NULL; inf_native_socket_make_error(errcode, &error); if(priv->status == INF_TCP_CONNECTION_CONNECTING) { inf_tcp_connection_connection_error(connection, error); } else { g_signal_emit( G_OBJECT(connection), tcp_connection_signals[ERROR_], 0, error ); } /* Error has been reported via signal emission, and there is nothing * else to do with it. */ g_error_free(error); } else { inf_tcp_connection_close(connection); } } else { if(events & INF_IO_INCOMING) { inf_tcp_connection_io_incoming(connection); } /* It may happen that the above closes the connection and we received * events for both INCOMING & OUTGOING here. */ if((priv->status != INF_TCP_CONNECTION_CLOSED) && (events & INF_IO_OUTGOING)) { inf_tcp_connection_io_outgoing(connection); } } g_object_unref(G_OBJECT(connection)); }
/** * nc_cluster_abundance_ref: * @cad: a #NcClusterAbundance * * Increases the reference count of @cad by one. * * Returns: (transfer full): @cad */ NcClusterAbundance * nc_cluster_abundance_ref (NcClusterAbundance *cad) { return g_object_ref (cad); }
/** * fo_property_keep_together_within_page_init: * @keep_together_within_page: #FoPropertyKeepTogetherWithinPage object to initialise. * * Implements #GInstanceInitFunc for #FoPropertyKeepTogetherWithinPage. **/ void fo_property_keep_together_within_page_init (FoPropertyKeepTogetherWithinPage *keep_together_within_page) { FO_PROPERTY (keep_together_within_page)->value = g_object_ref (fo_enum_factory_get_enum_by_value (FO_ENUM_ENUM_AUTO)); }
/** * fo_property_space_before_precedence_init: * @space_before_precedence: #FoPropertySpaceBeforePrecedence object to initialise. * * Implements #GInstanceInitFunc for #FoPropertySpaceBeforePrecedence. **/ void fo_property_space_before_precedence_init (FoPropertySpaceBeforePrecedence *space_before_precedence) { FO_PROPERTY (space_before_precedence)->value = g_object_ref (fo_integer_get_integer_zero ()); }
static gpointer _g_object_ref0 (gpointer self) { return self ? g_object_ref (self) : NULL; }
static void populate_cache (DzlTaskCache *cache, gconstpointer key, GTask *task, gpointer user_data) { IdeGettextDiagnosticProvider *self = user_data; g_autoptr(IdeUnsavedFile) unsaved_file = NULL; g_autoptr(GSubprocess) subprocess = NULL; GtkSourceLanguage *language; const gchar *language_id; const gchar *xgettext_lang; const gchar *temp_path; TranslationUnit *unit; IdeFile *file = (IdeFile *)key; GCancellable *cancellable; g_autoptr(GError) error = NULL; GPtrArray *args; g_assert (DZL_IS_TASK_CACHE (cache)); g_assert (IDE_IS_FILE (file)); g_assert (IDE_IS_GETTEXT_DIAGNOSTIC_PROVIDER (self)); cancellable = g_task_get_cancellable (task); if (NULL == (unsaved_file = get_unsaved_file (self, file))) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Failed to locate file contents"); return; } if (NULL == (language = ide_file_get_language (file)) || NULL == (language_id = gtk_source_language_get_id (language)) || NULL == (xgettext_lang = id_to_xgettext_language (language_id))) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Failed to determine language type"); return; } if (!ide_unsaved_file_persist (unsaved_file, cancellable, &error)) { g_task_return_error (task, g_steal_pointer (&error)); return; } temp_path = ide_unsaved_file_get_temp_path (unsaved_file); g_assert (temp_path != NULL); args = g_ptr_array_new (); g_ptr_array_add (args, "xgettext"); g_ptr_array_add (args, "--check=ellipsis-unicode"); g_ptr_array_add (args, "--check=quote-unicode"); g_ptr_array_add (args, "--check=space-ellipsis"); g_ptr_array_add (args, "-k_"); g_ptr_array_add (args, "-kN_"); g_ptr_array_add (args, "-L"); g_ptr_array_add (args, (gchar *)xgettext_lang); g_ptr_array_add (args, "-o"); g_ptr_array_add (args, "-"); g_ptr_array_add (args, (gchar *)temp_path); g_ptr_array_add (args, NULL); #ifdef IDE_ENABLE_TRACE { g_autofree gchar *str = NULL; str = g_strjoinv (" ", (gchar **)args->pdata); IDE_TRACE_MSG ("Launching '%s'", str); } #endif subprocess = g_subprocess_newv ((const gchar * const *)args->pdata, G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &error); g_ptr_array_free (args, TRUE); if (subprocess == NULL) { g_task_return_error (task, g_steal_pointer (&error)); return; } unit = g_slice_new0 (TranslationUnit); unit->file = g_object_ref (file); unit->unsaved_file = ide_unsaved_file_ref (unsaved_file); g_task_set_task_data (task, unit, (GDestroyNotify)translation_unit_free); g_subprocess_wait_async (subprocess, cancellable, subprocess_wait_cb, g_object_ref (task)); }
static void visit_directory (GFile *dir, SearchThreadData *data) { GFileEnumerator *enumerator; GFileInfo *info; GFile *child; const char *mime_type, *display_name; char *lower_name, *normalized; gboolean hit; int i; GList *l; const char *id; gboolean visited; enumerator = g_file_enumerate_children (dir, data->mime_types != NULL ? STD_ATTRIBUTES "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE : STD_ATTRIBUTES , 0, data->cancellable, NULL); if (enumerator == NULL) { return; } while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL) { if (g_file_info_get_is_hidden (info)) { goto next; } display_name = g_file_info_get_display_name (info); if (display_name == NULL) { goto next; } normalized = g_utf8_normalize (display_name, -1, G_NORMALIZE_NFD); lower_name = g_utf8_strdown (normalized, -1); g_free (normalized); hit = TRUE; for (i = 0; data->words[i] != NULL; i++) { if (strstr (lower_name, data->words[i]) == NULL) { hit = FALSE; break; } } g_free (lower_name); if (hit && data->mime_types) { mime_type = g_file_info_get_content_type (info); hit = FALSE; for (l = data->mime_types; mime_type != NULL && l != NULL; l = l->next) { if (g_content_type_equals (mime_type, l->data)) { hit = TRUE; break; } } } child = g_file_get_child (dir, g_file_info_get_name (info)); if (hit) { data->uri_hits = g_list_prepend (data->uri_hits, g_file_get_uri (child)); } data->n_processed_files++; if (data->n_processed_files > BATCH_SIZE) { send_batch (data); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE); visited = FALSE; if (id) { if (g_hash_table_lookup_extended (data->visited, id, NULL, NULL)) { visited = TRUE; } else { g_hash_table_insert (data->visited, g_strdup (id), NULL); } } if (!visited) { g_queue_push_tail (data->directories, g_object_ref (child)); } } g_object_unref (child); next: g_object_unref (info); } g_object_unref (enumerator); }
void gvfs_udisks2_utils_spawn (guint timeout_seconds, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, const gchar *command_line_format, ...) { va_list var_args; SpawnData *data; GError *error; gint child_argc; gchar **child_argv = NULL; data = g_slice_new0 (SpawnData); data->simple = g_simple_async_result_new (NULL, callback, user_data, gvfs_udisks2_utils_spawn); data->main_context = g_main_context_get_thread_default (); if (data->main_context != NULL) g_main_context_ref (data->main_context); data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL; va_start (var_args, command_line_format); data->command_line = g_strdup_vprintf (command_line_format, var_args); va_end (var_args); data->child_stdout = g_string_new (NULL); data->child_stderr = g_string_new (NULL); data->child_stdout_fd = -1; data->child_stderr_fd = -1; /* the life-cycle of SpawnData is tied to its GSimpleAsyncResult */ g_simple_async_result_set_op_res_gpointer (data->simple, data, (GDestroyNotify) spawn_data_free); error = NULL; if (data->cancellable != NULL) { /* could already be cancelled */ error = NULL; if (g_cancellable_set_error_if_cancelled (data->cancellable, &error)) { g_simple_async_result_take_error (data->simple, error); g_simple_async_result_complete_in_idle (data->simple); g_object_unref (data->simple); goto out; } data->cancellable_handler_id = g_cancellable_connect (data->cancellable, G_CALLBACK (on_cancelled), data, NULL); } error = NULL; if (!g_shell_parse_argv (data->command_line, &child_argc, &child_argv, &error)) { g_prefix_error (&error, "Error parsing command-line `%s': ", data->command_line); g_simple_async_result_take_error (data->simple, error); g_simple_async_result_complete_in_idle (data->simple); g_object_unref (data->simple); goto out; } error = NULL; if (!g_spawn_async_with_pipes (NULL, /* working directory */ child_argv, NULL, /* envp */ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, /* child_setup */ NULL, /* child_setup's user_data */ &(data->child_pid), NULL, /* gint *stdin_fd */ &(data->child_stdout_fd), &(data->child_stderr_fd), &error)) { g_prefix_error (&error, "Error spawning command-line `%s': ", data->command_line); g_simple_async_result_take_error (data->simple, error); g_simple_async_result_complete_in_idle (data->simple); g_object_unref (data->simple); goto out; } if (timeout_seconds > 0) { data->timeout_source = g_timeout_source_new_seconds (timeout_seconds); g_source_set_priority (data->timeout_source, G_PRIORITY_DEFAULT); g_source_set_callback (data->timeout_source, timeout_cb, data, NULL); g_source_attach (data->timeout_source, data->main_context); g_source_unref (data->timeout_source); } data->child_watch_source = g_child_watch_source_new (data->child_pid); g_source_set_callback (data->child_watch_source, (GSourceFunc) child_watch_cb, data, NULL); g_source_attach (data->child_watch_source, data->main_context); g_source_unref (data->child_watch_source); data->child_stdout_channel = g_io_channel_unix_new (data->child_stdout_fd); g_io_channel_set_flags (data->child_stdout_channel, G_IO_FLAG_NONBLOCK, NULL); data->child_stdout_source = g_io_create_watch (data->child_stdout_channel, G_IO_IN); g_source_set_callback (data->child_stdout_source, (GSourceFunc) read_child_stdout, data, NULL); g_source_attach (data->child_stdout_source, data->main_context); g_source_unref (data->child_stdout_source); data->child_stderr_channel = g_io_channel_unix_new (data->child_stderr_fd); g_io_channel_set_flags (data->child_stderr_channel, G_IO_FLAG_NONBLOCK, NULL); data->child_stderr_source = g_io_create_watch (data->child_stderr_channel, G_IO_IN); g_source_set_callback (data->child_stderr_source, (GSourceFunc) read_child_stderr, data, NULL); g_source_attach (data->child_stderr_source, data->main_context); g_source_unref (data->child_stderr_source); out: g_strfreev (child_argv); }
gboolean nm_device_bt_modem_added (NMDeviceBt *self, NMModem *modem, const char *driver) { NMDeviceBtPrivate *priv; const gchar *modem_data_port; const gchar *modem_control_port; char *base; NMDeviceState state; NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (NM_IS_DEVICE_BT (self), FALSE); g_return_val_if_fail (modem != NULL, FALSE); g_return_val_if_fail (NM_IS_MODEM (modem), FALSE); priv = NM_DEVICE_BT_GET_PRIVATE (self); modem_data_port = nm_modem_get_data_port (modem); modem_control_port = nm_modem_get_control_port (modem); g_return_val_if_fail (modem_data_port != NULL || modem_control_port != NULL, FALSE); if (!priv->rfcomm_iface) return FALSE; base = g_path_get_basename (priv->rfcomm_iface); if (g_strcmp0 (base, modem_data_port) && g_strcmp0 (base, modem_control_port)) { g_free (base); return FALSE; } g_free (base); /* Got the modem */ if (priv->timeout_id) { g_source_remove (priv->timeout_id); priv->timeout_id = 0; } /* Can only accept the modem in stage2, but since the interface matched * what we were expecting, don't let anything else claim the modem either. */ state = nm_device_get_state (NM_DEVICE (self)); if (state != NM_DEVICE_STATE_CONFIG) { nm_log_warn (LOGD_BT | LOGD_MB, "(%s): modem found but device not in correct state (%d)", nm_device_get_iface (NM_DEVICE (self)), nm_device_get_state (NM_DEVICE (self))); return TRUE; } nm_log_info (LOGD_BT | LOGD_MB, "Activation (%s/bluetooth) Stage 2 of 5 (Device Configure) modem found.", nm_device_get_iface (NM_DEVICE (self))); if (priv->modem) { g_warn_if_reached (); g_object_unref (priv->modem); } priv->modem = g_object_ref (modem); g_signal_connect (modem, NM_MODEM_PPP_STATS, G_CALLBACK (ppp_stats), self); g_signal_connect (modem, NM_MODEM_PPP_FAILED, G_CALLBACK (ppp_failed), self); g_signal_connect (modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK (modem_prepare_result), self); g_signal_connect (modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK (modem_ip4_config_result), self); g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self); g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self); /* In the old ModemManager the data port is known from the very beginning; * while in the new ModemManager the data port is set afterwards when the bearer gets * created */ if (modem_data_port) nm_device_set_ip_iface (NM_DEVICE (self), modem_data_port); g_signal_connect (modem, "notify::" NM_MODEM_DATA_PORT, G_CALLBACK (data_port_changed_cb), self); /* Kick off the modem connection */ if (!modem_stage1 (self, modem, &reason)) nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, reason); return TRUE; }
void ags_count_beats_audio_run_set_property(GObject *gobject, guint prop_id, const GValue *value, GParamSpec *param_spec) { AgsCountBeatsAudioRun *count_beats_audio_run; count_beats_audio_run = AGS_COUNT_BEATS_AUDIO_RUN(gobject); switch(prop_id){ case PROP_DELAY_AUDIO_RUN: { AgsDelayAudioRun *delay_audio_run; gboolean is_template; delay_audio_run = (AgsDelayAudioRun *) g_value_get_object(value); if(count_beats_audio_run->delay_audio_run == delay_audio_run) return; if(delay_audio_run != NULL && (AGS_RECALL_TEMPLATE & (AGS_RECALL(delay_audio_run)->flags)) != 0){ is_template = TRUE; }else{ is_template = FALSE; } if(count_beats_audio_run->delay_audio_run != NULL){ if(is_template){ ags_recall_remove_dependency(AGS_RECALL(count_beats_audio_run), (AgsRecall *) count_beats_audio_run->delay_audio_run); }else{ g_signal_handler_disconnect(G_OBJECT(count_beats_audio_run), count_beats_audio_run->sequencer_alloc_output_handler); g_signal_handler_disconnect(G_OBJECT(count_beats_audio_run), count_beats_audio_run->sequencer_count_handler); } g_object_unref(G_OBJECT(count_beats_audio_run->delay_audio_run)); } if(delay_audio_run != NULL){ g_object_ref(G_OBJECT(delay_audio_run)); if(is_template){ ags_recall_add_dependency(AGS_RECALL(count_beats_audio_run), ags_recall_dependency_new((GObject *) delay_audio_run)); }else{ count_beats_audio_run->sequencer_count_handler = g_signal_connect(G_OBJECT(delay_audio_run), "sequencer-alloc-output\0", G_CALLBACK(ags_count_beats_audio_run_sequencer_alloc_output_callback), count_beats_audio_run); count_beats_audio_run->sequencer_count_handler = g_signal_connect(G_OBJECT(delay_audio_run), "sequencer-count\0", G_CALLBACK(ags_count_beats_audio_run_sequencer_count_callback), count_beats_audio_run); count_beats_audio_run->notation_count_handler = g_signal_connect(G_OBJECT(delay_audio_run), "notation-alloc-output\0", G_CALLBACK(ags_count_beats_audio_run_notation_alloc_output_callback), count_beats_audio_run); count_beats_audio_run->notation_count_handler = g_signal_connect(G_OBJECT(delay_audio_run), "notation-count\0", G_CALLBACK(ags_count_beats_audio_run_notation_count_callback), count_beats_audio_run); } } count_beats_audio_run->delay_audio_run = delay_audio_run; } break; case PROP_NOTATION_COUNTER: { guint counter; counter = g_value_get_uint(value); count_beats_audio_run->notation_counter = counter; } break; case PROP_SEQUENCER_COUNTER: { guint counter; counter = g_value_get_uint(value); count_beats_audio_run->sequencer_counter = counter; } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec); break; }; }
/** * matecomponent_control_set_transient_for: * @control: a control with associated control frame * @window: a window upon which to set the transient window. * * Attempts to make the @window transient for the toplevel * of any associated controlframe the MateComponentControl may have. **/ void matecomponent_control_set_transient_for (MateComponentControl *control, GtkWindow *window, CORBA_Environment *opt_ev) { CORBA_char *id; GdkDisplay *display; GdkWindow *win; GdkNativeWindow window_id; CORBA_Environment *ev = NULL, tmp_ev; MateComponent_ControlFrame frame; gpointer local_win; g_return_if_fail (GTK_IS_WINDOW (window)); g_return_if_fail (MATECOMPONENT_IS_CONTROL (control)); /* FIXME: special case the local case ! * we can only do this if set_transient is virtualized * and thus we can catch it in MateComponentSocket and chain up * again if we are embedded inside an embedded thing. */ frame = control->priv->frame; if (frame == CORBA_OBJECT_NIL) return; if (opt_ev) ev = opt_ev; else { CORBA_exception_init (&tmp_ev); ev = &tmp_ev; } id = MateComponent_ControlFrame_getToplevelId (frame, ev); g_return_if_fail (!MATECOMPONENT_EX (ev) && id != NULL); window_id = matecomponent_control_x11_from_window_id (id); #ifdef TRANSIENT_DEBUG g_warning ("Got id '%s' -> %d", id, window_id); #endif CORBA_free (id); display = gtk_widget_get_display (GTK_WIDGET (window)); #if defined (GDK_WINDOWING_X11) local_win = gdk_xid_table_lookup_for_display (display, window_id); #elif defined (GDK_WINDOWING_WIN32) local_win = gdk_win32_handle_table_lookup (window_id); #endif if (local_win == NULL) win = gdk_window_foreign_new_for_display (display, window_id); else { win = GDK_WINDOW (local_win); g_object_ref (win); } g_return_if_fail (win != NULL); window_set_transient_for_gdk (window, win); if (!opt_ev) CORBA_exception_free (&tmp_ev); }
/** * inf_tcp_connection_send: * @connection: A #InfTcpConnection with status %INF_TCP_CONNECTION_CONNECTED. * @data: (type guint8*) (array length=len): The data to send. * @len: Number of bytes to send. * * Sends data through the TCP connection. The data is not sent immediately, * but enqueued to a buffer and will be sent as soon as kernel space * becomes available. The "sent" signal will be emitted when data has * really been sent. **/ void inf_tcp_connection_send(InfTcpConnection* connection, gconstpointer data, guint len) { InfTcpConnectionPrivate* priv; gconstpointer sent_data; guint sent_len; g_return_if_fail(INF_IS_TCP_CONNECTION(connection)); g_return_if_fail(len == 0 || data != NULL); priv = INF_TCP_CONNECTION_PRIVATE(connection); g_return_if_fail(priv->status == INF_TCP_CONNECTION_CONNECTED); g_object_ref(connection); /* Check whether we have data currently queued. If we have, then we need * to wait until that data has been sent before sending the new data. */ if(priv->front_pos == priv->back_pos) { /* Must not be set, because otherwise we would need something to send, * but there is nothing in the queue. */ g_assert(~priv->events & INF_IO_OUTGOING); /* Nothing in queue, send data directly. */ sent_len = len; sent_data = data; if(inf_tcp_connection_send_real(connection, data, &sent_len) == TRUE) { data = (const char*)data + sent_len; len -= sent_len; } else { /* Sending failed. The error signal has been emitted. */ /* Set len to zero so that we don't enqueue data. */ len = 0; sent_len = 0; } } else { /* Nothing sent */ sent_len = 0; } /* If we couldn't send all the data... */ if(len > 0) { /* If we have not enough space for the new data, move queue data back * onto the beginning of the queue, if not already */ if(priv->alloc - priv->front_pos < len && priv->back_pos > 0) { memmove( priv->queue, priv->queue + priv->back_pos, priv->front_pos - priv->back_pos ); priv->front_pos -= priv->back_pos; priv->back_pos = 0; } /* Allocate more memory if there is still not enough space */ if(priv->alloc - priv->front_pos < len) { /* Make sure we allocate enough */ priv->alloc = priv->front_pos + len; /* Always allocate a multiple of 1024 */ if(priv->alloc % 1024 != 0) priv->alloc = priv->alloc + (1024 - priv->alloc % 1024); priv->queue = g_realloc(priv->queue, priv->alloc); } memcpy(priv->queue + priv->front_pos, data, len); priv->front_pos += len; if(~priv->events & INF_IO_OUTGOING) { priv->events |= INF_IO_OUTGOING; inf_io_update_watch(priv->io, priv->watch, priv->events); } } if(sent_len > 0) { g_signal_emit( G_OBJECT(connection), tcp_connection_signals[SENT], 0, sent_data, sent_len ); } g_object_unref(connection); }
static void thunar_folder_finished (ThunarVfsJob *job, ThunarFolder *folder) { ThunarFile *file; GList *files; GList *lp; _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job)); _thunar_return_if_fail (THUNAR_IS_FILE (folder->corresponding_file)); _thunar_return_if_fail (folder->handle == NULL); _thunar_return_if_fail (folder->job == job); /* check if we need to merge new files with existing files */ if (G_UNLIKELY (folder->files != NULL)) { /* determine all added files (files on new_files, but not on files) */ for (files = NULL, lp = folder->new_files; lp != NULL; lp = lp->next) if (g_list_find (folder->files, lp->data) == NULL) { /* put the file on the added list */ files = g_list_prepend (files, lp->data); /* add to the internal files list */ folder->files = g_list_prepend (folder->files, lp->data); g_object_ref (G_OBJECT (lp->data)); } /* check if any files were added */ if (G_UNLIKELY (files != NULL)) { /* emit a "files-added" signal for the added files */ g_signal_emit (G_OBJECT (folder), folder_signals[FILES_ADDED], 0, files); /* release the added files list */ g_list_free (files); } /* determine all removed files (files on files, but not on new_files) */ for (files = NULL, lp = folder->files; lp != NULL; ) { /* determine the file */ file = THUNAR_FILE (lp->data); /* determine the next list item */ lp = lp->next; /* check if the file is not on new_files */ if (g_list_find (folder->new_files, file) == NULL) { /* put the file on the removed list (owns the reference now) */ files = g_list_prepend (files, file); /* remove from the internal files list */ folder->files = g_list_remove (folder->files, file); } } /* check if any files were removed */ if (G_UNLIKELY (files != NULL)) { /* emit a "files-removed" signal for the removed files */ g_signal_emit (G_OBJECT (folder), folder_signals[FILES_REMOVED], 0, files); /* release the removed files list */ thunar_file_list_free (files); } /* drop the temporary new_files list */ thunar_file_list_free (folder->new_files); folder->new_files = NULL; } else { /* just use the new files for the files list */ folder->files = folder->new_files; folder->new_files = NULL; /* emit a "files-added" signal for the new files */ g_signal_emit (G_OBJECT (folder), folder_signals[FILES_ADDED], 0, folder->files); } /* we did it, the folder is loaded */ g_signal_handlers_disconnect_matched (folder->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, folder); g_object_unref (G_OBJECT (folder->job)); folder->job = NULL; /* add us to the file alteration monitor */ folder->handle = thunar_vfs_monitor_add_directory (folder->monitor, thunar_file_get_path (folder->corresponding_file), thunar_folder_monitor, folder); /* tell the consumers that we have loaded the directory */ g_object_notify (G_OBJECT (folder), "loading"); }
char * _gdk_windowing_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; GdkAppLaunchContextPrivate *priv; GdkDisplay *display; GdkScreen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; GIcon *icon; guint32 timestamp; char *startup_id; GFileInfo *fileinfo; priv = GDK_APP_LAUNCH_CONTEXT (context)->priv; if (priv->screen) { screen = priv->screen; display = gdk_screen_get_display (priv->screen); } else if (priv->display) { display = priv->display; screen = gdk_display_get_default_screen (display); } else { display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); } fileinfo = NULL; files_count = g_list_length (files); if (files_count == 0) { description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); } else if (files_count == 1) { gchar *display_name; if (g_file_is_native (files->data)) fileinfo = g_file_query_info (files->data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_ICON, 0, NULL, NULL); display_name = get_display_name (files->data, fileinfo); description = g_strdup_printf (_("Opening %s"), display_name); g_free (display_name); } else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; if (priv->icon_name) icon_name = g_strdup (priv->icon_name); else { icon = NULL; if (priv->icon != NULL) icon = g_object_ref (priv->icon); else if (files_count == 1) icon = get_icon (files->data, fileinfo); if (icon == NULL) { icon = g_app_info_get_icon (info); if (icon != NULL) g_object_ref (icon); } if (icon != NULL) { icon_name = gicon_to_string (icon); g_object_unref (icon); } } binary_name = g_app_info_get_executable (info); timestamp = priv->timestamp; if (timestamp == GDK_CURRENT_TIME) timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen)); if (priv->workspace > -1) workspace_str = g_strdup_printf ("%d", priv->workspace); else workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); if (fileinfo) g_object_unref (fileinfo); add_startup_timeout (screen, startup_id); return startup_id; }