def showTempPasswordDialog(self): """ Sets overridePassword for a server. Using this one doesn't actually have to enter the password in the ServerDialog (and by extension save to disk). """ serverList = ServerList() # Create a stringlist to be used by the qinputdialog stringList = [] for server in serverList.getTable(): stringList.append(server.name) # Display list of servers (serverString, ok) = QInputDialog.getItem( self, QApplication.translate("MainWindow", "Select server"), QApplication.translate("MainWindow", "Server:"), stringList, editable=False ) if ok: server = serverList.getServerObjectByName(serverString) if server != None: # Ask for password (value, ok) = QInputDialog.getText( self, QApplication.translate("MainWindow", "Temporary password"), QApplication.translate("MainWindow", "Enter password:"), QLineEdit.Password ) if ok: # Use value as the overridePassword for the server. LumaConnection(server).overridePassword(value)
def showTempPasswordDialog(self): """ Sets overridePassword for a server. Using this one doesn't actually have to enter the password in the ServerDialog (and by extension save to disk). """ serverList = ServerList() # Create a stringlist to be used by the qinputdialog stringList = [] for server in serverList.getTable(): stringList.append(server.name) # Display list of servers (serverString, ok) = QInputDialog.getItem( self, QApplication.translate("MainWindow", "Select server"), QApplication.translate("MainWindow", "Server:"), stringList, editable=False) if ok: server = serverList.getServerObjectByName(serverString) if server != None: # Ask for password (value, ok) = QInputDialog.getText( self, QApplication.translate("MainWindow", "Temporary password"), QApplication.translate("MainWindow", "Enter password:"), QLineEdit.Password) if ok: # Use value as the overridePassword for the server. LumaConnection(server).overridePassword(value)
class SearchPlugin(QWidget, Ui_SearchPlugin): """The Luma Search plugin.""" __logger = logging.getLogger(__name__) def __init__(self, parent=None): super(SearchPlugin, self).__init__(parent) self.setupUi(self) self.setObjectName('SearchPlugin') self.openTabs = {} self.completer = None self.currentServer = None #self.connection = None self.resultSetCount = 0 self.serverListObject = ServerList() self.serverList = self.serverListObject.getTable() self.searchForm = SearchForm(parent=self) self.filterBuilder = FilterBuilder(parent=self) # Icons searchIcon = iconFromTheme( 'edit-find', ':/icons/32/edit-find') filterIcon = iconFromTheme( 'edit-find-replace', ':/icons/32/edit-find-replace') secureIcon = iconFromTheme( 'object-locked', ':/icons/16/object-locked') errorIcon = pixmapFromTheme( 'dialog-error', ':/icons/48/dialog-error', 24, 24) undoIcon = iconFromTheme( 'edit-undo', ':/icons/32/edit-undo') redoIcon = iconFromTheme( 'edit-redo', ':/icons/32/edit-redo') addIcon = iconFromTheme( 'list-add', ':/icons/32/list-add') self.indexSF = self.left.addTab(self.searchForm, searchIcon, '') self.indexFB = self.left.addTab(self.filterBuilder, filterIcon, '') self.searchForm.filterBuilderToolButton.setIcon(filterIcon) self.searchForm.errorIcon.setPixmap(errorIcon) self.filterBuilder.undoButton.setIcon(undoIcon) self.filterBuilder.redoButton.setIcon(redoIcon) self.filterBuilder.addSpecialCharButton.setIcon(addIcon) # The search plugin event filter we # use for acting upon various events eventFilter = SearchPluginEventFilter(self) # Install the eventFilter on desired widgets self.installEventFilter(eventFilter) self.right.installEventFilter(eventFilter) self.right.setUsesScrollButtons(True) self.__loadSettings() self.__connectSlots() # Only add text to these class and its children at this time self.retranslate(all=False) # TODO: maybe we allways want to return a list from ServerList, # eliminating the 'NoneType is not iterable' exceptions. if not self.serverList is None: for server in self.serverList: # As documendted in the ServerObject class: # 0 = Unencrypted, 1 = TLS, 2 = SSL if server.encryptionMethod == 0: self.searchForm.serverBox.addItem(server.name) else: self.searchForm.serverBox.addItem(secureIcon, server.name) def __connectSlots(self): """Connects signals and slots.""" self.right.tabCloseRequested[int].connect(self.onTabClose) # Filter Builder signals and slots self.filterBuilder.filterSaved.connect(self.loadFilterBookmarks) self.filterBuilder.useFilterRequest.connect(self.onUseFilterRequested) # Search Form signals and slots self.searchForm.searchButton.clicked.connect( self.onSearchButtonClicked) self.searchForm.filterBuilderToolButton.clicked.connect( self.onFilterBuilderButtonClicked) self.searchForm.serverBox.currentIndexChanged[int].connect( self.onServerChanged) def __loadSettings(self): """Loads the plugin settings if available. """ s = PluginSettings('search') self.autocompleteIsEnabled = s.pluginValue( 'autocomplete', False).toBool() self.searchForm.scope = s.pluginValue('scope', 2).toInt()[0] self.searchForm.sizeLimit = s.pluginValue('limit', 0).toInt()[0] self.filterBuilder.setFilterHighlighter( s.pluginValue('highlighting', False).toBool()) # Try to fetch the luma config prefix from the settings file, # and call the loadFilterBookmarks to populate search box self.configPrefix = s.configPrefix self.loadFilterBookmarks() def loadFilterBookmarks(self): """Reads the saved filter bookmarks from disk. The filter bookmarks is then passed to the search form widget. """ try: filterFile = os.path.join(self.configPrefix, 'filters') # We only try to read the filters file from disk if it # already exists. If not we do nothing, as it will be # created in the filter wizard if the user choose to do so. if os.path.isfile(filterFile): bookmarks = [] with open(filterFile, 'r+') as f: #bookmarks = f.readLines() for filter in f: bookmarks.append(filter.strip().decode('utf-8')) self.searchForm.populateFilterBookmarks(bookmarks) except IOError, e: msg = 'Unable to read file: {0} Reason:\n\t{1}' self.__logger.error(msg.format(filterFile, str(e)))
class SLTest(unittest.TestCase): """ Store the serverlist in this directory. """ def setUp(self): #print "setUp" self.sl = ServerList(tempfile.gettempdir(), "serverlisttest.xml") #self.sl.__configFile = os.path.join(self.sl._configPrefix, "serverlist.xml") def tearDown(self): pass """ Writes a serverlist in the current format to disk. """ def writeList(self): #print "writeList" try: f = open(self.sl.getConfigFilePath(), "w") f.write(""" <!DOCTYPE LumaServerFile> <LumaServerList version="1.2"> <LumaLdapServer port="1337" clientCertFile="" followAliases="0" clientCertKeyfile="" bindPassword="******" useCertificate="0" bindDN="" host="directory.d-trust.de" authMethod="1" bindAnon="1" encryptionMethod="0" name="d-trust" autoBase="0" checkServerCertificate="1"> <baseDNs> <base dn="dc=d-trust,dc=de"/> <base dn="dc=ntnu,dc=no.TULL"/> </baseDNs> </LumaLdapServer> <LumaLdapServer port="389" clientCertFile="" followAliases="0" clientCertKeyfile="" bindPassword="******" useCertificate="0" bindDN="" host="at.ntnu.no" authMethod="6" bindAnon="1" encryptionMethod="2" name="ntnu" autoBase="1" checkServerCertificate="2"> <baseDNs> <base dn="dc=lol,dc=com"/> <base dn="dc=ntnu,dc=no"/> </baseDNs> </LumaLdapServer> <LumaLdapServer port="392" clientCertFile="" followAliases="1" clientCertKeyfile="" bindPassword="******" useCertificate="0" bindDN="" host="x500.bund.de" authMethod="0" bindAnon="1" encryptionMethod="1" name="bund" autoBase="0" checkServerCertificate="0"> <baseDNs> <base dn="dc=bund,dc=de"/> </baseDNs> </LumaLdapServer> </LumaServerList> """) f.close() except IOError: print "----------------------" print "WRITE TO DISK FAILED!" print "----------------------" raise def getEmptyServerObject(self): #print "getEmptryServerObject" return ServerObject() """ Read and write and emtpy serverlist to/from disk. """ def testEmptyList(self): #print "testEmptyList" self.sl.setTable([]) self.sl.writeServerList() self.sl.readServerList() self.assertEqual(self.sl.getTable(), []) """ Tests for Read, delete, add and write, better than one BIG test, but each test is still a bit to dependent on the previous tests """ def testAdd(self): #print "testAdd" # Remove and add back the removed item self.sl.addServer(self.getEmptyServerObject()) # Check if it has been added correctly self.assertNotEqual(None, self.sl.getServerObject("")) def testDelete(self): #print "testDelete" # Delete and see if object still in list self.sl.setTable([self.getEmptyServerObject()]) self.assertNotEqual(None, self.sl.getServerObject("")) self.sl.deleteServer("") self.assertEqual(None, self.sl.getServerObject("")) def testRead(self): #print "testRead" # Write the list to disk and have ServerList read it. self.writeList() self._modifyTime = None #IMPORTANT - FORCES READ FROM DISK self.sl.readServerList() # Check that the server list was read correctly self.assertNotEqual(None, self.sl.getServerObject("d-trust")) self.assertNotEqual(None, self.sl.getServerObject("bund")) self.assertNotEqual(None, self.sl.getServerObject("ntnu")) def testWrite(self): #print "testWrite" # Write the list back to disk and read it back self.sl.setTable([self.getEmptyServerObject()]) self.sl.writeServerList() f = open(self.sl.getConfigFilePath(), "r") s = """ <!DOCTYPE LumaServerFile> <LumaServerList version="1.2"> <LumaLdapServer port="389" clientCertFile="" followAliases="0" bindPassword="" useCertificate="0" clientCertKeyFile="" bindDN="" host="" authMethod="0" bindAnon="1" encryptionMethod="0" name="" autoBase="1" checkServerCertificate="0"> <baseDNs/> </LumaLdapServer> </LumaServerList> """ #Verify the list is good read = f.read() f.close() s = s.strip() r = read.strip() self.assertEqual(s, r)
class SearchPlugin(QWidget, Ui_SearchPlugin): """The Luma Search plugin.""" __logger = logging.getLogger(__name__) def __init__(self, parent=None): super(SearchPlugin, self).__init__(parent) self.setupUi(self) self.setObjectName('SearchPlugin') self.openTabs = {} self.completer = None self.currentServer = None #self.connection = None self.resultSetCount = 0 self.serverListObject = ServerList() self.serverList = self.serverListObject.getTable() self.searchForm = SearchForm(parent=self) self.filterBuilder = FilterBuilder(parent=self) # Icons searchIcon = iconFromTheme('edit-find', ':/icons/32/edit-find') filterIcon = iconFromTheme('edit-find-replace', ':/icons/32/edit-find-replace') secureIcon = iconFromTheme('object-locked', ':/icons/16/object-locked') errorIcon = pixmapFromTheme('dialog-error', ':/icons/48/dialog-error', 24, 24) undoIcon = iconFromTheme('edit-undo', ':/icons/32/edit-undo') redoIcon = iconFromTheme('edit-redo', ':/icons/32/edit-redo') addIcon = iconFromTheme('list-add', ':/icons/32/list-add') self.indexSF = self.left.addTab(self.searchForm, searchIcon, '') self.indexFB = self.left.addTab(self.filterBuilder, filterIcon, '') self.searchForm.filterBuilderToolButton.setIcon(filterIcon) self.searchForm.errorIcon.setPixmap(errorIcon) self.filterBuilder.undoButton.setIcon(undoIcon) self.filterBuilder.redoButton.setIcon(redoIcon) self.filterBuilder.addSpecialCharButton.setIcon(addIcon) # The search plugin event filter we # use for acting upon various events eventFilter = SearchPluginEventFilter(self) # Install the eventFilter on desired widgets self.installEventFilter(eventFilter) self.right.installEventFilter(eventFilter) self.right.setUsesScrollButtons(True) self.__loadSettings() self.__connectSlots() # Only add text to these class and its children at this time self.retranslate(all=False) # TODO: maybe we allways want to return a list from ServerList, # eliminating the 'NoneType is not iterable' exceptions. if not self.serverList is None: for server in self.serverList: # As documendted in the ServerObject class: # 0 = Unencrypted, 1 = TLS, 2 = SSL if server.encryptionMethod == 0: self.searchForm.serverBox.addItem(server.name) else: self.searchForm.serverBox.addItem(secureIcon, server.name) def __connectSlots(self): """Connects signals and slots.""" self.right.tabCloseRequested[int].connect(self.onTabClose) # Filter Builder signals and slots self.filterBuilder.filterSaved.connect(self.loadFilterBookmarks) self.filterBuilder.useFilterRequest.connect(self.onUseFilterRequested) # Search Form signals and slots self.searchForm.searchButton.clicked.connect( self.onSearchButtonClicked) self.searchForm.filterBuilderToolButton.clicked.connect( self.onFilterBuilderButtonClicked) self.searchForm.serverBox.currentIndexChanged[int].connect( self.onServerChanged) def __loadSettings(self): """Loads the plugin settings if available. """ s = PluginSettings('search') self.autocompleteIsEnabled = s.pluginValue('autocomplete', False).toBool() self.searchForm.scope = s.pluginValue('scope', 2).toInt()[0] self.searchForm.sizeLimit = s.pluginValue('limit', 0).toInt()[0] self.filterBuilder.setFilterHighlighter( s.pluginValue('highlighting', False).toBool()) # Try to fetch the luma config prefix from the settings file, # and call the loadFilterBookmarks to populate search box self.configPrefix = s.configPrefix self.loadFilterBookmarks() def loadFilterBookmarks(self): """Reads the saved filter bookmarks from disk. The filter bookmarks is then passed to the search form widget. """ try: filterFile = os.path.join(self.configPrefix, 'filters') # We only try to read the filters file from disk if it # already exists. If not we do nothing, as it will be # created in the filter wizard if the user choose to do so. if os.path.isfile(filterFile): bookmarks = [] with open(filterFile, 'r+') as f: #bookmarks = f.readLines() for filter in f: bookmarks.append(filter.strip().decode('utf-8')) self.searchForm.populateFilterBookmarks(bookmarks) except IOError, e: msg = 'Unable to read file: {0} Reason:\n\t{1}' self.__logger.error(msg.format(filterFile, str(e)))