/
FDPreferences.cs
115 lines (98 loc) · 3.07 KB
/
FDPreferences.cs
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
/*
* Copyright 2012 Far Dog LLC or its affiliates. All Rights Reserved.
*
* Licensed under the GNU General Public License, Version 3.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* or in the "gpl-3.0" file accompanying this file. This file 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.
*/
using System;
using Gtk;
namespace snowpack
{
public partial class FDPreferences : Gtk.Dialog
{
FDUserSettings settings;
bool isFirstRun;
bool allowExit;
public FDPreferences (Gtk.Window win, Gtk.DialogFlags f, FDUserSettings userset, bool firstRun = false)
: base ("Preferences", win, f)
{
this.Build ();
settings = userset;
isFirstRun = firstRun;
allowExit = false;
//fill the settings fields
entryAWSAccessKey.Text = settings.AWSAccessKey;
entryAWSSecretKey.Text = settings.AWSSecretKey;
entryAWSGlacierVaultName.Text = settings.AWSGlacierVaultName;
comboboxAWSRegion.Active = settings.AWSRegion;
this.DeleteEvent += OnDeleteEvent;
//you can't cancel if this is firstrun
if(firstRun) buttonCancel.Sensitive = false;
}
//we need to verify that something has been entered at least
protected void VerifyOkResponse (object sender, System.EventArgs e)
{
Gdk.Color errorColor = new Gdk.Color(255,200,200);
bool allowSave = true;
if(String.IsNullOrWhiteSpace(entryAWSAccessKey.Text)) {
entryAWSAccessKey.ModifyBase(StateType.Normal, errorColor);
allowSave = false;
}
if(String.IsNullOrWhiteSpace(entryAWSSecretKey.Text)) {
entryAWSSecretKey.ModifyBase(StateType.Normal, errorColor);
allowSave = false;
}
if(String.IsNullOrWhiteSpace(entryAWSGlacierVaultName.Text)) {
entryAWSGlacierVaultName.ModifyBase(StateType.Normal, errorColor);
allowSave = false;
}
if(String.IsNullOrWhiteSpace(comboboxAWSRegion.ActiveText)) {
comboboxAWSRegion.ModifyBase(StateType.Normal, errorColor);
allowSave = false;
}
if (allowSave) {
settings.AWSAccessKey = entryAWSAccessKey.Text;
settings.AWSSecretKey = entryAWSSecretKey.Text;
settings.AWSGlacierVaultName = entryAWSGlacierVaultName.Text;
settings.AWSRegion = comboboxAWSRegion.Active;
settings.SaveSettings();
allowExit = true;
this.Respond(ResponseType.Ok);
}
else {
labelError.Text = "You must fill all required fields.";
}
}
protected void OnDeleteEvent(object sender, DeleteEventArgs e)
{
if(this.isFirstRun)
{
if(allowExit)
{
e.RetVal = false;
return;
}
e.RetVal = true;
return;
}
e.RetVal = false;
return;
}
protected void OnButtonOkClicked (object sender, System.EventArgs e)
{
VerifyOkResponse(sender, e);
}
protected void OnButtonOkActivated (object sender, System.EventArgs e)
{
VerifyOkResponse(sender, e);
}
}
}