905 lines
27 KiB
C#
905 lines
27 KiB
C#
/***********************************************************************
|
|
*
|
|
* Copyright (C) 2005-2006 Novell, Inc.
|
|
*
|
|
* 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
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
* you may find current contact information at www.novell.com.
|
|
*
|
|
***********************************************************************/
|
|
|
|
namespace Novell.CASA.GUI {
|
|
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Specialized;
|
|
using Gtk;
|
|
using Glade;
|
|
using Novell.CASA.MiCasa.Common;
|
|
using Novell.CASA.MiCasa.Communication;
|
|
|
|
|
|
public class GnomeKeyring : Store
|
|
{
|
|
|
|
Gtk.TreeStore tsSecretIDGnomeKeyring,
|
|
tsNativeInfoGnomeKeyring,
|
|
tsKeyValue;
|
|
|
|
CellRendererText cellEditable;
|
|
|
|
ArrayList arrDeletedKeys = null;
|
|
|
|
public bool IS_STORE_AGGREGATED = false;
|
|
|
|
#region Glade Widgets
|
|
|
|
[Glade.Widget]
|
|
public Gtk.Window windowMain;
|
|
|
|
public Gtk.TreeView tvSecretIDGnomeKeyring;
|
|
|
|
[Glade.Widget]
|
|
Gtk.TreeView tvKeyValue,
|
|
tvNativeInfoGnomeKeyring;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Dialog dialogNewSecret,
|
|
dialogManageSecret,
|
|
dialogConfirmDelete,
|
|
dialogLogin;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Menu menuRightClick;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Entry entrySecretID,
|
|
entryKey,
|
|
entryValue,
|
|
entryMasterPassword3,
|
|
entryMasterPassword4,
|
|
entryDeleteSecretID;
|
|
|
|
[Glade.Widget]
|
|
Gtk.CheckButton cbuttonShowPassword;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Label label86,
|
|
label88;
|
|
|
|
[Glade.Widget]
|
|
Gtk.Button buttonNewAdd,
|
|
buttonNewRemove;
|
|
|
|
[Glade.Widget]
|
|
Gtk.MenuItem cmiNewSecret,
|
|
cmiNewKey,
|
|
cmiDelete,
|
|
cmiView,
|
|
cmiLink,
|
|
cmiCopy;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// CONSTRUCTOR
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public GnomeKeyring()
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.GnomeKeyring() - BEGIN");
|
|
|
|
/// SecretID TreeStore
|
|
tvSecretIDGnomeKeyring = (Gtk.TreeView)CasaMain.gxml.GetWidget("tvSecretIDGnomeKeyring");
|
|
tsSecretIDGnomeKeyring = new TreeStore(typeof(string), typeof(string[]), typeof(string[]), typeof(string), typeof(string[]), typeof(string[]));
|
|
tvSecretIDGnomeKeyring.AppendColumn("Secret-ID",new CellRendererText(),"text",0);
|
|
tvSecretIDGnomeKeyring.Model = tsSecretIDGnomeKeyring;
|
|
tvSecretIDGnomeKeyring.RowActivated += new RowActivatedHandler(OntvSecretIDGnomeKeyringRowActivated);
|
|
tvSecretIDGnomeKeyring.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnRightClicked);
|
|
tvSecretIDGnomeKeyring.CursorChanged += new EventHandler(OnCursorChanged);
|
|
/// NativeInfo TreeStore
|
|
tvNativeInfoGnomeKeyring = (Gtk.TreeView)CasaMain.gxml.GetWidget("tvNativeInfoGnomeKeyring");
|
|
tsNativeInfoGnomeKeyring = new TreeStore(typeof(string), typeof(string));
|
|
tvNativeInfoGnomeKeyring.AppendColumn("NativeKey",new CellRendererText(),"text",0);
|
|
tvNativeInfoGnomeKeyring.AppendColumn("NativeValue",new CellRendererText(),"text",1);
|
|
tvNativeInfoGnomeKeyring.Model = tsNativeInfoGnomeKeyring;
|
|
tvNativeInfoGnomeKeyring.ModifyBase(StateType.Normal,new Gdk.Color(0xff,0xff,0xe6));
|
|
/// Aggregate the store
|
|
//AggregateStore();
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.GnomeKeyring() - END");
|
|
}
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// AGGREGATE STORE
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override void AggregateStore()
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.AggregateStore() - BEGIN");
|
|
|
|
try
|
|
{
|
|
tsSecretIDGnomeKeyring.Clear();
|
|
tsNativeInfoGnomeKeyring.Clear();
|
|
StoreDataInterface.AggregateStore(Common.STORE_GNOMEKEYRING);
|
|
StoreDataInterface.ReadStore(Common.STORE_GNOMEKEYRING,ref tsSecretIDGnomeKeyring);
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.AggregateStore() - EXCEPTION" + exp.ToString());
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.AggregateStore() - END");
|
|
}
|
|
|
|
|
|
|
|
///#######################################################################
|
|
/// DISPLAY NATIVE INFO
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void OnCursorChanged(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnCursorChanged() - BEGIN");
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
string selected = null;
|
|
string[] NativeKeys = null,
|
|
NativeValues = null;
|
|
|
|
if( tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter) )
|
|
selected = (string) model.GetValue(iter, 0);
|
|
|
|
if( (null != selected) && (selected.Length > 0) )
|
|
{
|
|
tsNativeInfoGnomeKeyring.Clear();
|
|
/// Populate NativeInfo
|
|
tsNativeInfoGnomeKeyring.AppendValues("Keyring Name","= "+ model.GetValue(iter,3));
|
|
NativeKeys = (string[]) model.GetValue(iter, 4);
|
|
NativeValues= (string[]) model.GetValue(iter, 5);
|
|
for( int i=0; i< NativeKeys.Length; i++ )
|
|
if( (NativeValues[i] != null) && (NativeValues[i] != "") )
|
|
tsNativeInfoGnomeKeyring.AppendValues(NativeKeys[i], "= "+NativeValues[i]);
|
|
tvNativeInfoGnomeKeyring.ShowAll();
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnCursorChanged() - END");
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// RIGHT-CLICK CONTEXT MENU
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void OnRightClicked(object obj, ButtonReleaseEventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - BEGIN");
|
|
|
|
if( 3 == args.Event.Button )
|
|
{
|
|
try
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - Context menu opened.");
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "menuRightClick", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
menuRightClick.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
|
|
|
|
if( 0 != tvSecretIDGnomeKeyring.Selection.CountSelectedRows() )
|
|
cmiLink.Sensitive = cmiCopy.Sensitive = false;
|
|
else
|
|
cmiNewKey.Sensitive = cmiView.Sensitive = cmiLink.Sensitive = cmiCopy.Sensitive = cmiDelete.Sensitive = false;
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - EXCEPTION" + exp.ToString());
|
|
}
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnRightClicked() - END");
|
|
}
|
|
|
|
///#######################################################################
|
|
/// VIEW KEY-VALUES
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override void ViewKeyValues()
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.ViewKeyValues() - BEGIN");
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
string selected= null;
|
|
string[] keys = null,
|
|
values = null;
|
|
try
|
|
{
|
|
if( null == arrDeletedKeys )
|
|
arrDeletedKeys = new ArrayList();
|
|
else
|
|
arrDeletedKeys.Clear();
|
|
|
|
if( tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter) )
|
|
{
|
|
selected = (string) model.GetValue(iter, 0);
|
|
keys = (string[]) model.GetValue(iter, 1);
|
|
values = (string[]) model.GetValue(iter, 2);
|
|
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogManageSecret", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
dialogManageSecret.TransientFor = (Gtk.Window)CasaMain.gxml.GetWidget("windowMain");
|
|
dialogManageSecret.Title = "GNOME Keyring - Manage Secret";
|
|
|
|
cellEditable = new CellRendererText();
|
|
cellEditable.Editable = true;
|
|
cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
|
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4
|
|
tsKeyValue = new TreeStore(typeof(string),typeof(string), typeof(string), typeof(bool), typeof(string));
|
|
tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0);
|
|
tvKeyValue.AppendColumn("Value",cellEditable,"text",2);
|
|
tvKeyValue.AppendColumn("Linked", new CellRendererText(), "text", 4);
|
|
|
|
entrySecretID.Text=selected;
|
|
|
|
for( int i=0; i< keys.Length; i++ )
|
|
{
|
|
if( (null != keys[i]) && (null != values[i]) )
|
|
tsKeyValue.AppendValues(keys[i], values[i], "********", false, "No");
|
|
|
|
}
|
|
tvKeyValue.Model = tsKeyValue;
|
|
entryKey.HasFocus = true;
|
|
//entryKey.Sensitive = entryValue.Sensitive = buttonNewAdd.Sensitive = buttonNewRemove.Sensitive = false;
|
|
}
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.ViewKeyValues() - EXCEPTION" + exp.ToString());
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.ViewKeyValues() - END");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// EDIT KEY-VALUE
|
|
/// </summary>
|
|
public void OnKeyValueEdited(object obj, EditedArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnKeyValueEdited() - BEGIN");
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
object val;
|
|
string KeyName = null,
|
|
KeyValue = null;
|
|
string[] Keys = null,
|
|
Values = null;
|
|
|
|
try
|
|
{
|
|
tvKeyValue.Selection.GetSelected (out model, out iter);
|
|
val = tsKeyValue.GetValue(iter,0);
|
|
KeyName = val.ToString();
|
|
if( true == cbuttonShowPassword.Active )
|
|
val = tsKeyValue.GetValue(iter,1);
|
|
else
|
|
val = tsKeyValue.GetValue(iter,2);
|
|
KeyValue = val.ToString();
|
|
|
|
tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter);
|
|
|
|
if( false == entrySecretID.Editable )
|
|
{
|
|
if( ("" != args.NewText) && (KeyValue != args.NewText) )
|
|
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_GNOMEKEYRING, Common.OPERATION_MODIFY_KEY, KeyName, args.NewText, ref model, ref iter) )
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnKeyValueEdited() - StoreDataInterface.UpdateStore() succeeded");
|
|
tvKeyValue.Selection.GetSelected (out model, out iter);
|
|
tsKeyValue.SetValue(iter, 1, args.NewText);
|
|
tsKeyValue.SetValue(iter, 2, "********");
|
|
|
|
tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter);
|
|
Keys = (string[]) model.GetValue(iter, 1);
|
|
Values = (string[]) model.GetValue(iter, 2);
|
|
for( int i=0; i< Keys.Length; i++ )
|
|
{
|
|
if( Keys[i] == KeyName )
|
|
{
|
|
Values[i] = args.NewText;
|
|
tsSecretIDGnomeKeyring.SetValue(iter, 2, Values);
|
|
break;
|
|
}
|
|
}
|
|
AggregateStore();
|
|
}
|
|
else
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnKeyValueEdited() - ERROR: STATUS_STORE_UPDATEFAILED");
|
|
}
|
|
else
|
|
{
|
|
tvKeyValue.Selection.GetSelected (out model, out iter);
|
|
tsKeyValue.SetValue(iter, 1, args.NewText);
|
|
tsKeyValue.SetValue(iter, 2, "********");
|
|
}
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnKeyValueEdited() - EXCEPTION:" + exp.ToString());
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnKeyValueEdited() - END");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// ADD BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonNewAdd_clicked(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewAdd_clicked() - BEGIN");
|
|
|
|
if( ("" != entryKey.Text) && ("" != entryValue.Text) )
|
|
{
|
|
TreeIter iterKey;
|
|
ArrayList arrKeys = null,
|
|
arrValues = null;
|
|
object val = null;
|
|
arrKeys = new ArrayList();
|
|
arrValues = new ArrayList();
|
|
|
|
if(tsKeyValue.GetIterFirst(out iterKey))
|
|
{
|
|
do
|
|
{
|
|
val = tsKeyValue.GetValue(iterKey,0);
|
|
arrKeys.Add(val.ToString());
|
|
val = tsKeyValue.GetValue(iterKey,1);
|
|
arrValues.Add(val.ToString());
|
|
}
|
|
while( tsKeyValue.IterNext(ref iterKey) );
|
|
}
|
|
if( -1 == (arrKeys.IndexOf(entryKey.Text)) )
|
|
iterKey = tsKeyValue.AppendValues(entryKey.Text, entryValue.Text, "********", true, "No");
|
|
|
|
//tvKeyValue.Selection.SelectIter(iterKey);
|
|
entryKey.Text = entryValue.Text = "";
|
|
entryKey.HasFocus = true;
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewAdd_clicked() - END");
|
|
}
|
|
|
|
/// <summary>
|
|
/// REMOVE BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonNewRemove_clicked(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewRemove_clicked() - BEGIN");
|
|
|
|
TreeModel modelKey;
|
|
TreeIter iterKey;
|
|
|
|
if(tvKeyValue.Selection.GetSelected (out modelKey, out iterKey))
|
|
if( false == (bool)tsKeyValue.GetValue(iterKey,3) )
|
|
arrDeletedKeys.Add(tsKeyValue.GetValue(iterKey,0));
|
|
|
|
if( 0 != tvKeyValue.Selection.CountSelectedRows() )
|
|
{
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
|
|
tvKeyValue.Selection.GetSelected (out model, out iter);
|
|
tsKeyValue.Remove(ref iter);
|
|
tvKeyValue.ColumnsAutosize();
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewRemove_clicked() - END");
|
|
}
|
|
|
|
/// <summary>
|
|
/// SHOW PASSWORD CHECK BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_cbuttonShowPassword_toggled(object obj, EventArgs args)
|
|
{
|
|
TreeViewColumn tvCol;
|
|
|
|
if( tvKeyValue.Model.IterNChildren() > 0 )
|
|
if( true == cbuttonShowPassword.Active)
|
|
{
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogLogin", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
dialogLogin.TransientFor = dialogManageSecret;
|
|
|
|
label86.Text = "Enter your Master Password to view passwords";
|
|
entryMasterPassword3.Text="";
|
|
entryMasterPassword3.HasFocus = true;
|
|
label88.Hide();
|
|
entryMasterPassword4.Hide();
|
|
dialogLogin.Show();
|
|
}
|
|
else
|
|
{
|
|
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
|
|
tvCol = new TreeViewColumn("Value", cellEditable, "text", 2);
|
|
tvKeyValue.InsertColumn(tvCol, 1);
|
|
}
|
|
|
|
}
|
|
|
|
public void okbuttonLogin_clicked(object abj, EventArgs args)
|
|
{
|
|
TreeViewColumn tvCol;
|
|
|
|
if( tvKeyValue.Model.IterNChildren() > 0 )
|
|
|
|
if( 0 == miCASA.SetMasterPassword(0, entryMasterPassword3.Text) )
|
|
{
|
|
tvKeyValue.RemoveColumn(tvKeyValue.GetColumn(1));
|
|
tvCol = new TreeViewColumn("Value", cellEditable, "text", 1);
|
|
tvKeyValue.InsertColumn(tvCol, 1);
|
|
dialogLogin.Destroy();
|
|
}
|
|
else
|
|
{
|
|
// prompt user
|
|
MessageDialog md=new MessageDialog(dialogLogin,Gtk.DialogFlags.Modal,
|
|
Gtk.MessageType.Warning,
|
|
Gtk.ButtonsType.Ok,
|
|
"Master Password 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)
|
|
{
|
|
cbuttonShowPassword.Active = false;
|
|
dialogLogin.Destroy();
|
|
}
|
|
|
|
|
|
public void OnDialogLoginDeleted(object obj, DeleteEventArgs args)
|
|
{
|
|
cbuttonShowPassword.Active = false;
|
|
dialogLogin.Destroy();
|
|
args.RetVal = true;
|
|
}
|
|
|
|
public void on_entryMasterPassword3_activate(object obj, EventArgs args)
|
|
{
|
|
if( "" != entryMasterPassword3.Text )
|
|
okbuttonLogin_clicked(obj, args);
|
|
}
|
|
|
|
public void on_entryMasterPassword4_activate(object obj, EventArgs args)
|
|
{
|
|
okbuttonLogin_clicked(obj, args);
|
|
}
|
|
|
|
private void md_Response2(object o, ResponseArgs args)
|
|
{
|
|
MessageDialog md = (MessageDialog)o;
|
|
if (md != null)
|
|
{
|
|
md.Destroy();
|
|
entryMasterPassword3.Text="";
|
|
entryMasterPassword3.HasFocus = true;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// MANAGE SECRET-ID DIALOG OK-BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonManageOk_clicked(object obj, EventArgs args)
|
|
{
|
|
TreeModel modelSecret;
|
|
TreeIter iterSecret,
|
|
iterKey;
|
|
string NewKey = null,
|
|
NewValue = null;
|
|
string[] strDeletedKeys = null;
|
|
bool dirtyBit = false;
|
|
//ArrayList arrKeys = null,
|
|
// arrValues = null;
|
|
|
|
try
|
|
{
|
|
if( (0 == tvKeyValue.Model.IterNChildren()) && tvSecretIDGnomeKeyring.Selection.GetSelected (out modelSecret, out iterSecret) )
|
|
{
|
|
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_GNOMEKEYRING, Common.OPERATION_DELETE_SECRET, "", "", ref modelSecret, ref iterSecret) )
|
|
{
|
|
tsSecretIDGnomeKeyring.Remove(ref iterSecret);
|
|
tvSecretIDGnomeKeyring.ColumnsAutosize();
|
|
tsNativeInfoGnomeKeyring.Clear();
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - DELETE_SECRET_SUCCEEDED");
|
|
}
|
|
else
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - DELETE_SECRET_FAILED");
|
|
AggregateStore();
|
|
}
|
|
else
|
|
{
|
|
if( (null != arrDeletedKeys) && (arrDeletedKeys.Count > 0) )
|
|
{
|
|
tvSecretIDGnomeKeyring.Selection.GetSelected (out modelSecret, out iterSecret);
|
|
strDeletedKeys = (string[])arrDeletedKeys.ToArray(typeof(string));
|
|
for( int i=0; i < strDeletedKeys.Length; i++)
|
|
{
|
|
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_GNOMEKEYRING, Common.OPERATION_DELETE_KEY, strDeletedKeys[i], null, ref modelSecret, ref iterSecret) )
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - DELETE_KEY_SUCCEEDED.");
|
|
else
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - DELETE_KEY_FAILED.");
|
|
}
|
|
arrDeletedKeys.Clear();
|
|
AggregateStore();
|
|
}
|
|
|
|
if( tsKeyValue.GetIterFirst(out iterKey) && tvSecretIDGnomeKeyring.Selection.GetSelected (out modelSecret, out iterSecret) )
|
|
{
|
|
do
|
|
{
|
|
NewKey = (string) tsKeyValue.GetValue(iterKey,0);
|
|
NewValue = (string) tsKeyValue.GetValue(iterKey,1);
|
|
dirtyBit = (bool) tsKeyValue.GetValue(iterKey,3);
|
|
|
|
if( true == dirtyBit )
|
|
{
|
|
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_GNOMEKEYRING, Common.OPERATION_ADD_KEY, NewKey, NewValue, ref modelSecret, ref iterSecret) )
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - ADD_KEY_VALUE_SUCCEEDED.");
|
|
else
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - ADD_KEY_VALUE_FAILED.");
|
|
}
|
|
}
|
|
while( tsKeyValue.IterNext(ref iterKey) );
|
|
AggregateStore();
|
|
}
|
|
}
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonManageOk_clicked() - EXCEPTION:" + exp.ToString());
|
|
}
|
|
|
|
tsKeyValue.Dispose();
|
|
dialogManageSecret.Destroy();
|
|
}
|
|
|
|
/// <summary>
|
|
/// MANAGE SECRET-ID DIALOG CANCEL-BUTTON CLICKED
|
|
/// </summary>
|
|
public void on_buttonManageCancel_clicked(object obj, EventArgs args)
|
|
{
|
|
tsKeyValue.Dispose();
|
|
dialogManageSecret.Destroy();
|
|
}
|
|
|
|
/// <summary>
|
|
/// SECRET-ID DOUBLE CLICKED
|
|
/// </summary>
|
|
private void OntvSecretIDGnomeKeyringRowActivated( object obj, RowActivatedArgs args )
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OntvSecretIDGnomeKeyringRowActivated() - ViewKeyValues() called.");
|
|
|
|
ViewKeyValues();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// VIEW KEY-VALUES CALLED VIA MAIN-MENU/CONTEXT-MENU
|
|
/// </summary>
|
|
public void OnViewActivated(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnViewActivated() - ViewKeyValues() called.");
|
|
|
|
ViewKeyValues();
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// ADD NEW SECRET
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void OnNewSecretActivated(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnNewSecretActivated() - BEGIN");
|
|
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogNewSecret", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
dialogNewSecret.TransientFor = (Gtk.Window)CasaMain.gxml.GetWidget("windowMain");
|
|
dialogNewSecret.Title = "GNOME Keyring - New Secret";
|
|
|
|
cellEditable = new CellRendererText();
|
|
cellEditable.Editable = true;
|
|
cellEditable.Edited += new EditedHandler(OnKeyValueEdited);
|
|
/// KEY:0 VALUE:1 VALUE-DUP:2 DIRTY-BIT:3 LINK:4
|
|
tsKeyValue = new TreeStore(typeof(string),typeof(string), typeof(string), typeof(bool), typeof(string));
|
|
tvKeyValue.AppendColumn("Key",new CellRendererText(),"text",0);
|
|
tvKeyValue.AppendColumn("Value",cellEditable,"text",2);
|
|
tvKeyValue.AppendColumn("Linked",new CellRendererText(),"text",4);
|
|
tvKeyValue.Model = tsKeyValue;
|
|
tsKeyValue.Clear();
|
|
entrySecretID.HasFocus = true;
|
|
entrySecretID.Text = "";
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnNewSecretActivated() - END");
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// ADD NEW KEY-VALUES TO EXISTING SECRET
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void OnNewKeyActivated(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnNewKeyActivated() - BEGIN");
|
|
|
|
ViewKeyValues();
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnNewKeyActivated() - END");
|
|
}
|
|
|
|
|
|
|
|
public void on_buttonNewOk_clicked(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewOk_clicked() - BEGIN");
|
|
|
|
TreeModel modelSecret;
|
|
TreeIter iterSecret,
|
|
iterKey;
|
|
string NewKey = null,
|
|
NewValue = null;
|
|
string[] Keys = null,
|
|
Values = null,
|
|
NativeKeys = null,
|
|
NativeValues = null;
|
|
object val = null;
|
|
ArrayList arrKeys = null,
|
|
arrValues = null;
|
|
|
|
if ((true == entrySecretID.Editable) && (entrySecretID.Text.IndexOf("*") > -1))
|
|
{
|
|
// prompt user
|
|
MessageDialog md=new MessageDialog(this.windowMain,Gtk.DialogFlags.Modal,
|
|
Gtk.MessageType.Warning,
|
|
Gtk.ButtonsType.Ok,
|
|
"Secret ID may not contain \"*\"");
|
|
|
|
md.Response += new ResponseHandler(md_Response);
|
|
md.SetPosition(Gtk.WindowPosition.CenterOnParent);
|
|
md.Modal = true;
|
|
md.Show();
|
|
return;
|
|
}
|
|
|
|
if( (true == entrySecretID.Editable) && ("" != entrySecretID.Text) && (tvKeyValue.Model.IterNChildren() > 0) )
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewOk_clicked() - Adding New Secrets and KeyValues.");
|
|
|
|
arrKeys = new ArrayList();
|
|
arrValues = new ArrayList();
|
|
|
|
try
|
|
{
|
|
if(tsKeyValue.GetIterFirst(out iterKey))
|
|
{
|
|
do
|
|
{
|
|
val = tsKeyValue.GetValue(iterKey,0);
|
|
NewKey = val.ToString();
|
|
val = tsKeyValue.GetValue(iterKey,1);
|
|
NewValue = val.ToString();
|
|
|
|
if( -1 == (arrKeys.IndexOf(NewKey)) )
|
|
{
|
|
arrKeys.Add(NewKey);
|
|
arrValues.Add(NewValue);
|
|
}
|
|
}
|
|
while( tsKeyValue.IterNext(ref iterKey) );
|
|
|
|
Keys = (string[])arrKeys.ToArray(typeof(string));
|
|
Values = (string[])arrValues.ToArray(typeof(string));
|
|
NativeKeys = new string[Common.MAX_NATIVE_ELEMENTS];
|
|
NativeValues = new string[Common.MAX_NATIVE_ELEMENTS];
|
|
NativeKeys[Common.INDEX_NATIVEINFO_FOLDERNAME] = Common.NATIVEINFO_FOLDERNAME;
|
|
NativeKeys[Common.INDEX_NATIVEINFO_TYPEID] = Common.NATIVEINFO_TYPEID;
|
|
NativeKeys[Common.INDEX_NATIVEINFO_SYNC] = Common.NATIVEINFO_SYNC;
|
|
NativeKeys[Common.INDEX_NATIVEINFO_SYNCTYPE] = Common.NATIVEINFO_SYNCTYPE;
|
|
NativeKeys[Common.INDEX_NATIVEINFO_MODIFIEDTIME] = Common.NATIVEINFO_MODIFIEDTIME;
|
|
NativeValues[Common.INDEX_NATIVEINFO_FOLDERNAME] = null;
|
|
NativeValues[Common.INDEX_NATIVEINFO_TYPEID] = "Network Password";
|
|
NativeValues[Common.INDEX_NATIVEINFO_SYNC] = null;
|
|
NativeValues[Common.INDEX_NATIVEINFO_SYNCTYPE] = null;
|
|
NativeValues[Common.INDEX_NATIVEINFO_MODIFIEDTIME] = null;
|
|
|
|
iterSecret = tsSecretIDGnomeKeyring.AppendValues(entrySecretID.Text, Keys, Values, "CASAkeyring", NativeKeys, NativeValues);
|
|
modelSecret = tvSecretIDGnomeKeyring.Model;
|
|
|
|
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_GNOMEKEYRING, Common.OPERATION_ADD_SECRET, "", "", ref modelSecret, ref iterSecret) )
|
|
{
|
|
AggregateStore();
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewOk_clicked() - ADD_NEW_SECRET_SUCCEEDED.");
|
|
}
|
|
else
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewOk_clicked() - ERROR: ADD_NEW_SECRET_FAILED");
|
|
}
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewOk_clicked() - EXCEPTION:" + exp.ToString());
|
|
}
|
|
tsKeyValue.Dispose();
|
|
dialogNewSecret.Destroy();
|
|
}
|
|
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonNewOk_clicked() - END");
|
|
}
|
|
|
|
private void md_Response(object o, ResponseArgs args)
|
|
{
|
|
MessageDialog md = (MessageDialog)o;
|
|
if (md != null)
|
|
{
|
|
md.Destroy();
|
|
}
|
|
}
|
|
|
|
public void on_buttonNewCancel_clicked(object obj, EventArgs args)
|
|
{
|
|
dialogNewSecret.Destroy();
|
|
}
|
|
|
|
public void on_helpbuttonNewSecret_clicked(object obj, EventArgs args)
|
|
{
|
|
Common.ShowHelpUrl("AddNewSecrets.htm");
|
|
}
|
|
|
|
///#######################################################################
|
|
/// LINK
|
|
|
|
/// <summary>
|
|
/// LINK Key-Values
|
|
/// </summary>
|
|
public void OnLinkActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
/// COPY
|
|
|
|
/// <summary>
|
|
/// COPY Key-Values
|
|
/// </summary>
|
|
public void OnCopyActivated(object obj, EventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
///#######################################################################
|
|
// DELETE SECRET
|
|
|
|
/// <summary>
|
|
/// DELETE Secret
|
|
/// </summary>
|
|
public void OnDeleteActivated(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnDeleteActivated() - BEGIN");
|
|
if( 0 != tvSecretIDGnomeKeyring.Selection.CountSelectedRows() )
|
|
{
|
|
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogConfirmDelete", null);
|
|
gxmlTemp.Autoconnect (this);
|
|
dialogConfirmDelete.TransientFor = (Gtk.Window)CasaMain.gxml.GetWidget("windowMain");
|
|
dialogNewSecret.Title = "GNOME Keyring - Delete Secret";
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
string selected = null;
|
|
if( tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter) )
|
|
{
|
|
selected = (string) model.GetValue (iter, 0);
|
|
if( (null != selected) && (selected.Length > 0) )
|
|
entryDeleteSecretID.Text = selected;
|
|
}
|
|
}
|
|
Logger.DbgLog("GUI:GnomeKeyring.OnDeleteActivated() - END");
|
|
}
|
|
|
|
public void on_buttonYes_clicked(object obj, EventArgs args)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonYes_clicked() - BEGIN");
|
|
|
|
TreeModel model;
|
|
TreeIter iter;
|
|
|
|
try
|
|
{
|
|
if( tvSecretIDGnomeKeyring.Selection.GetSelected (out model, out iter) )
|
|
{
|
|
if( Common.STATUS_SUCCESS == StoreDataInterface.UpdateStore(Common.STORE_GNOMEKEYRING, Common.OPERATION_DELETE_SECRET, "", "", ref model, ref iter) )
|
|
{
|
|
tsSecretIDGnomeKeyring.Remove(ref iter);
|
|
tvSecretIDGnomeKeyring.ColumnsAutosize();
|
|
tsNativeInfoGnomeKeyring.Clear();
|
|
dialogConfirmDelete.Destroy();
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonYes_clicked() - DELETE_SECRET_SUCCEEDED");
|
|
|
|
}
|
|
else
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonYes_clicked() - DELETE_SECRET_FAILED");
|
|
}
|
|
}
|
|
catch(Exception exp)
|
|
{
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonYes_clicked() - EXCEPTION:" + exp.ToString());
|
|
}
|
|
|
|
Logger.DbgLog("GUI:GnomeKeyring.on_buttonYes_clicked() - END");
|
|
}
|
|
|
|
public void on_buttonNo_clicked(object obj, EventArgs args)
|
|
{
|
|
dialogConfirmDelete.Destroy();
|
|
}
|
|
|
|
|
|
public void on_buttonhelpEditSecret_clicked(object obj, EventArgs args)
|
|
{
|
|
Common.ShowHelpUrl("EditingSecrets.html");
|
|
}
|
|
public void on_helpbuttonAuthentication_clicked(object obj, EventArgs args)
|
|
{
|
|
Common.ShowHelpUrl("CASAMasterPasswordAuthentication.htm");
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
///##################################################################
|
|
/// END OF FILE
|
|
///##################################################################
|