Skip to content

Commit

Permalink
#1861: skip loading mixins if the feature is disabled
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@19885 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 8, 2018
1 parent ed5321e commit 175676a
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/xpra/client/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def defaults_init(self):
self.init_packet_handlers()
sanity_checks()

def init(self, opts):
def init(self, opts, _extra_args=[]):
if self._init_done:
#the gtk client classes can inherit this method
#from multiple parents, skip initializing twice
Expand Down
33 changes: 14 additions & 19 deletions src/xpra/client/gtk_base/gtk_tray_menu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@
from xpra.codecs.loader import PREFERED_ENCODING_ORDER, get_encoding_help, get_encoding_name
from xpra.simple_stats import std_unit_dec
from xpra.platform.gui import get_icon_size
try:
from xpra.clipboard.translated_clipboard import TranslatedClipboardProtocolHelper
except ImportError:
TranslatedClipboardProtocolHelper = None
try:
from xpra import clipboard
HAS_CLIPBOARD = bool(clipboard)
except ImportError:
HAS_CLIPBOARD = False
from xpra.client import mixin_features


from xpra.log import Logger
log = Logger("menu")
Expand All @@ -44,7 +37,7 @@
RUNCOMMAND_MENU = envbool("XPRA_SHOW_RUNCOMMAND_MENU", True)
SHOW_SERVER_COMMANDS = envbool("XPRA_SHOW_SERVER_COMMANDS", True)
SHOW_TRANSFERS = envbool("XPRA_SHOW_TRANSFERS", True)
SHOW_CLIPBOARD_MENU = envbool("XPRA_SHOW_CLIPBOARD_MENU", HAS_CLIPBOARD)
SHOW_CLIPBOARD_MENU = envbool("XPRA_SHOW_CLIPBOARD_MENU", True)
SHOW_SHUTDOWN = envbool("XPRA_SHOW_SHUTDOWN", True)
WINDOWS_MENU = envbool("XPRA_SHOW_WINDOWS_MENU", True)

Expand Down Expand Up @@ -292,15 +285,15 @@ def set_menu_title(*_args):
menu.append(self.make_featuresmenuitem())
if self.client.keyboard_helper:
menu.append(self.make_layoutsmenuitem())
if SHOW_CLIPBOARD_MENU:
if mixin_features.clipboard and SHOW_CLIPBOARD_MENU:
menu.append(self.make_clipboardmenuitem())
if self.client.windows_enabled:
if mixin_features.windows:
menu.append(self.make_picturemenuitem())
if STARTSTOP_SOUND_MENU:
if mixin_features.audio and STARTSTOP_SOUND_MENU:
menu.append(self.make_audiomenuitem())
if WEBCAM_MENU:
if mixin_features.webcam and WEBCAM_MENU:
menu.append(self.make_webcammenuitem())
if self.client.windows_enabled and WINDOWS_MENU:
if mixin_features.windows and WINDOWS_MENU:
menu.append(self.make_windowsmenuitem())
if RUNCOMMAND_MENU or SHOW_SERVER_COMMANDS or SHOW_UPLOAD or SHOW_SHUTDOWN:
menu.append(self.make_servermenuitem())
Expand Down Expand Up @@ -419,13 +412,15 @@ def append_featuresmenuitems(self, menu):
menu.append(self.make_sharingmenuitem())
menu.append(self.make_lockmenuitem())
menu.append(self.make_readonlymenuitem())
menu.append(self.make_bellmenuitem())
menu.append(self.make_notificationsmenuitem())
if self.client.windows_enabled:
if mixin_features.windows:
menu.append(self.make_bellmenuitem())
if mixin_features.notifications:
menu.append(self.make_notificationsmenuitem())
if mixin_features.windows:
menu.append(self.make_cursorsmenuitem())
if self.client.client_supports_opengl:
menu.append(self.make_openglmenuitem())
if self.client.windows_enabled:
if mixin_features.windows:
menu.append(self.make_modalwindowmenuitem())
if self.client.keyboard_helper:
menu.append(self.make_keyboardsyncmenuitem())
Expand Down
21 changes: 21 additions & 0 deletions src/xpra/client/mixin_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# This file is part of Xpra.
# Copyright (C) 2018 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.log import Logger
log = Logger("server")

display = True
windows = True
webcam = True
audio = True
clipboard = True
notifications = True
dbus = True
mmap = True
logging = True
tray = True
network_state = True
encoding = True
10 changes: 8 additions & 2 deletions src/xpra/client/mixins/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from xpra.scripts.parsing import sound_option
from xpra.net.compression import Compressed
from xpra.os_util import get_machine_id, get_user_uuid, bytestostr, OSX, POSIX
from xpra.util import envint, typedict, csv
from xpra.util import envint, typedict, csv, updict
from xpra.client.mixins.stub_client_mixin import StubClientMixin


Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(self):
self.server_ogg_latency_fix = False
self.queue_used_sent = None

