Title: [commits] (morgen) [11357] Added "Save Settings" and "Restore Settings" to the Test menu
Revision
11357
Author
morgen
Date
2006-08-08 17:51:18 -0700 (Tue, 08 Aug 2006)

Log Message

Added "Save Settings" and "Restore Settings" to the Test menu

These will save your sharing account settings, and information about which
shares have you published or subscribed to. When if you restore, it will
set up your accounts for you and also subscribe to the shares.

Modified Paths

Added Paths

Diff

Modified: trunk/chandler/application/dialogs/SubscribeCollection.py (11356 => 11357)

--- trunk/chandler/application/dialogs/SubscribeCollection.py	2006-08-08 21:19:44 UTC (rev 11356)
+++ trunk/chandler/application/dialogs/SubscribeCollection.py	2006-08-09 00:51:18 UTC (rev 11357)
@@ -31,7 +31,8 @@
 
     def __init__(self, parent, title, size=wx.DefaultSize,
          pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE,
-         resources=None, view=None, url="" modal=True):
+         resources=None, view=None, url="" name=None, modal=True,
+         immediate=False, mine=None, publisher=None):
 
         wx.Dialog.__init__(self, parent, -1, title, pos, size, style)
 
@@ -39,6 +40,9 @@
         self.resources = resources
         self.parent = parent
         self.modal = modal
+        self.name = name
+        self.mine = mine
+        self.publisher = mine
 
         self.mySizer = wx.BoxSizer(wx.VERTICAL)
         self.toolPanel = self.resources.LoadPanel(self, "Subscribe")
@@ -71,6 +75,8 @@
         self.textUsername = wx.xrc.XRCCTRL(self, "TEXT_USERNAME")
         self.textPassword = wx.xrc.XRCCTRL(self, "TEXT_PASSWORD")
         self.checkboxKeepOut = wx.xrc.XRCCTRL(self, "CHECKBOX_KEEPOUT")
+        if self.mine:
+            self.checkboxKeepOut.SetValue(False)
         self.forceFreeBusy = wx.xrc.XRCCTRL(self, "CHECKBOX_FORCEFREEBUSY")
         
         self.subscribeButton = wx.xrc.XRCCTRL(self, "wxID_OK")
@@ -85,7 +91,10 @@
         self.textUrl.SetInsertionPointEnd()
         self.subscribing = False
 
+        if immediate:
+            self.OnSubscribe(None)
 
+
     def accountInfoCallback(self, host, path):
         return PromptForNewAccountInfo(self, host=host, path=path)
 
@@ -108,8 +117,16 @@
 
         collection = self.view[uuid]
 
+        if self.name:
+            collection.displayName = self.name
+
+        if self.publisher:
+            me = schema.ns("osaf.pim", self.view).currentContact.item
+            for share in collection.shares:
+                share.sharer = me
+
         # Put this collection into "My items" if not checked:
-        if not self.checkboxKeepOut.GetValue():
+        if not self.checkboxKeepOut.GetValue() or self.mine:
             logger.info(_(u'Moving collection into My Items'))
             schema.ns('osaf.pim', self.view).mine.addSource(collection)
 
@@ -254,7 +271,8 @@
                 self.EndModal(False)
             self.Destroy()
 
-def Show(parent, view=None, url="" modal=False):
+def Show(parent, view=None, url="" name=None, modal=False, immediate=False,
+         mine=None, publisher=None):
     xrcFile = os.path.join(Globals.chandlerDirectory,
      'application', 'dialogs', 'SubscribeCollection_wdr.xrc')
     #[i18n] The wx XRC loading method is not able to handle raw 8bit paths
@@ -262,7 +280,9 @@
     xrcFile = unicode(xrcFile, sys.getfilesystemencoding())
     resources = wx.xrc.XmlResource(xrcFile)
     win = SubscribeDialog(parent, _(u"Subscribe to Shared Collection"),
-                          resources=resources, view=view, url="" modal=modal)
+                          resources=resources, view=view, url="" name=name,
+                          modal=modal, immediate=immediate, mine=mine,
+                          publisher=publisher)
     win.CenterOnScreen()
     if modal:
         return win.ShowModal()

Added: trunk/chandler/parcels/osaf/settings.py (11356 => 11357)

