diff --git a/CASA/gui/FileChooser.cs b/CASA/gui/FileChooser.cs index 5b0bbe69..fa5074c1 100644 --- a/CASA/gui/FileChooser.cs +++ b/CASA/gui/FileChooser.cs @@ -1,200 +1,200 @@ -using System; -using System.IO; -using System.Threading; - -using Gtk; - -namespace Novell.CASA.GUI -{ - /// - /// Summary description for FileChooser. - /// - public class FileChooser - { - private string m_currentDirectory; - private string m_hintFile = null; - private string m_sFileSelected = null; - private bool m_bFileChoosing = true; - - private Gtk.TreeStore tsDrives = new TreeStore(typeof(string)); - private Gtk.TreeStore ts = new TreeStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string)); - - private string m_pathSeparator = "/"; - - Thread tChooserThread = null; - - +using System; +using System.IO; +using System.Threading; + +using Gtk; + +namespace Novell.CASA.GUI +{ + /// + /// Summary description for FileChooser. + /// + public class FileChooser + { + private string m_currentDirectory; + private string m_hintFile = null; + private string m_sFileSelected = null; + private bool m_bFileChoosing = true; + + private Gtk.TreeStore tsDrives = new TreeStore(typeof(string)); + private Gtk.TreeStore ts = new TreeStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string)); + + private string m_pathSeparator = "/"; + + Thread tChooserThread = null; + + #region Glade Widgets [Glade.Widget] Gtk.Dialog dialogFileChooser; - [Glade.Widget] - Gtk.TreeView treeviewFavorites, - treeviewListing; - - [Glade.Widget] - Gtk.Entry entrySelectedFile, - entryCurrentDir; - - [Glade.Widget] - Gtk.Button buttonUP; - - -#endregion - - public FileChooser() - { - - if (Common.IS_WINDOWS) - m_pathSeparator = "\\"; - - SetCurrentDirectory(Common.GetUserHomeDir()); - } - - private void SetCurrentDirectory(string dir) - { - // replace all instances of the path separator with correct one - if (Common.IS_WINDOWS) - m_currentDirectory = dir.Replace("/", "\\"); - else - m_currentDirectory = dir; - - - //if (m_currentDirectory.EndsWith(m_pathSeparator)) - // m_currentDirectory = m_currentDirectory.Substring(0, m_currentDirectory.Length - 1); - - DisplayDirectory(); - } - - public string GetFile(string sHintDir, string sHintFile) - { - if (sHintDir != null) - { - if (Directory.Exists(sHintDir)) - SetCurrentDirectory(sHintDir); - } - - if (sHintFile != null) - { - m_hintFile = sHintFile; - } - - DoWork(); - return m_currentDirectory + m_pathSeparator + m_sFileSelected; - - } - - private void DoWork() - { - - // display chooser - Show(); - - // wait for user - while (m_bFileChoosing) - { - // Flush pending events to keep the GUI reponsive - while (Gtk.Application.EventsPending ()) - Gtk.Application.RunIteration (); - Thread.Sleep(100); - } - } - - public void Show(string sHintDir, string sHintFile) - { - - if (sHintDir != null) - { - if (Directory.Exists(sHintDir)) - SetCurrentDirectory(sHintDir); - } - - if (sHintFile != null) - { - m_hintFile = sHintFile; - } - - this.Show(); - } - - public void Show() - { - // load and connect handlers + [Glade.Widget] + Gtk.TreeView treeviewFavorites, + treeviewListing; + + [Glade.Widget] + Gtk.Entry entrySelectedFile, + entryCurrentDir; + + [Glade.Widget] + Gtk.Button buttonUP; + + +#endregion + + public FileChooser() + { + + if (Common.IS_WINDOWS) + m_pathSeparator = "\\"; + + SetCurrentDirectory(Common.GetUserHomeDir()); + } + + private void SetCurrentDirectory(string dir) + { + // replace all instances of the path separator with correct one + if (Common.IS_WINDOWS) + m_currentDirectory = dir.Replace("/", "\\"); + else + m_currentDirectory = dir; + + + //if (m_currentDirectory.EndsWith(m_pathSeparator)) + // m_currentDirectory = m_currentDirectory.Substring(0, m_currentDirectory.Length - 1); + + DisplayDirectory(); + } + + public string GetFile(string sHintDir, string sHintFile) + { + if (sHintDir != null) + { + if (Directory.Exists(sHintDir)) + SetCurrentDirectory(sHintDir); + } + + if (sHintFile != null) + { + m_hintFile = sHintFile; + } + + DoWork(); + return m_currentDirectory + m_pathSeparator + m_sFileSelected; + + } + + private void DoWork() + { + + // display chooser + Show(); + + // wait for user + while (m_bFileChoosing) + { + // Flush pending events to keep the GUI reponsive + while (Gtk.Application.EventsPending ()) + Gtk.Application.RunIteration (); + Thread.Sleep(100); + } + } + + public void Show(string sHintDir, string sHintFile) + { + + if (sHintDir != null) + { + if (Directory.Exists(sHintDir)) + SetCurrentDirectory(sHintDir); + } + + if (sHintFile != null) + { + m_hintFile = sHintFile; + } + + this.Show(); + } + + public void Show() + { + // load and connect handlers Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "dialogFileChooser", null); - gxmlTemp.Autoconnect(this); - - // show logical drives - string[] drives = Directory.GetLogicalDrives(); - for (int i=0; i 1) - { - // if windows drive letter, keep the slash - if ((Common.IS_WINDOWS) && (iSlashIndex == 2)) - SetCurrentDirectory(m_currentDirectory.Substring(0, iSlashIndex + 1)); - else - SetCurrentDirectory(m_currentDirectory.Substring(0, iSlashIndex)); - - DisplayFileListing(); - } - } - - private void imageUp_ButtonPressEvent(object o, ButtonPressEventArgs args) - { - - } - } -} + if( treeviewFavorites.Selection.GetSelected (out model, out iter) ) + { + selected = (string)model.GetValue(iter, 0); + SetCurrentDirectory(selected); + DisplayFileListing(); + } + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + } + + public void on_btnCancelFileChooser_clicked(object obj, EventArgs args) + { + m_bFileChoosing = false; + if (dialogFileChooser != null) + { + dialogFileChooser.Destroy(); + } + } + + + public void on_dialogFileChooser_destroy(object o, EventArgs args) + { + m_bFileChoosing = false; + } + + public void on_buttonUP_clicked(object o, EventArgs args) + { + int iSlashIndex = m_currentDirectory.LastIndexOf(m_pathSeparator); + // back up one directory + if (iSlashIndex > 1) + { + // if windows drive letter, keep the slash + if ((Common.IS_WINDOWS) && (iSlashIndex == 2)) + SetCurrentDirectory(m_currentDirectory.Substring(0, iSlashIndex + 1)); + else + SetCurrentDirectory(m_currentDirectory.Substring(0, iSlashIndex)); + + DisplayFileListing(); + } + } + + private void imageUp_ButtonPressEvent(object o, ButtonPressEventArgs args) + { + + } + } +} diff --git a/CASA/gui/ImportSecrets.cs b/CASA/gui/ImportSecrets.cs index 2a1358f7..f2f5dc3c 100644 --- a/CASA/gui/ImportSecrets.cs +++ b/CASA/gui/ImportSecrets.cs @@ -1,91 +1,92 @@ -using System; -using System.IO; - +using System; +using System.IO; + using Novell.CASA.MiCasa.Communication; -using Novell.CASA.MiCasa.Common; - -namespace Novell.CASA.GUI -{ - /// - /// Summary description for ImportSecrets. - /// - public class ImportSecrets - { - Config m_config = null; - public MiCasa m_objMiCasa = null; - byte[] buffer = null; +using Novell.CASA.MiCasa.Common; + +namespace Novell.CASA.GUI +{ + /// + /// Summary description for ImportSecrets. + /// + public class ImportSecrets + { + Config m_config = null; + public MiCasa m_objMiCasa = null; + byte[] buffer = null; [Glade.Widget] Gtk.Entry entryMasterPassword; [Glade.Widget] - Gtk.Dialog dialogImport; - - public ImportSecrets(Config config, MiCasa objMiCasa) - { - m_config = config; - m_objMiCasa = objMiCasa; - } - - public void Run() - { - String sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);; - String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null); - string sFile = null; - + Gtk.Dialog dialogImport, + dialogLogin; + + public ImportSecrets(Config config, MiCasa objMiCasa) + { + m_config = config; + m_objMiCasa = objMiCasa; + } + + public void Run() + { + String sHintDir = m_config.GetConfigSetting(CommonGUI.HINT_DIR, null);; + String sHintFilename = m_config.GetConfigSetting(CommonGUI.HINT_FILENAME, null); + string sFile = null; + FileChooser fc = new FileChooser(); sFile = fc.GetFile(sHintDir, sHintFilename); - //fc.Show(sHintDir, sHintFilename); - //sFile = fc.GetSelectedFile(); - -#if W32 - // ask the user to locate the secret file to import - //sFile = CommonGUI.FileChooser(Gtk.FileChooserAction.Open, "Select import file", sHintDir, sHintFilename); -#else - //sFile = null; - //CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Not implemented"); -#endif - if (sFile != null) - { - // parse of the file:/// - if (sFile.StartsWith("file:///")) - { - sFile = sFile.Substring(8); - } - - if (File.Exists(sFile)) - { - - // let's read it - FileStream fs = new FileStream(sFile, FileMode.Open); - buffer = new byte[fs.Length]; - - int iBytes = fs.Read(buffer, 0, (int)fs.Length); - string data = System.Text.Encoding.ASCII.GetString(buffer); - - fs.Flush(); - fs.Close(); - - // check for clear text secrets - if (data.StartsWith("