- Timestamp:
- 07/09/06 17:28:56 (2 years ago)
- Files:
-
- 1 modified
-
storage/bookmarks_store.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
storage/bookmarks_store.py
r32 r33 12 12 # this class represent the whole bookmarks list 13 13 class bookmarks_store : 14 14 15 # bts_name is a string arg. It will be used to have 15 16 # differents bookmarks for differents protocols. … … 22 23 # 4- advanced search 23 24 self.listing = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 25 def reorder_callback(treemodel, path, iter, new_order): 26 print "reordering" 27 self.sync_file() 28 self.listing.connect("rows-reordered", reorder_callback) 24 29 if os.path.exists(bmark_file) : 25 doc = xml.dom.minidom.parse(bmark_file) 30 f = open(bmark_file,mode='r') 31 # sanitize the pretty XML 32 stringed = f.read().replace('\n','').replace('\t','') 33 doc = xml.dom.minidom.parseString(stringed) 26 34 for bmark in doc.getElementsByTagName("bookmark") : 27 35 title = bmark.getAttribute("title") … … 35 43 #then we create the file 36 44 f = open(bmark_file, mode='a+') 37 f.write(doc.to prettyxml())45 f.write(doc.toxml().encode("utf-8")) 38 46 f.close() 39 47 … … 56 64 self.listing.remove(to_delete) 57 65 self.sync_file() 66 67 def rename(self, to_rename, new_name) : 68 self.listing[to_rename][0]=new_name 69 self.sync_file() 58 70 59 71 def sync_file(self) : … … 64 76 doc2 = xml.dom.minidom.parseString(i[1]) 65 77 bmark = doc2.getElementsByTagName("bookmark")[0] 78 bmark.setAttribute("title",i[0].strip()) 66 79 store.appendChild(bmark) 67 80 #it's maybe not optimal to open/close the file each time we sync … … 69 82 # might be changed in the future. 70 83 f = open(bmark_file, mode='w+') 71 f.write(doc.toprettyxml() )84 f.write(doc.toprettyxml().encode("utf-8")) 72 85 f.close() 73 86 … … 77 90 # constructor take the path to the bug in the store. 78 91 def __init__(self,path) : 79 bug = ''80 search = ''81 product = ''82 title = ''92 zbug = 0 93 zsearch = '' 94 zproduct = '' 95 ztitle = '' 83 96 zetuple = path.get_selection().get_selected() 84 #method = zetuple[0].get_value(zetuple[1],1)85 97 string = zetuple[0].get_value(zetuple[1],1) 86 98 doc2 = xml.dom.minidom.parseString(string) 87 99 bmark = doc2.getElementsByTagName("bookmark")[0] 88 method = int(bmark.getAttribute("type"))89 if method == 1:100 zmethod = int(bmark.getAttribute("type")) 101 if zmethod == 1: 90 102 # besoin de programmation défensive ici FIXME 91 103 #bug = int(zetuple[0].get_value(zetuple[1],2)) 92 104 element = bmark.getElementsByTagName("bug")[0] 93 bug = int(element.childNodes[0].nodeValue)94 elif method == 2:105 zbug = int(element.childNodes[0].nodeValue) 106 elif zmethod == 2: 95 107 s_element = bmark.getElementsByTagName("search")[0] 96 search = s_element.childNodes[0].nodeValue97 elif method == 3:108 zsearch = s_element.childNodes[0].nodeValue 109 elif zmethod == 3: 98 110 s_element = bmark.getElementsByTagName("search") 99 111 p_element = bmark.getElementsByTagName("product")[0] 100 product = p_element.childNodes[0].nodeValue112 zproduct = p_element.childNodes[0].nodeValue 101 113 if len(s_element) == 0 : 102 search = None114 zsearch = None 103 115 else : 104 search = s_element[0].childNodes[0].nodeValue105 self.bug = str( bug)106 self.method = method107 self.search = search108 self.product = product116 zsearch = s_element[0].childNodes[0].nodeValue 117 self.bug = str(zbug) 118 self.method = zmethod 119 self.search = zsearch 120 self.product = zproduct 109 121 self.title = bmark.getAttribute("title") 110 122
