Package flumotion :: Package component :: Package misc :: Package httpserver :: Module ondemandbrowser
[hide private]

Source Code for Module flumotion.component.misc.httpserver.ondemandbrowser

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  """Ondemand Browser widget 
 19   
 20  The widget is in concept similar to the FileSelector but displaying full urls 
 21  for the files and adding a context menu for copying or opening the link. 
 22  """ 
 23   
 24  import gettext 
 25  import gtk 
 26  import urlparse 
 27  import os 
 28   
 29  try: 
 30      from kiwi.ui.widgets import contextmenu 
 31  except: 
 32      # kiwi < 1.9.22 
 33      contextmenu = None 
 34   
 35  from flumotion.ui.fileselector import FileSelector 
 36  from flumotion.common.interfaces import IDirectory 
 37   
 38  __version__ = "$Rev$" 
 39  _ = gettext.gettext 
 40   
 41   
42 -class _FileUri(object):
43
44 - def __init__(self, fileInfo, icon):
45 self.original = fileInfo 46 self.filename = fileInfo.filename 47 self.icon = icon
48
49 - def getPath(self):
50 return self.original.getPath()
51 52
53 -class OnDemandBrowser(FileSelector):
54
55 - def __init__(self, parent, adminModel):
56 FileSelector.__init__(self, parent, adminModel) 57 self._base_uri = None 58 self._root = None 59 if contextmenu: 60 self._popupmenu = self._create_popup_menu() 61 self.set_context_menu(self._popupmenu)
62
63 - def setBaseUri(self, base_uri):
64 self._base_uri = base_uri
65
66 - def setRoot(self, path):
67 self._root = os.path.normpath(path) 68 self.setDirectory(self._root)
69
70 - def _create_popup_menu(self):
71 popupmenu = contextmenu.ContextMenu() 72 item = contextmenu.ContextMenuItem('_Open Link', gtk.STOCK_JUMP_TO) 73 item.connect('activate', self._on_open_link_activate) 74 popupmenu.add(item) 75 popupmenu.append_separator() 76 item = contextmenu.ContextMenuItem('_Copy Link', gtk.STOCK_COPY) 77 item.connect('activate', self._on_copy_link_activate) 78 popupmenu.add(item) 79 popupmenu.show_all() 80 return popupmenu
81
82 - def _populateList(self, vfsFiles):
83 self.clear() 84 for vfsFile in vfsFiles: 85 if not IDirectory.providedBy(vfsFile) and self._onlyDirectories: 86 continue 87 path = vfsFile.getPath() 88 if path in self._root and path != self._root: 89 continue 90 icon = self._renderIcon(vfsFile.iconNames) 91 rel_path = path.replace(self._root, '') 92 if self._base_uri and vfsFile.filename != '..': 93 vfsFile.filename = urlparse.urljoin(self._base_uri, rel_path) 94 self.append(_FileUri(vfsFile, icon))
95 99
104