--- trunk/chandler/parcels/osaf/settings.py	2006-08-08 21:19:44 UTC (rev 11356)
+++ trunk/chandler/parcels/osaf/settings.py	2006-08-09 00:51:18 UTC (rev 11357)
@@ -0,0 +1,147 @@
+#   Copyright (c) 2003-2006 Open Source Applications Foundation
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+"""Save and Restore Application Settings"""
+
+import ConfigParser, logging
+from application import schema
+from osaf import pim, sharing
+from application.dialogs import SubscribeCollection
+from chandlerdb.util.c import UUID
+
+logger = logging.getLogger(__name__)
+
+
+def save(rv, filename):
+    """Save selected settings information, including all sharing accounts
+    and shares (whether published or subscribed), to an INI file"""
+
+    cfg = ConfigParser.ConfigParser()
+
+    # Sharing accounts
+    currentAccount = schema.ns('osaf.sharing', rv).currentWebDAVAccount.item
+    section_prefix = "sharing_account"
+    counter = 1
+
+    for account in sharing.WebDAVAccount.iterItems(rv):
+        section_name = "%s_%d" % (section_prefix, counter)
+        cfg.add_section(section_name)
+        cfg.set(section_name, "type", "webdav account")
+        cfg.set(section_name, "uuid", account.itsUUID)
+        cfg.set(section_name, "title", account.displayName)
+        cfg.set(section_name, "host", account.host)
+        cfg.set(section_name, "path", account.path)
+        cfg.set(section_name, "username", account.username)
+        cfg.set(section_name, "password", account.password)
+        cfg.set(section_name, "port", account.port)
+        cfg.set(section_name, "usessl", account.useSSL)
+        if account is currentAccount:
+            cfg.set(section_name, "default", "True")
+        counter += 1
+
+    # Subscriptions
+    mine = schema.ns('osaf.pim', rv).mine
+    section_prefix = "share"
+    counter = 1
+    for col in pim.ContentCollection.iterItems(rv):
+        share = sharing.getShare(col)
+        if share:
+            section_name = "%s_%d" % (section_prefix, counter)
+            cfg.add_section(section_name)
+            cfg.set(section_name, "type", "share")
+            cfg.set(section_name, "title", share.contents.displayName)
+            cfg.set(section_name, "mine", col in mine.sources)
+            urls = sharing.getUrls(share)
+            if sharing.isSharedByMe(share):
+                cfg.set(section_name, "publisher", "True")
+                cfg.set(section_name, "url", share.getLocation())
+            else:
+                cfg.set(section_name, "publisher", "False")
+                url = ""
+                cfg.set(section_name, "url", url)
+                if url != urls[0]:
+                    cfg.set(section_name, "ticket", urls[0])
+            counter += 1
+
+
+    output = file(filename, "w")
+    cfg.write(output)
+    output.close()
+
+
+def restore(rv, filename):
+    """Restore accounts and shares from an INI file"""
+
+    cfg = ConfigParser.ConfigParser()
+    cfg.read(filename)
+
+    # sharing accounts
+    for section in cfg.sections():
+        section_type = cfg.get(section, "type")
+        if section_type == "webdav account":
+            if cfg.has_option(section, "uuid"):
+                uuid = cfg.get(section, "uuid")
+                uuid = UUID(uuid)
+                account = rv.findUUID(uuid)
+                if account is None:
+                    kind = sharing.WebDAVAccount.getKind(rv)
+                    parent = schema.Item.getDefaultParent(rv)
+                    account = kind.instantiateItem(None, parent, uuid,
+                        withInitialValues=True)
+            else:
+                account = sharing.WebDAVAccount(itsView=rv)
+
+            account.displayName = cfg.get(section, "title")
+            account.host = cfg.get(section, "host")
+            account.path = cfg.get(section, "path")
+            account.username = cfg.get(section, "username")
+            account.password = cfg.get(section, "password")
+            account.port = cfg.getint(section, "port")
+            account.useSSL = cfg.getboolean(section, "usessl")
+
+            if (cfg.has_option(section, "default") and
+                cfg.get(section, "default")):
+                accountRef = schema.ns("osaf.sharing", rv).currentWebDAVAccount
+                accountRef.item = account
+
+    # shares
+    for section in cfg.sections():
+        section_type = cfg.get(section, "type")
+        if section_type == "share":
+            url = "" "url")
+
+            mine = False
+            if cfg.has_option(section, "mine"):
+                # Add to my items
+                mine = cfg.getboolean(section, "mine")
+
+            publisher = False
+            if cfg.has_option(section, "publisher"):
+                # make me the publisher
+                publisher = cfg.getboolean(section, "publisher")
+
+            subscribed = False
+            for share in sharing.Share.iterItems(rv):
+                if url == share.getLocation():
+                    subscribed = True
+
+            if not subscribed:
+                if cfg.has_option(section, "ticket"):
+                    url = "" "ticket")
+                title = cfg.get(section, "title")
+                SubscribeCollection.Show(None, view=rv, url="" name=title,
+                                         modal=False, immediate=True,
+                                         mine=mine, publisher=publisher)
+
Property changes on: trunk/chandler/parcels/osaf/settings.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: trunk/chandler/parcels/osaf/sharing/__init__.py (11356 => 11357)

