~lore-mattei/onehundredscopes/flickr-precise

« back to all changes in this revision

Viewing changes to src/unity-scope-flickr

  • Committer: Lorenzo Mattei
  • Date: 2012-03-02 16:05:08 UTC
  • Revision ID: lore.mattei@gmail.com-20120302160508-2wwea8zuqcz81a63
Fixes bug #943254

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
                self.scope = Unity.Scope.new ("/net/launchpad/scope/image/flickr")
45
45
                self.scope.search_in_global = False
46
46
                self.scope.connect ("search-changed", self.on_search_changed)
47
 
                self.scope.connect ("filters-changed", self.on_search_changed)
 
47
                self.scope.connect ("filters-changed", self.on_filtering_changed)
48
48
                self.scope.connect ("activate-uri", self.on_activate_uri);
49
49
                self.scope.connect("notify::active", self.on_lens_active)
 
50
                self.scope.props.sources.connect("notify::filtering",
 
51
            self.on_filtering_changed)
50
52
                self.scope.export()
51
53
 
52
54
        def on_activate_uri (self, scope, uri):
55
57
                        search = uri.split('__')[1]
56
58
                        results = self.scope.props.results_model
57
59
                        results.remove(results.get_iter_at_row(results.get_n_rows()-1))
58
 
                        # Here, we can safely assume that the user has a valid session token
59
 
                        self.update_results_model (search, results, page, True)
 
60
                        self.update_results_model (search, results, page, has_token)
60
61
                        return Unity.ActivationResponse(handled=Unity.HandledType.SHOW_DASH, goto_uri="")
61
62
                elif uri.startswith("connect"):
62
63
                        self.flickr_connect()
72
73
                (token, frob) = flickr.get_token_part_one(perms='write')
73
74
                global clicked
74
75
                clicked = True
75
 
        
 
76
 
 
77
        def on_filtering_changed(self, *_):
 
78
                """Run another search when a filter change is notified."""
 
79
                self.scope.queue_search_changed(Unity.SearchType.DEFAULT)
 
80
        
76
81
        def on_lens_active(self, *_):
77
82
                """ Run a search when the lens is opened """
78
83
                if self.scope.props.active:
91
96
                                if clicked:
92
97
                                        flickr.get_token_part_two((token, frob))
93
98
                        if search_type is Unity.SearchType.DEFAULT:
94
 
                                self.update_results_model(search_string, model, '1', has_token)
 
99
                                if search_string == '':
 
100
                                        print "Global view without search string : hide"
 
101
                                else:
 
102
                                        self.update_results_model(search_string, model, '1', has_token)
95
103
                        if search:
96
104
                                search.finished()
97
105
 
98
106
        def update_results_model(self, search, model, page, has_token):
99
107
                i = ''
100
108
                counter = 0
101
 
                cat = 2
 
109
                cat = 0
 
110
                if len(search) > 0:
 
111
                        cat = 2
 
112
                else:
 
113
                        cat = 0
102
114
                if not has_token:
103
115
                        model.append ("connect", "goa-panel", cat,"text/html", "Authorize with Flickr", '', '')
104
116
                else: