bigboard r7298 - trunk/bigboard/stocks/apps



Author: marco
Date: Mon Apr 14 23:41:37 2008
New Revision: 7298
URL: http://svn.gnome.org/viewvc/bigboard?rev=7298&view=rev

Log:
Drop statification. Implement a simpler system which displays
all the pinned apps, followed by:
- Top applications.
- Global top apps if there are not enough top applications or
  app tracking is not enabled.
- Local applications if you are not online.


Modified:
   trunk/bigboard/stocks/apps/AppsStock.py
   trunk/bigboard/stocks/apps/apps.py

Modified: trunk/bigboard/stocks/apps/AppsStock.py
==============================================================================
--- trunk/bigboard/stocks/apps/AppsStock.py	(original)
+++ trunk/bigboard/stocks/apps/AppsStock.py	Mon Apr 14 23:41:37 2008
@@ -33,9 +33,6 @@
   
 
 class AppsStock(bigboard.stock.AbstractMugshotStock):
-    STATIC_SET_SIZE = 4
-    DYNAMIC_SET_SIZE = 0
-    STATIFICATION_TIME_SEC = 60 * 60 #* 24 * 3; # 3 days
     __gsignals__ = {
 
     }    
@@ -50,21 +47,16 @@
         self.__message_link.connect("button-press-event", lambda link, event: self.__on_message_link())
         self.__message_link_url = None
         self.__subtitle = hippo.CanvasText(font="Bold 12px")
-        self.__static_set = CanvasVBox()
-        self.__dynamic_set = CanvasVBox()
+        self.__applications = CanvasVBox()
         
         self.__box.append(self.__message)
         self.__box.append(self.__message_link)        
         self.__box.append(self.__subtitle)
-        self.__box.append(self.__static_set)
-        self.__box.append(self.__dynamic_set)        
-        self.__box.set_child_visible(self.__dynamic_set, False)
+        self.__box.append(self.__applications)
         
         self.__app_browser = None
         self._add_more_button(self.__on_more_button)
         
-        self.__static_set_ids = {}
-
         gconf.client_get_default().notify_add(GCONF_KEY_APP_SIZE, self.__on_app_size_changed)
          
         self.__set_message('Loading...')
@@ -156,41 +148,54 @@
             
     def set_size(self, size):
         super(AppsStock, self).set_size(size)
-        for child in self.__static_set.get_children() + self.__dynamic_set.get_children():
+        for child in self.__applications.get_children():
             self.__set_item_size(child, size)        
 
-    def __fill_static_set(self):
-        self.__static_set.remove_all()
-        self.__static_set_ids = {}
-
-        usage = self.__repo.get_app_usage_enabled()
-        pinned_apps = self.__repo.get_pinned_apps()
-        global_top_apps = self.__repo.get_global_top_apps()
+    def __get_popular_local_apps(self):
         local_apps = self.__repo.get_local_apps()
-        static_size = gconf.client_get_default().get_int(GCONF_KEY_APP_SIZE) or 7
 
+        result = [app for app in local_apps if app.get_app_name_from_file_name() in POPULAR_APPS]
+        result.sort(lambda a, b: cmp(POPULAR_APPS.index(a.get_app_name_from_file_name()),
+                                     POPULAR_APPS.index(b.get_app_name_from_file_name())))
+
+        return result
+
+    def __cmp_application_usage(self, a, b):
+        # note the "-" in front of the cmp to sort descending
+        return - cmp(a.get_usage_count(), b.get_usage_count())
+
+    def __fill_applications(self):
         self.__set_subtitle(None)
+        self.__applications.remove_all()
+
         apps_in_set = []