--- trunk/chandler/parcels/osaf/sharing/__init__.py	2006-08-08 21:19:44 UTC (rev 11356)
+++ trunk/chandler/parcels/osaf/sharing/__init__.py	2006-08-09 00:51:18 UTC (rev 11357)
@@ -1025,6 +1025,7 @@
 
                 subShare.format = CloudXMLFormat(itsParent=subShare)
 
+                subShare.filterAttributes = []
                 for attr in CALDAVFILTER:
                     subShare.filterAttributes.append(attr)
 

Modified: trunk/chandler/parcels/osaf/views/main/Main.py (11356 => 11357)

--- trunk/chandler/parcels/osaf/views/main/Main.py	2006-08-08 21:19:44 UTC (rev 11356)
+++ trunk/chandler/parcels/osaf/views/main/Main.py	2006-08-09 00:51:18 UTC (rev 11357)
@@ -28,7 +28,7 @@
     SubscribeCollection, RestoreShares, autosyncprefs
 )
 
-from osaf import pim, sharing, messages, webserver, search
+from osaf import pim, sharing, messages, webserver, search, settings
 
 from osaf.pim import Contact, ContentCollection, mail, IndexedSelectionCollection
 from osaf.usercollections import UserCollection
@@ -749,6 +749,30 @@
         # Test menu item
         wx.GetApp().ShowPyShell(withFilling=True)
 
+    def onSaveSettingsEvent(self, event):
+        # triggered from "Test | Save Settings" Menu
+        wildcard = u"Settings files|*.ini|All files (*.*)|*.*"
+        dlg = wx.FileDialog(wx.GetApp().mainFrame,
+            "Save Settings", "", "chandler.ini", wildcard, wx.SAVE)
+        path = None
+        if dlg.ShowModal() == wx.ID_OK:
+            path = dlg.GetPath()
+        dlg.Destroy()
+        if path:
+            settings.save(self.itsView, path)
+
+    def onRestoreSettingsEvent(self, event):
+        # triggered from "Test | Restore Settings" Menu
+        wildcard = u"Settings files|*.ini|All files (*.*)|*.*"
+        dlg = wx.FileDialog(wx.GetApp().mainFrame,
+            "Restore Settings", "", "chandler.ini", wildcard, wx.OPEN)
+        path = None
+        if dlg.ShowModal() == wx.ID_OK:
+            path = dlg.GetPath()
+        dlg.Destroy()
+        if path:
+            settings.restore(self.itsView, path)
+
     def onActivateWebserverEventUpdateUI (self, event):
         for server in webserver.Server.iterItems(self.itsView):
             if server.isActivated():

Modified: trunk/chandler/parcels/osaf/views/main/events.py (11356 => 11357)

--- trunk/chandler/parcels/osaf/views/main/events.py	2006-08-08 21:19:44 UTC (rev 11356)
+++ trunk/chandler/parcels/osaf/views/main/events.py	2006-08-09 00:51:18 UTC (rev 11357)
@@ -135,6 +135,10 @@
 
     BlockEvent.template('ShowPyShell').install(parcel)
 
+    BlockEvent.template('SaveSettings').install(parcel)
+
+    BlockEvent.template('RestoreSettings').install(parcel)
+
     BlockEvent.template('EditAccountPreferences').install(parcel)
 
     BlockEvent.template(

Modified: trunk/chandler/parcels/osaf/views/main/menus.py (11356 => 11357)

--- trunk/chandler/parcels/osaf/views/main/menus.py	2006-08-08 21:19:44 UTC (rev 11356)
+++ trunk/chandler/parcels/osaf/views/main/menus.py	2006-08-09 00:51:18 UTC (rev 11357)
@@ -535,6 +535,14 @@
                         event = main.ShowPyCrust,
                         title = u'Show Python shell with &object browser...',
                         helpString = u'Brings up an interactive Python shell and object browser'),
+                    MenuItem.template('SaveSettingsItem',
+                        event = main.SaveSettings,
+                        title = u'Save settings...',
+                        helpString = u'Saves your accounts and shares'),
+                    MenuItem.template('RestoreSettingsItem',
+                        event = main.RestoreSettings,
+                        title = u'Restore settings...',
+                        helpString = u'Restores your accounts and shares'),
                     MenuItem.template('ActivateWebserverItem',
                         event = main.ActivateWebserver,
                         title = u'Activate built-in webserver',




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to