def init(self, opts):
def init(self, opts, _extra_args=[]):
self.av_sync = opts.av_sync
self.sound_properties = typedict()
self.speaker_allowed = sound_option(opts.speaker) in ("on", "off")
Expand Down Expand Up @@ -120,6 +120,8 @@ def vinfo(k):
log.warn(" %s", e)
except Exception:
log.error("failed to add pulseaudio info", exc_info=True)
#audio tagging:
self.init_audio_tagging(opts.tray_icon)


def cleanup(self):
Expand Down Expand Up @@ -148,6 +150,10 @@ def get_audio_capabilities(self):
log("audio capabilities: %s", caps)
return caps

def get_caps(self):
return updict({}, "sound", self.get_audio_capabilities())


def setup_connection(self, _conn):
pass

Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
self.server_clipboards = []
self.clipboard_helper = None

def init(self, opts):
def init(self, opts, _extra_args=[]):
self.client_clipboard_type = opts.clipboard
self.client_clipboard_direction = opts.clipboard_direction
self.client_supports_clipboard = not ((opts.clipboard or "").lower() in FALSE_OPTIONS)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self):
self.server_randr = False


def init(self, opts):
def init(self, opts, _extra_args=[]):
self.desktop_fullscreen = opts.desktop_fullscreen
self.desktop_scaling = opts.desktop_scaling
self.dpi = int(opts.dpi)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self):
self.encoding_defaults = {}


def init(self, opts):
def init(self, opts, _extra_args=[]):
self.allowed_encodings = opts.encodings
self.encoding = opts.encoding
self.video_scaling = parse_bool_or_int("video-scaling", opts.video_scaling)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/fileprint_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self):
self.send_printers_timer = 0
self.exported_printers = None

def init(self, opts):
def init(self, opts, _extra_args=[]):
#printing and file transfer:
FileTransferHandler.init_opts(self, opts)

Expand Down
29 changes: 18 additions & 11 deletions src/xpra/client/mixins/mmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
self.supports_mmap = MMAP_SUPPORTED


def init(self, opts):
def init(self, opts, _extra_args=[]):
if MMAP_SUPPORTED:
self.mmap_group = opts.mmap_group
if os.path.isabs(opts.mmap):
Expand Down Expand Up @@ -83,16 +83,23 @@ def iget(attrname, default_value=0):


def get_caps(self):
if self.mmap_enabled:
return {
"file" : self.mmap_filename,
"size" : self.mmap_size,
"token" : self.mmap_token,
"token_index" : self.mmap_token_index,
"token_bytes" : self.mmap_token_bytes,
"namespace" : True, #this client understands "mmap.ATTRIBUTE" format
}
return {}
if not self.mmap_enabled:
return {}
raw_caps = {
"file" : self.mmap_filename,
"size" : self.mmap_size,
"token" : self.mmap_token,
"token_index" : self.mmap_token_index,
"token_bytes" : self.mmap_token_bytes,
"namespace" : True, #this client understands "mmap.ATTRIBUTE" format
}
caps = {
"mmap" : raw_caps,
}
#pre 2.3 servers only use underscore instead of "." prefix for mmap caps:
for k,v in raw_caps.items():
caps["mmap_%s" % k] = v
return caps

def init_mmap(self, mmap_filename, mmap_group, socket_filename):
log("init_mmap(%s, %s, %s)", mmap_filename, mmap_group, socket_filename)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self):
self.ping_echo_timeout_timer = None


def init(self, opts):
def init(self, opts, _extra_args=[]):
self.pings = opts.pings
self.bandwidth_limit = parse_with_unit("bandwidth-limit", opts.bandwidth_limit)
self.bandwidth_detection = opts.bandwidth_detection
Expand Down
21 changes: 9 additions & 12 deletions src/xpra/client/mixins/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from xpra.platform.paths import get_icon_filename
from xpra.platform.gui import get_native_notifier_classes
from xpra.os_util import bytestostr
from xpra.util import envbool, repr_ellipsized, make_instance
from xpra.util import envbool, repr_ellipsized, make_instance, updict
from xpra.client.mixins.stub_client_mixin import StubClientMixin


Expand All @@ -31,7 +31,7 @@ def __init__(self):
self.notifier = None
self.tray = None

def init(self, opts):
def init(self, opts, _extra_args=[]):
if opts.notifications:
try:
from xpra import notifications
Expand All @@ -40,13 +40,9 @@ def init(self, opts):
log.warn("Warning: notifications module not found")
else:
self.client_supports_notifications = True

