--- /dev/null
+using System;
+using System.Collections.Generic;
+using Gtk;
+
+using mCloudAwk;
+
+namespace mCloudGui {
+
+ public partial class MainWindow: Gtk.Window
+ {
+ private const string new_text = "new ...";
+ private IMCloudAwk MCA;
+
+ public MainWindow (): base (Gtk.WindowType.Toplevel)
+ {
+ Build ();
+ this.MCA = new MCloudMgr ();
+ TConnection[] Conns = MCA.GetConnections ();
+ foreach (var Conn in Conns) {
+ this.ConnectionSelection.AppendText (Conn.Name);
+ }
+ this.ConnectionSelection.AppendText (new_text);
+ this.ConnectionSelection.Active = 0;
+ }
+
+ protected void OnDeleteEvent (object sender, DeleteEventArgs a)
+ {
+ MCA.Dispose ();
+ Application.Quit ();
+ a.RetVal = true;
+ }
+
+ protected void TestButtonPressed (object sender, EventArgs e)
+ {
+ // extract connection name
+ string connection_name = this.ConnectionSelection.ActiveText;
+
+ // TODO: implement ssh connection test
+ int r = this.MCA.TestConnection (connection_name);
+
+ if (r == MCloudMgr.SSH_NO_PW || r == MCloudMgr.SSH_WITH_PW) {
+ // everything fine
+ } else {
+ GtkUtil.MessageBox.Show("Keine ssh-Verbindung möglich");
+ return;
+ }
+
+ // if connection is new, add it to configuration
+ if (connection_name == new_text) {
+
+ // build connection object
+ connection_name = this.UserField.Text + "@" + this.ServerField.Text;
+ TConnection C = new TConnection {
+ Name = connection_name,
+ User = this.UserField.Text,
+ Server = this.ServerField.Text,
+ Password = this.PasswordField.Text
+ };
+ this.MCA.AddConnection (C);
+ }
+
+ // TODO: check login w/o password
+ bool login_without_password_possible = false;
+
+ if (!login_without_password_possible) {
+
+ // check existence of public key file
+ if (!System.IO.File.Exists ("/home/monodev/.ssh/id_dsa.pub")) {
+
+ // TODO: create public key file
+ using (System.IO.StreamWriter File = new System.IO.StreamWriter ("/home/monodev/.ssh/id_dsa.pub", false)) {
+ File.WriteLine ("Hallo");
+ }
+ }
+ // TODO: scp file to target
+ // TODO: append it to .ssh/authorized_keys
+ // TODO: test login w/o password again
+ }
+ // TODO: next configution step
+ this.Destroy ();
+ MCA.Dispose ();
+ DirectorySelectionWin DirWin = new DirectorySelectionWin ();
+ DirWin.Show ();
+
+ }
+
+ protected void ConnectionSelectionChanged (object sender, EventArgs e)
+ {
+ if (((Gtk.ComboBox)sender).ActiveText.IndexOf ('@') > 0) {
+ // grey input fields
+ this.ServerField.Sensitive = false;
+ this.PasswordField.Sensitive = false;
+ this.UserField.Sensitive = false;
+
+ // activate delete button
+ this.DeleteConnectionBtn.Sensitive = true;
+ } else {
+ // activate input fields
+ this.ServerField.Sensitive = true;
+ this.PasswordField.Sensitive = true;
+ this.UserField.Sensitive = true;
+
+ // deactivate delete button
+ this.DeleteConnectionBtn.Sensitive = false;
+ }
+ }
+
+ protected void DeleteConnectionPressed (object sender, EventArgs e)
+ {
+ string connection = this.ConnectionSelection.ActiveText;
+ if (this.ConnectionSelection.ActiveText.IndexOf ('@') == -1)
+ throw new Exception ("Cannot remove default entry");
+ int connPos = this.ConnectionSelection.Active;
+ this.ConnectionSelection.Active = connPos+1;
+ this.ConnectionSelection.RemoveText (connPos);
+ this.MCA.DeleteConnection (connection);
+ }
+ }
+}
\ No newline at end of file