Example #1
0
 def setKopeteAccounts(self):
     "Add imported accounts into Kopete"
     config = KConfig("kopeterc")
     for account in self.accounts:
         if account["type"] == "Jabber":
             groupname = "Account_JabberProtocol_" + account["user"]
             if not config.hasGroup(groupname):
                 pluginsGroup = config.group("Plugins")
                 pluginsGroup.writeEntry("kopete_jabberEnabled", "true")
                 accountGroup = config.group(groupname)
                 accountGroup.writeEntry("AccountId", account["user"])
                 accountGroup.writeEntry("Protocol", "JabberProtocol")
                 accountGroup.writeEntry("CustomServer", "true")
                 accountGroup.writeEntry("Server", account["host"])
                 accountGroup.writeEntry("Port", account["port"])
                 if account["SSL"]:
                     accountGroup.writeEntry("UseSSL", "true")
         elif account["type"] == "MSN":
             groupname = "Account_MSNProtocol_" + account["mail"]
             if not config.hasGroup(groupname):
                 pluginsGroup = config.group("Plugins")
                 pluginsGroup.writeEntry("kopete_msnEnabled", "true")
                 accountGroup = config.group(groupname)
                 accountGroup.writeEntry("AccountId", account["mail"])
                 accountGroup.writeEntry("Protocol", "MSNProtocol")
                 accountGroup.writeEntry("serverName",
                                         "messenger.hotmail.com")
                 accountGroup.writeEntry("serverPort", 1863)
     config.sync()
Example #2
0
 def setKopeteAccounts(self):
     "Add imported accounts into Kopete"
     config = KConfig("kopeterc")
     for account in self.accounts:
         if account["type"] == "Jabber":
             groupname = "Account_JabberProtocol_" + account["user"]
             if not config.hasGroup(groupname):
                 pluginsGroup = config.group("Plugins")
                 pluginsGroup.writeEntry("kopete_jabberEnabled", "true")
                 accountGroup = config.group(groupname)
                 accountGroup.writeEntry("AccountId", account["user"])
                 accountGroup.writeEntry("Protocol", "JabberProtocol")
                 accountGroup.writeEntry("CustomServer", "true")
                 accountGroup.writeEntry("Server", account["host"])
                 accountGroup.writeEntry("Port", account["port"])
                 if account["SSL"]:
                     accountGroup.writeEntry("UseSSL", "true")
         elif account["type"] == "MSN":
             groupname = "Account_MSNProtocol_" + account["mail"]
             if not config.hasGroup(groupname):
                 pluginsGroup = config.group("Plugins")
                 pluginsGroup.writeEntry("kopete_msnEnabled", "true")
                 accountGroup = config.group(groupname)
                 accountGroup.writeEntry("AccountId", account["mail"])
                 accountGroup.writeEntry("Protocol", "MSNProtocol")
                 accountGroup.writeEntry("serverName", "messenger.hotmail.com")
                 accountGroup.writeEntry("serverPort", 1863)
     config.sync()
Example #3
0
class StateManager(object):
    """Manages state and meta-info for documents.
    
    Asks Documents to save information like bookmarks and cursor position, etc.
    The information is saved in the 'metainfos' config file in the applications
    data directory.
    
    """
    def __init__(self, app):
        self.app = app
        self.metainfos = KConfig("metainfos", KConfig.NoGlobals, "appdata")
        
    def groupForUrl(self, url, create=False):
        """Returns a KConfigGroup for the given KUrl.
        
        Returns None if the group does not exist and create==False.
        
        """
        if not url.isEmpty():
            encodedurl = url.prettyUrl()
            if create or self.metainfos.hasGroup(encodedurl):
                return self.metainfos.group(encodedurl.encode('utf-8'))
            
    def loadState(self, doc):
        """Asks the Document to read its state from our config."""
        group = self.groupForUrl(doc.url())
        if group:
            last = group.readEntry("time", 0.0)
            # when it is a local file, only load the state when the
            # file was not modified later
            if not doc.localPath() or (
                    os.path.exists(doc.localPath()) and
                    os.path.getmtime(doc.localPath()) <= last):
                doc.readConfig(group)
            
    def saveState(self, doc):
        """Asks the Document to save its state to our config."""
        if doc.view and not doc.url().isEmpty():
            group = self.groupForUrl(doc.url(), True)
            group.writeEntry("time", time.time())
            doc.writeConfig(group)
            group.sync()
            
    def cleanup(self):
        """Purge entries that are not used for more than a month."""
        for g in self.metainfos.groupList():
            group = self.metainfos.group(g.encode('utf-8'))
            last = group.readEntry("time", 0.0)
            if (time.time() - last) / 86400 > 31:
                group.deleteGroup()
        self.metainfos.sync()