def init_ui(self):
log("client_supports_notifications=%s", self.client_supports_notifications)
if self.client_supports_notifications:
self.notifier = self.make_notifier()
log("using notifier=%s", self.notifier)
self.client_supports_notifications = self.notifier is not None
self.notifier = self.make_notifier()
log("using notifier=%s", self.notifier)
self.client_supports_notifications = self.notifier is not None


def cleanup(self):
Expand All @@ -68,12 +64,13 @@ def parse_server_capabilities(self):
return True


def get_notifications_caps(self):
return {
def get_caps(self):
return updict({}, "notifications", {
"" : self.client_supports_notifications,
"close" : self.client_supports_notifications,
"actions" : self.client_supports_notifications and self.notifier and self.notifier.handles_actions,
}
})


def init_authenticated_packet_handlers(self):
self.set_packet_handlers(self._ui_packet_handlers, {
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/remote_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
self.local_logging = None
self.log_both = False

def init(self, opts):
def init(self, opts, _extra_args=[]):
self.log_both = (opts.remote_logging or "").lower()=="both"
self.client_supports_remote_logging = self.log_both or parse_bool("remote-logging", opts.remote_logging)

Expand Down
5 changes: 1 addition & 4 deletions src/xpra/client/mixins/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
self.server_rpc_types = []
self.rpc_filter_timers = {}

def init(self, _opts):
def init(self, opts, _extra_args=[]):
pass

def cleanup(self):
Expand All @@ -41,9 +41,6 @@ def cleanup(self):
def run(self):
pass

def setup_connection(self, _conn):
pass


def parse_server_capabilities(self):
c = self.server_capabilities
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/stub_client_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
Options are usually obtained by parsing the command line,
or using a default configuration object.
"""
def init(self, _opts):
def init(self, _opts, _extra_args=[]):
pass

"""
Expand Down
57 changes: 28 additions & 29 deletions src/xpra/client/mixins/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,36 @@ def __init__(self):
self.tray = None
self.menu_helper = None

def init(self, opts):
def init(self, opts, _extra_args=[]):
self.tray_enabled = opts.tray
self.delay_tray = opts.delay_tray
self.tray_icon = opts.tray_icon

def init_ui(self):
""" initialize user interface """
if self.tray_enabled:
self.menu_helper = self.make_tray_menu_helper()
def setup_xpra_tray(*args):
log("setup_xpra_tray%s", args)
tray = self.setup_xpra_tray(self.tray_icon or "xpra")
self.tray = tray
if tray:
tray.show()
icon_timestamp = tray.icon_timestamp
def reset_icon():
if not self.tray:
return
#re-set the icon after a short delay,
#seems to help with buggy tray geometries,
#but don't do it if we have already changed the icon
#(ie: the dynamic window icon code may have set a new one)
if icon_timestamp==tray.icon_timestamp:
tray.set_icon()
self.timeout_add(1000, reset_icon)
if self.delay_tray:
self.connect("first-ui-received", setup_xpra_tray)
else:
#show shortly after the main loop starts running:
self.timeout_add(TRAY_DELAY, setup_xpra_tray)
if not self.tray_enabled:
return
self.menu_helper = self.make_tray_menu_helper()
if self.delay_tray:
self.connect("first-ui-received", self.setup_xpra_tray)
else:
#show shortly after the main loop starts running:
self.timeout_add(TRAY_DELAY, self.setup_xpra_tray)

def setup_xpra_tray(self, *args):
log("setup_xpra_tray%s", args)
tray = self.create_xpra_tray(self.tray_icon or "xpra")
self.tray = tray
if tray:
tray.show()
icon_timestamp = tray.icon_timestamp
def reset_icon():
if not self.tray:
return
#re-set the icon after a short delay,
#seems to help with buggy tray geometries,
#but don't do it if we have already changed the icon
#(ie: the dynamic window icon code may have set a new one)
if icon_timestamp==tray.icon_timestamp:
tray.set_icon()
self.timeout_add(1000, reset_icon)

def cleanup(self):
t = self.tray
Expand Down Expand Up @@ -89,7 +88,7 @@ def show_menu(self, *_args):
if self.menu_helper:
self.menu_helper.activate()

def setup_xpra_tray(self, tray_icon_filename):
def create_xpra_tray(self, tray_icon_filename):
tray = None
#this is our own tray
def xpra_tray_click(button, pressed, time=0):
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def cleanup(self):
self.stop_sending_webcam()


def init(self, opts):
def init(self, opts, _extra_args=[]):
self.webcam_option = opts.webcam
self.webcam_forwarding = self.webcam_option.lower() not in FALSE_OPTIONS
self.server_webcam = False
Expand Down
Loading

0 comments on commit 175676a

Please sign in to comment.