def OnUnPubSub(self, evt):
     share = sharing.getShare(self.collection)
     if sharing.isSharedByMe(share):
         sharing.unpublish(self.collection)
     else:
         sharing.unsubscribe(self.collection)
     if self.IsModal():
         self.EndModal(False)
     self.Destroy()
    def ShowManagePanel(self):
        # "Manage" mode -- i.e., the collection has already been shared

        self.Bind(wx.EVT_BUTTON, self.OnManageDone, id=wx.ID_OK)
        self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
        self.Bind(wx.EVT_BUTTON, self.OnInvite,
                  id=wx.xrc.XRCID("BUTTON_INVITE"))
        self.Bind(wx.EVT_BUTTON, self.OnUnPubSub,
                  id=wx.xrc.XRCID("BUTTON_UNPUBLISH"))

        view = self.collection.itsView
        name = self.collection.displayName
        wx.xrc.XRCCTRL(self, "TEXT_MANAGE_COLLNAME").SetLabel(name)

        share = sharing.getShare(self.collection)
        self.share = share
        account = getattr(share.conduit, 'account', None)
        if account is not None:
            name = share.conduit.account.displayName
        else:
            name = _(u"(via ticket)")
        wx.xrc.XRCCTRL(self, "TEXT_ACCOUNT").SetLabel(name)

        if hasattr(share, 'lastSuccess'):
            lastSync = SharingDetails.formatDateTime(view, share.lastSuccess)
        else:
            lastSync = _(u"Unknown")
        wx.xrc.XRCCTRL(self, "TEXT_SUCCESS").SetLabel(lastSync)

        self.UnPubSub = wx.xrc.XRCCTRL(self, "BUTTON_UNPUBLISH")

        share = sharing.getShare(self.collection)
        if sharing.isSharedByMe(share):
            self.UnPubSub.SetLabel(_(u"Unpublish"))
        else:
            self.UnPubSub.SetLabel(_(u"Unsubscribe"))


        self.CheckboxShareAlarms = wx.xrc.XRCCTRL(self, "CHECKBOX_ALARMS")
        self.CheckboxShareAlarms.Enable(True)
        self.CheckboxShareStatus = wx.xrc.XRCCTRL(self, "CHECKBOX_STATUS")
        self.CheckboxShareStatus.Enable(True)
        self.CheckboxShareTriage = wx.xrc.XRCCTRL(self, "CHECKBOX_TRIAGE")
        self.CheckboxShareTriage.Enable(True)
        self.CheckboxShareReply = wx.xrc.XRCCTRL(self, "CHECKBOX_REPLY")
        self.CheckboxShareReply.Enable(True)
        self.CheckboxShareBcc = wx.xrc.XRCCTRL(self, "CHECKBOX_BCC")
        self.CheckboxShareBcc.Enable(True)

        if isinstance(share.conduit, sharing.RecordSetConduit):
            self.originalFilters = set(share.conduit.filters)

        else:
            self.originalFilterAttributes = list(share.filterAttributes)

        self._loadAttributeFilterState(share)


        if getattr(share, "error", None):
            self._showErrorPanel()


        self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK"))
