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