CASA/CASA/gui/ExportSecrets.cs
2006-09-07 20:07:32 +00:00

177 lines
4.6 KiB
C#

using System;
using System.IO;
using Novell.CASA.MiCasa.Communication;
using Novell.CASA.MiCasa.Common;
using Gtk;
using Glade;
namespace Novell.CASA.GUI
{
/// <summary>
/// Summary description for ExportSecrets.
/// </summary>
public class ExportSecrets
{
private Config m_config = null;
[Glade.Widget]
Gtk.Label label86,
label88;
[Glade.Widget]
Gtk.Entry entryMasterPassword;
[Glade.Widget]
Gtk.Dialog dialogExport;
[Glade.Widget]
Gtk.CheckButton checkbuttonNoEncrypt;
[Glade.Widget]
Gtk.Button buttonNewFolder;
public ExportSecrets(Config config)
{
m_config = config;
}
public void Run()
{
// prompt for master password, and optional passphrase to encrypt
//Logger.DbgLog("GUI:CasaMain.Login() - IsMasterPasswordSet returned false");
#if W32
Glade.XML gxmlTemp = new Glade.XML ("../images/casa.glade", "dialogExport", null);
#endif
#if LINUX
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "dialogExport", null);
#endif
gxmlTemp.Autoconnect (this);
dialogExport.TransientFor = (Gtk.Window)CasaMain.gxmlMain.GetWidget("windowMain");;
dialogExport.Destroyed += new EventHandler(dialogExport_Destroyed);
dialogExport.Modal = true;
dialogExport.Show();
}
private void dialogExport_Destroyed(object sender, EventArgs e)
{
}
private void on_buttonCloseExportSecrets_clicked(object sender, EventArgs args)
{
if (dialogExport != null)
{
dialogExport.Destroy();
}
}
private void on_buttonOkExportSecrets_clicked(object sender, EventArgs args)
{
if( 0 == miCASA.SetMasterPassword(0, entryMasterPassword.Text) )
{
string sMasterPWD = entryMasterPassword.Text;
string sEncryptString = entryMasterPassword.Text;
if (checkbuttonNoEncrypt.Active)
sEncryptString = null;
if (dialogExport != null)
{
dialogExport.Destroy();
}
string sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);
string sHintFile = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null);
// prompt the user for storage location
string sFileName = GetStorageFileName(sHintDir, sHintFile);
if (sFileName != null)
{
//Store off this location for next export
int iLastSlash = sFileName.LastIndexOf("/");
if (Common.IS_WINDOWS)
iLastSlash = sFileName.LastIndexOf("\\");
if (iLastSlash > 0)
{
sHintFile = sFileName.Substring(iLastSlash + 1);
sHintDir = sFileName.Substring(0, sFileName.Length - sHintFile.Length);
}
// save for later use
m_config.SetConfigSetting(CommonGUI.HINT_DIR, sHintDir);
m_config.SetConfigSetting(CommonGUI.HINT_FILENAME, sHintFile);
m_config.WriteConfig();
// call our daemon to get the users secrets
ExportXMLSecrets exportSecrets = new ExportXMLSecrets(sMasterPWD, sEncryptString, sFileName);
object obj = Novell.CASA.MiCasa.Communication.MiCasaRequestReply.Send(MiCasaRequestReply.VERB_EXPORT_SECRETS, null, null, null, exportSecrets);
/*
byte[] theSecrets = (byte[])Novell.CASA.MiCasa.Communication.MiCasaRequestReply.Send(MiCasaRequestReply.VERB_EXPORT_SECRETS, null, null, null, exportSecrets);
// write em out.
FileStream fs = new FileStream(sFileName, FileMode.Create);
fs.Write(theSecrets, 0, theSecrets.Length);
fs.Flush();
fs.Close();
*/
CommonGUI.DisplayMessage(MessageType.Info, "Secrets saved to: \r\n" + sFileName);
}
}
else
{
// prompt user
MessageDialog md=new MessageDialog(dialogExport,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();
}
}
private string GetStorageFileName(string sHintDir, string sHintFile)
{
FileChooser fc = new FileChooser(FileChooser.ACTION_SAVE);
String sFileName = fc.GetFile(sHintDir, sHintFile, "*.casa");
/*
#if W32
String sFileName = CommonGUI.FileChooser(FileChooserAction.Save, "Select filename and location for secrets", sHintDir, sHintFile);
#else
String sFileName = null;
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Not implemented");
#endif
*/
return sFileName;
}
private void md_Response2(object o, ResponseArgs args)
{
MessageDialog md = (MessageDialog)o;
if (md != null)
{
md.Destroy();
}
}
}
}