forked from pozitronik/CloudMailRu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoteProperty.pas
232 lines (201 loc) · 6.64 KB
/
RemoteProperty.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
unit RemoteProperty;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, CloudMailRu, MRC_Helper, Vcl.Grids, Vcl.ValEdit, Vcl.Menus;
type
TPropertyForm = class(TForm)
PublicLinkLabel: TLabel;
WebLink: TEdit;
AccessCB: TCheckBox;
OkButton: TButton;
InvitesGB: TGroupBox;
InvitesLE: TValueListEditor;
InviteEmailEdit: TEdit;
InviteEmailLabel: TLabel;
InviteAcessCB: TComboBox;
AccessLabel: TLabel;
InviteBtn: TButton;
InvitesPopup: TPopupMenu;
ItemChangeAccess: TMenuItem;
ItemDelete: TMenuItem;
ItemRefresh: TMenuItem;
N1: TMenuItem;
procedure AccessCBClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
class function ShowProperty(parentWindow: HWND; RemoteProperty: TCloudMailRuDirListingItem; var Cloud: TCloudMailRu): integer;
procedure FormActivate(Sender: TObject);
procedure InviteBtnClick(Sender: TObject);
procedure ItemDeleteClick(Sender: TObject);
procedure ItemRefreshClick(Sender: TObject);
procedure Clean1Click(Sender: TObject);
procedure InvitesPopupPopup(Sender: TObject);
procedure ItemChangeAccessClick(Sender: TObject);
private
{Private declarations}
procedure WMHotKey(var Message: TMessage); message WM_HOTKEY;
procedure RefreshInvites();
protected
Props: TCloudMailRuDirListingItem;
InvitesListing: TCloudMailRuInviteInfoListing;
Cloud: TCloudMailRu;
public
{Public declarations}
end;
var
PropertyForm: TPropertyForm;
implementation
{$R *.dfm}
{TPropertyForm}
procedure TPropertyForm.AccessCBClick(Sender: TObject);
var
PublicLink: WideString;
begin
WebLink.Text := 'Wait for it...';
AccessCB.Enabled := false; //блокируем во избежание повторных кликов
if AccessCB.checked then
begin
if Self.Cloud.publishFile(Props.home, PublicLink) then
begin
WebLink.Text := 'https://cloud.mail.ru/public/' + PublicLink;
Props.WebLink := PublicLink;
WebLink.Enabled := true;
WebLink.SetFocus;
WebLink.SelectAll;
end else begin
MessageBoxW(Self.Handle, PWideChar('Error while publishing file ' + Props.home + ', see main log'), 'File publishing error', MB_OK + MB_ICONERROR);
end;
end else begin
if Cloud.publishFile(Props.home, Props.WebLink, CLOUD_UNPUBLISH) then
begin
WebLink.Text := '';
Props.WebLink := '';
WebLink.Enabled := false;
end else begin
MessageBoxW(Self.Handle, PWideChar('Error while unpublishing file ' + Props.home + ', see main log'), 'File unpublishing error', MB_OK + MB_ICONERROR);
end;
end;
AccessCB.Enabled := true;
end;
procedure TPropertyForm.Clean1Click(Sender: TObject);
begin
while InvitesLE.Strings.Count > 0 do InvitesLE.DeleteRow(1);
end;
procedure TPropertyForm.FormActivate(Sender: TObject);
begin
CenterWindow(Self.parentWindow, Self.Handle);
end;
procedure TPropertyForm.FormDestroy(Sender: TObject);
begin
UnregisterHotKey((Sender as TPropertyForm).Handle, 1)
end;
procedure TPropertyForm.FormShow(Sender: TObject);
begin
if not(Props.WebLink = '') then
begin
WebLink.Text := 'https://cloud.mail.ru/public/' + Props.WebLink;
WebLink.SetFocus;
WebLink.SelectAll;
end;
AccessCB.checked := not(Props.WebLink = '');
WebLink.Enabled := AccessCB.checked;
if Props.type_ = TYPE_DIR then
begin
InvitesGB.Height :=210;
InvitesGB.Enabled:=true;
RefreshInvites;
end else begin
InvitesGB.Height :=0;
InvitesGB.Enabled:=false;
end;
end;
procedure TPropertyForm.InviteBtnClick(Sender: TObject);
begin
if (Cloud.shareFolder(Props.home, InviteEmailEdit.Text, InviteAcessCB.ItemIndex)) then
begin
RefreshInvites;
end else begin
MessageBoxW(Self.Handle, PWideChar('Error while inviting ' + InviteEmailEdit.Text + ' to ' + Props.home + ' folder, see main log'), 'Folder invite error', MB_OK + MB_ICONERROR);
end;
end;
procedure TPropertyForm.InvitesPopupPopup(Sender: TObject);
var
email, access: WideString;
begin
email := InvitesLE.Keys[InvitesLE.Row];
if email = '' then
begin
ItemChangeAccess.Visible:=false;
ItemDelete.Visible := false;
exit;
end else begin
ItemChangeAccess.Visible:=true;
ItemDelete.Visible:=true;
end;
access :=InvitesLE.Values[email];
access := TCloudMailRu.CloudAccessToString(access, true);
ItemChangeAccess.Caption:='Change access to ' + access;
end;
procedure TPropertyForm.ItemChangeAccessClick(Sender: TObject);
var
email, access: WideString;
begin
email := InvitesLE.Keys[InvitesLE.Row];
access :=InvitesLE.Values[email];
if Cloud.shareFolder(Props.home, InvitesLE.Keys[InvitesLE.Row], TCloudMailRu.StringToCloudAccess(access, true)) then
begin
RefreshInvites;
end else begin
MessageBoxW(Self.Handle, PWideChar('Error while removing access to ' + InviteEmailEdit.Text + ' from ' + Props.home + ' folder, see main log'), 'Folder unshare error', MB_OK + MB_ICONERROR);
end;
end;
procedure TPropertyForm.ItemDeleteClick(Sender: TObject);
begin
if Cloud.shareFolder(Props.home, InvitesLE.Keys[InvitesLE.Row], CLOUD_SHARE_NO) then
begin
RefreshInvites;
end else begin
MessageBoxW(Self.Handle, PWideChar('Error while removing access to ' + InviteEmailEdit.Text + ' from ' + Props.home + ' folder, see main log'), 'Folder unshare error', MB_OK + MB_ICONERROR);
end;
end;
procedure TPropertyForm.ItemRefreshClick(Sender: TObject);
begin
RefreshInvites;
end;
procedure TPropertyForm.RefreshInvites;
var
i, InvitesCount: integer;
begin
while InvitesLE.Strings.Count > 0 do InvitesLE.DeleteRow(1);
if Cloud.getShareInfo(Props.home, Self.InvitesListing) then
begin
InvitesCount:=Length(Self.InvitesListing) - 1;
for i := 0 to InvitesCount do
begin
InvitesLE.InsertRow(Self.InvitesListing[i].name, TCloudMailRu.CloudAccessToString(Self.InvitesListing[i].access), true);
end;
end else begin
MessageBoxW(Self.Handle, PWideChar('Error while retrieving ' + Props.home + ' folder invites list, see main log'), 'Folder invite listing error', MB_OK + MB_ICONERROR);
end;
end;
class function TPropertyForm.ShowProperty(parentWindow: HWND; RemoteProperty: TCloudMailRuDirListingItem; var Cloud: TCloudMailRu): integer; //todo do we need cloud as var parameter?
var
PropertyForm: TPropertyForm;
begin
try
PropertyForm := TPropertyForm.Create(nil);
PropertyForm.parentWindow := parentWindow;
PropertyForm.Caption := RemoteProperty.name;
PropertyForm.Cloud := Cloud;
PropertyForm.Props := RemoteProperty;
RegisterHotKey(PropertyForm.Handle, 1, 0, VK_ESCAPE);
result := PropertyForm.Showmodal;
finally
FreeAndNil(PropertyForm);
end;
end;
procedure TPropertyForm.WMHotKey(var Message: TMessage);
begin
if (Message.LParamHi = VK_ESCAPE) and (GetForegroundWindow = Self.Handle) then Close;
end;
end.