~davidc3/onehundredscopes/photo

« back to all changes in this revision

Viewing changes to src/unity-lens-photo

  • Committer: David Call√©
  • Date: 2012-01-02 17:44:10 UTC
  • Revision ID: davidc@framli.eu-20120102174410-solyn9jif15rw7yx
Branch init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
#    Copyright (c) 2011 David Calle <davidc@framli.eu>
 
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 3 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, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
import sys
 
19
import os
 
20
from gi.repository import GLib, GObject, Gio
 
21
from gi.repository import Dee
 
22
# FIXME: Some weird bug in Dee or PyGI makes Dee fail unless we probe
 
23
#        it *before* we import the Unity module... ?!
 
24
_m = dir(Dee.SequenceModel)
 
25
from gi.repository import Unity
 
26
 
 
27
#[1]
 
28
BUS_NAME = "net.launchpad.lens.photo"
 
29
 
 
30
class Daemon:
 
31
 
 
32
        def __init__ (self):
 
33
                # The path for the Lens *must* also match the one in our .lens file
 
34
                #[2]
 
35
                self._lens = Unity.Lens.new ("/net/launchpad/lens/photo", "photo")
 
36
                #[3]
 
37
                self._scope = Unity.Scope.new ("/net/launchpad/lens/photo/main")
 
38
                
 
39
                #[4]
 
40
                self._lens.props.search_hint = "Search Photos"
 
41
                #[5]
 
42
                self._lens.props.visible = True;
 
43
                #[6]
 
44
                self._lens.props.search_in_global = True;
 
45
                
 
46
                # Populate categories
 
47
                cats = []
 
48
 
 
49
                cats.append (Unity.Category.new ("Photos",
 
50
                                                 Gio.ThemedIcon.new("/usr/share/unity/lenses/photo/unity-cat-designs.svg"),
 
51
                                                 Unity.CategoryRenderer.VERTICAL_TILE))
 
52
                cats.append (Unity.Category.new ("Albums",
 
53
                                                 Gio.ThemedIcon.new("/usr/share/unity/lenses/photo/unity-cat-designs.svg"),
 
54
                                                 Unity.CategoryRenderer.VERTICAL_TILE))
 
55
                cats.append (Unity.Category.new ("Flickr",
 
56
                                                 Gio.ThemedIcon.new("/usr/share/unity/4/lens-nav-photo.svg"),
 
57
                                                 Unity.CategoryRenderer.VERTICAL_TILE))
 
58
 
 
59
                self._lens.props.categories = cats
 
60
                
 
61
                # Populate filters
 
62
                filters = []
 
63
#               f = Unity.RadioOptionFilter.new ("photo_categories", "Assets", Gio.ThemedIcon.new("input-keyboard-symbolic"), False)
 
64
#               f.add_option ("palettes", "Palettes", None)
 
65
#               f.add_option ("icons", "Icons", None)
 
66
#               f.add_option ("brushes", "Brushes", None)
 
67
#               f.add_option ("designs", "Designs", None)
 
68
#               filters.append (f)
 
69
                self._lens.props.filters = filters
 
70
 
 
71
                self._lens.export ();
 
72
 
 
73
if __name__ == "__main__":
 
74
        session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
 
75
        session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
 
76
                                              'org.freedesktop.DBus',
 
77
                                              '/org/freedesktop/DBus',
 
78
                                              'org.freedesktop.DBus', None)
 
79
        result = session_bus.call_sync('RequestName',
 
80
                                       GLib.Variant ("(su)", (BUS_NAME, 0x4)),
 
81
                                       0, -1, None)
 
82
                                       
 
83
        # Unpack variant response with signature "(u)". 1 means we got it.
 
84
        result = result.unpack()[0]
 
85
        
 
86
        if result != 1 :
 
87
                print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME
 
88
                raise SystemExit (1)
 
89
        
 
90
        daemon = Daemon()
 
91
        GObject.MainLoop().run()