80
82
public override Gtk.Widget CreatePreferencesControl ()
82
84
Gtk.Table table = new Gtk.Table (1, 3, false);
84
86
// Read settings out of gconf
86
88
if (GetConfigSettings (out syncPath) == false)
87
89
syncPath = string.Empty;
89
Label l = new Label (Catalog.GetString ("Folder Path:"));
91
Label l = new Label (Catalog.GetString ("_Folder Path:"));
91
93
table.Attach (l, 0, 1, 0, 1);
93
95
pathEntry = new Entry ();
94
96
pathEntry.Text = syncPath;
95
97
table.Attach (pathEntry, 1, 2, 0, 1);
98
l.MnemonicWidget = pathEntry;
97
100
Image browseImage = new Image (Stock.Open, IconSize.Button);
98
Label browseLabel = new Label (Catalog.GetString ("Browse..."));
101
Label browseLabel = new Label (Catalog.GetString ("_Browse..."));
100
103
HBox browseBox = new HBox (false, 0);
101
104
browseBox.PackStart (browseImage);
102
browseBox.PackStart (browseLabel);
105
browseBox.PackStart (browseLabel);
104
107
Button browseButton = new Button ();
105
108
browseButton.Add (browseBox);
109
browseLabel.MnemonicWidget = browseButton;
106
110
browseButton.Clicked += OnBrowseButtonClicked;
107
111
table.Attach (browseButton, 2, 3, 0, 1, AttachOptions.Shrink, AttachOptions.Expand, 0, 0);
109
113
table.ShowAll ();
113
117
private void OnBrowseButtonClicked (object sender, EventArgs args)
115
119
FileChooserDialog chooserDlg =
116
new FileChooserDialog (Catalog.GetString ("Select Synchronization Folder..."),
118
FileChooserAction.SelectFolder,
119
Stock.Cancel, ResponseType.Cancel,
120
Stock.Ok, ResponseType.Ok);
120
new FileChooserDialog (Catalog.GetString ("Select Synchronization Folder..."),
122
FileChooserAction.SelectFolder,
123
Stock.Cancel, ResponseType.Cancel,
124
Stock.Ok, ResponseType.Ok);
121
125
chooserDlg.DefaultResponse = ResponseType.Cancel;
122
126
chooserDlg.SetFilename (pathEntry.Text);
124
128
ResponseType response = (ResponseType) chooserDlg.Run ();
126
130
if (response == ResponseType.Ok)
127
131
pathEntry.Text = chooserDlg.Filename;
129
133
chooserDlg.Destroy ();
133
137
/// The Addin should verify and check the connection to the service
134
138
/// when this is called. If verification and connection is successful,
137
141
public override bool SaveConfiguration ()
139
143
string syncPath = pathEntry.Text.Trim ();
141
145
if (syncPath == string.Empty) {
142
146
// TODO: Figure out a way to send the error back to the client
143
147
Logger.Debug ("The path is empty");
144
148
throw new TomboySyncException (Catalog.GetString ("Folder path field is empty."));
147
151
// Attempt to create the path and fail if we can't
148
152
if (Directory.Exists (syncPath) == false) {
159
163
string testPathBase = Path.Combine (syncPath, "test");
160
164
string testPath = testPathBase;
163
167
// Get unique new file name
164
168
while (File.Exists (testPath))
165
169
testPath = testPathBase + (++count).ToString ();
167
171
// Test ability to create and write
168
172
string testLine = "Testing write capabilities.";
169
173
using (FileStream fs = File.Create (testPath)) {
170
174
StreamWriter writer = new StreamWriter (fs);
171
175
writer.WriteLine (testLine);
174
178
// Test ability to read
175
179
bool testFileFound = false;
176
180
foreach (string filePath in Directory.GetFiles (syncPath))
177
if (filePath == testPath) {
178
testFileFound = true;
181
if (filePath == testPath) {
182
testFileFound = true;
181
185
if (!testFileFound)
182
186
; // TODO: Throw TomboySyncException
183
187
using (StreamReader reader = new StreamReader (testPath)) {
184
188
if (reader.ReadLine () != testLine)
185
189
; // TODO: Throw TomboySyncException
188
192
// Test ability to delete
189
193
File.Delete (testPath);
194
198
// TODO: Try to create and delete a file. If it fails, this should fail
195
199
Preferences.Set (Preferences.SYNC_LOCAL_PATH, path);