commit 8f44fd3a5bee9a85d5a33cc288ce2d27228faaab
Author: pkanavos <pkanavos@gmail.com>
Date:   Thu Apr 26 02:13:26 2012 +0300

    Selective Sync fixes
    FileState persistence fix that correctly stores forbidden files
    Permission check fix

diff --git a/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs b/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
index cae3de2..f7edd53 100644
--- a/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
+++ b/trunk/Pithos.Client.WPF/SelectiveSynch/SelectiveSynchViewModel.cs
@@ -49,6 +49,7 @@ using Pithos.Client.WPF.Properties;
 using Pithos.Client.WPF.Utils;
 using Pithos.Core;
 using Pithos.Interfaces;
+using Pithos.Network;
 
 namespace Pithos.Client.WPF.SelectiveSynch
 {
@@ -66,8 +67,9 @@ namespace Pithos.Client.WPF.SelectiveSynch
         }
 
         private ObservableCollection<ObjectInfo> _checks;
-        private readonly PithosMonitor _monitor;
+        //private readonly PithosMonitor _monitor;
         private bool _isBusy=true;
+        private string _apiKey;
 
         public ObservableCollection<ObjectInfo> Checks
         {
@@ -84,26 +86,30 @@ namespace Pithos.Client.WPF.SelectiveSynch
             NotifyOfPropertyChange(() => Checks);
         }
 
-        public SelectiveSynchViewModel(PithosMonitor monitor, IEventAggregator events, AccountSettings account)
+        public SelectiveSynchViewModel(/*PithosMonitor monitor,*/ IEventAggregator events, AccountSettings account, string apiKey)
         {
             Account = account;
             AccountName = account.AccountName;
             DisplayName = String.Format("Selective folder synchronization for {0}",account.AccountName);
-            _monitor = monitor;
+            //_monitor = monitor;
             _events = events;
+            _apiKey = apiKey;
             TaskEx.Run(LoadRootNode);
         }
 
         private void LoadRootNode()
-        {
-            var client = _monitor.CloudClient;
+        {            
+            //TODO: Check this
+            var client = new CloudFilesClient(AccountName,_apiKey){AuthenticationUrl=Account.ServerUrl,UsePithos=true};
+            client.Authenticate();
+            
 
-            var dirs = from container in client.ListContainers(_monitor.UserName)                       
+            var dirs = from container in client.ListContainers(AccountName)                       
                        select new DirectoryRecord
                                   {
                                       DisplayName = container.Name,
                                       Uri=new Uri(client.StorageUrl,String.Format(@"{0}/{1}",Account.AccountName, container.Name)),
-                                      Directories = (from dir in client.ListObjects(_monitor.UserName, container.Name)                                                     
+                                      Directories = (from dir in client.ListObjects(AccountName, container.Name)                                                     
                                                      where dir.IsDirectory
                                                      select dir).ToTree()
                                   };
@@ -173,21 +179,23 @@ namespace Pithos.Client.WPF.SelectiveSynch
                            from DirectoryRecord record in rootRecord
                            select record).ToList();
 
+            allNodes.Apply(record => record.IsChecked = false);
+
             if (selections.Count == 0)
             {
-                allNodes.Apply(record => record.IsChecked = false);
+            //    allNodes.Apply(record => record.IsChecked = false);
                 return;
             } 
             
             var selects = (from DirectoryRecord rootRecord in RootNodes
                           from DirectoryRecord record in rootRecord
-                          where record.Uri !=null &&  !selections.Contains(record.Uri.ToString())
+                          where record.Uri !=null &&  selections.Contains(record.Uri.ToString())
                           select record).ToList();
-            var shouldBeChecked = allNodes.Except(selects).ToList();
+            //var shouldBeChecked = allNodes.Except(selects).ToList();
 
-            selects.Apply(record=>record.IsChecked=false);
+            selects.Apply(record=>record.IsExplicitlyChecked=true);
 
-            shouldBeChecked.Apply(record => record.IsChecked = true);
+            //shouldBeChecked.Apply(record => record.IsChecked = true);
             
             
 
