static bool plugin_mapping_new(zathura_plugin_manager_t* plugin_manager, const gchar* type, zathura_plugin_t* plugin) { g_return_val_if_fail(plugin_manager != NULL, false); g_return_val_if_fail(type != NULL, false); g_return_val_if_fail(plugin != NULL, false); GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping) if (g_content_type_equals(type, mapping->type)) { girara_list_iterator_free(iter); return false; } GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping); zathura_type_plugin_mapping_t* mapping = g_try_malloc0(sizeof(zathura_type_plugin_mapping_t)); if (mapping == NULL) { return false; } mapping->type = g_strdup(type); mapping->plugin = plugin; girara_list_append(plugin_manager->type_plugin_mapping, mapping); return true; }
static FileMimeInfo get_file_mime_info (NautilusFileInfo *file) { FileMimeInfo file_mime_info; int i; file_mime_info.is_archive = FALSE; file_mime_info.is_derived_archive = FALSE; file_mime_info.is_compressed_archive = FALSE; for (i = 0; archive_mime_types[i].mime_type != NULL; i++) if (nautilus_file_info_is_mime_type (file, archive_mime_types[i].mime_type)) { char *mime_type; char *content_type_mime_file; char *content_type_mime_compare; mime_type = nautilus_file_info_get_mime_type (file); content_type_mime_file = g_content_type_from_mime_type (mime_type); content_type_mime_compare = g_content_type_from_mime_type (archive_mime_types[i].mime_type); file_mime_info.is_archive = TRUE; file_mime_info.is_compressed_archive = archive_mime_types[i].is_compressed; if ((content_type_mime_file != NULL) && (content_type_mime_compare != NULL)) file_mime_info.is_derived_archive = ! g_content_type_equals (content_type_mime_file, content_type_mime_compare); g_free (mime_type); g_free (content_type_mime_file); g_free (content_type_mime_compare); return file_mime_info; } return file_mime_info; }
static gboolean gth_image_saver_jpeg_can_save (GthImageSaver *self, const char *mime_type) { #ifdef HAVE_LIBJPEG return g_content_type_equals (mime_type, "image/jpeg"); #else /* ! HAVE_LIBJPEG */ GSList *formats; GSList *scan; GdkPixbufFormat *jpeg_format; if (! g_content_type_equals (mime_type, "image/jpeg")) return FALSE; formats = gdk_pixbuf_get_formats (); jpeg_format = NULL; for (scan = formats; (jpeg_format == NULL) && (scan != NULL); scan = g_slist_next (scan)) { GdkPixbufFormat *format = scan->data; char **mime_types; int i; mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; mime_types[i] != NULL; i++) if (g_content_type_equals (mime_types[i], "image/jpeg")) break; if (mime_types[i] == NULL) continue; if (! gdk_pixbuf_format_is_writable (format)) continue; jpeg_format = format; } return jpeg_format != NULL; #endif /* HAVE_LIBJPEG */ }
static gboolean is_valid_mime(const gchar *mime, const gchar **mlist) { gint i = 0; while (mlist[i]) { if (g_content_type_equals(mime, mlist[i])) return TRUE; i++; } return FALSE; }
zathura_plugin_t* zathura_plugin_manager_get_plugin(zathura_plugin_manager_t* plugin_manager, const char* type) { if (plugin_manager == NULL || plugin_manager->type_plugin_mapping == NULL || type == NULL) { return NULL; } zathura_plugin_t* plugin = NULL; GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping) if (g_content_type_equals(type, mapping->type)) { plugin = mapping->plugin; break; } GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping); return plugin; }
GthImage * gth_pixbuf_animation_new_from_file (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gpointer user_data, GCancellable *cancellable, GError **error) { const char *mime_type; GdkPixbufAnimation *animation; char *path; GthImage *image; mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, error); if (mime_type == NULL) return NULL; if ((file_data == NULL) || ! g_content_type_equals (mime_type, "image/gif")) return gth_pixbuf_new_from_file (istream, file_data, requested_size, original_width, original_height, FALSE, cancellable, error); path = g_file_get_path (file_data->file); if (path == NULL) { if (error != NULL) *error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not load file"); return NULL; } animation = gdk_pixbuf_animation_new_from_file (path, error); image = gth_image_new (); gth_image_set_pixbuf_animation (image, animation); g_object_unref (animation); g_free (path); return image; }
GthImage * gth_pixbuf_animation_new_from_file (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gboolean *loaded_original, gpointer user_data, GCancellable *cancellable, GError **error) { const char *mime_type; GthImage *image; mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, error); if (mime_type == NULL) return NULL; image = NULL; if (g_content_type_equals (mime_type, "image/gif")) { GdkPixbufAnimation *animation; animation = gdk_pixbuf_animation_new_from_stream (istream, cancellable, error); image = gth_image_new (); gth_image_set_pixbuf_animation (image, animation); _g_object_unref (animation); } else image = gth_pixbuf_new_from_file (istream, file_data, requested_size, original_width, original_height, loaded_original, FALSE, cancellable, error); return image; }
static VALUE rg_s_equals_p(G_GNUC_UNUSED VALUE self, VALUE arg1, VALUE arg2) { return CBOOL2RVAL(g_content_type_equals(RVAL2CSTR(arg1), RVAL2CSTR(arg2))); }
static gboolean gth_image_saver_png_can_save (GthImageSaver *self, const char *mime_type) { return g_content_type_equals (mime_type, "image/png"); }
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)); }
static const gchar * xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon) { XfdesktopRegularFileIcon *regular_file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon); if(!regular_file_icon->priv->tooltip) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); const gchar *content_type, *comment = NULL; gchar *description, *size_string, *time_string; guint64 size, mtime; gboolean is_desktop_file = FALSE; if(!info) return NULL; if(g_content_type_equals(g_file_info_get_content_type(info), "application/x-desktop")) { is_desktop_file = TRUE; } else { gchar *uri = g_file_get_uri(regular_file_icon->priv->file); if(g_str_has_suffix(uri, ".desktop")) is_desktop_file = TRUE; g_free(uri); } content_type = g_file_info_get_content_type(info); description = g_content_type_get_description(content_type); 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); regular_file_icon->priv->tooltip = g_strdup_printf(_("Type: %s\nSize: %s\nLast modified: %s"), description, size_string, time_string); /* Extract the Comment entry from the .desktop file */ if(is_desktop_file) { gchar *path = g_file_get_path(regular_file_icon->priv->file); XfceRc *rcfile = xfce_rc_simple_open(path, TRUE); g_free(path); if(rcfile) { xfce_rc_set_group(rcfile, "Desktop Entry"); comment = xfce_rc_read_entry(rcfile, "Comment", NULL); } /* Prepend the comment to the tooltip */ if(comment != NULL && *comment != '\0') { gchar *tooltip = regular_file_icon->priv->tooltip; regular_file_icon->priv->tooltip = g_strdup_printf("%s\n%s", comment, tooltip); g_free(tooltip); } xfce_rc_close(rcfile); } g_free(time_string); g_free(size_string); g_free(description); } return regular_file_icon->priv->tooltip; }
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)); }
gboolean gitg_utils_can_display_content_type(gchar const *content_type) { return g_content_type_is_a(content_type, "text/plain") || g_content_type_equals(content_type, "application/octet-stream"); }
static gboolean log_load (GIOSchedulerJob *io_job, GCancellable *cancellable, gpointer user_data) { /* this runs in a separate i/o thread */ LoadJob *job = user_data; LogviewLog *log = job->log; GFile *f = log->priv->file; GFileInfo *info; GInputStream *is; const char *peeked_buffer; const char * parse_data[2]; GSList *days; const char *content_type; GFileType type; GError *err = NULL; GTimeVal timeval; gboolean is_archive, can_read; info = g_file_query_info (f, G_FILE_ATTRIBUTE_ACCESS_CAN_READ "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_TIME_MODIFIED ",", 0, NULL, &err); if (err) { if (err->code == G_IO_ERROR_PERMISSION_DENIED) { /* TODO: PolicyKit integration */ } goto out; } can_read = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ); if (!can_read) { /* TODO: PolicyKit integration */ err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_PERMISSION_DENIED, _("You don't have enough permissions to read the file.")); g_object_unref (info); goto out; } type = g_file_info_get_file_type (info); content_type = g_file_info_get_content_type (info); is_archive = g_content_type_equals (content_type, "application/x-gzip"); if (type != (G_FILE_TYPE_REGULAR || G_FILE_TYPE_SYMBOLIC_LINK) || (!g_content_type_is_a (content_type, "text/plain") && !is_archive)) { err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_NOT_A_LOG, _("The file is not a regular file or is not a text file.")); g_object_unref (info); goto out; } log->priv->file_size = g_file_info_get_size (info); g_file_info_get_modification_time (info, &timeval); log->priv->file_time = timeval.tv_sec; log->priv->display_name = g_strdup (g_file_info_get_display_name (info)); g_object_unref (info); /* initialize the stream */ is = G_INPUT_STREAM (g_file_read (f, NULL, &err)); if (err) { if (err->code == G_IO_ERROR_PERMISSION_DENIED) { /* TODO: PolicyKit integration */ } goto out; } if (is_archive) { #ifdef HAVE_ZLIB GZHandle *gz; gboolean res; guchar * buffer; gsize bytes_read; GInputStream *real_is; time_t mtime; /* seconds */ /* this also skips the header from |is| */ res = read_gzip_header (is, &mtime); if (!res) { g_object_unref (is); err = create_zlib_error (); goto out; } log->priv->file_time = mtime; gz = gz_handle_new (f, is); res = gz_handle_init (gz); if (!res) { g_object_unref (is); gz_handle_free (gz); err = create_zlib_error (); goto out; } real_is = g_memory_input_stream_new (); do { buffer = g_malloc (1024); res = gz_handle_read (gz, buffer, 1024, &bytes_read); g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (real_is), buffer, bytes_read, g_free); } while (res == TRUE && bytes_read > 0); if (!res) { gz_handle_free (gz); g_object_unref (real_is); g_object_unref (is); err = create_zlib_error (); goto out; } g_object_unref (is); is = real_is; gz_handle_free (gz); #else /* HAVE_ZLIB */ g_object_unref (is); err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_NOT_SUPPORTED, _("This version of System Log does not support GZipped logs.")); goto out; #endif /* HAVE_ZLIB */ } log->priv->stream = g_data_input_stream_new (is); /* sniff into the stream for a timestamped line */ g_buffered_input_stream_fill (G_BUFFERED_INPUT_STREAM (log->priv->stream), (gssize) g_buffered_input_stream_get_buffer_size (G_BUFFERED_INPUT_STREAM (log->priv->stream)), NULL, &err); if (err == NULL) { peeked_buffer = g_buffered_input_stream_peek_buffer (G_BUFFERED_INPUT_STREAM (log->priv->stream), NULL); parse_data[0] = peeked_buffer; parse_data[1] = NULL; if ((days = log_read_dates (parse_data, time (NULL))) != NULL) { log->priv->has_days = TRUE; g_slist_foreach (days, (GFunc) logview_utils_day_free, NULL); g_slist_free (days); } else { log->priv->has_days = FALSE; } } else { log->priv->has_days = FALSE; g_clear_error (&err); } g_object_unref (is); out: if (err) { job->err = err; } g_io_scheduler_job_send_to_mainloop_async (io_job, log_load_done, job, NULL); return FALSE; }
static void visit_directory (GFile *dir, SearchThreadData *data) { GFileEnumerator *enumerator; GFileInfo *info; GFile *child; const char *mime_type, *display_name; char *lower_name, *normalized; gboolean hit; int i; GList *l; const char *id; gboolean visited; enumerator = g_file_enumerate_children (dir, data->mime_types != NULL ? STD_ATTRIBUTES "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE : STD_ATTRIBUTES , 0, data->cancellable, NULL); if (enumerator == NULL) { return; } while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL) { if (g_file_info_get_is_hidden (info)) { goto next; } display_name = g_file_info_get_display_name (info); if (display_name == NULL) { goto next; } normalized = g_utf8_normalize (display_name, -1, G_NORMALIZE_NFD); lower_name = g_utf8_strdown (normalized, -1); g_free (normalized); hit = data->words_and; for (i = 0; data->words[i] != NULL; i++) { if (data->word_strstr[i]) { if ((strstr (lower_name, data->words[i]) != NULL)^data->words_and) { hit = !data->words_and; break; } } else if (strwildcardcmp (data->words[i], lower_name)^data->words_and) { hit = !data->words_and; break; } } g_free (lower_name); if (hit && data->mime_types) { mime_type = g_file_info_get_content_type (info); hit = FALSE; for (l = data->mime_types; mime_type != NULL && l != NULL; l = l->next) { if (g_content_type_equals (mime_type, l->data)) { hit = TRUE; break; } } } child = g_file_get_child (dir, g_file_info_get_name (info)); if (hit) { data->uri_hits = g_list_prepend (data->uri_hits, g_file_get_uri (child)); } data->n_processed_files++; if (data->n_processed_files > BATCH_SIZE) { send_batch (data); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE); visited = FALSE; if (id) { if (g_hash_table_lookup_extended (data->visited, id, NULL, NULL)) { visited = TRUE; } else { g_hash_table_insert (data->visited, g_strdup (id), NULL); } } if (!visited) { g_queue_push_tail (data->directories, g_object_ref (child)); } } g_object_unref (child); next: g_object_unref (info); } g_object_unref (enumerator); }