-        using_local_apps = False
-        if usage:
-            apps_in_set = pinned_apps
-        if len(apps_in_set) == 0:
-            if len(global_top_apps) > 0:
-                apps_in_set = global_top_apps
-                self.__set_subtitle("Popular Applications")
-            elif len(local_apps) > 0:
-                apps_in_set = local_apps
-                using_local_apps = True
-
-        if using_local_apps:
-            apps_in_set = filter(lambda a: POPULAR_APPS.count(a.get_app_name_from_file_name()) > 0, apps_in_set)
-            apps_in_set.sort(lambda a, b: cmp(POPULAR_APPS.index(a.get_app_name_from_file_name()), POPULAR_APPS.index(b.get_app_name_from_file_name())))
-        else: 
-            ## note the "-" in front of the cmp to sort descending
-            apps_in_set.sort(lambda a, b: - cmp(a.get_usage_count(), b.get_usage_count()))
-   
+
+        if self.__repo.get_app_usage_enabled():
+            pinned_apps = self.__repo.get_pinned_apps()
+            pinned_apps.sort(self.__cmp_application_usage)
+
+            my_top_apps = self.__repo.get_my_top_apps()
+            my_top_apps.sort(self.__cmp_application_usage)
+        else:
+            pinned_apps = []
+            my_top_apps = []
+
+        global_top_apps = self.__repo.get_global_top_apps()
+        global_top_apps.sort(self.__cmp_application_usage)
+
+        for app in (pinned_apps + my_top_apps + global_top_apps):
+            if app not in apps_in_set:
+                apps_in_set.append(app)
+
+        if not apps_in_set:
+            apps_in_set = self.__get_popular_local_apps()
+
+        if global_top_apps and not my_top_apps and not pinned_apps:
+            self.__set_subtitle("Popular Applications")
+
+        size = gconf.client_get_default().get_int(GCONF_KEY_APP_SIZE) or 7   
         for i, app in enumerate(apps_in_set):
-            if i >= static_size:
+            if i >= size:
                 break
 
             # don't display apps that are not installed if the user is not logged in
@@ -200,8 +205,7 @@
             display = apps_widgets.AppDisplay(apps_widgets.AppLocation.STOCK, app)
             display.connect("button-press-event", lambda display, event: display.launch()) 
             #_logger.debug("setting static set app: %s", app)
-            self.__static_set.append(display)
-            self.__static_set_ids[app.get_id()] = True
+            self.__applications.append(display)
 
     @defer_idle_func(logger=_logger)
     def __sync(self):
@@ -209,8 +213,6 @@
         
         self.__set_message(None)        
              
-        self.__box.set_child_visible(self.__dynamic_set, False)
-
         usage = self.__repo.get_app_usage_enabled()
 
         #_logger.debug("usage: %s", usage)
@@ -219,6 +221,4 @@
             self.__set_message("Enable application tracking", 
                                globals.get_baseurl() + "/account")        
 
-        self.__fill_static_set()
-
-        self.__repo.pin_stuff_if_we_have_none()
+        self.__fill_applications()

Modified: trunk/bigboard/stocks/apps/apps.py
==============================================================================
--- trunk/bigboard/stocks/apps/apps.py	(original)
+++ trunk/bigboard/stocks/apps/apps.py	Mon Apr 14 23:41:37 2008
@@ -537,29 +537,6 @@
     def set_app_pinned(self, app, pinned):
         self.set_app_id_pinned(app.get_id(), pinned)
 
-    def pin_stuff_if_we_have_none(self):
-        ## if no apps are pinned and application usage is enabled, initially pin
-        ## some stuff
-        if self.__myself and (len(self.__my_pinned_apps) == 0): 
-            if self.__myself.applicationUsageStart > 0:
-                _logger.debug("no static set")           
-                app_stalking_duration = (time.mktime(time.gmtime())) - (int(self.__myself.applicationUsageStart)/1000) 
-                _logger.debug("comparing stalking duration %s to statification time %s", app_stalking_duration, self.STATIFICATION_TIME_SEC)                  
-                if app_stalking_duration > self.STATIFICATION_TIME_SEC and len(self.__myself.topApplications) > 0:
-                    # We don't have a static set yet, time to make it
-                    pinned_ids = []
-                    for app_resource in self.__myself.topApplications:
-                        if len(pinned_ids) >= self.STATIC_SET_SIZE:
-                            break
-                        pinned_ids.append(app_resource.id)
-
-                    _logger.debug("creating initial pin set: %s", pinned_ids)
-                    for id in pinned_ids:
-                        self.set_app_id_pinned(id, True)
-        
-                        ## change notification should come in as the new pinned apps are
-                        ## created, and then we'll re-sync in response
-
     def __on_search_results(self, results_handler, category, search_terms, app_resources):
         _logger.debug("Got search results for search_terms='%s'", search_terms);
         ## on the first results_handler to be called, we'll need to remove the pending



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]