# -*- coding: utf-8 # $Id$ # # Copyright 2001, 2002 by IVA Team and contributors # # This file is part of IVA. # # IVA 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. # # IVA 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 IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Contains class WebtopFile, which represents an uploaded (binary) file in a user's webtop.""" __version__ = "$Revision$"[11:-2] import Globals from WebtopItem import WebtopItem import OFS,time from AccessControl import ClassSecurityInfo from common import perm_view from zope.interface import implements from interfaces import IWebtopItem, IWebtopFile, IStatistics from zope.component import adapter, getUtility from zope.app.container.interfaces import IObjectAddedEvent class WebtopFile(WebtopItem, OFS.Image.File): """A file in a Webtop.""" meta_type = "WebtopFile" security = ClassSecurityInfo() implements(IWebtopItem, IWebtopFile) def __init__(self, parent, name, file, original_name=''): """Construct the webtop folder object.""" WebtopItem.__init__(self,parent,name) self.original_name = original_name OFS.Image.File.__init__(self, self.id, self.title, file) # FIXME: As this function returns some content for catalog # FIXME: to index, we should do all possible conversions here # FIXME: (RTF -> ascii, PDF -> ascii, and so on ...) security.declarePrivate('get_content') def get_content(self): """Return content of the file.""" return self.data security.declareProtected(perm_view, 'get_size') def get_size(self): """Return size of the object.""" return self.getSize() security.declareProtected(perm_view,'get_realname') def get_realname(self): return self.original_name security.declareProtected(perm_view, 'get_realname_or_id') def get_realname_or_id(self): """ return realname or id """ if self.has_realname(): return self.get_realname() else: # XXX: This is hack. content-type is application/octet-stream; name="11_intr2.mcd" # XXX: we split it until we get name and return it as filename. if '; name=' in self.content_type: a = self.content_type.split(';') if len(a) < 2: return self.id b = a[1] a = b.split('"') if len(a) < 2: return self.id return a[1] return self.id security.declareProtected(perm_view,'has_realname') def has_realname(self): if getattr(self.aq_self, 'original_name', ''): return 1 else: return 0 Globals.InitializeClass(WebtopFile) # EOF @adapter(IWebtopFile, IObjectAddedEvent) def added(obj, event): try: content_type = obj.getContentType() except AttributeError: content_type = 'application/dontknow' content_type_major = content_type[:content_type.find('/')] if content_type == 'text/html': obj.set_icon('type_html.gif') elif content_type_major == 'text': obj.set_icon('type_doc.gif') elif content_type_major == 'audio': obj.set_icon('type_audio.gif') elif content_type_major == 'image': obj.set_icon('type_image.gif') elif content_type_major == 'video': obj.set_icon('type_video.gif') else: obj.set_icon('type_no.gif') obj.set_icon('document_gif.gif')