def OnManageDone(self, evt):

        for share in sharing.SharedItem(self.collection).shares:
            self._saveAttributeFilterState(share)

        if self.IsModal():
            self.EndModal(False)
        self.Destroy()

        share = sharing.getShare(self.collection)
        needsSync = False
        if isinstance(share.conduit, sharing.RecordSetConduit):
            for filter in self.originalFilters:
                if filter not in share.conduit.filters:
                    # A filter has been removed so we need to re-synchronize
                    needsSync = True
                    break
        else:
            if share.filterAttributes != self.originalFilterAttributes:
                needsSync = True

        if needsSync:
            self.view.commit()
            sharing.scheduleNow(self.view, collection=share.contents,
                                forceUpdate=True)
    def _finishedShare(self, shareUUID):

        self.activity.completed()
        self.listener.unregister()


        # Pull in the changes from sharing view
        self.taskView.commit(sharing.mergeFunction)
        sharing.releaseView(self.taskView)
        self.view.refresh(lambda code, item, attr, val: val)

        self._showStatus(u" " + _(u"Done") + u"\n")
        self._hideUpdate()

        share = sharing.getShare(self.collection)

        self.buttonPanel.Hide()
        self.mySizer.Detach(self.buttonPanel)
        self.buttonPanel = self.resources.LoadPanel(self,
                                                    "PublishedButtonsPanel")
        self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5)

        self.Bind(wx.EVT_CLOSE,  self.OnPublishDone)
        self.Bind(wx.EVT_BUTTON, self.OnPublishDone, id=wx.ID_OK)
        self.Bind(wx.EVT_BUTTON, self.OnInvite,
                  id=wx.xrc.XRCID("BUTTON_INVITE"))
        self._resize()

        return True
    def RoundTrip(self):

        # Export
        view0 = self.views[0]
        sandbox0 = view0.findPath("//sandbox")
        coll0 = sandbox0.findPath("testCollection")
        account = sandbox0.findPath("account")

        shares = sharing.publish(coll0, account)
        self.assert_(len(shares) == 2, "Wrong number of shares created")
        share = sharing.getShare(coll0) # Get the 'main' share
        urls = sharing.getUrls(share)
        self.assert_(len(urls) == 2, "Wrong number of sharing urls")
        url = urls[0] # The read/write ticket url

        # Import
        view1 = self.views[1]
        coll1 = sharing.subscribe(view1, url)

        self.assertEqual(coll0.itsUUID, coll1.itsUUID, "Collection UUIDs "
            "don't match")

        # Make sure that the items we imported have the same displayNames
        # as the ones we exported (and no fewer, no more), and UUIDs match
        names = {}
        for item in coll0:
            names[item.displayName] = 1
        for item in coll1:
            self.assert_(item.displayName in names, "Imported item that wasn't "
             "exported")
            del names[item.displayName]
            self.assertEqual(item.displayName, self.uuids[item.itsUUID],
                "UUID of imported item doesn't match original")
        self.assert_(len(names) == 0, "Import is missing some items that were "
         "exported")
 def OnCopy(self, event):
     gotClipboard = wx.TheClipboard.Open()
     if gotClipboard:
         share = sharing.getShare(self.collection)
         urlString = (os.linesep * 2).join(sharing.getLabeledUrls(share))
         wx.TheClipboard.SetData(wx.TextDataObject(unicode(urlString)))
         wx.TheClipboard.Close()
 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 _getURLsUpdate(self, activity, status=None, **kw):
     if status == STATUS_ACTIVE:
         self._setStatusText(activity.title)
     elif status == STATUS_COMPLETE:
         count = len(self.currentTask.result or ())
         newTicketCount = 0
         
         if self.currentTask.result is None:
             # Tickets not supported; unable to fetch, etc, etc
             pass
         else:
             conduit = sharing.getShare(self.collection).conduit
             
             def updateTicket(key, ticket):
                 if getattr(conduit, key, None) != ticket.ticketId:
                     setattr(conduit, key, ticket.ticketId)
                     return 1
                 else:
                     return 0
             
             
             for ticket in self.currentTask.result:
                 if ticket.read and not ticket.write:
                     newTicketCount += updateTicket('ticketReadOnly', ticket)
                 elif ticket.read and ticket.write:
                     newTicketCount += updateTicket('ticketReadWrite', ticket)
             
         
         if count != 0:
             if newTicketCount == 0:
                 self._setStatusText(_("Checked ticket(s)."))
             else:
                 self._setStatusText(
                     _(
                         u"Received %(newTicketCount)d new ticket(s)."
                     ) % dict(newTicketCount=newTicketCount)
                 )
         else:
             self._setStatusText(_(u"Unable to check ticket(s)."))
         
         conduit.itsView.commit() # we changed something eh
         self.update(tryToFetch=False)
                 
     elif status == STATUS_FAILED:
         self._setStatusText(
             _(u"Unable to check tickets: See chandler.log for details.")
         )
         sharing.logger.warning("Unable to check tickets: %s",
                                "\n".join(self.currentTask.result))
         self.update(tryToFetch=False)
    def update(self, tryToFetch=True):
        share = sharing.getShare(self.collection)

        if tryToFetch:
            url = share.getLocation(privilege='ticketdiscovery')
            self.CopyButton.Enable(False)
            urlText = ''
            self.getInviteURLs(share, url)
        else:
            urlText = _(u"Give out the URL(s) below to invite others to "
                         "subscribe to '%(collection)s':") % {
                            'collection' : self.collection.displayName
                        }
            urlString = (os.linesep * 2).join(sharing.getLabeledUrls(share))

            urlText = "%s%s%s" % (urlText, (os.linesep * 2), urlString)

            self.CopyButton.Enable(True)
            
        self._setURLText(urlText)
Beispiel #8
0
    def RoundTrip(self):

        # Export
        view0 = self.views[0]
        sandbox0 = view0.findPath("//sandbox")
        coll0 = sandbox0.findPath("testCollection")
        account = sandbox0.findPath("account")

        shares = sharing.publish(coll0, account)
        self.assert_(len(shares) == 2, "Wrong number of shares created")
        share = sharing.getShare(coll0)  # Get the 'main' share
        urls = sharing.getUrls(share)
        self.assert_(len(urls) == 2, "Wrong number of sharing urls")
        url = urls[0]  # The read/write ticket url

        # Import
        view1 = self.views[1]
        coll1 = sharing.subscribe(view1, url)

        self.assertEqual(coll0.itsUUID, coll1.itsUUID, "Collection UUIDs "
                         "don't match")

        # Make sure that the items we imported have the same displayNames
        # as the ones we exported (and no fewer, no more), and UUIDs match
        names = {}
        for item in coll0:
            names[item.displayName] = 1
        for item in coll1:
            self.assert_(item.displayName in names,
                         "Imported item that wasn't "
                         "exported")
            del names[item.displayName]
            self.assertEqual(item.displayName, self.uuids[item.itsUUID],
                             "UUID of imported item doesn't match original")
        self.assert_(
            len(names) == 0, "Import is missing some items that were "
            "exported")
    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"))
Beispiel #10
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()