[gevice/gevice-2-0] New branch gevice-2-0



commit de916b77d44944b6954ed24daa32f925f7c476dd
Author: Alejandro Valdes Jimenez <avaldes gnome org>
Date:   Fri Oct 28 14:47:37 2011 -0300

    New branch gevice-2-0

 ChangeLog             |    6 +
 INSTALL-DBASE         |   33 ---
 NEWS                  |    4 +-
 README                |    2 +-
 configure.ac          |   12 +-
 db_gevice             |  Bin 0 -> 25600 bytes
 gevice.sql            |  651 -------------------------------------------------
 src/gevice.py         |  130 +++++++----
 src/gevicedatabase.py |  560 ++++++++++++++++++-------------------------
 src/gevicedevice.py   |  486 ++++++++++++++++++-------------------
 src/gevicemodel.py    |  345 +++++++++++++-------------
 src/geviceprefer.py   |   57 -----
 12 files changed, 739 insertions(+), 1547 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d0b689f..babd10c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-10-28  Alejandro Valdes Jimenez  <avaldes gnome org>
+	* New branch: 2.0
+	* INSTALL-DBASE:
+	* db_gevice:
+	* gevice.sql:
+
 2011-10-27  Alejandro Valdes Jimenez  <avaldes gnome org>
 	* README:
 	* src/gevice.py: remove some tab spaces.
diff --git a/NEWS b/NEWS
index 6791703..0cb9a0b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
-2009-05-14  Alejandro Valdes Jimenez  <avaldes utalca cl>
+2011-10-28  Alejandro Valdes Jimenez  <avaldes gnome org>
+	* Remove support for Postgresql database. Now, Sqlite3 is used.
 
+2009-05-14  Alejandro Valdes Jimenez  <avaldes gnome org>
 	* Now, the new hosting for this project is in http://projects.gnome.org/gevice/. I very very happy! 
diff --git a/README b/README
index b7a383b..4eb5e87 100644
--- a/README
+++ b/README
@@ -10,7 +10,7 @@ it. See the COPYING file for details.
 * Features
 	- Allow you to draw the net model.
 	- Allow you to print the net diagram in png,gif,jpg formats.
-	- Allow you to save your model in database (Postgresql)
+	- Allow you to save your model in database (Sqlite3)
 	- Allow you to manager the device, in terminal (telnet,ssh or local) or with RDP, VNC.
 	- Allow export data to CSV file. Use "|" to separate fields (or other).
 
