root / trunk / Pithos.OFM / FileManagerViewModel.cs @ 71374945
History | View | Annotate | Download (4 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel.Composition; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Threading.Tasks; |
7 |
using System.Windows; |
8 |
using Caliburn.Micro; |
9 |
using Pithos.Interfaces; |
10 |
using Pithos.Network; |
11 |
|
12 |
namespace Pithos.OFM |
13 |
{ |
14 |
[Export, PartCreationPolicy(CreationPolicy.Shared)] |
15 |
public class FileManagerViewModel:Screen |
16 |
{ |
17 |
[Import] |
18 |
public CloudFilesViewModel CloudFiles { get; set; } |
19 |
|
20 |
[Import] |
21 |
public LocalFilesViewModel LocalFiles { get; set; } |
22 |
|
23 |
public IEnumerable<AccountSettings> Accounts |
24 |
{ |
25 |
get { return _accounts; } |
26 |
set |
27 |
{ |
28 |
if (Equals(value, _accounts)) return; |
29 |
_accounts = value; |
30 |
NotifyOfPropertyChange(() => Accounts); |
31 |
} |
32 |
} |
33 |
|
34 |
public string Title |
35 |
{ |
36 |
get { return _title; } |
37 |
set |
38 |
{ |
39 |
if (value == _title) return; |
40 |
_title = value; |
41 |
NotifyOfPropertyChange(() => Title); |
42 |
} |
43 |
} |
44 |
|
45 |
public bool IsCloudSelected |
46 |
{ |
47 |
get { return CloudFiles.IsCloudSelected; } |
48 |
set |
49 |
{ |
50 |
if (value.Equals(CloudFiles.IsCloudSelected)) return; |
51 |
CloudFiles.IsCloudSelected = value; |
52 |
LocalFiles.IsLocalSelected = !value; |
53 |
NotifyOfPropertyChange(() => IsCloudSelected); |
54 |
} |
55 |
} |
56 |
|
57 |
public bool IsLocalSelected |
58 |
{ |
59 |
get { return LocalFiles.IsLocalSelected; } |
60 |
set |
61 |
{ |
62 |
if (value.Equals(LocalFiles.IsLocalSelected)) return; |
63 |
LocalFiles.IsLocalSelected = value; |
64 |
IsCloudSelected = !value; |
65 |
NotifyOfPropertyChange(() => IsLocalSelected); |
66 |
} |
67 |
} |
68 |
|
69 |
private IEnumerable<AccountSettings> _accounts; |
70 |
private string _title; |
71 |
|
72 |
private AccountSettings _currentAccount; |
73 |
|
74 |
private AccountSettings _currentLoadedAccount; |
75 |
|
76 |
public AccountSettings CurrentAccount |
77 |
{ |
78 |
get |
79 |
{ |
80 |
return _currentAccount; |
81 |
} |
82 |
set |
83 |
{ |
84 |
if (_currentAccount==value) return; |
85 |
|
86 |
_currentAccount = value; |
87 |
NotifyOfPropertyChange(() => CurrentAccount); |
88 |
|
89 |
|
90 |
if (_currentAccount != null) |
91 |
{ |
92 |
//Value can be null while selecting a new account |
93 |
//We need a separate account field to record the last account we loaded |
94 |
if (_currentLoadedAccount == value) return; |
95 |
_currentLoadedAccount = value; |
96 |
|
97 |
this.Title = String.Format("Pithos+ OFM - {0}", _currentAccount.AccountName); |
98 |
|
99 |
|
100 |
|
101 |
TaskEx.Run(() => LocalFiles.LoadLocalFiles(_currentAccount.RootPath)); |
102 |
TaskEx.Run( |
103 |
() => |
104 |
CloudFiles.LoadCloudFiles(_currentAccount.AccountName, _currentAccount.ApiKey, _currentAccount.ServerUrl)); |
105 |
} |
106 |
} |
107 |
} |
108 |
|
109 |
|
110 |
|
111 |
public FileManagerViewModel() |
112 |
{ |
113 |
DisplayName = "Pithos+ OFM"; |
114 |
// _watcher.Created += (o, e) => NotifyOfPropertyChange(()=>LocalItems); |
115 |
// _watcher.Deleted += (o, e) => NotifyOfPropertyChange(() => LocalItems); |
116 |
// _watcher.Renamed += (o, e) => NotifyOfPropertyChange(() => LocalItems); |
117 |
} |
118 |
|
119 |
|
120 |
|
121 |
public bool CanUpload { get { return LocalFiles.CanUpload; } } |
122 |
|
123 |
public void Upload() |
124 |
{ |
125 |
|
126 |
} |
127 |
|
128 |
public bool CanDownload { get { return CloudFiles.CanDownload; } } |
129 |
|
130 |
public void Download() |
131 |
{ |
132 |
|
133 |
} |
134 |
} |
135 |
} |