def toggleAutoConnect_(self, sender): share = self.config_manager.get_sharebykey('title', sender.parentItem().title()) if share.get('share_type') in ['managed', 'smb_home']: existing_share, index = self.config_manager.get_managedshare_bykey( 'title', share.get('title')) else: existing_share, index = self.config_manager.get_useradded_bykey( 'title', share.get('title')) if existing_share: if existing_share.get('connect_automatically'): sender.setState_(False) existing_share['connect_automatically'] = False self.config_manager.update_share(existing_share, index) NSLog('User has set {0} to no longer connect automatically'. format(existing_share.get('title'))) else: sender.setState_(True) existing_share['connect_automatically'] = True if existing_share.get( 'mount_point' ) not in SMUtilities.get_mounted_network_volumes(): SMUtilities.mount_share(existing_share.get('share_url')) self.config_manager.update_share(existing_share, index) NSLog('User has set {0} to connect automatically.'.format( existing_share.get('title'))) if self.addShareWindow.isVisible(): self.connectAutoCheck.setState_(share.get('connect_automatically'))
def autoMountShares(self): managed_shares = SMUtilities.get_managed_shares() user_added_shares = SMUtilities.get_user_added_shares() if self.ldap_reachable: for share in managed_shares: if (share.get('connect_automatically') and share.get('mount_point') not in SMUtilities.get_mounted_network_volumes()): NSLog('Automounting {0}'.format(share.get('share_url'))) SMUtilities.mount_share(share.get('share_url')) for share in user_added_shares: if (share.get('connect_automatically') and share.get('mount_point') not in SMUtilities.get_mounted_network_volumes()): SMUtilities.mount_share(share.get('share_url'))
def updateShareMenu(self, share_path): mounted_volumes_base_paths = [ os.path.basename(mounted) for mounted in SMUtilities.get_mounted_network_volumes() ] share_menu_titles = [ menu_item.title() for menu_item in self.connectMenu.itemArray() ] network_share = self.config_manager.get_sharebykey( 'mount_point', share_path) if self.ldap_reachable: NSLog('Updating menu for "{0}"'.format(network_share.get('title'))) item_index = self.connectMenu.indexOfItemWithTitle_( network_share.get('title')) self.connectMenu.removeItemAtIndex_(item_index) self.connectMenu.insertItem_atIndex_( self.buildShareMenu(network_share), item_index) # below updates the Umount All menu item for share in share_menu_titles: if share in mounted_volumes_base_paths: unmount_all = True break else: unmount_all = False unmount = self.connectMenu.itemWithTitle_('Unmount All') if unmount_all: unmount.setAction_(self.unmountShare_) unmount.setTarget_(self) else: unmount.setAction_(None) unmount.setTarget_(self)
def processUserAddedShares(self): user_added_shares = SMUtilities.get_user_added_shares() self.connectMenu.addItem_(NSMenuItem.separatorItem()) if user_added_shares: no_available_shares = self.connectMenu.indexOfItemWithTitle_( 'No available shares...') if no_available_shares != -1: self.connectMenu.removeItemAtIndex_(no_available_shares) for share in user_added_shares: share_menu = self.buildShareMenu(share) self.connectMenu.addItem_(share_menu) if share.get('hide_from_menu'): share_menu.setHidden_(True) self.connectMenu.addItem_(NSMenuItem.separatorItem()) if self.ldap_reachable: hide_all = False self.connectMenu.addItemWithTitle_action_keyEquivalent_( 'Show Hidden', self.toggleShowHidden_, '').setTarget_(self) self.connectMenu.itemWithTitle_('Show Hidden').setHidden_(True) self.toggleShowHiddenButton() else: hide_all = True self.connectMenu.addItemWithTitle_action_keyEquivalent_( 'Check For Updates', self.manualUpdate_, '').setTarget_(self) for shareMenu in self.connectMenu.itemArray(): if shareMenu.submenu() and hide_all: shareMenu.setHidden_(True) self.connectMenu.addItem_(NSMenuItem.separatorItem()) if SMUtilities.get_mounted_network_volumes(): self.connectMenu.addItemWithTitle_action_keyEquivalent_( 'Unmount All', self.unmountShare_, '').setTarget_(self) else: self.connectMenu.addItemWithTitle_action_keyEquivalent_( 'Unmount All', None, '')
def buildShareMenu(self, share): user_added_shares = SMUtilities.get_user_added_shares() shareMenu = NSMenu.alloc().init() connectMenuItem = NSMenuItem.alloc( ).initWithTitle_action_keyEquivalent_(share.get('title'), None, '') if share.get( 'mount_point') in SMUtilities.get_mounted_network_volumes(): connectMenuItem.setState_(True) shareMenu.addItemWithTitle_action_keyEquivalent_( 'Unmount Share', self.unmountShare_, '').setTarget_(self) shareMenu.addItemWithTitle_action_keyEquivalent_( 'Open Folder', self.openFolderClicked_, '').setTarget_(self) else: connectMenuItem.setState_(False) shareMenu.addItemWithTitle_action_keyEquivalent_( 'Mount Share', self.connectToShare_, '').setTarget_(self) shareMenu.addItem_(NSMenuItem.separatorItem()) shareMenu.addItemWithTitle_action_keyEquivalent_( 'Connect Automatically', self.toggleAutoConnect_, '').setTarget_(self) if share.get('connect_automatically'): shareMenu.itemWithTitle_('Connect Automatically').setState_(True) shareMenu.addItemWithTitle_action_keyEquivalent_( 'Hide from Menu', self.toggleHideShare_, '').setTarget_(self) if share in user_added_shares: shareMenu.addItemWithTitle_action_keyEquivalent_( 'Remove from Menu', self.removeUserShare_, '').setTarget_(self) connectMenuItem.setSubmenu_(shareMenu) return connectMenuItem
def processUserAddedShares(self): user_added_shares = SMUtilities.get_user_added_shares() self.connectMenu.addItem_(NSMenuItem.separatorItem()) if user_added_shares: no_available_shares = self.connectMenu.indexOfItemWithTitle_('No available shares...') if no_available_shares != -1: self.connectMenu.removeItemAtIndex_(no_available_shares) for share in user_added_shares: share_menu = self.buildShareMenu(share) self.connectMenu.addItem_(share_menu) if share.get('hide_from_menu'): share_menu.setHidden_(True) self.connectMenu.addItem_(NSMenuItem.separatorItem()) if self.ldap_reachable: hide_all = False self.connectMenu.addItemWithTitle_action_keyEquivalent_('Show Hidden', self.toggleShowHidden_, '').setTarget_(self) self.connectMenu.itemWithTitle_('Show Hidden').setHidden_(True) self.toggleShowHiddenButton() else: hide_all = True self.connectMenu.addItemWithTitle_action_keyEquivalent_('Check For Updates', self.manualUpdate_, '').setTarget_(self) for shareMenu in self.connectMenu.itemArray(): if shareMenu.submenu() and hide_all: shareMenu.setHidden_(True) self.connectMenu.addItem_(NSMenuItem.separatorItem()) if SMUtilities.get_mounted_network_volumes(): self.connectMenu.addItemWithTitle_action_keyEquivalent_('Unmount All', self.unmountShare_, '').setTarget_(self) else: self.connectMenu.addItemWithTitle_action_keyEquivalent_('Unmount All', None, '')
def buildShareMenu(self, share): user_added_shares = SMUtilities.get_user_added_shares() shareMenu = NSMenu.alloc().init() connectMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(share.get('title'), None, '') if share.get('mount_point') in SMUtilities.get_mounted_network_volumes(): connectMenuItem.setState_(True) shareMenu.addItemWithTitle_action_keyEquivalent_('Unmount Share', self.unmountShare_, '').setTarget_(self) shareMenu.addItemWithTitle_action_keyEquivalent_('Open Folder', self.openFolderClicked_, '').setTarget_(self) else: connectMenuItem.setState_(False) shareMenu.addItemWithTitle_action_keyEquivalent_('Mount Share', self.connectToShare_, '').setTarget_(self) shareMenu.addItem_(NSMenuItem.separatorItem()) shareMenu.addItemWithTitle_action_keyEquivalent_('Connect Automatically', self.toggleAutoConnect_, '').setTarget_(self) if share.get('connect_automatically'): shareMenu.itemWithTitle_('Connect Automatically').setState_(True) shareMenu.addItemWithTitle_action_keyEquivalent_('Hide from Menu', self.toggleHideShare_, '').setTarget_(self) if share in user_added_shares: shareMenu.addItemWithTitle_action_keyEquivalent_('Remove from Menu', self.removeUserShare_, '').setTarget_(self) connectMenuItem.setSubmenu_(shareMenu) return connectMenuItem
def unmountShare_(self, sender): NSLog('User clicked {}'.format(sender.title())) mounted_volumes = SMUtilities.get_mounted_network_volumes() if sender.title() == 'Unmount All': for mounted in mounted_volumes: SMUtilities.unmount_share(mounted) else: network_share = self.config_manager.get_sharebykey('title', sender.parentItem().title()) if network_share.get('mount_point') in mounted_volumes: SMUtilities.unmount_share(network_share.get('mount_point'))
def unmountShare_(self, sender): NSLog('User clicked {}'.format(sender.title())) mounted_volumes = SMUtilities.get_mounted_network_volumes() if sender.title() == 'Unmount All': for mounted in mounted_volumes: SMUtilities.unmount_share(mounted) else: network_share = self.config_manager.get_sharebykey( 'title', sender.parentItem().title()) if network_share.get('mount_point') in mounted_volumes: SMUtilities.unmount_share(network_share.get('mount_point'))
def connectToShare_(self, sender): NSLog('User clicked {}'.format(sender.title())) try: share_title = sender.parentItem().title() except AttributeError: share_title = self.shareTitleField.stringValue() network_share = self.config_manager.get_sharebykey('title', share_title) if network_share.get('mount_point') in SMUtilities.get_mounted_network_volumes(): d = PyDialog.AlertDialog('Cannot mount "{0}"'.format(network_share.get('title')), 'Volume is already mounted at "{0}"'.format(network_share.get('mount_point'))) d.display() else: SMUtilities.mount_share(network_share.get('share_url'))
def connectToShare_(self, sender): NSLog('User clicked {}'.format(sender.title())) try: share_title = sender.parentItem().title() except AttributeError: share_title = self.shareTitleField.stringValue() network_share = self.config_manager.get_sharebykey( 'title', share_title) if network_share.get( 'mount_point') in SMUtilities.get_mounted_network_volumes(): d = PyDialog.AlertDialog( 'Cannot mount "{0}"'.format(network_share.get('title')), 'Volume is already mounted at "{0}"'.format( network_share.get('mount_point'))) d.display() else: SMUtilities.mount_share(network_share.get('share_url'))
def toggleAutoConnect_(self, sender): share = self.config_manager.get_sharebykey('title', sender.parentItem().title()) if share.get('share_type') in ['managed', 'smb_home']: existing_share, index = self.config_manager.get_managedshare_bykey('title', share.get('title')) else: existing_share, index = self.config_manager.get_useradded_bykey('title', share.get('title')) if existing_share: if existing_share.get('connect_automatically'): sender.setState_(False) existing_share['connect_automatically'] = False self.config_manager.update_share(existing_share, index) NSLog('User has set {0} to no longer connect automatically'.format(existing_share.get('title'))) else: sender.setState_(True) existing_share['connect_automatically'] = True if existing_share.get('mount_point') not in SMUtilities.get_mounted_network_volumes(): SMUtilities.mount_share(existing_share.get('share_url')) self.config_manager.update_share(existing_share, index) NSLog('User has set {0} to connect automatically.'.format(existing_share.get('title'))) if self.addShareWindow.isVisible(): self.connectAutoCheck.setState_(share.get('connect_automatically'))
def updateShareMenu(self, share_path): mounted_volumes_base_paths = [os.path.basename(mounted) for mounted in SMUtilities.get_mounted_network_volumes()] share_menu_titles = [menu_item.title() for menu_item in self.connectMenu.itemArray()] network_share = self.config_manager.get_sharebykey('mount_point', share_path) if self.ldap_reachable: NSLog('Updating menu for "{0}"'.format(network_share.get('title'))) item_index = self.connectMenu.indexOfItemWithTitle_(network_share.get('title')) self.connectMenu.removeItemAtIndex_(item_index) self.connectMenu.insertItem_atIndex_(self.buildShareMenu(network_share), item_index) # below updates the Umount All menu item for share in share_menu_titles: if share in mounted_volumes_base_paths: unmount_all = True break else: unmount_all = False unmount = self.connectMenu.itemWithTitle_('Unmount All') if unmount_all: unmount.setAction_(self.unmountShare_) unmount.setTarget_(self) else: unmount.setAction_(None) unmount.setTarget_(self)
def unmountAllShares(self): mounted_volumes = SMUtilities.get_mounted_network_volumes() for mounted in mounted_volumes: SMUtilities.unmount_share(mounted)