[d-feet] D-Feet: Add a persistant history to the combobox in the "connect to other bus" dialog.



commit 2e3c902674f76ebd9281ecfaf2770239b881ebbf
Author: Florent Viard <fviard lacie com>
Date:   Mon Sep 13 16:23:06 2010 +0200

    D-Feet: Add a persistant history to the combobox in the "connect to other bus" dialog.

 dfeet/DFeetApp.py                |   28 +++++++++++++++++++++++++++-
 dfeet/_ui/addconnectiondialog.py |    4 ++++
 dfeet/settings.py                |    3 ++-
 3 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/dfeet/DFeetApp.py b/dfeet/DFeetApp.py
index e8d17c8..271ca98 100644
--- a/dfeet/DFeetApp.py
+++ b/dfeet/DFeetApp.py
@@ -16,6 +16,9 @@ from _ui.executemethoddialog import ExecuteMethodDialog
 
 
 class DFeetApp:
+
+    HISTORY_MAX_SIZE = 10
+
     def __init__(self):
         signal_dict = {'add_session_bus': self.add_session_bus_cb,
                        'add_system_bus': self.add_system_bus_cb,
@@ -42,6 +45,7 @@ class DFeetApp:
                                  int(settings.general['windowheight']))
 
         self._load_tabs(settings)
+        self._load_addbus_history(settings)
 
         self.main_window.show()
 
@@ -56,6 +60,13 @@ class DFeetApp:
             else:
                 self.add_bus(address = bus_name)
 
+    def _load_addbus_history(self, settings):
+        self.add_bus_history = []
+        self.combo_addbus_history_model = gtk.ListStore(str)
+        for bus_add in settings.general['addbus_list']:
+            if bus_add != '':
+                self.add_bus_history.append(bus_add)
+
     def _add_bus_tab(self, bus_watch):
         name = bus_watch.get_bus_name()
         bus_paned = _ui.BusBox(bus_watch)
@@ -126,6 +137,11 @@ class DFeetApp:
 
     def add_bus_address_cb(self, action):
         dialog = AddConnectionDialog(self.main_window)
+        self.combo_addbus_history_model.clear()
+        # Load combo box history
+        for el in self.add_bus_history:
+            self.combo_addbus_history_model.append([el])
+        dialog.set_model(self.combo_addbus_history_model)
         result = dialog.run()
         if result == 1:
             bus_address = dialog.get_address()
@@ -135,6 +151,13 @@ class DFeetApp:
                 self.add_bus(dbus_introspector.SYSTEM_BUS)
             else:
                 self.add_bus(address = bus_address)
+                # Fill history
+                if bus_address in self.add_bus_history:
+                    self.add_bus_history.remove(bus_address)
+                self.add_bus_history.insert(0, bus_address)
+                # Truncating history
+                if (len(self.add_bus_history) > self.HISTORY_MAX_SIZE):
+                    self.add_bus_history = self.add_bus_history[0:self.HISTORY_MAX_SIZE]
 
         dialog.destroy()
 
@@ -155,8 +178,11 @@ class DFeetApp:
             child = self.notebook.get_nth_page(i)
             bus_watch = child.get_bus_watch()
             tab_list.append(bus_watch.get_bus_name())
-   
+
+        self.add_bus_history = self.add_bus_history[0:self.HISTORY_MAX_SIZE]
+
         settings.general['bustabs_list'] = tab_list
+        settings.general['addbus_list'] = self.add_bus_history
          
         settings.write()
 
diff --git a/dfeet/_ui/addconnectiondialog.py b/dfeet/_ui/addconnectiondialog.py
index 8ad74a7..af99ae9 100644
--- a/dfeet/_ui/addconnectiondialog.py
+++ b/dfeet/_ui/addconnectiondialog.py
@@ -28,3 +28,7 @@ class AddConnectionDialog:
         self.dialog.response(self.RESPONSE_CONNECT)
         return True
 
+    def set_model(self, model):
+        self.combo_entry.set_model(model)
+        self.combo_entry.set_text_column(0)
+
diff --git a/dfeet/settings.py b/dfeet/settings.py
index dc53365..ef9e7b4 100644
--- a/dfeet/settings.py
+++ b/dfeet/settings.py
@@ -20,7 +20,8 @@ class Settings:
                 "windowheight" : 550,
                 "windowwidth" : 900,
                 "windowstate" : None,
-                "bustabs_list" : []
+                "bustabs_list" : [],
+                "addbus_list" : []
                 }
     
     def __init__(self, filename = None):



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