~unity-team/unity-lens-shopping/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 *
 */
using Dee;
using Config;
using Gee;

namespace Unity.ShoppingLens {
  
  const string ICON_PATH = Config.DATADIR + "/icons/unity-icon-theme/places/svg/";
  
  public class Daemon : GLib.Object
  {
    private Unity.Lens lens;
     
    construct
    {
      lens = new Unity.Lens("/com/canonical/unity/lens/shopping", "shopping");
      lens.search_in_global = true;
      lens.search_hint = _("Search products");
      lens.sources_display_name = _("Sources");
      lens.visible = false;
      
      populate_categories ();
      populate_filters ();

      var shopping_scope = new ShoppingScope ();
      lens.add_local_scope (shopping_scope);

      try {
        lens.export ();
      } catch (GLib.IOError e) {
        stdout.printf ("error %s\n", e.message);
      }
    }

    private void populate_filters ()
    {
      var filters = new GLib.List<Unity.Filter> ();

      /* TODO */

      /* A filter */
      {
      }

      /* Another filter */
      {
      }

      lens.filters = filters;
    }

    // FIXME: icons!
    private void populate_categories ()
    {
      /* Offsets of categories must match up with the Category enum */
      
      Unity.Category cat;
      var categories = new GLib.List<Unity.Category> ();
      var icon_dir = File.new_for_path (ICON_PATH);

      cat = new Unity.Category (_("More suggestions"),
                                new FileIcon (icon_dir.get_child ("group-treat-yourself.svg")),
                                Unity.CategoryRenderer.FLOW);
      categories.append (cat);

      cat = new Unity.Category (_("For purchase"),
                                new FileIcon (icon_dir.get_child ("group-songs.svg")),
                                Unity.CategoryRenderer.FLOW);
      categories.append (cat);

      lens.categories = categories;
    }
  }
} /* namespace */