static gchar* get_time_string (gint minutes) { static gchar time_string[STR_LTH]; static gchar minutes_string[STR_LTH]; gint hours; if (minutes < 0) { return NULL; } hours = minutes / 60; minutes = minutes % 60; if (hours > 0) { g_sprintf (minutes_string, g_dngettext (NULL, "%d minute", "%d minutes", minutes), minutes); g_sprintf (time_string, g_dngettext (NULL, "%d hour, %s remaining", "%d hours, %s remaining", hours), hours, minutes_string); } else { g_sprintf (time_string, g_dngettext (NULL, "%d minute remaining", "%d minutes remaining", minutes), minutes); } if (configuration.debug_output == TRUE) { g_printf (_("time string: %s\n"), time_string); } return time_string; }
/*! * \brief Check and - if huge - let the user confirm the diagram size before export */ gboolean confirm_export_size (Diagram *dia, GtkWindow *parent, guint flags) { GtkWidget *dialog; int pages = 0; gint64 bytes = 0; gchar *size, *msg; gboolean ret; pages = ceil((dia->data->extents.right - dia->data->extents.left) / dia->data->paper.width) * ceil((dia->data->extents.bottom - dia->data->extents.top) / dia->data->paper.height); /* three guesses: 4 bytes per pixel, 20 pixels per cm; using * dia->data->paper.scaling */ bytes = (gint64)4 * ceil((dia->data->extents.right - dia->data->extents.left) * dia->data->paper.scaling * 20) * ceil((dia->data->extents.bottom - dia->data->extents.top) * dia->data->paper.scaling * 20); if ((flags & CONFIRM_PRINT) && (pages < 10)) /* hardcoded limits for the dialog to show */ return TRUE; else if ((flags & CONFIRM_MEMORY) && (bytes < (G_GINT64_CONSTANT(100)<<16))) return TRUE; /* smaller than 100MB */ else if ((flags & CONFIRM_PAGES) && (pages < 50)) return TRUE; /* message and limits depend on the flags give */ size = g_format_size (bytes); /* See: https://live.gnome.org/TranslationProject/DevGuidelines/Plurals */ if (flags & CONFIRM_PRINT) msg = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "You are about to print a diagram with %d page.", /* not triggered */ "You are about to print a diagram with %d pages.", pages), pages); else if ((flags & ~CONFIRM_PAGES) == 0) msg = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "You are about to export a diagram with %d page.", /* not triggered */ "You are about to export a diagram with %d pages.", pages), pages); else msg = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "You are about to export a diagram which may require %s of memory.(%d page).", "You are about to export a diagram which may require %s of memory.(%d pages).", pages), size, pages); dialog = gtk_message_dialog_new (parent, /* diagrams display 'shell' */ GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK_CANCEL, "%s", msg); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("You can adjust the size of the diagram by changing " "the 'Scaling' in the 'Page Setup' dialog.\n" "Alternatively use 'Best Fit' " "to move objects/handles into the intended bounds.")); gtk_window_set_title (GTK_WINDOW (dialog), _("Confirm Diagram Size")); g_free (size); g_signal_connect(G_OBJECT (dialog), "response", G_CALLBACK(confirm_respond), NULL); ret = (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog))); gtk_widget_destroy(dialog); return ret; }
/* geany_xml_encode_notify * * Display a status notification message saying how many entities were * encoded. */ static void geany_xml_encode_notify(GeanyDocument* document, int count) { assert(document); if (count) { gchar const* file_name = g_path_get_basename(DOC_FILENAME(document)); // Statusbar message for %n replacements in file %s gchar const* msg = g_dngettext( NULL, "%s: replaced %d XML special character with an entity reference.", "%s: replaced %d XML special characters with entity references.", count ); ui_set_statusbar(TRUE, msg, file_name, count); g_free((gchar*)file_name); } else { // Statusbar message when no replacements were done ui_set_statusbar(FALSE, _("No XML special characters found.")); } }
/** * g_format_size: * @size: a size in bytes * * Formats a size (for example the size of a file) into a human readable * string. Sizes are rounded to the nearest size prefix (kB, MB, GB) * and are displayed rounded to the nearest tenth. E.g. the file size * 3292528 bytes will be converted into the string "3.2 MB". * * The prefix units base is 1000 (i.e. 1 kB is 1000 bytes). * * This string should be freed with g_free() when not needed any longer. * * See g_format_size_full() for more options about how the size might be * formatted. * * Returns: a newly-allocated formatted string containing a human readable * file size * * Since: 2.30 */ gchar * g_format_size (guint64 size) { GString *string; string = g_string_new (NULL); if (size < KILOBYTE_FACTOR) { g_string_printf (string, g_dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes", (guint) size), (guint) size); } else if (size < MEGABYTE_FACTOR) g_string_printf (string, _("%.1f kB"), (gdouble) size / (gdouble) KILOBYTE_FACTOR); else if (size < GIGABYTE_FACTOR) g_string_printf (string, _("%.1f MB"), (gdouble) size / (gdouble) MEGABYTE_FACTOR); else if (size < TERABYTE_FACTOR) g_string_printf (string, _("%.1f GB"), (gdouble) size / (gdouble) GIGABYTE_FACTOR); else if (size < PETABYTE_FACTOR) g_string_printf (string, _("%.1f TB"), (gdouble) size / (gdouble) TERABYTE_FACTOR); else if (size < EXABYTE_FACTOR) g_string_printf (string, _("%.1f PB"), (gdouble) size / (gdouble) PETABYTE_FACTOR); else g_string_printf (string, _("%.1f EB"), (gdouble) size / (gdouble) EXABYTE_FACTOR); return g_string_free (string, FALSE); }
static void update_selection_status (DialogData *data) { GList *file_list; int n_selected; goffset size_selected; GList *scan; char *size_selected_formatted; char *text_selected; file_list = get_files_to_download (data); n_selected = 0; size_selected = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; n_selected++; size_selected += g_file_info_get_size (file_data->info); } size_selected_formatted = g_format_size (size_selected); text_selected = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_selected), n_selected, size_selected_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text_selected); g_free (text_selected); g_free (size_selected_formatted); _g_object_list_unref (file_list); }
static const gchar * xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon) { XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon); if(!special_file_icon->priv->tooltip) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(!info) return NULL; if(XFDESKTOP_SPECIAL_FILE_ICON_TRASH == special_file_icon->priv->type) { if(special_file_icon->priv->trash_item_count == 0) { special_file_icon->priv->tooltip = g_strdup(_("Trash is empty")); } else { special_file_icon->priv->tooltip = g_strdup_printf(g_dngettext(GETTEXT_PACKAGE, _("Trash contains one item"), _("Trash contains %d items"), special_file_icon->priv->trash_item_count), special_file_icon->priv->trash_item_count); } } else { const gchar *description; gchar *size_string, *time_string; guint64 size, mtime; if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_FILESYSTEM) description = _("File System"); else if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_HOME) description = _("Home"); else { description = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION); } size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE); size_string = g_format_size(size); mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED); time_string = xfdesktop_file_utils_format_time_for_display(mtime); special_file_icon->priv->tooltip = g_strdup_printf(_("%s\nSize: %s\nLast modified: %s"), description, size_string, time_string); g_free(size_string); g_free(time_string); } } return special_file_icon->priv->tooltip; }
const gchar * gtr_ngettext( const gchar * msgid, const gchar * msgid_plural, gulong n ) { #if GLIB_CHECK_VERSION( 2, 18, 0 ) return g_dngettext( NULL, msgid, msgid_plural, n ); #else return ngettext( msgid, msgid_plural, n ); #endif }
G_CONST_RETURN char * aw_item_get_display_name (AwItemType item, int amount) { switch (item) { case AW_ITEM_FARM: return g_dngettext (GETTEXT_PACKAGE, "Farm", "Farms", amount); case AW_ITEM_FACTORY: return g_dngettext (GETTEXT_PACKAGE, "Factory", "Factories", amount); case AW_ITEM_CYBERNET: return g_dngettext (GETTEXT_PACKAGE, "Cybernet", "Cybernets", amount); case AW_ITEM_LABORATORY: return g_dngettext (GETTEXT_PACKAGE, "Laboratory", "Laboratories", amount); case AW_ITEM_STARBASE: return g_dngettext (GETTEXT_PACKAGE, "Starbase", "Starbases", amount); case AW_ITEM_TRANSPORT: return g_dngettext (GETTEXT_PACKAGE, "Transport", "Transports", amount); case AW_ITEM_COLONY_SHIP: return g_dngettext (GETTEXT_PACKAGE, "Colony Ship", "Colony Ships", amount); case AW_ITEM_DESTROYER: return g_dngettext (GETTEXT_PACKAGE, "Destroyer", "Destroyers", amount); case AW_ITEM_CRUISER: return g_dngettext (GETTEXT_PACKAGE, "Cruiser", "Cruisers", amount); case AW_ITEM_BATTLESHIP: return g_dngettext (GETTEXT_PACKAGE, "Battleship", "Battleships", amount); case AW_ITEM_TRADE: return _("Interstellar Trade"); case AW_ITEM_INVALID: case AW_ITEM_LAST: break; } return NULL; }
static void update_selection_status (DialogData *data) { GList *file_list; int n_selected; char *text_selected; file_list = get_files_to_download (data); n_selected = g_list_length (file_list); text_selected = g_strdup_printf (g_dngettext (NULL, "%d file", "%d files", n_selected), n_selected); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text_selected); g_free (text_selected); _g_object_list_unref (file_list); }
/* Runs the wipe operation */ static void nw_extension_run_delete_operation (GtkWindow *parent, GList *files) { gchar *confirm_primary_text = NULL; guint n_items; n_items = g_list_length (files); if (n_items > 1) { confirm_primary_text = g_strdup_printf (g_dngettext(GETTEXT_PACKAGE, /* TRANSLATORS: singular is not really used, N is strictly >1 */ "Are you sure you want " "to wipe the %u " "selected items?", /* plural form */ "Are you sure you want " "to wipe the %u " "selected items?", n_items), n_items); } else if (n_items > 0) { gchar *name; name = g_filename_display_basename (files->data); confirm_primary_text = g_strdup_printf (_("Are you sure you want to wipe " "\"%s\"?"), name); g_free (name); } nw_operation_manager_run ( parent, files, /* confirm dialog */ confirm_primary_text, _("If you wipe an item, it will not be recoverable."), _("_Wipe"), gtk_image_new_from_stock (GTK_STOCK_DELETE, GTK_ICON_SIZE_BUTTON), /* progress dialog */ _("Wiping files..."), /* operation launcher */ nw_delete_operation_new (), /* failed dialog */ _("Wipe failed."), /* success dialog */ _("Wipe successful."), _("Item(s) have been successfully wiped.") ); g_free (confirm_primary_text); }
static gboolean ip4_routes_transform_to_description (GBinding *binding, const GValue *source_value, GValue *target_value, gpointer user_data) { GPtrArray *routes; char *text; routes = g_value_get_boxed (source_value); if (!routes || !routes->len) text = g_strdup (_("(No custom routes)")); else { text = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "One custom route", "%d custom routes", routes->len), routes->len); } g_value_take_string (target_value, text); return TRUE; }
gint tracker_process_stop (TrackerProcessTypes daemons_to_term, TrackerProcessTypes daemons_to_kill) { GSList *pids, *l; gchar *str; if (daemons_to_kill == TRACKER_PROCESS_TYPE_NONE && daemons_to_term == TRACKER_PROCESS_TYPE_NONE) { return 0; } pids = tracker_process_find_all (); str = g_strdup_printf (g_dngettext (NULL, "Found %d PID…", "Found %d PIDs…", g_slist_length (pids)), g_slist_length (pids)); g_print ("%s\n", str); g_free (str); for (l = pids; l; l = l->next) { TrackerProcessData *pd; const gchar *basename; pid_t pid; pd = l->data; basename = pd->cmd; pid = pd->pid; if (daemons_to_term != TRACKER_PROCESS_TYPE_NONE) { if ((daemons_to_term == TRACKER_PROCESS_TYPE_STORE && !g_str_has_suffix (basename, "tracker-store")) || (daemons_to_term == TRACKER_PROCESS_TYPE_MINERS && !strstr (basename, "tracker-miner"))) { continue; } if (kill (pid, SIGTERM) == -1) { const gchar *errstr = g_strerror (errno); str = g_strdup_printf (_("Could not terminate process %d — “%s”"), pid, basename); g_printerr (" %s: %s\n", str, errstr ? errstr : _("No error given")); g_free (str); } else { str = g_strdup_printf (_("Terminated process %d — “%s”"), pid, basename); g_print (" %s\n", str); g_free (str); } } else if (daemons_to_kill != TRACKER_PROCESS_TYPE_NONE) { if ((daemons_to_kill == TRACKER_PROCESS_TYPE_STORE && !g_str_has_suffix (basename, "tracker-store")) || (daemons_to_kill == TRACKER_PROCESS_TYPE_MINERS && !strstr (basename, "tracker-miner"))) { continue; } if (kill (pid, SIGKILL) == -1) { const gchar *errstr = g_strerror (errno); str = g_strdup_printf (_("Could not kill process %d — “%s”"), pid, basename); g_printerr (" %s: %s\n", str, errstr ? errstr : _("No error given")); g_free (str); } else { str = g_strdup_printf (_("Killed process %d — “%s”"), pid, basename); g_print (" %s\n", str); g_free (str); } } } g_slist_foreach (pids, (GFunc) tracker_process_data_free, NULL); g_slist_free (pids); return 0; }
void dlg_export_to_picasaweb (GthBrowser *browser, GList *file_list) { DialogData *data; GtkTreeSelection *selection; GList *scan; int n_total; goffset total_size; char *total_size_formatted; char *text; data = g_new0 (DialogData, 1); data->browser = browser; data->settings = g_settings_new (GTHUMB_PICASAWEB_SCHEMA); data->location = gth_file_data_dup (gth_browser_get_location_data (browser)); data->builder = _gtk_builder_new_from_file ("export-to-picasaweb.ui", "picasaweb"); data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog"); data->cancellable = g_cancellable_new (); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("name_treeviewcolumn")); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", ALBUM_NAME_COLUMN, NULL); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_EMBLEM_COLUMN, NULL); } _gtk_window_resize_to_fit_screen_height (data->dialog, 500); data->file_list = NULL; n_total = 0; total_size = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; const char *mime_type; mime_type = gth_file_data_get_mime_type (file_data); if (g_content_type_equals (mime_type, "image/bmp") || g_content_type_equals (mime_type, "image/gif") || g_content_type_equals (mime_type, "image/jpeg") || g_content_type_equals (mime_type, "image/png")) { total_size += g_file_info_get_size (file_data->info); n_total++; data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data)); } } data->file_list = g_list_reverse (data->file_list); if (data->file_list == NULL) { GError *error; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected.")); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), error); g_clear_error (&error); destroy_dialog (data); return; } total_size_formatted = g_format_size (total_size); text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text); g_free (text); g_free (total_size_formatted); /* Set the widget data */ data->list_view = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NO_SELECTION, FALSE); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE); gtk_widget_show (data->list_view); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0); gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("album_liststore")), ALBUM_NAME_COLUMN, GTK_SORT_ASCENDING); gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH) != -1); _gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_HEIGHT)); /* Set the signals handlers. */ g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (export_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("add_album_button"), "clicked", G_CALLBACK (add_album_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("resize_checkbutton"), "toggled", G_CALLBACK (resize_checkbutton_toggled_cb), data); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview"))); gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect (selection, "changed", G_CALLBACK (albums_treeview_selection_changed_cb), data); update_sensitivity (data); data->service = picasa_web_service_new (data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (service_account_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (service_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service)); web_service_autoconnect (WEB_SERVICE (data->service)); }
/** * pk_action_lookup_get_message: **/ static gchar * pk_action_lookup_get_message (PolkitBackendActionLookup *lookup, const gchar *action_id, PolkitDetails *details, PolkitActionDescription *action_description) { PkRoleEnum role = PK_ROLE_ENUM_UNKNOWN; gboolean only_trusted = TRUE; const gchar *cmdline; const gchar *role_text; const gchar *only_trusted_text; const gchar *str; const gchar *text; gchar *message = NULL; gchar **package_ids = NULL; GString *string; guint len = 1; if (!g_str_has_prefix (action_id, "org.freedesktop.packagekit.")) goto out; /* get role */ role_text = polkit_details_lookup (details, "role"); if (role_text != NULL) role = pk_role_enum_from_string (role_text); /* get only-trusted */ only_trusted_text = polkit_details_lookup (details, "only-trusted"); if (only_trusted_text != NULL) only_trusted = g_str_equal (only_trusted_text, "true"); /* get the command line */ cmdline = polkit_details_lookup (details, "cmdline"); if (role == PK_ROLE_ENUM_REPO_ENABLE && pk_action_lookup_cmdline_is_debuginfo_install (cmdline)) { message = g_strdup (N_("To install debugging packages, extra sources need to be enabled")); goto out; } /* use the message shipped in the policy file */ if (only_trusted) goto out; /* find out the number of packages so we pluralize corectly */ str = polkit_details_lookup (details, "package_ids"); if (str != NULL) { package_ids = pk_package_ids_from_string (str); len = g_strv_length (package_ids); g_strfreev (package_ids); } /* UpdatePackages */ if (role == PK_ROLE_ENUM_UPDATE_PACKAGES) { string = g_string_new (""); /* TRANSLATORS: is not GPG signed */ g_string_append (string, g_dgettext (GETTEXT_PACKAGE, N_("The software is not from a trusted source."))); g_string_append (string, "\n"); /* TRANSLATORS: user has to trust provider -- I know, this sucks */ text = g_dngettext (GETTEXT_PACKAGE, N_("Do not update this package unless you are sure it is safe to do so."), N_("Do not update these packages unless you are sure it is safe to do so."), len); g_string_append (string, text); message = g_string_free (string, FALSE); goto out; } /* InstallPackages */ if (role == PK_ROLE_ENUM_INSTALL_PACKAGES) { string = g_string_new (""); /* TRANSLATORS: is not GPG signed */ g_string_append (string, g_dgettext (GETTEXT_PACKAGE, N_("The software is not from a trusted source."))); g_string_append (string, "\n"); /* TRANSLATORS: user has to trust provider -- I know, this sucks */ text = g_dngettext (GETTEXT_PACKAGE, N_("Do not install this package unless you are sure it is safe to do so."), N_("Do not install these packages unless you are sure it is safe to do so."), len); g_string_append (string, text); message = g_string_free (string, FALSE); goto out; } out: return message; }
static gboolean _dtv_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip) { int bin_x, bin_y; GtkTreePath *path = NULL; GtkTreeViewColumn *column; GtkTreeIter iter; GtkTreeModel *model; GdkRectangle cell_area; GString *markup; gboolean had_info = FALSE; gtk_tree_view_convert_widget_to_bin_window_coords ( GTK_TREE_VIEW (widget), x, y, &bin_x, &bin_y); if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), bin_x, bin_y, &path, &column, NULL, NULL)) { model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); if (gtk_tree_model_get_iter (model, &iter, path)) { /* show some useful information */ Diagram *diagram; Layer *layer; DiaObject *object; gtk_tree_model_get (model, &iter, DIAGRAM_COLUMN, &diagram, -1); gtk_tree_model_get (model, &iter, LAYER_COLUMN, &layer, -1); gtk_tree_model_get (model, &iter, OBJECT_COLUMN, &object, -1); markup = g_string_new (NULL); if (diagram) { gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Diagram"), diagram->filename); g_string_append (markup, em); g_free (em); } if (layer) { gchar *name = layer_get_name (layer); gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Layer"), name); g_string_append (markup, em); g_free (em); g_free (name); } else if (diagram) { int layers = data_layer_count (DIA_DIAGRAM_DATA (diagram)); g_string_append_printf (markup, g_dngettext (GETTEXT_PACKAGE, "%d Layer", "%d Layers", layers), layers); } if (object) { gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Type"), object->type->name); g_string_append (markup, em); g_free (em); g_string_append_printf (markup, "<b>%s</b>: %g,%g\n", Q_("object|Position"), object->position.x, object->position.y); g_string_append_printf (markup, "%d %s", g_list_length (object->children), _("Children")); /* and some dia_object_get_meta ? */ } else if (layer) { int objects = layer_object_count (layer); g_string_append_printf (markup, g_dngettext (GETTEXT_PACKAGE, "%d Object", "%d Objects", objects), objects); } if (markup->len > 0) { gtk_tree_view_get_cell_area (GTK_TREE_VIEW (widget), path, column, &cell_area); gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (widget), cell_area.x, cell_area.y, &cell_area.x, &cell_area.y); gtk_tooltip_set_tip_area (tooltip, &cell_area); gtk_tooltip_set_markup (tooltip, markup->str); had_info = TRUE; } /* drop references */ if (diagram) g_object_unref (diagram); g_string_free (markup, TRUE); } gtk_tree_path_free (path); if (had_info) return TRUE; } return GTK_WIDGET_CLASS (_dtv_parent_class)->query_tooltip (widget, x, y, keyboard_mode, tooltip); }
static char * gdk_x11_app_launch_context_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; GdkDisplay *display; GdkX11Screen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; GIcon *icon; guint32 timestamp; char *startup_id; GFileInfo *fileinfo; GdkAppLaunchContext *ctx; ctx = GDK_APP_LAUNCH_CONTEXT (context); display = ctx->display; screen = GDK_X11_DISPLAY (display)->screen; fileinfo = NULL; files_count = g_list_length (files); if (files_count == 0) { description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); } else if (files_count == 1) { gchar *display_name; if (g_file_is_native (files->data)) fileinfo = g_file_query_info (files->data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_ICON, 0, NULL, NULL); display_name = get_display_name (files->data, fileinfo); description = g_strdup_printf (_("Opening %s"), display_name); g_free (display_name); } else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; if (ctx->icon_name) icon_name = g_strdup (ctx->icon_name); else { icon = NULL; if (ctx->icon != NULL) icon = g_object_ref (ctx->icon); else if (files_count == 1) icon = get_icon (files->data, fileinfo); if (icon == NULL) { icon = g_app_info_get_icon (info); if (icon != NULL) g_object_ref (icon); } if (icon != NULL) { icon_name = gicon_to_string (icon); g_object_unref (icon); } } binary_name = g_app_info_get_executable (info); timestamp = ctx->timestamp; if (timestamp == GDK_CURRENT_TIME) timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_x11_screen_get_screen_number (screen)); if (ctx->workspace > -1) workspace_str = g_strdup_printf ("%d", ctx->workspace); else workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); if (fileinfo) g_object_unref (fileinfo); add_startup_timeout (screen, startup_id); return startup_id; }
static void load_chain (PatrolDialogWindow *self, PatrolDialogRecord *r, guint idx, GtkWidget *container) { /* build tree model */ GtkTreeStore *tree_store = gtk_tree_store_new(COLS_NUM, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_POINTER); GtkTreeIter *parent = NULL, iter; gint i, num_certs = gcr_certificate_chain_get_length(r->chain); GcrCertificate *cert = NULL; for (i = num_certs - 1; i >= 0; i--) { cert = gcr_certificate_chain_get_certificate(r->chain, i); gchar *label = gcr_certificate_get_subject_name(cert); gtk_tree_store_append(tree_store, &iter, parent); gtk_tree_store_set(tree_store, &iter, COL_NAME, label, COL_PIN, i == r->pin_level, COL_PIN_LEVEL, i, COL_CERT, cert, COL_REC, r, -1); parent = &iter; g_free(label); } /* set hierarchy title */ GtkWidget *title_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start(GTK_BOX(container), title_box, FALSE, FALSE, 0); gchar *text, *str; GtkWidget *label = gtk_label_new(NULL); GtkWidget *value; if (idx == 0) { switch (self->pv->result) { case PATROL_VERIFY_NEW: case PATROL_VERIFY_CHANGE: text = g_strdup_printf("<b>%s</b>", _("New Certificate")); break; case PATROL_VERIFY_REJECT: text = g_strdup_printf("<b>%s</b>", _("Rejected Certificate")); break; default: text = g_strdup_printf("<b>%s</b>", _("Selected Certificate")); break; } } else { text = g_strdup_printf("<b>%s #%d</b>", _("Stored Certificate"), idx); gtk_widget_set_margin_bottom(GTK_WIDGET(label), 2); } gtk_label_set_markup(GTK_LABEL(label), text); g_free(text); gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START); gtk_box_pack_start(GTK_BOX(title_box), label, FALSE, FALSE, 0); GtkWidget *grid = gtk_grid_new(); gtk_widget_set_margin_left(GTK_WIDGET(grid), 5); gtk_box_pack_start(GTK_BOX(title_box), grid, FALSE, FALSE, 0); label = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(label), _("Seen: ")); str = g_strdup_printf("%" G_GINT64_FORMAT, r->rec.count_seen); text = g_strdup_printf(g_dngettext(textdomain(NULL), "%s time", "%s times", r->rec.count_seen), str); g_free(str); value = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(value), text); g_free(text); gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START); gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1); gtk_grid_attach(GTK_GRID(grid), value, 1, 0, 1, 1); label = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(label), _("First seen: ")); GDateTime *dtime = g_date_time_new_from_unix_local(r->rec.first_seen); text = g_date_time_format(dtime, "%c"); g_date_time_unref(dtime); value = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(value), text); g_free(text); gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START); gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(grid), label, 0, 1, 1, 1); gtk_grid_attach(GTK_GRID(grid), value, 1, 1, 1, 1); if (r->rec.first_seen != r->rec.last_seen) { label = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(label), _("Last seen: ")); dtime = g_date_time_new_from_unix_local(r->rec.last_seen); text = g_date_time_format(dtime, "%c"); g_date_time_unref(dtime); value = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(value), text); g_free(text); gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START); gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1); gtk_grid_attach(GTK_GRID(grid), value, 1, 2, 1, 1); } if (cert) { label = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(label), _("Validity: ")); GDate *expiry = gcr_certificate_get_expiry_date(cert); GDate *now = g_date_new(); g_date_set_time_t(now, time(NULL)); gint diff = g_date_days_between(now, expiry); g_date_free(now); g_date_free(expiry); if (diff > 0) { text = g_strdup_printf(g_dngettext(textdomain(NULL), "Certificate is valid for %d more day", "Certificate is valid for %d more days", diff), diff); } else if (diff < 0) { diff = abs(diff); text = g_strdup_printf(g_dngettext(textdomain(NULL), "Certificate <b>expired</b> %d day ago", "Certificate <b>expired</b> %d days ago", diff), diff); } else { text = g_strdup_printf("Certificate expires today"); } value = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(value), text); g_free(text); gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START); gtk_widget_set_halign(GTK_WIDGET(value), GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(grid), label, 0, 3, 1, 1); gtk_grid_attach(GTK_GRID(grid), value, 1, 3, 1, 1); } gtk_widget_show_all(title_box); /* build tree view */ GtkWidget *tree_view; tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store)); gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view)); gtk_box_pack_start(GTK_BOX(container), tree_view, FALSE, FALSE, 0); gtk_widget_show(tree_view); g_signal_connect(tree_view, "focus-in-event", G_CALLBACK(on_tree_view_focus), self); g_signal_connect(self->pv->renderer, "data-changed", G_CALLBACK(on_cert_changed), tree_view); GtkTreeSelection *tree_sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); g_signal_connect(tree_sel, "changed", G_CALLBACK(on_tree_selection_changed), self); if (idx == 0) // new chain gtk_tree_selection_select_iter(tree_sel, &iter); /* first column */ GtkCellRenderer *tree_renderer = gtk_cell_renderer_text_new(); GtkTreeViewColumn *tree_column = gtk_tree_view_column_new_with_attributes(_("Certificate Hierarchy"), tree_renderer, "text", COL_NAME, NULL); gtk_tree_view_column_set_expand (tree_column, TRUE); gtk_tree_view_insert_column (GTK_TREE_VIEW (tree_view), tree_column, -1); /* second column */ GtkCellRenderer *toggle_renderer = gtk_cell_renderer_toggle_new(); g_signal_connect(toggle_renderer, "toggled", G_CALLBACK(on_radio_toggled), tree_store); gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(toggle_renderer), TRUE); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view), -1, _("Pin"), toggle_renderer, "active", COL_PIN, NULL); g_object_unref(tree_store); }
gint tracker_control_general_run (void) { GError *error = NULL; GSList *pids; GSList *l; gchar *str; gpointer verbosity_type_enum_class_pointer = NULL; TrackerVerbosity set_log_verbosity_value = TRACKER_VERBOSITY_ERRORS; /* Constraints */ if (kill_option != TERM_NONE && terminate_option != TERM_NONE) { g_printerr ("%s\n", _("You can not use the --kill and --terminate arguments together")); return EXIT_FAILURE; } if ((hard_reset || soft_reset) && terminate_option != TERM_NONE) { g_printerr ("%s\n", _("You can not use the --terminate with --hard-reset or --soft-reset, --kill is implied")); return EXIT_FAILURE; } if (hard_reset && soft_reset) { g_printerr ("%s\n", _("You can not use the --hard-reset and --soft-reset arguments together")); return EXIT_FAILURE; } if (get_log_verbosity && set_log_verbosity) { g_printerr ("%s\n", _("You can not use the --get-logging and --set-logging arguments together")); return EXIT_FAILURE; } if (set_log_verbosity) { if (g_ascii_strcasecmp (set_log_verbosity, "debug") == 0) { set_log_verbosity_value = TRACKER_VERBOSITY_DEBUG; } else if (g_ascii_strcasecmp (set_log_verbosity, "detailed") == 0) { set_log_verbosity_value = TRACKER_VERBOSITY_DETAILED; } else if (g_ascii_strcasecmp (set_log_verbosity, "minimal") == 0) { set_log_verbosity_value = TRACKER_VERBOSITY_MINIMAL; } else if (g_ascii_strcasecmp (set_log_verbosity, "errors") == 0) { set_log_verbosity_value = TRACKER_VERBOSITY_ERRORS; } else { g_printerr ("%s\n", _("Invalid log verbosity, try 'debug', 'detailed', 'minimal' or 'errors'")); return EXIT_FAILURE; } } if (hard_reset || soft_reset) { /* Imply --kill */ kill_option = TERM_ALL; } if (get_log_verbosity || set_log_verbosity) { GType etype; /* Since we don't reference this enum anywhere, we do * it here to make sure it exists when we call * g_type_class_peek(). This wouldn't be necessary if * it was a param in a GObject for example. * * This does mean that we are leaking by 1 reference * here and should clean it up, but it doesn't grow so * this is acceptable. */ etype = tracker_verbosity_get_type (); verbosity_type_enum_class_pointer = g_type_class_ref (etype); } /* Unless we are stopping processes or listing processes, * don't iterate them. */ if (kill_option != TERM_NONE || terminate_option != TERM_NONE || list_processes) { guint32 own_pid; guint32 own_uid; gchar *own_pid_str; pids = get_pids (); str = g_strdup_printf (g_dngettext (NULL, "Found %d PID…", "Found %d PIDs…", g_slist_length (pids)), g_slist_length (pids)); g_print ("%s\n", str); g_free (str); /* Establish own uid/pid */ own_pid = (guint32) getpid (); own_pid_str = g_strdup_printf ("%d", own_pid); own_uid = get_uid_for_pid (own_pid_str, NULL); g_free (own_pid_str); for (l = pids; l; l = l->next) { GError *error = NULL; gchar *filename; gchar *contents = NULL; gchar **strv; guint uid; uid = get_uid_for_pid (l->data, &filename); /* Stat the file and make sure current user == file owner */ if (uid != own_uid) { continue; } /* Get contents to determine basename */ if (!g_file_get_contents (filename, &contents, NULL, &error)) { str = g_strdup_printf (_("Could not open '%s'"), filename); g_printerr ("%s, %s\n", str, error ? error->message : _("no error given")); g_free (str); g_clear_error (&error); g_free (contents); g_free (filename); continue; } strv = g_strsplit (contents, "^@", 2); if (strv && strv[0]) { gchar *basename; basename = g_path_get_basename (strv[0]); if ((g_str_has_prefix (basename, "tracker") == TRUE || g_str_has_prefix (basename, "lt-tracker") == TRUE) && g_str_has_suffix (basename, "-control") == FALSE && g_str_has_suffix (basename, "-status-icon") == FALSE) { pid_t pid; pid = atoi (l->data); str = g_strdup_printf (_("Found process ID %d for '%s'"), pid, basename); g_print ("%s\n", str); g_free (str); if (terminate_option != TERM_NONE) { if ((terminate_option == TERM_STORE && !g_str_has_suffix (basename, "tracker-store")) || (terminate_option == TERM_MINERS && !strstr (basename, "tracker-miner"))) { continue; } if (kill (pid, SIGTERM) == -1) { const gchar *errstr = g_strerror (errno); str = g_strdup_printf (_("Could not terminate process %d"), pid); g_printerr (" %s, %s\n", str, errstr ? errstr : _("no error given")); g_free (str); } else { str = g_strdup_printf (_("Terminated process %d"), pid); g_print (" %s\n", str); g_free (str); } } else if (kill_option != TERM_NONE) { if ((kill_option == TERM_STORE && !g_str_has_suffix (basename, "tracker-store")) || (kill_option == TERM_MINERS && !strstr (basename, "tracker-miner"))) { continue; } if (kill (pid, SIGKILL) == -1) { const gchar *errstr = g_strerror (errno); str = g_strdup_printf (_("Could not kill process %d"), pid); g_printerr (" %s, %s\n", str, errstr ? errstr : _("no error given")); g_free (str); } else { str = g_strdup_printf (_("Killed process %d"), pid); g_print (" %s\n", str); g_free (str); } } } g_free (basename); } g_strfreev (strv); g_free (contents); g_free (filename); } g_slist_foreach (pids, (GFunc) g_free, NULL); g_slist_free (pids); /* If we just wanted to list processes, all done */ if (list_processes && terminate_option == TERM_NONE && kill_option == TERM_NONE) { return EXIT_SUCCESS; } } if (hard_reset || soft_reset) { guint log_handler_id; #ifndef DISABLE_JOURNAL gchar *rotate_to; TrackerDBConfig *db_config; gsize chunk_size; gint chunk_size_mb; #endif /* DISABLE_JOURNAL */ /* Set log handler for library messages */ log_handler_id = g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL, log_handler, NULL); g_log_set_default_handler (log_handler, NULL); #ifndef DISABLE_JOURNAL db_config = tracker_db_config_new (); chunk_size_mb = tracker_db_config_get_journal_chunk_size (db_config); chunk_size = (gsize) ((gsize) chunk_size_mb * (gsize) 1024 * (gsize) 1024); rotate_to = tracker_db_config_get_journal_rotate_destination (db_config); /* This call is needed to set the journal's filename */ tracker_db_journal_set_rotating ((chunk_size_mb != -1), chunk_size, rotate_to); g_free (rotate_to); g_object_unref (db_config); #endif /* DISABLE_JOURNAL */ /* Clean up (select_cache_size and update_cache_size don't matter here) */ if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE, FALSE, 100, 100, NULL, NULL, NULL, &error)) { g_message ("Error initializing database: %s", error->message); g_free (error); return EXIT_FAILURE; } #ifndef DISABLE_JOURNAL tracker_db_journal_init (NULL, FALSE, NULL); #endif /* DISABLE_JOURNAL */ tracker_db_manager_remove_all (hard_reset); tracker_db_manager_shutdown (); #ifndef DISABLE_JOURNAL tracker_db_journal_shutdown (NULL); #endif /* DISABLE_JOURNAL */ /* Unset log handler */ g_log_remove_handler (NULL, log_handler_id); } if (remove_config) { GMainLoop *main_loop; GFile *file; TrackerCrawler *crawler; const gchar *suffix = ".cfg"; const gchar *home_conf_dir; gchar *path; GSList *all, *l; crawler = tracker_crawler_new (); main_loop = g_main_loop_new (NULL, FALSE); g_signal_connect (crawler, "check-file", G_CALLBACK (crawler_check_file_cb), &suffix); g_signal_connect (crawler, "finished", G_CALLBACK (crawler_finished_cb), main_loop); /* Go through service files */ /* Check the default XDG_DATA_HOME location */ home_conf_dir = g_getenv ("XDG_CONFIG_HOME"); if (home_conf_dir && tracker_path_has_write_access_or_was_created (home_conf_dir)) { path = g_build_path (G_DIR_SEPARATOR_S, home_conf_dir, "tracker", NULL); } else { home_conf_dir = g_getenv ("HOME"); if (!home_conf_dir || !tracker_path_has_write_access_or_was_created (home_conf_dir)) { home_conf_dir = g_get_home_dir (); } path = g_build_path (G_DIR_SEPARATOR_S, home_conf_dir, ".config", "tracker", NULL); } file = g_file_new_for_path (path); g_free (path); g_print ("%s\n", _("Removing configuration files…")); tracker_crawler_start (crawler, file, FALSE); g_object_unref (file); g_main_loop_run (main_loop); g_object_unref (crawler); g_print ("%s\n", _("Resetting existing configuration…")); all = tracker_gsettings_get_all (NULL); if (!all) { return EXIT_FAILURE; } for (l = all; l; l = l->next) { ComponentGSettings *c = l->data; gchar **keys, **p; if (!c) { continue; } g_print (" %s\n", c->name); keys = g_settings_list_keys (c->settings); for (p = keys; p && *p; p++) { g_print (" %s\n", *p); g_settings_reset (c->settings, *p); } if (keys) { g_strfreev (keys); } g_settings_apply (c->settings); } tracker_gsettings_free (all); } /* Deal with logging changes AFTER the config may have been * reset, this way users can actually use --remove-config with * the --set-logging switch. */ if (get_log_verbosity) { GSList *all; gint longest = 0; all = tracker_gsettings_get_all (&longest); if (!all) { return EXIT_FAILURE; } g_print ("%s:\n", _("Components")); tracker_gsettings_print_verbosity (all, longest, TRUE); g_print ("\n"); /* Miners */ g_print ("%s (%s):\n", _("Miners"), _("Only those with config listed")); tracker_gsettings_print_verbosity (all, longest, FALSE); g_print ("\n"); tracker_gsettings_free (all); } if (set_log_verbosity) { GSList *all; gchar *str; gint longest = 0; all = tracker_gsettings_get_all (&longest); if (!all) { return EXIT_FAILURE; } str = g_strdup_printf (_("Setting log verbosity for all components to '%s'…"), set_log_verbosity); g_print ("%s\n", str); g_print ("\n"); g_free (str); tracker_gsettings_set_all (all, set_log_verbosity_value); tracker_gsettings_free (all); /* We free to make sure we get new settings and that * they're saved properly. */ all = tracker_gsettings_get_all (&longest); if (!all) { return EXIT_FAILURE; } g_print ("%s:\n", _("Components")); tracker_gsettings_print_verbosity (all, longest, TRUE); g_print ("\n"); /* Miners */ g_print ("%s (%s):\n", _("Miners"), _("Only those with config listed")); tracker_gsettings_print_verbosity (all, longest, FALSE); g_print ("\n"); tracker_gsettings_free (all); } if (verbosity_type_enum_class_pointer) { g_type_class_unref (verbosity_type_enum_class_pointer); } if (start) { TrackerMinerManager *manager; GSList *miners, *l; if (hard_reset || soft_reset) { g_print ("%s\n", _("Waiting one second before starting miners…")); /* Give a second's grace to avoid race conditions */ g_usleep (G_USEC_PER_SEC); } g_print ("%s\n", _("Starting miners…")); /* Auto-start the miners here */ manager = tracker_miner_manager_new_full (TRUE, &error); if (!manager) { g_printerr (_("Could not start miners, manager could not be created, %s"), error ? error->message : "unknown error"); g_printerr ("\n"); g_clear_error (&error); return EXIT_FAILURE; } miners = tracker_miner_manager_get_available (manager); /* Get the status of all miners, this will start all * miners not already running. */ for (l = miners; l; l = l->next) { const gchar *display_name; gdouble progress = 0.0; display_name = tracker_miner_manager_get_display_name (manager, l->data); if (!tracker_miner_manager_get_status (manager, l->data, NULL, &progress, NULL)) { g_printerr (" ✗ %s (%s)\n", display_name, _("perhaps a disabled plugin?")); } else { g_print (" ✓ %s\n", display_name); } g_free (l->data); } g_slist_free (miners); g_object_unref (manager); } if (backup) { GDBusConnection *connection; GDBusProxy *proxy; GError *error = NULL; GVariant *v; gchar *uri; uri = get_uri_from_arg (backup); g_print ("%s\n", _("Backing up database")); g_print (" %s\n", uri); connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (!connection) { g_critical ("Could not connect to the D-Bus session bus, %s", error ? error->message : "no error given."); g_clear_error (&error); g_free (uri); return EXIT_FAILURE; } proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.Tracker1", "/org/freedesktop/Tracker1/Backup", "org.freedesktop.Tracker1.Backup", NULL, &error); if (error) { g_critical ("Could not create proxy on the D-Bus session bus, %s", error ? error->message : "no error given."); g_clear_error (&error); g_free (uri); return EXIT_FAILURE; } /* Backup/Restore can take some time */ g_dbus_proxy_set_default_timeout (proxy, G_MAXINT); v = g_dbus_proxy_call_sync (proxy, "Save", g_variant_new ("(s)", uri), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (proxy) { g_object_unref (proxy); } if (error) { g_critical ("Could not backup database, %s", error ? error->message : "no error given."); g_clear_error (&error); g_free (uri); return EXIT_FAILURE; } if (v) { g_variant_unref (v); } g_free (uri); } if (restore) { GDBusConnection *connection; GDBusProxy *proxy; GError *error = NULL; GVariant *v; gchar *uri; uri = get_uri_from_arg (restore); g_print ("%s\n", _("Restoring database from backup")); g_print (" %s\n", uri); connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (!connection) { g_critical ("Could not connect to the D-Bus session bus, %s", error ? error->message : "no error given."); g_clear_error (&error); g_free (uri); return EXIT_FAILURE; } proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.Tracker1", "/org/freedesktop/Tracker1/Backup", "org.freedesktop.Tracker1.Backup", NULL, &error); if (error) { g_critical ("Could not create proxy on the D-Bus session bus, %s", error ? error->message : "no error given."); g_clear_error (&error); g_free (uri); return EXIT_FAILURE; } /* Backup/Restore can take some time */ g_dbus_proxy_set_default_timeout (proxy, G_MAXINT); v = g_dbus_proxy_call_sync (proxy, "Restore", g_variant_new ("(s)", uri), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (proxy) { g_object_unref (proxy); } if (error) { g_critical ("Could not restore database, %s", error ? error->message : "no error given."); g_clear_error (&error); g_free (uri); return EXIT_FAILURE; } if (v) { g_variant_unref (v); } g_free (uri); } return EXIT_SUCCESS; }
/** * gdk_pixbuf_from_pixdata: * @pixdata: a #GdkPixdata to convert into a #GdkPixbuf. * @copy_pixels: whether to copy raw pixel data; run-length encoded * pixel data is always copied. * @error: location to store possible errors. * * Converts a #GdkPixdata to a #GdkPixbuf. If @copy_pixels is %TRUE or * if the pixel data is run-length-encoded, the pixel data is copied into * newly-allocated memory; otherwise it is reused. * * Returns: (transfer full): a new #GdkPixbuf. * Deprecated: 2.32: Use #GResource instead. **/ GdkPixbuf* gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata, gboolean copy_pixels, GError **error) { guint encoding, bpp; guint8 *data = NULL; g_return_val_if_fail (pixdata != NULL, NULL); g_return_val_if_fail (pixdata->width > 0, NULL); g_return_val_if_fail (pixdata->height > 0, NULL); g_return_val_if_fail (pixdata->rowstride >= pixdata->width, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGB || (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_SAMPLE_WIDTH_MASK) == GDK_PIXDATA_SAMPLE_WIDTH_8, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK) == GDK_PIXDATA_ENCODING_RAW || (pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK) == GDK_PIXDATA_ENCODING_RLE, NULL); g_return_val_if_fail (pixdata->pixel_data != NULL, NULL); bpp = (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGB ? 3 : 4; encoding = pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK; g_debug ("gdk_pixbuf_from_pixdata() called on:"); g_debug ("\tEncoding %s", encoding == GDK_PIXDATA_ENCODING_RAW ? "raw" : "rle"); g_debug ("\tDimensions: %d x %d", pixdata->width, pixdata->height); g_debug ("\tRowstride: %d, Length: %d", pixdata->rowstride, pixdata->length); g_debug ("\tCopy pixels == %s", copy_pixels ? "true" : "false"); if (encoding == GDK_PIXDATA_ENCODING_RLE) copy_pixels = TRUE; /* Sanity check the length and dimensions */ if (SIZE_OVERFLOWS (pixdata->height, pixdata->rowstride)) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } if (encoding == GDK_PIXDATA_ENCODING_RAW && pixdata->length >= 1 && pixdata->length < pixdata->height * pixdata->rowstride - GDK_PIXDATA_HEADER_LENGTH) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } if (copy_pixels) { data = g_try_malloc_n (pixdata->height, pixdata->rowstride); if (!data) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, g_dngettext(GETTEXT_PACKAGE, "failed to allocate image buffer of %u byte", "failed to allocate image buffer of %u bytes", pixdata->rowstride * pixdata->height), pixdata->rowstride * pixdata->height); return NULL; } } if (encoding == GDK_PIXDATA_ENCODING_RLE) { const guint8 *rle_buffer = pixdata->pixel_data; guint8 *rle_buffer_limit = NULL; guint8 *image_buffer = data; guint8 *image_limit = data + pixdata->rowstride * pixdata->height; gboolean check_overrun = FALSE; if (pixdata->length >= 1) rle_buffer_limit = pixdata->pixel_data + pixdata->length - GDK_PIXDATA_HEADER_LENGTH; while (image_buffer < image_limit && (rle_buffer_limit != NULL || rle_buffer > rle_buffer_limit)) { guint length; if (RLE_OVERRUN(1)) { check_overrun = TRUE; break; } length = *(rle_buffer++); if (length & 128) { length = length - 128; check_overrun = image_buffer + length * bpp > image_limit; if (check_overrun) length = (image_limit - image_buffer) / bpp; if (RLE_OVERRUN(bpp < 4 ? 3 : 4)) { check_overrun = TRUE; break; } if (bpp < 4) /* RGB */ do { memcpy (image_buffer, rle_buffer, 3); image_buffer += 3; } while (--length); else /* RGBA */ do { memcpy (image_buffer, rle_buffer, 4); image_buffer += 4; } while (--length); if (RLE_OVERRUN(bpp)) { check_overrun = TRUE; break; } rle_buffer += bpp; } else { length *= bpp; check_overrun = image_buffer + length > image_limit; if (check_overrun) length = image_limit - image_buffer; if (RLE_OVERRUN(length)) { check_overrun = TRUE; break; } memcpy (image_buffer, rle_buffer, length); image_buffer += length; rle_buffer += length; } } if (check_overrun) { g_free (data); g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } } else if (copy_pixels) memcpy (data, pixdata->pixel_data, pixdata->rowstride * pixdata->height); else data = pixdata->pixel_data; return gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, 8, pixdata->width, pixdata->height, pixdata->rowstride, copy_pixels ? (GdkPixbufDestroyNotify) g_free : NULL, data); }
/** * gdk_pixbuf_from_pixdata: * @pixdata: a #GdkPixdata to convert into a #GdkPixbuf. * @copy_pixels: whether to copy raw pixel data; run-length encoded * pixel data is always copied. * @error: location to store possible errors. * * Converts a #GdkPixdata to a #GdkPixbuf. If @copy_pixels is %TRUE or * if the pixel data is run-length-encoded, the pixel data is copied into * newly-allocated memory; otherwise it is reused. * * Returns: (transfer full): a new #GdkPixbuf. **/ GdkPixbuf* gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata, gboolean copy_pixels, GError **error) { guint encoding, bpp; guint8 *data = NULL; g_return_val_if_fail (pixdata != NULL, NULL); g_return_val_if_fail (pixdata->width > 0, NULL); g_return_val_if_fail (pixdata->height > 0, NULL); g_return_val_if_fail (pixdata->rowstride >= pixdata->width, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGB || (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_SAMPLE_WIDTH_MASK) == GDK_PIXDATA_SAMPLE_WIDTH_8, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK) == GDK_PIXDATA_ENCODING_RAW || (pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK) == GDK_PIXDATA_ENCODING_RLE, NULL); g_return_val_if_fail (pixdata->pixel_data != NULL, NULL); bpp = (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGB ? 3 : 4; encoding = pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK; if (encoding == GDK_PIXDATA_ENCODING_RLE) copy_pixels = TRUE; if (copy_pixels) { data = g_try_malloc (pixdata->rowstride * pixdata->height); if (!data) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, g_dngettext(GETTEXT_PACKAGE, "failed to allocate image buffer of %u byte", "failed to allocate image buffer of %u bytes", pixdata->rowstride * pixdata->height), pixdata->rowstride * pixdata->height); return NULL; } } if (encoding == GDK_PIXDATA_ENCODING_RLE) { const guint8 *rle_buffer = pixdata->pixel_data; guint8 *image_buffer = data; guint8 *image_limit = data + pixdata->rowstride * pixdata->height; gboolean check_overrun = FALSE; while (image_buffer < image_limit) { guint length = *(rle_buffer++); if (length & 128) { length = length - 128; check_overrun = image_buffer + length * bpp > image_limit; if (check_overrun) length = (image_limit - image_buffer) / bpp; if (bpp < 4) /* RGB */ do { memcpy (image_buffer, rle_buffer, 3); image_buffer += 3; } while (--length); else /* RGBA */ do { memcpy (image_buffer, rle_buffer, 4); image_buffer += 4; } while (--length); rle_buffer += bpp; } else { length *= bpp; check_overrun = image_buffer + length > image_limit; if (check_overrun) length = image_limit - image_buffer; memcpy (image_buffer, rle_buffer, length); image_buffer += length; rle_buffer += length; } } if (check_overrun) { g_free (data); g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } } else if (copy_pixels) memcpy (data, pixdata->pixel_data, pixdata->rowstride * pixdata->height); else data = pixdata->pixel_data; return gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, 8, pixdata->width, pixdata->height, pixdata->rowstride, copy_pixels ? (GdkPixbufDestroyNotify) g_free : NULL, data); }
static void gcr_key_renderer_real_render (GcrRenderer *renderer, GcrViewer *viewer) { GcrKeyRenderer *self; GcrDisplayView *view; const gchar *text = ""; GckAttributes *attrs; gpointer fingerprint; gsize n_fingerprint; gchar *display; gulong klass; gulong key_type; guint size; self = GCR_KEY_RENDERER (renderer); if (GCR_IS_DISPLAY_VIEW (viewer)) { view = GCR_DISPLAY_VIEW (viewer); } else { g_warning ("GcrKeyRenderer only works with internal specific " "GcrViewer returned by gcr_viewer_new()."); return; } _gcr_display_view_begin (view, renderer); attrs = calculate_attrs (self); if (attrs == NULL) { _gcr_display_view_end (view, renderer); return; } if (!gck_attributes_find_ulong (attrs, CKA_CLASS, &klass) || !gck_attributes_find_ulong (attrs, CKA_KEY_TYPE, &key_type)) { g_warning ("private key does not have the CKA_CLASS and CKA_KEY_TYPE attributes"); _gcr_display_view_end (view, renderer); gck_attributes_unref (attrs); return; } _gcr_display_view_set_icon (view, renderer, self->pv->icon); display = calculate_label (self); _gcr_display_view_append_title (view, renderer, display); g_free (display); if (klass == CKO_PRIVATE_KEY) { if (key_type == CKK_RSA) text = _("Private RSA Key"); else if (key_type == CKK_DSA) text = _("Private DSA Key"); else if (key_type == CKK_EC) text = _("Private Elliptic Curve Key"); else text = _("Private Key"); } else if (klass == CKO_PUBLIC_KEY) { if (key_type == CKK_RSA) text = _("Public DSA Key"); else if (key_type == CKK_DSA) text = _("Public DSA Key"); else if (key_type == CKK_EC) text = _("Public Elliptic Curve Key"); else text = _("Public Key"); } _gcr_display_view_append_content (view, renderer, text, NULL); size = _gcr_subject_public_key_attributes_size (attrs); if (size > 0) { display = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%u bit", "%u bits", size), size); _gcr_display_view_append_content (view, renderer, _("Strength"), display); g_free (display); } _gcr_display_view_start_details (view, renderer); if (key_type == CKK_RSA) text = _("RSA"); else if (key_type == CKK_DSA) text = _("DSA"); else if (key_type == CKK_EC) text = _("Elliptic Curve"); else text = _("Unknown"); _gcr_display_view_append_value (view, renderer, _("Algorithm"), text, FALSE); if (size == 0) display = g_strdup (_("Unknown")); else display = g_strdup_printf ("%u", size); _gcr_display_view_append_value (view, renderer, _("Size"), display, FALSE); g_free (display); /* Fingerprints */ _gcr_display_view_append_heading (view, renderer, _("Fingerprints")); fingerprint = calculate_fingerprint (self, attrs, G_CHECKSUM_SHA1, &n_fingerprint); if (fingerprint) { _gcr_display_view_append_hex (view, renderer, _("SHA1"), fingerprint, n_fingerprint); g_free (fingerprint); } fingerprint = calculate_fingerprint (self, attrs, G_CHECKSUM_SHA256, &n_fingerprint); if (fingerprint) { _gcr_display_view_append_hex (view, renderer, _("SHA256"), fingerprint, n_fingerprint); g_free (fingerprint); } _gcr_display_view_end (view, renderer); gck_attributes_unref (attrs); }
static void gtk_message_internal(const char* title, enum ShowAgainStyle showAgain, char const *fmt, va_list args, va_list args2) { static gchar *buf = NULL; static gint alloc = 0; gint len; DiaMessageInfo *msginfo; GtkTextBuffer *textbuffer; gboolean askForShowAgain = FALSE; if (showAgain != ALWAYS_SHOW) { /* We persistently stored that the user has chosen to not see the * dialog again (whether by checking or not unchecking the box) */ persistence_register_boolean((gchar *)title, FALSE); if (persistence_get_boolean((gchar *)title)) { /* If not showing again, just return at once */ return; } askForShowAgain = TRUE; } if (message_hash_table == NULL) { message_hash_table = g_hash_table_new(g_str_hash, g_str_equal); } len = g_printf_string_upper_bound (fmt, args); if (len >= alloc) { if (buf) g_free (buf); alloc = nearest_pow (MAX(len + 1, 1024)); buf = g_new (char, alloc); } vsprintf (buf, fmt, args2); msginfo = (DiaMessageInfo*)g_hash_table_lookup(message_hash_table, fmt); if (msginfo == NULL) { msginfo = g_new0(DiaMessageInfo, 1); g_hash_table_insert(message_hash_table, (char *)fmt, msginfo); } if (msginfo->dialog == NULL) message_create_dialog(title, msginfo, buf); if (msginfo->repeats != NULL) { if (g_list_length(msginfo->repeats) > 1) { char *newlabel; guint num = g_list_length(msginfo->repeats); /* See: https://live.gnome.org/TranslationProject/DevGuidelines/Plurals */ newlabel = g_strdup_printf(g_dngettext (GETTEXT_PACKAGE, "There is %d similar message.", /* not triggered */ "There are %d similar messages.", num), num); gtk_label_set_text(GTK_LABEL(msginfo->repeat_label), newlabel); } /* for repeated messages, show the last one */ g_object_set (msginfo->dialog, "text", buf, NULL); gtk_widget_show(msginfo->repeat_label); gtk_widget_show(msginfo->show_repeats); } /* Insert in scrollable view, but only the repeated ones */ if (msginfo->repeats != NULL) { textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(msginfo->repeat_view)); gtk_text_buffer_insert_at_cursor(textbuffer, buf, -1); } msginfo->repeats = g_list_prepend(msginfo->repeats, g_strdup(buf)); if (askForShowAgain) { gtk_widget_show(msginfo->no_show_again); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(msginfo->no_show_again), showAgain == SUGGEST_NO_SHOW_AGAIN); } else { gtk_widget_hide(msginfo->no_show_again); } gtk_widget_show (msginfo->dialog); }
static int get_no_args (void) { gchar *str; gchar *data_dir; guint64 remaining_bytes; gdouble remaining; gint remaining_time; gint files, folders; /* How many files / folders do we have? */ if (get_file_and_folder_count (&files, &folders) != 0) { return EXIT_FAILURE; } g_print (_("Currently indexed")); g_print (": "); g_print (g_dngettext (NULL, "%d file", "%d files", files), files); g_print (", "); g_print (g_dngettext (NULL, "%d folders", "%d folders", folders), folders); g_print ("\n"); /* How much space is left? */ data_dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL); remaining_bytes = tracker_file_system_get_remaining_space (data_dir); str = g_format_size (remaining_bytes); remaining = tracker_file_system_get_remaining_space_percentage (data_dir); g_print ("%s: %s (%3.2lf%%)\n", _("Remaining space on database partition"), str, remaining); g_free (str); g_free (data_dir); /* Are we finished indexing? */ if (!are_miners_finished (&remaining_time)) { gchar *remaining_time_str; remaining_time_str = tracker_seconds_to_string (remaining_time, TRUE); g_print ("%s: ", _("Data is still being indexed")); g_print (_("Estimated %s left"), remaining_time_str); g_print ("\n"); g_free (remaining_time_str); } else { g_print ("%s\n", _("All data miners are idle, indexing complete")); } g_print ("\n\n"); return EXIT_SUCCESS; }
char * mpl_gdk_windowing_get_startup_notify_id (GAppLaunchContext *context, GAppInfo *info, GList *files) { static int sequence = 0; #if 0 GdkAppLaunchContextPrivate *priv; #endif GdkDisplay *display; GdkScreen *screen; int files_count; char *description; char *icon_name; const char *binary_name; const char *application_id; char *screen_str; char *workspace_str; #if 0 GIcon *icon; #endif guint32 timestamp; char *startup_id; #if 0 priv = GDK_APP_LAUNCH_CONTEXT (context)->priv; if (priv->screen) { screen = priv->screen; display = gdk_screen_get_display (priv->screen); } else if (priv->display) { display = priv->display; screen = gdk_display_get_default_screen (display); } else { display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); } #else display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); #endif files_count = g_list_length (files); if (files_count == 0) description = g_strdup_printf (_("Starting %s"), g_app_info_get_name (info)); else if (files_count == 1) description = g_strdup_printf (_("Opening %s"), get_display_name (files->data)); else description = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Opening %d Item", "Opening %d Items", files_count), files_count); icon_name = NULL; #if 0 if (priv->icon_name) icon_name = g_strdup (priv->icon_name); else { icon = NULL; if (priv->icon != NULL) icon = g_object_ref (priv->icon); else if (files_count == 1) icon = get_icon (files->data); if (icon == NULL) { icon = g_app_info_get_icon (info); g_object_ref (icon); } if (icon) icon_name = gicon_to_string (icon); g_object_unref (icon); } #endif binary_name = g_app_info_get_executable (info); #if 0 timestamp = priv->timestamp; if (timestamp == GDK_CURRENT_TIME) #endif timestamp = gdk_x11_display_get_user_time (display); screen_str = g_strdup_printf ("%d", gdk_screen_get_number (screen)); #if 0 if (priv->workspace > -1) workspace_str = g_strdup_printf ("%d", priv->workspace); else #endif workspace_str = NULL; if (G_IS_DESKTOP_APP_INFO (info)) application_id = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info)); else application_id = NULL; startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu", g_get_prgname (), (unsigned long)getpid (), g_get_host_name (), binary_name, sequence++, (unsigned long)timestamp); gdk_x11_display_broadcast_startup_message (display, "new", "ID", startup_id, "NAME", g_app_info_get_name (info), "SCREEN", screen_str, "BIN", binary_name, "ICON", icon_name, "DESKTOP", workspace_str, "DESCRIPTION", description, "WMCLASS", NULL, /* FIXME */ "APPLICATION_ID", application_id, NULL); g_free (description); g_free (screen_str); g_free (workspace_str); g_free (icon_name); add_startup_timeout (screen, startup_id); return startup_id; }
void dlg_export_to_flickr (FlickrServer *server, GthBrowser *browser, GList *file_list) { DialogData *data; GList *scan; int n_total; goffset total_size; char *total_size_formatted; char *text; char *title; data = g_new0 (DialogData, 1); data->server = server; data->browser = browser; data->settings = g_settings_new (GTHUMB_FLICKR_SCHEMA); data->location = gth_file_data_dup (gth_browser_get_location_data (browser)); data->builder = _gtk_builder_new_from_file ("export-to-flickr.ui", "flicker_utils"); data->cancellable = g_cancellable_new (); data->dialog = g_object_new (GTK_TYPE_DIALOG, "transient-for", GTK_WINDOW (browser), "modal", FALSE, "destroy-with-parent", FALSE, "use-header-bar", _gtk_settings_get_dialogs_use_header (), NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))), _gtk_builder_get_widget (data->builder, "dialog_content")); gtk_dialog_add_buttons (GTK_DIALOG (data->dialog), _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL, _GTK_LABEL_UPLOAD, GTK_RESPONSE_OK, NULL); _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; data->photoset_combobox = gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL (GET_WIDGET ("photoset_liststore"))); gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (data->photoset_combobox), PHOTOSET_TITLE_COLUMN); gtk_widget_show (data->photoset_combobox); gtk_container_add (GTK_CONTAINER (GET_WIDGET ("photoset_combobox_container")), data->photoset_combobox); cell_layout = GTK_CELL_LAYOUT (data->photoset_combobox); gtk_cell_layout_clear (cell_layout); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", PHOTOSET_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", PHOTOSET_TITLE_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", PHOTOSET_N_PHOTOS_COLUMN, NULL); } data->file_list = NULL; n_total = 0; total_size = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; const char *mime_type; mime_type = gth_file_data_get_mime_type (file_data); if (g_content_type_equals (mime_type, "image/bmp") || g_content_type_equals (mime_type, "image/gif") || g_content_type_equals (mime_type, "image/jpeg") || g_content_type_equals (mime_type, "image/png")) { total_size += g_file_info_get_size (file_data->info); n_total++; data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data)); } } data->file_list = g_list_reverse (data->file_list); if (data->file_list == NULL) { GError *error; error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected.")); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), error); g_clear_error (&error); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); return; } total_size_formatted = g_format_size (total_size); text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text); g_free (text); g_free (total_size_formatted); _gtk_window_resize_to_fit_screen_height (data->dialog, 500); /* Set the widget data */ data->list_view = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NO_SELECTION, FALSE); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE); gtk_widget_show (data->list_view); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0); gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list); gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (data->photoset_combobox))), g_file_info_get_edit_name (data->location->info)); gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, FALSE); title = g_strdup_printf (_("Export to %s"), data->server->name); gtk_window_set_title (GTK_WINDOW (data->dialog), title); g_free (title); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")), g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_WIDTH) != -1); _gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")), g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_WIDTH), g_settings_get_int (data->settings, PREF_FLICKR_RESIZE_HEIGHT)); /* Set the signals handlers. */ g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (export_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("resize_checkbutton"), "toggled", G_CALLBACK (resize_checkbutton_toggled_cb), data); update_sensitivity (data); data->service = flickr_service_new (server, data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (authentication_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (authentication_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service), GTH_TASK_FLAGS_DEFAULT); web_service_autoconnect (WEB_SERVICE (data->service)); }