diff --git a/configure.ac b/configure.ac
index 7aa9933..164776d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([gevice], [1.0.0],[http://bugzilla.gnome.org/enter_bug.cgi?product=gevice],[gevice])
+AC_INIT([gevice], [2.0.0],[http://bugzilla.gnome.org/enter_bug.cgi?product=gevice],[gevice])
 AC_CONFIG_SRCDIR(src/gevice.py)
 
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
@@ -60,16 +60,6 @@ else
 	exit 1 
 fi
 
-MODULE_NAME="psycopg2"
-$PYTHONC -c "import $MODULE_NAME" 2>/dev/null
-if test $? -eq 0
-then
-	AC_MSG_RESULT(checking for python module: $MODULE_NAME: found)
-else
-	AC_MSG_RESULT(checking for python module: $MODULE_NAME: not found)
-	exit 1 
-fi
-
 MODULE_NAME="pygraphviz"
 $PYTHONC -c "import $MODULE_NAME" 2>/dev/null
 if test $? -eq 0
diff --git a/db_gevice b/db_gevice
new file mode 100644
index 0000000..b56bf64
Binary files /dev/null and b/db_gevice differ
diff --git a/src/gevice.py b/src/gevice.py
index d8bf6b6..865c68f 100755
--- a/src/gevice.py
+++ b/src/gevice.py
@@ -20,6 +20,7 @@ from gi.repository import Gtk, GdkPixbuf, Vte, GLib
 
 import os
 import os.path
+from struct import unpack
 
 import config
 import gevicefind
@@ -40,6 +41,8 @@ from gettext import gettext as _
 
 class Gevice:
   def __init__ (self):
+    # SQLite format 3 (header string)
+    self.magic = ('\x53', '\x51', '\x4c', '\x69', '\x74', '\x65', '\x20', '\x66', '\x6f', '\x72', '\x6d', '\x61', '\x74', '\x20', '\x33', '\x00')
     self.list_models = None
     self.list_links = None
     self.list_location = None
@@ -60,7 +63,7 @@ class Gevice:
     
     # model for devices
     self.gmodel = gevicemodel.GeviceModel(self)
-    
+
     # get widgets of main app
     builder = Gtk.Builder()
     builder.add_from_file(os.path.join (config.UIDIR, "main.xml"))
@@ -93,7 +96,6 @@ class Gevice:
     
     # create MenuBar
     self.menubar = self.uimanager.get_widget ('/MainMenu')
-    #self.vbox_main.pack_start (self.menubar,False,False,0)
     self.vbox_main.pack_start (self.menubar,False,False,0)
     
     # create a Toolbar and set style
@@ -127,7 +129,6 @@ class Gevice:
     self.maintoolbar.insert(separator_user,13)
     self.maintoolbar.insert(self.toolitem_proto,14)
     
-    
     # create combobox_proto
     self.vboxproto = Gtk.VBox(homogeneous=False,spacing=0)
     self.combobox_proto = Gtk.ComboBox(model=self.modelproto,has_entry=False)
@@ -141,6 +142,17 @@ class Gevice:
     
     self.hbox.pack_start (self.maintoolbar,True,True,0)	
     
+    # infobar
+    self.infobar = Gtk.InfoBar()
+    self.infobar.add_button (Gtk.STOCK_OK, Gtk.ResponseType.OK)
+    self.infobar.connect("response", self.infobar_response_received)
+    
+    self.vbox_main.pack_start(self.infobar,False,False,0)
+    
+    self.label_infobar = Gtk.Label(label="InfoBar Example")
+    content = self.infobar.get_content_area()
+    content.add(self.label_infobar)
+    
     # add treeview to vboxtreeview
     self.scroll = Gtk.ScrolledWindow()
     self.scroll.add (self.gmodel.treeview)
@@ -163,7 +175,13 @@ class Gevice:
     
     # show all
     self.window_main.show_all()
+
+    self.infobar.hide()
     return
+
+  def infobar_response_received(self, infobar, response):
+    if response == Gtk.ResponseType.OK:
+        infobar.hide()
   
   def create_actionsgroups (self):
     self.actiongroup_window = Gtk.ActionGroup ('Window Actions')
@@ -239,12 +257,17 @@ class Gevice:
   def main(self):
     Gtk.main()
   
+  def show_infobar_message (self,msg,type_msg):
+    self.infobar.set_message_type(type_msg)
+    self.label_infobar.set_text(msg)    
+    self.infobar.show_all()
+
   def show_message (self,msg,type_msg,buttons,window):
     if (window == None):
       window = self.window_main
-      
-    dialog = Gtk.Dialog(config.PACKAGE,window,flags=0,buttons=(buttons))
-    
+
+    dialog = Gtk.Dialog(config.PACKAGE,window,flags=1,buttons=(buttons))
+
     label = Gtk.Label(msg)
     content_area = dialog.get_content_area()
     content_area.add (label)
@@ -252,7 +275,7 @@ class Gevice:
 
     result = dialog.run()
     dialog.destroy()
-    
+
     return result
   
   def close_page_of_notebook(self,widget,vpaned):
@@ -302,7 +325,8 @@ class Gevice:
       i = self.gmodel.get_iter_selected (self.gmodel.treeview)
       
       if not i["iter"]:
-        result = gevice.show_message (_("Not device selected"), None,(Gtk.STOCK_OK, Gtk.ResponseType.OK), None)
+        result = gevice.show_infobar_message (_("Not device selected"), 
+          Gtk.MessageType.INFO)
         return
       else:
         # get data from device selected (devicename, IP)
@@ -381,7 +405,7 @@ class Gevice:
       "update2":" where id_modelo=",
       "delete":"delete from modelo where id_modelo=",
       "max_id":"select max(id_modelo) + 1 from modelo;",
-      "insert":"insert into modelo values ",
+      "insert":"insert into modelo (id_modelo, id_tipo_disp, id_marca, nom_modelo) values ",
       "sql_mark":"select nom_marca,id_marca from marca;",
       "sql_tipo_disp":"select nom_tipo_disp,id_tipo_disp from tipo_disp"}
       
@@ -401,7 +425,7 @@ class Gevice:
       "update2":" where id_rack=",
       "delete":"delete from rack where id_rack=",
       "max_id":"select max(id_rack) + 1 from rack;",
-      "insert":"insert into rack values ",
+      "insert":"insert into rack (id_rack, id_nivel, id_edif, detalle) values ",
       "sql_level":"select nom_nivel,id_nivel from nivel;",
       "sql_edifice":"select '[' || campus.nom_campus || '][' || edificio.nom_edif || ']', edificio.id_edif from edificio inner join campus on edificio.id_campus = campus.id_campus order by campus.nom_campus,edificio.nom_edif "}
     
@@ -415,12 +439,14 @@ class Gevice:
     sql_select = sql_select + "from edificio inner join campus on edificio.id_campus = campus.id_campus "
     sql_select = sql_select +  "order by 2,3"
     
+    print sql_select
+    
     sql = {"select":sql_select,
       "update1":"update edificio set nom_edif=",
       "update2":" where id_edif=",
       "delete":"delete from edificio where id_edif=",
       "max_id":"select max(id_edif) + 1 from edificio;",
-      "insert":"insert into edificio values ",
+      "insert":"insert into edificio (id_edif, id_campus, nom_edif) values ",
       "sql_campus":"select nom_campus, id_campus from campus;"}
       
     dialogmaintainer = gevicemaintainer.GeviceMaintainer ()
@@ -430,7 +456,7 @@ class Gevice:
     
   def on_action_level (gevice,action,data):
     sql = {"select":"select * from nivel order by 1",
-      "insert":"insert into nivel values ",
+      "insert":"insert into nivel (id_nivel, nom_nivel) values ",
       "delete":"delete from nivel where id_nivel=",
       "update1":"update nivel set nom_nivel=",
       "update2":" where id_nivel=",
@@ -443,7 +469,7 @@ class Gevice:
     
   def on_action_campus (gevice,action,data):
     sql = {"select":"select * from campus order by 1",
-      "insert":"insert into campus values ",
+      "insert":"insert into campus (id_campus, nom_campus) values ",
       "delete":"delete from campus where id_campus=",
       "update1":"update campus set nom_campus=",
       "update2":" where id_campus=",
@@ -456,7 +482,7 @@ class Gevice:
   
   def on_action_mark (gevice,action,data):
     sql = {"select":"select * from marca order by 1",
-      "insert":"insert into marca values ",
+      "insert":"insert into marca (id_marca, nom_marca) values ",
       "delete":"delete from marca where id_marca=",
       "update1":"update marca set nom_marca=",
       "update2":" where id_marca=",
@@ -464,12 +490,12 @@ class Gevice:
     
     dialogmaintainer = gevicemaintainer.GeviceMaintainer ()
     dialogmaintainer.load_interface (gevice,_("Mark"),sql)
-    dialogmaintainer.load_data (gevice,sql)
+    dialogmaintainer.load_data (gevice,sql) 
     dialogmaintainer.show_interface ()
     
   def on_action_typeofdev (gevice,action,data):
     sql = {"select":"select * from tipo_disp order by 1",
-      "insert":"insert into tipo_disp values ",
+      "insert":"insert into tipo_disp (id_tipo_disp, nom_tipo_disp) values ",
       "delete":"delete from tipo_disp where id_tipo_disp=",
       "update1":"update tipo_disp set nom_tipo_disp=",
       "update2":" where id_tipo_disp=",
@@ -482,7 +508,7 @@ class Gevice:
   
   def on_action_typeoflink (gevice,action,data):
     sql = {"select":"select * from tipo_enlace order by 1",
-      "insert":"insert into tipo_enlace values ",
+      "insert":"insert into tipo_enlace (id_tipo_enlace, nom_tipo_enlace) values ",
       "delete":"delete from tipo_enlace where id_tipo_enlace=",
       "update1":"update tipo_enlace set nom_tipo_enlace=",
       "update2":" where id_tipo_enlace=",
@@ -530,10 +556,8 @@ class Gevice:
       gevice.gdiagram.load_interface (gevice)
       gevice.gdiagram.show_interface ()
     else:
-      result = gevice.show_message (_("You need choose some device to generate the diagram."), 
-        None,
-        (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-        gevice.window_main)
+      result = gevice.show_infobar_message (_("You need choose some device to generate the diagram."), 
+        Gtk.MessageType.INFO)
       
   def on_action_print (gevice,action):
     gprint = geviceprint.GevicePrint()
@@ -563,33 +587,49 @@ class Gevice:
     gevice.gdevice.show_interface ()
     
   def on_action_open (gevice,action,data):
-    if (not gevice.connected_to_database):
-      gevice.gdbase = gevicedatabase.GeviceDatabase ()
-      gevice.gdbase.load_interface (gevice)
-      gevice.gdbase.label_host.set_text (gevice.gpref.host)
-      gevice.gdbase.label_dbase.set_text (gevice.gpref.dbase)
-      gevice.gdbase.label_user_dbase.set_text (gevice.gpref.user_dbase)
-      gevice.gdbase.show_interface ()
+    if (not gevice.connected_to_database):    
+      filechooser = Gtk.FileChooserDialog(title=_("Open Database"), 
+        parent=gevice.window_main, 
+        action=Gtk.FileChooserAction.OPEN, 
+        buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT))	
+
+      filechooser.set_select_multiple(False)
+
+      response = filechooser.run()
+
+      if response == Gtk.ResponseType.ACCEPT:
+        dbsqlite = filechooser.get_filename()
+
+      filechooser.destroy()    
+        
+      with open(dbsqlite, 'rb') as handle:
+        s = unpack('cccccccccccccccc', handle.read(16))
+        if s == gevice.magic:
+          gevice.gdbase = gevicedatabase.GeviceDatabase (dbsqlite,gevice)
+          gevice.update_statusbar (dbsqlite)
+        else:
+          result = gevice.show_infobar_message (_("Seems not sqlite3: " + dbsqlite), 
+            Gtk.MessageType.ERROR)
     else:
       gevice.gmodel.treestore.clear()
       gevice.gmodel.treeview.set_model(None)
       
-    action_open = gevice.actiongroup_window.get_action("Open")
-    action_open.set_property ("stock-id",Gtk.STOCK_DISCONNECT)
-    action_open.set_property ("tooltip",_("Connect to database"))
-    action_open.set_property ("label",_("Connect"))
-    
-    gevice.actiongroup_window.set_sensitive (True)
-    gevice.actiongroup_model.set_sensitive (False)
-    gevice.actiongroup_device.set_sensitive (False)
-    gevice.connected_to_database = False
+      action_open = gevice.actiongroup_window.get_action("Open")
+      action_open.set_property ("stock-id",Gtk.STOCK_DISCONNECT)
+      action_open.set_property ("tooltip",_("Connect to database"))
+      action_open.set_property ("label",_("Connect"))
+    
+      gevice.actiongroup_window.set_sensitive (True)
+      gevice.actiongroup_model.set_sensitive (False)
+      gevice.actiongroup_device.set_sensitive (False)
+      gevice.connected_to_database = False
+      
+      gevice.update_statusbar("")
     
   def on_action_save (gevice,action,data):
     gevice.gdbase.save_data_to_database(gevice)
-    result = gevice.show_message (_("Model saved"),
-      None,
-      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-      None)
+    result = gevice.show_infobar_message (_("Model saved"),
+      Gtk.MessageType.INFO)
     
   def on_action_connect(self,action,data):
     flag = True
@@ -647,12 +687,8 @@ class Gevice:
     
     return proto
   
-  def update_statusbar (self):
-    msg = _("[Host: ") + self.gpref.host + " "
-    msg+= _("Database: ") + self.gpref.dbase + " "
-    msg+= _("User: ") + self.gpref.user_dbase + "]"
-    
-    self.statusbar.push (self.context_id,msg)
+  def update_statusbar (self,dbsqlite):
+    self.statusbar.push (self.context_id,dbsqlite)
 
 if __name__ == "__main__":
   gevice = Gevice()
diff --git a/src/gevicedatabase.py b/src/gevicedatabase.py
index 6bb055a..e49f0e5 100644
--- a/src/gevicedatabase.py
+++ b/src/gevicedatabase.py
@@ -1,6 +1,6 @@
 from gi.repository import Gtk, Gdk
 import os
-import psycopg2
+import sqlite3
 
 import config
 
@@ -11,330 +11,238 @@ gettext.bind_textdomain_codeset (config.PACKAGE, "UTF-8");
 from gettext import gettext as _
 
 class GeviceDatabase:
-    def __init__ (self):
-        self.dbase = None
-        self.user = None
-        self.host = None
-        self.passwd = None
-
-        self.conn = None
-        self.cur = None
-        
-        self.devices_to_connect = []
-        
-    
-    def connect (self,passwd,gevice):
-        try:
-            conn = psycopg2.connect("dbname=" + gevice.gpref.dbase + " user=" + gevice.gpref.user_dbase + " host=" + gevice.gpref.host + " password=" + passwd)
-            return conn
-        except:
-	    result = gevice.show_message (_("Unable to connect to the database"),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      self.window_database)
-            return False
-
-
-    def execute_sql_select (self,gevice,sql):
-        try:
-            self.cur.execute(sql)
-            rows = self.cur.fetchall()
-            return rows
-        except:
-	    result = gevice.show_message (_("Unable to execute SQL: " + sql),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      None)
-            return False
-        
-    def execute_sql_insert (self,gevice,sql):
-        try:
-            self.cur.execute(sql)
-            return True
-        except:
-	    result = gevice.show_message (_("Unable to execute SQL: " + sql),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      None)
-            return False
-            
-    def execute_sql_delete (self,gevice,sql):
-        try:
-            self.cur.execute(sql)
-            return True
-        except:
-	    result = gevice.show_message (_("Unable to execute SQL: " + sql),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      None)
-            return False
-
-    def execute_sql_update (self,gevice,sql):
-        try:
-            self.cur.execute(sql)
-            return True
-        except:
-	    result = gevice.show_message (_("Unable to execute SQL: " + sql),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      None)
-            return False
-
-    def load_interface (self,gevice,action="connect"):
-	builder = Gtk.Builder()
-	builder.add_from_file(os.path.join (config.UIDIR, "dbase.xml"))
-	
-	self.window_database = builder.get_object ("window_database")
-	self.button_connect_cancel = builder.get_object ("button_connect_cancel")
-	self.button_connect_dbase = builder.get_object ("button_connect_dbase")
-	self.label_host = builder.get_object ("label_host")
-	self.label_dbase = builder.get_object ("label_dbase")
-	self.label_user_dbase = builder.get_object ("label_user_dbase")
-	self.entry_passwd_dbase = builder.get_object ("entry_passwd_dbase")
-	
-	self.button_connect_cancel.connect ("clicked",self.on_button_connect_cancel_clicked)
-	
-	if action=="save":
-	  self.button_connect_dbase.connect ("clicked",self.on_button_connect_dbase_clicked_save,gevice)
-	  self.entry_passwd_dbase.connect ("key-press-event", self.on_entry_passwd_dbase_key_press_save,gevice)	  
-	  self.window_database.set_title (_("Save database"))
-	  self.button_connect_dbase.set_label (_("Save"))
-	else:
-	  self.button_connect_dbase.connect ("clicked",self.on_button_connect_dbase_clicked,gevice)
-	  self.entry_passwd_dbase.connect ("key-press-event", self.on_entry_passwd_dbase_key_press,gevice)
-
-
-    def close_window (self,window):
-	    window.destroy()
-
-
-    def on_entry_passwd_dbase_key_press (self,widget,event,gevice):
-        if Gdk.keyval_name(event.keyval) == "Return":
-            self.on_button_connect_dbase_clicked(None,gevice)
-
-    def on_entry_passwd_dbase_key_press_save (self,widget,event,gevice):
-        if Gdk.keyval_name(event.keyval) == "Return":
-            self.on_button_connect_dbase_clicked_save(None,gevice)
-
-    def on_button_connect_cancel_clicked (self,button):
-        self.close_window (self.window_database)
-
-
-    def on_button_connect_dbase_clicked (self,button,gevice):
-        passwd = self.entry_passwd_dbase.get_text()
-        self.conn = self.connect(passwd,gevice)
-        
-        if (self.conn):
-            gevice.connected_to_database = True
-            self.cur = self.conn.cursor()
-            
-            self.load_data_from_database(gevice)
-
-            action_open = gevice.actiongroup_window.get_action("Open")
-            action_open.set_property ("stock-id",Gtk.STOCK_CONNECT)
-            action_open.set_property ("tooltip",_("Disconnect from database"))
-            action_open.set_property ("label",_("Disconnect"))
-            
-            self.close_window (self.window_database)
-        else:
-            gevice.connected_to_database = False
-
-    def on_button_connect_dbase_clicked_save (self,button,gevice):
-        passwd = self.entry_passwd_dbase.get_text()
-        self.conn = self.connect(passwd,gevice)
-
-	if (self.conn):
-	    gevice.connected_to_database = True
-	    self.cur = self.conn.cursor()
-
-	    self.save_data_to_database(gevice)	
-	    self.close_window (self.window_database)
-
-    def show_interface (self):
-    	self.window_database.show_all()
-
-    
-    def load_data_from_database (self,gevice):
-        gevice.gmodel.treestore.clear()
-        gevice.gmodel.treeview.set_model(None)
-        gevice.gmodel.treeview.set_model(gevice.gmodel.treestore)
-
-        self.lserial = []
-        sql = "select dispositivo.serial from dispositivo where dispositivo.serial "
-        sql = sql + "not in (select serialh from conecta order by serialh)"
-        
-        rows = self.execute_sql_select(gevice,sql)
-
-        if rows:        
-            # copy to list
-            for row in rows:
-                self.lserial.append(row[0])
-        
-            # for every serial, get your children
-            token = None
-            for serial in self.lserial:
-                if (not serial == token):
-                
-                    self.process_row (serial,None,0,gevice)
-                    token = serial
-            
-            gevice.gmodel.treeview.expand_all()        
-        
-        gevice.actiongroup_model.set_sensitive(True)
-        gevice.actiongroup_device.set_sensitive (True)
-
-    def process_row (self,serial,iterp,id_type_link,gevice):
-        sql = "select nom_disp,id_modelo,nom_tipo_disp || ' ' || nom_marca || ' ' || nom_modelo, "
-        sql = sql + "ip_disp,serial,obs_disp,ubicacion,id_rack,ptas_disp "
-        sql = sql + " from todoslosdispositivos where serial='" + serial + "'"
-        
-        row = self.execute_sql_select(gevice,sql)
-        
-        if row:
-            itern = gevice.gmodel.treestore.append(iterp)
-            gevice.gmodel.insert_new_item (itern,row,id_type_link)
-
-            sql2 = "select serialh,id_tipo_enlace from conecta where serialp='" + serial + "'"
-            rows = self.execute_sql_select(gevice,sql2)
-            
-            if rows:        
-                for children in rows:
-                    self.process_row (children[0],itern,children[1],gevice)
-
-
-    def save_data_to_database (self,gevice):
-        self.delete_conections(gevice)
-        self.delete_devices (gevice)
-        self.devices_to_connect = []
-
-        # save deviceis into database
-        gevice.gmodel.treestore.foreach(self.copy_device_to_dbase,gevice)
-        
-        for connected in self.devices_to_connect:
-            self.insert_conections(connected,gevice)
-       
-        self.conn.commit()
-
-
-    def copy_device_to_dbase (self,model,path,iter,gevice):
-        data = gevice.gmodel.treestore.get(
-            iter,
-            config.COLUMN_NAME_DEV,
-            config.COLUMN_ID_MODEL_DEV,
-            config.COLUMN_IP_DEV,
-            config.COLUMN_SERIAL_DEV,
-            config.COLUMN_OBS_DEV,
-            config.COLUMN_ID_TYPE_LINK_DEV,
-            config.COLUMN_ID_LOCATION_DEV,
-            config.COLUMN_PTAS_DISP)
-
-        self.insert_device (data,gevice)
-        
-        if (gevice.gmodel.treestore.iter_has_child(iter)):
-            iterc = gevice.gmodel.treestore.iter_children(iter)
-            
-            next = iterc
-        
-            while next:
-                child = gevice.gmodel.treestore.get(next,config.COLUMN_SERIAL_DEV,config.COLUMN_ID_TYPE_LINK_DEV)
-                self.devices_to_connect.append ("'" + data[3] + "','" + child[0] + "'" + "," + child[1])
-                next2 = gevice.gmodel.treestore.iter_next(next)
-                next = next2
-
-
-    def insert_device (self,data,gevice):        
-        sql = "insert into dispositivo (serial,id_modelo,nom_disp,obs_disp,ip_disp,id_rack,ptas_disp) "
-        sql = sql + "values ('" + data[3] + "'," + data[1] + ",'" + data[0] + "','" + data[4] + "','" + data[2] + "','" + data[6] + "','" + data[7] + "');"
-        rp = self.execute_sql_insert (gevice,sql)
-
+  def __init__ (self,dbsqlite,gevice):
+    self.dbsqlite = dbsqlite
+    self.cur = None
+    self.devices_to_connect = []
     
-    def insert_conections (self,serials,gevice):
-        sql = "insert into conecta (serialp,serialh,id_tipo_enlace) values (" + serials + ");"
-        rp = self.execute_sql_insert (gevice,sql)
-
-    
-    def delete_conections (self,gevice):
-        sql = "delete from conecta"        
-        st = self.execute_sql_delete (gevice,sql)
-
+    self.conn = self.connect (gevice)    
+
+    if (self.conn):
+      gevice.connected_to_database = True
+      self.cur = self.conn.cursor()
+
+      self.load_data_from_database(gevice)
+
+      action_open = gevice.actiongroup_window.get_action("Open")
+      action_open.set_property ("stock-id",Gtk.STOCK_CONNECT)
+      action_open.set_property ("tooltip",_("Disconnect from database"))
+      action_open.set_property ("label",_("Disconnect"))
+
+    else:
+      gevice.connected_to_database = False
+
+  def connect (self, gevice):
+    try:
+      conn = sqlite3.connect(self.dbsqlite)
+      return conn
+    except:
+      result = gevice.show_message (_("Unable to connect to the database"), Gtk.MessageType.ERROR, (Gtk.STOCK_OK, Gtk.ResponseType.OK), None)
+      return False
+
+  def execute_sql_select (self,gevice,sql):  
+    try:
+      self.cur.execute(sql)
+      rows = self.cur.fetchall()
+      return rows
+    except:
+      result = gevice.show_message (_("Unable to execute SQL: " + sql), Gtk.MessageType.ERROR, (Gtk.STOCK_OK, Gtk.ResponseType.OK), None)
+      return False
+
+  def execute_sql_insert (self,gevice,sql):
+    try:
+      self.cur.execute(sql)
+      return True
+    except:
+      result = gevice.show_message (_("Unable to execute SQL: " + sql), Gtk.MessageType.ERROR, (Gtk.STOCK_OK, Gtk.ResponseType.OK), None)
+      return False
+
+  def execute_sql_delete (self,gevice,sql):
+    try:
+      self.cur.execute(sql)
+      return True
+    except:
+      result = gevice.show_message (_("Unable to execute SQL: " + sql), Gtk.MessageType.ERROR, (Gtk.STOCK_OK, Gtk.ResponseType.OK), None)
+      return False
+
+  def execute_sql_update (self,gevice,sql):
+    try:
+      self.cur.execute(sql)
+      return True
+    except:
+      result = gevice.show_message (_("Unable to execute SQL: " + sql), Gtk.MessageType.ERROR, (Gtk.STOCK_OK, Gtk.ResponseType.OK), None)
+      return False
+
+  def load_data_from_database (self,gevice):
+    gevice.gmodel.treestore.clear()
+    gevice.gmodel.treeview.set_model(None)
+    gevice.gmodel.treeview.set_model(gevice.gmodel.treestore)
+
+    self.lserial = []
+    sql = "select dispositivo.serial from dispositivo where dispositivo.serial "
+    sql = sql + "not in (select serialh from conecta order by serialh)"
+
+    rows = self.execute_sql_select(gevice,sql)
+
+    if rows:
+      # copy to list
+      for row in rows:
+        self.lserial.append(row[0])
+
+      # for every serial, get your children
+      token = None
+      for serial in self.lserial:
+        if (not serial == token):
+          self.process_row (serial,None,0,gevice)
+          token = serial
+
+      gevice.gmodel.treeview.expand_all()        
+
+    gevice.actiongroup_model.set_sensitive(True)
+    gevice.actiongroup_device.set_sensitive (True)
+
+  def process_row (self,serial,iterp,id_type_link,gevice):
+    sql = "select nom_disp,id_modelo,nom_tipo_disp || ' ' || nom_marca || ' ' || nom_modelo, "
+    sql = sql + "ip_disp,serial,obs_disp,ubicacion,id_rack,ptas_disp "
+    sql = sql + " from todoslosdispositivos where serial='" + serial + "'"
+
+    row = self.execute_sql_select(gevice,sql)
+
+    if row:
+      itern = gevice.gmodel.treestore.append(iterp)
+      gevice.gmodel.insert_new_item (itern,row,id_type_link)
+
+      sql2 = "select serialh,id_tipo_enlace from conecta where serialp='" + serial + "'"
+      rows = self.execute_sql_select(gevice,sql2)
+
+      if rows:        
+        for children in rows:
+          self.process_row (children[0],itern,children[1],gevice)
+
+  def save_data_to_database (self,gevice):
+    self.delete_conections(gevice)
+    self.delete_devices (gevice)
+    self.devices_to_connect = []
+
+    # save deviceis into database
+    gevice.gmodel.treestore.foreach(self.copy_device_to_dbase,gevice)
+
+    for connected in self.devices_to_connect:
+      self.insert_conections(connected,gevice)
+
+    self.conn.commit()
+
+  def copy_device_to_dbase (self,model,path,iter,gevice):
+    data = gevice.gmodel.treestore.get(
+      iter,
+      config.COLUMN_NAME_DEV,
+      config.COLUMN_ID_MODEL_DEV,
+      config.COLUMN_IP_DEV,
+      config.COLUMN_SERIAL_DEV,
+      config.COLUMN_OBS_DEV,
+      config.COLUMN_ID_TYPE_LINK_DEV,
+      config.COLUMN_ID_LOCATION_DEV,
+      config.COLUMN_PTAS_DISP)
+
+    self.insert_device (data,gevice)
+
+    if (gevice.gmodel.treestore.iter_has_child(iter)):
+      iterc = gevice.gmodel.treestore.iter_children(iter)
+      next = iterc
+      
+      while next:
+        child = gevice.gmodel.treestore.get(next,config.COLUMN_SERIAL_DEV,config.COLUMN_ID_TYPE_LINK_DEV)
+        self.devices_to_connect.append ("'" + data[3] + "','" + child[0] + "'" + "," + child[1])
+        next2 = gevice.gmodel.treestore.iter_next(next)
+        next = next2
+
+  def insert_device (self,data,gevice):        
+    sql = "insert into dispositivo (serial,id_modelo,nom_disp,obs_disp,ip_disp,id_rack,ptas_disp) "
+    sql = sql + "values ('" + data[3] + "'," + data[1] + ",'" + data[0] + "','" + data[4] + "','" + data[2] + "','" + data[6] + "','" + data[7] + "');"
+    rp = self.execute_sql_insert (gevice,sql)
+
+  def insert_conections (self,serials,gevice):
+    sql = "insert into conecta (serialp,serialh,id_tipo_enlace) values (" + serials + ");"
+    rp = self.execute_sql_insert (gevice,sql)
+
+  def delete_conections (self,gevice):
+    sql = "delete from conecta"        
+    st = self.execute_sql_delete (gevice,sql)
+
+  def delete_devices (self,gevice):
+    sql = "delete from dispositivo"
+    st = self.execute_sql_delete (gevice,sql)
+
+  def get_list_of_models (self,gevice):
+    liststore = Gtk.ListStore(str,int)
+
+    sql = "select nom_tipo_disp || ' ' || nom_marca || ' ' || nom_modelo,modelo.id_modelo "
+    sql = sql + "from modelo inner join tipo_disp on modelo.id_tipo_disp = tipo_disp.id_tipo_disp "
+    sql = sql + "inner join marca on modelo.id_marca = marca.id_marca order by "
+    sql = sql + "nom_tipo_disp,nom_marca,nom_modelo"
+
+    rows = self.execute_sql_select(gevice,sql)
+
+    if rows:
+      for row in rows:
+        iter = liststore.append ()
+        liststore.set_value (iter, config.COLUMN_NAME_MODEL_DEV2,str(row[0]))
+        liststore.set_value (iter, config.COLUMN_ID_MODEL_DEV2,int(row[1]))
+        
+      return liststore
+    else:
+      return False
+
+  def get_list_of_links (self,gevice):
+    liststore = Gtk.ListStore(str,int)
 
-    def delete_devices (self,gevice):
-        sql = "delete from dispositivo"
-        st = self.execute_sql_delete (gevice,sql)
-
-
-    def get_list_of_models (self,gevice):
-        liststore = Gtk.ListStore(str,int)
-        
-        sql = "select nom_tipo_disp || ' ' || nom_marca || ' ' || nom_modelo,modelo.id_modelo "
-        sql = sql + "from modelo inner join tipo_disp on modelo.id_tipo_disp = tipo_disp.id_tipo_disp "
-        sql = sql + "inner join marca on modelo.id_marca = marca.id_marca order by "
-        sql = sql + "nom_tipo_disp,nom_marca,nom_modelo"
-        
-        rows = self.execute_sql_select(gevice,sql)
-        
-        if rows:
-            for row in rows:
-                iter = liststore.append ()
-                liststore.set_value (iter, config.COLUMN_NAME_MODEL_DEV2,str(row[0]))
-		liststore.set_value (iter, config.COLUMN_ID_MODEL_DEV2,int(row[1]))
-        
-            return liststore
-        else:
-            return False
-    
-    
-    def get_list_of_links (self,gevice):
-        liststore = Gtk.ListStore(str,int)
-            
-        sql = "select nom_tipo_enlace,id_tipo_enlace from tipo_enlace"
-        
-        rows = self.execute_sql_select(gevice,sql)
-        
-        if rows:
-            for row in rows:
-                iter = liststore.append ()
-                liststore.set_value (iter,config.COLUMN_NAME_TYPE_LINK_DEV2,str(row[0]))
-		liststore.set_value (iter,config.COLUMN_ID_TYPE_LINK_DEV2,int(row[1]))
-        
-            return liststore
-        else:
-            return False
-
-
-    def get_list_of_location (self,gevice):
-        liststore = Gtk.ListStore(str,int)
-        
-        sql = "select '[' || campus.nom_campus || '][' || edificio.nom_edif || '][' || nivel.nom_nivel || '][' || rack.detalle || ']' as location, rack.id_rack "        
-        sql = sql + "from rack "
-        sql = sql + "join edificio on rack.id_edif = edificio.id_edif "
-        sql = sql + "join nivel on rack.id_nivel = nivel.id_nivel "
-        sql = sql + "join campus on edificio.id_campus = campus.id_campus "
-        sql = sql + "order by campus.nom_campus,edificio.nom_edif,nivel.nom_nivel "
-
-        rows = self.execute_sql_select(gevice,sql)
-		
-        if rows:
-            for row in rows:
-                iter = liststore.append ()
-                liststore.set_value (iter,config.COLUMN_LOCATION_DEV2,str(row[0]))
-		liststore.set_value (iter,config.COLUMN_ID_LOCATION_DEV2,int(row[1]))
-
-            return liststore
-        else:
-            return False
-
-    def get_list_of_data (self,gevice,sql):
-        liststore = Gtk.ListStore(str,int)
-
-        rows = self.execute_sql_select(gevice,sql)
-        
-        if rows:
-            for row in rows:
-                iter = liststore.append ()
-                liststore.set_value (iter,0,str(row[0]))
-		liststore.set_value (iter,1,int(row[1]))
-                           
-            return liststore
-        else:
-            return False
+    sql = "select nom_tipo_enlace,id_tipo_enlace from tipo_enlace"
+
+    rows = self.execute_sql_select(gevice,sql)
+
+    if rows:
+      for row in rows:
+        iter = liststore.append ()
+        liststore.set_value (iter,config.COLUMN_NAME_TYPE_LINK_DEV2,str(row[0]))
+        liststore.set_value (iter,config.COLUMN_ID_TYPE_LINK_DEV2,int(row[1]))
+
+      return liststore
+    else:
+      return False
+
+  def get_list_of_location (self,gevice):
+    liststore = Gtk.ListStore(str,int)
+
+    sql = "select '[' || campus.nom_campus || '][' || edificio.nom_edif || '][' || nivel.nom_nivel || '][' || rack.detalle || ']' as location, rack.id_rack "        
+    sql = sql + "from rack "
+    sql = sql + "join edificio on rack.id_edif = edificio.id_edif "
+    sql = sql + "join nivel on rack.id_nivel = nivel.id_nivel "
+    sql = sql + "join campus on edificio.id_campus = campus.id_campus "
+    sql = sql + "order by campus.nom_campus,edificio.nom_edif,nivel.nom_nivel "
+
+    rows = self.execute_sql_select(gevice,sql)
+
+    if rows:
+      for row in rows:
+        iter = liststore.append ()
+        liststore.set_value (iter,config.COLUMN_LOCATION_DEV2,str(row[0]))
+        liststore.set_value (iter,config.COLUMN_ID_LOCATION_DEV2,int(row[1]))
+
+      return liststore
+    else:
+      return False
+
+  def get_list_of_data (self,gevice,sql):
+    liststore = Gtk.ListStore(str,int)
+
+    rows = self.execute_sql_select(gevice,sql)
+
+    if rows:
+      for row in rows:
+        iter = liststore.append ()
+        liststore.set_value (iter,0,str(row[0]))
+        liststore.set_value (iter,1,int(row[1]))
+
+      return liststore
+    else:
+      return False
diff --git a/src/gevicedevice.py b/src/gevicedevice.py
index 49c8711..ec91f8b 100644
--- a/src/gevicedevice.py
+++ b/src/gevicedevice.py
@@ -10,250 +10,244 @@ gettext.bind_textdomain_codeset (config.PACKAGE, "UTF-8");
 from gettext import gettext as _
 
 class GeviceDevice:
-    def __init__ (self):
-        self.action = "add"
-        self.exists_serial = False
-        self.exists_serial_name = ""
-        
-        self.window_device = None
-        self.entry_name_device = None
-        self.entry_ip_device = None
-        self.entry_comment_device = None
-        self.entry_serial_device = None
-        self.entry_ports = None
-        self.combo_link = None
-        self.combo_model = None
-        self.combo_location = None
-        self.button_cancel_device = None
-        self.button_accept_device = None
-
-    def add_device (self):
-        self.action = "add"
-        
-        self.entry_serial_device.set_sensitive (True)
-        
-        self.entry_name_device.set_text("")
-        self.entry_ip_device.set_text("127.0.0.1")
-        self.entry_serial_device.set_text("")
-        self.entry_ports.set_text("")
-        self.entry_comment_device.set_text("")
-        self.combo_model.set_active(0)
-        self.combo_link.set_active(0)
-        self.combo_location.set_active(0)
-        self.window_device.set_title (_("New device"))
-
-    def modify_device (self,gevice):
-        self.action = "mod"       
-        
-        self.entry_serial_device.set_sensitive (False)
-        
-        self.index_combo = 0
-        self.index_link = 0
-        self.index_location = 0
-        
-        data = gevice.gmodel.get_data_of_device_from_model(gevice.gmodel.treeview)
-        
-        self.id_model = data[1]
-        self.id_link = data[5]
-        self.id_location = data[6]
-        
-        
-        models = gevice.gdbase.get_list_of_models (gevice)
-        models.foreach (self.get_index_combo_model,gevice)
-        
-        links = gevice.gdbase.get_list_of_links (gevice)
-        links.foreach (self.get_index_combo_link,gevice)
-        
-        location = gevice.gdbase.get_list_of_location (gevice)
-        location.foreach (self.get_index_combo_location,gevice)        
-               
-        self.entry_name_device.set_text(data[0])
-        self.combo_model.set_active(self.index_combo)
-        self.entry_ip_device.set_text(data[2])
-        self.entry_serial_device.set_text(data[3])
-        self.entry_comment_device.set_text(data[4])
-        self.entry_ports.set_text(data[7])
-        self.combo_link.set_active(self.index_link)
-        self.combo_location.set_active(self.index_location)
-        
-        self.window_device.set_title (_("Modify device"))
+  def __init__ (self):
+    self.action = "add"
+    self.exists_serial = False
+    self.exists_serial_name = ""
+
+    self.window_device = None
+    self.entry_name_device = None
+    self.entry_ip_device = None
+    self.entry_comment_device = None
+    self.entry_serial_device = None
+    self.entry_ports = None
+    self.combo_link = None
+    self.combo_model = None
+    self.combo_location = None
+    self.button_cancel_device = None
+    self.button_accept_device = None
+
+  def add_device (self):
+    self.action = "add"
+
+    self.entry_serial_device.set_sensitive (True)
+
+    self.entry_name_device.set_text("")
+    self.entry_ip_device.set_text("127.0.0.1")
+    self.entry_serial_device.set_text("")
+    self.entry_ports.set_text("")
+    self.entry_comment_device.set_text("")
+    self.combo_model.set_active(0)
+    self.combo_link.set_active(0)
+    self.combo_location.set_active(0)
+    self.window_device.set_title (_("New device"))
+
+  def modify_device (self,gevice):
+    self.action = "mod"       
+
+    self.entry_serial_device.set_sensitive (False)
+
+    self.index_combo = 0
+    self.index_link = 0
+    self.index_location = 0
+
+    data = gevice.gmodel.get_data_of_device_from_model(gevice.gmodel.treeview)
+
+    self.id_model = data[1]
+    self.id_link = data[5]
+    self.id_location = data[6]
+
+    models = gevice.gdbase.get_list_of_models (gevice)
+    models.foreach (self.get_index_combo_model,gevice)
+
+    links = gevice.gdbase.get_list_of_links (gevice)
+    links.foreach (self.get_index_combo_link,gevice)
+
+    location = gevice.gdbase.get_list_of_location (gevice)
+    location.foreach (self.get_index_combo_location,gevice)        
+
+    self.entry_name_device.set_text(data[0])
+    self.combo_model.set_active(self.index_combo)
+    self.entry_ip_device.set_text(data[2])
+    self.entry_serial_device.set_text(data[3])
+    self.entry_comment_device.set_text(data[4])
+    self.entry_ports.set_text(data[7])
+    self.combo_link.set_active(self.index_link)
+    self.combo_location.set_active(self.index_location)
+
+    self.window_device.set_title (_("Modify device"))
     
-    def get_index_combo_model (self,model,path,iter,gevice):
-        data = model.get (iter,
-            config.COLUMN_ID_MODEL_DEV2)
-                
-        if (int(data[0]) == int(self.id_model)):
-            return True
-        
-        self.index_combo = self.index_combo + 1
-
-
-    def get_index_combo_link (self,model,path,iter,gevice):
-        data = model.get (iter,
-            config.COLUMN_ID_TYPE_LINK_DEV2)
-                
-        if (int(data[0]) == int(self.id_link)):
-            return True
-        
-        self.index_link = self.index_link + 1
-
-    def get_index_combo_location (self,model,path,iter,gevice):
-        data = model.get (iter,
-            config.COLUMN_ID_LOCATION_DEV2)
-                
-        if (int(data[0]) == int(self.id_location)):
-            return True
-        
-        self.index_location = self.index_location + 1
-
-
-    def remove_device (self,gevice):
-        self.action = "del"
-        
-        data = gevice.gmodel.get_data_of_device_from_model(gevice.gmodel.treeview)
-	
-	result = gevice.show_message (_("Do you want to remove: ") + data[0],
-	  None,
-	  (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_YES, Gtk.ResponseType.YES),
-	  None)
-
-	if result == Gtk.ResponseType.YES:
-            i = gevice.gmodel.get_iter_selected (gevice.gmodel.treeview)
-            gevice.gmodel.treestore.remove(i["iter"])
-
-
-    def load_interface (self,gevice):
-	builder = Gtk.Builder()
-	builder.add_from_file(os.path.join (config.UIDIR, "device.xml"))
-	
-        self.window_device = builder.get_object ("window_device")
-        self.entry_name_device = builder.get_object ("entry_name_device")
-        self.entry_ip_device = builder.get_object ("entry_ip_device")
-        self.entry_comment_device = builder.get_object ("entry_comment_device")
-        self.entry_serial_device = builder.get_object ("entry_serial_device")
-        self.entry_ports = builder.get_object ("entry_ports")
-        self.combo_link = builder.get_object ("combo_link")
-        self.combo_location = builder.get_object ("combo_location")
-        self.combo_model = builder.get_object ("combo_model")
-        self.button_cancel_device = builder.get_object ("button_cancel_device")
-        self.button_accept_device = builder.get_object ("button_accept_device")
-
-        # signals window device
-        self.window_device.connect ("delete-event",self.on_window_device_delete_event)
-        self.button_cancel_device.connect ("clicked",self.on_button_cancel_device_clicked)
-        self.button_accept_device.connect ("clicked",self.on_button_accept_device_clicked,gevice)
-       
-	cell = Gtk.CellRendererText()
-        self.combo_model.pack_start(cell,True)
-        self.combo_model.add_attribute(cell, 'text', 0)
-        gevice.list_models = gevice.gdbase.get_list_of_models (gevice)
-        self.combo_model.set_model (gevice.list_models)
-        
-	cell = Gtk.CellRendererText()
-        self.combo_link.pack_start(cell,True)
-        self.combo_link.add_attribute(cell, 'text', 0)
-        gevice.list_links = gevice.gdbase.get_list_of_links (gevice)
-        self.combo_link.set_model (gevice.list_links)
-        
-	cell = Gtk.CellRendererText()
-        self.combo_location.pack_start(cell,True)
-        self.combo_location.add_attribute(cell, 'text', 0)
-        gevice.list_location = gevice.gdbase.get_list_of_location (gevice)
-        self.combo_location.set_model (gevice.list_location)        
-	
-
-    def show_interface (self):
-        self.window_device.show_all ()
-
-    def close_window (self,window):
-        window.destroy()
-
-    def on_button_cancel_device_clicked (self,button):
-        self.close_window (self.window_device)
-
-    def on_window_device_delete_event (self,window,event):
-        self.close_window (window)
-
-    def verify_serial(self,model,path,iter,serial):
-        data = model.get(
-            iter,
-            config.COLUMN_NAME_DEV,
-            config.COLUMN_ID_MODEL_DEV,
-            config.COLUMN_IP_DEV,
-            config.COLUMN_SERIAL_DEV,
-            config.COLUMN_OBS_DEV,
-            config.COLUMN_ID_TYPE_LINK_DEV)
-        
-        if (serial.strip() == data[3].strip()):
-            self.exists_serial = True
-            self.exists_serial_name = data[0]
-            return
-            
-
-    def on_button_accept_device_clicked (self,button,gevice):        
-        alldata = True
-        
-        serial = self.entry_serial_device.get_text()
-        name = self.entry_name_device.get_text()
-        ip = self.entry_ip_device.get_text()        
-        comment = self.entry_comment_device.get_text()
-        ports = self.entry_ports.get_text()
-        
-        if (not name.strip()):
-            alldata = False
-	    result = gevice.show_message (_("Enter name of device"),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      self.window_device)	      
-        elif (not serial.strip()):
-            alldata = False
-	    result = gevice.show_message (_("Enter serial number of device"),
-	      None,
-	      (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-	      self.window_device)
-
-        gevice.gmodel.treestore.foreach(self.verify_serial,serial)
-
-        if self.action == "add":
-            if (self.exists_serial):
-                alldata = False
-		result = gevice.show_message (_("Serial number exist, view device: "  + self.exists_serial_name),
-		  None,
-		  (Gtk.STOCK_OK, Gtk.ResponseType.OK),
-		  self.window_device)
-
-        if alldata:        
-            iter_model = self.combo_model.get_active_iter()
-            id_model = gevice.list_models.get_value(iter_model,config.COLUMN_ID_MODEL_DEV2)
-            name_model = gevice.list_models.get_value(iter_model,config.COLUMN_NAME_MODEL_DEV2)
-
-            iter_type_link = self.combo_link.get_active_iter()
-            id_link = gevice.list_links.get_value(iter_type_link,config.COLUMN_ID_TYPE_LINK_DEV2)
-            
-            iter_type_location = self.combo_location.get_active_iter()
-            id_location = gevice.list_location.get_value(iter_type_location,config.COLUMN_ID_LOCATION_DEV2)            
-            name_location = gevice.list_location.get_value(iter_type_location,config.COLUMN_LOCATION_DEV2)
-
-            i = gevice.gmodel.get_iter_selected(gevice.gmodel.treeview)
-
-            if self.action == "add":
-                newiter = gevice.gmodel.treestore.append(i["iter"])
-            else:
-                newiter = i["iter"]
-
-            gevice.gmodel.treestore.set_value (newiter, config.COLUMN_NAME_DEV,str(name.strip()))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_ID_MODEL_DEV,str(id_model))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_NAME_MODEL_DEV,str(name_model))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_IP_DEV,str(ip))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_SERIAL_DEV,str(serial))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_OBS_DEV,str(comment))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_LOCATION,str(name_location))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_ID_LOCATION_DEV,str(id_location))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_ID_TYPE_LINK_DEV,str(id_link))
-	    gevice.gmodel.treestore.set_value (newiter, config.COLUMN_PTAS_DISP,str(ports))
-
-            if i["path"]:
-                gevice.gmodel.treeview.expand_to_path(i["path"][0])
-
-            self.close_window(self.window_device)
-            gevice.actiongroup_model.set_sensitive (True)
+  def get_index_combo_model (self,model,path,iter,gevice):
+    data = model.get (iter,
+      config.COLUMN_ID_MODEL_DEV2)
+
+    if (int(data[0]) == int(self.id_model)):
+      return True
+
+    self.index_combo = self.index_combo + 1
+
+  def get_index_combo_link (self,model,path,iter,gevice):
+    data = model.get (iter,
+      config.COLUMN_ID_TYPE_LINK_DEV2)
+
+    if (int(data[0]) == int(self.id_link)):
+      return True
+
+    self.index_link = self.index_link + 1
+
+  def get_index_combo_location (self,model,path,iter,gevice):
+    data = model.get (iter,
+      config.COLUMN_ID_LOCATION_DEV2)
+
+    if (int(data[0]) == int(self.id_location)):
+      return True
+
+    self.index_location = self.index_location + 1
+
+  def remove_device (self,gevice):
+    self.action = "del"
+
+    data = gevice.gmodel.get_data_of_device_from_model(gevice.gmodel.treeview)
+
+    result = gevice.show_message (_("Do you want to remove: ") + data[0],
+      Gtk.MessageType.QUESTION,
+      (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_YES, Gtk.ResponseType.YES),
+      None)
+
+    if result == Gtk.ResponseType.YES:
+      i = gevice.gmodel.get_iter_selected (gevice.gmodel.treeview)
+      gevice.gmodel.treestore.remove(i["iter"])
+
+  def load_interface (self,gevice):
+    builder = Gtk.Builder()
+    builder.add_from_file(os.path.join (config.UIDIR, "device.xml"))
+
+    self.window_device = builder.get_object ("window_device")
+    self.entry_name_device = builder.get_object ("entry_name_device")
+    self.entry_ip_device = builder.get_object ("entry_ip_device")
+    self.entry_comment_device = builder.get_object ("entry_comment_device")
+    self.entry_serial_device = builder.get_object ("entry_serial_device")
+    self.entry_ports = builder.get_object ("entry_ports")
+    self.combo_link = builder.get_object ("combo_link")
+    self.combo_location = builder.get_object ("combo_location")
+    self.combo_model = builder.get_object ("combo_model")
+    self.button_cancel_device = builder.get_object ("button_cancel_device")
+    self.button_accept_device = builder.get_object ("button_accept_device")
+
+    # signals window device
+    self.window_device.connect ("delete-event",self.on_window_device_delete_event)
+    self.button_cancel_device.connect ("clicked",self.on_button_cancel_device_clicked)
+    self.button_accept_device.connect ("clicked",self.on_button_accept_device_clicked,gevice)
+
+    cell = Gtk.CellRendererText()
+    self.combo_model.pack_start(cell,True)
+    self.combo_model.add_attribute(cell, 'text', 0)
+    gevice.list_models = gevice.gdbase.get_list_of_models (gevice)
+    self.combo_model.set_model (gevice.list_models)
+
+    cell = Gtk.CellRendererText()
+    self.combo_link.pack_start(cell,True)
+    self.combo_link.add_attribute(cell, 'text', 0)
+    gevice.list_links = gevice.gdbase.get_list_of_links (gevice)
+    self.combo_link.set_model (gevice.list_links)
+
+    cell = Gtk.CellRendererText()
+    self.combo_location.pack_start(cell,True)
+    self.combo_location.add_attribute(cell, 'text', 0)
+    gevice.list_location = gevice.gdbase.get_list_of_location (gevice)
+    self.combo_location.set_model (gevice.list_location)        
+
+  def show_interface (self):
+    self.window_device.show_all ()
+
+  def close_window (self,window):
+    window.destroy()
+
+  def on_button_cancel_device_clicked (self,button):
+    self.close_window (self.window_device)
+
+  def on_window_device_delete_event (self,window,event):
+    self.close_window (window)
+
+  def verify_serial(self,model,path,iter,serial):
+    data = model.get(
+      iter,
+      config.COLUMN_NAME_DEV,
+      config.COLUMN_ID_MODEL_DEV,
+      config.COLUMN_IP_DEV,
+      config.COLUMN_SERIAL_DEV,
+      config.COLUMN_OBS_DEV,
+      config.COLUMN_ID_TYPE_LINK_DEV)
+
+    if (serial.strip() == data[3].strip()):
+      self.exists_serial = True
+      self.exists_serial_name = data[0]
+      return
+
+  def on_button_accept_device_clicked (self,button,gevice):        
+    alldata = True
+
+    serial = self.entry_serial_device.get_text()
+    name = self.entry_name_device.get_text()
+    ip = self.entry_ip_device.get_text()        
+    comment = self.entry_comment_device.get_text()
+    ports = self.entry_ports.get_text()
+
+    if (not name.strip()):
+      alldata = False
+      result = gevice.show_message (_("Enter name of device"),
+        None,
+        (Gtk.STOCK_OK, Gtk.ResponseType.OK),
+        self.window_device)	      
+    elif (not serial.strip()):
+      alldata = False
+      result = gevice.show_message (_("Enter serial number of device"),
+        None,
+        (Gtk.STOCK_OK, Gtk.ResponseType.OK),
+        self.window_device)
+
+    gevice.gmodel.treestore.foreach(self.verify_serial,serial)
+
+    if self.action == "add":
+      if (self.exists_serial):
+        alldata = False
+        result = gevice.show_message (_("Serial number exist, view device: "  + self.exists_serial_name),
+          None,
+          (Gtk.STOCK_OK, Gtk.ResponseType.OK),
+          self.window_device)
+
+    if alldata:        
+      iter_model = self.combo_model.get_active_iter()
+      id_model = gevice.list_models.get_value(iter_model,config.COLUMN_ID_MODEL_DEV2)
+      name_model = gevice.list_models.get_value(iter_model,config.COLUMN_NAME_MODEL_DEV2)
+
+      iter_type_link = self.combo_link.get_active_iter()
+      id_link = gevice.list_links.get_value(iter_type_link,config.COLUMN_ID_TYPE_LINK_DEV2)
+
+      iter_type_location = self.combo_location.get_active_iter()
+      id_location = gevice.list_location.get_value(iter_type_location,config.COLUMN_ID_LOCATION_DEV2)            
+      name_location = gevice.list_location.get_value(iter_type_location,config.COLUMN_LOCATION_DEV2)
+
+      i = gevice.gmodel.get_iter_selected(gevice.gmodel.treeview)
+
+      if self.action == "add":
+        newiter = gevice.gmodel.treestore.append(i["iter"])
+      else:
+        newiter = i["iter"]
+
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_NAME_DEV,str(name.strip()))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_ID_MODEL_DEV,str(id_model))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_NAME_MODEL_DEV,str(name_model))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_IP_DEV,str(ip))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_SERIAL_DEV,str(serial))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_OBS_DEV,str(comment))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_LOCATION,str(name_location))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_ID_LOCATION_DEV,str(id_location))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_ID_TYPE_LINK_DEV,str(id_link))
+      gevice.gmodel.treestore.set_value (newiter, config.COLUMN_PTAS_DISP,str(ports))
+
+      if i["path"]:
+        gevice.gmodel.treeview.expand_to_path(i["path"][0])
+
+      self.close_window(self.window_device)
+      gevice.actiongroup_model.set_sensitive (True)
diff --git a/src/gevicemodel.py b/src/gevicemodel.py
index db59c06..3c350fd 100644
--- a/src/gevicemodel.py
+++ b/src/gevicemodel.py
@@ -9,182 +9,179 @@ gettext.bind_textdomain_codeset (config.PACKAGE, "UTF-8");
 from gettext import gettext as _
 
 class GeviceModel:
