static void channel_ready (GObject *source, GAsyncResult *result, gpointer user_data) { ChVisitor *visitor = (ChVisitor*) user_data; TpChannel *channel; const gchar *ident; TpMessage *message; GError *error = NULL; if (!tp_proxy_prepare_finish (source, result, &error)) { g_printerr ("error loading channel: %s\n", error->message); return; } channel = TP_CHANNEL (source); ident = tp_channel_get_identifier (channel); if (verbose > 0) { g_printerr ("channel ready \"%s\" (type %s)\n", ident, tp_channel_get_channel_type (channel)); } GList *messages, *iter; if (TP_IS_TEXT_CHANNEL (channel)) { messages = tp_text_channel_dup_pending_messages ( TP_TEXT_CHANNEL (channel)); for (iter = messages; iter; iter = iter->next) { TpMessage *message = TP_MESSAGE (iter->data); message_cb (message); } if (acknowledge) { tp_text_channel_ack_messages_async (TP_TEXT_CHANNEL (channel), messages, ack_messages_cb, NULL); } g_list_free_full (messages, g_object_unref); if (send_message && !has_sent_message_to (ident)) { message = tp_client_message_new_text(0, msg_buffer); g_ptr_array_add (messages_sent, g_strdup (ident)); ch_visitor_incref (visitor); tp_text_channel_send_message_async (TP_TEXT_CHANNEL (channel), message, 0, send_message_cb, visitor); } } else { g_printerr ("error loading channel: %s is not a text channel\n", tp_channel_get_identifier (channel)); } ch_visitor_decref (visitor); }
static void apteryx__find (Apteryx__Server_Service *service, const Apteryx__Find *find, Apteryx__SearchResult_Closure closure, void *closure_data) { Apteryx__SearchResult result = APTERYX__SEARCH_RESULT__INIT; GList *possible_matches = NULL; GList *iter = NULL; char *tmp = NULL; char *ptr = NULL; char *chunk; GList *matches = NULL; int i; /* Check parameters */ if (find == NULL || find->n_matches == 0 || find->matches == NULL) { ERROR ("FIND: Invalid parameters.\n"); INC_COUNTER (counters.find_invalid); goto exit; } INC_COUNTER (counters.find); /* Debug */ for (i = 0; apteryx_debug && i < find->n_matches; i++) { DEBUG ("FIND: %s = %s\n", find->matches[i]->path, find->matches[i]->value); } /* Grab first level (from root) */ tmp = g_strdup (find->path); chunk = strtok_r( tmp, "*", &ptr); if (chunk) { possible_matches = search_path (chunk); } /* For each * do a search + add keys, then re-search */ while ((chunk = strtok_r (NULL, "*", &ptr)) != NULL) { GList *last_round = possible_matches; possible_matches = NULL; for (iter = g_list_first (last_round); iter; iter = g_list_next (iter)) { char *next_level = NULL; next_level = g_strdup_printf("%s%s", (char*) iter->data, chunk); possible_matches = g_list_concat (search_path (next_level), possible_matches); g_free (next_level); } g_list_free_full (last_round, g_free); } /* Go through each path match and see if all keys match */ for (iter = g_list_first (possible_matches); iter; iter = g_list_next (iter)) { bool possible_match = true; for (i = 0; i < find->n_matches && possible_match; i++) { char *key = NULL; char *value = NULL; key = g_strdup_printf("%s%s", (char*)iter->data, strrchr (find->matches[i]->path, '*') + 1); value = get_value (key); /* A "" value on a match maps to no return value from provider / database */ if (strlen (find->matches[i]->value) == 0 && value == NULL) { possible_match = true; } else if ((strlen (find->matches[i]->value) == 0 && value != NULL) || (value == NULL && strlen (find->matches[i]->value) > 0)) { /* Match miss - we can stop checking */ possible_match = false; } else if (strcmp (value, find->matches[i]->value) != 0) { /* Match miss - we can stop checking */ possible_match = false; } g_free (key); g_free (value); } /* All keys match, so this is a good path */ if (possible_match) { matches = g_list_prepend (matches, g_strdup ((char*)iter->data)); } } g_list_free_full (possible_matches, g_free); DEBUG ("FIND: matches:\n"); /* Prepare the results */ result.n_paths = g_list_length (matches); if (result.n_paths > 0) { result.paths = (char **) g_malloc (result.n_paths * sizeof (char *)); for (i = 0, iter = g_list_first (matches); iter; iter = g_list_next (iter), i++) { DEBUG (" = %s\n", (char *) iter->data); result.paths[i] = (char *) iter->data; } } else { DEBUG (" NONE\n"); } exit: /* Return result */ closure (&result, closure_data); /* Cleanup */ g_free (tmp); g_list_free_full (matches, g_free); if (result.paths) g_free (result.paths); return; }
/* This function returns true if indexers were called (list may still be NULL) */ static bool index_get (const char *path, GList **result) { GList *indexers = NULL; GList *results = NULL; GList *iter = NULL; /* Retrieve a list of providers for this path */ indexers = cb_match (&index_list, path, CB_MATCH_EXACT|CB_MATCH_WILD|CB_MATCH_CHILD); if (!indexers) { *result = NULL; return false; } /* Find the first good indexer */ for (iter = indexers; iter; iter = g_list_next (iter)) { cb_info_t *indexer = iter->data; ProtobufCService *rpc_client; Apteryx__Index index = APTERYX__INDEX__INIT; search_data_t data = {0}; /* Check for local provider */ if (indexer->id == getpid ()) { apteryx_index_callback cb = (apteryx_index_callback) (long) indexer->cb; DEBUG ("INDEX LOCAL \"%s\" (0x%"PRIx64",0x%"PRIx64")\n", indexer->path, indexer->id, indexer->cb); results = cb (path); break; } DEBUG ("INDEX CB \"%s\" (0x%"PRIx64",0x%"PRIx64")\n", indexer->path, indexer->id, indexer->cb); /* Setup IPC */ rpc_client = rpc_client_connect (rpc, indexer->uri); if (!rpc_client) { /* Throw away the no good validator */ ERROR ("Invalid INDEX CB %s (0x%"PRIx64",0x%"PRIx64")\n", indexer->path, indexer->id, indexer->cb); cb_destroy (indexer); INC_COUNTER (counters.indexed_no_handler); continue; } /* Do remote get */ index.path = (char *) path; index.id = indexer->id; index.cb = indexer->cb; apteryx__client__index (rpc_client, &index, handle_search_response, &data); if (!data.done) { INC_COUNTER (counters.indexed_timeout); ERROR ("No response from indexer for path \"%s\"\n", (char *)path); rpc_client_release (rpc, rpc_client, false); } else { rpc_client_release (rpc, rpc_client, true); } /* Result */ INC_COUNTER (counters.indexed); INC_COUNTER (indexer->count); if (data.paths) { results = data.paths; break; } } g_list_free_full (indexers, (GDestroyNotify) cb_release); *result = results; return true; }
void on_trkproperties_edit_activate (GtkMenuItem *menuitem, gpointer user_data) { if (numtracks != 1) { return; // TODO: multiple track editing support } GtkTreeView *treeview = GTK_TREE_VIEW (lookup_widget (trackproperties, "metalist")); GtkTreeSelection *sel = gtk_tree_view_get_selection (treeview); int count = gtk_tree_selection_count_selected_rows (sel); if (count != 1) { return; // multiple fields can't be edited at the same time } GtkWidget *dlg = create_edit_tag_value_dlg (); gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (trackproperties)); gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK); GList *lst = gtk_tree_selection_get_selected_rows (sel, NULL); GtkTreePath *path = lst->data; GtkTreeIter iter; gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); GValue key = {0,}; gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 2, &key); GValue value = {0,}; gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 4, &value); const char *skey = g_value_get_string (&key); const char *svalue = g_value_get_string (&value); char *uppercase_key = strdup (skey); for (char *p = uppercase_key; *p; p++) { *p = toupper (*p); } gtk_entry_set_text (GTK_ENTRY (lookup_widget (dlg, "field_name")), uppercase_key); free (uppercase_key); GtkTextBuffer *buffer = gtk_text_buffer_new (NULL); gtk_text_buffer_set_text (buffer, svalue, strlen (svalue)); gtk_text_view_set_buffer (GTK_TEXT_VIEW (lookup_widget (dlg, "field_value")), buffer); g_value_unset (&key); g_value_unset (&value); g_list_free_full (lst, (GDestroyNotify) gtk_tree_path_free); int response = gtk_dialog_run (GTK_DIALOG (dlg)); if (response == GTK_RESPONSE_OK) { GtkTextIter begin, end; gtk_text_buffer_get_start_iter (buffer, &begin); gtk_text_buffer_get_end_iter (buffer, &end); char *new_text = gtk_text_buffer_get_text (buffer, &begin, &end, TRUE); update_meta_iter_with_edited_value (&iter, new_text); free (new_text); trkproperties_modified = 1; } g_object_unref (buffer); gtk_widget_destroy (dlg); }
void nautilus_launch_application_by_uri (GAppInfo *application, GList *uris, GtkWindow *parent_window) { char *uri; GList *locations, *l; GFile *location; NautilusFile *file; gboolean result; GError *error; GdkDisplay *display; GdkAppLaunchContext *launch_context; NautilusIconInfo *icon; int count, total; g_assert (uris != NULL); /* count the number of uris with local paths */ count = 0; total = g_list_length (uris); locations = NULL; for (l = uris; l != NULL; l = l->next) { uri = l->data; location = g_file_new_for_uri (uri); if (g_file_is_native (location)) { count++; } locations = g_list_prepend (locations, location); } locations = g_list_reverse (locations); if (parent_window != NULL) { display = gtk_widget_get_display (GTK_WIDGET (parent_window)); } else { display = gdk_display_get_default (); } launch_context = gdk_display_get_app_launch_context (display); if (parent_window != NULL) { gdk_app_launch_context_set_screen (launch_context, gtk_window_get_screen (parent_window)); } file = nautilus_file_get_by_uri (uris->data); icon = nautilus_file_get_icon (file, 48, 0); nautilus_file_unref (file); if (icon) { gdk_app_launch_context_set_icon_name (launch_context, nautilus_icon_info_get_used_name (icon)); g_object_unref (icon); } error = NULL; if (count == total) { /* All files are local, so we can use g_app_info_launch () with * the file list we constructed before. */ result = g_app_info_launch (application, locations, G_APP_LAUNCH_CONTEXT (launch_context), &error); } else { /* Some files are non local, better use g_app_info_launch_uris (). */ result = g_app_info_launch_uris (application, uris, G_APP_LAUNCH_CONTEXT (launch_context), &error); } g_object_unref (launch_context); if (result) { for (l = uris; l != NULL; l = l->next) { file = nautilus_file_get_by_uri (l->data); nautilus_recent_add_file (file, application); nautilus_file_unref (file); } } g_list_free_full (locations, g_object_unref); }
END_TEST START_TEST (test_metadata_database) { GSignondConfig *config = NULL; guint32 methodid = 0; guint32 identity_id = 5; const gchar *method1 = "method1"; GSignondIdentityInfo *identity = NULL, *identity2= NULL; GSignondIdentityInfoList *identities = NULL; GSignondSecurityContext *ctx1 = NULL; GList *methods = NULL, *reflist = NULL; GSignondSecurityContextList *acl; GSignondSecurityContext *owner = NULL; config = gsignond_config_new (); gsignond_config_set_string (config, GSIGNOND_CONFIG_GENERAL_SECURE_DIR, "/tmp/gsignond"); GSignondDbMetadataDatabase* metadata_db = NULL; metadata_db = gsignond_db_metadata_database_new (config); g_object_unref(config); fail_if (metadata_db == NULL); ctx1 = gsignond_security_context_new_from_values ("sysctx1", "appctx1"); identity = _get_filled_identity_info_2 (&identity, FALSE, FALSE, FALSE, FALSE, FALSE); fail_unless (gsignond_db_metadata_database_insert_method ( metadata_db, method1, &methodid) == FALSE); fail_unless (gsignond_db_metadata_database_get_method_id ( metadata_db, method1) == 0); fail_unless (gsignond_db_metadata_database_get_methods ( metadata_db, identity_id, ctx1) == NULL); fail_unless (gsignond_db_metadata_database_get_methods ( metadata_db, identity_id, ctx1) == NULL); fail_unless (gsignond_db_metadata_database_update_identity ( metadata_db, identity) == FALSE); fail_unless (gsignond_db_metadata_database_get_identity ( metadata_db, identity_id) == NULL); fail_unless (gsignond_db_metadata_database_get_identities ( metadata_db, NULL) == NULL); fail_unless (gsignond_db_metadata_database_remove_identity ( metadata_db, identity_id) == FALSE); fail_unless (gsignond_db_metadata_database_remove_reference ( metadata_db, identity_id, ctx1, "reference1") == FALSE); fail_unless (gsignond_db_metadata_database_get_references ( metadata_db, identity_id, ctx1) == NULL); fail_unless (gsignond_db_metadata_database_get_accesscontrol_list ( metadata_db, identity_id) == NULL); fail_unless (gsignond_db_metadata_database_get_owner ( metadata_db, identity_id) == NULL); fail_unless (gsignond_db_metadata_database_open (metadata_db) == TRUE); fail_unless (gsignond_db_metadata_database_open (metadata_db) == TRUE); fail_unless (gsignond_db_sql_database_clear ( GSIGNOND_DB_SQL_DATABASE (metadata_db)) == TRUE); fail_unless (gsignond_db_metadata_database_get_accesscontrol_list ( metadata_db, identity_id) == NULL); fail_unless (gsignond_db_metadata_database_get_owner ( metadata_db, identity_id) == NULL); fail_unless (gsignond_db_metadata_database_get_method_id ( metadata_db, method1) == 0); fail_unless (gsignond_db_metadata_database_insert_method ( metadata_db, method1, &methodid) == TRUE); fail_unless (methodid == gsignond_db_metadata_database_get_method_id ( metadata_db, method1)); /*update_identity*/ identity = _get_filled_identity_info_2 (&identity, TRUE, FALSE, FALSE, FALSE, FALSE); fail_unless (gsignond_db_metadata_database_update_identity ( metadata_db, identity) == 0); identity = _get_filled_identity_info_2 (&identity, FALSE, TRUE, FALSE, FALSE, FALSE); fail_unless (gsignond_db_metadata_database_update_identity ( metadata_db, identity) == 0); identity = _get_filled_identity_info_2 (&identity, FALSE, FALSE, TRUE, FALSE, FALSE); fail_unless (gsignond_db_metadata_database_update_identity ( metadata_db, identity) == 0); identity = _get_filled_identity_info_2 (&identity, FALSE, FALSE, FALSE, TRUE, FALSE); fail_unless (gsignond_db_metadata_database_update_identity ( metadata_db, identity) == 0); identity = _get_filled_identity_info_2 (&identity, FALSE, FALSE, FALSE, FALSE, TRUE); identity_id = gsignond_db_metadata_database_update_identity ( metadata_db, identity); fail_unless (identity_id != 0); gsignond_identity_info_set_id (identity, identity_id); identity2 = gsignond_db_metadata_database_get_identity ( metadata_db, identity_id); fail_if (identity2 == NULL); gsignond_identity_info_unref (identity2); /*get_identity/identities*/ fail_unless (gsignond_db_metadata_database_get_identity ( metadata_db, 2222) == NULL); identities = gsignond_db_metadata_database_get_identities (metadata_db, NULL); fail_unless (identities != NULL); fail_unless (g_list_length (identities) == 1); gsignond_identity_info_list_free (identities); /*methods*/ methods = gsignond_db_metadata_database_get_methods (metadata_db, identity_id, ctx1); fail_if (methods == NULL); g_list_free_full (methods, g_free); /*references*/ fail_unless (gsignond_db_metadata_database_get_references ( metadata_db, identity_id, ctx1) == NULL); fail_unless (gsignond_db_metadata_database_remove_reference ( metadata_db, identity_id, ctx1, "reference1" ) == FALSE); fail_unless (gsignond_db_metadata_database_insert_reference ( metadata_db, identity_id, ctx1, "reference1") == TRUE); fail_unless (gsignond_db_metadata_database_insert_reference ( metadata_db, identity_id, ctx1, "reference1") == TRUE); reflist = gsignond_db_metadata_database_get_references ( metadata_db, identity_id, ctx1); fail_if (reflist == NULL); fail_unless (g_list_length (reflist) == 1); g_list_free_full (reflist, g_free); fail_unless (gsignond_db_metadata_database_remove_reference ( metadata_db, identity_id, ctx1, "reference1" ) == TRUE); gsignond_security_context_free (ctx1); /*acl*/ acl = gsignond_db_metadata_database_get_accesscontrol_list (metadata_db, identity_id); fail_if (acl == NULL); gsignond_security_context_list_free (acl); /*owner*/ owner = gsignond_db_metadata_database_get_owner (metadata_db, identity_id); fail_if (owner == NULL); fail_unless (gsignond_db_metadata_database_remove_identity ( metadata_db, identity_id) == TRUE); fail_unless (gsignond_db_metadata_database_get_identities ( metadata_db, NULL) == NULL); fail_unless (gsignond_db_metadata_database_get_methods ( metadata_db, identity_id, owner) == NULL); gsignond_security_context_free (owner); gsignond_identity_info_unref (identity); fail_unless (gsignond_db_sql_database_close ( GSIGNOND_DB_SQL_DATABASE (metadata_db)) == TRUE); g_object_unref(metadata_db); }
static void update(dt_lib_module_t *user_data, gboolean early_bark_out) { // early_bark_out = FALSE; // FIXME: when barking out early we don't update on ctrl-a/ctrl-shift-a. but // otherwise it's impossible to edit text const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_metadata_t *d = (dt_lib_metadata_t *)self->data; const int imgsel = dt_control_get_mouse_over_id(); if(early_bark_out && imgsel == d->imgsel) return; d->imgsel = imgsel; sqlite3_stmt *stmt; GList *title = NULL; uint32_t title_count = 0; GList *description = NULL; uint32_t description_count = 0; GList *creator = NULL; uint32_t creator_count = 0; GList *publisher = NULL; uint32_t publisher_count = 0; GList *rights = NULL; uint32_t rights_count = 0; // using dt_metadata_get() is not possible here. we want to do all this in a single pass, everything else // takes ages. if(imgsel < 0) // selected images { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT key, value FROM main.meta_data WHERE id IN " "(SELECT imgid FROM main.selected_images) GROUP BY " "key, value ORDER BY value", -1, &stmt, NULL); } else // single image under mouse cursor { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT key, value FROM main.meta_data " "WHERE id = ?1 GROUP BY key, value ORDER BY value", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgsel); } while(sqlite3_step(stmt) == SQLITE_ROW) { if(sqlite3_column_bytes(stmt, 1)) { char *value = g_strdup((char *)sqlite3_column_text(stmt, 1)); switch(sqlite3_column_int(stmt, 0)) { case DT_METADATA_XMP_DC_CREATOR: creator_count++; creator = g_list_append(creator, value); break; case DT_METADATA_XMP_DC_PUBLISHER: publisher_count++; publisher = g_list_append(publisher, value); break; case DT_METADATA_XMP_DC_TITLE: title_count++; title = g_list_append(title, value); break; case DT_METADATA_XMP_DC_DESCRIPTION: description_count++; description = g_list_append(description, value); break; case DT_METADATA_XMP_DC_RIGHTS: rights_count++; rights = g_list_append(rights, value); break; } } } sqlite3_finalize(stmt); fill_combo_box_entry(d->title, title_count, title, &(d->multi_title)); fill_combo_box_entry(d->description, description_count, description, &(d->multi_description)); fill_combo_box_entry(d->rights, rights_count, rights, &(d->multi_rights)); fill_combo_box_entry(d->creator, creator_count, creator, &(d->multi_creator)); fill_combo_box_entry(d->publisher, publisher_count, publisher, &(d->multi_publisher)); g_list_free_full(title, g_free); g_list_free_full(description, g_free); g_list_free_full(creator, g_free); g_list_free_full(publisher, g_free); g_list_free_full(rights, g_free); }
/* update all values to reflect mouse over image id or no data at all */ static void _metadata_view_update_values(dt_lib_module_t *self) { dt_lib_metadata_view_t *d = (dt_lib_metadata_view_t *)self->data; int32_t mouse_over_id = dt_control_get_mouse_over_id(); if (mouse_over_id == -1) { const dt_view_t *cv = dt_view_manager_get_current_view(darktable.view_manager); if(cv->view((dt_view_t*)cv) == DT_VIEW_DARKROOM) { mouse_over_id = darktable.develop->image_storage.id; } else { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select imgid from selected_images limit 1", -1, &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) mouse_over_id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); } } if(mouse_over_id >= 0) { char value[512]; char pathname[PATH_MAX]; const dt_image_t *img = dt_image_cache_read_get(darktable.image_cache, mouse_over_id); if(!img) goto fill_minuses; if(img->film_id == -1) { dt_image_cache_read_release(darktable.image_cache, img); goto fill_minuses; } /* update all metadata */ dt_image_film_roll(img, value, sizeof(value)); _metadata_update_value(d->metadata[md_internal_filmroll], value); const int tp = 512; char tooltip[tp]; snprintf(tooltip, tp, _("double click to jump to film roll\n%s"), value); g_object_set(G_OBJECT(d->metadata[md_internal_filmroll]), "tooltip-text", tooltip, (char *)NULL); snprintf(value,sizeof(value),"%d", img->id); _metadata_update_value(d->metadata[md_internal_imgid], value); _metadata_update_value(d->metadata[md_internal_filename], img->filename); snprintf(value,sizeof(value),"%d", img->version); _metadata_update_value(d->metadata[md_internal_version], value); gboolean from_cache = FALSE; dt_image_full_path(img->id, pathname, sizeof(pathname), &from_cache); _metadata_update_value(d->metadata[md_internal_fullpath], pathname); snprintf(value, sizeof(value), "%s", (img->flags & DT_IMAGE_LOCAL_COPY)?_("yes"):_("no")); _metadata_update_value(d->metadata[md_internal_local_copy], value); /* EXIF */ _metadata_update_value_end(d->metadata[md_exif_model], img->exif_model); _metadata_update_value_end(d->metadata[md_exif_lens], img->exif_lens); _metadata_update_value_end(d->metadata[md_exif_maker], img->exif_maker); snprintf(value, sizeof(value), "F/%.1f", img->exif_aperture); _metadata_update_value(d->metadata[md_exif_aperture], value); if(img->exif_exposure <= 0.5) snprintf(value, sizeof(value), "1/%.0f", 1.0/img->exif_exposure); else snprintf(value, sizeof(value), "%.1f''", img->exif_exposure); _metadata_update_value(d->metadata[md_exif_exposure], value); snprintf(value, sizeof(value), "%.0f mm", img->exif_focal_length); _metadata_update_value(d->metadata[md_exif_focal_length], value); if (isnan(img->exif_focus_distance) || fpclassify(img->exif_focus_distance) == FP_ZERO) { _metadata_update_value(d->metadata[md_exif_focus_distance], NODATA_STRING); } else { snprintf(value, sizeof(value), "%.2f m", img->exif_focus_distance); _metadata_update_value(d->metadata[md_exif_focus_distance], value); } snprintf(value, sizeof(value), "%.0f", img->exif_iso); _metadata_update_value(d->metadata[md_exif_iso], value); _metadata_update_value(d->metadata[md_exif_datetime], img->exif_datetime_taken); snprintf(value, sizeof(value), "%d", img->height); _metadata_update_value(d->metadata[md_exif_height], value); snprintf(value, sizeof(value), "%d", img->width); _metadata_update_value(d->metadata[md_exif_width], value); /* XMP */ GList *res; if((res = dt_metadata_get(img->id, "Xmp.dc.title", NULL))!=NULL) { snprintf(value, sizeof(value), "%s", (char*)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_title], value); if((res = dt_metadata_get(img->id, "Xmp.dc.creator", NULL))!=NULL) { snprintf(value, sizeof(value), "%s", (char*)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_creator], value); if((res = dt_metadata_get(img->id, "Xmp.dc.rights", NULL))!=NULL) { snprintf(value, sizeof(value), "%s", (char*)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_rights], value); /* geotagging */ /* latitude */ if(isnan(img->latitude)) { _metadata_update_value(d->metadata[md_geotagging_lat], NODATA_STRING); } else { #ifdef HAVE_MAP if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *latitude = osd_latitude_str(img->latitude); _metadata_update_value(d->metadata[md_geotagging_lat], latitude); g_free(latitude); } else { #endif gchar NS = img->latitude<0?'S':'N'; snprintf(value, sizeof(value), "%c %09.6f", NS, fabs(img->latitude)); _metadata_update_value(d->metadata[md_geotagging_lat], value); #ifdef HAVE_MAP } #endif } /* longitude */ if(isnan(img->longitude)) { _metadata_update_value(d->metadata[md_geotagging_lon], NODATA_STRING); } else { #ifdef HAVE_MAP if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *longitude = osd_longitude_str(img->longitude); _metadata_update_value(d->metadata[md_geotagging_lon], longitude); g_free(longitude); } else { #endif gchar EW = img->longitude<0?'W':'E'; snprintf(value, sizeof(value), "%c %010.6f", EW, fabs(img->longitude)); _metadata_update_value(d->metadata[md_geotagging_lon], value); #ifdef HAVE_MAP } #endif } /* release img */ dt_image_cache_read_release(darktable.image_cache, img); } return; /* reset */ fill_minuses: for(int k=0; k<md_size; k++) _metadata_update_value(d->metadata[k],NODATA_STRING); }
static void nautilus_window_slot_dispose (GObject *object) { NautilusWindowSlot *slot; GtkWidget *widget; slot = NAUTILUS_WINDOW_SLOT (object); nautilus_window_slot_clear_forward_list (slot); nautilus_window_slot_clear_back_list (slot); if (slot->content_view) { widget = GTK_WIDGET (slot->content_view); gtk_widget_destroy (widget); g_object_unref (slot->content_view); slot->content_view = NULL; } if (slot->new_content_view) { widget = GTK_WIDGET (slot->new_content_view); gtk_widget_destroy (widget); g_object_unref (slot->new_content_view); slot->new_content_view = NULL; } if (slot->set_status_timeout_id != 0) { g_source_remove (slot->set_status_timeout_id); slot->set_status_timeout_id = 0; } if (slot->loading_timeout_id != 0) { g_source_remove (slot->loading_timeout_id); slot->loading_timeout_id = 0; } nautilus_window_slot_set_viewed_file (slot, NULL); /* TODO? why do we unref here? the file is NULL. * It was already here before the slot move, though */ nautilus_file_unref (slot->viewed_file); if (slot->location) { /* TODO? why do we ref here, instead of unreffing? * It was already here before the slot migration, though */ g_object_ref (slot->location); } g_list_free_full (slot->pending_selection, g_object_unref); slot->pending_selection = NULL; g_clear_object (&slot->current_location_bookmark); g_clear_object (&slot->last_location_bookmark); if (slot->find_mount_cancellable != NULL) { g_cancellable_cancel (slot->find_mount_cancellable); slot->find_mount_cancellable = NULL; } slot->details->pane = NULL; g_free (slot->title); slot->title = NULL; G_OBJECT_CLASS (nautilus_window_slot_parent_class)->dispose (object); }
gboolean flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) var_deploy_base = NULL; g_autoptr(GFile) var_deploy_files = NULL; g_autoptr(GFile) base = NULL; g_autoptr(GFile) files_dir = NULL; g_autoptr(GFile) usr_dir = NULL; g_autoptr(GFile) var_dir = NULL; g_autoptr(GFile) var_tmp_dir = NULL; g_autoptr(GFile) var_run_dir = NULL; g_autoptr(GFile) metadata_file = NULL; g_autoptr(GString) metadata_contents = NULL; const char *app_id; const char *directory; const char *sdk; const char *runtime; const char *branch = "master"; g_autofree char *runtime_ref = NULL; g_autofree char *var_ref = NULL; g_autofree char *sdk_ref = NULL; int i; context = g_option_context_new ("DIRECTORY APPNAME SDK RUNTIME [BRANCH] - Initialize a directory for building"); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 5) return usage_error (context, "RUNTIME must be specified", error); directory = argv[1]; app_id = argv[2]; sdk = argv[3]; runtime = argv[4]; if (argc >= 6) branch = argv[5]; if (!flatpak_is_valid_name (app_id)) return flatpak_fail (error, "'%s' is not a valid application name", app_id); if (!flatpak_is_valid_name (runtime)) return flatpak_fail (error, "'%s' is not a valid runtime name", runtime); if (!flatpak_is_valid_name (sdk)) return flatpak_fail (error, "'%s' is not a valid sdk name", sdk); if (!flatpak_is_valid_branch (branch)) return flatpak_fail (error, "'%s' is not a valid branch name", branch); runtime_ref = flatpak_build_untyped_ref (runtime, branch, opt_arch); sdk_ref = flatpak_build_untyped_ref (sdk, branch, opt_arch); base = g_file_new_for_commandline_arg (directory); if (!gs_file_ensure_directory (base, TRUE, cancellable, error)) return FALSE; files_dir = g_file_get_child (base, "files"); if (opt_sdk_dir) usr_dir = g_file_get_child (base, opt_sdk_dir); else usr_dir = g_file_get_child (base, "usr"); var_dir = g_file_get_child (base, "var"); var_tmp_dir = g_file_get_child (var_dir, "tmp"); var_run_dir = g_file_get_child (var_dir, "run"); metadata_file = g_file_get_child (base, "metadata"); if (!opt_update && g_file_query_exists (files_dir, cancellable)) return flatpak_fail (error, "Build directory %s already initialized", directory); if (opt_writable_sdk) { g_autofree char *full_sdk_ref = g_strconcat ("runtime/", sdk_ref, NULL); g_autoptr(GError) my_error = NULL; g_autoptr(GFile) sdk_deploy_files = NULL; g_autoptr(FlatpakDeploy) sdk_deploy = NULL; sdk_deploy = flatpak_find_deploy_for_ref (full_sdk_ref, cancellable, error); if (sdk_deploy == NULL) return FALSE; if (!gs_shutil_rm_rf (usr_dir, NULL, &my_error)) { if (!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_propagate_error (error, g_steal_pointer (&my_error)); return FALSE; } g_clear_error (&my_error); } sdk_deploy_files = flatpak_deploy_get_files (sdk_deploy); if (!flatpak_cp_a (sdk_deploy_files, usr_dir, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; if (opt_sdk_extensions) { g_autoptr(GKeyFile) metakey = flatpak_deploy_get_metadata (sdk_deploy); GList *extensions = NULL, *l; /* We leak this on failure, as we have no autoptr for deep lists.. */ extensions = flatpak_list_extensions (metakey, opt_arch, branch); for (i = 0; opt_sdk_extensions[i] != NULL; i++) { const char *requested_extension = opt_sdk_extensions[i]; gboolean found = FALSE; for (l = extensions; l != NULL; l = l->next) { FlatpakExtension *ext = l->data; if (strcmp (ext->installed_id, requested_extension) == 0 || strcmp (ext->id, requested_extension) == 0) { g_autoptr(GFile) ext_deploy_dir = flatpak_find_deploy_dir_for_ref (ext->ref, cancellable, NULL); if (ext_deploy_dir != NULL) { g_autoptr(GFile) ext_deploy_files = g_file_get_child (ext_deploy_dir, "files"); g_autoptr(GFile) target = g_file_resolve_relative_path (usr_dir, ext->directory); g_autoptr(GFile) target_parent = g_file_get_parent (target); if (!gs_file_ensure_directory (target_parent, TRUE, cancellable, error)) return FALSE; /* An extension overrides whatever is there before, so we clean up first */ if (!gs_shutil_rm_rf (target, cancellable, error)) return FALSE; if (!flatpak_cp_a (ext_deploy_files, target, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; found = TRUE; } else { g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free); return flatpak_fail (error, "Requested extension %s not installed\n", requested_extension); } } } if (!found) return flatpak_fail (error, "No extension %s in sdk\n", requested_extension); } g_list_free_full (extensions, (GDestroyNotify) flatpak_extension_free); } } if (opt_var) { var_ref = flatpak_build_runtime_ref (opt_var, branch, opt_arch); var_deploy_base = flatpak_find_deploy_dir_for_ref (var_ref, cancellable, error); if (var_deploy_base == NULL) return FALSE; var_deploy_files = g_file_get_child (var_deploy_base, "files"); } if (opt_update) return TRUE; if (!g_file_make_directory (files_dir, cancellable, error)) return FALSE; if (var_deploy_files) { if (!gs_shutil_cp_a (var_deploy_files, var_dir, cancellable, error)) return FALSE; } else { if (!g_file_make_directory (var_dir, cancellable, error)) return FALSE; } if (!gs_file_ensure_directory (var_tmp_dir, FALSE, cancellable, error)) return FALSE; if (!g_file_query_exists (var_run_dir, cancellable) && !g_file_make_symbolic_link (var_run_dir, "/run", cancellable, error)) return FALSE; metadata_contents = g_string_new ("[Application]\n"); g_string_append_printf (metadata_contents, "name=%s\n" "runtime=%s\n" "sdk=%s\n", app_id, runtime_ref, sdk_ref); if (opt_tags != NULL) { g_string_append (metadata_contents, "tags="); for (i = 0; opt_tags[i] != NULL; i++) { g_string_append (metadata_contents, opt_tags[i]); g_string_append_c (metadata_contents, ';'); } g_string_append_c (metadata_contents, '\n'); } if (!g_file_replace_contents (metadata_file, metadata_contents->str, metadata_contents->len, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error)) return FALSE; return TRUE; }
static void athena_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value) { AthenaListModel *model; FileEntry *file_entry; AthenaFile *file; char *str; GdkPixbuf *icon, *rendered_icon; GIcon *gicon, *emblemed_icon, *emblem_icon; AthenaIconInfo *icon_info; GEmblem *emblem; GList *emblem_icons, *l; int icon_size; AthenaZoomLevel zoom_level; AthenaFile *parent_file; char *emblems_to_ignore[3]; int i; AthenaFileIconFlags flags; model = (AthenaListModel *)tree_model; g_return_if_fail (model->details->stamp == iter->stamp); g_return_if_fail (!g_sequence_iter_is_end (iter->user_data)); file_entry = g_sequence_get (iter->user_data); file = file_entry->file; switch (column) { case ATHENA_LIST_MODEL_FILE_COLUMN: g_value_init (value, ATHENA_TYPE_FILE); g_value_set_object (value, file); break; case ATHENA_LIST_MODEL_SUBDIRECTORY_COLUMN: g_value_init (value, ATHENA_TYPE_DIRECTORY); g_value_set_object (value, file_entry->subdirectory); break; case ATHENA_LIST_MODEL_SMALLEST_ICON_COLUMN: case ATHENA_LIST_MODEL_SMALLER_ICON_COLUMN: case ATHENA_LIST_MODEL_SMALL_ICON_COLUMN: case ATHENA_LIST_MODEL_STANDARD_ICON_COLUMN: case ATHENA_LIST_MODEL_LARGE_ICON_COLUMN: case ATHENA_LIST_MODEL_LARGER_ICON_COLUMN: case ATHENA_LIST_MODEL_LARGEST_ICON_COLUMN: g_value_init (value, GDK_TYPE_PIXBUF); if (file != NULL) { zoom_level = athena_list_model_get_zoom_level_from_column_id (column); icon_size = athena_get_icon_size_for_zoom_level (zoom_level); flags = ATHENA_FILE_ICON_FLAGS_USE_THUMBNAILS | ATHENA_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE | ATHENA_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM; if (model->details->drag_view != NULL) { GtkTreePath *path_a, *path_b; gtk_tree_view_get_drag_dest_row (model->details->drag_view, &path_a, NULL); if (path_a != NULL) { path_b = gtk_tree_model_get_path (tree_model, iter); if (gtk_tree_path_compare (path_a, path_b) == 0) { flags |= ATHENA_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT; } gtk_tree_path_free (path_a); gtk_tree_path_free (path_b); } } gicon = G_ICON (athena_file_get_icon_pixbuf (file, icon_size, TRUE, flags)); /* render emblems with GEmblemedIcon */ parent_file = athena_file_get_parent (file); i = 0; emblems_to_ignore[i++] = ATHENA_FILE_EMBLEM_NAME_TRASH; if (parent_file) { if (!athena_file_can_write (parent_file)) { emblems_to_ignore[i++] = ATHENA_FILE_EMBLEM_NAME_CANT_WRITE; } athena_file_unref (parent_file); } emblems_to_ignore[i++] = NULL; emblem_icons = athena_file_get_emblem_icons (file, emblems_to_ignore); /* pick only the first emblem we can render for the list view */ for (l = emblem_icons; l != NULL; l = l->next) { emblem_icon = l->data; if (athena_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) { emblem = g_emblem_new (emblem_icon); emblemed_icon = g_emblemed_icon_new (gicon, emblem); g_object_unref (gicon); g_object_unref (emblem); gicon = emblemed_icon; break; } } g_list_free_full (emblem_icons, g_object_unref); icon_info = athena_icon_info_lookup (gicon, icon_size); icon = athena_icon_info_get_pixbuf_at_size (icon_info, icon_size); g_object_unref (icon_info); g_object_unref (gicon); if (model->details->highlight_files != NULL && g_list_find_custom (model->details->highlight_files, file, (GCompareFunc) athena_file_compare_location)) { rendered_icon = eel_create_spotlight_pixbuf (icon); if (rendered_icon != NULL) { g_object_unref (icon); icon = rendered_icon; } } g_value_set_object (value, icon); g_object_unref (icon); } break; case ATHENA_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN: g_value_init (value, G_TYPE_BOOLEAN); g_value_set_boolean (value, file != NULL && athena_file_can_rename (file)); break; default: if (column >= ATHENA_LIST_MODEL_NUM_COLUMNS || column < ATHENA_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) { AthenaColumn *athena_column; GQuark attribute; athena_column = model->details->columns->pdata[column - ATHENA_LIST_MODEL_NUM_COLUMNS]; g_value_init (value, G_TYPE_STRING); g_object_get (athena_column, "attribute_q", &attribute, NULL); if (file != NULL) { str = athena_file_get_string_attribute_with_default_q (file, attribute); g_value_take_string (value, str); } else if (attribute == attribute_name_q) { if (file_entry->parent->loaded) { g_value_set_string (value, _("(Empty)")); } else { g_value_set_string (value, _("Loading...")); } } } else { g_assert_not_reached (); } } }
/** * asb_task_process: * @task: A #AsbTask * @error_not_used: A #GError or %NULL * * Processes the task. * * Returns: %TRUE for success, %FALSE otherwise * * Since: 0.1.0 **/ gboolean asb_task_process (AsbTask *task, GError **error_not_used) { AsRelease *release; AsbApp *app; AsbPlugin *plugin = NULL; AsbTaskPrivate *priv = GET_PRIVATE (task); GList *apps = NULL; GList *l; GPtrArray *array; gboolean ret; gchar *cache_id; guint i; guint nr_added = 0; g_autoptr(GError) error = NULL; g_autofree gchar *basename = NULL; /* reset the profile timer */ asb_package_log_start (priv->pkg); /* ensure nevra read */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_NEVRA, error_not_used)) return FALSE; g_debug ("starting: %s", asb_package_get_name (priv->pkg)); /* treat archive as a special case */ if (g_str_has_suffix (priv->filename, ".cab")) { AsApp *app_tmp; GPtrArray *apps_tmp; g_autoptr(AsStore) store = as_store_new (); g_autoptr(GFile) file = g_file_new_for_path (priv->filename); if (!as_store_from_file (store, file, NULL, NULL, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to parse %s: %s", asb_package_get_filename (priv->pkg), error->message); return TRUE; } apps_tmp = as_store_get_apps (store); for (i = 0; i < apps_tmp->len; i++) { g_autoptr(AsbApp) app2 = NULL; app_tmp = AS_APP (g_ptr_array_index (apps_tmp, i)); app2 = asb_app_new (priv->pkg, as_app_get_id (app_tmp)); as_app_subsume (AS_APP (app2), app_tmp); asb_context_add_app (priv->ctx, app2); /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); as_app_add_metadata (AS_APP (app2), "X-CacheID", cache_id); g_free (cache_id); } nr_added++; } g_debug ("added %u apps from archive", apps_tmp->len); goto skip; } /* ensure file list read */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_FILES, error_not_used)) return FALSE; /* did we get a file match on any plugin */ basename = g_path_get_basename (priv->filename); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Getting filename match for %s", basename); asb_task_add_suitable_plugins (task); if (priv->plugins_to_run->len == 0) { asb_context_add_app_ignore (priv->ctx, priv->pkg); goto out; } /* delete old tree if it exists */ ret = asb_utils_ensure_exists_and_empty (priv->tmpdir, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to clear: %s", error->message); goto out; } /* explode tree */ g_debug ("decompressing files: %s", asb_package_get_name (priv->pkg)); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Exploding tree for %s", asb_package_get_name (priv->pkg)); ret = asb_package_explode (priv->pkg, priv->tmpdir, asb_context_get_file_globs (priv->ctx), &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to explode: %s", error->message); g_clear_error (&error); goto skip; } /* add extra packages */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_DEPS | ASB_PACKAGE_ENSURE_SOURCE, error_not_used)) return FALSE; ret = asb_task_explode_extra_packages (task, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to explode extra file: %s", error->message); goto skip; } /* run plugins */ g_debug ("examining: %s", asb_package_get_name (priv->pkg)); for (i = 0; i < priv->plugins_to_run->len; i++) { GList *apps_tmp = NULL; plugin = g_ptr_array_index (priv->plugins_to_run, i); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Processing %s with %s", basename, plugin->name); apps_tmp = asb_plugin_process (plugin, priv->pkg, priv->tmpdir, &error); if (apps_tmp == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process '%s': %s", plugin->name, error->message); g_clear_error (&error); } for (l = apps_tmp; l != NULL; l = l->next) { app = ASB_APP (l->data); asb_plugin_add_app (&apps, AS_APP (app)); } g_list_free_full (apps_tmp, g_object_unref); } if (apps == NULL) goto skip; /* print */ g_debug ("processing: %s", asb_package_get_name (priv->pkg)); for (l = apps; l != NULL; l = l->next) { app = l->data; /* never set */ if (as_app_get_id (AS_APP (app)) == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_INFO, "app id not set for %s", asb_package_get_name (priv->pkg)); continue; } /* copy data from pkg into app */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_LICENSE | ASB_PACKAGE_ENSURE_RELEASES | ASB_PACKAGE_ENSURE_VCS | ASB_PACKAGE_ENSURE_URL, error_not_used)) return FALSE; if (asb_package_get_url (priv->pkg) != NULL && as_app_get_url_item (AS_APP (app), AS_URL_KIND_HOMEPAGE) == NULL) { as_app_add_url (AS_APP (app), AS_URL_KIND_HOMEPAGE, asb_package_get_url (priv->pkg)); } if (asb_package_get_license (priv->pkg) != NULL && as_app_get_project_license (AS_APP (app)) == NULL) { as_app_set_project_license (AS_APP (app), asb_package_get_license (priv->pkg)); } /* add the source name so we can suggest these together */ if (g_strcmp0 (asb_package_get_source_pkgname (priv->pkg), asb_package_get_name (priv->pkg)) != 0) { as_app_set_source_pkgname (AS_APP (app), asb_package_get_source_pkgname (priv->pkg)); } /* set all the releases on the app */ array = asb_package_get_releases (priv->pkg); for (i = 0; i < array->len; i++) { release = g_ptr_array_index (array, i); as_app_add_release (AS_APP (app), release); } /* run each refine plugin on each app */ ret = asb_plugin_loader_process_app (asb_context_get_plugin_loader (priv->ctx), priv->pkg, app, priv->tmpdir, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process on %s: %s", as_app_get_id (AS_APP (app)), error->message); g_clear_error (&error); goto skip; } /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); as_app_add_metadata (AS_APP (app), "X-CacheID", cache_id); g_free (cache_id); } /* set the VCS information into the metadata */ if (asb_package_get_vcs (priv->pkg) != NULL) { as_app_add_metadata (AS_APP (app), "VersionControlSystem", asb_package_get_vcs (priv->pkg)); } /* save any screenshots early */ if (array->len == 0) { if (!asb_app_save_resources (ASB_APP (app), ASB_APP_SAVE_FLAG_SCREENSHOTS, error_not_used)) return FALSE; } /* all okay */ asb_context_add_app (priv->ctx, app); nr_added++; } skip: /* add a dummy element to the AppStream metadata so that we don't keep * parsing this every time */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID) && nr_added == 0) asb_context_add_app_ignore (priv->ctx, priv->pkg); /* delete tree */ g_debug ("deleting temp files: %s", asb_package_get_name (priv->pkg)); if (!asb_utils_rmtree (priv->tmpdir, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to delete tree: %s", error->message); goto out; } /* write log */ g_debug ("writing log: %s", asb_package_get_name (priv->pkg)); if (!asb_package_log_flush (priv->pkg, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to write package log: %s", error->message); goto out; } out: /* clear loaded resources */ asb_package_close (priv->pkg, NULL); asb_package_clear (priv->pkg, ASB_PACKAGE_ENSURE_DEPS | ASB_PACKAGE_ENSURE_FILES); g_list_free_full (apps, (GDestroyNotify) g_object_unref); return TRUE; }
/* update all values to reflect mouse over image id or no data at all */ static void _metadata_view_update_values(dt_lib_module_t *self) { dt_lib_metadata_view_t *d = (dt_lib_metadata_view_t *)self->data; int32_t mouse_over_id = dt_control_get_mouse_over_id(); if(mouse_over_id == -1) { const dt_view_t *cv = dt_view_manager_get_current_view(darktable.view_manager); if(cv->view((dt_view_t *)cv) == DT_VIEW_DARKROOM) { mouse_over_id = darktable.develop->image_storage.id; } else { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select imgid from selected_images limit 1", -1, &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) mouse_over_id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); } } if(mouse_over_id >= 0) { char value[512]; char pathname[PATH_MAX] = { 0 }; const dt_image_t *img = dt_image_cache_get(darktable.image_cache, mouse_over_id, 'r'); if(!img) goto fill_minuses; if(img->film_id == -1) { dt_image_cache_read_release(darktable.image_cache, img); goto fill_minuses; } /* update all metadata */ dt_image_film_roll(img, value, sizeof(value)); _metadata_update_value(d->metadata[md_internal_filmroll], value); const int tp = 512; char tooltip[tp]; snprintf(tooltip, tp, _("double click to jump to film roll\n%s"), value); gtk_widget_set_tooltip_text(GTK_WIDGET(d->metadata[md_internal_filmroll]), tooltip); snprintf(value, sizeof(value), "%d", img->id); _metadata_update_value(d->metadata[md_internal_imgid], value); snprintf(value, sizeof(value), "%d", img->group_id); _metadata_update_value(d->metadata[md_internal_groupid], value); _metadata_update_value(d->metadata[md_internal_filename], img->filename); snprintf(value, sizeof(value), "%d", img->version); _metadata_update_value(d->metadata[md_internal_version], value); gboolean from_cache = FALSE; dt_image_full_path(img->id, pathname, sizeof(pathname), &from_cache); _metadata_update_value(d->metadata[md_internal_fullpath], pathname); snprintf(value, sizeof(value), "%s", (img->flags & DT_IMAGE_LOCAL_COPY) ? _("yes") : _("no")); _metadata_update_value(d->metadata[md_internal_local_copy], value); // TODO: decide if this should be removed for a release. maybe #ifdef'ing to only add it to git compiles? // the bits of the flags #if SHOW_FLAGS { #define EMPTY_FIELD '.' #define FALSE_FIELD '.' #define TRUE_FIELD '!' char *tooltip = NULL; char *flag_descriptions[] = { N_("unused"), N_("unused/deprecated"), N_("ldr"), N_("raw"), N_("hdr"), N_("marked for deletion"), N_("auto-applying presets applied"), N_("legacy flag. set for all new images"), N_("local copy"), N_("has .txt"), N_("has .wav") }; char *tooltip_parts[14] = { 0 }; int next_tooltip_part = 0; memset(value, EMPTY_FIELD, sizeof(value)); int stars = img->flags & 0x7; char *star_string = NULL; if(stars == 6) { value[0] = 'x'; tooltip_parts[next_tooltip_part++] = _("image rejected"); } else { value[0] = '0' + stars; tooltip_parts[next_tooltip_part++] = star_string = g_strdup_printf(ngettext("image has %d star", "image has %d stars", stars), stars); } if(img->flags & 8) { value[1] = TRUE_FIELD; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[0]); } else value[1] = FALSE_FIELD; if(img->flags & DT_IMAGE_THUMBNAIL_DEPRECATED) { value[2] = TRUE_FIELD; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[1]); } else value[2] = FALSE_FIELD; if(img->flags & DT_IMAGE_LDR) { value[3] = 'l'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[2]); } if(img->flags & DT_IMAGE_RAW) { value[4] = 'r'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[3]); } if(img->flags & DT_IMAGE_HDR) { value[5] = 'h'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[4]); } if(img->flags & DT_IMAGE_REMOVE) { value[6] = 'd'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[5]); } if(img->flags & DT_IMAGE_AUTO_PRESETS_APPLIED) { value[7] = 'a'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[6]); } if(img->flags & DT_IMAGE_NO_LEGACY_PRESETS) { value[8] = 'p'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[7]); } if(img->flags & DT_IMAGE_LOCAL_COPY) { value[9] = 'c'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[8]); } if(img->flags & DT_IMAGE_HAS_TXT) { value[10] = 't'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[9]); } if(img->flags & DT_IMAGE_HAS_WAV) { value[11] = 'w'; tooltip_parts[next_tooltip_part++] = _(flag_descriptions[10]); } static const struct { char *tooltip; char flag; } loaders[] = { { N_("unknown"), EMPTY_FIELD}, { N_("tiff"), 't'}, { N_("png"), 'p'}, { N_("j2k"), 'J'}, { N_("jpeg"), 'j'}, { N_("exr"), 'e'}, { N_("rgbe"), 'R'}, { N_("pfm"), 'P'}, { N_("GraphicsMagick"), 'g'}, { N_("rawspeed"), 'r'} }; int loader = (unsigned int)img->loader < sizeof(loaders) / sizeof(*loaders) ? img->loader : 0; value[12] = loaders[loader].flag; char *loader_tooltip = g_strdup_printf(_("loader: %s"), _(loaders[loader].tooltip)); tooltip_parts[next_tooltip_part++] = loader_tooltip; value[13] = '\0'; tooltip = g_strjoinv("\n", tooltip_parts); g_free(loader_tooltip); _metadata_update_value(d->metadata[md_internal_flags], value); gtk_widget_set_tooltip_text(GTK_WIDGET(d->metadata[md_internal_flags]), tooltip); g_free(star_string); g_free(tooltip); #undef EMPTY_FIELD #undef FALSE_FIELD #undef TRUE_FIELD } #endif // SHOW_FLAGS /* EXIF */ _metadata_update_value_end(d->metadata[md_exif_model], img->camera_alias); _metadata_update_value_end(d->metadata[md_exif_lens], img->exif_lens); _metadata_update_value_end(d->metadata[md_exif_maker], img->camera_maker); snprintf(value, sizeof(value), "F/%.1f", img->exif_aperture); _metadata_update_value(d->metadata[md_exif_aperture], value); if(img->exif_exposure <= 0.5) snprintf(value, sizeof(value), "1/%.0f", 1.0 / img->exif_exposure); else snprintf(value, sizeof(value), "%.1f''", img->exif_exposure); _metadata_update_value(d->metadata[md_exif_exposure], value); snprintf(value, sizeof(value), "%.0f mm", img->exif_focal_length); _metadata_update_value(d->metadata[md_exif_focal_length], value); if(isnan(img->exif_focus_distance) || fpclassify(img->exif_focus_distance) == FP_ZERO) { _metadata_update_value(d->metadata[md_exif_focus_distance], NODATA_STRING); } else { snprintf(value, sizeof(value), "%.2f m", img->exif_focus_distance); _metadata_update_value(d->metadata[md_exif_focus_distance], value); } snprintf(value, sizeof(value), "%.0f", img->exif_iso); _metadata_update_value(d->metadata[md_exif_iso], value); struct tm tt_exif = { 0 }; if(sscanf(img->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &tt_exif.tm_year, &tt_exif.tm_mon, &tt_exif.tm_mday, &tt_exif.tm_hour, &tt_exif.tm_min, &tt_exif.tm_sec) == 6) { char datetime[200]; tt_exif.tm_year -= 1900; tt_exif.tm_mon--; tt_exif.tm_isdst = -1; mktime(&tt_exif); // just %c is too long and includes a time zone that we don't know from exif strftime(datetime, sizeof(datetime), "%a %x %X", &tt_exif); _metadata_update_value(d->metadata[md_exif_datetime], datetime); } else _metadata_update_value(d->metadata[md_exif_datetime], img->exif_datetime_taken); snprintf(value, sizeof(value), "%d", img->height); _metadata_update_value(d->metadata[md_exif_height], value); snprintf(value, sizeof(value), "%d", img->width); _metadata_update_value(d->metadata[md_exif_width], value); /* XMP */ GList *res; if((res = dt_metadata_get(img->id, "Xmp.dc.title", NULL)) != NULL) { snprintf(value, sizeof(value), "%s", (char *)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_title], value); if((res = dt_metadata_get(img->id, "Xmp.dc.creator", NULL)) != NULL) { snprintf(value, sizeof(value), "%s", (char *)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_creator], value); if((res = dt_metadata_get(img->id, "Xmp.dc.rights", NULL)) != NULL) { snprintf(value, sizeof(value), "%s", (char *)res->data); _filter_non_printable(value, sizeof(value)); g_list_free_full(res, &g_free); } else snprintf(value, sizeof(value), NODATA_STRING); _metadata_update_value(d->metadata[md_xmp_rights], value); /* geotagging */ /* latitude */ if(isnan(img->latitude)) { _metadata_update_value(d->metadata[md_geotagging_lat], NODATA_STRING); } else { if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *latitude = dt_util_latitude_str(img->latitude); _metadata_update_value(d->metadata[md_geotagging_lat], latitude); g_free(latitude); } else { gchar NS = img->latitude < 0 ? 'S' : 'N'; snprintf(value, sizeof(value), "%c %09.6f", NS, fabs(img->latitude)); _metadata_update_value(d->metadata[md_geotagging_lat], value); } } /* longitude */ if(isnan(img->longitude)) { _metadata_update_value(d->metadata[md_geotagging_lon], NODATA_STRING); } else { if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *longitude = dt_util_longitude_str(img->longitude); _metadata_update_value(d->metadata[md_geotagging_lon], longitude); g_free(longitude); } else { gchar EW = img->longitude < 0 ? 'W' : 'E'; snprintf(value, sizeof(value), "%c %010.6f", EW, fabs(img->longitude)); _metadata_update_value(d->metadata[md_geotagging_lon], value); } } /* elevation */ if(isnan(img->elevation)) { _metadata_update_value(d->metadata[md_geotagging_ele], NODATA_STRING); } else { if(dt_conf_get_bool("plugins/lighttable/metadata_view/pretty_location")) { gchar *elevation = dt_util_elevation_str(img->elevation); _metadata_update_value(d->metadata[md_geotagging_ele], elevation); g_free(elevation); } else { snprintf(value, sizeof(value), "%.2f %s", img->elevation, _("m")); _metadata_update_value(d->metadata[md_geotagging_ele], value); } } /* release img */ dt_image_cache_read_release(darktable.image_cache, img); #ifdef USE_LUA dt_lua_async_call_alien(lua_update_metadata, 0,NULL,NULL, LUA_ASYNC_TYPENAME,"void*",self, LUA_ASYNC_TYPENAME,"int32_t",mouse_over_id,LUA_ASYNC_DONE); #endif } return; /* reset */ fill_minuses: for(int k = 0; k < md_size; k++) _metadata_update_value(d->metadata[k], NODATA_STRING); #ifdef USE_LUA dt_lua_async_call_alien(lua_update_metadata, 0,NULL,NULL, LUA_ASYNC_TYPENAME,"void*",self, LUA_ASYNC_TYPENAME,"int32_t",-1,LUA_ASYNC_DONE); #endif }
int32_t dt_camera_capture_job_run(dt_job_t *job) { dt_camera_capture_t *t=(dt_camera_capture_t*)job->param; int total = t->brackets ? t->count * t->brackets : t->count; char message[512]= {0}; double fraction=0; snprintf(message, 512, ngettext ("capturing %d image", "capturing %d images", total), total ); /* try to get exp program mode for nikon */ char *expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "expprogram"); /* if fail, lets try fetching mode for cannon */ if(!expprogram) expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "autoexposuremode"); /* Fetch all values for shutterspeed and initialize current value */ GList *values=NULL; gconstpointer original_value=NULL; const char *cvalue = dt_camctl_camera_get_property(darktable.camctl, NULL, "shutterspeed"); const char *value = dt_camctl_camera_property_get_first_choice(darktable.camctl, NULL, "shutterspeed"); /* get values for bracketing */ if (t->brackets && expprogram && expprogram[0]=='M' && value && cvalue) { do { // Add value to list values = g_list_append(values, g_strdup(value)); // Check if current values is the same as original value, then lets store item ptr if (strcmp(value,cvalue) == 0) original_value = g_list_last(values)->data; } while ((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, "shutterspeed")) != NULL); } else { /* if this was an intended bracket capture bail out */ if(t->brackets) { dt_control_log(_("please set your camera to manual mode first!")); return 1; } } /* create the bgjob plate */ const guint *jid = dt_control_backgroundjobs_create(darktable.control, 0, message); GList *current_value = g_list_find(values,original_value); for(uint32_t i=0; i<t->count; i++) { // Delay if active if(t->delay) g_usleep(t->delay*G_USEC_PER_SEC); for(uint32_t b=0; b<(t->brackets*2)+1; b++) { // If bracket capture, lets set change shutterspeed if (t->brackets) { if (b == 0) { // First bracket, step down time with (steps*brackets), also check so we never set the longest shuttertime which would be bulb mode for(uint32_t s=0; s<(t->steps*t->brackets); s++) if (g_list_next(current_value) && g_list_next(g_list_next(current_value))) current_value = g_list_next(current_value); } else { // Step up with (steps) for(uint32_t s=0; s<t->steps; s++) if(g_list_previous(current_value)) current_value = g_list_previous(current_value); } } // set the time property for bracket capture if (t->brackets && current_value) dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); // Capture image dt_camctl_camera_capture(darktable.camctl,NULL); fraction += 1.0/total; dt_control_backgroundjobs_progress(darktable.control, jid, fraction); } // lets reset to original value before continue if (t->brackets) { current_value = g_list_find(values,original_value); dt_camctl_camera_set_property_string(darktable.camctl, NULL, "shutterspeed", current_value->data); } } dt_control_backgroundjobs_destroy(darktable.control, jid); // free values if(values) { g_list_free_full(values, g_free); } return 0; }
/* This will check if the application the user wanted exists will return that * application. If it doesn't exist, it will create one and return that. * It also sets the app info as the default for this type. */ static GAppInfo * add_or_find_application (CajaOpenWithDialog *dialog) { GAppInfo *app; GError *error; gboolean success, should_set_default; char *message; error = NULL; app = NULL; if (dialog->details->selected_app_info) { app = g_object_ref (dialog->details->selected_app_info); } else { char *app_name; const char *commandline; commandline = gtk_entry_get_text (GTK_ENTRY (dialog->details->entry)); app_name = get_app_name (commandline, &error); if (app_name != NULL) { app = g_app_info_create_from_commandline (commandline, app_name, G_APP_INFO_CREATE_NONE, &error); g_free (app_name); } } if (app == NULL) { message = g_strdup_printf (_("Could not add application to the application database: %s"), error ? error->message : _("Unknown error")); eel_show_error_dialog (_("Could not add application"), message, GTK_WINDOW (dialog)); g_free (message); if (error) g_error_free (error); return NULL; } should_set_default = (dialog->details->add_mode) || (!dialog->details->add_mode && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->checkbox))); success = TRUE; if (should_set_default) { if (dialog->details->content_type) { success = g_app_info_set_as_default_for_type (app, dialog->details->content_type, &error); } else { success = g_app_info_set_as_default_for_extension (app, dialog->details->extension, &error); } } else { GList *applications; applications = g_app_info_get_all_for_type (dialog->details->content_type); if (dialog->details->content_type && applications != NULL) { /* we don't care about reporting errors here */ g_app_info_add_supports_type (app, dialog->details->content_type, NULL); } if (applications != NULL) { g_list_free_full (applications, g_object_unref); } } if (!success && should_set_default) { message = g_strdup_printf (_("Could not set application as the default: %s"), error->message); eel_show_error_dialog (_("Could not set as default application"), message, GTK_WINDOW (dialog)); g_free (message); g_error_free (error); } g_signal_emit_by_name (caja_signaller_get_current (), "mime_data_changed"); return app; }
static GList * tokenize (TextgenTemplate *tpl, const gchar *text, gint length, GError **error) { gboolean success = TRUE; GList *list = NULL; gint pos = 0; gint cur_line = 1; gint cur_column = 1; gint text_start = 0; GError *tmp_error = NULL; while (pos < length) { Token *instruction_token; gboolean ignore_empty_line; gint after_instruction_end; instruction_token = maybe_parse_instruction (tpl, text, length, pos, cur_line, cur_column, &ignore_empty_line, &after_instruction_end, &cur_line, &cur_column, &tmp_error); if (tmp_error) { g_propagate_error (error, tmp_error); success = FALSE; goto finish; } if (instruction_token) { gint after_text_end = pos; gint next_text_start = after_instruction_end; if (ignore_empty_line) { gint i; gint newline_before_empty_line; gint newline_after_empty_line; gboolean empty_before; gboolean empty_after; empty_before = check_line_empty_before (text, after_text_end - 1, &newline_before_empty_line); empty_after = check_line_empty_after (text, length, next_text_start, &newline_after_empty_line); if (empty_before && empty_after) { after_text_end = newline_before_empty_line + 1; next_text_start = newline_after_empty_line + 1; cur_line++; cur_column = 1; } } if (text_start < after_text_end) { Token *text_token = token_new_text_from_range (text, text_start, after_text_end); list = g_list_prepend (list, text_token); } pos = text_start = next_text_start; list = g_list_prepend (list, instruction_token); } else { advance_pos (tpl, text, length, &pos, &cur_line, &cur_column, &tmp_error); if (tmp_error) { g_propagate_error (error, tmp_error); success = FALSE; goto finish; } } } if (text_start < length) { Token *text_token = token_new_text_from_range (text, text_start, length); list = g_list_prepend (list, text_token); } finish: if (success) return g_list_reverse (list); else { g_list_free_full (list, free_token); return NULL; } }
static void free_frame_list (GList * list) { g_list_free_full (list, (GDestroyNotify) free_frame); }
static Node * parse_list (TextgenTemplate *tpl, GList *tokens, CheckEndFunc check_end, GList **end, GError **error) { gboolean success = TRUE; GList *list = NULL; GList *l; l = tokens; while (l && !(check_end && check_end (l))) { Token *token = l->data; if (token->type == TOKEN_TEXT) { Node *node; node = g_slice_new (Node); node->type = NODE_TEXT; node->value.text.text = token->content; node->value.text.length = token->content_length; token->owns_content = FALSE; list = g_list_prepend (list, node); l = l->next; } else if (token->type == TOKEN_VARIABLE) { Node *node; node = g_slice_new (Node); node->type = NODE_VARIABLE; node->value.variable.name = token->content; node->value.variable.line = token->line; node->value.variable.column = token->column; token->owns_content = FALSE; list = g_list_prepend (list, node); l = l->next; } else if (token->type == TOKEN_EXPRESSION || token->type == TOKEN_SCRIPT) { Node *node; node = g_slice_new (Node); node->type = token->type == TOKEN_EXPRESSION ? NODE_EXPRESSION : NODE_SCRIPT; node->value.script.code = token->content; node->value.script.length = token->content_length; node->value.script.code_line = token->line; node->value.script.code_column = token->content_column; token->owns_content = FALSE; list = g_list_prepend (list, node); l = l->next; } else if (token->type == TOKEN_COMMAND) { if (g_ascii_strcasecmp (token->command, "IF") == 0) { Node *node; GList *end; GError *tmp_error = NULL; node = parse_condition (tpl, l, &end, &tmp_error); if (tmp_error) { g_propagate_error (error, tmp_error); success = FALSE; goto finish; } list = g_list_prepend (list, node); l = end->next; } else if (g_ascii_strcasecmp (token->command, "INCLUDE") == 0) { Node *node; node = g_slice_new (Node); node->type = NODE_INCLUDE; node->value.script.code = token->content; node->value.script.length = token->content_length; node->value.script.code_line = token->line; node->value.script.code_column = token->content_column; token->owns_content = FALSE; list = g_list_prepend (list, node); l = l->next; } else { emit_message (tpl, TEXTGEN_MESSAGE_ERROR, token->line, token->column, _("Unknown command %s"), token->command); set_parse_error (error); success = FALSE; goto finish; } } } if (end) *end = l; finish: if (success) { Node *node = g_slice_new (Node); node->type = NODE_LIST; node->value.list = g_list_reverse (list); return node; } else { g_list_free_full (list, free_node); return NULL; } }
END_TEST START_TEST (test_credentials_database) { GSignondConfig *config = NULL; guint32 identity_id = 5; GSignondIdentityInfo *identity = NULL, *identity2= NULL; GSignondIdentityInfoList *identities = NULL; GSignondSecurityContext *ctx1 = NULL; GList *methods = NULL, *reflist = NULL; GSignondSecurityContextList *acl = NULL ; GSignondSecurityContext *owner = NULL; GSignondDbCredentialsDatabase *credentials_db = NULL; GSignondSecretStorage *storage =NULL; GHashTable *data = NULL; GHashTable *data2 = NULL; Data input; GSignondDictionary *cap_filter = NULL; GSignondDictionary *type_filter = NULL; GSignondDictionary *cap_type_filter = NULL; GSignondDictionary *no_cap_filter = NULL; config = gsignond_config_new (); gsignond_config_set_string (config, GSIGNOND_CONFIG_GENERAL_SECURE_DIR, "/tmp/gsignond"); storage = g_object_new (GSIGNOND_TYPE_SECRET_STORAGE, "config", config, NULL); g_object_unref(config); credentials_db = gsignond_db_credentials_database_new ( config, storage); g_object_unref (storage); fail_if (credentials_db == NULL); fail_unless (gsignond_db_credentials_database_open_secret_storage ( credentials_db) == TRUE); fail_unless (gsignond_db_credentials_database_clear ( credentials_db) == TRUE); identity = _get_filled_identity_info (); /*identity load/update*/ identity_id = gsignond_db_credentials_database_update_identity ( credentials_db, identity); fail_unless (identity_id != 0); gsignond_identity_info_set_id (identity, identity_id); fail_unless (gsignond_db_credentials_database_load_identity ( credentials_db, 555, FALSE) == NULL); identity2 = gsignond_db_credentials_database_load_identity ( credentials_db, identity_id, FALSE); fail_if (identity2 == NULL); gsignond_identity_info_unref (identity2); identity2 = gsignond_db_credentials_database_load_identity ( credentials_db, identity_id, TRUE); fail_if (identity2 == NULL); fail_unless (g_strcmp0 (gsignond_identity_info_get_username ( identity2), "username1") == 0); fail_unless (g_strcmp0 (gsignond_identity_info_get_secret ( identity2), "secret1") == 0); gsignond_identity_info_unref (identity2); fail_unless (gsignond_db_credentials_database_check_secret ( credentials_db, identity_id, "username2", "secret1") == FALSE); fail_unless (gsignond_db_credentials_database_check_secret ( credentials_db, identity_id, "username1", "secret2") == FALSE); fail_unless (gsignond_db_credentials_database_check_secret ( credentials_db, 0, "username1", "secret2") == FALSE); fail_unless (gsignond_db_credentials_database_check_secret ( credentials_db, identity_id, "username1", "secret1") == TRUE); ctx1 = gsignond_security_context_new_from_values ("sysctx1", "appctx1"); methods = gsignond_db_credentials_database_get_methods (credentials_db, identity_id, ctx1); fail_if (methods == NULL); g_list_free_full (methods, g_free); /* add data to store */ data = g_hash_table_new_full ((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal, (GDestroyNotify)NULL, (GDestroyNotify)g_variant_unref); g_hash_table_insert (data,"key1",g_variant_new_string ("string_value")); g_hash_table_insert (data,"key2",g_variant_new_double (12223.4223)); g_hash_table_insert (data,"key3",g_variant_new_uint16(20)); g_hash_table_insert (data,"key4",g_variant_new("^ay", "byte_value")); fail_unless (gsignond_db_credentials_database_update_data ( credentials_db, 0, "method1", data) == FALSE); fail_unless (gsignond_db_credentials_database_update_data ( credentials_db, identity_id, "method1", data) == TRUE); fail_unless (gsignond_db_credentials_database_update_data ( credentials_db, identity_id, "method1", data) == TRUE); fail_unless (gsignond_db_credentials_database_load_data ( credentials_db, 0, "method1") == NULL); fail_unless (gsignond_db_credentials_database_load_data ( credentials_db, identity_id, "method2") == NULL); data2 = gsignond_db_credentials_database_load_data (credentials_db, identity_id, "method1"); fail_if (data2 == NULL); input.table = data; input.status = 1; g_hash_table_foreach (data2, (GHFunc)_compare_key_value, &input); fail_if (input.status != 1); gsignond_dictionary_unref(data2); g_hash_table_unref(data); fail_unless (gsignond_db_credentials_database_remove_data ( credentials_db, 0, "method1") == FALSE); fail_unless (gsignond_db_credentials_database_remove_data ( credentials_db, identity_id, "method1") == TRUE); /*references*/ fail_unless (gsignond_db_credentials_database_insert_reference ( credentials_db, identity_id, ctx1, "reference1") == TRUE); reflist = gsignond_db_credentials_database_get_references (credentials_db, identity_id, ctx1); fail_if (reflist == NULL); fail_unless (g_list_length (reflist) == 1); g_list_free_full (reflist, g_free); fail_unless (gsignond_db_credentials_database_remove_reference ( credentials_db, identity_id, ctx1, "reference2") == FALSE); fail_unless (gsignond_db_credentials_database_remove_reference ( credentials_db, identity_id, ctx1, "reference1") == TRUE); gsignond_security_context_free (ctx1); acl = gsignond_db_credentials_database_get_accesscontrol_list ( credentials_db, identity_id); fail_if (acl == NULL); gsignond_security_context_list_free (acl); owner = gsignond_db_credentials_database_get_owner ( credentials_db, identity_id); fail_if (owner == NULL); gsignond_security_context_free (owner); owner = gsignond_db_credentials_database_get_identity_owner ( credentials_db, identity_id); fail_if (owner == NULL); gsignond_security_context_free (owner); /* load_identities : matched with caption and security context */ cap_filter = gsignond_dictionary_new (); GSignondSecurityContext *ctx = gsignond_security_context_new_from_values("sysctx1", "appctx1"); gsignond_dictionary_set_string (cap_filter, "Caption", "cap"); gsignond_dictionary_set(cap_filter, "Owner", gsignond_security_context_to_variant(ctx)); gsignond_security_context_free (ctx); identities = gsignond_db_credentials_database_load_identities ( credentials_db, cap_filter); gsignond_dictionary_unref (cap_filter); fail_if (identities == NULL); fail_unless (g_list_length (identities) == 1); gsignond_identity_info_list_free (identities); /* load_identities: matched with type */ type_filter = gsignond_dictionary_new(); gsignond_dictionary_set_int32 (type_filter, "Type", 456); identities = gsignond_db_credentials_database_load_identities ( credentials_db, type_filter); gsignond_dictionary_unref (type_filter); fail_if (identities == NULL); fail_unless (g_list_length (identities) == 1); gsignond_identity_info_list_free (identities); /* load_identities: matched with type and caption */ cap_type_filter = gsignond_dictionary_new(); gsignond_dictionary_set_int32 (cap_type_filter, "Type", 456); gsignond_dictionary_set_string (cap_type_filter, "Caption", "CAP"); identities = gsignond_db_credentials_database_load_identities ( credentials_db, cap_type_filter); gsignond_dictionary_unref (cap_type_filter); fail_if (identities == NULL); fail_unless (g_list_length (identities) == 1); gsignond_identity_info_list_free (identities); /* Negative load_identities query */ no_cap_filter = gsignond_dictionary_new(); gsignond_dictionary_set_string (no_cap_filter, "Caption", "non_existing"); identities = gsignond_db_credentials_database_load_identities ( credentials_db, no_cap_filter); gsignond_dictionary_unref (no_cap_filter); fail_unless (identities == NULL); fail_unless (gsignond_db_credentials_database_remove_identity ( credentials_db, identity_id) == TRUE); gsignond_identity_info_unref (identity); g_object_unref(credentials_db); }
static void photos_import_dialog_initialize_index_and_popover (PhotosImportDialog *self) { GHashTableIter iter; GList *extra_collections = NULL; GList *l; PhotosBaseItem *collection; guint n_buttons = 0; g_clear_pointer (&self->index, (GDestroyNotify) dzl_fuzzy_mutable_index_unref); g_clear_pointer (&self->recent_collections, (GDestroyNotify) photos_utils_object_list_free_full); gtk_container_foreach (GTK_CONTAINER (self->collections_popover_grid), (GtkCallback) gtk_widget_destroy, NULL); gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE); photos_import_dialog_enable_create_new (self, FALSE); photos_import_dialog_show_add_existing (self, FALSE); self->index = dzl_fuzzy_mutable_index_new_with_free_func (FALSE, g_object_unref); dzl_fuzzy_mutable_index_begin_bulk_insert (self->index); g_hash_table_iter_init (&iter, self->collections); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &collection)) { const gchar *name; name = photos_base_item_get_name (collection); dzl_fuzzy_mutable_index_insert (self->index, name, g_object_ref (collection)); self->recent_collections = g_list_prepend (self->recent_collections, g_object_ref (collection)); } dzl_fuzzy_mutable_index_end_bulk_insert (self->index); self->recent_collections = g_list_sort_with_data (self->recent_collections, photos_import_dialog_sort_func, self); for (l = self->recent_collections; l != NULL && n_buttons < MAX_MATCHES; l = l->next) { GtkWidget *collection_button; collection = PHOTOS_BASE_ITEM (l->data); collection_button = photos_import_dialog_create_collection_button (collection); gtk_container_add (GTK_CONTAINER (self->collections_popover_grid), collection_button); gtk_widget_show_all (collection_button); n_buttons++; } if (self->recent_collections != NULL) { GVariant *state; const gchar *id; if (l != NULL) { l->prev->next = NULL; l->prev = NULL; extra_collections = g_steal_pointer (&l); } collection = PHOTOS_BASE_ITEM (self->recent_collections->data); id = photos_filterable_get_id (PHOTOS_FILTERABLE (collection)); state = g_variant_new_string (id); g_action_change_state (G_ACTION (self->add_existing_action), state); photos_import_dialog_show_add_existing (self, TRUE); } photos_import_dialog_enable_create_new (self, TRUE); photos_import_dialog_update_response_sensitivity (self); g_list_free_full (extra_collections, g_object_unref); g_return_if_fail (g_list_length (self->recent_collections) <= MAX_MATCHES); }
static gboolean _lib_location_search(gpointer user_data) { GMarkupParseContext *ctx = NULL; CURL *curl = NULL; CURLcode res; GError *err = NULL; dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_location_t *lib = (dt_lib_location_t *)self->data; gchar *query = NULL, *text = NULL; /* get escaped search text */ text = g_uri_escape_string(gtk_entry_get_text(lib->search), NULL, FALSE); if(!(text && *text)) goto bail_out; /* clean up previous results before adding new */ g_free(lib->response); lib->response = NULL; lib->response_size = 0; g_list_free_full(lib->places, g_free); lib->places = NULL; gtk_container_foreach(GTK_CONTAINER(lib->result), (GtkCallback)gtk_widget_destroy, NULL); /* build the query url */ query = dt_util_dstrcat(query, "http://nominatim.openstreetmap.org/search/%s?format=xml&limit=%d", text, LIMIT_RESULT); /* load url */ curl = curl_easy_init(); if(!curl) goto bail_out; curl_easy_setopt(curl, CURLOPT_URL, query); // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_WRITEDATA, lib); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _lib_location_curl_write_data); res = curl_easy_perform(curl); if(res != 0) goto bail_out; if(!lib->response) goto bail_out; /* parse xml response and populate the result list */ ctx = g_markup_parse_context_new(&_lib_location_parser, 0, lib, NULL); g_markup_parse_context_parse(ctx, lib->response, lib->response_size, &err); if(err) goto bail_out; /* add the places into the result list */ GList *item = lib->places; if(!item) goto bail_out; while(item) { _lib_location_result_t *p = (_lib_location_result_t *)item->data; fprintf(stderr, "(%f,%f) %s\n", p->lon, p->lat, p->name); item = g_list_next(item); } /* cleanup an exit search job */ bail_out: if(err) { fprintf(stderr, "location search: %s\n", err->message); g_error_free(err); } if(curl) curl_easy_cleanup(curl); g_free(text); g_free(query); if(ctx) g_markup_parse_context_free(ctx); /* enable the widgets */ gtk_widget_set_sensitive(GTK_WIDGET(lib->search), TRUE); // gtk_widget_set_sensitive(lib->result, FALSE); return FALSE; }
/* go through changes in the change queue, send ones with the same kind * in a list to the different caja_directory_notify calls */ void caja_file_changes_consume_changes (gboolean consume_all) { CajaFileChange *change; GList *additions, *changes, *deletions, *moves; GList *position_set_requests; GFilePair *pair; CajaFileChangesQueuePosition *position_set; guint chunk_count; CajaFileChangesQueue *queue; gboolean flush_needed; additions = NULL; changes = NULL; deletions = NULL; moves = NULL; position_set_requests = NULL; queue = caja_file_changes_queue_get(); /* Consume changes from the queue, stuffing them into one of three lists, * keep doing it while the changes are of the same kind, then send them off. * This is to ensure that the changes get sent off in the same order that they * arrived. */ for (chunk_count = 0; ; chunk_count++) { change = caja_file_changes_queue_get_change (queue); /* figure out if we need to flush the pending changes that we collected sofar */ if (change == NULL) { flush_needed = TRUE; /* no changes left, flush everything */ } else { flush_needed = additions != NULL && change->kind != CHANGE_FILE_ADDED && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE; flush_needed |= changes != NULL && change->kind != CHANGE_FILE_CHANGED; flush_needed |= moves != NULL && change->kind != CHANGE_FILE_MOVED && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE; flush_needed |= deletions != NULL && change->kind != CHANGE_FILE_REMOVED; flush_needed |= position_set_requests != NULL && change->kind != CHANGE_POSITION_SET && change->kind != CHANGE_POSITION_REMOVE && change->kind != CHANGE_FILE_ADDED && change->kind != CHANGE_FILE_MOVED; flush_needed |= !consume_all && chunk_count >= CONSUME_CHANGES_MAX_CHUNK; /* we have reached the chunk maximum */ } if (flush_needed) { /* Send changes we collected off. * At one time we may only have one of the lists * contain changes. */ if (deletions != NULL) { deletions = g_list_reverse (deletions); caja_directory_notify_files_removed (deletions); g_list_free_full (deletions, g_object_unref); deletions = NULL; } if (moves != NULL) { moves = g_list_reverse (moves); caja_directory_notify_files_moved (moves); pairs_list_free (moves); moves = NULL; } if (additions != NULL) { additions = g_list_reverse (additions); caja_directory_notify_files_added (additions); g_list_free_full (additions, g_object_unref); additions = NULL; } if (changes != NULL) { changes = g_list_reverse (changes); caja_directory_notify_files_changed (changes); g_list_free_full (changes, g_object_unref); changes = NULL; } if (position_set_requests != NULL) { position_set_requests = g_list_reverse (position_set_requests); caja_directory_schedule_position_set (position_set_requests); position_set_list_free (position_set_requests); position_set_requests = NULL; } } if (change == NULL) { /* we are done */ return; } /* add the new change to the list */ switch (change->kind) { case CHANGE_FILE_ADDED: additions = g_list_prepend (additions, change->from); break; case CHANGE_FILE_CHANGED: changes = g_list_prepend (changes, change->from); break; case CHANGE_FILE_REMOVED: deletions = g_list_prepend (deletions, change->from); break; case CHANGE_FILE_MOVED: pair = g_new (GFilePair, 1); pair->from = change->from; pair->to = change->to; moves = g_list_prepend (moves, pair); break; case CHANGE_POSITION_SET: position_set = g_new (CajaFileChangesQueuePosition, 1); position_set->location = change->from; position_set->set = TRUE; position_set->point = change->point; position_set->screen = change->screen; position_set_requests = g_list_prepend (position_set_requests, position_set); break; case CHANGE_POSITION_REMOVE: position_set = g_new (CajaFileChangesQueuePosition, 1); position_set->location = change->from; position_set->set = FALSE; position_set_requests = g_list_prepend (position_set_requests, position_set); break; default: g_assert_not_reached (); break; } g_free (change); } }
void nautilus_launch_desktop_file (GdkScreen *screen, const char *desktop_file_uri, const GList *parameter_uris, GtkWindow *parent_window) { GError *error; char *message, *desktop_file_path; const GList *p; GList *files; int total, count; GFile *file, *desktop_file; GDesktopAppInfo *app_info; GdkAppLaunchContext *context; /* Don't allow command execution from remote locations * to partially mitigate the security * risk of executing arbitrary commands. */ desktop_file = g_file_new_for_uri (desktop_file_uri); desktop_file_path = g_file_get_path (desktop_file); if (!g_file_is_native (desktop_file)) { g_free (desktop_file_path); g_object_unref (desktop_file); eel_show_error_dialog (_("Sorry, but you cannot execute commands from " "a remote site."), _("This is disabled due to security considerations."), parent_window); return; } g_object_unref (desktop_file); app_info = g_desktop_app_info_new_from_filename (desktop_file_path); g_free (desktop_file_path); if (app_info == NULL) { eel_show_error_dialog (_("There was an error launching the application."), NULL, parent_window); return; } /* count the number of uris with local paths */ count = 0; total = g_list_length ((GList *) parameter_uris); files = NULL; for (p = parameter_uris; p != NULL; p = p->next) { file = g_file_new_for_uri ((const char *) p->data); if (g_file_is_native (file)) { count++; } files = g_list_prepend (files, file); } /* check if this app only supports local files */ if (g_app_info_supports_files (G_APP_INFO (app_info)) && !g_app_info_supports_uris (G_APP_INFO (app_info)) && parameter_uris != NULL) { if (count == 0) { /* all files are non-local */ eel_show_error_dialog (_("This drop target only supports local files."), _("To open non-local files copy them to a local folder and then" " drop them again."), parent_window); g_list_free_full (files, g_object_unref); g_object_unref (app_info); return; } else if (count != total) { /* some files are non-local */ eel_show_warning_dialog (_("This drop target only supports local files."), _("To open non-local files copy them to a local folder and then" " drop them again. The local files you dropped have already been opened."), parent_window); } } error = NULL; context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (parent_window))); /* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */ gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME); gdk_app_launch_context_set_screen (context, gtk_window_get_screen (parent_window)); if (count == total) { /* All files are local, so we can use g_app_info_launch () with * the file list we constructed before. */ g_app_info_launch (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (context), &error); } else { /* Some files are non local, better use g_app_info_launch_uris (). */ g_app_info_launch_uris (G_APP_INFO (app_info), (GList *) parameter_uris, G_APP_LAUNCH_CONTEXT (context), &error); } if (error != NULL) { message = g_strconcat (_("Details: "), error->message, NULL); eel_show_error_dialog (_("There was an error launching the application."), message, parent_window); g_error_free (error); g_free (message); } g_list_free_full (files, g_object_unref); g_object_unref (context); g_object_unref (app_info); }
static void gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self) { GList *all_applications = NULL; GList *recommended_apps = NULL; GList *fallback_apps = NULL; GList *exclude_apps = NULL; GAppInfo *default_app = NULL; gboolean show_headings; gboolean apps_added; show_headings = TRUE; apps_added = FALSE; if (self->priv->show_all) show_headings = FALSE; if (self->priv->show_default && self->priv->content_type) { default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE); if (default_app != NULL) { gtk_app_chooser_add_default (self, default_app); apps_added = TRUE; exclude_apps = g_list_prepend (exclude_apps, default_app); } } #ifndef G_OS_WIN32 if ((self->priv->content_type && self->priv->show_recommended) || self->priv->show_all) { if (self->priv->content_type) recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type); apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"), show_headings, !self->priv->show_all, /* mark as recommended */ FALSE, /* mark as fallback */ recommended_apps, exclude_apps); exclude_apps = g_list_concat (exclude_apps, g_list_copy (recommended_apps)); } if ((self->priv->content_type && self->priv->show_fallback) || self->priv->show_all) { if (self->priv->content_type) fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type); apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"), show_headings, FALSE, /* mark as recommended */ !self->priv->show_all, /* mark as fallback */ fallback_apps, exclude_apps); exclude_apps = g_list_concat (exclude_apps, g_list_copy (fallback_apps)); } #endif if (self->priv->show_other || self->priv->show_all) { all_applications = g_app_info_get_all (); apps_added |= gtk_app_chooser_widget_add_section (self, _("Other Applications"), show_headings, FALSE, FALSE, all_applications, exclude_apps); } if (!apps_added) update_no_applications_label (self); gtk_widget_set_visible (self->priv->no_apps, !apps_added); gtk_app_chooser_widget_select_first (self); if (default_app != NULL) g_object_unref (default_app); g_list_free_full (all_applications, g_object_unref); g_list_free_full (recommended_apps, g_object_unref); g_list_free_full (fallback_apps, g_object_unref); g_list_free (exclude_apps); }
/** * cockpit_web_response_error: * @self: the response * @status: the HTTP status code * @headers: headers to include or NULL * @format: printf format of error message * * Send an error message with a basic HTML page containing * the error. */ void cockpit_web_response_error (CockpitWebResponse *self, guint code, GHashTable *headers, const gchar *format, ...) { va_list var_args; gchar *reason = NULL; const gchar *message; GBytes *input = NULL; GList *output, *l; GError *error = NULL; g_return_if_fail (COCKPIT_IS_WEB_RESPONSE (self)); if (format) { va_start (var_args, format); reason = g_strdup_vprintf (format, var_args); va_end (var_args); message = reason; } else { switch (code) { case 400: message = "Bad request"; break; case 401: message = "Not Authorized"; break; case 403: message = "Forbidden"; break; case 404: message = "Not Found"; break; case 405: message = "Method Not Allowed"; break; case 413: message = "Request Entity Too Large"; break; case 502: message = "Remote Page is Unavailable"; break; case 500: message = "Internal Server Error"; break; default: if (code < 100) reason = g_strdup_printf ("%u Continue", code); else if (code < 200) reason = g_strdup_printf ("%u OK", code); else if (code < 300) reason = g_strdup_printf ("%u Moved", code); else reason = g_strdup_printf ("%u Failed", code); message = reason; break; } } g_debug ("%s: returning error: %u %s", self->logname, code, message); if (cockpit_web_failure_resource) { input = g_resources_lookup_data (cockpit_web_failure_resource, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); if (input == NULL) { g_critical ("couldn't load: %s: %s", cockpit_web_failure_resource, error->message); g_error_free (error); } } if (!input) input = g_bytes_new_static (default_failure_template, strlen (default_failure_template)); if (headers) { if (!g_hash_table_lookup (headers, "Content-Type")) g_hash_table_replace (headers, g_strdup ("Content-Type"), g_strdup ("text/html; charset=utf8")); cockpit_web_response_headers_full (self, code, message, -1, headers); } else { cockpit_web_response_headers (self, code, message, -1, "Content-Type", "text/html; charset=utf8", NULL); } output = cockpit_template_expand (input, substitute_message, (gpointer)message); g_bytes_unref (input); for (l = output; l != NULL; l = g_list_next (l)) { if (!cockpit_web_response_queue (self, l->data)) break; } if (l == NULL) cockpit_web_response_complete (self); g_list_free_full (output, (GDestroyNotify)g_bytes_unref); g_free (reason); }
int store (dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, const int imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata, const int num, const int total, const gboolean high_quality) { dt_imageio_gallery_t *d = (dt_imageio_gallery_t *)sdata; char filename[DT_MAX_PATH_LEN]= {0}; char dirname[DT_MAX_PATH_LEN]= {0}; gboolean from_cache = FALSE; dt_image_full_path(imgid, dirname, DT_MAX_PATH_LEN, &from_cache); // we're potentially called in parallel. have sequence number synchronized: dt_pthread_mutex_lock(&darktable.plugin_threadsafe); { char tmp_dir[DT_MAX_PATH_LEN]; d->vp->filename = dirname; d->vp->jobcode = "export"; d->vp->imgid = imgid; d->vp->sequence = num; dt_variables_expand(d->vp, d->filename, TRUE); g_strlcpy(tmp_dir, dt_variables_get_result(d->vp), DT_MAX_PATH_LEN); // if filenamepattern is a directory just let att ${FILE_NAME} as default.. if ( g_file_test(tmp_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) || ((d->filename+strlen(d->filename)-1)[0]=='/' || (d->filename+strlen(d->filename)-1)[0]=='\\') ) snprintf (d->filename+strlen(d->filename), DT_MAX_PATH_LEN-strlen(d->filename), "/$(FILE_NAME)"); // avoid braindead export which is bound to overwrite at random: if(total > 1 && !g_strrstr(d->filename, "$")) { snprintf(d->filename+strlen(d->filename), DT_MAX_PATH_LEN-strlen(d->filename), "_$(SEQUENCE)"); } gchar* fixed_path = dt_util_fix_path(d->filename); g_strlcpy(d->filename, fixed_path, DT_MAX_PATH_LEN); g_free(fixed_path); dt_variables_expand(d->vp, d->filename, TRUE); g_strlcpy(filename, dt_variables_get_result(d->vp), DT_MAX_PATH_LEN); g_strlcpy(dirname, filename, DT_MAX_PATH_LEN); const char *ext = format->extension(fdata); char *c = dirname + strlen(dirname); for(; c>dirname && *c != '/'; c--); if(*c == '/') *c = '\0'; if(g_mkdir_with_parents(dirname, 0755)) { fprintf(stderr, "[imageio_storage_gallery] could not create directory: `%s'!\n", dirname); dt_control_log(_("could not create directory `%s'!"), dirname); dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); return 1; } // store away dir. snprintf(d->cached_dirname, DT_MAX_PATH_LEN, "%s", dirname); c = filename + strlen(filename); for(; c>filename && *c != '.' && *c != '/' ; c--); if(c <= filename || *c=='/') c = filename + strlen(filename); sprintf(c,".%s",ext); // save image to list, in order: pair_t *pair = malloc(sizeof(pair_t)); char *title = NULL, *description = NULL; GList *res_title, *res_desc; res_title = dt_metadata_get(imgid, "Xmp.dc.title", NULL); if(res_title) { title = res_title->data; } res_desc = dt_metadata_get(imgid, "Xmp.dc.description", NULL); if(res_desc) { description = res_desc->data; } char relfilename[256], relthumbfilename[256]; c = filename + strlen(filename); for(; c>filename && *c != '/' ; c--); if(*c == '/') c++; if(c <= filename) c = filename; snprintf(relfilename, sizeof(relfilename), "%s", c); snprintf(relthumbfilename, sizeof(relthumbfilename), "%s", relfilename); c = relthumbfilename + strlen(relthumbfilename); for(; c>relthumbfilename && *c != '.'; c--); if(c <= relthumbfilename) c = relthumbfilename + strlen(relthumbfilename); sprintf(c, "-thumb.%s", ext); char subfilename[DT_MAX_PATH_LEN], relsubfilename[256]; snprintf(subfilename, DT_MAX_PATH_LEN, "%s", d->cached_dirname); char* sc = subfilename + strlen(subfilename); sprintf(sc, "/img_%d.html", num); sprintf(relsubfilename, "img_%d.html", num); snprintf(pair->line, sizeof(pair->line), "\n" " <div><a class=\"dia\" rel=\"lightbox[viewer]\" title=\"%s - %s\" href=\"%s\"><span></span><img src=\"%s\" alt=\"img%d\" class=\"img\"/></a>\n" " <h1>%s</h1>\n" " %s</div>\n", title?title:relfilename, description?description:" ", relfilename, relthumbfilename, num, title?title:" ", description?description:" "); char next[256]; sprintf(next, "img_%d.html", (num)%total+1); char prev[256]; sprintf(prev, "img_%d.html", (num==1)?total:num-1); pair->pos = num; if(res_title) g_list_free_full(res_title, &g_free); if(res_desc) g_list_free_full(res_desc, &g_free); d->l = g_list_insert_sorted(d->l, pair, (GCompareFunc)sort_pos); } // end of critical block dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); /* export image to file */ if(dt_imageio_export(imgid, filename, format, fdata, high_quality,FALSE,self,sdata) != 0) { fprintf(stderr, "[imageio_storage_gallery] could not export to file: `%s'!\n", filename); dt_control_log(_("could not export to file `%s'!"), filename); return 1; } /* also export thumbnail: */ // write with reduced resolution: const int max_width = fdata->max_width; const int max_height = fdata->max_height; fdata->max_width = 200; fdata->max_height = 200; // alter filename with -thumb: char *c = filename + strlen(filename); for(; c>filename && *c != '.' && *c != '/' ; c--); if(c <= filename || *c=='/') c = filename + strlen(filename); const char *ext = format->extension(fdata); sprintf(c,"-thumb.%s",ext); if(dt_imageio_export(imgid, filename, format, fdata, FALSE,FALSE,self,sdata) != 0) { fprintf(stderr, "[imageio_storage_gallery] could not export to file: `%s'!\n", filename); dt_control_log(_("could not export to file `%s'!"), filename); return 1; } // restore for next image: fdata->max_width = max_width; fdata->max_height = max_height; printf("[export_job] exported to `%s'\n", filename); char *trunc = filename + strlen(filename) - 32; if(trunc < filename) trunc = filename; dt_control_log(_("%d/%d exported to `%s%s'"), num, total, trunc != filename ? ".." : "", trunc); return 0; }
static void _traverse_paths (GList **pvlist, const char *path) { GList *children, *iter; char *value = NULL; size_t vsize; /* Look for a value - db first */ if (!db_get (path, (unsigned char**)&value, &vsize)) { /* Provide next */ value = provide_get (path); } if (value) { Apteryx__PathValue *pv = NULL; /* Allocate a new pv */ pv = g_malloc0 (sizeof (Apteryx__PathValue)); pv->path = g_strdup (path); pv->value = value; /* Add to the list */ *pvlist = g_list_prepend (*pvlist, pv); } /* Check for children - index first */ char *path_s = g_strdup_printf ("%s/", path); if (!index_get (path_s, &children)) { /* Search database next */ children = db_search (path_s); /* Append any provided paths */ GList *providers = NULL; providers = cb_match (&provide_list, path_s, CB_MATCH_PART); for (iter = providers; iter; iter = g_list_next (iter)) { cb_info_t *provider = iter->data; char *ptr, *ppath; int len = strlen (path_s); if (strcmp (provider->path, path_s) == 0) continue; ppath = g_strdup (provider->path); if ((ptr = strchr (&ppath[len+1], '/')) != 0) *ptr = '\0'; if (!g_list_find_custom (children, ppath, (GCompareFunc) strcmp)) children = g_list_prepend (children, ppath); else g_free (ppath); } g_list_free_full (providers, (GDestroyNotify) cb_release); } for (iter = children; iter; iter = g_list_next (iter)) { _traverse_paths (pvlist, (const char *) iter->data); } g_list_free_full (children, g_free); g_free (path_s); }
static void _dt_history_cleanup_multi_instance(int imgid, int minnum) { /* as we let the user decide which history item to copy, we can end with some gaps in multi-instance numbering. for ex., if user decide to not copy the 2nd instance of a module which as 3 instances. let's clean-up the history multi-instance. What we want to do is have a unique multi_priority value for each iop. Furthermore this value must start to 0 and increment one by one for each multi-instance of the same module. On SQLite there is no notion of ROW_NUMBER, so we use rather resource consuming SQL statement, but as an history has never a huge number of items that's not a real issue. We only do this for the given imgid and only for num>minnum, that is we only handle new history items just copied. */ typedef struct _history_item_t { int num; char op[1024]; int mi; int new_mi; } _history_item_t; // we first reload all the newly added history item sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT num, operation, multi_priority FROM " "main.history WHERE imgid=?1 AND num>=?2 ORDER BY " "operation, multi_priority", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, minnum); GList *hitems = NULL; while(sqlite3_step(stmt) == SQLITE_ROW) { const char *op = (const char *)sqlite3_column_text(stmt, 1); GList *modules = darktable.iop; while (modules) { dt_iop_module_so_t *find_op = (dt_iop_module_so_t *)(modules->data); if (!strcmp(find_op->op, op)) { break; } modules = g_list_next(modules); } if (modules && (((dt_iop_module_so_t *)(modules->data))->flags() & IOP_FLAGS_ONE_INSTANCE)) { // the current module is a single-instance one, so there's no point in trying to mess up our multi_priority value continue; } _history_item_t *hi = (_history_item_t *)calloc(1, sizeof(_history_item_t)); hi->num = sqlite3_column_int(stmt, 0); snprintf(hi->op, sizeof(hi->op), "%s", sqlite3_column_text(stmt, 1)); hi->mi = sqlite3_column_int(stmt, 2); hi->new_mi = -5; // means : not changed atm hitems = g_list_append(hitems, hi); } sqlite3_finalize(stmt); // then we change the multi-priority to be sure to have a correct numbering char op[1024] = ""; int c_mi = 0; int nb_change = 0; GList *items = g_list_first(hitems); while(items) { _history_item_t *hi = (_history_item_t *)(items->data); if(strcmp(op, hi->op) != 0) { g_strlcpy(op, hi->op, sizeof(op)); c_mi = 0; } if(hi->mi != c_mi) nb_change++; hi->new_mi = c_mi; c_mi++; items = g_list_next(items); } if(nb_change == 0) { // everything is ok, nothing to change g_list_free_full(hitems, free); return; } // and we update the history items char *req = NULL; req = dt_util_dstrcat(req, "%s", "UPDATE main.history SET multi_priority = CASE num "); items = g_list_first(hitems); while(items) { _history_item_t *hi = (_history_item_t *)(items->data); if(hi->mi != hi->new_mi) { req = dt_util_dstrcat(req, "WHEN %d THEN %d ", hi->num, hi->new_mi); } items = g_list_next(items); } req = dt_util_dstrcat(req, "%s", "else multi_priority end where imgid=?1 and num>=?2"); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), req, -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, minnum); sqlite3_step(stmt); sqlite3_finalize(stmt); g_free(req); g_list_free_full(hitems, free); }
static int validate_set (const char *path, const char *value) { GList *validators = NULL; GList *iter = NULL; int32_t result = 0; /* Retrieve a list of validators for this path */ validators = cb_match (&validation_list, path, CB_MATCH_EXACT|CB_MATCH_WILD|CB_MATCH_CHILD|CB_MATCH_WILD_PATH); if (!validators) return 0; /* Protect sensitive values with this lock - released in apteryx_set */ pthread_mutex_lock (&validating); /* Call each validator */ for (iter = validators; iter; iter = g_list_next (iter)) { cb_info_t *validator = iter->data; ProtobufCService *rpc_client; Apteryx__Validate validate = APTERYX__VALIDATE__INIT; /* Check for local validator */ if (validator->id == getpid ()) { apteryx_watch_callback cb = (apteryx_watch_callback) (long) validator->cb; DEBUG ("VALIDATE LOCAL \"%s\" (0x%"PRIx64",0x%"PRIx64")\n", validator->path, validator->id, validator->cb); cb (path, value); continue; } DEBUG ("VALIDATE CB %s = %s (0x%"PRIx64",0x%"PRIx64")\n", validator->path, value, validator->id, validator->cb); /* Setup IPC */ rpc_client = rpc_client_connect (rpc, validator->uri); if (!rpc_client) { /* Throw away the no good validator */ ERROR ("Invalid VALIDATE CB %s (0x%"PRIx64",0x%"PRIx64")\n", validator->path, validator->id, validator->cb); cb_destroy (validator); INC_COUNTER (counters.validated_no_handler); continue; } /* Do remote validate */ validate.path = (char *)path; validate.value = (char *)value; validate.id = validator->id; validate.cb = validator->cb; apteryx__client__validate (rpc_client, &validate, handle_validate_response, &result); if (result < 0) { DEBUG ("Set of %s to %s rejected by process %"PRIu64" (%d)\n", (char *)path, (char*)value, validator->id, result); INC_COUNTER (counters.validated_timeout); rpc_client_release (rpc, rpc_client, false); break; } else { rpc_client_release (rpc, rpc_client, true); } INC_COUNTER (counters.validated); } g_list_free_full (validators, (GDestroyNotify) cb_release); /* This one is fine, but lock is still held */ return result < 0 ? result : 1; }
static void update_progress_for_device (const gchar *operation, const gchar *dev, double progress) { StorageDaemon *daemon; StorageManager *manager; GList *jobs, *l; daemon = storage_daemon_get (); manager = storage_daemon_get_manager (daemon); jobs = storage_daemon_get_jobs (daemon); for (l = jobs; l; l = g_list_next (l)) { UDisksJob *job = l->data; const gchar *const *job_objects; int i; if (g_strcmp0 (udisks_job_get_operation (job), operation) != 0) continue; job_objects = udisks_job_get_objects (job); for (i = 0; job_objects[i]; i++) { StorageBlock *block; gboolean found = FALSE; block = storage_manager_find_block (manager, job_objects[i]); if (block) { if (g_strcmp0 (storage_block_get_device (block), dev) == 0) { found = TRUE; } else { const gchar **symlinks; int j; symlinks = storage_block_get_symlinks (block); for (j = 0; symlinks[j]; j++) { if (g_strcmp0 (symlinks[j], dev) == 0) { found = TRUE; break; } } } } if (found) { udisks_job_set_progress (job, progress); udisks_job_set_progress_valid (job, TRUE); } } } g_list_free_full (jobs, g_object_unref); }