コード例 #1
0
    def OnNewAccount(self, evt):

        selection = self.choiceNewType.GetSelection()
        if selection == 0:
            return

        accountType = self.choiceNewType.GetClientData(selection)
        self.choiceNewType.SetSelection(0)

        if accountType == "IMAP":
            item = Mail.IMAPAccount(view=self.view)
        elif accountType == "POP":
            item = Mail.POPAccount(view=self.view)
        elif accountType == "SMTP":
            item = Mail.SMTPAccount(view=self.view)
        elif accountType == "WebDAV":
            item = Sharing.WebDAVAccount(view=self.view)

        accountName = "New %s account" % accountType
        item.displayName = accountName

        values = {}

        for (field, desc) in PANELS[accountType]['fields'].iteritems():

            if desc['type'] == 'currentPointer':
                setting = False

            elif desc['type'] == 'itemRef':
                setting = None

            else:
                try:
                    setting = desc['default']
                except KeyError:
                    setting = DEFAULTS[desc['type']]

            values[field] = setting

        self.data.append({
            "item": item.itsUUID,
            "values": values,
            "type": accountType,
            "isNew": True
        })

        index = self.accountsList.Append(accountName)
        self.accountsList.SetSelection(index)
        self.__SwapDetailPanel(index)
コード例 #2
0
    def __ApplyChanges(self):
        """ Take the data from the list and apply the values to the items. """

        # First store the current form values to the data structure
        self.__StoreFormData(self.currentPanelType, self.currentPanel,
                             self.data[self.currentIndex]['values'])

        for account in self.data:

            uuid = account['item']

            if uuid:
                # We already have an account item created
                item = self.view.findUUID(account['item'])

            else:
                # We need to create an account item

                if account['type'] == "IMAP":
                    item = Mail.IMAPAccount(view=self.view)

                elif account['type'] == "POP":
                    item = Mail.POPAccount(view=self.view)

                elif account['type'] == "SMTP":
                    item = Mail.SMTPAccount(view=self.view)

                    #XXX: Temp change that checks if no SMTP Account currently
                    #     exists and makes the new account the defaultSMTPAccount
                    #     for the default IMAP ccount

                    if Mail.getCurrentSMTPAccount(view=self.view)[0] is None:
                        mailAccount = Mail.getCurrentMailAccount(
                            view=self.view)

                        if mailAccount is not None:
                            mailAccount.defaultSMTPAccount = item

                elif account['type'] == "WebDAV":
                    item = Sharing.WebDAVAccount(view=self.view)

            values = account['values']
            panel = PANELS[account['type']]

            if panel.has_key("saveHandler"):
                # Call custom save handler; if None returned, we don't do
                # any more processing of that account within this loop
                item = panel["saveHandler"](item, panel['fields'], values)

            if item is not None:
                # Process each field defined in the PANEL data structure;
                # applying the values to the appropriate attributes:

                for (field, desc) in panel['fields'].iteritems():

                    if desc['type'] == 'currentPointer':
                        # If this value is True, make this item current:
                        if values[field]:
                            app = schema.ns('osaf.app', self.view)
                            ref = getattr(app, desc['pointer'])
                            ref.item = item

                    elif desc['type'] == 'itemRef':
                        # Find the item for this UUID and assign the itemref:
                        if values[field]:
                            item.setAttributeValue(
                                desc['attr'],
                                self.view.findUUID(values[field]))

                    else:
                        # Otherwise, make the literal assignment:
                        try:
                            item.setAttributeValue(desc['attr'], values[field])
                        except:
                            pass