~elementary-os/elementaryos/os-patch-gnome-control-center-precise

« back to all changes in this revision

Viewing changes to panels/background/bg-colors-source.c

  • Committer: Sergey "Shnatsel" Davidoff
  • Date: 2012-05-18 13:02:50 UTC
  • Revision ID: shnatsel@gmail.com-20120518130250-2u99ldq61a42rbt7
Initial import, version 1:3.4.1-0ubuntu2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* bg-colors-source.c */
 
2
/*
 
3
 * Copyright (C) 2010 Intel, Inc
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Author: Thomas Wood <thomas.wood@intel.com>
 
20
 *
 
21
 */
 
22
 
 
23
#include <config.h>
 
24
#include "bg-colors-source.h"
 
25
 
 
26
#include "cc-background-item.h"
 
27
 
 
28
#include <glib/gi18n-lib.h>
 
29
#include <gdesktop-enums.h>
 
30
 
 
31
G_DEFINE_TYPE (BgColorsSource, bg_colors_source, BG_TYPE_SOURCE)
 
32
 
 
33
#define COLORS_SOURCE_PRIVATE(o) \
 
34
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_COLORS_SOURCE, BgColorsSourcePrivate))
 
35
 
 
36
static void
 
37
bg_colors_source_class_init (BgColorsSourceClass *klass)
 
38
{
 
39
}
 
40
 
 
41
struct {
 
42
        const char *name;
 
43
        GDesktopBackgroundShading type;
 
44
        int orientation;
 
45
} items[] = {
 
46
        { N_("Horizontal Gradient"), G_DESKTOP_BACKGROUND_SHADING_HORIZONTAL, GTK_ORIENTATION_HORIZONTAL },
 
47
        { N_("Vertical Gradient"), G_DESKTOP_BACKGROUND_SHADING_VERTICAL, GTK_ORIENTATION_VERTICAL },
 
48
        { N_("Solid Color"), G_DESKTOP_BACKGROUND_SHADING_SOLID, -1 },
 
49
};
 
50
 
 
51
#define PCOLOR "#023c88"
 
52
#define SCOLOR "#5789ca"
 
53
 
 
54
static GEmblem *
 
55
get_arrow_icon (GtkOrientation orientation)
 
56
{
 
57
  GIcon *themed;
 
58
  GEmblem *emblem;
 
59
  if (orientation == GTK_ORIENTATION_HORIZONTAL)
 
60
    themed = g_themed_icon_new ("go-next-symbolic");
 
61
  else
 
62
    themed = g_themed_icon_new ("go-down-symbolic");
 
63
  emblem = g_emblem_new_with_origin (themed, G_EMBLEM_ORIGIN_DEVICE);
 
64
  g_object_unref (themed);
 
65
  return emblem;
 
66
}
 
67
 
 
68
static void
 
69
bg_colors_source_init (BgColorsSource *self)
 
70
{
 
71
  GnomeDesktopThumbnailFactory *thumb_factory;
 
72
  guint i;
 
73
  GtkListStore *store;
 
74
 
 
75
  store = bg_source_get_liststore (BG_SOURCE (self));
 
76
 
 
77
  thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
 
78
 
 
79
  for (i = 0; i < G_N_ELEMENTS (items); i++)
 
80
    {
 
81
      CcBackgroundItemFlags flags;
 
82
      CcBackgroundItem *item;
 
83
      GIcon *pixbuf;
 
84
 
 
85
      item = cc_background_item_new (NULL);
 
86
      flags = CC_BACKGROUND_ITEM_HAS_PCOLOR |
 
87
              CC_BACKGROUND_ITEM_HAS_SCOLOR |
 
88
              CC_BACKGROUND_ITEM_HAS_SHADING |
 
89
              CC_BACKGROUND_ITEM_HAS_PLACEMENT |
 
90
              CC_BACKGROUND_ITEM_HAS_URI;
 
91
      /* It does have a URI, it's "none" */
 
92
 
 
93
      g_object_set (G_OBJECT (item),
 
94
                    "name", _(items[i].name),
 
95
                    "primary-color", PCOLOR,
 
96
                    "secondary-color", SCOLOR,
 
97
                    "shading", items[i].type,
 
98
                    "placement", G_DESKTOP_BACKGROUND_STYLE_NONE,
 
99
                    "flags", flags,
 
100
                    NULL);
 
101
 
 
102
      /* insert the item into the liststore */
 
103
      pixbuf = cc_background_item_get_thumbnail (item,
 
104
                                                 thumb_factory,
 
105
                                                 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
 
106
      if (items[i].orientation != -1)
 
107
        {
 
108
          GEmblem *emblem;
 
109
          GIcon *icon;
 
110
 
 
111
          emblem = get_arrow_icon (items[i].orientation);
 
112
          icon = g_emblemed_icon_new (G_ICON (pixbuf), emblem);
 
113
          g_object_unref (emblem);
 
114
          g_object_unref (pixbuf);
 
115
          pixbuf = icon;
 
116
        }
 
117
      gtk_list_store_insert_with_values (store, NULL, 0,
 
118
                                         0, pixbuf,
 
119
                                         1, item,
 
120
                                         2, _(items[i].name),
 
121
                                         -1);
 
122
 
 
123
      g_object_unref (pixbuf);
 
124
    }
 
125
 
 
126
  g_object_unref (thumb_factory);
 
127
}
 
128
 
 
129
BgColorsSource *
 
130
bg_colors_source_new (void)
 
131
{
 
132
  return g_object_new (BG_TYPE_COLORS_SOURCE, NULL);
 
133
}
 
134