2011-07-04 17:52:46 +00:00
|
|
|
// SparkleShare, a collaboration and sharing tool.
|
|
|
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2011-10-01 21:15:46 +00:00
|
|
|
using System.Collections.Generic;
|
2011-07-04 17:52:46 +00:00
|
|
|
using System.IO;
|
|
|
|
|
2011-10-01 21:15:46 +00:00
|
|
|
using SparkleLib;
|
|
|
|
|
2011-07-04 17:52:46 +00:00
|
|
|
namespace SparkleShare {
|
|
|
|
|
|
|
|
public enum PageType {
|
|
|
|
Setup,
|
|
|
|
Add,
|
|
|
|
Syncing,
|
|
|
|
Error,
|
2011-09-13 00:05:45 +00:00
|
|
|
Finished,
|
|
|
|
Tutorial
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class SparkleSetupController {
|
|
|
|
|
|
|
|
public event ChangePageEventHandler ChangePageEvent;
|
|
|
|
public delegate void ChangePageEventHandler (PageType page);
|
2011-08-27 15:53:17 +00:00
|
|
|
|
|
|
|
public event UpdateProgressBarEventHandler UpdateProgressBarEvent;
|
2011-08-27 15:10:39 +00:00
|
|
|
public delegate void UpdateProgressBarEventHandler (double percentage);
|
2011-07-04 17:52:46 +00:00
|
|
|
|
2011-10-04 23:08:37 +00:00
|
|
|
public event ChangeAddressFieldEventHandler ChangeAddressFieldEvent;
|
|
|
|
public delegate void ChangeAddressFieldEventHandler (string text,
|
|
|
|
string example_text, FieldState state);
|
|
|
|
|
|
|
|
public event ChangePathFieldEventHandler ChangePathFieldEvent;
|
|
|
|
public delegate void ChangePathFieldEventHandler (string text,
|
|
|
|
string example_text, FieldState state);
|
|
|
|
|
2011-10-01 21:15:46 +00:00
|
|
|
public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> ();
|
2011-10-04 23:08:37 +00:00
|
|
|
public SparklePlugin SelectedPlugin;
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2011-09-13 00:05:45 +00:00
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
public int SelectedPluginIndex {
|
|
|
|
get {
|
|
|
|
return Plugins.IndexOf (SelectedPlugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-13 00:05:45 +00:00
|
|
|
public int TutorialPageNumber {
|
|
|
|
get {
|
|
|
|
return this.tutorial_page_number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 18:57:34 +00:00
|
|
|
public string PreviousUrl {
|
|
|
|
get {
|
|
|
|
return this.previous_url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
public string PreviousAddress {
|
2011-07-04 17:52:46 +00:00
|
|
|
get {
|
2011-10-05 21:23:35 +00:00
|
|
|
return this.previous_address;
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
public string PreviousPath {
|
2011-07-04 17:52:46 +00:00
|
|
|
get {
|
2011-10-05 21:23:35 +00:00
|
|
|
return this.previous_path;
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string SyncingFolder {
|
|
|
|
get {
|
|
|
|
return this.syncing_folder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public PageType PreviousPage {
|
|
|
|
get {
|
|
|
|
return this.previous_page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-22 18:54:28 +00:00
|
|
|
public string GuessedUserName {
|
|
|
|
get {
|
|
|
|
return Program.Controller.UserName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GuessedUserEmail {
|
|
|
|
get {
|
|
|
|
if (Program.Controller.UserEmail.Equals ("Unknown"))
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return Program.Controller.UserEmail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-13 00:05:45 +00:00
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
private string previous_address = "";
|
|
|
|
private string previous_path = "";
|
2011-09-13 00:05:45 +00:00
|
|
|
private string previous_url = "";
|
|
|
|
private string syncing_folder = "";
|
|
|
|
private int tutorial_page_number = 1;
|
2011-07-04 17:52:46 +00:00
|
|
|
private PageType previous_page;
|
|
|
|
|
2011-09-13 00:05:45 +00:00
|
|
|
|
2011-07-04 17:52:46 +00:00
|
|
|
public SparkleSetupController ()
|
|
|
|
{
|
2011-10-01 21:15:46 +00:00
|
|
|
string local_plugins_path = SparkleHelpers.CombineMore (
|
|
|
|
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
|
|
|
"sparkleshare", "plugins");
|
|
|
|
|
2011-10-01 22:19:31 +00:00
|
|
|
if (Directory.Exists (local_plugins_path))
|
2011-10-01 21:15:46 +00:00
|
|
|
foreach (string xml_file_path in Directory.GetFiles (local_plugins_path, "*.xml"))
|
|
|
|
Plugins.Add (new SparklePlugin (xml_file_path));
|
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
if (Directory.Exists (Program.Controller.PluginsPath)) {
|
|
|
|
foreach (string xml_file_path in Directory.GetFiles (Program.Controller.PluginsPath, "*.xml")) {
|
2011-10-04 23:08:37 +00:00
|
|
|
if (xml_file_path.EndsWith ("own-server.xml"))
|
|
|
|
Plugins.Insert (0, new SparklePlugin (xml_file_path));
|
|
|
|
else
|
|
|
|
Plugins.Add (new SparklePlugin (xml_file_path));
|
|
|
|
}
|
|
|
|
}
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
SelectedPlugin = Plugins [0];
|
|
|
|
|
2011-07-04 17:52:46 +00:00
|
|
|
ChangePageEvent += delegate (PageType page) {
|
|
|
|
this.previous_page = page;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ShowSetupPage ()
|
|
|
|
{
|
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetupPageCompleted (string full_name, string email)
|
|
|
|
{
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.UserName = full_name;
|
|
|
|
Program.Controller.UserEmail = email;
|
2011-07-04 17:52:46 +00:00
|
|
|
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.GenerateKeyPair ();
|
|
|
|
Program.Controller.UpdateState ();
|
2011-07-04 17:52:46 +00:00
|
|
|
|
|
|
|
if (ChangePageEvent != null)
|
2011-09-13 00:05:45 +00:00
|
|
|
ChangePageEvent (PageType.Tutorial);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void TutorialPageCompleted ()
|
|
|
|
{
|
2011-09-22 18:54:28 +00:00
|
|
|
this.tutorial_page_number++;
|
2011-09-13 00:05:45 +00:00
|
|
|
|
2011-09-22 18:54:28 +00:00
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Tutorial);
|
2011-09-13 00:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void TutorialSkipped ()
|
|
|
|
{
|
|
|
|
this.tutorial_page_number = 4;
|
|
|
|
|
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Tutorial);
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
public void ShowAddPage ()
|
|
|
|
{
|
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Add);
|
|
|
|
|
|
|
|
SelectedPluginChanged (SelectedPluginIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddPageCompleted (string address, string path)
|
2011-07-04 17:52:46 +00:00
|
|
|
{
|
2011-10-05 21:23:35 +00:00
|
|
|
this.syncing_folder = Path.GetFileNameWithoutExtension (path);
|
|
|
|
this.previous_address = address;
|
|
|
|
this.previous_path = path;
|
2011-07-04 17:52:46 +00:00
|
|
|
|
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Syncing);
|
|
|
|
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.FolderFetched += delegate {
|
2011-07-04 17:52:46 +00:00
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Finished);
|
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
this.previous_address = "";
|
|
|
|
this.syncing_folder = "";
|
|
|
|
this.previous_url = "";
|
|
|
|
SelectedPlugin = Plugins [0];
|
2011-07-04 17:52:46 +00:00
|
|
|
};
|
|
|
|
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.FolderFetchError += delegate (string remote_url) {
|
2011-08-27 18:57:34 +00:00
|
|
|
this.previous_url = remote_url;
|
|
|
|
|
2011-07-04 17:52:46 +00:00
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Error);
|
|
|
|
|
|
|
|
this.syncing_folder = "";
|
|
|
|
};
|
2011-08-27 15:53:17 +00:00
|
|
|
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.FolderFetching += delegate (double percentage) {
|
2011-08-27 15:53:17 +00:00
|
|
|
if (UpdateProgressBarEvent != null)
|
|
|
|
UpdateProgressBarEvent (percentage);
|
|
|
|
};
|
2011-07-04 17:52:46 +00:00
|
|
|
|
2011-10-05 21:23:35 +00:00
|
|
|
Program.Controller.FetchFolder (address, path);
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ErrorPageCompleted ()
|
|
|
|
{
|
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Add);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-26 20:47:46 +00:00
|
|
|
public void SyncingCancelled ()
|
|
|
|
{
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.StopFetcher ();
|
2011-08-26 20:47:46 +00:00
|
|
|
|
|
|
|
if (ChangePageEvent != null)
|
|
|
|
ChangePageEvent (PageType.Add);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-04 17:52:46 +00:00
|
|
|
public void FinishedPageCompleted ()
|
|
|
|
{
|
2011-10-05 21:23:35 +00:00
|
|
|
this.previous_address = "";
|
|
|
|
this.previous_path = "";
|
2011-09-03 20:23:45 +00:00
|
|
|
Program.Controller.UpdateState ();
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
2011-10-04 23:08:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
public void SelectedPluginChanged (int plugin_index)
|
|
|
|
{
|
|
|
|
SelectedPlugin = Plugins [plugin_index];
|
|
|
|
|
|
|
|
if (SelectedPlugin.Address != null) {
|
|
|
|
if (ChangeAddressFieldEvent != null)
|
2011-10-05 21:23:35 +00:00
|
|
|
ChangeAddressFieldEvent (SelectedPlugin.Address, "", FieldState.Disabled);
|
2011-10-04 23:08:37 +00:00
|
|
|
|
|
|
|
} else if (SelectedPlugin.AddressExample != null) {
|
|
|
|
if (ChangeAddressFieldEvent != null)
|
2011-10-05 21:23:35 +00:00
|
|
|
ChangeAddressFieldEvent ("", SelectedPlugin.AddressExample, FieldState.Enabled);
|
2011-10-04 23:08:37 +00:00
|
|
|
} else {
|
|
|
|
if (ChangeAddressFieldEvent != null)
|
2011-10-05 21:23:35 +00:00
|
|
|
ChangeAddressFieldEvent ("", "", FieldState.Enabled);
|
2011-10-04 23:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SelectedPlugin.Path != null) {
|
|
|
|
if (ChangePathFieldEvent != null)
|
2011-10-05 21:23:35 +00:00
|
|
|
ChangePathFieldEvent (SelectedPlugin.Path, "", FieldState.Disabled);
|
2011-10-04 23:08:37 +00:00
|
|
|
|
|
|
|
} else if (SelectedPlugin.PathExample != null) {
|
|
|
|
if (ChangePathFieldEvent != null)
|
2011-10-05 21:23:35 +00:00
|
|
|
ChangePathFieldEvent ("", SelectedPlugin.PathExample, FieldState.Enabled);
|
2011-10-04 23:08:37 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (ChangePathFieldEvent != null)
|
2011-10-05 21:23:35 +00:00
|
|
|
ChangePathFieldEvent ("", "", FieldState.Enabled);
|
2011-10-04 23:08:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum FieldState {
|
|
|
|
Enabled,
|
|
|
|
Disabled
|
2011-07-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
}
|