diff --git a/c_gui/CasaMain.cs b/c_gui/CasaMain.cs index 6a8c6b2f..7c2f5264 100644 --- a/c_gui/CasaMain.cs +++ b/c_gui/CasaMain.cs @@ -19,6 +19,9 @@ using Novell.CASA; using Novell.CASA.MiCasa.Common; using Novell.CASA.MiCasa.Communication; +#if W32 +using Microsoft.Win32; +#endif public class CasaMain { @@ -84,6 +87,8 @@ public class CasaMain mmiEdit, mmiOptions, mmiDebug; + [Glade.Widget] + Gtk.CheckMenuItem mmiShowTaskIcon; #endregion @@ -106,12 +111,24 @@ public class CasaMain Application.Init(); - if (Common.IsTrayAvailable() && Common.IsArgSet(args, Common.ARG_SHOW_TRAY_ICON)) + if (args.Length > 0) { - mCasaTray = new CasaTray(); + if (Common.IsTrayAvailable() && Common.IsArgSet(args, Common.ARG_SHOW_TRAY_ICON)) + { + mCasaTray = new CasaTray(); + } + else + { + // launch both + if (Common.IsTrayAvailable()) + mCasaTray = new CasaTray(); + new CasaMain(args); + } } else + { new CasaMain(args); + } Application.Run(); @@ -220,6 +237,9 @@ public class CasaMain else UnlockGUI(); + if (mCasaTray != null) + mmiShowTaskIcon.Active = true; + windowMain.Show(); Logger.DbgLog("GUI:CasaMain.InitializeGUI() - END"); @@ -727,13 +747,13 @@ public class CasaMain public void OnDestroyMiCASASecrets(object sender, EventArgs args) { - Logger.DbgLog("GUI:CasaMain.OnDestroyMiCASASecrets() - START"); - CommonGUI.menuDestroyMiCasa_Activated(sender, args); + Logger.DbgLog("GUI:CasaMain.OnDestroyMiCASASecrets() - START"); + CommonGUI temp = new CommonGUI(); + temp.menuDestroyMiCasa_Activated(this, mCasaTray); Logger.DbgLog("GUI:CasaMain.OnDestroyMiCASASecrets() - END"); } - internal void LockGUI() { mmiLockSecrets.Sensitive = false; @@ -1011,6 +1031,90 @@ public class CasaMain dialogPreferences.Destroy(); } + public void on_show_tasktray_icon1_activate(object obj, EventArgs args) + { + if (mmiShowTaskIcon.Active) + { + if (mCasaTray == null) + { + if (IsTraySetForStartup() == false) + PromptUserForStartup(); + + mCasaTray = new CasaTray(this); + } + } + else + { + if (mCasaTray != null) + { + mCasaTray.Destroy(); + mCasaTray = null; + } + } + } + + private bool IsTraySetForStartup() + { +#if W32 + string sStartup = CommonGUI.ReadRegKey( + Registry.CurrentUser, + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", + "CASA Tray"); + + if (sStartup == null || sStartup.Length < 1) + return false; + else + return true; +#endif + +#if LINUX + // TODO check startup script for the user. + return false; +#endif + } + + private void PromptUserForStartup() + { + // prompt user + MessageDialog md=new MessageDialog(null,Gtk.DialogFlags.Modal, + Gtk.MessageType.Question, + Gtk.ButtonsType.YesNo, + "Show the Tray Icon at startup?"); + + md.SetPosition(Gtk.WindowPosition.Center); + md.Response +=new ResponseHandler(md_Response); + md.Modal = true; + md.SetIconFromFile(Common.CASAICONS); + md.Show(); + } + + private void md_Response(object o, ResponseArgs args) + { + if (args.ResponseId.Equals(Gtk.ResponseType.Yes)) + { + +#if W32 + // get our program path + String sPath = "\"" +Environment.GetEnvironmentVariable("ProgramFiles")+ + "\\Novell\\CASA\\bin\\CASAManager.exe\" -tray"; + + CommonGUI.WriteRegKey(Registry.CurrentUser, + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", + "CASA Tray", + sPath); +#endif + + // TODO: Set startup script for the user + + + } + + MessageDialog md = (MessageDialog)o; + if (md != null) + { + md.Destroy(); + } + } ///####################################################################### /// DEBUG @@ -1119,7 +1223,7 @@ public class CasaMain internal void Focus() { windowMain.Present(); - } + } } } ///########################################################################### diff --git a/c_gui/CasaTray.cs b/c_gui/CasaTray.cs index 50e8cb91..88268c1c 100644 --- a/c_gui/CasaTray.cs +++ b/c_gui/CasaTray.cs @@ -15,13 +15,13 @@ namespace Novell.CASA.GUI public class CasaTray { - #if W32 private static System.Windows.Forms.NotifyIcon notifyIcon; public static System.Drawing.Icon m_iconNormal; public static System.Drawing.Icon m_iconLocked; #endif #if LINUX + Egg.TrayIcon icon; EventBox eb; private Gtk.Image m_imageLocked = new Image("images/CASA_16.png", IconSize.Menu); private Gtk.Image m_imageUnlocked = new Image(Stock.Find, IconSize.Menu); @@ -30,9 +30,19 @@ namespace Novell.CASA.GUI private static CasaMain mCasaMain = null; + public CasaTray(CasaMain casaInstance) + { + mCasaMain = casaInstance; + Setup(); + } + public CasaTray() { + Setup(); + } + private void Setup() + { #if W32 Stream s = null; notifyIcon = new System.Windows.Forms.NotifyIcon(); @@ -94,10 +104,11 @@ namespace Novell.CASA.GUI // hooking event eb.ButtonPressEvent += new ButtonPressEventHandler (this.OnImageClick); - Egg.TrayIcon icon = new Egg.TrayIcon("Test"); + icon = new Egg.TrayIcon("Test"); icon.Add(eb); // showing the trayicon - icon.ShowAll(); + icon.ShowAll(); + #endif } @@ -179,7 +190,12 @@ namespace Novell.CASA.GUI } private void OnPopupClick(object o, EventArgs args) { - Application.Quit(); // quits the application when the users clicks the popup menu + if (mCasaMain != null) + { + this.Destroy(); + } + else + Application.Quit(); // quits the application when the users clicks the popup menu } #if W32 private void notifyIcon_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) @@ -200,24 +216,7 @@ namespace Novell.CASA.GUI if (mCasaMain == null) mCasaMain = new CasaMain(null); else - mCasaMain.Focus(); - - /* - // launch the GUI - Process myProcess = new Process(); -#if W32 - ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("CASAManager.exe"); -#else - ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("mono"); - myProcessStartInfo.Arguments = "/opt/novell/CASA/bin/CASAManager.exe"; -#endif - myProcessStartInfo.UseShellExecute = false; - myProcessStartInfo.RedirectStandardOutput = true; - myProcess.StartInfo = myProcessStartInfo; - myProcess.Start(); - */ - - + mCasaMain.Focus(); } private void menuLockMiCasa_Activated(object sender, EventArgs e) @@ -259,7 +258,8 @@ namespace Novell.CASA.GUI private void menuDestroyMiCasa_Activated(object sender, EventArgs e) { - CommonGUI.menuDestroyMiCasa_Activated(sender, e); + CommonGUI temp = new CommonGUI(); + temp.menuDestroyMiCasa_Activated(mCasaMain, this); } internal void UpdateTrayIcon(bool StoreIsLocked) @@ -278,5 +278,17 @@ namespace Novell.CASA.GUI #endif } + + internal void Destroy() + { +#if W32 + notifyIcon.Dispose(); +#endif +#if LINUX + // Does not work + icon.Dispose(); +#endif + + } } } diff --git a/c_gui/Common.cs b/c_gui/Common.cs index 9084b855..2e9c203f 100644 --- a/c_gui/Common.cs +++ b/c_gui/Common.cs @@ -84,7 +84,16 @@ public class Common ///############################################################## /// ARG CONSTANTS - public static string ARG_SHOW_TRAY_ICON = "tray"; + public static string ARG_SHOW_TRAY_ICON = "-tray"; + + ///############################################################# + ///CasaIcons path +#if W32 + public static string CASAICONS = "../images/CASAIcons.ico"; +#endif +#if LINUX + public static string CASAICONS = "opt/novell/CASA/images/CASAIcons.ico"; +#endif ///############################################################## /// ERROR CODES diff --git a/c_gui/CommonGUI.cs b/c_gui/CommonGUI.cs index fc74e361..bbf153a0 100644 --- a/c_gui/CommonGUI.cs +++ b/c_gui/CommonGUI.cs @@ -6,6 +6,9 @@ using Novell.CASA; using Novell.CASA.MiCasa.Common; using Novell.CASA.MiCasa.Communication; +#if W32 +using Microsoft.Win32; +#endif namespace Novell.CASA.GUI { /// @@ -68,8 +71,11 @@ namespace Novell.CASA.GUI dialogLogin.Show(); } - internal static void menuDestroyMiCasa_Activated(object sender, EventArgs e) + internal void menuDestroyMiCasa_Activated(CasaMain casaMain, CasaTray tray) { + mCasaInstance = casaMain; + mTrayInstance = tray; + // prompt user MessageDialog md=new MessageDialog(null,Gtk.DialogFlags.Modal, Gtk.MessageType.Warning, @@ -79,15 +85,18 @@ namespace Novell.CASA.GUI md.SetPosition(Gtk.WindowPosition.Center); md.Response +=new ResponseHandler(md_Response); md.Modal = true; + md.SetIconFromFile(Common.CASAICONS); md.Show(); } - private static void md_Response(object o, ResponseArgs args) + private void md_Response(object o, ResponseArgs args) { if (args.ResponseId.Equals(Gtk.ResponseType.Ok)) { - MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_ALL_SECRETS); + MiCasaRequestReply.Send(MiCasaRequestReply.VERB_REMOVE_ALL_SECRETS); + if (mCasaInstance != null) + mCasaInstance.objMiCasa.AggregateStore(); } MessageDialog md = (MessageDialog)o; @@ -119,20 +128,20 @@ namespace Novell.CASA.GUI else { // prompt user - MessageDialog md=new MessageDialog(mainWindow,Gtk.DialogFlags.Modal, + 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.Modal = true; + md.SetIconFromFile(Common.CASAICONS); md.Show(); } } - - - + public void closebuttonLogin_clicked(object abj, EventArgs args) { dialogLogin.Destroy(); @@ -176,5 +185,63 @@ namespace Novell.CASA.GUI mTrayInstance.UpdateTrayIcon(false); } } +#if W32 + internal static string ReadRegKey(RegistryKey rk, string sSubKey, string KeyName) + { + // Opening the registry key + // RegistryKey rk = Registry.Users; + // Open a subKey as read-only + RegistryKey sk1 = rk.OpenSubKey(sSubKey); + // If the RegistrySubKey doesn't exist -> (null) + if ( sk1 == null ) + { + return null; + } + else + { + try + { + // If the RegistryKey exists I get its value + // or null is returned. + return (string)sk1.GetValue(KeyName.ToUpper()); + } + catch (Exception e) + { + //ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper()); + return null; + } + } + } + + internal static void WriteRegKey(RegistryKey rk, string sSubKey, string KeyName, string sKeyValue) + { + RegistryKey sk1 = rk.OpenSubKey(sSubKey, true); + // If the RegistrySubKey doesn't exist -> (null) + if ( sk1 == null ) + { + //return null; + } + else + { + try + { + // If the RegistryKey exists I get its value + // or null is returned. + sk1.SetValue(KeyName, sKeyValue); + sk1.Close(); + } + catch (Exception e) + { + sk1.Close(); + //ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper()); + Console.Write(e.ToString()); + //return null; + } + } + + + } + +#endif } } diff --git a/c_gui/MiCasa.cs b/c_gui/MiCasa.cs index e782c644..d187b20c 100644 --- a/c_gui/MiCasa.cs +++ b/c_gui/MiCasa.cs @@ -460,7 +460,7 @@ public class MiCasa : Store gxmlTemp.Autoconnect (this); dialogLogin.TransientFor = dialogManageSecret; - label86.Text = "Enter your Master Password to view passwords"; + label86.Text = "Enter your Master Password to view values"; entryMasterPassword3.Text=""; entryMasterPassword3.HasFocus = true; label88.Hide(); diff --git a/c_gui/StorePolicyInterface.cs b/c_gui/StorePolicyInterface.cs index b2fa89c5..1d05d2f1 100644 --- a/c_gui/StorePolicyInterface.cs +++ b/c_gui/StorePolicyInterface.cs @@ -301,7 +301,6 @@ namespace Novell.CASA.GUI { //Common.ShowErrorDialog(exp); } } - } } diff --git a/c_gui/images/casa-1.5.glade b/c_gui/images/casa-1.5.glade index aa6e1b8f..e72c7853 100644 --- a/c_gui/images/casa-1.5.glade +++ b/c_gui/images/casa-1.5.glade @@ -52,7 +52,7 @@ True - + True gtk-new 1 @@ -74,7 +74,7 @@ - + True gtk-new 1 @@ -95,7 +95,7 @@ - + True gtk-new 1 @@ -121,7 +121,7 @@ - + True gtk-refresh 1 @@ -148,7 +148,7 @@ - + True gtk-dialog-authentication 1 @@ -169,7 +169,7 @@ - + True gtk-open 1 @@ -190,7 +190,7 @@ - + True gtk-delete 1 @@ -218,7 +218,7 @@ - + True gtk-quit 1 @@ -254,7 +254,7 @@ - + True gtk-zoom-fit 1 @@ -275,7 +275,7 @@ - + True gtk-jump-to 1 @@ -296,7 +296,7 @@ - + True gtk-copy 1 @@ -324,7 +324,7 @@ - + True gtk-delete 1 @@ -358,7 +358,7 @@ - + True gtk-revert-to-saved 1 @@ -379,7 +379,7 @@ - + True gtk-preferences 1 @@ -391,6 +391,22 @@ + + + + True + + + + + + True + Show Tasktray Icon + True + False + + + @@ -413,7 +429,7 @@ - + True gtk-file 1 @@ -434,7 +450,7 @@ - + True gtk-missing-image 1 @@ -471,7 +487,7 @@ - + True gtk-zoom-fit 1 @@ -505,7 +521,7 @@ - + True gtk-help 1 @@ -532,7 +548,7 @@ - + True gtk-dialog-info 1 @@ -1330,7 +1346,7 @@ True False True - micasa-logo.png + CASAicons.ico True False False @@ -1513,7 +1529,7 @@ their backend stores. 500 True True - micasa-logo.png + CASAicons.ico True False False @@ -3165,7 +3181,7 @@ their backend stores. True False True - micasa-logo.png + CASAicons.ico True False False @@ -3399,7 +3415,7 @@ and all the key-value pairs. True False True - micasa-logo.png + CASAicons.ico True False False @@ -3578,7 +3594,7 @@ Console. True False True - micasa-logo.png + CASAicons.ico True False False @@ -3944,7 +3960,7 @@ prompted for the Master Password at startup. True False True - micasa-logo.png + CASAicons.ico True False False @@ -4444,7 +4460,7 @@ prompted for the Master Password at startup. True False True - micasa-logo.png + CASAicons.ico True False False @@ -4786,7 +4802,7 @@ CSL Manojna</b> True False True - micasa-logo.png + CASAicons.ico True False False @@ -5112,6 +5128,7 @@ prompted for the Master Password at startup. False True False + CASAicons.ico True False False @@ -5227,7 +5244,7 @@ prompted for the Master Password at startup. 500 True True - micasa-logo.png + CASAicons.ico True False False @@ -5779,7 +5796,7 @@ prompted for the Master Password at startup. False False True - micasa-logo.png + CASAicons.ico True False False @@ -5931,7 +5948,7 @@ instance is already running.</b> False False True - micasa-logo.png + CASAicons.ico True False False