def onShareItemEvent(self, event): """ Share an ItemCollection. """ itemCollection = event.arguments["item"] # Make sure we have all the accounts; returns False if the user cancels # out and we don't. if not Sharing.ensureAccountSetUp(self.itsView): return webdavAccount = Sharing.getWebDAVAccount(self.itsView) # commit changes, since we'll be switching to Twisted thread # @@@DLD bug 1998 - update comment above and use refresh instead? self.RepositoryCommitWithStatus() # show status self.setStatusMessage(_("Sharing collection %s") % itemCollection.displayName) # Get or make a share for this item collection share = Sharing.getShare(itemCollection) isNewShare = share is None if isNewShare: share = Sharing.newOutboundShare(self.itsView, itemCollection, account=webdavAccount) # Copy the invitee list into the share's list. As we go, collect the # addresses we'll notify. if len(itemCollection.invitees) == 0: self.setStatusMessage(_("No invitees!")) return inviteeList = [] inviteeStringsList = [] for invitee in itemCollection.invitees: inviteeList.append(invitee) inviteeStringsList.append(invitee.emailAddress) inviteeContact = Contact.getContactForEmailAddress(self.itsView, invitee.emailAddress) if not inviteeContact in share.sharees: share.sharees.append(inviteeContact) # Sync the collection with WebDAV self.setStatusMessage(_("accessing WebDAV server")) try: if not share.exists(): share.create() share.put() except Sharing.SharingError, err: self.setStatusMessage(_("Sharing failed.")) msg = "Couldn't share collection:\n%s" % err.message application.dialogs.Util.ok(wx.GetApp().mainFrame, "Error", msg) if isNewShare: share.conduit.delete() share.format.delete() share.delete() return
def ShowPublishPanel(self): # "Publish" mode -- i.e., the collection has not yet been shared self.Bind(wx.EVT_BUTTON, self.OnPublish, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL) collName = Sharing.getFilteredCollectionDisplayName(self.collection, self.filterKinds) wx.xrc.XRCCTRL(self, "TEXT_COLLNAME").SetLabel(collName) self.currentAccount = Sharing.getWebDAVAccount(self.view) # Populate the listbox of sharing accounts self.accounts = self._getSharingAccounts() self.accountsControl = wx.xrc.XRCCTRL(self, "CHOICE_ACCOUNT") self.accountsControl.Clear() for account in self.accounts: newIndex = self.accountsControl.Append(account.displayName) self.accountsControl.SetClientData(newIndex, account) if account is self.currentAccount: self.accountsControl.SetSelection(newIndex) self.Bind(wx.EVT_CHOICE, self.OnChangeAccount, id=wx.xrc.XRCID("CHOICE_ACCOUNT")) self.CheckboxShareAlarms = wx.xrc.XRCCTRL(self, "CHECKBOX_ALARMS") self.CheckboxShareAlarms.SetValue(False) self.CheckboxShareStatus = wx.xrc.XRCCTRL(self, "CHECKBOX_STATUS") self.CheckboxShareStatus.SetValue(False) self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK"))
def onSyncCollectionEvent (self, event): # Triggered from "Test | Sync collection..." self.itsView.commit() collection = self.getSidebarSelectedCollection () if collection is not None: for share in collection.shares: if share.active: Sharing.syncShare(share)
def onSyncCollectionEvent(self, event): # Triggered from "Test | Sync collection..." self.itsView.commit() collection = self.getSidebarSelectedCollection() if collection is not None: for share in collection.shares: if share.active: Sharing.syncShare(share)
def Import(self, view, filename): path = os.path.join(os.getenv('CHANDLERHOME') or '.', 'parcels', 'osaf', 'sharing', 'tests') sandbox = self.repo.findPath("//sandbox") conduit = Sharing.FileSystemConduit(parent=sandbox, sharePath=path, shareName=filename, view=view) format = ICalendar.ICalendarFormat(parent=sandbox) self.share = Sharing.Share(parent=sandbox, conduit=conduit, format=format) self.share.get() return format
def testImport(self): if os.environ.get('CHANDLER_PERFORMANCE_TEST'): self.loadParcel("parcel:osaf.pim.calendar") path = os.path.join(os.getenv('CHANDLERHOME') or '.', 'parcels', 'osaf', 'sharing', 'tests') conduit = Sharing.FileSystemConduit(name="conduit", sharePath=path, shareName="3kevents.ics", view=self.rep.view) format = ICalendar.ICalendarFormat(name="format", view=self.rep.view) share = Sharing.Share(name="share", conduit=conduit, format=format, view=self.rep.view) share.get()
def onExportIcalendarEvent(self, event): # triggered from "File | Import/Export" Menu wildcard = "iCalendar files|*.ics|All files (*.*)|*.*" dlg = wx.FileDialog(wx.GetApp().mainFrame, "Choose filename to export to", "", "export.ics", wildcard, wx.SAVE | wx.OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: (dir, filename) = os.path.split(dlg.GetPath()) dlg.Destroy() else: dlg.Destroy() self.setStatusMessage("Export aborted") return self.setStatusMessage ("Exporting to %s" % filename) try: share = Sharing.OneTimeFileSystemShare(dir, filename, ICalendar.ICalendarFormat, view=self.itsView) collection = ItemCollection(view=self.itsView) for event in Calendar.CalendarEvent.iterItems(self.itsView): collection.add(event) share.contents = collection share.put() self.setStatusMessage("Export completed") except: trace = "".join(traceback.format_exception (*sys.exc_info())) logger.info("Failed exportFile:\n%s" % trace) self.setStatusMessage("Export failed")
def onImportIcalendarEvent(self, event): # triggered from "File | Import/Export" menu wildcard = "iCalendar files|*.ics|All files (*.*)|*.*" dlg = wx.FileDialog(wx.GetApp().mainFrame, "Choose a file to import", "", "import.ics", wildcard, wx.OPEN | wx.HIDE_READONLY) if dlg.ShowModal() == wx.ID_OK: (dir, filename) = os.path.split(dlg.GetPath()) dlg.Destroy() else: dlg.Destroy() self.setStatusMessage("Import aborted") return self.setStatusMessage ("Importing from %s" % filename) try: share = Sharing.OneTimeFileSystemShare(dir, filename, ICalendar.ICalendarFormat, view=self.itsView) collection = share.get() self.postEventByName ("AddToSidebarWithoutCopyingAndSelectFirst", {'items':[collection]}) self.setStatusMessage ("Import completed") except: trace = "".join(traceback.format_exception (*sys.exc_info())) logger.info("Failed importFile:\n%s" % trace) self.setStatusMessage("Import failed")
def OnSubscribe(self, evt): view = self.view url = self.textUrl.GetValue() if url.startswith('webcal:'): url = 'http:' + url[7:] share = Sharing.findMatchingShare(view, url) if share is not None: self.__showStatus("You are already subscribed") return try: share = Sharing.Share(view=view) share.configureInbound(url) if share is None: return if self.accountPanel.IsShown(): share.conduit.account.username = self.textUsername.GetValue() share.conduit.account.password = self.textPassword.GetValue() self.__showStatus("In progress...") wx.Yield() share.sync() collection = share.contents mainView = Globals.views[0] mainView.postEventByName( "AddToSidebarWithoutCopyingAndSelectFirst", {'items': [collection]}) event = 'ApplicationBarAll' if share.filterKinds and len(share.filterKinds) == 1: filterKind = share.filterKinds[0] if filterKind == '//parcels/osaf/pim/calendar/CalendarEventMixin': event = 'ApplicationBarEvent' elif filterKind == '//parcels/osaf/pim/tasks/TaskMixin': event = 'ApplicationBarTask' elif filterKind == '//parcels/osaf/pim/mail/MailMessageMixin': event = 'ApplicationBarMail' mainView.postEventByName(event, {}) self.EndModal(True) except Sharing.NotAllowed, err: self.__showAccountInfo(share.conduit.account) share.delete(True)
def onCopyCollectionURLEventUpdateUI(self, event): enable = False collection = self.getSidebarSelectedCollection() if collection is not None: share = Sharing.getShare(collection) if share is not None: enable = True event.arguments['Enable'] = enable
def onCopyCollectionURLEventUpdateUI(self, event): enable = False collection = self.getSidebarSelectedCollection() if collection is not None: share = Sharing.getShare(collection) if share is not None: enable = True event.arguments["Enable"] = enable
def onSyncWebDAVEvent(self, event): """ Synchronize WebDAV sharing. The "File | Sync | WebDAV" menu item """ # commit repository changes before synch # @@@DLD bug 1998 - update comment above and use refresh instead? self.RepositoryCommitWithStatus() # find all the shared collections and sync them. self.setStatusMessage(_("Checking shared collections...")) if Sharing.checkForActiveShares(self.itsView): self.setStatusMessage(_("Synchronizing shared collections...")) Sharing.syncAll(self.itsView) else: self.setStatusMessage(_("No shared collections found")) return self.setStatusMessage(_("Shared collections synchronized"))
def onSyncWebDAVEvent (self, event): """ Synchronize WebDAV sharing. The "File | Sync | WebDAV" menu item """ # commit repository changes before synch # @@@DLD bug 1998 - update comment above and use refresh instead? self.RepositoryCommitWithStatus() # find all the shared collections and sync them. self.setStatusMessage (_("Checking shared collections...")) if Sharing.checkForActiveShares(self.itsView): self.setStatusMessage (_("Synchronizing shared collections...")) Sharing.syncAll(self.itsView) else: self.setStatusMessage (_("No shared collections found")) return self.setStatusMessage (_("Shared collections synchronized"))
def onCopyCollectionURLEvent(self, event): collection = self.getSidebarSelectedCollection() if collection is not None: share = Sharing.getShare(collection) if share is not None: url = str(share.getLocation()) gotClipboard = wx.TheClipboard.Open() if gotClipboard: wx.TheClipboard.SetData(wx.TextDataObject(url)) wx.TheClipboard.Close()
def __init__(self, parent, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, resources=None, view=None, url=None): wx.Dialog.__init__(self, parent, -1, title, pos, size, style) self.view = view self.resources = resources self.parent = parent self.mySizer = wx.BoxSizer(wx.VERTICAL) self.toolPanel = self.resources.LoadPanel(self, "Subscribe") self.mySizer.Add(self.toolPanel, 0, wx.GROW | wx.ALL, 5) self.statusPanel = self.resources.LoadPanel(self, "StatusPanel") self.statusPanel.Hide() self.accountPanel = self.resources.LoadPanel(self, "UsernamePasswordPanel") self.accountPanel.Hide() self.SetSizer(self.mySizer) self.mySizer.SetSizeHints(self) self.mySizer.Fit(self) self.textUrl = wx.xrc.XRCCTRL(self, "TEXT_URL") if url is not None: self.textUrl.SetValue(url) else: account = Sharing.getWebDAVAccount(self.view) if account: url = account.getLocation() self.textUrl.SetValue(url) self.Bind(wx.EVT_TEXT, self.OnTyping, self.textUrl) self.textStatus = wx.xrc.XRCCTRL(self, "TEXT_STATUS") self.textUsername = wx.xrc.XRCCTRL(self, "TEXT_USERNAME") self.textPassword = wx.xrc.XRCCTRL(self, "TEXT_PASSWORD") self.checkboxKeepOut = wx.xrc.XRCCTRL(self, "CHECKBOX_KEEPOUT") self.checkboxKeepOut.Enable(False) # Not yet supported self.Bind(wx.EVT_BUTTON, self.OnSubscribe, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL) self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK")) self.textUrl.SetFocus() self.textUrl.SetInsertionPointEnd()
def onSyncAllEvent(self, event): """ Synchronize Mail and all sharing. The "File | Sync | All" menu item """ # find all the shared collections and sync them. self.onSyncWebDAVEvent(event) # If mail is set up, fetch it: if Sharing.isInboundMailSetUp(self.itsView): self.setStatusMessage(_("Getting new Mail")) self.onGetNewMailEvent(event)
def onShareSidebarCollectionEventUpdateUI(self, event): """ Update the menu to reflect the selected collection name """ collection = self.getSidebarSelectedCollection() if collection is not None: sidebar = Block.findBlockByName("Sidebar") if sidebar.filterKind is None: filterKindPath = [] else: filterKindPath = [str(sidebar.filterKind.itsPath)] collName = Sharing.getFilteredCollectionDisplayName(collection, filterKindPath) menuTitle = _('Share "%s"...') % collName else: menuTitle = _("Share a collection...") event.arguments["Text"] = menuTitle event.arguments["Enable"] = collection is not None and (not Sharing.isShared(collection))
def onSyncAllEvent (self, event): """ Synchronize Mail and all sharing. The "File | Sync | All" menu item """ # find all the shared collections and sync them. self.onSyncWebDAVEvent (event) # If mail is set up, fetch it: if Sharing.isInboundMailSetUp(self.itsView): self.setStatusMessage (_("Getting new Mail")) self.onGetNewMailEvent (event)
def OnUnPubSub(self, evt): share = Sharing.getShare(self.collection) if Sharing.isSharedByMe(share): Sharing.unpublish(self.collection) else: Sharing.unsubscribe(self.collection) self.EndModal(True)
def RoundTripNonCollection(self): # Export repo = self.repos[0] theItem = ContentItem(view=repo.view) theItem.displayName = "I'm an item" conduit = Sharing.FileSystemConduit(sharePath=".", shareName="exporteditem", view=repo.view) format = Sharing.CloudXMLFormat(view=repo.view) self.share3 = Sharing.Share(contents=theItem, conduit=conduit, format=format, view=repo.view) if self.share3.exists(): self.share3.destroy() self.share3.create() self.share3.put() # Import repo = self.repos[1] conduit = Sharing.FileSystemConduit(sharePath=".", shareName="exporteditem", view=repo.view) format = Sharing.CloudXMLFormat(view=repo.view) self.share4 = Sharing.Share(conduit=conduit, format=format, view=repo.view) self.share4.get() alsoTheItem = self.share4.contents self.assert_(alsoTheItem.displayName == "I'm an item", "Single-item import/export failed")
def onShareSidebarCollectionEventUpdateUI (self, event): """ Update the menu to reflect the selected collection name """ collection = self.getSidebarSelectedCollection () if collection is not None: sidebar = Block.findBlockByName("Sidebar") if sidebar.filterKind is None: filterKindPath = [] else: filterKindPath = [str(sidebar.filterKind.itsPath)] collName = Sharing.getFilteredCollectionDisplayName(collection, filterKindPath) menuTitle = _('Share "%s"...') % collName else: menuTitle = _('Share a collection...') event.arguments ['Text'] = menuTitle event.arguments['Enable'] = collection is not None and (not Sharing.isShared(collection))
def getButtonState (self, buttonName, item): if buttonName == u'Icon': if item in self.checkedItems: return 'Checked' elif buttonName == u'SharingIcon': share = Sharing.getShare(item) if share is not None: if (share.sharer is not None and str(share.sharer.itsPath) == "//userdata/me"): return "Upload" else: return "Download" return ""
def writeICalendarUnicodeBug3338(self): event = Calendar.CalendarEvent(view = self.repo.view) event.displayName = u"unicode \u0633\u0644\u0627\u0645" event.startTime = datetime.datetime(2010, 1, 1, 10) event.endTime = datetime.datetime(2010, 1, 1, 11) coll = ItemCollection(name="testcollection", parent=self.sandbox) coll.add(event) filename = "unicode_export.ics" conduit = Sharing.FileSystemConduit(name="conduit", sharePath=".", shareName=filename, view=self.repo.view) format = ICalendar.ICalendarFormat(name="format", view=self.repo.view) self.share = Sharing.Share(name="share",contents=coll, conduit=conduit, format=format, view=self.repo.view) if self.share.exists(): self.share.destroy() self.share.create() self.share.put() cal=vobject.readComponents(file(filename, 'rb')).next() self.assertEqual(cal.vevent[0].summary[0].value, event.displayName) self.share.destroy()
def onSyncCollectionEventUpdateUI(self, event): """ Update the menu to reflect the selected collection name """ collection = self.getSidebarSelectedCollection() if collection is not None: sidebar = Block.findBlockByName("Sidebar") if sidebar.filterKind is None: filterKindPath = [] else: filterKindPath = [str(sidebar.filterKind.itsPath)] collName = Sharing.getFilteredCollectionDisplayName(collection, filterKindPath) menuTitle = _('Sync "%s"') % collName if Sharing.isShared(collection): event.arguments["Enable"] = True else: event.arguments["Enable"] = False else: event.arguments["Enable"] = False menuTitle = _("Sync a collection") event.arguments["Text"] = menuTitle
def __init__(self, parent, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, resources=None, view=None, collection=None, filterKindPath=None): wx.Dialog.__init__(self, parent, -1, title, pos, size, style) self.resources = resources self.view = view self.parent = parent self.collection = collection # The collection to share # List of kinds (paths) to share if filterKindPath is None: self.filterKinds = [] else: self.filterKinds = [filterKindPath] self.mySizer = wx.BoxSizer(wx.VERTICAL) # Is this collection already shared? self.shareXML = Sharing.getShare(self.collection) if self.shareXML is None: # Not yet shared, show "Publish" self.mainPanel = self.resources.LoadPanel(self, "PublishCollection") self.buttonPanel = self.resources.LoadPanel(self, "PublishButtonsPanel") else: # Already shared, show "Manage" self.mainPanel = self.resources.LoadPanel(self, "ManageCollection") self.buttonPanel = self.resources.LoadPanel(self, "ManageButtonsPanel") # Create/Hide the status panel that appears when there is text to # display self.statusPanel = self.resources.LoadPanel(self, "StatusPanel") self.statusPanel.Hide() self.textStatus = wx.xrc.XRCCTRL(self, "TEXT_STATUS") # Fit all the pieces together self.mySizer.Add(self.mainPanel, 0, wx.GROW|wx.ALL, 5) self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5) self.SetSizer(self.mySizer) self.mySizer.SetSizeHints(self) self.mySizer.Fit(self) if self.shareXML is None: # Not yet shared, show "Publish" self.ShowPublishPanel() else: # Already shared, show "Manage" self.ShowManagePanel()
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)
def OnOk(self, evt): title = self.textTitle.GetValue() shareName = self.textShareName.GetValue() accountIndex = self.choiceAccount.GetSelection() - 1 account = self.accounts[accountIndex] if not self.join: collIndex = self.choiceColl.GetSelection() - 1 collection = self.collections[collIndex] if self.share is None: conduit = Sharing.WebDAVConduit(account=account, shareName=shareName, view=self.view) if shareName.endswith('.ics'): format = ICalendar.ICalendarFormat(view=self.view) else: format = Sharing.CloudXMLFormat(view=self.view) if self.join: self.share = Sharing.Share(conduit=conduit, format=format, view=self.view) else: self.share = Sharing.Share(contents=collection, conduit=conduit, format=format, view=self.view) self.share.displayName = title else: self.share.displayName = title self.share.conduit.account = account self.share.conduit.shareName = shareName self.share.contents = collection self.EndModal(True)
def __init__(self, parent, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, resources=None, view=None, url=None): wx.Dialog.__init__(self, parent, -1, title, pos, size, style) self.view = view self.resources = resources self.parent = parent self.mySizer = wx.BoxSizer(wx.VERTICAL) self.toolPanel = self.resources.LoadPanel(self, "Subscribe") self.mySizer.Add(self.toolPanel, 0, wx.GROW|wx.ALL, 5) self.statusPanel = self.resources.LoadPanel(self, "StatusPanel") self.statusPanel.Hide() self.accountPanel = self.resources.LoadPanel(self, "UsernamePasswordPanel") self.accountPanel.Hide() self.SetSizer(self.mySizer) self.mySizer.SetSizeHints(self) self.mySizer.Fit(self) self.textUrl = wx.xrc.XRCCTRL(self, "TEXT_URL") if url is not None: self.textUrl.SetValue(url) else: account = Sharing.getWebDAVAccount(self.view) if account: url = account.getLocation() self.textUrl.SetValue(url) self.Bind(wx.EVT_TEXT, self.OnTyping, self.textUrl) self.textStatus = wx.xrc.XRCCTRL(self, "TEXT_STATUS") self.textUsername = wx.xrc.XRCCTRL(self, "TEXT_USERNAME") self.textPassword = wx.xrc.XRCCTRL(self, "TEXT_PASSWORD") self.checkboxKeepOut = wx.xrc.XRCCTRL(self, "CHECKBOX_KEEPOUT") self.checkboxKeepOut.Enable(False) # Not yet supported self.Bind(wx.EVT_BUTTON, self.OnSubscribe, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL) self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK")) self.textUrl.SetFocus() self.textUrl.SetInsertionPointEnd()
def sharedWebDAVCollections (self): # return the list of all the shared collections # @@@DLD - use new query, once it can handle method calls, or when our item.isShared # attribute is correctly set. UseNewQuery = False if UseNewQuery: qString = u"for i in '//parcels/osaf/pim/ItemCollection' where len (i.sharedURL) > 0" collQuery = Query.Query (self.itsView.repository, qString) collQuery.recursive = False collections = list(collQuery) else: collections = [ coll for coll in ItemCollection.iterItems(self.itsView) if Sharing.isShared(coll) ] return collections
def OnSubscribe(self, evt): view = self.view url = self.textUrl.GetValue() if url.startswith('webcal:'): url = 'http:' + url[7:] share = Sharing.findMatchingShare(view, url) if share is not None: self.__showStatus("You are already subscribed") return try: share = Sharing.Share(view=view) share.configureInbound(url) if share is None: return if self.accountPanel.IsShown(): share.conduit.account.username = self.textUsername.GetValue() share.conduit.account.password = self.textPassword.GetValue() self.__showStatus("In progress...") wx.Yield() share.sync() collection = share.contents mainView = Globals.views[0] mainView.postEventByName("AddToSidebarWithoutCopyingAndSelectFirst", {'items':[collection]}) event = 'ApplicationBarAll' if share.filterKinds and len(share.filterKinds) == 1: filterKind = share.filterKinds[0] if filterKind == '//parcels/osaf/pim/calendar/CalendarEventMixin': event = 'ApplicationBarEvent' elif filterKind == '//parcels/osaf/pim/tasks/TaskMixin': event = 'ApplicationBarTask' elif filterKind == '//parcels/osaf/pim/mail/MailMessageMixin': event = 'ApplicationBarMail' mainView.postEventByName(event, {}) self.EndModal(True) except Sharing.NotAllowed, err: self.__showAccountInfo(share.conduit.account) share.delete(True)
def onGetNewMailEvent (self, event): # Make sure we have all the accounts; returns False if the user cancels # out and we don't. if not Sharing.ensureAccountSetUp(self.itsView): return view = self.itsView # @@@DLD bug 1998 - why do we have to commit here? Are we pushing our changes # over to mail? view.commit() for account in Mail.IMAPAccount.getActiveAccounts(self.itsView): Globals.mailService.getIMAPInstance(account).getMail() for account in Mail.POPAccount.getActiveAccounts(self.itsView): Globals.mailService.getPOPInstance(account).getMail() view.refresh()
def onGetNewMailEvent(self, event): # Make sure we have all the accounts; returns False if the user cancels # out and we don't. if not Sharing.ensureAccountSetUp(self.itsView): return view = self.itsView # @@@DLD bug 1998 - why do we have to commit here? Are we pushing our changes # over to mail? view.commit() for account in Mail.IMAPAccount.getActiveAccounts(self.itsView): Globals.mailService.getIMAPInstance(account).getMail() for account in Mail.POPAccount.getActiveAccounts(self.itsView): Globals.mailService.getPOPInstance(account).getMail() view.refresh()
def displaySMTPSendSuccess (self, mailMessage): """ Called when the SMTP Send was successful. """ if mailMessage is not None and mailMessage.isOutbound: self.setStatusMessage (_('Mail "%s" sent.') % mailMessage.about) # If this was a sharing invitation, find its collection and remove the # successfully-notified addressees from the invites list. try: (url, collectionName) = MailSharing.getSharingHeaderInfo(mailMessage) except KeyError: pass else: share = Sharing.findMatchingShare(self.itsView, url) itemCollection = share.contents for addresseeContact in mailMessage.toAddress: if addresseeContact in itemCollection.invitees: itemCollection.invitees.remove(addresseeContact)
def displaySMTPSendSuccess(self, mailMessage): """ Called when the SMTP Send was successful. """ if mailMessage is not None and mailMessage.isOutbound: self.setStatusMessage(_('Mail "%s" sent.') % mailMessage.about) # If this was a sharing invitation, find its collection and remove the # successfully-notified addressees from the invites list. try: (url, collectionName) = MailSharing.getSharingHeaderInfo(mailMessage) except KeyError: pass else: share = Sharing.findMatchingShare(self.itsView, url) itemCollection = share.contents for addresseeContact in mailMessage.toAddress: if addresseeContact in itemCollection.invitees: itemCollection.invitees.remove(addresseeContact)
def RoundTrip(self): # Export repo = self.repos[0] sandbox = repo.findPath("//sandbox") coll = sandbox.findPath("testcollection") conduit = Sharing.FileSystemConduit(name="conduit", parent=sandbox, sharePath=".", shareName="exportedcollection", view=repo.view) format = Sharing.CloudXMLFormat(name="format", parent=sandbox, view=repo.view) self.share1 = Sharing.Share(name="share", parent=sandbox, contents=coll, conduit=conduit, format=format, view=repo.view) if self.share1.exists(): self.share1.destroy() self.share1.create() self.share1.put() # Import repo = self.repos[1] sandbox = repo.findPath("//sandbox") coll = sandbox.findPath("testcollection") conduit = Sharing.FileSystemConduit(name="conduit", parent=sandbox, sharePath=".", shareName="exportedcollection", view=repo.view) format = Sharing.CloudXMLFormat(name="format", parent=sandbox, view=repo.view) self.share2 = Sharing.Share(name="share", parent=sandbox, conduit=conduit, format=format, view=repo.view) self.share2.get() # Make sure that the items we imported have the same displayNames # as the ones we exported (and no fewer, no more) names = {} for item in self.share1.contents: names[item.displayName] = 1 for item in self.share2.contents: self.assert_(item.displayName in names, "Imported item that wasn't" "exported") del names[item.displayName] 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.OnCopy, id=wx.xrc.XRCID("BUTTON_CLIPBOARD")) self.Bind(wx.EVT_BUTTON, self.OnUnPubSub, id=wx.xrc.XRCID("BUTTON_UNPUBLISH")) name = self.collection.displayName wx.xrc.XRCCTRL(self, "TEXT_MANAGE_COLLNAME").SetLabel(name) name = self.shareXML.conduit.account.displayName wx.xrc.XRCCTRL(self, "TEXT_ACCOUNT").SetLabel(name) url = self.shareXML.conduit.getLocation() wx.xrc.XRCCTRL(self, "TEXT_URL").SetLabel(url) self.UnPubSub = wx.xrc.XRCCTRL(self, "BUTTON_UNPUBLISH") share = Sharing.getShare(self.collection) if Sharing.isSharedByMe(share): self.UnPubSub.SetLabel("Unpublish") else: self.UnPubSub.SetLabel("Unsubscribe") # Controls for managing filtered shares: self.RadioItems = wx.xrc.XRCCTRL(self, "RADIO_ITEMS") self.RadioItemsHidden = wx.xrc.XRCCTRL(self, "RADIO_ITEMS_HIDDEN") self.RadioItemsHidden.Hide() wx.EVT_RADIOBUTTON(self.RadioItems, self.RadioItems.GetId(), self.OnAllItemsClicked) self.CheckboxMail = wx.xrc.XRCCTRL(self, "CHECK_MAIL") wx.EVT_CHECKBOX(self.CheckboxMail, self.CheckboxMail.GetId(), self.OnFilterClicked) self.CheckboxTasks = wx.xrc.XRCCTRL(self, "CHECK_TASKS") wx.EVT_CHECKBOX(self.CheckboxTasks, self.CheckboxTasks.GetId(), self.OnFilterClicked) self.CheckboxEvents = wx.xrc.XRCCTRL(self, "CHECK_EVENTS") wx.EVT_CHECKBOX(self.CheckboxEvents, self.CheckboxEvents.GetId(), self.OnFilterClicked) self.CheckboxShareAlarms = wx.xrc.XRCCTRL(self, "CHECKBOX_ALARMS") self.CheckboxShareAlarms.Enable(False) self.CheckboxShareStatus = wx.xrc.XRCCTRL(self, "CHECKBOX_STATUS") self.CheckboxShareStatus.Enable(False) self.filterKinds = self.shareXML.filterKinds self._loadKindFilterState() self._loadAttributeFilterState(self.shareXML) self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK"))
def onUnpublishSidebarCollectionEventUpdateUI(self, event): collection = self.getSidebarSelectedCollection() if collection is not None: share = Sharing.getShare(collection) sharedByMe = Sharing.isSharedByMe(share) event.arguments["Enable"] = collection is not None and Sharing.isShared(collection) and sharedByMe
def __init__(self, parent, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, resources=None, view=None, share=None, join=False): wx.Dialog.__init__(self, parent, -1, title, pos, size, style) self.view = view self.join = join self.share = share self.resources = resources self.mySizer = wx.BoxSizer(wx.VERTICAL) self.toolPanel = self.resources.LoadPanel(self, "ShareEditor") self.mySizer.Add(self.toolPanel, 0, wx.ALIGN_CENTER | wx.ALL, 5) self.SetSizer(self.mySizer) self.mySizer.SetSizeHints(self) self.mySizer.Fit(self) self.textTitle = wx.xrc.XRCCTRL(self, "TEXT_TITLE") wx.EVT_SET_FOCUS(self.textTitle, self.OnFocusGained) self.choiceColl = wx.xrc.XRCCTRL(self, "CHOICE_COLL") self.choiceAccount = wx.xrc.XRCCTRL(self, "CHOICE_ACCOUNT") self.textShareName = wx.xrc.XRCCTRL(self, "TEXT_SHARENAME") wx.EVT_SET_FOCUS(self.textShareName, self.OnFocusGained) if join: self.choiceColl.Disable() if share is not None: # share provided self.textTitle.SetValue(share.getItemDisplayName()) self.textShareName.SetValue(share.conduit.shareName) account = share.conduit.account else: # creating the share account = Sharing.getWebDAVAccount(self.view) self.textTitle.SetValue("Enter a descriptive title") self.textShareName.SetValue("Enter directory name to use") self.accounts = [] i = 0 for item in Sharing.WebDAVAccount.iterItems(self.view): self.accounts.append(item) self.choiceAccount.Append(item.getItemDisplayName()) if account is item: defaultChoice = i i += 1 self.choiceAccount.SetSelection(defaultChoice) if not join: from osaf.pim.ItemCollection import ItemCollection self.collections = [] i = 1 for item in ItemCollection.iterItems(self.view): self.collections.append(item) self.choiceColl.Append(item.getItemDisplayName()) if item.getItemDisplayName() == "Calendar Demo": defaultChoice = i if share is not None and share.contents is not None: if item is share.contents: self.choiceColl.SetSelection(i) i += 1 if share is None or share.contents is None: self.choiceColl.SetSelection(defaultChoice) self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL) self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK")) self.textTitle.SetFocus()
def onUnpublishSidebarCollectionEvent(self, event): collection = self.getSidebarSelectedCollection() if collection is not None: Sharing.unpublish(collection)
def onSyncWebDAVEventUpdateUI (self, event): accountOK = Sharing.isWebDAVSetUp(self.itsView) haveActiveShares = Sharing.checkForActiveShares(self.itsView) event.arguments ['Enable'] = accountOK and haveActiveShares
def onSyncWebDAVEventUpdateUI(self, event): accountOK = Sharing.isWebDAVSetUp(self.itsView) haveActiveShares = Sharing.checkForActiveShares(self.itsView) event.arguments["Enable"] = accountOK and haveActiveShares
def OnPublish(self, evt): # Publish the collection # Update the UI by disabling/hiding various panels, and swapping in a # new set of buttons self.mainPanel.Enable(False) self.buttonPanel.Hide() self.mySizer.Detach(self.buttonPanel) self.buttonPanel = self.resources.LoadPanel(self, "PublishingButtonsPanel") self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5) publishingButton = wx.xrc.XRCCTRL(self, "BUTTON_PUBLISHING") publishingButton.Enable(False) self.Bind(wx.EVT_BUTTON, self.OnPublishDone, id=wx.ID_CANCEL) self._clearStatus() self._resize() wx.Yield() try: # Populate the list of existing shares on the selected webdav server self.existing = self._getExistingFiles() suggestedName = self._suggestName() shareName = suggestedName shareNameSafe = urllib.quote_plus(shareName.encode('utf-8')) accountIndex = self.accountsControl.GetSelection() account = self.accountsControl.GetClientData(accountIndex) # Create the main share object shareXML = Sharing.newOutboundShare(self.view, self.collection, kinds=self.filterKinds, shareName=shareNameSafe, account=account) self.shareXML = shareXML shareXML.displayName = shareName self._saveAttributeFilterState(shareXML) # Create the secondary (.ics) share object iCalName = "%s.ics" % shareNameSafe shareICal = Sharing.newOutboundShare(self.view, self.collection, kinds=self.filterKinds, shareName=iCalName, account=account) self.shareICal = shareICal shareICal.displayName = "%s.ics" % shareName self._saveAttributeFilterState(shareICal) # For the .ics share, use ICalendarFormat instead format = ICalendar.ICalendarFormat(view=self.view) shareICal.mode = "put" shareICal.format = format shareICal.hidden = True self._showStatus("Wait for Sharing URLs...\n") if shareXML.exists(): raise Sharing.SharingError("Share already exists") else: self._showStatus("Creating collection on server...") shareXML.create() self._showStatus(" done.\n") self._showStatus("Publishing collection to server...") shareXML.put() self._showStatus(" done.\n") self._showStatus("Publishing calendar file to server...") shareICal.put() self._showStatus(" done.\n") except (Sharing.SharingError, zanshin.error.Error), e: # Display the error # self._clearStatus() self._showStatus("\nSharing error:\n%s\n" % e.message) logger.exception("Failed to publish collection") # self._showStatus("Exception:\n%s" % traceback.format_exc(10)) # Clean up all share objects we created try: shareXML.delete(True) shareICal.delete(True) except: pass # Re-enable the main panel and switch back to the "Share" button self.mainPanel.Enable(True) self.buttonPanel.Hide() self.mySizer.Detach(self.buttonPanel) self.buttonPanel = self.resources.LoadPanel(self, "PublishButtonsPanel") self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5) self.Bind(wx.EVT_BUTTON, self.OnPublish, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL) self._resize() return
def onUnsubscribeSidebarCollectionEvent(self, event): collection = self.getSidebarSelectedCollection() if collection is not None: Sharing.unsubscribe(collection)
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
def onManageSidebarCollectionEventUpdateUI(self, event): collection = self.getSidebarSelectedCollection() event.arguments["Enable"] = collection is not None and (Sharing.isShared(collection))
def sharedWebDAVCollections(self): # return the list of all the shared collections # @@@DLD - use new query, once it can handle method calls, or when our item.isShared # attribute is correctly set. UseNewQuery = False if UseNewQuery: qString = u"for i in '//parcels/osaf/pim/ItemCollection' where len (i.sharedURL) > 0" collQuery = Query.Query(self.itsView.repository, qString) collQuery.recursive = False collections = list(collQuery) else: collections = [coll for coll in ItemCollection.iterItems(self.itsView) if Sharing.isShared(coll)] return collections
def __init__( self, parent, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, resources=None, view=None, share=None, join=False, ): wx.Dialog.__init__(self, parent, -1, title, pos, size, style) self.view = view self.join = join self.share = share self.resources = resources self.mySizer = wx.BoxSizer(wx.VERTICAL) self.toolPanel = self.resources.LoadPanel(self, "ShareEditor") self.mySizer.Add(self.toolPanel, 0, wx.ALIGN_CENTER | wx.ALL, 5) self.SetSizer(self.mySizer) self.mySizer.SetSizeHints(self) self.mySizer.Fit(self) self.textTitle = wx.xrc.XRCCTRL(self, "TEXT_TITLE") wx.EVT_SET_FOCUS(self.textTitle, self.OnFocusGained) self.choiceColl = wx.xrc.XRCCTRL(self, "CHOICE_COLL") self.choiceAccount = wx.xrc.XRCCTRL(self, "CHOICE_ACCOUNT") self.textShareName = wx.xrc.XRCCTRL(self, "TEXT_SHARENAME") wx.EVT_SET_FOCUS(self.textShareName, self.OnFocusGained) if join: self.choiceColl.Disable() if share is not None: # share provided self.textTitle.SetValue(share.getItemDisplayName()) self.textShareName.SetValue(share.conduit.shareName) account = share.conduit.account else: # creating the share account = Sharing.getWebDAVAccount(self.view) self.textTitle.SetValue("Enter a descriptive title") self.textShareName.SetValue("Enter directory name to use") self.accounts = [] i = 0 for item in Sharing.WebDAVAccount.iterItems(self.view): self.accounts.append(item) self.choiceAccount.Append(item.getItemDisplayName()) if account is item: defaultChoice = i i += 1 self.choiceAccount.SetSelection(defaultChoice) if not join: from osaf.pim.ItemCollection import ItemCollection self.collections = [] i = 1 for item in ItemCollection.iterItems(self.view): self.collections.append(item) self.choiceColl.Append(item.getItemDisplayName()) if item.getItemDisplayName() == "Calendar Demo": defaultChoice = i if share is not None and share.contents is not None: if item is share.contents: self.choiceColl.SetSelection(i) i += 1 if share is None or share.contents is None: self.choiceColl.SetSelection(defaultChoice) self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL) self.SetDefaultItem(wx.xrc.XRCCTRL(self, "wxID_OK")) self.textTitle.SetFocus()
def onUnpublishSidebarCollectionEventUpdateUI(self, event): collection = self.getSidebarSelectedCollection () if collection is not None: share = Sharing.getShare(collection) sharedByMe = Sharing.isSharedByMe(share) event.arguments['Enable'] = collection is not None and Sharing.isShared(collection) and sharedByMe