CASA/c_gui/CommonGUI.cs
2005-10-12 15:27:21 +00:00

181 lines
4.2 KiB
C#

using System;
using Gtk;
using Glade;
using Novell.CASA;
using Novell.CASA.MiCasa.Common;
using Novell.CASA.MiCasa.Communication;
namespace Novell.CASA.GUI
{
/// <summary>
/// Summary description for CommonGUI.
/// </summary>
public class CommonGUI
{
[Glade.Widget]
Gtk.Label label86,
label88;
[Glade.Widget]
Gtk.Entry entryMasterPassword1,
entryMasterPassword2,
entryMasterPassword3,
entryMasterPassword4;
[Glade.Widget]
Gtk.Dialog dialogLogin;
Gtk.Window mainWindow = new Window("Test");
private CasaMain mCasaInstance = null;
private CasaTray mTrayInstance = null;
public CommonGUI()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// HandleUnlock dialog
/// </summary>
public void HandleUnlock(CasaMain managerInstance, CasaTray trayInstance)
{
mCasaInstance = managerInstance;
mTrayInstance = trayInstance;
//Logger.DbgLog("GUI:CasaMain.Login() - IsMasterPasswordSet returned false");
#if W32
Glade.XML gxmlTemp = new Glade.XML ("../images/casa-1.5.glade", "dialogLogin", null);
#endif
#if LINUX
Glade.XML gxmlTemp = new Glade.XML ("/opt/novell/CASA/images/casa-1.5.glade", "dialogLogin", null);
#endif
gxmlTemp.Autoconnect (this);
//dialogLogin.TransientFor = windowMain;
label86.Text = "Enter your Master Password to unlock your secrets";
entryMasterPassword3.Text="";
label88.Hide();
entryMasterPassword4.Hide();
dialogLogin.SetPosition(Gtk.WindowPosition.Center);
dialogLogin.Destroyed += new EventHandler(dialogLogin_Destroyed);
dialogLogin.Show();
}
internal static void menuDestroyMiCasa_Activated(object sender, EventArgs e)
{
// prompt user
MessageDialog md=new MessageDialog(null,Gtk.DialogFlags.Modal,
Gtk.MessageType.Warning,
Gtk.ButtonsType.OkCancel,
"This will destroy all of your miCASA secrets.\r\nAre you sure?");
md.SetPosition(Gtk.WindowPosition.Center);
md.Response +=new ResponseHandler(md_Response);
md.Modal = true;
md.Show();
}
private static void md_Response(object o, ResponseArgs args)
{
if (args.ResponseId.Equals(Gtk.ResponseType.Ok))
{
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_ALL_SECRETS);
}
MessageDialog md = (MessageDialog)o;
if (md != null)
{
md.Destroy();
}
}
private void md_Response2(object o, ResponseArgs args)
{
MessageDialog md = (MessageDialog)o;
if (md != null)
{
md.Destroy();
}
}
public void okbuttonLogin_clicked(object abj, EventArgs args)
{
if( 0 == miCASA.SetMasterPassword(0, entryMasterPassword3.Text) )
{
// unlock it
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_UNLOCK_STORE, entryMasterPassword3.Text);
dialogLogin.Destroy();
}
else
{
// prompt user
MessageDialog md=new MessageDialog(mainWindow,Gtk.DialogFlags.Modal,
Gtk.MessageType.Warning,
Gtk.ButtonsType.Ok,
"Master Password entered is incorrect");
md.Response +=new ResponseHandler(md_Response2);
md.SetPosition(Gtk.WindowPosition.CenterOnParent);
md.Modal = true;
md.Show();
}
}
public void closebuttonLogin_clicked(object abj, EventArgs args)
{
dialogLogin.Destroy();
}
public void OnDialogLoginDeleted(object obj, DeleteEventArgs args)
{
args.RetVal = true;
}
public void on_entryMasterPassword3_activate(object obj, EventArgs args)
{
if( true == entryMasterPassword4.Visible )
entryMasterPassword4.HasFocus = true;
else if( "" != entryMasterPassword3.Text )
okbuttonLogin_clicked(obj, args);
}
public void on_entryMasterPassword4_activate(object obj, EventArgs args)
{
okbuttonLogin_clicked(obj, args);
}
private void dialogLogin_Destroyed(object sender, EventArgs e)
{
bool bStoreLocked = MiCASAStore.IsLocked();
if (mCasaInstance != null)
{
if (bStoreLocked)
mCasaInstance.LockGUI();
else
mCasaInstance.UnlockGUI();
}
if (mTrayInstance != null)
{
if (bStoreLocked)
mTrayInstance.UpdateTrayIcon(true);
else
mTrayInstance.UpdateTrayIcon(false);
}
}
}
}