def _add_mount(self, widget, data=None): """Present dialog to user for creating a new mount""" keyring_manager = self._parent._application.keyring_manager # create dialog and get response from user dialog = SambaInputDialog(self._window) dialog.set_keyring_available(keyring_manager.is_available()) response = dialog.get_response() if response[0] == gtk.RESPONSE_OK: name = response[1][SambaResult.NAME] uri = self.__form_uri( response[1][SambaResult.SERVER], response[1][SambaResult.SHARE], response[1][SambaResult.DIRECTORY] ) requires_login = response[1][SambaResult.PASSWORD] != '' if requires_login: if keyring_manager.is_available(): try: # prepare attributes attributes = { 'server': uri, 'user': response[1][SambaResult.USERNAME] } # first, try to store password with keyring keyring_manager.store_password( name, response[1][SambaResult.PASSWORD], attributes, entry_type=EntryType.NETWORK ) except KeyringCreateError: # show error message print "Keyring create error, we need it to store this option" else: # store entry self.__store_mount(response[1], uri) else: # show error message print "Keyring is not available but it's needed!" else: # no login required, just store self.__store_mount(response[1], uri) # save mounts to config file self.__save_list()
def _add_mount(self, widget, data=None): """Present dialog to user for creating a new mount""" keyring_manager = self._parent._application.keyring_manager # create dialog and get response from user dialog = SambaInputDialog(self._window) dialog.set_keyring_available(keyring_manager.is_available()) response = dialog.get_response() if response[0] == gtk.RESPONSE_OK: name = response[1][SambaResult.NAME] uri = self.__form_uri(response[1][SambaResult.SERVER], response[1][SambaResult.SHARE], response[1][SambaResult.DIRECTORY]) requires_login = response[1][SambaResult.PASSWORD] != '' if requires_login: if keyring_manager.is_available(): try: # prepare attributes attributes = { 'server': uri, 'user': response[1][SambaResult.USERNAME] } # first, try to store password with keyring keyring_manager.store_password( name, response[1][SambaResult.PASSWORD], attributes, entry_type=EntryType.NETWORK) except KeyringCreateError: # show error message print "Keyring create error, we need it to store this option" else: # store entry self.__store_mount(response[1], uri) else: # show error message print "Keyring is not available but it's needed!" else: # no login required, just store self.__store_mount(response[1], uri) # save mounts to config file self.__save_list()
def _edit_mount(self, widget, data=None): """Present dialog to user for editing existing mount""" keyring_manager = self._parent._application.keyring_manager selection = self._list.get_selection() item_list, selected_iter = selection.get_selected() if selected_iter is not None: dialog = SambaInputDialog(self._window) old_name = item_list.get_value(selected_iter, SambaColumn.NAME) # set dialog parameters dialog.set_keyring_available(keyring_manager.is_available()) dialog.set_name(old_name) dialog.set_server(item_list.get_value(selected_iter, SambaColumn.SERVER)) dialog.set_share(item_list.get_value(selected_iter, SambaColumn.SHARE)) dialog.set_directory(item_list.get_value(selected_iter, SambaColumn.DIRECTORY)) dialog.set_domain(item_list.get_value(selected_iter, SambaColumn.DOMAIN)) dialog.set_username(item_list.get_value(selected_iter, SambaColumn.USERNAME)) # show editing dialog response = dialog.get_response() if response[0] == gtk.RESPONSE_OK: new_name = response[1][SambaResult.NAME] # modify list store item_list.set_value(selected_iter, SambaColumn.NAME, new_name) item_list.set_value(selected_iter, SambaColumn.SERVER, response[1][SambaResult.SERVER]) item_list.set_value(selected_iter, SambaColumn.SHARE, response[1][SambaResult.SHARE]) item_list.set_value(selected_iter, SambaColumn.DIRECTORY, response[1][SambaResult.DIRECTORY]) item_list.set_value(selected_iter, SambaColumn.DOMAIN, response[1][SambaResult.DOMAIN]) item_list.set_value(selected_iter, SambaColumn.USERNAME, response[1][SambaResult.USERNAME]) # rename entry if needed if new_name != old_name: keyring_manager.rename_entry(old_name, new_name) # form URI uri = self.__form_uri( response[1][SambaResult.SERVER], response[1][SambaResult.SHARE], response[1][SambaResult.DIRECTORY] ) item_list.set_value(selected_iter, SambaColumn.URI, uri) # save changes self.__save_list()
def _edit_mount(self, widget, data=None): """Present dialog to user for editing existing mount""" keyring_manager = self._parent._application.keyring_manager selection = self._list.get_selection() item_list, selected_iter = selection.get_selected() if selected_iter is not None: dialog = SambaInputDialog(self._window) old_name = item_list.get_value(selected_iter, SambaColumn.NAME) # set dialog parameters dialog.set_keyring_available(keyring_manager.is_available()) dialog.set_name(old_name) dialog.set_server( item_list.get_value(selected_iter, SambaColumn.SERVER)) dialog.set_share( item_list.get_value(selected_iter, SambaColumn.SHARE)) dialog.set_directory( item_list.get_value(selected_iter, SambaColumn.DIRECTORY)) dialog.set_domain( item_list.get_value(selected_iter, SambaColumn.DOMAIN)) dialog.set_username( item_list.get_value(selected_iter, SambaColumn.USERNAME)) # show editing dialog response = dialog.get_response() if response[0] == gtk.RESPONSE_OK: new_name = response[1][SambaResult.NAME] # modify list store item_list.set_value(selected_iter, SambaColumn.NAME, new_name) item_list.set_value(selected_iter, SambaColumn.SERVER, response[1][SambaResult.SERVER]) item_list.set_value(selected_iter, SambaColumn.SHARE, response[1][SambaResult.SHARE]) item_list.set_value(selected_iter, SambaColumn.DIRECTORY, response[1][SambaResult.DIRECTORY]) item_list.set_value(selected_iter, SambaColumn.DOMAIN, response[1][SambaResult.DOMAIN]) item_list.set_value(selected_iter, SambaColumn.USERNAME, response[1][SambaResult.USERNAME]) # rename entry if needed if new_name != old_name: keyring_manager.rename_entry(old_name, new_name) # form URI uri = self.__form_uri(response[1][SambaResult.SERVER], response[1][SambaResult.SHARE], response[1][SambaResult.DIRECTORY]) item_list.set_value(selected_iter, SambaColumn.URI, uri) # save changes self.__save_list()