예제 #3
0
def save(rv, filename):
    """
    Save selected settings information, including all sharing accounts
    and shares (whether published or subscribed), to an INI file.

    @param rv:       Repository view
    @param filename: File to save settings into
    """

    cfg = ConfigObj()
    cfg.encoding = "UTF8"
    cfg.filename = filename

    # Sharing accounts
    counter = 1
    for account in sharing.SharingAccount.iterItems(rv):
        if account.username: # skip account if not configured
            section_name = u"sharing_account_%d" % counter
            cfg[section_name] = {}
            if isinstance(account, sharing.HubAccount):
                cfg[section_name][u"type"] = u"hub account"
            elif isinstance(account, sharing.CosmoAccount):
                cfg[section_name][u"type"] = u"cosmo account"
            else:
                cfg[section_name][u"type"] = u"webdav account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"path"] = account.path
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)
            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"usessl"] = account.useSSL
            counter += 1
            
    # Subscriptions
    mine = schema.ns("osaf.pim", rv).mine
    counter = 1
    sidebar = schema.ns("osaf.app", rv).sidebarCollection
    for col in sidebar:
        share = sharing.getShare(col)
        if share:
            section_name = u"share_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"share"
            cfg[section_name][u"title"] = share.contents.displayName
            cfg[section_name][u"mine"] = col in mine.sources
            uc = usercollections.UserCollection(col)
            if getattr(uc, "color", False):
                color = uc.color
                cfg[section_name][u"red"] = color.red
                cfg[section_name][u"green"] = color.green
                cfg[section_name][u"blue"] = color.blue
                cfg[section_name][u"alpha"] = color.alpha
            urls = sharing.getUrls(share)
            if sharing.isSharedByMe(share):
                cfg[section_name][u"publisher"] = u"True"
                if isinstance(share.conduit, sharing.CosmoConduit):
                    c = share.conduit
                    cfg[section_name][u"url"] = c.getLocation(morsecode=True)
                else:
                    cfg[section_name][u"url"] = share.getLocation()
            else:
                cfg[section_name][u"publisher"] = u"False"
                url = share.getLocation()
                cfg[section_name][u"url"] = url
                if url != urls[0]:
                    cfg[section_name][u"ticket"] = urls[0]
            if isinstance(share.conduit, sharing.RecordSetConduit):
                c = share.conduit
                cfg[section_name][u"filters"] = ",".join(c.filters)
            counter += 1

    # SMTP accounts
    counter = 1
    currentAccount = getattr(schema.ns("osaf.pim", rv).currentOutgoingAccount,
                             "item", None)

    for account in pim.mail.SMTPAccount.iterItems(rv):
        if account.isActive and account.host:
            section_name = u"smtp_account_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"smtp account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"auth"] = account.useAuth
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)

            if currentAccount and account is currentAccount:
                cfg[section_name][u"default"] = u"True"

            if account.fromAddress:
                cfg[section_name][u"name"] = account.fromAddress.fullName
                cfg[section_name][u"address"] = account.fromAddress.emailAddress

            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"security"] = account.connectionSecurity
            counter += 1

    # IMAP accounts
    currentAccount = getattr(schema.ns("osaf.pim", rv).currentIncomingAccount,
                             "item", None)
    counter = 1
    for account in pim.mail.IMAPAccount.iterItems(rv):
        if account.isActive and account.host:
            section_name = u"imap_account_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"imap account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)

            if account.replyToAddress:
                cfg[section_name][u"name"] = account.replyToAddress.fullName
                cfg[section_name][u"address"] = account.replyToAddress.emailAddress

            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"security"] = account.connectionSecurity

            if currentAccount and account is currentAccount:
                cfg[section_name][u"default"] = u"True"

            folderNum = len(account.folders)

            if folderNum:
                cfg[section_name]["imap_folder_num"] = folderNum

                fCounter = 0

                for folder in account.folders:
                    fname = "imap_folder_%d" % fCounter
                    cfg[section_name][fname] = {}
                    cfg[section_name][fname][u"type"] = u"imap folder"
                    cfg[section_name][fname][u"uuid"] = folder.itsUUID
                    cfg[section_name][fname][u"title"] = folder.displayName
                    cfg[section_name][fname][u"name"] = folder.folderName
                    cfg[section_name][fname][u"type"] = folder.folderType
                    # Commented out for 1.0. These features are not
                    # supported in the Chandler UI. So leave them out
                    # of the ini files as well.
                    #cfg[section_name][fname][u"max"] = folder.downloadMax
                    #cfg[section_name][fname][u"del"] = folder.deleteOnDownload
                    fCounter += 1

            counter += 1

    # POP accounts
    currentAccount = getattr(schema.ns("osaf.pim", rv).currentIncomingAccount,
                             "item", None)


    counter = 1
    for account in pim.mail.POPAccount.iterItems(rv):
        if account.isActive and account.host:
            section_name = u"pop_account_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"pop account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)

            if account.replyToAddress:
                cfg[section_name][u"name"] = account.replyToAddress.fullName
                cfg[section_name][u"address"] = account.replyToAddress.emailAddress

            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"security"] = account.connectionSecurity
            cfg[section_name][u"del"] = account.deleteOnDownload

            if currentAccount and account is currentAccount:
                cfg[section_name][u"default"] = u"True"
            counter += 1

    # Show timezones
    cfg[u"timezones"] = {}
    showTZ = schema.ns("osaf.pim", rv).TimezonePrefs.showUI
    cfg[u"timezones"][u"type"] = u"show timezones"
    cfg[u"timezones"][u"show_timezones"] = showTZ

    # Visible hours
    cfg[u"visible_hours"] = {}
    cfg[u"visible_hours"][u"type"] = u"visible hours"
    calPrefs = schema.ns("osaf.framework.blocks.calendar", rv).calendarPrefs
    cfg[u"visible_hours"][u"height_mode"] = calPrefs.hourHeightMode
    cfg[u"visible_hours"][u"num_hours"] = calPrefs.visibleHours

    # Master password
    prefs = schema.ns("osaf.framework.MasterPassword", rv).masterPasswordPrefs
    cfg[u"master_password"] = {}
    cfg[u"master_password"][u"masterPassword"] = prefs.masterPassword
    cfg[u"master_password"][u"timeout"] = prefs.timeout
    if hasattr(prefs, "protect"):
        cfg[u"master_password"][u"protect"] = prefs.protect

    # password, we'll just use the master password section as they are tied
    dummy = schema.ns("osaf.framework.password", rv).passwordPrefs.dummyPassword
    savePassword(cfg[u"master_password"], dummy, sectionName=u"dummyPassword")

    cfg.write()