2011-02-10 20:30:57 +00:00
|
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
2010-08-10 15:26:07 +01:00
|
|
|
|
*
|
2011-02-10 20:30:57 +00:00
|
|
|
|
* Copyright (C) 2010-2011 Red Hat, Inc.
|
2010-08-10 15:26:07 +01:00
|
|
|
|
*
|
2011-02-10 20:30:57 +00:00
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
2010-08-10 15:26:07 +01:00
|
|
|
|
*
|
2011-02-10 20:30:57 +00:00
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2010-08-10 15:26:07 +01:00
|
|
|
|
*
|
2011-02-10 20:30:57 +00:00
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 12:57:27 +01:00
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2010-08-10 15:26:07 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
|
|
|
|
|
#include <libgnome-desktop/gnome-bg.h>
|
2011-02-17 20:59:55 +01:00
|
|
|
|
#include <gdesktop-enums.h>
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 12:29:29 +00:00
|
|
|
|
#include "cc-background-item.h"
|
2011-02-10 20:30:57 +00:00
|
|
|
|
#include "gdesktop-enums-types.h"
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
struct _CcBackgroundItem
|
2010-08-10 15:26:07 +01:00
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
/* properties */
|
|
|
|
|
char *name;
|
2011-02-11 18:04:57 +00:00
|
|
|
|
char *uri;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
char *size;
|
|
|
|
|
GDesktopBackgroundStyle placement;
|
|
|
|
|
GDesktopBackgroundShading shading;
|
|
|
|
|
char *primary_color;
|
|
|
|
|
char *secondary_color;
|
|
|
|
|
char *source_url; /* Used by the Flickr source */
|
|
|
|
|
char *source_xml; /* Used by the Wallpapers source */
|
|
|
|
|
gboolean is_deleted;
|
2011-02-14 17:47:01 +00:00
|
|
|
|
gboolean needs_download;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
CcBackgroundItemFlags flags;
|
2013-01-25 11:56:58 +00:00
|
|
|
|
guint64 modified;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
/* internal */
|
2014-06-30 15:47:24 +02:00
|
|
|
|
GdkPixbuf *slideshow_emblem;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
GnomeBG *bg;
|
|
|
|
|
char *mime_type;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_NAME,
|
2011-02-11 18:04:57 +00:00
|
|
|
|
PROP_URI,
|
2011-02-10 20:30:57 +00:00
|
|
|
|
PROP_PLACEMENT,
|
|
|
|
|
PROP_SHADING,
|
|
|
|
|
PROP_PRIMARY_COLOR,
|
|
|
|
|
PROP_SECONDARY_COLOR,
|
|
|
|
|
PROP_IS_DELETED,
|
|
|
|
|
PROP_SOURCE_URL,
|
|
|
|
|
PROP_SOURCE_XML,
|
|
|
|
|
PROP_FLAGS,
|
2011-02-14 17:47:01 +00:00
|
|
|
|
PROP_SIZE,
|
2013-01-25 11:56:58 +00:00
|
|
|
|
PROP_NEEDS_DOWNLOAD,
|
|
|
|
|
PROP_MODIFIED
|
2011-02-10 20:30:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void cc_background_item_finalize (GObject *object);
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (CcBackgroundItem, cc_background_item, G_TYPE_OBJECT)
|
|
|
|
|
|
2014-06-30 15:47:24 +02:00
|
|
|
|
static GdkPixbuf *slideshow_emblem = NULL;
|
|
|
|
|
|
2014-08-12 23:48:46 +02:00
|
|
|
|
static GdkPixbuf *
|
2014-06-30 15:47:24 +02:00
|
|
|
|
get_emblemed_pixbuf (CcBackgroundItem *item, GdkPixbuf *pixbuf, gint scale_factor)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
{
|
2014-06-30 15:47:24 +02:00
|
|
|
|
int eh;
|
|
|
|
|
int ew;
|
|
|
|
|
int h;
|
|
|
|
|
int w;
|
|
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->slideshow_emblem == NULL) {
|
2014-06-30 15:47:24 +02:00
|
|
|
|
if (slideshow_emblem == NULL) {
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GIcon) icon = NULL;
|
2014-06-30 15:47:24 +02:00
|
|
|
|
GtkIconTheme *theme;
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GtkIconInfo) icon_info = NULL;
|
|
|
|
|
g_autoptr(GError) error = NULL;
|
2014-06-30 15:47:24 +02:00
|
|
|
|
|
|
|
|
|
icon = g_themed_icon_new ("slideshow-emblem");
|
|
|
|
|
theme = gtk_icon_theme_get_default ();
|
|
|
|
|
icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
|
|
|
|
|
icon,
|
|
|
|
|
16,
|
|
|
|
|
scale_factor,
|
|
|
|
|
GTK_ICON_LOOKUP_FORCE_SIZE |
|
|
|
|
|
GTK_ICON_LOOKUP_USE_BUILTIN);
|
2015-01-09 17:52:26 +01:00
|
|
|
|
if (icon_info == NULL) {
|
|
|
|
|
g_warning ("Your icon theme is missing the slideshow-emblem icon, "
|
|
|
|
|
"please file a bug against it");
|
2017-09-04 10:42:56 +12:00
|
|
|
|
return g_object_ref (pixbuf);
|
2015-01-09 17:52:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 15:47:24 +02:00
|
|
|
|
slideshow_emblem = gtk_icon_info_load_icon (icon_info, &error);
|
|
|
|
|
if (slideshow_emblem == NULL) {
|
|
|
|
|
g_warning ("Failed to load slideshow emblem: %s", error->message);
|
2017-09-04 10:42:56 +12:00
|
|
|
|
return g_object_ref (pixbuf);
|
2014-06-30 15:47:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (slideshow_emblem), (gpointer *) (&slideshow_emblem));
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->slideshow_emblem = slideshow_emblem;
|
2014-06-30 15:47:24 +02:00
|
|
|
|
} else {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->slideshow_emblem = g_object_ref (slideshow_emblem);
|
2014-06-30 15:47:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eh = gdk_pixbuf_get_height (slideshow_emblem);
|
|
|
|
|
ew = gdk_pixbuf_get_width (slideshow_emblem);
|
|
|
|
|
h = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
w = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
|
x = w - ew;
|
|
|
|
|
y = h - eh;
|
|
|
|
|
|
|
|
|
|
gdk_pixbuf_composite (slideshow_emblem, pixbuf, x, y, ew, eh, x, y, 1.0, 1.0, GDK_INTERP_BILINEAR, 255);
|
|
|
|
|
|
2017-09-04 10:42:56 +12:00
|
|
|
|
return g_object_ref (pixbuf);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
set_bg_properties (CcBackgroundItem *item)
|
|
|
|
|
{
|
2017-09-26 14:12:13 -04:00
|
|
|
|
GdkRGBA pcolor = { 0, 0, 0, 0 };
|
|
|
|
|
GdkRGBA scolor = { 0, 0, 0, 0 };
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->uri) {
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GFile) file = NULL;
|
|
|
|
|
g_autofree gchar *filename = NULL;
|
2011-02-11 18:04:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
file = g_file_new_for_commandline_arg (item->uri);
|
2011-02-11 18:04:57 +00:00
|
|
|
|
filename = g_file_get_path (file);
|
2017-09-25 14:16:09 -04:00
|
|
|
|
gnome_bg_set_filename (item->bg, filename);
|
2011-02-11 18:04:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->primary_color != NULL) {
|
2017-09-26 14:12:13 -04:00
|
|
|
|
gdk_rgba_parse (&pcolor, item->primary_color);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->secondary_color != NULL) {
|
2017-09-26 14:12:13 -04:00
|
|
|
|
gdk_rgba_parse (&scolor, item->secondary_color);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-26 14:12:13 -04:00
|
|
|
|
gnome_bg_set_rgba (item->bg, item->shading, &pcolor, &scolor);
|
2017-09-25 14:16:09 -04:00
|
|
|
|
gnome_bg_set_placement (item->bg, item->placement);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
gboolean
|
|
|
|
|
cc_background_item_changes_with_time (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
gboolean changes;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-11 03:18:22 +00:00
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), FALSE);
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
changes = FALSE;
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->bg != NULL) {
|
|
|
|
|
changes = gnome_bg_changes_with_time (item->bg);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
return changes;
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
update_size (CcBackgroundItem *item)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_clear_pointer (&item->size, g_free);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->uri == NULL) {
|
|
|
|
|
item->size = g_strdup ("");
|
2011-02-10 20:30:57 +00:00
|
|
|
|
} else {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (gnome_bg_has_multiple_sizes (item->bg) || gnome_bg_changes_with_time (item->bg)) {
|
|
|
|
|
item->size = g_strdup (_("multiple sizes"));
|
2011-02-10 20:30:57 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* translators: 100 × 100px
|
|
|
|
|
* Note that this is not an "x", but U+00D7 MULTIPLICATION SIGN */
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->size = g_strdup_printf (_("%d × %d"),
|
|
|
|
|
item->width,
|
|
|
|
|
item->height);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-03-29 23:44:58 -04:00
|
|
|
|
static GdkPixbuf *
|
|
|
|
|
render_at_size (GnomeBG *bg,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
|
|
|
|
|
gnome_bg_draw (bg, pixbuf, gdk_screen_get_default (), FALSE);
|
|
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 23:48:46 +02:00
|
|
|
|
GdkPixbuf *
|
2011-02-10 20:30:57 +00:00
|
|
|
|
cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
|
|
|
|
|
GnomeDesktopThumbnailFactory *thumbs,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
2014-06-30 15:47:24 +02:00
|
|
|
|
int scale_factor,
|
2011-03-29 23:44:58 -04:00
|
|
|
|
int frame,
|
|
|
|
|
gboolean force_size)
|
2011-02-10 20:30:57 +00:00
|
|
|
|
{
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
|
|
|
|
g_autoptr(GdkPixbuf) retval = NULL;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2011-02-11 03:18:22 +00:00
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
|
|
|
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
set_bg_properties (item);
|
|
|
|
|
|
2011-03-29 23:44:58 -04:00
|
|
|
|
if (force_size) {
|
|
|
|
|
/* FIXME: this doesn't play nice with slideshow stepping at all,
|
|
|
|
|
* because it will always render the current slideshow frame, which
|
|
|
|
|
* might not be what we want.
|
|
|
|
|
* We're lacking an API to draw a high-res GnomeBG manually choosing
|
|
|
|
|
* the slideshow frame though, so we can't do much better than this
|
|
|
|
|
* for now.
|
|
|
|
|
*/
|
2017-09-25 14:16:09 -04:00
|
|
|
|
pixbuf = render_at_size (item->bg, width, height);
|
2011-03-29 23:44:58 -04:00
|
|
|
|
} else {
|
|
|
|
|
if (frame >= 0) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
pixbuf = gnome_bg_create_frame_thumbnail (item->bg,
|
2011-03-29 23:44:58 -04:00
|
|
|
|
thumbs,
|
|
|
|
|
gdk_screen_get_default (),
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
frame);
|
|
|
|
|
} else {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
pixbuf = gnome_bg_create_thumbnail (item->bg,
|
2011-03-29 23:44:58 -04:00
|
|
|
|
thumbs,
|
|
|
|
|
gdk_screen_get_default (),
|
|
|
|
|
width,
|
|
|
|
|
height);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
if (pixbuf != NULL
|
|
|
|
|
&& frame != -2
|
2017-09-25 14:16:09 -04:00
|
|
|
|
&& gnome_bg_changes_with_time (item->bg)) {
|
2014-08-12 23:48:46 +02:00
|
|
|
|
retval = get_emblemed_pixbuf (item, pixbuf, scale_factor);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
} else {
|
2017-09-04 10:42:56 +12:00
|
|
|
|
retval = g_steal_pointer (&pixbuf);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
gnome_bg_get_image_size (item->bg,
|
2011-02-10 20:30:57 +00:00
|
|
|
|
thumbs,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
2017-09-25 14:16:09 -04:00
|
|
|
|
&item->width,
|
|
|
|
|
&item->height);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
update_size (item);
|
|
|
|
|
|
2017-09-04 10:42:56 +12:00
|
|
|
|
return g_steal_pointer (&retval);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
|
|
|
|
|
2014-08-12 23:48:46 +02:00
|
|
|
|
GdkPixbuf *
|
2011-02-10 20:30:57 +00:00
|
|
|
|
cc_background_item_get_thumbnail (CcBackgroundItem *item,
|
|
|
|
|
GnomeDesktopThumbnailFactory *thumbs,
|
|
|
|
|
int width,
|
2014-06-30 15:47:24 +02:00
|
|
|
|
int height,
|
|
|
|
|
int scale_factor)
|
2011-02-10 20:30:57 +00:00
|
|
|
|
{
|
2014-06-30 15:47:24 +02:00
|
|
|
|
return cc_background_item_get_frame_thumbnail (item, thumbs, width, height, scale_factor, -1, FALSE);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
update_info (CcBackgroundItem *item,
|
|
|
|
|
GFileInfo *_info)
|
|
|
|
|
{
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GFileInfo) info = NULL;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
if (_info == NULL) {
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GFile) file = NULL;
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
file = g_file_new_for_uri (item->uri);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
info = g_file_query_info (file,
|
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_NAME ","
|
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_SIZE ","
|
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
|
2011-02-11 18:04:57 +00:00
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
|
2011-02-10 20:30:57 +00:00
|
|
|
|
G_FILE_ATTRIBUTE_TIME_MODIFIED,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
} else {
|
|
|
|
|
info = g_object_ref (_info);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_clear_pointer (&item->mime_type, g_free);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
if (info == NULL
|
|
|
|
|
|| g_file_info_get_content_type (info) == NULL) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->uri == NULL) {
|
|
|
|
|
item->mime_type = g_strdup ("image/x-no-data");
|
|
|
|
|
g_free (item->name);
|
|
|
|
|
item->name = g_strdup (_("No Desktop Background"));
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->name == NULL)
|
|
|
|
|
item->name = g_strdup (g_file_info_get_display_name (info));
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->mime_type = g_strdup (g_file_info_get_content_type (info));
|
|
|
|
|
if (item->modified == 0)
|
2017-09-04 10:42:56 +12:00
|
|
|
|
item->modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
gboolean
|
|
|
|
|
cc_background_item_load (CcBackgroundItem *item,
|
|
|
|
|
GFileInfo *info)
|
|
|
|
|
{
|
2011-02-11 03:18:22 +00:00
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), FALSE);
|
2011-02-11 18:52:38 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->uri == NULL)
|
2011-02-11 18:52:38 +00:00
|
|
|
|
return TRUE;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
update_info (item, info);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->mime_type != NULL
|
|
|
|
|
&& (g_str_has_prefix (item->mime_type, "image/")
|
|
|
|
|
|| strcmp (item->mime_type, "application/xml") == 0)) {
|
2011-02-10 20:30:57 +00:00
|
|
|
|
set_bg_properties (item);
|
|
|
|
|
} else {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-11 12:38:46 +00:00
|
|
|
|
/* FIXME we should handle XML files as well */
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->mime_type != NULL &&
|
|
|
|
|
g_str_has_prefix (item->mime_type, "image/")) {
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autofree gchar *filename = NULL;
|
2011-02-11 18:04:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
filename = g_filename_from_uri (item->uri, NULL, NULL);
|
2011-02-11 18:04:57 +00:00
|
|
|
|
gdk_pixbuf_get_file_info (filename,
|
2017-09-25 14:16:09 -04:00
|
|
|
|
&item->width,
|
|
|
|
|
&item->height);
|
2011-02-11 12:38:46 +00:00
|
|
|
|
update_size (item);
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_name (CcBackgroundItem *item,
|
|
|
|
|
const char *value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->name);
|
|
|
|
|
item->name = g_strdup (value);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
cc_background_item_get_name (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->name;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
2011-02-11 18:04:57 +00:00
|
|
|
|
_set_uri (CcBackgroundItem *item,
|
|
|
|
|
const char *value)
|
2011-02-10 20:30:57 +00:00
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->uri);
|
2011-02-14 13:03:30 +00:00
|
|
|
|
if (value && *value == '\0') {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->uri = NULL;
|
2011-02-14 13:03:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (value && strstr (value, "://") == NULL)
|
|
|
|
|
g_warning ("URI '%s' is invalid", value);
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->uri = g_strdup (value);
|
2011-02-14 13:03:30 +00:00
|
|
|
|
}
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
const char *
|
2011-02-11 18:04:57 +00:00
|
|
|
|
cc_background_item_get_uri (CcBackgroundItem *item)
|
2011-02-10 20:30:57 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->uri;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_placement (CcBackgroundItem *item,
|
|
|
|
|
GDesktopBackgroundStyle value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->placement = value;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_shading (CcBackgroundItem *item,
|
|
|
|
|
GDesktopBackgroundShading value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->shading = value;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_primary_color (CcBackgroundItem *item,
|
|
|
|
|
const char *value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->primary_color);
|
|
|
|
|
item->primary_color = g_strdup (value);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
const char *
|
|
|
|
|
cc_background_item_get_pcolor (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
2010-08-12 11:23:55 +01:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->primary_color;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_secondary_color (CcBackgroundItem *item,
|
|
|
|
|
const char *value)
|
2010-08-10 15:26:07 +01:00
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->secondary_color);
|
|
|
|
|
item->secondary_color = g_strdup (value);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
2010-08-10 15:26:07 +01:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
const char *
|
|
|
|
|
cc_background_item_get_scolor (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->secondary_color;
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
GDesktopBackgroundStyle
|
|
|
|
|
cc_background_item_get_placement (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), G_DESKTOP_BACKGROUND_STYLE_SCALED);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->placement;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GDesktopBackgroundShading
|
|
|
|
|
cc_background_item_get_shading (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), G_DESKTOP_BACKGROUND_SHADING_SOLID);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->shading;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_set_is_deleted (CcBackgroundItem *item,
|
|
|
|
|
gboolean value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->is_deleted = value;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_set_source_url (CcBackgroundItem *item,
|
|
|
|
|
const char *value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->source_url);
|
|
|
|
|
item->source_url = g_strdup (value);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
cc_background_item_get_source_url (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->source_url;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_set_source_xml (CcBackgroundItem *item,
|
|
|
|
|
const char *value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->source_xml);
|
|
|
|
|
item->source_xml = g_strdup (value);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
cc_background_item_get_source_xml (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->source_xml;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_set_flags (CcBackgroundItem *item,
|
|
|
|
|
CcBackgroundItemFlags value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->flags = value;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CcBackgroundItemFlags
|
|
|
|
|
cc_background_item_get_flags (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->flags;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
cc_background_item_get_size (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->size;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-14 17:47:01 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_needs_download (CcBackgroundItem *item,
|
|
|
|
|
gboolean value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->needs_download = value;
|
2011-02-14 17:47:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
cc_background_item_get_needs_download (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->needs_download;
|
2011-02-14 17:47:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-02 13:39:37 +00:00
|
|
|
|
static void
|
|
|
|
|
_set_modified (CcBackgroundItem *item,
|
|
|
|
|
guint64 value)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->modified = value;
|
2013-02-02 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 11:56:58 +00:00
|
|
|
|
guint64
|
|
|
|
|
cc_background_item_get_modified (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
return item->modified;
|
2013-01-25 11:56:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
static void
|
|
|
|
|
cc_background_item_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
CcBackgroundItem *self;
|
|
|
|
|
|
|
|
|
|
self = CC_BACKGROUND_ITEM (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_NAME:
|
|
|
|
|
_set_name (self, g_value_get_string (value));
|
|
|
|
|
break;
|
2011-02-11 18:04:57 +00:00
|
|
|
|
case PROP_URI:
|
|
|
|
|
_set_uri (self, g_value_get_string (value));
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_PLACEMENT:
|
|
|
|
|
_set_placement (self, g_value_get_enum (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SHADING:
|
|
|
|
|
_set_shading (self, g_value_get_enum (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_PRIMARY_COLOR:
|
|
|
|
|
_set_primary_color (self, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SECONDARY_COLOR:
|
|
|
|
|
_set_secondary_color (self, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_IS_DELETED:
|
|
|
|
|
_set_is_deleted (self, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SOURCE_URL:
|
|
|
|
|
_set_source_url (self, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SOURCE_XML:
|
|
|
|
|
_set_source_xml (self, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_FLAGS:
|
|
|
|
|
_set_flags (self, g_value_get_flags (value));
|
|
|
|
|
break;
|
2011-02-14 17:47:01 +00:00
|
|
|
|
case PROP_NEEDS_DOWNLOAD:
|
|
|
|
|
_set_needs_download (self, g_value_get_boolean (value));
|
|
|
|
|
break;
|
2013-02-02 13:39:37 +00:00
|
|
|
|
case PROP_MODIFIED:
|
|
|
|
|
_set_modified (self, g_value_get_uint64 (value));
|
|
|
|
|
break;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
cc_background_item_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
CcBackgroundItem *self;
|
|
|
|
|
|
|
|
|
|
self = CC_BACKGROUND_ITEM (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_NAME:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->name);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
2011-02-11 18:04:57 +00:00
|
|
|
|
case PROP_URI:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->uri);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_PLACEMENT:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_enum (value, self->placement);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHADING:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_enum (value, self->shading);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_PRIMARY_COLOR:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->primary_color);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SECONDARY_COLOR:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->secondary_color);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_IS_DELETED:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_boolean (value, self->is_deleted);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SOURCE_URL:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->source_url);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SOURCE_XML:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->source_xml);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_FLAGS:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_flags (value, self->flags);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SIZE:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_string (value, self->size);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
break;
|
2011-02-14 17:47:01 +00:00
|
|
|
|
case PROP_NEEDS_DOWNLOAD:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_boolean (value, self->needs_download);
|
2011-02-14 17:47:01 +00:00
|
|
|
|
break;
|
2013-01-25 11:56:58 +00:00
|
|
|
|
case PROP_MODIFIED:
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_value_set_uint64 (value, self->modified);
|
2013-01-25 11:56:58 +00:00
|
|
|
|
break;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
|
cc_background_item_constructor (GType type,
|
|
|
|
|
guint n_construct_properties,
|
|
|
|
|
GObjectConstructParam *construct_properties)
|
|
|
|
|
{
|
|
|
|
|
CcBackgroundItem *background_item;
|
|
|
|
|
|
|
|
|
|
background_item = CC_BACKGROUND_ITEM (G_OBJECT_CLASS (cc_background_item_parent_class)->constructor (type,
|
2017-09-04 10:42:56 +12:00
|
|
|
|
n_construct_properties,
|
|
|
|
|
construct_properties));
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
|
|
|
|
return G_OBJECT (background_item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
cc_background_item_class_init (CcBackgroundItemClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
object_class->get_property = cc_background_item_get_property;
|
|
|
|
|
object_class->set_property = cc_background_item_set_property;
|
|
|
|
|
object_class->constructor = cc_background_item_constructor;
|
|
|
|
|
object_class->finalize = cc_background_item_finalize;
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_NAME,
|
|
|
|
|
g_param_spec_string ("name",
|
|
|
|
|
"name",
|
|
|
|
|
"name",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
g_object_class_install_property (object_class,
|
2011-02-11 18:04:57 +00:00
|
|
|
|
PROP_URI,
|
|
|
|
|
g_param_spec_string ("uri",
|
|
|
|
|
"uri",
|
|
|
|
|
"uri",
|
2011-02-10 20:30:57 +00:00
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_PLACEMENT,
|
|
|
|
|
g_param_spec_enum ("placement",
|
|
|
|
|
"placement",
|
|
|
|
|
"placement",
|
|
|
|
|
G_DESKTOP_TYPE_DESKTOP_BACKGROUND_STYLE,
|
|
|
|
|
G_DESKTOP_BACKGROUND_STYLE_SCALED,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_SHADING,
|
|
|
|
|
g_param_spec_enum ("shading",
|
|
|
|
|
"shading",
|
|
|
|
|
"shading",
|
|
|
|
|
G_DESKTOP_TYPE_DESKTOP_BACKGROUND_SHADING,
|
|
|
|
|
G_DESKTOP_BACKGROUND_SHADING_SOLID,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_PRIMARY_COLOR,
|
|
|
|
|
g_param_spec_string ("primary-color",
|
|
|
|
|
"primary-color",
|
|
|
|
|
"primary-color",
|
|
|
|
|
"#000000000000",
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_SECONDARY_COLOR,
|
|
|
|
|
g_param_spec_string ("secondary-color",
|
|
|
|
|
"secondary-color",
|
|
|
|
|
"secondary-color",
|
|
|
|
|
"#000000000000",
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_IS_DELETED,
|
|
|
|
|
g_param_spec_boolean ("is-deleted",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_SOURCE_URL,
|
|
|
|
|
g_param_spec_string ("source-url",
|
|
|
|
|
"source-url",
|
|
|
|
|
"source-url",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_SOURCE_XML,
|
|
|
|
|
g_param_spec_string ("source-xml",
|
|
|
|
|
"source-xml",
|
|
|
|
|
"source-xml",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_FLAGS,
|
|
|
|
|
g_param_spec_flags ("flags",
|
|
|
|
|
"flags",
|
|
|
|
|
"flags",
|
|
|
|
|
G_DESKTOP_TYPE_BACKGROUND_ITEM_FLAGS,
|
|
|
|
|
0,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_SIZE,
|
|
|
|
|
g_param_spec_string ("size",
|
|
|
|
|
"size",
|
|
|
|
|
"size",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
2011-02-14 17:47:01 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_NEEDS_DOWNLOAD,
|
|
|
|
|
g_param_spec_boolean ("needs-download",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
TRUE,
|
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
2013-01-25 11:56:58 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_MODIFIED,
|
|
|
|
|
g_param_spec_uint64 ("modified",
|
|
|
|
|
"modified",
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
G_MAXUINT64,
|
|
|
|
|
0,
|
2013-02-02 13:39:37 +00:00
|
|
|
|
G_PARAM_READWRITE));
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
cc_background_item_init (CcBackgroundItem *item)
|
|
|
|
|
{
|
2017-09-25 14:16:09 -04:00
|
|
|
|
item->bg = gnome_bg_new ();
|
|
|
|
|
|
|
|
|
|
item->shading = G_DESKTOP_BACKGROUND_SHADING_SOLID;
|
|
|
|
|
item->placement = G_DESKTOP_BACKGROUND_STYLE_SCALED;
|
|
|
|
|
item->primary_color = g_strdup ("#000000000000");
|
|
|
|
|
item->secondary_color = g_strdup ("#000000000000");
|
|
|
|
|
item->needs_download = TRUE;
|
|
|
|
|
item->flags = 0;
|
|
|
|
|
item->modified = 0;
|
2011-02-10 20:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
cc_background_item_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
CcBackgroundItem *item;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (object != NULL);
|
|
|
|
|
g_return_if_fail (CC_IS_BACKGROUND_ITEM (object));
|
|
|
|
|
|
|
|
|
|
item = CC_BACKGROUND_ITEM (object);
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_return_if_fail (item != NULL);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_free (item->name);
|
|
|
|
|
g_free (item->uri);
|
|
|
|
|
g_free (item->primary_color);
|
|
|
|
|
g_free (item->secondary_color);
|
|
|
|
|
g_free (item->mime_type);
|
|
|
|
|
g_free (item->size);
|
|
|
|
|
g_free (item->source_url);
|
|
|
|
|
g_free (item->source_xml);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->bg != NULL)
|
|
|
|
|
g_object_unref (item->bg);
|
2011-02-10 20:30:57 +00:00
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_clear_object (&item->slideshow_emblem);
|
2014-06-30 15:47:24 +02:00
|
|
|
|
|
2011-02-10 20:30:57 +00:00
|
|
|
|
G_OBJECT_CLASS (cc_background_item_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CcBackgroundItem *
|
2011-02-11 18:04:57 +00:00
|
|
|
|
cc_background_item_new (const char *uri)
|
2011-02-10 20:30:57 +00:00
|
|
|
|
{
|
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
|
|
object = g_object_new (CC_TYPE_BACKGROUND_ITEM,
|
2011-02-11 18:04:57 +00:00
|
|
|
|
"uri", uri,
|
2011-02-10 20:30:57 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
return CC_BACKGROUND_ITEM (object);
|
2010-08-10 15:26:07 +01:00
|
|
|
|
}
|
2011-02-11 03:35:50 +00:00
|
|
|
|
|
2011-02-11 12:48:28 +00:00
|
|
|
|
CcBackgroundItem *
|
|
|
|
|
cc_background_item_copy (CcBackgroundItem *item)
|
|
|
|
|
{
|
|
|
|
|
CcBackgroundItem *ret;
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
ret = cc_background_item_new (item->uri);
|
|
|
|
|
ret->name = g_strdup (item->name);
|
|
|
|
|
ret->size = g_strdup (item->size);
|
|
|
|
|
ret->placement = item->placement;
|
|
|
|
|
ret->shading = item->shading;
|
|
|
|
|
ret->primary_color = g_strdup (item->primary_color);
|
|
|
|
|
ret->secondary_color = g_strdup (item->secondary_color);
|
|
|
|
|
ret->source_url = g_strdup (item->source_url);
|
|
|
|
|
ret->source_xml = g_strdup (item->source_xml);
|
|
|
|
|
ret->is_deleted = item->is_deleted;
|
|
|
|
|
ret->needs_download = item->needs_download;
|
|
|
|
|
ret->flags = item->flags;
|
2011-02-11 12:48:28 +00:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 03:35:50 +00:00
|
|
|
|
static const char *
|
|
|
|
|
flags_to_str (CcBackgroundItemFlags flag)
|
|
|
|
|
{
|
|
|
|
|
GFlagsClass *fclass;
|
|
|
|
|
GFlagsValue *value;
|
|
|
|
|
|
|
|
|
|
fclass = G_FLAGS_CLASS (g_type_class_peek (G_DESKTOP_TYPE_BACKGROUND_ITEM_FLAGS));
|
|
|
|
|
value = g_flags_get_first_value (fclass, flag);
|
|
|
|
|
|
|
|
|
|
g_assert (value);
|
|
|
|
|
|
|
|
|
|
return value->value_nick;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-13 02:31:36 +00:00
|
|
|
|
static const char *
|
|
|
|
|
enum_to_str (GType type,
|
|
|
|
|
int v)
|
|
|
|
|
{
|
|
|
|
|
GEnumClass *eclass;
|
|
|
|
|
GEnumValue *value;
|
|
|
|
|
|
|
|
|
|
eclass = G_ENUM_CLASS (g_type_class_peek (type));
|
|
|
|
|
value = g_enum_get_value (eclass, v);
|
|
|
|
|
|
|
|
|
|
g_assert (value);
|
|
|
|
|
|
|
|
|
|
return value->value_nick;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 03:35:50 +00:00
|
|
|
|
void
|
|
|
|
|
cc_background_item_dump (CcBackgroundItem *item)
|
|
|
|
|
{
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GString) flags = NULL;
|
2011-02-11 03:35:50 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (CC_IS_BACKGROUND_ITEM (item));
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
g_debug ("name:\t\t\t%s", item->name);
|
|
|
|
|
g_debug ("URI:\t\t\t%s", item->uri ? item->uri : "NULL");
|
|
|
|
|
if (item->size)
|
|
|
|
|
g_debug ("size:\t\t\t'%s'", item->size);
|
2011-02-11 03:35:50 +00:00
|
|
|
|
flags = g_string_new (NULL);
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->flags & (1 << i)) {
|
2011-02-11 03:35:50 +00:00
|
|
|
|
g_string_append (flags, flags_to_str (1 << i));
|
|
|
|
|
g_string_append_c (flags, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flags->len == 0)
|
|
|
|
|
g_string_append (flags, "-none-");
|
|
|
|
|
g_debug ("flags:\t\t\t%s", flags->str);
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (item->primary_color)
|
|
|
|
|
g_debug ("pcolor:\t\t\t%s", item->primary_color);
|
|
|
|
|
if (item->secondary_color)
|
|
|
|
|
g_debug ("scolor:\t\t\t%s", item->secondary_color);
|
|
|
|
|
g_debug ("placement:\t\t%s", enum_to_str (G_DESKTOP_TYPE_DESKTOP_BACKGROUND_STYLE, item->placement));
|
|
|
|
|
g_debug ("shading:\t\t%s", enum_to_str (G_DESKTOP_TYPE_DESKTOP_BACKGROUND_SHADING, item->shading));
|
|
|
|
|
if (item->source_url)
|
|
|
|
|
g_debug ("source URL:\t\t%s", item->source_url);
|
|
|
|
|
if (item->source_xml)
|
|
|
|
|
g_debug ("source XML:\t\t%s", item->source_xml);
|
|
|
|
|
g_debug ("deleted:\t\t%s", item->is_deleted ? "yes" : "no");
|
|
|
|
|
if (item->mime_type)
|
|
|
|
|
g_debug ("mime-type:\t\t%s", item->mime_type);
|
|
|
|
|
g_debug ("dimensions:\t\t%d x %d", item->width, item->height);
|
|
|
|
|
g_debug ("modified: %"G_GUINT64_FORMAT, item->modified);
|
2011-02-11 03:35:50 +00:00
|
|
|
|
g_debug (" ");
|
|
|
|
|
}
|
2011-02-13 02:49:03 +00:00
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
files_equal (const char *a,
|
|
|
|
|
const char *b)
|
|
|
|
|
{
|
2017-09-04 10:42:56 +12:00
|
|
|
|
g_autoptr(GFile) file1 = NULL;
|
|
|
|
|
g_autoptr(GFile) file2 = NULL;
|
2011-02-13 02:49:03 +00:00
|
|
|
|
gboolean retval;
|
|
|
|
|
|
2011-02-14 19:49:07 +00:00
|
|
|
|
if (a == NULL &&
|
|
|
|
|
b == NULL)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2011-02-14 07:42:58 +00:00
|
|
|
|
if (a == NULL ||
|
|
|
|
|
b == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-02-13 02:49:03 +00:00
|
|
|
|
file1 = g_file_new_for_commandline_arg (a);
|
|
|
|
|
file2 = g_file_new_for_commandline_arg (b);
|
|
|
|
|
if (g_file_equal (file1, file2) == FALSE)
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
else
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
colors_equal (const char *a,
|
|
|
|
|
const char *b)
|
|
|
|
|
{
|
2017-09-26 14:12:13 -04:00
|
|
|
|
GdkRGBA color1, color2;
|
2011-02-13 02:49:03 +00:00
|
|
|
|
|
2017-09-26 14:12:13 -04:00
|
|
|
|
gdk_rgba_parse (&color1, a);
|
|
|
|
|
gdk_rgba_parse (&color2, b);
|
2011-02-13 02:49:03 +00:00
|
|
|
|
|
2017-09-26 14:12:13 -04:00
|
|
|
|
return gdk_rgba_equal (&color1, &color2);
|
2011-02-13 02:49:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
cc_background_item_compare (CcBackgroundItem *saved,
|
|
|
|
|
CcBackgroundItem *configured)
|
|
|
|
|
{
|
|
|
|
|
CcBackgroundItemFlags flags;
|
|
|
|
|
|
2017-09-25 14:16:09 -04:00
|
|
|
|
flags = saved->flags;
|
2011-02-14 07:43:30 +00:00
|
|
|
|
if (flags == 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-02-13 02:49:03 +00:00
|
|
|
|
if (flags & CC_BACKGROUND_ITEM_HAS_URI) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (files_equal (saved->uri, configured->uri) == FALSE)
|
2011-02-13 02:49:03 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (flags & CC_BACKGROUND_ITEM_HAS_SHADING) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (saved->shading != configured->shading)
|
2011-02-13 02:49:03 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (saved->placement != configured->placement)
|
2011-02-13 02:49:03 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (colors_equal (saved->primary_color,
|
|
|
|
|
configured->primary_color) == FALSE) {
|
2011-02-13 02:49:03 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flags & CC_BACKGROUND_ITEM_HAS_SCOLOR) {
|
2017-09-25 14:16:09 -04:00
|
|
|
|
if (colors_equal (saved->secondary_color,
|
|
|
|
|
configured->secondary_color) == FALSE) {
|
2011-02-13 02:49:03 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|