Changeset 33 for storage

Show
Ignore:
Timestamp:
07/09/06 17:28:56 (2 years ago)
Author:
ploum
Message:

#12 Cannot rename a bookmark
+ sanitize XML stuff (prettyXML is really nasty)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • storage/bookmarks_store.py

    r32 r33  
    1212# this class represent the whole bookmarks list 
    1313class bookmarks_store : 
     14 
    1415        # bts_name is a string arg. It will be used to have 
    1516        # differents bookmarks for differents protocols. 
     
    2223                # 4- advanced search 
    2324                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) 
    2429                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) 
    2634                        for bmark in doc.getElementsByTagName("bookmark") : 
    2735                                title = bmark.getAttribute("title") 
     
    3543                        #then we create the file 
    3644                        f = open(bmark_file, mode='a+') 
    37                         f.write(doc.toprettyxml()) 
     45                        f.write(doc.toxml().encode("utf-8")) 
    3846                        f.close() 
    3947 
     
    5664                self.listing.remove(to_delete) 
    5765                self.sync_file() 
     66         
     67        def rename(self, to_rename, new_name) : 
     68                self.listing[to_rename][0]=new_name 
     69                self.sync_file() 
    5870 
    5971        def sync_file(self) : 
     
    6476                        doc2 = xml.dom.minidom.parseString(i[1]) 
    6577                        bmark = doc2.getElementsByTagName("bookmark")[0] 
     78                        bmark.setAttribute("title",i[0].strip()) 
    6679                        store.appendChild(bmark) 
    6780                #it's maybe not optimal to open/close the file each time we sync 
     
    6982                # might be changed in the future. 
    7083                f = open(bmark_file, mode='w+') 
    71                 f.write(doc.toprettyxml()) 
     84                f.write(doc.toprettyxml().encode("utf-8")) 
    7285                f.close() 
    7386                 
     
    7790        # constructor take the path to the bug in the store. 
    7891        def __init__(self,path) : 
    79                 bug = '' 
    80                 search = '' 
    81                 product = '' 
    82                 title = '' 
     92                zbug = 0 
     93                zsearch = '' 
     94                zproduct = '' 
     95                ztitle = '' 
    8396                zetuple = path.get_selection().get_selected() 
    84                 #method = zetuple[0].get_value(zetuple[1],1) 
    8597                string = zetuple[0].get_value(zetuple[1],1) 
    8698                doc2 = xml.dom.minidom.parseString(string) 
    8799                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: 
    90102                        # besoin de programmation défensive ici FIXME 
    91103                        #bug = int(zetuple[0].get_value(zetuple[1],2)) 
    92104                        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: 
    95107                        s_element = bmark.getElementsByTagName("search")[0] 
    96                         search = s_element.childNodes[0].nodeValue 
    97                 elif method == 3: 
     108                        zsearch = s_element.childNodes[0].nodeValue 
     109                elif zmethod == 3: 
    98110                        s_element = bmark.getElementsByTagName("search") 
    99111                        p_element = bmark.getElementsByTagName("product")[0] 
    100                         product = p_element.childNodes[0].nodeValue 
     112                        zproduct = p_element.childNodes[0].nodeValue 
    101113                        if len(s_element) == 0 : 
    102                                 search = None 
     114                                zsearch = None 
    103115                        else :   
    104                                 search = s_element[0].childNodes[0].nodeValue 
    105                 self.bug = str(bug) 
    106                 self.method = method 
    107                 self.search = search 
    108                 self.product = product 
     116                                zsearch = s_element[0].childNodes[0].nodeValue 
     117                self.bug = str(zbug) 
     118                self.method = zmethod 
     119                self.search = zsearch 
     120                self.product = zproduct 
    109121                self.title = bmark.getAttribute("title") 
    110122