Compare commits
2 Commits
release-gn
...
wip/backgr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b763ca9ff | ||
|
|
e9cf229a13 |
@@ -113,7 +113,7 @@ COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION
|
||||
gio-unix-2.0
|
||||
gsettings-desktop-schemas >= $SCHEMAS_REQUIRED_VERSION"
|
||||
|
||||
LIBGD_INIT([_view-common notification main-toolbar stack static])
|
||||
LIBGD_INIT([gtk-hacks _view-common notification main-toolbar stack static])
|
||||
|
||||
PKG_CHECK_MODULES(LIBLANGUAGE, $COMMON_MODULES gnome-desktop-3.0 fontconfig)
|
||||
PKG_CHECK_MODULES(LIBSHORTCUTS, $COMMON_MODULES x11)
|
||||
|
||||
@@ -10,6 +10,7 @@ dist_slideshowemblem_DATA = slideshow-emblem.svg
|
||||
INCLUDES = \
|
||||
$(PANEL_CFLAGS) \
|
||||
$(BACKGROUND_PANEL_CFLAGS) \
|
||||
-I$(top_srcdir)/libgd \
|
||||
-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
|
||||
-DDATADIR="\"$(datadir)\"" \
|
||||
-DGNOME_DESKTOP_USE_UNSTABLE_API \
|
||||
@@ -40,7 +41,7 @@ libbackground_chooser_la_SOURCES = \
|
||||
bg-colors-source.c \
|
||||
bg-colors-source.h
|
||||
|
||||
libbackground_chooser_la_LIBADD = $(PANEL_LIBS) $(BACKGROUND_PANEL_LIBS)
|
||||
libbackground_chooser_la_LIBADD = $(PANEL_LIBS) $(BACKGROUND_PANEL_LIBS) $(top_builddir)/libgd/libgd.la
|
||||
|
||||
libbackground_la_SOURCES = \
|
||||
cc-background-panel.c \
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
<gresources>
|
||||
<gresource prefix="/org/gnome/control-center/background">
|
||||
<file preprocess="xml-stripblanks">background.ui</file>
|
||||
<file preprocess="to-pixdata">thumbnail-frame.png</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <gio/gio.h>
|
||||
#include <libgd/gd.h>
|
||||
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
|
||||
#include <gdesktop-enums.h>
|
||||
|
||||
@@ -61,6 +62,11 @@ const char * const content_types[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
const char * const screenshot_types[] = {
|
||||
"image/png",
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *bg_pictures_source_get_unique_filename (const char *uri);
|
||||
|
||||
static void
|
||||
@@ -133,6 +139,26 @@ bg_pictures_source_class_init (BgPicturesSourceClass *klass)
|
||||
object_class->finalize = bg_pictures_source_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
remove_placeholder (BgPicturesSource *bg_source, CcBackgroundItem *item)
|
||||
{
|
||||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeRowReference *row_ref;
|
||||
|
||||
store = bg_source_get_liststore (BG_SOURCE (bg_source));
|
||||
row_ref = g_object_get_data (G_OBJECT (item), "row-ref");
|
||||
if (row_ref == NULL)
|
||||
return;
|
||||
|
||||
path = gtk_tree_row_reference_get_path (row_ref);
|
||||
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
|
||||
return;
|
||||
|
||||
gtk_list_store_remove (store, &iter);
|
||||
}
|
||||
|
||||
static void
|
||||
picture_scaled (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
@@ -141,17 +167,29 @@ picture_scaled (GObject *source_object,
|
||||
BgPicturesSource *bg_source;
|
||||
CcBackgroundItem *item;
|
||||
GError *error = NULL;
|
||||
GdkPixbuf *framed_pixbuf = NULL;
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
GtkBorder border;
|
||||
const char *software;
|
||||
const char *uri;
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeRowReference *row_ref;
|
||||
GtkListStore *store;
|
||||
gint16 x_border;
|
||||
gint16 y_border;
|
||||
int height;
|
||||
int width;
|
||||
|
||||
item = g_object_get_data (source_object, "item");
|
||||
pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
|
||||
if (pixbuf == NULL)
|
||||
{
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
g_warning ("Failed to load image: %s", error->message);
|
||||
{
|
||||
g_warning ("Failed to load image: %s", error->message);
|
||||
remove_placeholder (BG_PICTURES_SOURCE (user_data), item);
|
||||
}
|
||||
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
@@ -162,7 +200,6 @@ picture_scaled (GObject *source_object,
|
||||
*/
|
||||
bg_source = BG_PICTURES_SOURCE (user_data);
|
||||
store = bg_source_get_liststore (BG_SOURCE (bg_source));
|
||||
item = g_object_get_data (source_object, "item");
|
||||
uri = cc_background_item_get_uri (item);
|
||||
|
||||
/* Ignore screenshots */
|
||||
@@ -177,11 +214,38 @@ picture_scaled (GObject *source_object,
|
||||
|
||||
cc_background_item_load (item, NULL);
|
||||
|
||||
/* insert the item into the liststore */
|
||||
gtk_list_store_insert_with_values (store, &iter, -1,
|
||||
0, pixbuf,
|
||||
1, item,
|
||||
-1);
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
x_border = (gint16) (THUMBNAIL_WIDTH - width) / 2 + 2;
|
||||
y_border = (gint16) (THUMBNAIL_HEIGHT - height) / 2 + 2;
|
||||
|
||||
border.left = border.right = x_border;
|
||||
border.bottom = border.top = y_border;
|
||||
framed_pixbuf = gd_embed_image_in_frame (pixbuf,
|
||||
"resource:///org/gnome/control-center/background/thumbnail-frame.png",
|
||||
&border,
|
||||
&border);
|
||||
|
||||
row_ref = g_object_get_data (G_OBJECT (item), "row-ref");
|
||||
if (row_ref == NULL)
|
||||
{
|
||||
/* insert the item into the liststore if it did not exist */
|
||||
gtk_list_store_insert_with_values (store, NULL, -1,
|
||||
0, framed_pixbuf,
|
||||
1, item,
|
||||
-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = gtk_tree_row_reference_get_path (row_ref);
|
||||
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
|
||||
{
|
||||
/* otherwise update the thumbnail */
|
||||
gtk_list_store_set (store, &iter,
|
||||
0, framed_pixbuf,
|
||||
-1);
|
||||
}
|
||||
}
|
||||
|
||||
g_hash_table_insert (bg_source->priv->known_items,
|
||||
bg_pictures_source_get_unique_filename (uri),
|
||||
@@ -189,6 +253,7 @@ picture_scaled (GObject *source_object,
|
||||
|
||||
|
||||
out:
|
||||
g_clear_object (&framed_pixbuf);
|
||||
g_clear_object (&pixbuf);
|
||||
}
|
||||
|
||||
@@ -210,6 +275,7 @@ picture_opened_for_read (GObject *source_object,
|
||||
{
|
||||
char *filename = g_file_get_path (G_FILE (source_object));
|
||||
g_warning ("Failed to load picture '%s': %s", filename, error->message);
|
||||
remove_placeholder (BG_PICTURES_SOURCE (user_data), item);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
@@ -241,6 +307,16 @@ in_content_types (const char *content_type)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
in_screenshot_types (const char *content_type)
|
||||
{
|
||||
guint i;
|
||||
for (i = 0; screenshot_types[i]; i++)
|
||||
if (g_str_equal (screenshot_types[i], content_type))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_single_file (BgPicturesSource *bg_source,
|
||||
GFile *file,
|
||||
@@ -249,9 +325,23 @@ add_single_file (BgPicturesSource *bg_source,
|
||||
{
|
||||
const gchar *content_type;
|
||||
CcBackgroundItem *item = NULL;
|
||||
GError *error = NULL;
|
||||
GdkPixbuf *framed_pixbuf = NULL;
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
GtkBorder border;
|
||||
GtkIconInfo *icon_info = NULL;
|
||||
GtkIconTheme *theme;
|
||||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path = NULL;
|
||||
GtkTreeRowReference *row_ref;
|
||||
char *uri = NULL;
|
||||
gboolean retval = FALSE;
|
||||
gint16 x_border;
|
||||
gint16 y_border;
|
||||
guint64 mtime;
|
||||
int height;
|
||||
int width;
|
||||
|
||||
/* find png and jpeg files */
|
||||
content_type = g_file_info_get_content_type (info);
|
||||
@@ -275,6 +365,53 @@ add_single_file (BgPicturesSource *bg_source,
|
||||
if (source_uri != NULL)
|
||||
g_object_set (G_OBJECT (item), "source-url", source_uri, NULL);
|
||||
|
||||
if (in_screenshot_types (content_type))
|
||||
goto read_file;
|
||||
|
||||
theme = gtk_icon_theme_get_default ();
|
||||
icon_info = gtk_icon_theme_lookup_icon (theme,
|
||||
"content-loading-symbolic",
|
||||
16,
|
||||
GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
|
||||
if (icon_info == NULL)
|
||||
{
|
||||
g_warning ("Failed to find placeholder icon");
|
||||
goto read_file;
|
||||
}
|
||||
|
||||
pixbuf = gtk_icon_info_load_icon (icon_info, &error);
|
||||
if (pixbuf == NULL)
|
||||
{
|
||||
g_warning ("Failed to load placeholder icon: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
goto read_file;
|
||||
}
|
||||
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
x_border = (gint16) (THUMBNAIL_WIDTH - width) / 2 + 2;
|
||||
y_border = (gint16) (THUMBNAIL_HEIGHT - height) / 2 + 2;
|
||||
|
||||
border.left = border.right = x_border;
|
||||
border.bottom = border.top = y_border;
|
||||
framed_pixbuf = gd_embed_image_in_frame (pixbuf,
|
||||
"resource:///org/gnome/control-center/background/thumbnail-frame.png",
|
||||
&border,
|
||||
&border);
|
||||
|
||||
store = bg_source_get_liststore (BG_SOURCE (bg_source));
|
||||
|
||||
/* insert the item into the liststore */
|
||||
gtk_list_store_insert_with_values (store, &iter, -1,
|
||||
0, framed_pixbuf,
|
||||
1, item,
|
||||
-1);
|
||||
|
||||
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
|
||||
row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
|
||||
g_object_set_data_full (G_OBJECT (item), "row-ref", row_ref, (GDestroyNotify) gtk_tree_row_reference_free);
|
||||
|
||||
read_file:
|
||||
g_object_set_data_full (G_OBJECT (file), "item", g_object_ref (item), g_object_unref);
|
||||
|
||||
g_file_read_async (file, G_PRIORITY_DEFAULT,
|
||||
@@ -284,6 +421,10 @@ add_single_file (BgPicturesSource *bg_source,
|
||||
retval = TRUE;
|
||||
|
||||
out:
|
||||
gtk_tree_path_free (path);
|
||||
g_clear_object (&framed_pixbuf);
|
||||
g_clear_object (&pixbuf);
|
||||
g_clear_object (&icon_info);
|
||||
g_clear_object (&item);
|
||||
g_object_unref (file);
|
||||
g_free (uri);
|
||||
|
||||
BIN
panels/background/thumbnail-frame.png
Normal file
BIN
panels/background/thumbnail-frame.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 482 B |
Reference in New Issue
Block a user