2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2006-02-01 18:48:29 +01:00
|
|
|
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library 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
|
2006-01-31 23:01:47 +01:00
|
|
|
* Library Lesser General Public License for more details.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-01-31 23:01:47 +01:00
|
|
|
* License along with this library; if not, Novell, Inc.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-31 23:01:47 +01:00
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
using Gtk;
|
|
|
|
using Glade;
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
using Novell.CASA;
|
|
|
|
using Novell.CASA.MiCasa.Common;
|
|
|
|
using Novell.CASA.MiCasa.Communication;
|
|
|
|
|
2005-10-13 01:10:40 +02:00
|
|
|
namespace Novell.CASA.GUI
|
2005-10-12 17:27:21 +02:00
|
|
|
{
|
|
|
|
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
|
2005-10-13 00:50:50 +02:00
|
|
|
#if LINUX
|
2005-10-13 21:56:58 +02:00
|
|
|
Egg.TrayIcon icon;
|
2005-10-12 21:30:36 +02:00
|
|
|
EventBox eb;
|
2005-10-13 01:10:40 +02:00
|
|
|
private Gtk.Image m_imageLocked = new Image("images/CASA_16.png", IconSize.Menu);
|
|
|
|
private Gtk.Image m_imageUnlocked = new Image(Stock.Find, IconSize.Menu);
|
2005-10-13 00:47:25 +02:00
|
|
|
|
2005-10-12 21:30:36 +02:00
|
|
|
#endif
|
2005-10-12 17:27:21 +02:00
|
|
|
|
|
|
|
private static CasaMain mCasaMain = null;
|
2006-01-07 00:08:58 +01:00
|
|
|
private Menu popupMenu = null;
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2005-10-13 21:56:58 +02:00
|
|
|
public CasaTray(CasaMain casaInstance)
|
|
|
|
{
|
|
|
|
mCasaMain = casaInstance;
|
|
|
|
Setup();
|
|
|
|
}
|
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
public CasaTray()
|
|
|
|
{
|
2005-10-13 21:56:58 +02:00
|
|
|
Setup();
|
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2005-10-13 21:56:58 +02:00
|
|
|
private void Setup()
|
|
|
|
{
|
2005-10-12 17:27:21 +02:00
|
|
|
#if W32
|
|
|
|
Stream s = null;
|
|
|
|
notifyIcon = new System.Windows.Forms.NotifyIcon();
|
|
|
|
try
|
|
|
|
{
|
2006-02-22 00:25:34 +01:00
|
|
|
//s = File.OpenRead("../images/CASAIcons.ico");
|
|
|
|
s = File.OpenRead("D:/brandi/Client/App.ico");
|
2005-10-12 17:27:21 +02:00
|
|
|
m_iconNormal = new System.Drawing.Icon(s);
|
|
|
|
notifyIcon.Icon = m_iconNormal;
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
//MessageBox.Show("File 'notify.ico' cannot be found", "Error");
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
Console.WriteLine("File 'notify.ico' cannot be found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (s != null)
|
|
|
|
{
|
|
|
|
s.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2005-10-13 00:47:25 +02:00
|
|
|
s = File.OpenRead("../images/CASAIconsLocked.ico");
|
2005-10-12 17:27:21 +02:00
|
|
|
m_iconLocked = new System.Drawing.Icon(s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2005-10-13 00:47:25 +02:00
|
|
|
Console.WriteLine("File 'CASAIcons.ico' cannot be found");
|
2005-10-12 17:27:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (s != null)
|
|
|
|
{
|
|
|
|
s.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//notifyIcon.Click +=new EventHandler(notifyIcon_Click);
|
2006-02-22 00:25:34 +01:00
|
|
|
notifyIcon.DoubleClick +=new EventHandler(notifyIcon_DoubleClick);
|
|
|
|
notifyIcon.MouseDown += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseDown);
|
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
notifyIcon.Visible = true;
|
2005-10-13 00:47:25 +02:00
|
|
|
|
|
|
|
UpdateTrayIcon(MiCASAStore.IsLocked());
|
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
#endif
|
2005-10-12 19:13:47 +02:00
|
|
|
#if LINUX
|
2005-10-12 17:27:21 +02:00
|
|
|
/* in order to receive signals, we need a eventbox, because Gtk.Image doesn't receive signals */
|
2005-10-12 21:30:36 +02:00
|
|
|
eb = new EventBox();
|
2005-10-13 01:10:40 +02:00
|
|
|
eb.Add(m_imageUnlocked); // using stock icon
|
2005-10-12 17:27:21 +02:00
|
|
|
// hooking event
|
2005-10-12 21:30:36 +02:00
|
|
|
eb.ButtonPressEvent += new ButtonPressEventHandler (this.OnImageClick);
|
|
|
|
|
2005-10-13 21:56:58 +02:00
|
|
|
icon = new Egg.TrayIcon("Test");
|
2005-10-12 17:27:21 +02:00
|
|
|
icon.Add(eb);
|
|
|
|
// showing the trayicon
|
2005-10-13 21:56:58 +02:00
|
|
|
icon.ShowAll();
|
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ShowContextMenu()
|
|
|
|
{
|
2006-01-07 00:08:58 +01:00
|
|
|
if (popupMenu != null && popupMenu.Visible)
|
|
|
|
{
|
|
|
|
popupMenu.Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (popupMenu == null || !popupMenu.Visible)
|
|
|
|
{
|
|
|
|
popupMenu = new Menu(); // creates the menu
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
MenuItem miSep = new MenuItem();
|
|
|
|
MenuItem miSep2 = new MenuItem();
|
|
|
|
MenuItem miSep3 = new MenuItem();
|
|
|
|
|
|
|
|
ImageMenuItem menuLaunchGUI = new ImageMenuItem ("Manage Secrets");
|
|
|
|
Image appimg = new Image(Stock.New, IconSize.Menu);
|
|
|
|
menuLaunchGUI.Image = appimg; // sets the menu item's image
|
|
|
|
menuLaunchGUI.Activated +=new EventHandler(menuLaunchGUI_Activated);
|
|
|
|
popupMenu.Add(menuLaunchGUI);
|
|
|
|
popupMenu.Add(miSep);
|
|
|
|
|
|
|
|
ImageMenuItem menuLockMiCasa = new ImageMenuItem ("Lock Secrets");
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
//appimg = new Image(Stock.Close, IconSize.Menu);
|
|
|
|
appimg = new Image("gtk-dialog-authentication", IconSize.Menu);
|
|
|
|
menuLockMiCasa.Image = appimg; // sets the menu item's image
|
|
|
|
menuLockMiCasa.Activated +=new EventHandler(menuLockMiCasa_Activated);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
ImageMenuItem menuUnLockMiCasa = new ImageMenuItem ("Unlock Secrets...");
|
|
|
|
appimg = new Image(Stock.Open, IconSize.Menu);
|
|
|
|
menuUnLockMiCasa.Image = appimg; // sets the menu item's image
|
|
|
|
menuUnLockMiCasa.Activated +=new EventHandler(menuLockMiCasa_Activated);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2005-12-20 18:41:46 +01:00
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
popupMenu.Add(menuLockMiCasa);
|
|
|
|
popupMenu.Add(menuUnLockMiCasa);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
popupMenu.Add(miSep2);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
ImageMenuItem menuDestroyMiCasa = new ImageMenuItem ("Destroy Secrets");
|
|
|
|
appimg = new Image(Stock.Delete, IconSize.Menu);
|
|
|
|
menuDestroyMiCasa.Image = appimg; // sets the menu item's image
|
|
|
|
menuDestroyMiCasa.Activated +=new EventHandler(menuDestroyMiCasa_Activated);
|
|
|
|
popupMenu.Add(menuDestroyMiCasa);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
if (MiCASAStore.IsLocked())
|
|
|
|
{
|
|
|
|
menuLockMiCasa.Sensitive = false;
|
|
|
|
menuDestroyMiCasa.Sensitive = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menuUnLockMiCasa.Sensitive = false;
|
|
|
|
menuDestroyMiCasa.Sensitive = true;
|
|
|
|
}
|
2005-12-20 18:41:46 +01:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
ImageMenuItem menuOptionsMiCasa = new ImageMenuItem ("Options ....");
|
|
|
|
menuOptionsMiCasa.Sensitive = false;
|
|
|
|
popupMenu.Add(menuOptionsMiCasa);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
popupMenu.Add(miSep3);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
// creates a menu item with no image as default
|
|
|
|
ImageMenuItem menuPopup1 = new ImageMenuItem ("Exit");
|
|
|
|
appimg = new Image(Stock.Quit, IconSize.Menu);
|
|
|
|
menuPopup1.Image = appimg; // sets the menu item's image
|
|
|
|
popupMenu.Add(menuPopup1); // adds the menu item to the menu
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
// hooks a event when the user clicks the icon
|
|
|
|
menuPopup1.Activated += new EventHandler(this.OnPopupClick);
|
|
|
|
popupMenu.ShowAll(); // shows everything
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
// pops up the actual menu when the user right clicks
|
|
|
|
//popupMenu.Popup(null, null, null, IntPtr.Zero, args.Event.Button, args.Event.Time);
|
2005-10-12 17:27:21 +02:00
|
|
|
|
2006-01-07 00:08:58 +01:00
|
|
|
popupMenu.Popup();
|
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnImageClick (object o, ButtonPressEventArgs args) // handler for mouse click
|
|
|
|
{
|
|
|
|
if (args.Event.Button == 3) //right click
|
|
|
|
{
|
|
|
|
ShowContextMenu();
|
|
|
|
}
|
2006-01-09 19:55:50 +01:00
|
|
|
if (args.Event.Button == 1)
|
|
|
|
{
|
|
|
|
menuLaunchGUI_Activated(null, null);
|
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
|
|
|
private void OnPopupClick(object o, EventArgs args)
|
|
|
|
{
|
2005-10-13 21:56:58 +02:00
|
|
|
if (mCasaMain != null)
|
|
|
|
{
|
|
|
|
this.Destroy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Application.Quit(); // quits the application when the users clicks the popup menu
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
|
|
|
#if W32
|
2006-02-22 00:25:34 +01:00
|
|
|
|
|
|
|
private void notifyIcon_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
|
|
|
|
{
|
2005-10-12 17:27:21 +02:00
|
|
|
if (e.Button == System.Windows.Forms.MouseButtons.Right)
|
2006-02-22 00:25:34 +01:00
|
|
|
ShowContextMenu();
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
2006-02-22 00:25:34 +01:00
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
public void CasaManagerQuit()
|
|
|
|
{
|
2006-01-09 19:55:50 +01:00
|
|
|
//mCasaMain = null;
|
|
|
|
if (mCasaMain != null)
|
|
|
|
mCasaMain.Hide();
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void menuLaunchGUI_Activated(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mCasaMain == null)
|
|
|
|
mCasaMain = new CasaMain(null);
|
|
|
|
else
|
2006-01-09 19:55:50 +01:00
|
|
|
{
|
|
|
|
mCasaMain.Show();
|
2005-10-13 21:56:58 +02:00
|
|
|
mCasaMain.Focus();
|
2006-01-09 19:55:50 +01:00
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void menuLockMiCasa_Activated(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (MiCASAStore.IsLocked())
|
|
|
|
{
|
|
|
|
//if( false == miCASA.IsSecretPersistent(1,"") )
|
|
|
|
CommonGUI cg = new CommonGUI();
|
|
|
|
cg.HandleUnlock(mCasaMain, this);
|
|
|
|
|
|
|
|
//UpdateTrayIcon(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MiCasaRequestReply.Send(MiCasaRequestReply.VERB_LOCK_STORE);
|
|
|
|
if (mCasaMain != null)
|
2006-01-20 19:44:28 +01:00
|
|
|
{
|
2005-10-12 17:27:21 +02:00
|
|
|
mCasaMain.LockGUI();
|
2006-01-20 19:44:28 +01:00
|
|
|
mCasaMain.RefreshStores();
|
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
UpdateTrayIcon(true);
|
2006-01-20 19:44:28 +01:00
|
|
|
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
public bool IsMasterPasswordSet()
|
|
|
|
{
|
|
|
|
string MICASA_PASSCODE_BY_MASTER_PASSWD_FILE = "/.miCASAPCByMPasswd";
|
|
|
|
string fileName = Environment.GetEnvironmentVariable("HOME")+MICASA_PASSCODE_BY_MASTER_PASSWD_FILE;
|
|
|
|
return (File.Exists(fileName));
|
2005-10-13 01:10:40 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void notifyIcon_DoubleClick(object sender, EventArgs e)
|
|
|
|
{
|
2005-10-31 21:24:36 +01:00
|
|
|
|
|
|
|
//menuLockMiCasa_Activated(sender, e);
|
|
|
|
menuLaunchGUI_Activated(sender, e);
|
2005-10-13 01:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void menuDestroyMiCasa_Activated(object sender, EventArgs e)
|
|
|
|
{
|
2005-10-13 21:56:58 +02:00
|
|
|
CommonGUI temp = new CommonGUI();
|
|
|
|
temp.menuDestroyMiCasa_Activated(mCasaMain, this);
|
2005-10-13 01:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void UpdateTrayIcon(bool StoreIsLocked)
|
|
|
|
{
|
|
|
|
#if W32
|
|
|
|
if (StoreIsLocked)
|
|
|
|
{
|
|
|
|
notifyIcon.Text = "miCASA - Locked";
|
|
|
|
notifyIcon.Icon = m_iconLocked;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notifyIcon.Text = "miCASA - Not Locked";
|
|
|
|
notifyIcon.Icon = m_iconNormal;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2005-10-13 21:56:58 +02:00
|
|
|
|
|
|
|
internal void Destroy()
|
|
|
|
{
|
2006-01-09 19:55:50 +01:00
|
|
|
|
|
|
|
if (mCasaMain != null)
|
|
|
|
mCasaMain.Dispose();
|
|
|
|
|
2005-10-13 21:56:58 +02:00
|
|
|
#if W32
|
|
|
|
notifyIcon.Dispose();
|
|
|
|
#endif
|
|
|
|
#if LINUX
|
|
|
|
// Does not work
|
|
|
|
icon.Dispose();
|
|
|
|
#endif
|
2006-01-09 19:55:50 +01:00
|
|
|
Application.Quit();
|
2005-10-13 21:56:58 +02:00
|
|
|
|
2006-02-22 00:25:34 +01:00
|
|
|
}
|
2005-10-12 17:27:21 +02:00
|
|
|
}
|
2005-10-13 01:10:40 +02:00
|
|
|
}
|