Ejemplo n.º 1
0
 def init_clipboard(self):
     log("init_clipboard() enabled=%s, filter file=%s", self.clipboard,
         self.clipboard_filter_file)
     ### Clipboard handling:
     self._clipboard_helper = None
     self._clipboard_client = None
     self._clipboards = []
     if not self.clipboard:
         return
     clipboard_filter_res = []
     if self.clipboard_filter_file:
         if not os.path.exists(self.clipboard_filter_file):
             log.error(
                 "invalid clipboard filter file: '%s' does not exist - clipboard disabled!",
                 self.clipboard_filter_file)
             return
         try:
             with open(self.clipboard_filter_file, "r") as f:
                 for line in f:
                     clipboard_filter_res.append(line.strip())
                 log(
                     "loaded %s regular expressions from clipboard filter file %s",
                     len(clipboard_filter_res), self.clipboard_filter_file)
         except OSError:
             log.error(
                 "Error: reading clipboard filter file %s - clipboard disabled!",
                 self.clipboard_filter_file,
                 exc_info=True)
             return
     try:
         from xpra.platform.gui import get_clipboard_native_class
         clipboard_class = get_clipboard_native_class()
         assert clipboard_class, "no native clipboard support"
         parts = clipboard_class.split(".")
         mod = ".".join(parts[:-1])
         module = __import__(mod, {}, {}, [parts[-1]])
         ClipboardClass = getattr(module, parts[-1])
         log("ClipboardClass for %s: %s", clipboard_class, ClipboardClass)
         kwargs = {
             "filters": clipboard_filter_res,
             "can-send": self.clipboard_direction in ("to-client", "both"),
             "can-receive": self.clipboard_direction
             in ("to-server", "both"),
         }
         self._clipboard_helper = ClipboardClass(self.send_clipboard_packet,
                                                 self.clipboard_progress,
                                                 **kwargs)
         self._clipboard_helper.init_proxies_claim()
         self._clipboards = CLIPBOARDS
     except Exception:
         #log("gdk clipboard helper failure", exc_info=True)
         log.error("Error: failed to setup clipboard helper", exc_info=True)
         self.clipboard = False
Ejemplo n.º 2
0
 def get_clipboard_helper_classes(self):
     ct = self.client_clipboard_type
     if ct and ct.lower() in FALSE_OPTIONS:
         return []
     from xpra.scripts.main import CLIPBOARD_CLASS
     #first add the platform specific one, (may be None):
     clipboard_options = [
         CLIPBOARD_CLASS,
         get_clipboard_native_class(),
     ]
     log("get_clipboard_helper_classes() unfiltered list=%s",
         clipboard_options)
     if ct and ct.lower() != "auto" and ct.lower() not in TRUE_OPTIONS:
         #try to match the string specified:
         filtered = [
             x for x in clipboard_options
             if x and x.lower().find(self.client_clipboard_type) >= 0
         ]
         if not filtered:
             log.warn("Warning: no clipboard types matching '%s'",
                      self.client_clipboard_type)
             log.warn(" clipboard synchronization is disabled")
             return []
         log(" found %i clipboard types matching '%s'", len(filtered),
             self.client_clipboard_type)
         clipboard_options = filtered
     #now try to load them:
     log("get_clipboard_helper_classes() options=%s", clipboard_options)
     loadable = []
     for co in clipboard_options:
         if not co:
             continue
         try:
             parts = co.split(".")
             mod = ".".join(parts[:-1])
             module = __import__(mod, {}, {}, [parts[-1]])
             helperclass = getattr(module, parts[-1])
             loadable.append(helperclass)
         except ImportError:
             log("cannot load %s", co, exc_info=True)
             continue
     log("get_clipboard_helper_classes()=%s", loadable)
     return loadable