-    def __init__ (self,gevice):
-        self.treestore = Gtk.TreeStore(str,str,str,str,str,str,str,str,str,str)
-        
-        self.treeview = Gtk.TreeView (model=self.treestore)
-        self.treeview.set_rules_hint (True)
-        self.treeview.set_reorderable (True)
-        
-        # create columns
-        col = Gtk.TreeViewColumn (_("Device"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_NAME_DEV)
-
-        col = Gtk.TreeViewColumn (_("Model"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_NAME_MODEL_DEV)
-
-        col = Gtk.TreeViewColumn (_("IP"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_IP_DEV)
-
-        col = Gtk.TreeViewColumn (_("Serial"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_SERIAL_DEV)
-
-        col = Gtk.TreeViewColumn (_("Comments"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_OBS_DEV)
-
-        col = Gtk.TreeViewColumn (_("Location"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_LOCATION)        
-
-        col = Gtk.TreeViewColumn (_("Ports Availables"))
-        col.set_resizable (True)
-        self.treeview.append_column (col)
-        cell =  Gtk.CellRendererText()
-        col.pack_start (cell,True)
-        col.add_attribute (cell,"text",config.COLUMN_PTAS_DISP)        
-
-        selection = self.treeview.get_selection()
-        selection.connect ("changed",self.on_device_selection_changed,gevice)
-
-        return
-
-    def insert_new_item (self,newiter,row,id_type_link):
-      self.treestore.set_value (newiter, config.COLUMN_NAME_DEV, str(row[0][0]))
-      self.treestore.set_value (newiter, config.COLUMN_ID_MODEL_DEV, str(row[0][1]))
-      self.treestore.set_value (newiter, config.COLUMN_NAME_MODEL_DEV, str(row[0][2]))
-      self.treestore.set_value (newiter, config.COLUMN_IP_DEV, str(row[0][3]))
-      self.treestore.set_value (newiter, config.COLUMN_SERIAL_DEV, str(row[0][4]))
-      self.treestore.set_value (newiter, config.COLUMN_OBS_DEV, str(row[0][5]))
-      self.treestore.set_value (newiter, config.COLUMN_LOCATION, str(row[0][6]))
-      self.treestore.set_value (newiter, config.COLUMN_ID_LOCATION_DEV, str(row[0][7]))
-      self.treestore.set_value (newiter, config.COLUMN_PTAS_DISP, str(row[0][8]))
-      self.treestore.set_value (newiter, config.COLUMN_ID_TYPE_LINK_DEV, str(id_type_link))
-    
-    def on_device_selection_changed (self,selection,gevice):
-        model,iter = selection.get_selected()
-
-        if (iter):
-            gevice.actiongroup_device.set_sensitive (True)
-        else:
-            gevice.actiongroup_device.set_sensitive (False)
-
-    def get_iter_selected (self,treeview):
-        treeselection = treeview.get_selection()
-        model,iter = treeselection.get_selected()
-
-        model,path = treeselection.get_selected_rows()
-
-        selected = {"iter":iter,"path":path,"model":model}
-
-        return selected
-
-    def get_data_of_device_from_model(self,treeview):
-        i = self.get_iter_selected (treeview)
-
-        data = i["model"].get(i["iter"],
-            config.COLUMN_NAME_DEV,
-            config.COLUMN_ID_MODEL_DEV,
-            config.COLUMN_IP_DEV,  
-            config.COLUMN_SERIAL_DEV,
-            config.COLUMN_OBS_DEV,
-            config.COLUMN_ID_TYPE_LINK_DEV,
-            config.COLUMN_ID_LOCATION_DEV,
-            config.COLUMN_PTAS_DISP)
-
-        return data
-
-
-    def get_model_from_device (self,treestore,path,iter):
-        name_model,type = treestore.get(iter,
-            config.COLUMN_MODEL,
-            config.COLUMN_TYPE)	
-
-        if int(self.selected) == int(type):
-            l_tmp = self.lists_m
-
-            it = l_tmp.get_iter_first()
-
-            if it:
-                exist = False
-                while (it):
-                    tmp = l_tmp.get(it,0)
-
-                    if tmp[0] == name_model:
-                        exist = True
-                        break
-                    else:
-                        it = l_tmp.iter_next(it)
-
-                if not exist:
-                    iter = self.lists_m.append ()
-                    self.lists_m.set (iter,0,name_model)
-            else:
-                iter = self.lists_m.append ()
-                self.lists_m.set (iter,0,name_model)
-
-    def get_data_of_device_from_key (self,key,gevice):
-        "return data of key"
-
-        iter = gevice.list_devices.get_iter_first()
-
-        while (iter):
-            id = gevice.list_devices.get_value(iter,config.COLUMN_DEVICE)
-
-            if str(key) == str(id):
-                name_type = gevice.list_devices.get_value(iter,config.COLUMN_NAME_DEVICE)
-                pix =  gevice.list_devices.get_value(iter,config.COLUMN_PIXBUF)
+  def __init__ (self,gevice):
+    self.treestore = Gtk.TreeStore(str,str,str,str,str,str,str,str,str,str)
+
+    self.treeview = Gtk.TreeView (model=self.treestore)
+    self.treeview.set_rules_hint (True)
+    self.treeview.set_reorderable (True)
+
+    # create columns
+    col = Gtk.TreeViewColumn (_("Device"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_NAME_DEV)
+
+    col = Gtk.TreeViewColumn (_("Model"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_NAME_MODEL_DEV)
+
+    col = Gtk.TreeViewColumn (_("IP"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_IP_DEV)
+
+    col = Gtk.TreeViewColumn (_("Serial"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_SERIAL_DEV)
+
+    col = Gtk.TreeViewColumn (_("Comments"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_OBS_DEV)
+
+    col = Gtk.TreeViewColumn (_("Location"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_LOCATION)        
+
+    col = Gtk.TreeViewColumn (_("Ports Availables"))
+    col.set_resizable (True)
+    self.treeview.append_column (col)
+    cell =  Gtk.CellRendererText()
+    col.pack_start (cell,True)
+    col.add_attribute (cell,"text",config.COLUMN_PTAS_DISP)        
+
+    selection = self.treeview.get_selection()
+    selection.connect ("changed",self.on_device_selection_changed,gevice)
+
+    return
+
+  def insert_new_item (self,newiter,row,id_type_link):
+    self.treestore.set_value (newiter, config.COLUMN_NAME_DEV, str(row[0][0]))
+    self.treestore.set_value (newiter, config.COLUMN_ID_MODEL_DEV, str(row[0][1]))
+    self.treestore.set_value (newiter, config.COLUMN_NAME_MODEL_DEV, str(row[0][2]))
+    self.treestore.set_value (newiter, config.COLUMN_IP_DEV, str(row[0][3]))
+    self.treestore.set_value (newiter, config.COLUMN_SERIAL_DEV, str(row[0][4]))
+    self.treestore.set_value (newiter, config.COLUMN_OBS_DEV, str(row[0][5]))
+    self.treestore.set_value (newiter, config.COLUMN_LOCATION, str(row[0][6]))
+    self.treestore.set_value (newiter, config.COLUMN_ID_LOCATION_DEV, str(row[0][7]))
+    self.treestore.set_value (newiter, config.COLUMN_PTAS_DISP, str(row[0][8]))
+    self.treestore.set_value (newiter, config.COLUMN_ID_TYPE_LINK_DEV, str(id_type_link))
+
+  def on_device_selection_changed (self,selection,gevice):
+    model,iter = selection.get_selected()
+
+    if (iter):
+      gevice.actiongroup_device.set_sensitive (True)
+    else:
+      gevice.actiongroup_device.set_sensitive (False)
+
+  def get_iter_selected (self,treeview):
+    treeselection = treeview.get_selection()
+    model,iter = treeselection.get_selected()
+
+    model,path = treeselection.get_selected_rows()
+    selected = {"iter":iter,"path":path,"model":model}
+
+    return selected
+
+  def get_data_of_device_from_model(self,treeview):
+    i = self.get_iter_selected (treeview)
+
+    data = i["model"].get(i["iter"],
+      config.COLUMN_NAME_DEV,
+      config.COLUMN_ID_MODEL_DEV,
+      config.COLUMN_IP_DEV,  
+      config.COLUMN_SERIAL_DEV,
+      config.COLUMN_OBS_DEV,
+      config.COLUMN_ID_TYPE_LINK_DEV,
+      config.COLUMN_ID_LOCATION_DEV,
+      config.COLUMN_PTAS_DISP)
+
+    return data
+
+  def get_model_from_device (self,treestore,path,iter):
+    name_model,type = treestore.get(iter,
+      config.COLUMN_MODEL,
+      config.COLUMN_TYPE)	
+
+    if int(self.selected) == int(type):
+      l_tmp = self.lists_m
+
+      it = l_tmp.get_iter_first()
+
+      if it:
+        exist = False
+        while (it):
+          tmp = l_tmp.get(it,0)
+
+          if tmp[0] == name_model:
+            exist = True
+            break
+          else:
+              it = l_tmp.iter_next(it)
+
+        if not exist:
+          iter = self.lists_m.append ()
+          self.lists_m.set (iter,0,name_model)
+      else:
+        iter = self.lists_m.append ()
+        self.lists_m.set (iter,0,name_model)
+
+  def get_data_of_device_from_key (self,key,gevice):
+    "return data of key"
+
+    iter = gevice.list_devices.get_iter_first()
+
+    while (iter):
+      id = gevice.list_devices.get_value(iter,config.COLUMN_DEVICE)
+
+      if str(key) == str(id):
+        name_type = gevice.list_devices.get_value(iter,config.COLUMN_NAME_DEVICE)
+        pix =  gevice.list_devices.get_value(iter,config.COLUMN_PIXBUF)
+
+        return name_type, pix
+
+      iter = gevice.list_devices.iter_next(iter)
+    return None,None
+
+  def get_data_of_link_from_key (self,key,gevice):
+    links = gevice.gdbase.get_list_of_links (gevice)
+    iter = links.get_iter_first()
 
-                return name_type, pix
+    while (iter):
+      id = links.get_value(iter,1)
 
-            iter = gevice.list_devices.iter_next(iter)
-        return None,None
+      if str(key) == str(id):
+        pix =  links.get_value(iter,1)
+        name =  links.get_value(iter,0)
 
-    def get_data_of_link_from_key (self,key,gevice):
-        links = gevice.gdbase.get_list_of_links (gevice)
-        iter = links.get_iter_first()
+        return pix,name
+
+      iter = links.iter_next(iter)
+    return None,None
 
-        while (iter):
-            id = links.get_value(iter,1)
+  def expand_treeview (self,flag):
+    seleccion,iterador = self.treeview.get_selection().get_selected()
+    path = self.treestore.get_path(iterador)
 
-            if str(key) == str(id):
-                pix =  links.get_value(iter,1)
-                name =  links.get_value(iter,0)
-
-                return pix,name
-
-            iter = links.iter_next(iter)
-        return None,None
-
-    def expand_treeview (self,flag):
-        seleccion,iterador = self.treeview.get_selection().get_selected()
-        path = self.treestore.get_path(iterador)
-
-        if flag:
-            self.treeview.expand_row(path,True)
-        else:
-            self.treeview.collapse_row(path)
-	
+    if flag:
+      self.treeview.expand_row(path,True)
+    else:
+      self.treeview.collapse_row(path)
diff --git a/src/geviceprefer.py b/src/geviceprefer.py
index 3a122bc..7e45e16 100644
--- a/src/geviceprefer.py
+++ b/src/geviceprefer.py
@@ -26,9 +26,6 @@ class GevicePrefer:
         self.diagmodel = False
         self.diaglink = False
         self.csvseparator = "|"
-        self.host = _("Host")
-        self.dbase = _("Database")
-        self.user_dbase = _("User database")
         
     
     def load_interface (self,gevice):
@@ -53,9 +50,6 @@ class GevicePrefer:
         self.checkbutton_ip_diag = builder.get_object ("checkbutton_ip_diag")
         self.checkbutton_model_diag = builder.get_object ("checkbutton_model_diag")
         self.checkbutton_link_diag = builder.get_object ("checkbutton_link_diag")
-        self.entry_host = builder.get_object ("entry_host")
-        self.entry_dbase = builder.get_object ("entry_dbase")
-        self.entry_user_dbase = builder.get_object ("entry_user_dbase")
         self.button_add_user = builder.get_object ("button_add_user")
         self.button_rem_user = builder.get_object ("button_rem_user")
         self.treeview_users = builder.get_object ("treeview_users")
@@ -76,20 +70,12 @@ class GevicePrefer:
         self.checkbutton_ip_diag.connect ("toggled",self.change_estatus_on_diagram,gevice)
         self.checkbutton_model_diag.connect ("toggled",self.change_estatus_on_diagram,gevice)
         self.checkbutton_link_diag.connect ("toggled",self.change_estatus_on_diagram,gevice)
-        self.entry_host.connect ("changed",self.on_entry_host_changed,gevice)
-        self.entry_dbase.connect ("changed",self.on_entry_dbase_changed,gevice)
-        self.entry_user_dbase.connect ("changed",self.on_entry_user_dbase_changed,gevice)
-        
         self.button_add_user.connect ("clicked",self.on_button_add_user_clicked,gevice)
         self.button_rem_user.connect ("clicked",self.on_button_rem_user_clicked,gevice)        
         
         # for not activate callback when loading preferences
         self.flag_load_preferences = True
         
-        self.entry_host.set_text(self.host)
-        self.entry_user_dbase.set_text(self.user_dbase)
-        self.entry_dbase.set_text(self.dbase)
-        
         self.checkbutton_ip.set_active(self.viewip)
         self.checkbutton_model.set_active(self.viewmodel)
         self.checkbutton_serial.set_active(self.viewserial)
@@ -219,15 +205,6 @@ class GevicePrefer:
 
     def on_spinbutton_prefer_change_value (self,spinbutton,gevice):
         self.save_preferences(gevice)
-
-    def on_entry_host_changed (self,editable,gevice):
-        self.save_preferences(gevice)
-        
-    def on_entry_dbase_changed (self,editable,gevice):
-        self.save_preferences(gevice)
-        
-    def on_entry_user_dbase_changed (self,editable,gevice):
-        self.save_preferences(gevice)
         
     def on_entry_backcolor_changed (self,editable,gevice):
         self.save_preferences(gevice)
@@ -241,9 +218,6 @@ class GevicePrefer:
     def load_preferences (self,gevice):
         client = gconf.client_get_default()
 
-        host = client.get_string('/apps/gevice/host')
-        dbase = client.get_string('/apps/gevice/dbase')
-        user_dbase = client.get_string('/apps/gevice/user_dbase')
         backcolor = client.get_string('/apps/gevice/backcolor')
         forecolor = client.get_string('/apps/gevice/forecolor')
         csvseparator = client.get_string('/apps/gevice/csvseparator')
@@ -263,15 +237,6 @@ class GevicePrefer:
             self.listusers = listusers
         else:
             self.listusers = ['user']
-                    
-        if (host):
-            self.host = host        
-
-        if (user_dbase):
-            self.user_dbase = user_dbase        
-
-        if (dbase):
-            self.dbase = dbase        
         
         if (backcolor):
             self.backcolor = backcolor            
@@ -281,28 +246,9 @@ class GevicePrefer:
             
         if (csvseparator):
             self.csvseparator = csvseparator
-        
-        gevice.update_statusbar ()
-
     
     def save_preferences(self,gevice):
         if (not self.flag_load_preferences):
-        
-            host = self.entry_host.get_text()
-            host = host.strip()
-            if len(host) >= 0:
-                self.host = host
-            
-            dbase = self.entry_dbase.get_text()
-            dbase = dbase.strip()
-            if len(dbase) >= 0:
-                self.dbase = dbase
-            
-            user_dbase = self.entry_user_dbase.get_text()
-            user_dbase = user_dbase.strip()
-            if len(user_dbase) >= 0:
-                self.user_dbase = user_dbase
-            
             self.viewip = self.checkbutton_ip.get_active()
             self.viewmodel = self.checkbutton_model.get_active()
             self.viewserial = self.checkbutton_serial.get_active()
@@ -317,9 +263,6 @@ class GevicePrefer:
             self.diaglink = self.checkbutton_link_diag.get_active()
         
             client = gconf.client_get_default()
-            client.set_string('/apps/gevice/host', self.host)
-            client.set_string('/apps/gevice/dbase', self.dbase)
-            client.set_string('/apps/gevice/user_dbase', self.user_dbase)
             client.set_bool('/apps/gevice/viewip', self.viewip)
             client.set_bool('/apps/gevice/viewmodel', self.viewmodel)
             client.set_bool('/apps/gevice/viewserial', self.viewserial)



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