Example #4
0
class ExpandManager(ShortcutClient):
    def __init__(self, mainwin):
        self.mainwin = mainwin
        ShortcutClient.__init__(self, mainwin.expansionShortcuts)
        self.expansions = KConfig("expansions", KConfig.NoGlobals, "appdata")
        # delete shortcut actions that do not exist here anymore
        self.shakeHands(self.expansionsList())
        
    def actionTriggered(self, name):
        return self.doExpand(name)
        
    def populateAction(self, name, action):
        action.setText(self.description(name))
        
    def expand(self):
        """
        Reads the last word in the current document. If it is not
        an expansion, open the expansion dialog. If the string matches
        multiple possible expansions, also open the dialog with the matching
        expansions shown.
        """
        doc = self.mainwin.currentDocument()
        cursor = doc.view.cursorPosition()
        lastWord = re.split("\W+",
            doc.line()[:cursor.column()])[-1]
        
        if lastWord and self.expansionExists(lastWord):
            # delete entered expansion name
            begin = KTextEditor.Cursor(cursor)
            begin.setColumn(begin.column() - len(lastWord))
            # write the expansion
            self.doExpand(lastWord, remove=KTextEditor.Range(begin, cursor))
            return
        # open dialog and let the user choose
        self.expansionDialog().show()
        
    @cacheresult
    def expansionDialog(self):
        return ExpansionDialog(self)

    def expansionExists(self, name):
        return (self.expansions.hasGroup(name) and
                self.expansions.group(name).hasKey("Name"))

    def expansionsList(self):
        """
        Return list of all defined shortcuts.
        """
        return [name for name in self.expansions.groupList()
                     if self.expansions.group(name).hasKey("Name")]

    def description(self, name):
        """
        Return the description for the expansion name.
        """
        return self.expansions.group(name).readEntry("Name", "")
    
    def doExpand(self, expansion, remove=None):
        """
        Perform the given expansion, must exist.
        if remove is given, use doc.replaceText to replace that Range.
        """
        doc = self.mainwin.currentDocument()
        
        group = self.expansions.group(expansion)
        text = group.readEntry("Text", "")
        
        # where to insert the text:
        cursor = remove and remove.start() or doc.view.cursorPosition()
        
        # translate pitches (marked by @)
        # find the current language
        lang = ly.parse.documentLanguage(doc.textToCursor(cursor))
        writer = ly.pitch.pitchWriter[lang or "nederlands"]
        reader = ly.pitch.pitchReader["nederlands"]
        
        def repl(matchObj):
            pitch = matchObj.group(1)
            result = reader(pitch)
            if result:
                note, alter = result
                return writer(note, alter)
            return matchObj.group()
            
        text = re.sub(r"@([a-z]+)(?!\.)", repl, text)
            
        # if the expansion starts with a backslash and the character just 
        # before the cursor is also a backslash, don't repeat it.
        if (text.startswith("\\") and cursor.column() > 0
            and doc.line()[cursor.column()-1] == "\\"):
            text = text[1:]
        
        doc.manipulator().insertTemplate(text, cursor, remove)

    def addExpansion(self, text = None):
        """ Open the expansion dialog with a new expansion given in text. """
        dlg = self.expansionDialog()
        dlg.show()
        dlg.addItem(text)