static void on_drag_data_received (GtkWidget * widget, GdkDragContext * context, int x, int y, GtkSelectionData * seldata, guint inf, guint time, gpointer data) { SourceData *userdata = g_new0 (SourceData, 1); #ifdef G_OS_WIN32 gchar *filename = g_filename_from_uri ((const gchar *) seldata->data, NULL, NULL); #else GdkPixbufFormat *format; gchar **uris = gtk_selection_data_get_uris (seldata); gchar *filename = NULL; g_return_if_fail (uris != NULL); filename = g_filename_from_uri (uris[0], NULL, NULL); g_return_if_fail (filename != NULL); format = gdk_pixbuf_get_file_info (filename, NULL, NULL); g_return_if_fail (format); g_print ("received %s image: %s\n", filename, gdk_pixbuf_format_get_name (format)); #endif userdata->nick = "location"; userdata->value = g_strdup (filename); userdata->data = data; saveddelay = delay; if (delay > 0) { g_print ("%d\n", delay); g_timeout_add_seconds (1, set_location_delayed, userdata); } else g_object_set (G_OBJECT (userdata->data), userdata->nick, userdata->value, NULL); g_free (filename); }
static GtkWidget *image_widget_from_filename(const gchar *filename) { GtkWidget *image = NULL; GdkPixbuf *picture = NULL; GError *error = NULL; gint w, h; gdk_pixbuf_get_file_info(filename, &w, &h); if (w != AVATAR_SIZE || h != AVATAR_SIZE) /* server can provide a different size from the requested in URL */ picture = gdk_pixbuf_new_from_file_at_scale( filename, AVATAR_SIZE, AVATAR_SIZE, TRUE, &error); else /* exact size */ picture = gdk_pixbuf_new_from_file(filename, &error); if (error != NULL) { g_warning("failed to load image '%s': %s", filename, error->message); g_error_free(error); } else { if (picture) { image = gtk_image_new_from_pixbuf(picture); g_object_unref(picture); } else g_warning("failed to load image '%s': no error returned!", filename); } return image; }
static gboolean scan_photo_path(gchar *prefix_path, gchar *file, gchar *logo, GSList **pl) { GDir *dir = NULL; gchar path[1024] = {0}; gboolean is_photo_dir = FALSE; GError *err = NULL; const gchar *name = NULL; photo_item_t *pi = NULL; dir = g_dir_open(prefix_path, 0, &err); if(dir) { while(name = g_dir_read_name(dir)) { snprintf(path, 1024, "%s/%s", prefix_path, name); //DD("path = %s\n", path); if(is_photo_dir == FALSE) { if(g_file_test(path, G_FILE_TEST_IS_REGULAR) && gdk_pixbuf_get_file_info(path, NULL, NULL)) { strncpy(logo, path, strlen(path)); is_photo_dir = TRUE; if(pl) { pi = g_new(photo_item_t, 1); pi->path = strdup(path); pi->pixbuf = gdk_pixbuf_new_from_file_at_scale(path, MEDIAUI_WIDTH-2, MEDIAUI_HEIGHT-2, TRUE, &err); pi->w = gdk_pixbuf_get_width(pi->pixbuf); pi->h = gdk_pixbuf_get_height(pi->pixbuf); *pl = g_slist_append(*pl, pi); } } } else if(gdk_pixbuf_get_file_info(path, NULL, NULL)) { if(pl) { pi = g_new(photo_item_t, 1); pi->path = strdup(path); pi->pixbuf = NULL; *pl = g_slist_append(*pl, pi); } } } g_dir_close(dir); } else { ERROR("open photo dir = %s failed\n", prefix_path); } if(is_photo_dir) strncpy(file, prefix_path, 1024); return is_photo_dir; }
static gboolean scan_music_path(gchar *prefix_path, gchar *file, gchar *logo) { gboolean is_music_exist = FALSE, is_logo_exist = FALSE; gchar path[1024] = {0}; snprintf(logo, 1024, "%s/logo.jpg", prefix_path); is_logo_exist = g_file_test(logo, G_FILE_TEST_IS_REGULAR|G_FILE_TEST_EXISTS) && gdk_pixbuf_get_file_info(logo, NULL, NULL); if(! is_logo_exist) { bzero(logo, 1024); snprintf(logo, 1024, "%s/logo.png", prefix_path); is_logo_exist = g_file_test(logo, G_FILE_TEST_IS_REGULAR|G_FILE_TEST_EXISTS) && gdk_pixbuf_get_file_info(logo, NULL, NULL); } snprintf(file, 1024, "%s/music.pls", prefix_path); is_music_exist = g_file_test(file, G_FILE_TEST_IS_REGULAR|G_FILE_TEST_EXISTS); if(! is_music_exist) { snprintf(file, 1024, "%s/music.mp3", prefix_path); is_music_exist = g_file_test(logo, G_FILE_TEST_IS_REGULAR|G_FILE_TEST_EXISTS); } return is_music_exist && is_logo_exist; }
/* builds a folder/file path and then tests if that file is a valid image. * returns the file location if it does, NULL if it doesn't */ static gchar * xfdesktop_check_file_is_valid(const gchar *folder, const gchar *file) { gchar *path = g_strconcat(folder, "/", file, NULL); if(gdk_pixbuf_get_file_info(path, NULL, NULL) == NULL) { g_free(path); path = NULL; } return path; }
CoglBool _cogl_bitmap_get_size_from_file (const char *filename, int *width, int *height) { _COGL_RETURN_VAL_IF_FAIL (filename != NULL, FALSE); if (gdk_pixbuf_get_file_info (filename, width, height) != NULL) return TRUE; return FALSE; }
gboolean _cogl_bitmap_get_size_from_file (const gchar *filename, gint *width, gint *height) { g_return_val_if_fail (filename != NULL, FALSE); if (gdk_pixbuf_get_file_info (filename, width, height) != NULL) return TRUE; return FALSE; }
static void update_preview_cb (GtkFileChooser *file_chooser, gpointer data) { GtkImage *preview = GTK_IMAGE (data); g_autofree char *filename = gtk_file_chooser_get_preview_filename (file_chooser); gint preview_width = 0; gint preview_height = 0; struct g_stat st_buf; g_autoptr(GdkPixbuf) pixbuf = NULL; GdkPixbufFormat *preview_format = gdk_pixbuf_get_file_info (filename, &preview_width, &preview_height); if (!filename || g_stat (filename, &st_buf) || (!S_ISREG (st_buf.st_mode))) { gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE); return; // stat failed or file is not regular } if (!preview_format || preview_width <= 0 || preview_height <= 0 || preview_width > MAX_PREVIEW_SOURCE_SIZE || preview_height > MAX_PREVIEW_SOURCE_SIZE) { gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE); return; // unpreviewable, 0px, or unsafely large } if (preview_width > MAX_PREVIEW_SIZE || preview_height > MAX_PREVIEW_SIZE) { pixbuf = gdk_pixbuf_new_from_file_at_size (filename, MAX_PREVIEW_SIZE, MAX_PREVIEW_SIZE, NULL); } else { pixbuf = gdk_pixbuf_new_from_file (filename, NULL); } pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf); gtk_widget_set_size_request (GTK_WIDGET (preview), gdk_pixbuf_get_width (pixbuf) + 6, gdk_pixbuf_get_height (pixbuf) + 6); gtk_image_set_from_pixbuf (preview, pixbuf); gtk_file_chooser_set_preview_widget_active (file_chooser, pixbuf != NULL); }
static gboolean import_data (const gchar *filename, DiagramData *data, DiaContext *ctx, void* user_data) { DiaObjectType *otype = object_get_type("Standard - Image"); gint width, height; if (!otype) /* this would be really broken */ return FALSE; if (!user_data) { dia_context_add_message(ctx, _("Calling error, missing user_data.")); return FALSE; } if (gdk_pixbuf_get_file_info (filename, &width, &height)) { DiaObject *obj; Handle *h1, *h2; Point point; point.x = point.y = 0.0; obj = otype->ops->create(&point, otype->default_user_data, &h1, &h2); if (obj) { GPtrArray *plist = g_ptr_array_new (); prop_list_add_filename (plist, "image_file", filename); prop_list_add_real (plist, "elem_width", width / 20.0); prop_list_add_real (plist, "elem_height", height / 20.0); obj->ops->set_props(obj, plist); prop_list_free (plist); layer_add_object(data->active_layer, obj); return TRUE; } } else { dia_context_add_message(ctx, _("Pixbuf[%s] can't load:\n%s"), (gchar*)user_data, dia_context_get_filename(ctx)); } return FALSE; }
/******************************** * AL_Sheet_Add * Add New sheet to project @ filename: new image */ gboolean AL_Sheet_Add( gchar * filename ) { gboolean results = FALSE; gchar * file, * dest; GdkPixbuf * image = NULL; GdkPixbufFormat * f = gdk_pixbuf_get_file_info(filename, NULL, NULL); if ( g_strcmp0(gdk_pixbuf_format_get_name(f), "png") ) // Not a PNG image { file = g_strconcat( g_path_get_basename(filename), ".png", NULL); dest = g_build_filename( mokoiBasePath, "sprites", file, NULL ); GdkPixbuf * src = gdk_pixbuf_new_from_file( filename, NULL ); results = gdk_pixbuf_save(src, dest, "png", NULL, NULL); g_object_unref( src ); } else { file = g_path_get_basename( filename ); dest = g_build_filename( mokoiBasePath, "sprites", file, NULL ); results = Meg_FileCopy( filename, dest ); } if ( results ) { image = gdk_pixbuf_new_from_file( dest, NULL ); Sheet_Create( image, dest ); Sheet_Get( file, TRUE ); g_object_unref( image ); } else { Meg_Error_Print( __func__, __LINE__, "AL_Sheet_Add: Can't create %s", dest ); } g_free( dest ); g_free( file ); return results; }
static GdkPixbuf * _eventd_nd_pixbuf_from_file(const gchar *path, gint width, gint height) { GError *error = NULL; GdkPixbufFormat *format; GdkPixbuf *pixbuf; if ( *path == 0 ) return NULL; if ( ( ( width > 0 ) || ( height > 0 ) ) && ( ( format = gdk_pixbuf_get_file_info(path, NULL, NULL) ) != NULL ) && gdk_pixbuf_format_is_scalable(format) ) pixbuf = gdk_pixbuf_new_from_file_at_size(path, width, height, &error); else pixbuf = gdk_pixbuf_new_from_file(path, &error); if ( pixbuf == NULL ) g_warning("Couldn't load file '%s': %s", path, error->message); g_clear_error(&error); return pixbuf; }
static GdkPixbuf * create_preview_pixbuf (const gchar *uri) { GdkPixbuf *pixbuf = NULL; if ((uri != NULL) && (uri[0] != '\0')) { gchar *file = NULL; if (g_path_is_absolute (uri) == TRUE) { file = g_strdup (uri); } else { /* URIs are local, because gtk_file_chooser_get_local_only() is true. */ file = g_filename_from_uri (uri, NULL, NULL); } if (file != NULL) { GdkPixbufFormat *info; gint width; gint height; info = gdk_pixbuf_get_file_info (file, &width, &height); if (width > 128 || height > 128) { pixbuf = gdk_pixbuf_new_from_file_at_size (file, 128, 128, NULL); } else { pixbuf = gdk_pixbuf_new_from_file (file, NULL); } g_free (file); } } return pixbuf; }
static GdkPixbuf* _vfs_thumbnail_load( const char* file_path, const char* uri, int size, time_t mtime ) { #if GLIB_CHECK_VERSION(2, 16, 0) GChecksum *cs; #else md5_state_t md5_state; md5_byte_t md5[ 16 ]; #endif char file_name[ 40 ]; char* thumbnail_file; char mtime_str[ 32 ]; const char* thumb_mtime; int i, w, h; struct stat statbuf; GdkPixbuf* thumbnail, *result = NULL; int create_size; if ( size > 256 ) create_size = 512; else if ( size > 128 ) create_size = 256; else create_size = 128; gboolean file_is_video = FALSE; #ifdef HAVE_FFMPEG VFSMimeType* mimetype = vfs_mime_type_get_from_file_name( file_path ); if ( mimetype ) { if ( strncmp( vfs_mime_type_get_type( mimetype ), "video/", 6 ) == 0 ) file_is_video = TRUE; vfs_mime_type_unref( mimetype ); } #endif if ( file_is_video == FALSE ) { if ( !gdk_pixbuf_get_file_info( file_path, &w, &h ) ) return NULL; /* image format cannot be recognized */ /* If the image itself is very small, we should load it directly */ if ( w <= create_size && h <= create_size ) { if( w <= size && h <= size ) return gdk_pixbuf_new_from_file( file_path, NULL ); return gdk_pixbuf_new_from_file_at_size( file_path, size, size, NULL ); } } #if GLIB_CHECK_VERSION(2, 16, 0) cs = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(cs, uri, strlen(uri)); memcpy( file_name, g_checksum_get_string(cs), 32 ); g_checksum_free(cs); #else md5_init( &md5_state ); md5_append( &md5_state, ( md5_byte_t * ) uri, strlen( uri ) ); md5_finish( &md5_state, md5 ); for ( i = 0; i < 16; ++i ) sprintf( ( file_name + i * 2 ), "%02x", md5[ i ] ); #endif strcpy( ( file_name + 32 ), ".png" ); thumbnail_file = g_build_filename( g_get_home_dir(), ".thumbnails/normal", file_name, NULL ); if( G_UNLIKELY( 0 == mtime ) ) { if( stat( file_path, &statbuf ) != -1 ) mtime = statbuf.st_mtime; } if ( file_is_video && time( NULL ) - mtime < 5 ) /* if mod time of video being thumbnailed is less than 5 sec ago, * don't create a thumbnail (is copying?) * FIXME: This means that a newly saved file may not show a thumbnail * until refresh. */ return NULL; /* load existing thumbnail */ thumbnail = gdk_pixbuf_new_from_file( thumbnail_file, NULL ); if ( thumbnail ) { w = gdk_pixbuf_get_width( thumbnail ); h = gdk_pixbuf_get_height( thumbnail ); } if ( !thumbnail || ( w < size && h < size ) || !( thumb_mtime = gdk_pixbuf_get_option( thumbnail, "tEXt::Thumb::MTime" ) ) || atol( thumb_mtime ) != mtime ) { if( thumbnail ) g_object_unref( thumbnail ); /* create new thumbnail */ if ( file_is_video == FALSE ) { thumbnail = gdk_pixbuf_new_from_file_at_size( file_path, create_size, create_size, NULL ); if ( thumbnail ) { // Note: gdk_pixbuf_apply_embedded_orientation returns a new // pixbuf or same with incremented ref count, so unref GdkPixbuf* thumbnail_old = thumbnail; thumbnail = gdk_pixbuf_apply_embedded_orientation( thumbnail ); g_object_unref( thumbnail_old ); sprintf( mtime_str, "%lu", mtime ); gdk_pixbuf_save( thumbnail, thumbnail_file, "png", NULL, "tEXt::Thumb::URI", uri, "tEXt::Thumb::MTime", mtime_str, NULL ); chmod( thumbnail_file, 0600 ); /* only the owner can read it. */ } } #ifdef HAVE_FFMPEG else { video_thumbnailer* video_thumb = video_thumbnailer_create(); /* Setting a callback to allow silencing of stdout/stderr messages * from the library. This is no longer required since v2.0.11, where * silence is the default. It can be used for debugging in 2.0.11 * and later. */ //video_thumbnailer_set_log_callback(on_video_thumbnailer_log_message); if ( video_thumb ) { video_thumb->seek_percentage = 25; video_thumb->overlay_film_strip = 1; video_thumb->thumbnail_size = create_size; video_thumbnailer_generate_thumbnail_to_file( video_thumb, file_path, thumbnail_file ); video_thumbnailer_destroy( video_thumb ); chmod( thumbnail_file, 0600 ); /* only the owner can read it. */ thumbnail = gdk_pixbuf_new_from_file( thumbnail_file, NULL ); } } #endif } if ( thumbnail ) { w = gdk_pixbuf_get_width( thumbnail ); h = gdk_pixbuf_get_height( thumbnail ); if ( w > h ) { h = h * size / w; w = size; } else if ( h > w ) { w = w * size / h; h = size; } else { w = h = size; } if ( w > 0 && h > 0 ) result = gdk_pixbuf_scale_simple( thumbnail, w, h, GDK_INTERP_BILINEAR ); g_object_unref( thumbnail ); } g_free( thumbnail_file ); return result; }
GthImage * gth_pixbuf_new_from_file (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gboolean *loaded_original, gboolean scale_to_original, GCancellable *cancellable, GError **error) { ScaleData scale_data; GdkPixbufLoader *pixbuf_loader; GdkPixbuf *pixbuf; GthImage *image; gboolean original_size_rotated = FALSE; if (original_width != NULL) *original_width = -1; if (original_height != NULL) *original_height = -1; scale_data.requested_size = requested_size; scale_data.original_width = -1; scale_data.original_height = -1; scale_data.loader_width = -1; scale_data.loader_height = -1; pixbuf_loader = gdk_pixbuf_loader_new (); g_signal_connect (pixbuf_loader, "size-prepared", G_CALLBACK (pixbuf_loader_size_prepared_cb), &scale_data); pixbuf = load_from_stream (pixbuf_loader, istream, requested_size, cancellable, error); g_object_unref (pixbuf_loader); if ((pixbuf != NULL) && scale_to_original) { GdkPixbuf *tmp; tmp = _gdk_pixbuf_scale_simple_safe (pixbuf, scale_data.original_width, scale_data.original_height, GDK_INTERP_NEAREST); g_object_unref (pixbuf); pixbuf = tmp; } if ((original_width != NULL) && (original_height != NULL)) { if (file_data != NULL) { char *path; path = g_file_get_path (file_data->file); if (path != NULL) { gdk_pixbuf_get_file_info (path, &scale_data.original_width, &scale_data.original_height); original_size_rotated = TRUE; g_free (path); } } } if (pixbuf != NULL) { GdkPixbuf *rotated; rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf); if (rotated != NULL) { if (! original_size_rotated) { /* swap width and height */ int tmp = scale_data.original_width; scale_data.original_width = scale_data.original_height; scale_data.original_height =tmp; } g_object_unref (pixbuf); pixbuf = rotated; } } image = gth_image_new (); if (pixbuf != NULL) { cairo_surface_t *surface; cairo_surface_metadata_t *metadata; surface = _cairo_image_surface_create_from_pixbuf (pixbuf); metadata = _cairo_image_surface_get_metadata (surface); metadata->original_width = scale_data.original_width; metadata->original_height = scale_data.original_height; metadata->has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); gth_image_set_cairo_surface (image, surface); } if (original_width != NULL) *original_width = scale_data.original_width; if (original_height != NULL) *original_height = scale_data.original_height; if (loaded_original != NULL) *loaded_original = (pixbuf != NULL) && (scale_data.original_width == gdk_pixbuf_get_width (pixbuf)) && (scale_data.original_height == gdk_pixbuf_get_height (pixbuf)); _g_object_unref (pixbuf); return image; }
static void prefs_custom_header_val_from_file_cb(void) { gchar *filename = NULL; gchar *contents = NULL; const gchar *hdr = gtk_entry_get_text(GTK_ENTRY(customhdr.hdr_entry)); if (!strcmp(hdr, "Face")) filename = filesel_select_file_open(_("Choose a PNG file"), NULL); else if (!strcmp(hdr, "X-Face")) filename = filesel_select_file_open(_("Choose an XBM file"), NULL); else filename = filesel_select_file_open(_("Choose a text file"), NULL); if (!strcmp(hdr, "Face") || !strcmp(hdr, "X-Face")) { if (filename && is_file_exist(filename)) { FILE *fp = NULL; gint len; gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE]; gchar *tmp = NULL; gint w, h; GdkPixbufFormat *format = gdk_pixbuf_get_file_info( filename, &w, &h); if (format == NULL) { alertpanel_error(_("This file isn't an image.")); g_free(filename); return; } if (w != 48 || h != 48) { alertpanel_error(_("The chosen image isn't the correct size (48x48).")); g_free(filename); return; } if (!strcmp(hdr, "Face")) { if (get_file_size(filename) > 725) { alertpanel_error(_("The image is too big; it must be maximum 725 bytes.")); g_free(filename); return; } if (g_ascii_strcasecmp("png", gdk_pixbuf_format_get_name(format))) { alertpanel_error(_("The image isn't in the correct format (PNG).")); g_print("%s\n", gdk_pixbuf_format_get_name(format)); g_free(filename); return; } } else if (!strcmp(hdr, "X-Face")) { gchar *tmp = NULL, *cmd = NULL; int i = 0; if (g_ascii_strcasecmp("xbm", gdk_pixbuf_format_get_name(format))) { alertpanel_error(_("The image isn't in the correct format (XBM).")); g_print("%s\n", gdk_pixbuf_format_get_name(format)); g_free(filename); return; } cmd = g_strdup_printf("compface %s", filename); tmp = get_command_output(cmd); g_free(cmd); if (tmp == NULL || *tmp == '\0') { alertpanel_error(_("Couldn't call `compface`. Make sure it's in your $PATH.")); g_free(filename); g_free(tmp); return; } if (strstr(tmp, "compface:")) { alertpanel_error(_("Compface error: %s"), tmp); g_free(filename); g_free(tmp); return; } while (tmp[i]) { gchar *tmp2 = NULL; if (tmp[i] == ' ') { i++; continue; } if (tmp[i] == '\r' || tmp[i] == '\n') { i++; continue; } tmp2 = contents; contents = g_strdup_printf("%s%c",tmp2?tmp2:"", tmp[i]); g_free(tmp2); i++; } g_free(tmp); goto settext; } fp = g_fopen(filename, "rb"); if (!fp) { g_free(filename); return; } while ((len = fread(inbuf, sizeof(gchar), B64_LINE_SIZE, fp)) == B64_LINE_SIZE) { base64_encode(outbuf, inbuf, B64_LINE_SIZE); tmp = contents; contents = g_strconcat(tmp?tmp:"",outbuf, NULL); g_free(tmp); } if (len > 0 && feof(fp)) { tmp = contents; base64_encode(outbuf, inbuf, len); contents = g_strconcat(tmp?tmp:"",outbuf, NULL); g_free(tmp); } fclose(fp); } } else { if (!filename) return; contents = file_read_to_str(filename); if (strchr(contents, '\n') || strchr(contents,'\r')) { alertpanel_error(_("This file contains newlines.")); g_free(contents); g_free(filename); return; } } settext: if (contents && strlen(contents)) gtk_entry_set_text(GTK_ENTRY(customhdr.val_entry), contents); g_free(contents); g_free(filename); }
static gboolean prepare_photo_id (GtkWindow *parent, gchar *path, gchar **result, GError **error) { GdkPixbuf *pixbuf = NULL; GdkPixbuf *sampled; GdkPixbufFormat *format; gint width, height; gboolean rewrite = FALSE; gboolean resample = FALSE; gboolean suggest = FALSE; gboolean r; gchar *name; struct stat sb; int fd; g_assert (path); g_assert (result); g_assert (!error || !*error); *result = NULL; format = gdk_pixbuf_get_file_info (path, &width, &height); if (!format) { g_set_error (error, SEAHORSE_ERROR, -1, _("This is not a image file, or an unrecognized kind of image file. Try to use a JPEG image.")); return FALSE; } /* Check if it's a JPEG */ name = gdk_pixbuf_format_get_name (format); r = g_strcmp0 (name, "jpeg") == 0; g_free (name); /* JPEGs we can use straight up */ if (r) { /* If so we may just be able to use it straight up */ if (stat (path, &sb) != -1) { /* Large file size, suggest resampling */ if (sb.st_size > 8192) suggest = TRUE; } /* Other formats */ } else { rewrite = TRUE; /* Check for large, but allow strange orientations */ if ((width + height) > (LARGE_WIDTH + LARGE_HEIGHT)) suggest = TRUE; } /* Suggest to the user that we resize the photo */ if (suggest) { switch (suggest_resize (parent)) { case GTK_RESPONSE_ACCEPT: resample = TRUE; rewrite = TRUE; break; case GTK_RESPONSE_REJECT: resample = FALSE; break; default: /* FALSE with error not set = cancel */ return FALSE; } } /* No rewrite */ if (!rewrite) return TRUE; /* Load the photo if necessary */ pixbuf = gdk_pixbuf_new_from_file (path, error); if (!pixbuf) return FALSE; /* Resize it properly */ if (resample && calc_scale (&width, &height)) { sampled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); g_return_val_if_fail (sampled != NULL, FALSE); pixbuf = sampled; sampled = NULL; } /* And write it out to a temp */ fd = g_file_open_tmp ("seahorse-photo.XXXXXX", result, error); if (fd == -1) { g_object_unref (pixbuf); return FALSE; } r = gdk_pixbuf_save_to_callback (pixbuf, save_to_fd, GINT_TO_POINTER (fd), "jpeg", error, "quality", "75", NULL); close (fd); g_object_unref (pixbuf); if (!r) { g_free (*result); *result = NULL; return FALSE; } return TRUE; }
/* Setting '/theme' changed either at widget or at xfconf property */ static void _xfdashboard_settings_widget_changed_theme(XfdashboardSettings *self, GtkTreeSelection *inSelection) { XfdashboardSettingsPrivate *priv; GtkTreeModel *model; GtkTreeIter iter; gchar *themeDisplayName; gchar *themeComment; gchar *themeAuthor; gchar *themeVersion; gchar *themeScreenshot; gchar *themeFilename; gchar *themeName; g_return_if_fail(XFDASHBOARD_IS_SETTINGS(self)); g_return_if_fail(GTK_IS_TREE_SELECTION(inSelection)); priv=self->priv; themeDisplayName=NULL; themeComment=NULL; themeAuthor=NULL; themeVersion=NULL; themeScreenshot=NULL; themeFilename=NULL; themeName=NULL; /* Get selected entry from widget */ if(gtk_tree_selection_get_selected(inSelection, &model, &iter)) { /* Get data from model */ gtk_tree_model_get(model, &iter, COLUMN_THEME_NAME, &themeName, COLUMN_THEME_FILE, &themeFilename, COLUMN_THEME_DISPLAY_NAME, &themeDisplayName, COLUMN_THEME_DESCRIPTION, &themeComment, COLUMN_THEME_AUTHORS, &themeAuthor, COLUMN_THEME_VERSION, &themeVersion, COLUMN_THEME_SCREENSHOTS, &themeScreenshot, -1); } /* Set text in labels */ if(themeDisplayName) { gtk_label_set_text(GTK_LABEL(priv->widgetThemeName), themeDisplayName); gtk_widget_show(priv->widgetThemeName); gtk_widget_show(priv->widgetThemeNameLabel); } else { gtk_widget_hide(priv->widgetThemeName); gtk_widget_hide(priv->widgetThemeNameLabel); } if(themeComment) { gtk_label_set_text(GTK_LABEL(priv->widgetThemeDescription), themeComment); gtk_widget_show(priv->widgetThemeDescription); gtk_widget_show(priv->widgetThemeDescriptionLabel); } else { gtk_widget_hide(priv->widgetThemeDescription); gtk_widget_hide(priv->widgetThemeDescriptionLabel); } if(themeAuthor) { gtk_label_set_text(GTK_LABEL(priv->widgetThemeAuthor), themeAuthor); gtk_widget_show(priv->widgetThemeAuthor); gtk_widget_show(priv->widgetThemeAuthorLabel); } else { gtk_widget_hide(priv->widgetThemeAuthor); gtk_widget_hide(priv->widgetThemeAuthorLabel); } if(themeVersion) { gtk_label_set_text(GTK_LABEL(priv->widgetThemeVersion), themeVersion); gtk_widget_show(priv->widgetThemeVersion); gtk_widget_show(priv->widgetThemeVersionLabel); } else { gtk_widget_hide(priv->widgetThemeVersion); gtk_widget_hide(priv->widgetThemeVersionLabel); } /* Set screenshot */ if(themeScreenshot) { gchar *screenshotFile; GdkPixbuf *screenshotImage; screenshotFile=NULL; screenshotImage=NULL; /* Get screenshot file but resolve relative path if needed */ if(!g_path_is_absolute(themeScreenshot)) { GFile *file; GFile *parentPath; gchar *themePath; file=NULL; parentPath=NULL; themePath=NULL; /* Resolve relative path relative to theme path */ file=g_file_new_for_path(themeFilename); if(file) parentPath=g_file_get_parent(file); if(parentPath) themePath=g_file_get_path(parentPath); if(themePath) screenshotFile=g_build_filename(themePath, themeScreenshot, NULL); /* Release allocated resources */ if(themePath) g_free(themePath); if(parentPath) g_object_unref(parentPath); if(file) g_object_unref(file); } else { /* Path is absolute so just create a copy */ screenshotFile=g_strdup(themeScreenshot); } /* If screenshot file exists set up and show image * otherwise hide image. */ if(screenshotFile && g_file_test(screenshotFile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { GError *error; gint width; gint height; error=NULL; /* Check if screenshot fits into widget without scaling or * scale it to maximum size but preserve aspect ratio. */ if(gdk_pixbuf_get_file_info(screenshotFile, &width, &height)) { if(width<MAX_SCREENSHOT_WIDTH) { screenshotImage=gdk_pixbuf_new_from_file(screenshotFile, &error); } else { screenshotImage=gdk_pixbuf_new_from_file_at_scale(screenshotFile, MAX_SCREENSHOT_WIDTH, -1, TRUE, &error); } if(error) { g_warning("Could not load screenshot: %s", error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) g_error_free(error); if(screenshotImage) { g_object_unref(screenshotImage); screenshotImage=NULL; } } } } if(screenshotImage) { gtk_image_set_from_pixbuf(GTK_IMAGE(priv->widgetThemeScreenshot), screenshotImage); gtk_widget_show(priv->widgetThemeScreenshot); } else { gtk_widget_hide(priv->widgetThemeScreenshot); } /* Release allocated resources */ if(screenshotImage) g_object_unref(screenshotImage); if(screenshotFile) g_free(screenshotFile); } else { gtk_widget_hide(priv->widgetThemeScreenshot); } /* Set value at xfconf property if it must be changed */ if(themeName) { gchar *currentTheme; currentTheme=xfconf_channel_get_string(priv->xfconfChannel, "/theme", DEFAULT_THEME); if(g_strcmp0(currentTheme, themeName)) { xfconf_channel_set_string(priv->xfconfChannel, "/theme", themeName); } g_free(currentTheme); } /* Release allocated resources */ if(themeDisplayName) g_free(themeDisplayName); if(themeComment) g_free(themeComment); if(themeAuthor) g_free(themeAuthor); if(themeVersion) g_free(themeVersion); if(themeScreenshot) g_free(themeScreenshot); if(themeFilename) g_free(themeFilename); if(themeName) g_free(themeName); }
static gboolean notification_libnotify_create(MsgInfo *msginfo, NotificationFolderType nftype) { GdkPixbuf *pixbuf; NotificationPopup *ppopup; gchar *summary = NULL; gchar *text = NULL; gchar *utf8_str = NULL; gchar *subj = NULL; gchar *from = NULL; gchar *foldname = NULL; GList *caps = NULL; gboolean support_actions = FALSE; g_return_val_if_fail(msginfo, FALSE); ppopup = &(popup[nftype]); /* init libnotify if necessary */ if(!notify_is_initted()) { if(!notify_init("claws-mail")) { debug_print("Notification Plugin: Failed to initialize libnotify. " "No popup will be shown.\n"); return FALSE; } } switch(nftype) { case F_TYPE_MAIL: summary = _("New Mail message"); from = notification_libnotify_sanitize_str(msginfo->from ? msginfo->from : _("(No From)")); subj = notification_libnotify_sanitize_str(msginfo->subject ? msginfo->subject : _("(No Subject)")); if (notify_config.popup_display_folder_name) { foldname = notification_libnotify_sanitize_str(msginfo->folder->path); text = g_strconcat(from,"\n\n", subj, "\n\n", foldname, NULL); } else text = g_strconcat(from, "\n\n",subj, NULL); /* Make sure text is valid UTF8 */ utf8_str = notification_validate_utf8_str(text); g_free(text); if(from) g_free(from); if(subj) g_free(subj); if(foldname) g_free(foldname); break; case F_TYPE_NEWS: summary = _("New News post"); utf8_str = g_strdup(_("A new message arrived")); break; case F_TYPE_CALENDAR: summary = _("New Calendar message"); utf8_str = g_strdup(_("A new calendar message arrived")); break; case F_TYPE_RSS: summary = _("New RSS feed article"); utf8_str = g_strdup(_("A new article in a RSS feed arrived")); break; default: summary = _("New unknown message"); utf8_str = g_strdup(_("Unknown message type arrived")); break; } ppopup->notification = notify_notification_new(summary, utf8_str, NULL #if !NOTIFY_CHECK_VERSION(0, 7, 0) , NULL #endif ); g_free(utf8_str); if(ppopup->notification == NULL) { debug_print("Notification Plugin: Failed to create a new " "notification.\n"); return FALSE; } caps = notify_get_server_caps(); if(caps != NULL) { GList *c; for(c = caps; c != NULL; c = c->next) { if(strcmp((char*)c->data, "actions") == 0 ) { support_actions = TRUE; break; } } g_list_foreach(caps, (GFunc)g_free, NULL); g_list_free(caps); } /* Default action */ if (support_actions) notify_notification_add_action(ppopup->notification, "default", _("Present main window"), (NotifyActionCallback)default_action_cb, GINT_TO_POINTER(nftype), notification_libnotify_free_func); /* Icon */ pixbuf = NULL; #ifndef USE_ALT_ADDRBOOK if(msginfo && msginfo->from) { gchar *icon_path; icon_path = addrindex_get_picture_file(msginfo->from); if(is_file_exist(icon_path)) { GError *error = NULL; gint w, h; gdk_pixbuf_get_file_info(icon_path, &w, &h); if((w > 64) || (h > 64)) pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path, 64, 64, TRUE, &error); else pixbuf = gdk_pixbuf_new_from_file(icon_path, &error); if(!pixbuf) { debug_print("Could not load picture file: %s\n", error ? error->message : "no details"); g_error_free(error); } } else debug_print("Picture path does not exist: %s\n",icon_path); g_free(icon_path); } #endif if(!pixbuf) pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64)); if(pixbuf) { notify_notification_set_icon_from_pixbuf(ppopup->notification, pixbuf); g_object_unref(pixbuf); } else /* This is not fatal */ debug_print("Notification plugin: Icon could not be loaded.\n"); /* timeout */ notify_notification_set_timeout(ppopup->notification, notify_config.popup_timeout); /* Category */ notify_notification_set_category(ppopup->notification, "email.arrived"); /* get notified on bubble close */ g_signal_connect(G_OBJECT(popup->notification), "closed", G_CALLBACK(popup_timeout_fun), NULL); /* Show the popup */ notify_notification_set_hint_string(ppopup->notification, "desktop-entry", "claws-mail"); if(!notify_notification_show(ppopup->notification, &(ppopup->error))) { debug_print("Notification Plugin: Failed to send notification: %s\n", ppopup->error->message); g_clear_error(&(ppopup->error)); g_object_unref(G_OBJECT(ppopup->notification)); ppopup->notification = NULL; return FALSE; } debug_print("Notification Plugin: Popup created with libnotify.\n"); ppopup->count = 1; /* Store path to message */ if(nftype == F_TYPE_MAIL) { if(msginfo && msginfo->folder) { gchar *ident; ident = folder_item_get_identifier(msginfo->folder); ppopup->msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S, msginfo->msgnum); g_free(ident); } else ppopup->msg_path = NULL; } return TRUE; }
/** * as_image_load_filename_full: * @image: a #AsImage instance. * @filename: filename to read from * @dest_size: The size of the constructed pixbuf, or 0 for the native size * @src_size_min: The smallest source size allowed, or 0 for none * @flags: a #AsImageLoadFlags, e.g. %AS_IMAGE_LOAD_FLAG_NONE * @error: A #GError or %NULL. * * Reads an image from a file. * * Returns: %TRUE for success * * Since: 0.5.6 **/ gboolean as_image_load_filename_full (AsImage *image, const gchar *filename, guint dest_size, guint src_size_min, AsImageLoadFlags flags, GError **error) { AsImagePrivate *priv = GET_PRIVATE (image); guint pixbuf_height; guint pixbuf_width; guint tmp_height; guint tmp_width; g_autoptr(GdkPixbuf) pixbuf = NULL; g_autoptr(GdkPixbuf) pixbuf_src = NULL; g_autoptr(GdkPixbuf) pixbuf_tmp = NULL; /* only support non-deprecated types */ if (flags & AS_IMAGE_LOAD_FLAG_ONLY_SUPPORTED) { GdkPixbufFormat *fmt; fmt = gdk_pixbuf_get_file_info (filename, NULL, NULL); if (fmt == NULL) { g_set_error_literal (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "image format was not recognized"); return FALSE; } if (g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "png") != 0 && g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "jpeg") != 0 && g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "xpm") != 0 && g_strcmp0 (gdk_pixbuf_format_get_name (fmt), "svg") != 0) { g_set_error (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "image format %s is not supported", gdk_pixbuf_format_get_name (fmt)); return FALSE; } } /* update basename */ if (flags & AS_IMAGE_LOAD_FLAG_SET_BASENAME) { g_autofree gchar *basename = NULL; basename = g_path_get_basename (filename); as_image_set_basename (image, basename); } /* update checksum */ if (flags & AS_IMAGE_LOAD_FLAG_SET_CHECKSUM) { gsize len; g_autofree gchar *data = NULL; g_autofree gchar *md5_tmp = NULL; /* get the contents so we can hash the predictable file data, * rather than the unpredicatable (for JPEG) pixel data */ if (!g_file_get_contents (filename, &data, &len, error)) return FALSE; md5_tmp = g_compute_checksum_for_data (G_CHECKSUM_MD5, (guchar * )data, len); as_ref_string_assign_safe (&priv->md5, md5_tmp); } /* load the image of the native size */ if (dest_size == 0) { pixbuf = gdk_pixbuf_new_from_file (filename, error); if (pixbuf == NULL) return FALSE; as_image_set_pixbuf (image, pixbuf); return TRUE; } /* open file in native size */ if (g_str_has_suffix (filename, ".svg")) { pixbuf_src = gdk_pixbuf_new_from_file_at_scale (filename, (gint) dest_size, (gint) dest_size, TRUE, error); } else { pixbuf_src = gdk_pixbuf_new_from_file (filename, error); } if (pixbuf_src == NULL) return FALSE; /* check size */ if (gdk_pixbuf_get_width (pixbuf_src) < (gint) src_size_min && gdk_pixbuf_get_height (pixbuf_src) < (gint) src_size_min) { g_set_error (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "icon was too small %ix%i", gdk_pixbuf_get_width (pixbuf_src), gdk_pixbuf_get_height (pixbuf_src)); return FALSE; } /* don't do anything to an icon with the perfect size */ pixbuf_width = (guint) gdk_pixbuf_get_width (pixbuf_src); pixbuf_height = (guint) gdk_pixbuf_get_height (pixbuf_src); if (pixbuf_width == dest_size && pixbuf_height == dest_size) { as_image_set_pixbuf (image, pixbuf_src); return TRUE; } /* never scale up, just pad */ if (pixbuf_width < dest_size && pixbuf_height < dest_size) { g_debug ("icon padded to %ux%u as size %ux%u", dest_size, dest_size, pixbuf_width, pixbuf_height); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (gint) dest_size, (gint) dest_size); gdk_pixbuf_fill (pixbuf, 0x00000000); gdk_pixbuf_copy_area (pixbuf_src, 0, 0, /* of src */ (gint) pixbuf_width, (gint) pixbuf_height, pixbuf, (gint) (dest_size - pixbuf_width) / 2, (gint) (dest_size - pixbuf_height) / 2); as_image_set_pixbuf (image, pixbuf); return TRUE; } /* is the aspect ratio perfectly square */ if (pixbuf_width == pixbuf_height) { pixbuf = gdk_pixbuf_scale_simple (pixbuf_src, (gint) dest_size, (gint) dest_size, GDK_INTERP_HYPER); as_image_set_pixbuf (image, pixbuf); return TRUE; } /* create new square pixbuf with alpha padding */ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (gint) dest_size, (gint) dest_size); gdk_pixbuf_fill (pixbuf, 0x00000000); if (pixbuf_width > pixbuf_height) { tmp_width = dest_size; tmp_height = dest_size * pixbuf_height / pixbuf_width; } else { tmp_width = dest_size * pixbuf_width / pixbuf_height; tmp_height = dest_size; } pixbuf_tmp = gdk_pixbuf_scale_simple (pixbuf_src, (gint) tmp_width, (gint) tmp_height, GDK_INTERP_HYPER); if (flags & AS_IMAGE_LOAD_FLAG_SHARPEN) as_pixbuf_sharpen (pixbuf_tmp, 1, -0.5); gdk_pixbuf_copy_area (pixbuf_tmp, 0, 0, /* of src */ (gint) tmp_width, (gint) tmp_height, pixbuf, (gint) (dest_size - tmp_width) / 2, (gint) (dest_size - tmp_height) / 2); as_image_set_pixbuf (image, pixbuf); return TRUE; }
static GdkPixbuf* _vfs_thumbnail_load( const char* file_path, const char* uri, int size, time_t mtime ) { #if GLIB_CHECK_VERSION(2, 16, 0) GChecksum *cs; #else md5_state_t md5_state; md5_byte_t md5[ 16 ]; #endif char file_name[ 40 ]; char* thumbnail_file; char mtime_str[ 32 ]; const char* thumb_mtime; int i, w, h; struct stat statbuf; GdkPixbuf* thumbnail, *result = NULL; if ( !gdk_pixbuf_get_file_info( file_path, &w, &h ) ) return NULL; /* image format cannot be recognized */ /* If the image itself is very small, we should load it directly */ if ( w <= 128 && h <= 128 ) { if( w <= size && h <= size ) return gdk_pixbuf_new_from_file( file_path, NULL ); return gdk_pixbuf_new_from_file_at_size( file_path, size, size, NULL ); } #if GLIB_CHECK_VERSION(2, 16, 0) cs = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(cs, uri, strlen(uri)); memcpy( file_name, g_checksum_get_string(cs), 32 ); g_checksum_free(cs); #else md5_init( &md5_state ); md5_append( &md5_state, ( md5_byte_t * ) uri, strlen( uri ) ); md5_finish( &md5_state, md5 ); for ( i = 0; i < 16; ++i ) sprintf( ( file_name + i * 2 ), "%02x", md5[ i ] ); #endif strcpy( ( file_name + 32 ), ".png" ); thumbnail_file = g_build_filename( g_get_home_dir(), ".thumbnails/normal", file_name, NULL ); if( G_UNLIKELY( 0 == mtime ) ) { if( stat( file_path, &statbuf ) != -1 ) mtime = statbuf.st_mtime; } /* load existing thumbnail */ thumbnail = gdk_pixbuf_new_from_file( thumbnail_file, NULL ); if ( !thumbnail || !( thumb_mtime = gdk_pixbuf_get_option( thumbnail, "tEXt::Thumb::MTime" ) ) || atol( thumb_mtime ) != mtime ) { if( thumbnail ) g_object_unref( thumbnail ); /* create new thumbnail */ thumbnail = gdk_pixbuf_new_from_file_at_size( file_path, 128, 128, NULL ); if ( thumbnail ) { sprintf( mtime_str, "%lu", mtime ); gdk_pixbuf_save( thumbnail, thumbnail_file, "png", NULL, "tEXt::Thumb::URI", uri, "tEXt::Thumb::MTime", mtime_str, NULL ); chmod( thumbnail_file, 0600 ); /* only the owner can read it. */ } } if ( thumbnail ) { w = gdk_pixbuf_get_width( thumbnail ); h = gdk_pixbuf_get_height( thumbnail ); if ( w > h ) { h = h * size / w; w = size; } else if ( h > w ) { w = w * size / h; h = size; } else { w = h = size; } result = gdk_pixbuf_scale_simple( thumbnail, w, h, GDK_INTERP_BILINEAR ); gdk_pixbuf_unref( thumbnail ); } g_free( thumbnail_file ); return result; }
static void gth_metadata_provider_image_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes, GCancellable *cancellable) { gboolean format_recognized; GFileInputStream *stream; char *description = NULL; int width; int height; const char *mime_type = NULL; format_recognized = FALSE; stream = g_file_read (file_data->file, cancellable, NULL); if (stream != NULL) { int buffer_size; guchar *buffer; gssize size; buffer_size = BUFFER_SIZE; buffer = g_new (guchar, buffer_size); size = g_input_stream_read (G_INPUT_STREAM (stream), buffer, buffer_size, cancellable, NULL); if (size >= 0) { if ((size >= 24) /* PNG signature */ && (buffer[0] == 0x89) && (buffer[1] == 0x50) && (buffer[2] == 0x4E) && (buffer[3] == 0x47) && (buffer[4] == 0x0D) && (buffer[5] == 0x0A) && (buffer[6] == 0x1A) && (buffer[7] == 0x0A) /* IHDR Image header */ && (buffer[12] == 0x49) && (buffer[13] == 0x48) && (buffer[14] == 0x44) && (buffer[15] == 0x52)) { /* PNG */ width = (buffer[16] << 24) + (buffer[17] << 16) + (buffer[18] << 8) + buffer[19]; height = (buffer[20] << 24) + (buffer[21] << 16) + (buffer[22] << 8) + buffer[23]; description = _("PNG"); mime_type = "image/png"; format_recognized = TRUE; } #if HAVE_LIBJPEG else if ((size >= 4) && (buffer[0] == 0xff) && (buffer[1] == 0xd8) && (buffer[2] == 0xff)) { /* JPEG */ GthTransform orientation; if (g_seekable_can_seek (G_SEEKABLE (stream))) { g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, cancellable, NULL); } else { g_object_unref (stream); stream = g_file_read (file_data->file, cancellable, NULL); } if (_jpeg_get_image_info (G_INPUT_STREAM (stream), &width, &height, &orientation, cancellable, NULL)) { description = _("JPEG"); mime_type = "image/jpeg"; format_recognized = TRUE; if ((orientation == GTH_TRANSFORM_ROTATE_90) || (orientation == GTH_TRANSFORM_ROTATE_270) || (orientation == GTH_TRANSFORM_TRANSPOSE) || (orientation == GTH_TRANSFORM_TRANSVERSE)) { int tmp = width; width = height; height = tmp; } } } #endif /* HAVE_LIBJPEG */ #if HAVE_LIBWEBP else if ((size > 15) && (memcmp (buffer + 8, "WEBPVP8", 7) == 0)) { WebPDecoderConfig config; if (WebPInitDecoderConfig (&config)) { if (WebPGetFeatures (buffer, buffer_size, &config.input) == VP8_STATUS_OK) { width = config.input.width; height = config.input.height; description = _("WebP"); mime_type = "image/webp"; format_recognized = TRUE; } WebPFreeDecBuffer (&config.output); } } #endif /* HAVE_LIBWEBP */ else if ((size >= 26) && (strncmp ((char *) buffer, "gimp xcf ", 9) == 0)) { /* XCF */ GInputStream *mem_stream; GDataInputStream *data_stream; mem_stream = g_memory_input_stream_new_from_data (buffer, BUFFER_SIZE, NULL); data_stream = g_data_input_stream_new (mem_stream); g_data_input_stream_set_byte_order (data_stream, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN); if (g_seekable_seek (G_SEEKABLE (data_stream), 14, G_SEEK_SET, NULL, NULL)) { int base_type; width = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); height = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); base_type = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); if (base_type == 0) description = "XCF RGB"; else if (base_type == 1) description = "XCF grayscale"; else if (base_type == 2) description = "XCF indexed"; else description = "XCF"; mime_type = "image/x-xcf"; format_recognized = TRUE; } g_object_unref (data_stream); g_object_unref (mem_stream); } } g_free (buffer); g_object_unref (stream); } if (! format_recognized) { /* use gdk_pixbuf_get_file_info */ char *filename; filename = g_file_get_path (file_data->file); if (filename != NULL) { GdkPixbufFormat *format; format = gdk_pixbuf_get_file_info (filename, &width, &height); if (format != NULL) { format_recognized = TRUE; description = gdk_pixbuf_format_get_description (format); } g_free (filename); } } if (format_recognized) { char *size; g_file_info_set_attribute_string (file_data->info, "general::format", description); g_file_info_set_attribute_int32 (file_data->info, "image::width", width); g_file_info_set_attribute_int32 (file_data->info, "image::height", height); g_file_info_set_attribute_int32 (file_data->info, "frame::width", width); g_file_info_set_attribute_int32 (file_data->info, "frame::height", height); if (mime_type != NULL) gth_file_data_set_mime_type (file_data, mime_type); size = g_strdup_printf (_("%d × %d"), width, height); g_file_info_set_attribute_string (file_data->info, "general::dimensions", size); g_free (size); } }
static gboolean notification_trayicon_popup_create(MsgInfo *msginfo, NotificationFolderType nftype) { gchar *summary = NULL; gchar *utf8_str = NULL; GdkPixbuf *pixbuf; GList *caps = NULL; gboolean support_actions = FALSE; /* init libnotify if necessary */ if(!notify_is_initted()) { if(!notify_init("claws-mail")) { debug_print("Notification Plugin: Failed to initialize libnotify. " "No popups will be shown.\n"); return FALSE; } } /* Count messages */ notification_trayicon_popup_count_msgs(nftype); summary = notification_trayicon_popup_assemble_summary(); utf8_str = notification_trayicon_popup_assemble_body(msginfo); #if NOTIFY_CHECK_VERSION(0, 7, 0) popup.notification = notify_notification_new(summary, utf8_str, NULL); #else popup.notification = notify_notification_new(summary, utf8_str, NULL, NULL); notify_notification_attach_to_status_icon(popup.notification, trayicon); #endif g_free(summary); g_free(utf8_str); caps = notify_get_server_caps(); if(caps != NULL) { GList *c; for(c = caps; c != NULL; c = c->next) { if(strcmp((char*)c->data, "actions") == 0 ) { support_actions = TRUE; break; } } g_list_foreach(caps, (GFunc)g_free, NULL); g_list_free(caps); } /* Default action */ if (support_actions) notify_notification_add_action(popup.notification, "default", "Present main window", (NotifyActionCallback) notification_trayicon_popup_default_action_cb, GINT_TO_POINTER(nftype), notification_trayicon_popup_free_func); if(popup.notification == NULL) { debug_print("Notification Plugin: Failed to create a new notification.\n"); return FALSE; } /* Icon */ pixbuf = NULL; #ifndef USE_NEW_ADDRBOOK if(msginfo && msginfo->from) { gchar *icon_path; icon_path = addrindex_get_picture_file(msginfo->from); if(is_file_exist(icon_path)) { GError *error = NULL; gint w, h; gdk_pixbuf_get_file_info(icon_path, &w, &h); if((w > 64) || (h > 64)) pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path, 64, 64, TRUE, &error); else pixbuf = gdk_pixbuf_new_from_file(icon_path, &error); if(!pixbuf) { debug_print("Could not load picture file: %s\n", error ? error->message : "no details"); g_error_free(error); } } else debug_print("Picture path does not exist: %s\n",icon_path); g_free(icon_path); } #endif if(!pixbuf) pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64)); if(pixbuf) { notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf); g_object_unref(pixbuf); } else /* This is not fatal */ debug_print("Notification plugin: Icon could not be loaded.\n"); /* timeout */ notify_notification_set_timeout(popup.notification, notify_config.trayicon_popup_timeout); /* Category */ notify_notification_set_category(popup.notification, "email.arrived"); /* get notified on bubble close */ g_signal_connect(G_OBJECT(popup.notification), "closed", G_CALLBACK(popup_timeout_fun), NULL); /* Show the popup */ notify_notification_set_hint_string(popup.notification, "desktop-entry", "claws-mail"); if(!notify_notification_show(popup.notification, &(popup.error))) { debug_print("Notification Plugin: Failed to send notification: %s\n", popup.error->message); g_clear_error(&(popup.error)); g_object_unref(G_OBJECT(popup.notification)); popup.notification = NULL; return FALSE; } /* Store path to message */ if(nftype == F_TYPE_MAIL) { if(msginfo->folder && msginfo->folder) { gchar *ident; ident = folder_item_get_identifier(msginfo->folder); popup.msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S, msginfo->msgnum); g_free(ident); } else popup.msg_path = NULL; } debug_print("Notification Plugin: Popup created with libnotify.\n"); return TRUE; }
static gboolean _show_group_dialog (CairoDockGroupDescription *pGroupDescription) { gchar *cDescription = NULL; if (pGroupDescription->cDescription != NULL) { if (*pGroupDescription->cDescription == '/') { //g_print ("on recupere la description de %s\n", pGroupDescription->cDescription); gsize length = 0; GError *erreur = NULL; g_file_get_contents (pGroupDescription->cDescription, &cDescription, &length, &erreur); if (erreur != NULL) { cd_warning (erreur->message); g_error_free (erreur); } } } int iPreviewWidgetWidth; GtkWidget *pPreviewImage = cairo_dock_get_preview_image (&iPreviewWidgetWidth); if (pGroupDescription->cPreviewFilePath != NULL && strcmp (pGroupDescription->cPreviewFilePath, "none") != 0) { //g_print ("on recupere la prevue de %s\n", pGroupDescription->cPreviewFilePath); int iPreviewWidth, iPreviewHeight; GdkPixbuf *pPreviewPixbuf = NULL; if (gdk_pixbuf_get_file_info (pGroupDescription->cPreviewFilePath, &iPreviewWidth, &iPreviewHeight) != NULL) { if (iPreviewWidth > CAIRO_DOCK_PREVIEW_WIDTH) { iPreviewHeight *= 1.*CAIRO_DOCK_PREVIEW_WIDTH/iPreviewWidth; iPreviewWidth = CAIRO_DOCK_PREVIEW_WIDTH; } if (iPreviewHeight > CAIRO_DOCK_PREVIEW_HEIGHT) { iPreviewWidth *= 1.*CAIRO_DOCK_PREVIEW_HEIGHT/iPreviewHeight; iPreviewHeight = CAIRO_DOCK_PREVIEW_HEIGHT; } if (iPreviewWidth > iPreviewWidgetWidth) { iPreviewHeight *= 1.*iPreviewWidgetWidth/iPreviewWidth; iPreviewWidth = iPreviewWidgetWidth; } g_print ("preview : %dx%d\n", iPreviewWidth, iPreviewHeight); pPreviewPixbuf = gdk_pixbuf_new_from_file_at_size (pGroupDescription->cPreviewFilePath, iPreviewWidth, iPreviewHeight, NULL); } if (pPreviewPixbuf == NULL) { cd_warning ("pas de prevue disponible"); pPreviewPixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); } gtk_image_set_from_pixbuf (GTK_IMAGE (pPreviewImage), pPreviewPixbuf); gdk_pixbuf_unref (pPreviewPixbuf); gtk_widget_show (pPreviewImage); } if (s_pDialog != NULL) if (! cairo_dock_dialog_unreference (s_pDialog)) cairo_dock_dialog_unreference (s_pDialog); Icon *pIcon = cairo_dock_get_current_active_icon (); if (pIcon == NULL || pIcon->cParentDockName == NULL || pIcon->fPersonnalScale > 0) pIcon = cairo_dock_get_dialogless_icon (); CairoDock *pDock = cairo_dock_search_dock_from_name (pIcon != NULL ? pIcon->cParentDockName : NULL); s_pDialog = cairo_dock_show_temporary_dialog_with_icon (dgettext (pGroupDescription->cGettextDomain, cDescription != NULL ? cDescription : pGroupDescription->cDescription), pIcon, CAIRO_CONTAINER (pDock), 0., pGroupDescription->cIcon); cairo_dock_dialog_reference (s_pDialog); g_free (cDescription); s_iSidShowGroupDialog = 0; return FALSE; }
static gint headerview_show_contact_pic (HeaderView *headerview, MsgInfo *msginfo) { #ifndef USE_ALT_ADDRBOOK GtkWidget *hbox = headerview->hbox; GtkWidget *image; gchar *filename = NULL; GError *error = NULL; GdkPixbuf *picture = NULL; gint w, h; if (!gtk_widget_get_visible(headerview->hbox)) return -1; if (headerview->image) { gtk_widget_destroy(headerview->image); headerview->image = NULL; } filename = addrindex_get_picture_file(msginfo->from); if (!filename) return -1; if (!is_file_exist(filename)) { g_free(filename); return -1; } gdk_pixbuf_get_file_info(filename, &w, &h); if (w > 48 || h > 48) picture = gdk_pixbuf_new_from_file_at_scale(filename, 48, 48, TRUE, &error); else picture = gdk_pixbuf_new_from_file(filename, &error); g_free(filename); if (error) { debug_print("Failed to import image: \n%s", error->message); g_error_free(error); return -1; } if (picture) image = gtk_image_new_from_pixbuf(picture); else return -1; g_object_unref(picture); if (image) { gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); gtk_widget_show(image); } headerview->image = image; if (image == NULL) return -1; else return 0; #else /* new address book */ return -1; #endif }