79
79
self._pending = None
80
80
self.sources_list = []
81
81
self.recommendations = []
82
self.recommendations_last_update = 0
82
83
self.scope = Unity.Scope.new("/net/launchpad/scope/remotevideos")
83
84
self.scope.search_in_global = False
84
85
self.scope.connect("search-changed", self.on_search_changed)
95
96
self.session.add_feature_by_type(SoupGNOME.ProxyResolverGNOME)
96
97
self.preferences = Unity.PreferencesManager.get_default()
97
98
self.query_list_of_sources()
98
self.update_recommendations()
99
99
self.preferences.connect("notify::remote-content-search", self.on_filtering_or_preference_changed)
100
100
self.scope.export()
101
101
# refresh the at least once every 30 minutes
102
102
GLib.timeout_add_seconds(REFRESH_INTERVAL/2, self.refresh_online_videos)
104
def update_recommendations(self):
105
"""Query the server for 'recommendations'.
107
In v0 extended, that means simply do an empty search with Amazon
108
as the source since it's the only paid provider at the moment.
110
if self.preferences.props.remote_content_search != Unity.PreferencesManagerRemoteContent.ALL:
112
msg = Soup.Message.new("GET", SERVER + "/search?q=&sources=Amazon")
113
self.session.queue_message(msg, self._recs_cb, None)
115
def _recs_cb(self, session, msg, user_data):
116
recs = self._handle_search_msg(msg)
117
print "Got %d recommendations from the server" % len(recs)
119
self.recommendations = recs
120
dt = REFRESH_INTERVAL
123
GLib.timeout_add_seconds(dt, self.update_recommendations)
125
104
def query_list_of_sources(self):
126
105
"""Query the server for a list of sources that will be used
127
106
to build sources filter options and search queries."""
272
251
def get_results(self, search_string, search, model, sources):
273
252
"""Query the server with the search string and the list of sources."""
274
if not search_string and not sources and self.recommendations:
275
self.update_results_model(search, model, self.recommendations, True)
253
if not search_string and not sources and self.recommendations and \
254
time.time()-self.recommendations_last_update < REFRESH_INTERVAL:
255
self.update_results_model(search, model, self.recommendations)
277
257
if self._pending is not None:
278
258
self.session.cancel_message(self._pending,
287
267
self._pending = Soup.Message.new("GET", url)
288
268
self.session.queue_message(self._pending,
270
(search, model, sources))
292
def _search_cb(self, session, msg, (search, model)):
272
def _search_cb(self, session, msg, (search, model, sources)):
293
273
if msg is not self._pending:
294
274
# nothing to do here
295
275
print "WAT? _search_cb snuck in on a non-pending msg"
297
277
self._pending = None
298
278
results = self._handle_search_msg(msg)
279
# cache no-query results
280
if not search.props.search_string.strip() and not sources and results:
281
self.recommendations = results
282
self.recommendations_last_update = time.time()
299
283
self.update_results_model(search, model, results)
301
285
def _handle_search_msg(self, msg):