/*! \fn GdkPixbuf* CDesktopAppChooser::m_LoadIconFile(const char* file_name, int size)
    \brief Try to find it in "pixmaps", "icons/hicolor", "icons/hicolor/scalable/apps" directories.

    \param[in] file_name. The icon name for searching.
    \param[in] size. The width(height) of the icon for searching. 
    \return PixelBuffer object representing the designated icon.
*/
GdkPixbuf* CDesktopAppChooser::m_LoadIconFile(const char* file_name, int size)
{
  GdkPixbuf* icon = NULL;
  char *file_path = NULL;
  const gchar **dirs = (const gchar**)g_get_system_data_dirs();   /* To read the environment variable which is specified in freedesktop.org Base Directory. */
  const gchar **dir = NULL;
  gchar *sizeName = NULL;

  for( (dir = dirs); *dir; ++dir )
  {
     /* Searching in "/usr/share/pixmaps" directory */
     if(g_strrstr(file_name, ".") &&
        (g_strrstr(file_name, EXT_NAME_PNG) || g_strrstr(file_name, EXT_NAME_XPM) || g_strrstr(file_name, EXT_NAME_SVG)) )
     {
        file_path = g_build_filename( *dir, ICON_SEARCH_PATH_PIXMAPS, file_name, NULL );
        icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

        if(file_path)		
          g_free(file_path);

        file_path = NULL;		

        if( icon )
		  break;
     }
     else
     {
        gchar *tempFileName = NULL;

        /* Try to load icon file with ".png" extension. */
        tempFileName = g_strdup_printf("%s%s", file_name, EXT_NAME_PNG);
        file_path = g_build_filename( *dir, ICON_SEARCH_PATH_PIXMAPS, tempFileName, NULL );
        icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

        if(tempFileName)
          g_free(tempFileName);

        tempFileName = NULL;

        if(file_path)		
          g_free(file_path);

        file_path = NULL;		

        if( icon )
          break;

        /* Try to load icon file with ".xpm" extension. */
        tempFileName = g_strdup_printf("%s%s", file_name, EXT_NAME_XPM);
        file_path = g_build_filename( *dir, ICON_SEARCH_PATH_PIXMAPS, tempFileName, NULL );
        icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

        if(tempFileName)
          g_free(tempFileName);

        tempFileName = NULL;

        if(file_path)		
          g_free(file_path);

        file_path = NULL;		

        if( icon )
          break;

        /* Try to load icon whose name in the end of  ".svg" */
        tempFileName = g_strdup_printf("%s%s", file_name, EXT_NAME_SVG);
        file_path = g_build_filename( *dir, ICON_SEARCH_PATH_PIXMAPS, tempFileName, NULL );
        icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

        if(tempFileName)
          g_free(tempFileName);

        tempFileName = NULL;

        if(file_path)		
          g_free(file_path);

        file_path = NULL;		

        if( icon )
          break;
     }	

     /* Searching in "/usr/share/icons/hicolor/SizexSize/apps", 
        "/usr/local/share/icons/hicolor/SizexSize/apps" directories.
        These are needed to assign the directory name formed in size. */
     sizeName = g_strdup_printf("%s/%dx%d/apps", ICON_SEARCH_PATH_HICOLOR, size, size);
     file_path = g_build_filename( *dir, sizeName, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(file_path)		
       g_free( file_path );

     if(sizeName)		
       g_free(sizeName);

     file_path = NULL;	
     sizeName = NULL;	

     if( icon )
       break;

     /* Searching in "/usr/share/icons/hicolor/scalable/apps",
        "/usr/local/share/icons/hicolor/scalable/apps" directories. */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_HICOLOR_SCALABLE, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(file_path)		
       g_free( file_path );

     file_path = NULL;	

     if( icon )
       break;

     /* Searching in "/usr/share/icons/gnome/scalable" directory. */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_GNOME_SCALABLE, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(file_path)
       g_free( file_path );

     file_path = NULL;	

     if( icon )
       break;

     /* Searching in "/usr/share/icons/gnome/scalable/apps" directory. */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_GNOME_SCALABLE_APPS, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(file_path)
       g_free( file_path );

     file_path = NULL;	

     if( icon )
       break;

     /* Searching in "/usr/share/icons/gnome/SizexSize/apps" directory.
		These are needed to assign the directory name formed in size. */
     sizeName = g_strdup_printf("%s/%dx%d/apps", ICON_SEARCH_PATH_GNOME, size, size);
     file_path = g_build_filename( *dir, sizeName, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(file_path)
       g_free (file_path);

     if(sizeName)
       g_free(sizeName);

     file_path = NULL;
     sizeName = NULL;

     if( icon )
       break;
  }

  return icon;
}
Пример #2
0
/*****************************************************************************
 * ItemChange: Playlist item change callback
 *****************************************************************************/
static int ItemChange( vlc_object_t *p_this, const char *psz_var,
                       vlc_value_t oldval, vlc_value_t newval, void *param )
{
    VLC_UNUSED(psz_var); VLC_UNUSED(oldval); VLC_UNUSED(newval);
    char           psz_tmp[MAX_LENGTH];
    char           psz_notify[MAX_LENGTH];
    char           *psz_title;
    char           *psz_artist;
    char           *psz_album;
    char           *psz_arturl;
    input_thread_t *p_input = playlist_CurrentInput( (playlist_t*)p_this );
    intf_thread_t  *p_intf  = param;
    intf_sys_t     *p_sys   = p_intf->p_sys;

    if( !p_input )
        return VLC_SUCCESS;

    if( p_input->b_dead )
    {
        /* Not playing anything ... */
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

    /* Wait a tad so the meta has been fetched
     * FIXME that's awfully wrong */
    msleep( 10000 );

    /* Playing something ... */
    input_item_t *p_input_item = input_GetItem( p_input );
    psz_title = input_item_GetTitleFbName( p_input_item );

    /* We need at least a title */
    if( EMPTY_STR( psz_title ) )
    {
        free( psz_title );
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

    psz_artist = input_item_GetArtist( p_input_item );
    psz_album = input_item_GetAlbum( p_input_item );

    if( !EMPTY_STR( psz_artist ) )
    {
        if( !EMPTY_STR( psz_album ) )
            snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s\n[%s]",
                      psz_title, psz_artist, psz_album );
        else
            snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s",
                      psz_title, psz_artist );
    }
    else
        snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>", psz_title );

    free( psz_title );
    free( psz_artist );
    free( psz_album );

    GdkPixbuf *pix = NULL;
    psz_arturl = input_item_GetArtURL( p_input_item );
    vlc_object_release( p_input );

    if( psz_arturl )
    {
        char *psz = make_path( psz_arturl );
        free( psz_arturl );
        psz_arturl = psz;
    }

    if( psz_arturl )
    { /* scale the art to show it in notify popup */
        GError *p_error = NULL;
        pix = gdk_pixbuf_new_from_file_at_scale( psz_arturl,
                                                 72, 72, TRUE, &p_error );
    }
    else /* else we show state-of-the art logo */
    {
        /* First try to get an icon from the current theme. */
        GtkIconTheme* p_theme = gtk_icon_theme_get_default();
        pix = gtk_icon_theme_load_icon( p_theme, "vlc", 72, 0, NULL);

        if( !pix )
        {
        /* Load icon from share/ */
            GError *p_error = NULL;
            char *psz_pixbuf;
            char *psz_data = config_GetDataDir();
            if( asprintf( &psz_pixbuf, "%s/icons/48x48/vlc.png", psz_data ) >= 0 )
            {
                pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error );
                free( psz_pixbuf );
            }
            free( psz_data );
        }
    }

    free( psz_arturl );

    /* we need to replace '&' with '&amp;' because '&' is a keyword of
     * notification-daemon parser */
    const int i_len = strlen( psz_tmp );
    int i_notify = 0;
    for( int i = 0; i < i_len && i_notify < ( MAX_LENGTH - 5 ); i++ )
    { /* we use MAX_LENGTH - 5 because if the last char of psz_tmp is '&'
       * we will need 5 more characters: 'amp;\0' .
       * however that's unlikely to happen because the last char is '\0' */
        if( psz_tmp[i] != '&' )
        {
            psz_notify[i_notify] = psz_tmp[i];
        }
        else
        {
            strcpy( &psz_notify[i_notify], "&amp;" );
            i_notify += 4;
        }
        i_notify++;
    }
    psz_notify[i_notify] = '\0';

    vlc_mutex_lock( &p_sys->lock );

    Notify( p_this, psz_notify, pix, p_intf );

    vlc_mutex_unlock( &p_sys->lock );

    return VLC_SUCCESS;
}
/*! \fn gchar* CDesktopAppChooser::m_GetIconFullName(const char* file_name, int size )
    \brief Try to find it in "pixmaps", "icons/hicolor", "icons/hicolor/scalable/apps" directories.

    \param[in] file_name.
    \param[in] size.
    \return Newly allocated string representing the icon's full name.
*/
gchar* CDesktopAppChooser::m_GetIconFullName(const char* file_name, int size)
{
  GdkPixbuf *icon = NULL;
  char *file_path = NULL;
  const gchar **dirs = (const gchar**)g_get_system_data_dirs();
  const gchar **dir = NULL;
  gchar *sizeName = NULL; 
	
  for( (dir = dirs); *dir; ++dir )
  {
     /* Searching in "/usr/share/pixmaps" */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_PIXMAPS/*"pixmaps"*/, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if( icon )
     {
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
        g_object_unref(icon);
        break;
     }
     else
     {
        if(file_path)		
          g_free(file_path);

        file_path = NULL;		
     }

     /* Searching in "/usr/share/icons/hicolor/SizexSize/apps", "/usr/local/share/icons/hicolor/SizexSize/apps" directories.
        These are needed to assign the directory name formed in size. */
     sizeName = g_strdup_printf( "%s/%dx%d/apps", ICON_SEARCH_PATH_HICOLOR, size, size);
     file_path = g_build_filename( *dir, sizeName, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(sizeName)		
       g_free(sizeName);

     sizeName = NULL;	
		
     if( icon )
     {
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
        g_object_unref(icon);
        break;
     }
     else
     {
        if(file_path)		
          g_free( file_path );

        file_path = NULL;	
     }

     /* Searching in "/usr/share/icons/hicolor/scalable/apps", "/usr/local/share/icons/hicolor/scalable/apps" directories. */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_HICOLOR_SCALABLE, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if( icon )
     {
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
        g_object_unref(icon);
        break;
     }
     else
     {
        if(file_path)		
          g_free( file_path );

        file_path = NULL;			
     }

     /* Searching in "/usr/share/icons/gnome/scalable". */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_GNOME_SCALABLE, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if( icon )
     {
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
        g_object_unref(icon);
        break;
     }
     else
     {
        if(file_path)
          g_free( file_path );

        file_path = NULL;	
     }

     /* Searching in "/usr/share/icons/gnome/scalable/apps". */
     file_path = g_build_filename( *dir, ICON_SEARCH_PATH_GNOME_SCALABLE_APPS, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if( icon )
     {
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
	    g_object_unref(icon);
        break;
     }
     else
     {
        if(file_path)
          g_free( file_path );

        file_path = NULL;	
     }

     /* Searching in "/usr/share/icons/gnome/SizexSize/apps".
        These are needed to assign the directory name formed in size. */
     sizeName = g_strdup_printf( "%s/%dx%d/apps", ICON_SEARCH_PATH_GNOME, size, size );
     file_path = g_build_filename( *dir,  sizeName, file_name, NULL );
     icon = gdk_pixbuf_new_from_file_at_scale( file_path, size, size, TRUE, NULL );

     if(sizeName)
       g_free(sizeName);

     sizeName = NULL;

     if ( icon )
     {
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
        g_object_unref(icon);			
        break;		
     }
	 else
     {
        if(file_path)
          g_free (file_path);

        file_path = NULL;
     }
  }

  return file_path;
}
Пример #4
0
static void
astro_contact_row_init (AstroContactRow *row)
{
  AstroContactRowPrivate *priv;
  ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
  gchar *font = NULL;
  GdkPixbuf *pixbuf;
  
  priv = row->priv = ASTRO_CONTACT_ROW_GET_PRIVATE (row);

  priv->name = NULL;
  priv->icon = NULL;
  priv->active = FALSE;

  /* The background texture */
  if (!GDK_IS_PIXBUF (bg_pixbuf))
    bg_pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR"/applet_bg.png", NULL);
  if (!CLUTTER_IS_ACTOR (bg_texture))
    {
      bg_texture = clutter_texture_new_from_pixbuf (bg_pixbuf);
      clutter_actor_show (bg_texture);
    }
  
  priv->bg = tidy_texture_frame_new (CLUTTER_TEXTURE (bg_texture), 
                                     15, 15, 15, 15);
  clutter_container_add_actor (CLUTTER_CONTAINER (row), priv->bg);
  clutter_actor_set_position (priv->bg, 0, 0);
  clutter_actor_set_size (priv->bg, CSW()*0.5, ROW_HEIGHT);
  clutter_actor_set_opacity (priv->bg, 0);

  /* The icon */
  priv->texture = clutter_texture_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (row), priv->texture);
  clutter_actor_set_position (priv->texture, PADDING, PADDING);
  clutter_actor_set_size (priv->texture, ICON_SIZE, ICON_SIZE);

  /* The label */
  font = g_strdup_printf ("Sans %d", (gint)(ROW_HEIGHT * 0.3));
  priv->label = clutter_label_new_full (font, " ", &white);
  clutter_label_set_line_wrap (CLUTTER_LABEL (priv->label), FALSE);
  clutter_actor_set_width (priv->label, CSW()/2);
  clutter_container_add_actor (CLUTTER_CONTAINER (row), priv->label);
  clutter_actor_set_position (priv->label, (PADDING*2) + ICON_SIZE, 
                              ROW_HEIGHT /2);
  g_free (font);

  /* Contact bar */
  pixbuf = gdk_pixbuf_new_from_file_at_scale (PKGDATADIR"/contact-bar.svg", 
                                              -1, ROW_HEIGHT-(PADDING*4), TRUE,
                                              NULL);
  priv->bar = clutter_texture_new_from_pixbuf (pixbuf);
  clutter_container_add_actor (CLUTTER_CONTAINER (row), priv->bar);
  clutter_actor_set_position (priv->bar, 
                              (PADDING*2) + ICON_SIZE,
                              ROW_HEIGHT + PADDING);
  clutter_actor_set_opacity (priv->bar, 0);

  /* Timelines */
  priv->active_time = clutter_timeline_new_for_duration (200);
  priv->active_temp = clutter_effect_template_new (priv->active_time,
                                                   clutter_sine_inc_func);
  priv->bar_time = clutter_timeline_new_for_duration (600);
  priv->bar_temp = clutter_effect_template_new (priv->bar_time,
                                                clutter_sine_inc_func);

  priv->active_time = clutter_timeline_new_for_duration (800);
  priv->alpha = clutter_alpha_new_full (priv->active_time,
                                        clutter_sine_inc_func,
                                        NULL, NULL);
  priv->behave = astro_behave_new (priv->alpha,
                                   (AstroBehaveAlphaFunc)_resize_alpha,
                                   row);

  clutter_actor_show_all (CLUTTER_ACTOR (row));
}
Пример #5
0
/**
 * asb_app_load_icon:
 */
static GdkPixbuf *
asb_app_load_icon (AsbApp *app,
		   const gchar *filename,
		   const gchar *logfn,
		   guint icon_size,
		   guint min_icon_size,
		   GError **error)
{
	GdkPixbuf *pixbuf = NULL;
	guint pixbuf_height;
	guint pixbuf_width;
	guint tmp_height;
	guint tmp_width;
	_cleanup_object_unref_ GdkPixbuf *pixbuf_src = NULL;
	_cleanup_object_unref_ GdkPixbuf *pixbuf_tmp = NULL;

	/* open file in native size */
	if (g_str_has_suffix (filename, ".svg")) {
		pixbuf_src = gdk_pixbuf_new_from_file_at_scale (filename,
								icon_size,
								icon_size,
								TRUE, error);
	} else {
		pixbuf_src = gdk_pixbuf_new_from_file (filename, error);
	}
	if (pixbuf_src == NULL)
		return NULL;

	/* check size */
	if (gdk_pixbuf_get_width (pixbuf_src) < (gint) min_icon_size &&
	    gdk_pixbuf_get_height (pixbuf_src) < (gint) min_icon_size) {
		g_set_error (error,
			     ASB_PLUGIN_ERROR,
			     ASB_PLUGIN_ERROR_FAILED,
			     "icon %s was too small %ix%i",
			     logfn,
			     gdk_pixbuf_get_width (pixbuf_src),
			     gdk_pixbuf_get_height (pixbuf_src));
		return NULL;
	}

	/* does the icon not have an alpha channel */
	if (!gdk_pixbuf_get_has_alpha (pixbuf_src)) {
		asb_package_log (asb_app_get_package (app),
				 ASB_PACKAGE_LOG_LEVEL_INFO,
				 "icon %s does not have an alpha channel",
				 logfn);
	}

	/* don't do anything to an icon with the perfect size */
	pixbuf_width = gdk_pixbuf_get_width (pixbuf_src);
	pixbuf_height = gdk_pixbuf_get_height (pixbuf_src);
	if (pixbuf_width == icon_size && pixbuf_height == icon_size)
		return g_object_ref (pixbuf_src);

	/* never scale up, just pad */
	if (pixbuf_width < icon_size && pixbuf_height < icon_size) {
		_cleanup_free_ gchar *size_str = NULL;
		size_str = g_strdup_printf ("%ix%i",
					    pixbuf_width,
					    pixbuf_height);
		asb_package_log (asb_app_get_package (app),
				 ASB_PACKAGE_LOG_LEVEL_INFO,
				 "icon %s padded to %ix%i as size %s",
				 logfn, icon_size, icon_size, size_str);
		pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
					 icon_size, icon_size);
		gdk_pixbuf_fill (pixbuf, 0x00000000);
		gdk_pixbuf_copy_area (pixbuf_src,
				      0, 0, /* of src */
				      pixbuf_width, pixbuf_height,
				      pixbuf,
				      (icon_size - pixbuf_width) / 2,
				      (icon_size - pixbuf_height) / 2);
		return pixbuf;
	}

	/* is the aspect ratio perfectly square */
	if (pixbuf_width == pixbuf_height) {
		pixbuf = gdk_pixbuf_scale_simple (pixbuf_src,
						  icon_size, icon_size,
						  GDK_INTERP_HYPER);
		as_pixbuf_sharpen (pixbuf, 1, -0.5);
		return pixbuf;
	}

	/* create new square pixbuf with alpha padding */
	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
				 icon_size, icon_size);
	gdk_pixbuf_fill (pixbuf, 0x00000000);
	if (pixbuf_width > pixbuf_height) {
		tmp_width = icon_size;
		tmp_height = icon_size * pixbuf_height / pixbuf_width;
	} else {
		tmp_width = icon_size * pixbuf_width / pixbuf_height;
		tmp_height = icon_size;
	}
	pixbuf_tmp = gdk_pixbuf_scale_simple (pixbuf_src, tmp_width, tmp_height,
					      GDK_INTERP_HYPER);
	as_pixbuf_sharpen (pixbuf_tmp, 1, -0.5);
	gdk_pixbuf_copy_area (pixbuf_tmp,
			      0, 0, /* of src */
			      tmp_width, tmp_height,
			      pixbuf,
			      (icon_size - tmp_width) / 2,
			      (icon_size - tmp_height) / 2);
	return pixbuf;
}
Пример #6
0
static gboolean images_save_resized_image(const gchar *image_filename){
	GdkPixbuf *pixbuf=NULL;
	GError *error=NULL;
	if(!(pixbuf=gdk_pixbuf_new_from_file_at_scale(image_filename, ImagesDefault, ImagesDefault, TRUE, &error))){
		debug("Image error: %s (%d x %d); error message: %s", image_filename, ImagesDefault, ImagesDefault, error->message);
		if(error)
			g_error_free(error);
		if(pixbuf)
			uber_object_unref(pixbuf);
		return FALSE;
	}
	
	gchar *image_type=NULL;
	if(!(image_type=g_regex_replace(images_extension_regex, image_filename, -1, 0, "\\1", 0, NULL))){
		debug("**ERROR:** failed to determine image type of: <%s>", image_filename);
		if(image_type)
			uber_free(image_type);
		if(pixbuf)
			uber_object_unref(pixbuf);
		return FALSE;
	}
	
	if(!( G_STR_N_EMPTY(image_type) && g_str_n_equal(image_type, image_filename) && strcasecmp(image_type, "gif") )){
		uber_free(image_type);
		uber_object_unref(pixbuf);
		return FALSE;
	}
	
	if(!strcasecmp(image_type, "jpg")){
		uber_free(image_type);
		image_type=g_strdup("jpeg");
	}else{
		gchar *image_type_lower=NULL;
		image_type_lower=g_utf8_strdown(image_type, -1);
		uber_free(image_type);
		image_type=image_type_lower;
		image_type_lower=NULL;
	}
	
	GSList *formats=NULL;
	for(formats=g_slist_nth(gdk_pixbuf_formats, 0); formats->data; formats=formats->next){
		//gdk_format=(GdkPixbufFormat)formats->data;
		if(!strcasecmp(image_type, gdk_pixbuf_format_get_name(formats->data))){
			error=NULL;
			gboolean resized_saved=FALSE;
			if(!(gdk_pixbuf_save(pixbuf, image_filename, image_type, &error, NULL))){
				debug("**ERROR:** failed to save resized image to: <%s>; error message: %s", image_filename, error->message);
				if(resized_saved)
					resized_saved=FALSE;
			}else{
				debug("Saved resized image to: <%s>", image_filename);
				if(!resized_saved)
					resized_saved=TRUE;
			}
			if(error)
				g_error_free(error);
			if(pixbuf)
				uber_object_unref(pixbuf);
			uber_free(image_type);
			
			return resized_saved;
		}
		//g_slist_free(formats);
	}
	
	uber_free(image_type);
	
	if(pixbuf)
		uber_object_unref(pixbuf);
	
	return FALSE;
}/*images_save_resized_image(image_filename);*/
Пример #7
0
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;
}
Пример #8
0
/*****************************************************************************
 * ItemChange: Playlist item change callback
 *****************************************************************************/
static int ItemChange( vlc_object_t *p_this, const char *psz_var,
                       vlc_value_t oldval, vlc_value_t newval, void *param )
{
    VLC_UNUSED(psz_var);
    VLC_UNUSED(oldval);
    VLC_UNUSED(newval);
    char                psz_tmp[MAX_LENGTH];
    char                psz_notify[MAX_LENGTH];
    char                *psz_title      = NULL;
    char                *psz_artist     = NULL;
    char                *psz_album      = NULL;
    char                *psz_arturl     = NULL;
    input_thread_t      *p_input        =  playlist_CurrentInput(
            (playlist_t*) p_this );
    intf_thread_t       *p_intf         = param;
    intf_sys_t          *p_sys          = p_intf->p_sys;

    if( !p_input )
        return VLC_SUCCESS;

    if( p_input->b_dead )
    {
        /* Not playing anything ... */
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

    /* Wait a tad so the meta has been fetched
     * FIXME that's awfully wrong */
    msleep( 1000*4 );

    /* Playing something ... */
    input_item_t *p_input_item = input_GetItem( p_input );
    psz_artist = input_item_GetArtist( p_input_item );
    psz_album = input_item_GetAlbum( p_input_item );
    psz_title = input_item_GetTitleFbName( p_input_item );

    if( EMPTY_STR( psz_title ) )
    {   /* Not enough metadata ... */
        free( psz_title );
        free( psz_artist );
        free( psz_album );
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }
    if( EMPTY_STR( psz_artist ) )
    {
        free( psz_artist );
        psz_artist = NULL;
    }
    if( EMPTY_STR( psz_album ) )
    {
        free( psz_album );
        psz_album = NULL;
    }

    if( psz_artist && psz_album )
        snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s\n[%s]",
                  psz_title, psz_artist, psz_album );
    else if( psz_artist )
        snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>\n%s",
                  psz_title, psz_artist );
    else
        snprintf( psz_tmp, MAX_LENGTH, "<b>%s</b>", psz_title );

    free( psz_title );
    free( psz_artist );
    free( psz_album );

    GdkPixbuf *pix = NULL;
    psz_arturl = input_item_GetArtURL( p_input_item );
    vlc_object_release( p_input );

    if( psz_arturl && !strncmp( psz_arturl, "file://", 7 ) &&
            decode_URI( psz_arturl + 7 ) )
    {   /* scale the art to show it in notify popup */
        GError *p_error = NULL;
        pix = gdk_pixbuf_new_from_file_at_scale( &psz_arturl[7],
                72, 72, TRUE, &p_error );
    }
    else /* else we show state-of-the art logo */
    {
        GError *p_error = NULL;
        char *psz_pixbuf;
        if( asprintf( &psz_pixbuf, "%s/vlc48x48.png", config_GetDataDir() ) >= 0 )
        {
            pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error );
            free( psz_pixbuf );
        }
    }

    free( psz_arturl );

    /* we need to replace '&' with '&amp;' because '&' is a keyword of
     * notification-daemon parser */
    const int i_len = strlen( psz_tmp );
    int i_notify = 0;
    for( int i = 0; i < i_len && i_notify < ( MAX_LENGTH - 5 ); i++ )
    {   /* we use MAX_LENGTH - 5 because if the last char of psz_tmp is '&'
         * we will need 5 more characters: 'amp;\0' .
         * however that's unlikely to happen because the last char is '\0' */
        if( psz_tmp[i] != '&' )
        {
            psz_notify[i_notify] = psz_tmp[i];
        }
        else
        {
            snprintf( &psz_notify[i_notify], 6, "&amp;" );
            i_notify += 4;
        }
        i_notify++;
    }
    psz_notify[i_notify] = '\0';

    vlc_mutex_lock( &p_sys->lock );

    Notify( p_this, psz_notify, pix, p_intf );

    vlc_mutex_unlock( &p_sys->lock );

    return VLC_SUCCESS;
}
static void
create_user_combobox (PolkitMateAuthenticationDialog *dialog)
{
  int n;
  GtkComboBox *combo;
  GtkTreeIter iter;
  GtkCellRenderer *renderer;

  /* if we've already built the list of admin users once, then avoid
   * doing it again.. (this is mainly used when the user entered the
   * wrong password and the dialog is recycled)
   */
  if (dialog->priv->store != NULL)
    return;

  combo = GTK_COMBO_BOX (dialog->priv->user_combobox);
  dialog->priv->store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);

  gtk_list_store_append (dialog->priv->store, &iter);
  gtk_list_store_set (dialog->priv->store, &iter,
                      PIXBUF_COL, NULL,
                      TEXT_COL, _("Select user..."),
                      USERNAME_COL, NULL,
                      -1);


  /* For each user */
  for (n = 0; dialog->priv->users[n] != NULL; n++)
    {
      gchar *gecos;
      gchar *real_name;
      GdkPixbuf *pixbuf;
      struct passwd *passwd;

      /* we're single threaded so this is fine */
      errno = 0;
      passwd = getpwnam (dialog->priv->users[n]);
      if (passwd == NULL)
        {
          g_warning ("Error doing getpwnam(\"%s\"): %s", dialog->priv->users[n], strerror (errno));
          continue;
        }

      if (passwd->pw_gecos != NULL)
        gecos = g_locale_to_utf8 (passwd->pw_gecos, -1, NULL, NULL, NULL);
      else
        gecos = NULL;

      if (gecos != NULL && strlen (gecos) > 0)
        {
          gchar *first_comma;
          first_comma = strchr (gecos, ',');
          if (first_comma != NULL)
            *first_comma = '\0';
        }
      if (gecos != NULL && strlen (gecos) > 0 && strcmp (gecos, dialog->priv->users[n]) != 0)
        real_name = g_strdup_printf (_("%s (%s)"), gecos, dialog->priv->users[n]);
       else
         real_name = g_strdup (dialog->priv->users[n]);
      g_free (gecos);

      /* Load users face */
      pixbuf = NULL;
      if (passwd->pw_dir != NULL)
        {
          gchar *path;
          path = g_strdup_printf ("%s/.face", passwd->pw_dir);
          /* TODO: we probably shouldn't hard-code the size to 16x16 */
          pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 16, 16, TRUE, NULL);
          g_free (path);
        }

      /* fall back to stock_person icon */
      if (pixbuf == NULL)
        {
          pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                             "stock_person",
                                             GTK_ICON_SIZE_MENU,
                                             0,
                                             NULL);
        }

      gtk_list_store_append (dialog->priv->store, &iter);
      gtk_list_store_set (dialog->priv->store, &iter,
                          PIXBUF_COL, pixbuf,
                          TEXT_COL, real_name,
                          USERNAME_COL, dialog->priv->users[n],
                          -1);

      g_free (real_name);
      g_object_unref (pixbuf);
    }

  gtk_combo_box_set_model (combo, GTK_TREE_MODEL (dialog->priv->store));

  renderer = gtk_cell_renderer_pixbuf_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE);
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo),
                                  renderer,
                                  "pixbuf", PIXBUF_COL,
                                  NULL);
  gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
                                      renderer,
                                      user_combobox_set_sensitive,
                                      NULL, NULL);

  renderer = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo),
                                  renderer,
                                  "text", TEXT_COL,
                                  NULL);
  gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
                                      renderer,
                                      user_combobox_set_sensitive,
                                      NULL, NULL);

  /* Initially select the "Select user..." ... */
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);

  /* Listen when a new user is selected */
  g_signal_connect (GTK_WIDGET (combo),
                    "changed",
                    G_CALLBACK (user_combobox_changed),
                    dialog);
}
Пример #10
0
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;
}
Пример #11
0
static GtkWidget *create_media_preview_ui_by_type (GtkWidget *window, gint type) {
  GtkWidget *hbox = NULL;
  GtkWidget *ebox = NULL;
  GdkPixbuf *pixbuf = NULL;
  GError *err = NULL;
  GtkTreeModel *model = NULL;
  gchar *url = NULL;
  gchar *prefix_env = NULL;

  hbox = gtk_hbox_new(TRUE, 6);
  ebox = gtk_event_box_new();
  if(type == EBOX_PHOTO_UI) {
    photo_item_t *pi = NULL;
    gchar file[1024] = {0}, logo[1024] = {0};

    prefix_env = getenv("PHOTO_PATH1");
    if(! prefix_env)
      prefix_env = PHOTO_PATH1;

    if(scan_photo_path(prefix_env, file, logo, &(g_pu.pl[0]))) {
      pi = (photo_item_t *) (g_pu.pl[0]->data);
      pixbuf = g_object_ref(pi->pixbuf);
      url = strdup(logo);
    }
    g_pu.ebox[0] = ebox;
    g_pu.curr[0] = g_pu.pl[0];
    DEBUG("pixbuf = %x, width = %d, height = %d\n", pixbuf, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
  } else {
    gchar file[1024] = {0}, logo[1024] = {0};

    prefix_env = getenv("MUSIC_PATH1");
    if(! prefix_env)
      prefix_env = MUSIC_PATH1;

    if(scan_music_path(prefix_env, file, logo)) {
      pixbuf = gdk_pixbuf_new_from_file_at_scale(logo, MEDIAUI_WIDTH-2, MEDIAUI_HEIGHT-2, FALSE, &err);
      url = strdup(file);
    }
  }
  ebox_set_data(ebox, url, pixbuf, model);
  gtk_widget_set_size_request(ebox, MEDIAUI_WIDTH, MEDIAUI_HEIGHT);
  g_signal_connect(G_OBJECT(ebox), "button_press_event", G_CALLBACK(ebox_button_press_event_cb), (gpointer)type);
  g_signal_connect(G_OBJECT(ebox), "expose-event", G_CALLBACK(ebox_draw_background), (gpointer)type);
  gtk_box_pack_start(GTK_BOX(hbox), ebox, FALSE, FALSE, 0);

  ebox = gtk_event_box_new();
  if(type == EBOX_PHOTO_UI) {
    photo_item_t *pi = NULL;
    gchar file[1024] = {0}, logo[1024] = {0};

    prefix_env = getenv("PHOTO_PATH2");
    if(! prefix_env)
      prefix_env = PHOTO_PATH2;

    if(scan_photo_path(prefix_env, file, logo, &(g_pu.pl[1]))) {
      pi = (photo_item_t *) (g_pu.pl[1]->data);
      pixbuf = g_object_ref(pi->pixbuf);
      url = strdup(logo);
    }
    g_pu.ebox[1] = ebox;
    g_pu.curr[1] = g_pu.pl[1];
    DEBUG("file = %s, pixbuf = %x, width = %d, height = %d\n", file, pixbuf, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
  } else {
    gchar file[1024] = {0}, logo[1024] = {0};

    prefix_env = getenv("MUSIC_PATH2");
    if(! prefix_env)
      prefix_env = MUSIC_PATH2;

    if(scan_music_path(prefix_env, file, logo)) {
      pixbuf = gdk_pixbuf_new_from_file_at_scale(logo, MEDIAUI_WIDTH-2, MEDIAUI_HEIGHT-2, FALSE, &err);
      url = strdup(file);
    }
  }
  ebox_set_data(ebox, url, pixbuf, model);
  gtk_widget_set_size_request(ebox, MEDIAUI_WIDTH, MEDIAUI_HEIGHT);
  g_signal_connect(G_OBJECT(ebox), "button_press_event", G_CALLBACK(ebox_button_press_event_cb), (gpointer)type);
  g_signal_connect(G_OBJECT(ebox), "expose-event", G_CALLBACK(ebox_draw_background), (gpointer)type);
  gtk_box_pack_start(GTK_BOX(hbox), ebox, FALSE, FALSE, 0);

  ebox = gtk_event_box_new();
  if(type == EBOX_PHOTO_UI) {
    photo_item_t *pi = NULL;
    gchar file[1024] = {0}, logo[1024] = {0};

    prefix_env = getenv("PHOTO_PATH3");
    if(! prefix_env)
      prefix_env = PHOTO_PATH3;

    if(scan_photo_path(prefix_env, file, logo, &(g_pu.pl[2]))) {
      pi = (photo_item_t *) (g_pu.pl[2]->data);
      pixbuf = g_object_ref(pi->pixbuf);
      url = strdup(logo);
    }
    g_pu.ebox[2] = ebox;
    g_pu.curr[2] = g_pu.pl[2];
    DEBUG("pixbuf = %x, width = %d, height = %d\n", pixbuf, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
  } else {
    gchar file[1024] = {0}, logo[1024] = {0};

    prefix_env = getenv("MUSIC_PATH3");
    if(! prefix_env)
      prefix_env = MUSIC_PATH3;

    if(scan_music_path(prefix_env, file, logo)) {
      pixbuf = gdk_pixbuf_new_from_file_at_scale(logo, MEDIAUI_WIDTH-2, MEDIAUI_HEIGHT-2, FALSE, &err);
      url = strdup(file);
    }
  }
  ebox_set_data(ebox, url, pixbuf, model);
  gtk_widget_set_size_request(ebox, MEDIAUI_WIDTH, MEDIAUI_HEIGHT);
  g_signal_connect(G_OBJECT(ebox), "button_press_event", G_CALLBACK(ebox_button_press_event_cb), (gpointer)type);
  g_signal_connect(G_OBJECT(ebox), "expose-event", G_CALLBACK(ebox_draw_background), (gpointer)type);
  gtk_box_pack_start(GTK_BOX(hbox), ebox, FALSE, FALSE, 0);

  return hbox;
}
Пример #12
0
/* 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);
}
Пример #13
0
gboolean toon_clutter_stage_set_window_icon(ClutterStage *stage, const gchar *path, GError ** /*error*/ )
{
    (void) stage;
    (void) path;
#if 0
    // TODO: assign some GError* to error in case of failure.
    Display *dpy = clutter_x11_get_default_display();
    Window win = clutter_x11_get_stage_window(stage);
    static Atom net_wm_icon = None;

    if (! net_wm_icon)
        net_wm_icon = XInternAtom(dpy, "_NET_WM_ICON", False);

    GdkPixbuf *pixbuf = NULL;
    GError *pixbuf_error = NULL;

    gint pixels_w = 32;
    gint pixels_h = 32;
    //g_info("Loading image at size of %dx%d\n", pixels_w, pixels_h);
    pixbuf = gdk_pixbuf_new_from_file_at_scale(path, pixels_w, pixels_h, FALSE, &pixbuf_error);
    if (! pixbuf)
    {
        g_error("Error loading image %s: %s", path, pixbuf_error->message);
        g_error_free(pixbuf_error);
        pixbuf_error = NULL;
        g_object_unref(pixbuf);
        return FALSE;
    }
    int n_channels = gdk_pixbuf_get_n_channels(pixbuf);
    if (n_channels != 4)
    {
        g_critical("Image has no alpha channel and we require one.");
        g_object_unref(pixbuf);
        return FALSE;
    }
    g_assert(gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB);
    g_assert(gdk_pixbuf_get_bits_per_sample(pixbuf) == 8);
    g_assert(gdk_pixbuf_get_has_alpha(pixbuf));
    g_assert(n_channels == 4);

    gulong bufsize = pixels_w * pixels_h * sizeof(char) * 4;
    guchar *data = (guchar *) g_malloc(bufsize + (sizeof(gulong) * 2));
    ((gulong *)data)[0] = pixels_w;
    ((gulong *)data)[1] = pixels_h;
    guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
    memcpy((void *) &(((gulong *)data)[2]), (void *) pixels, bufsize);

    ///* For some inexplicable reason XChangeProperty always takes
    // * an array of longs when the format == 32 even on 64-bit
    // * architectures where sizeof(long) != 32. Therefore we need
    // * to pointlessly pad each 32-bit value with an extra 4
    // * bytes so that libX11 can remove them again to send the
    // * request. We can do this in-place if we start from the
    // * end 
    // */
    //if (sizeof(gulong) != 4)
    //{
    //    const guint32 *src = (guint32 *) (data + 2) + pixels_w * pixels_h;
    //    gulong *dst = data + 2 + pixels_w * pixels_h;
 
    //    while (dst > data + 2)
    //    {
    //        *(--dst) = *(--src);
    //    }
    //}

    XChangeProperty(
        dpy, // X11 display
        win, // X11 window
        net_wm_icon, // name of property
        XA_CARDINAL, // type of property
        32, // format
        PropModeReplace, // mode
        (unsigned char *) data, // data (we must cast it to unsigned char* if format is 32)
        pixels_w * pixels_h + 2); // nelements

    g_free(data);
    g_object_unref(pixbuf);
#endif
    return TRUE;
}
Пример #14
0
void fx_head_initialize(FxMain* fxmain)
{
	
	GdkPixbuf* pb;
	GtkWidget *vbox , *headbox , *alignment , *halign;
	GtkWidget* hbox = gtk_hbox_new(FALSE , 0);
	FxHead* fxhead = fx_head_new();
	fxmain->headPanel = fxhead;
	halign = gtk_alignment_new(0, 0 , 0 , 0);
	gtk_container_add(GTK_CONTAINER(halign) , hbox);
	
	pb = gdk_pixbuf_new_from_file_at_scale(SKIN_DIR"fetion.svg",
			USER_PORTRAIT_SIZE, USER_PORTRAIT_SIZE, TRUE, NULL);
	fxhead->portrait = gtk_image_new_from_pixbuf(pb);
	g_object_unref(pb);

	GtkWidget *frame;
	frame = gtk_frame_new(NULL);
	gtk_widget_set_usize(frame , 55 , 55);
	fxhead->portraitbox = gtk_event_box_new();
	gtk_container_add(GTK_CONTAINER(fxhead->portraitbox) , fxhead->portrait);
	gtk_container_add(GTK_CONTAINER(frame) , fxhead->portraitbox);
	gtk_box_pack_start(GTK_BOX(hbox) , frame , FALSE , FALSE , 10 );

	g_signal_connect(G_OBJECT(fxhead->portraitbox)
				   , "button_press_event"
				   , GTK_SIGNAL_FUNC(fx_head_change_portrait_func)
				   , fxmain);
				 
	g_signal_connect(G_OBJECT(fxhead->portraitbox)
				   , "enter_notify_event"
				   , GTK_SIGNAL_FUNC(fx_head_change_portrait_func)
				   , fxmain);

	g_signal_connect(G_OBJECT(fxhead->portraitbox)
				   , "leave_notify_event"
				   , GTK_SIGNAL_FUNC(fx_head_change_portrait_func)
				   , fxmain);

	vbox = gtk_vbox_new(TRUE , 0);

	headbox = gtk_hbox_new(FALSE , 0);

	fxhead->state_button = gtk_event_box_new();
	pb = gdk_pixbuf_new_from_file_at_size(SKIN_DIR"online.svg" , 20 , 20 , FALSE);
	fxhead->state_img = gtk_image_new_from_pixbuf(pb);
	g_object_unref(pb);
	gtk_container_add(GTK_CONTAINER(fxhead->state_button) , fxhead->state_img);
	gtk_widget_set_events(fxhead->state_button
						, GDK_MOTION_NOTIFY
						| GDK_BUTTON_PRESS
						| GDK_BUTTON_RELEASE
						| GDK_ENTER_NOTIFY
						| GDK_LEAVE_NOTIFY);
	g_signal_connect(G_OBJECT(fxhead->state_button)
					 , "button_press_event"
					 , GTK_SIGNAL_FUNC(fx_head_popup_statemenu_func)
					 , fxmain);
	g_signal_connect(G_OBJECT(fxhead->state_button)
					 , "enter_notify_event"
					 , GTK_SIGNAL_FUNC(fx_head_popup_statemenu_func)
					 , fxmain);
	g_signal_connect(G_OBJECT(fxhead->state_button)
					 , "leave_notify_event"
					 , GTK_SIGNAL_FUNC(fx_head_popup_statemenu_func)
					 , fxmain);

	g_signal_connect(G_OBJECT(fxhead->portraitbox)
				   , "leave_notify_event"
				   , GTK_SIGNAL_FUNC(fx_head_change_portrait_func)
				   , fxmain);

	gtk_box_pack_start(GTK_BOX(headbox) , fxhead->state_button , TRUE , TRUE , 0);

	fxhead->name_label = gtk_label_new(NULL);
	fxhead->state_label = gtk_label_new(NULL);
	gtk_box_pack_start(GTK_BOX(headbox) , fxhead->name_label , TRUE , TRUE , 0);
	gtk_box_pack_start(GTK_BOX(headbox) , fxhead->state_label , TRUE , TRUE , 0);

	fxhead->impre_box = gtk_event_box_new();
	g_signal_connect(G_OBJECT(fxhead->impre_box)
				   , "button_press_event"
				   , GTK_SIGNAL_FUNC(fx_head_impre_event_func)
				   , fxmain);
	g_signal_connect(G_OBJECT(fxhead->impre_box)
				   , "button_release_event"
				   , GTK_SIGNAL_FUNC(fx_head_impre_event_func)
				   , fxmain);
	g_signal_connect(G_OBJECT(fxhead->impre_box)
				   , "enter_notify_event"
				   , GTK_SIGNAL_FUNC(fx_head_impre_event_func)
				   , fxmain);
	g_signal_connect(G_OBJECT(fxhead->impre_box)
				   , "leave_notify_event"
				   , GTK_SIGNAL_FUNC(fx_head_impre_event_func)
				   , fxmain);
	fxhead->impre_entry = gtk_entry_new();
	g_signal_connect(G_OBJECT(fxhead->impre_entry)
				   , "focus-out-event"
				   , GTK_SIGNAL_FUNC(fx_head_impre_focus_out_func)
				   , fxmain);
	g_signal_connect(G_OBJECT(fxhead->impre_entry)
				   , "activate"
				   , G_CALLBACK(fx_head_impre_activate_func)
				   , fxmain);
	fxhead->impre_label = gtk_label_new(NULL);
	gtk_label_set_width_chars(GTK_LABEL(fxhead->impre_label) , 15);
	gtk_misc_set_alignment(GTK_MISC(fxhead->impre_label) , 0 , 0);

	alignment = gtk_alignment_new(0 , 0 , 0 , 0);
	gtk_container_add(GTK_CONTAINER(alignment) , headbox);
	gtk_box_pack_start(GTK_BOX(vbox) , alignment , FALSE , TRUE , 0);

	gtk_container_add(GTK_CONTAINER(fxhead->impre_box) , fxhead->impre_label);
	gtk_box_pack_start(GTK_BOX(vbox) , fxhead->impre_box , FALSE , FALSE , 0);
	gtk_box_pack_start(GTK_BOX(vbox) , fxhead->impre_entry , FALSE , FALSE , 0);
	gtk_box_pack_start(GTK_BOX(hbox) , vbox , FALSE , TRUE , 10);

	fxhead->topbox = gtk_hbox_new(FALSE , 0);
	gtk_box_pack_start(GTK_BOX(fxhead->topbox) , halign , FALSE , FALSE , 0);
	gtk_box_pack_start(GTK_BOX(fxmain->mainbox) , fxhead->topbox , FALSE , FALSE , 10);
	fx_head_bind(fxmain);	
}
Пример #15
0
/**
 * 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;
}
Пример #16
0
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
}