# This file is part of Recently Used Desklet # # Recently Used Desklet is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # Recently Used Desklet is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with Recently Used Desklet; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307 USA from xml.sax import saxutils from RecentFile import RecentFile import string import os class RecentParser(saxutils.DefaultHandler): __COLLECTION = "RecentFiles" __ITEM = "RecentItem" __URI = "URI" __MIME_TYPE = "Mime-Type" __TIMESTAMP = "Timestamp" __GROUPS = "Groups" __GROUP = "Group" def __init__(self, theme): self.__recent_files = [] self.__buffer = "" self.__theme = theme self.__recent_file = None def startElement(self, name, attrs): if name == self.__ITEM: self.__recent_file = RecentFile(self.__theme) self.__buffer = "" def endElement(self, name): if name == self.__ITEM: ## Double check that the file is still there if ( self.__recent_file and os.path.exists( self.__recent_file.get_local_file_path() ) ): self.__recent_files.append(self.__recent_file) self.__recent_file = None elif name == self.__URI: self.__recent_file.set_uri(self.__buffer) elif name == self.__MIME_TYPE: self.__recent_file.set_mime_type(self.__buffer) elif name == self.__TIMESTAMP: self.__recent_file.set_timestamp(int(self.__buffer)) elif name == self.__GROUP: self.__recent_file.set_group_name(self.__buffer) self.__buffer = "" def characters(self, ch): self.__buffer = self.__buffer + ch def get_recent_files(self): return self.__recent_files