- Limit where persistent files can be saved.

This commit is contained in:
Jim Norman 2007-01-04 08:58:30 +00:00
parent d0a9891cdf
commit fbfa990210
3 changed files with 570 additions and 543 deletions

View File

@ -1750,6 +1750,7 @@ namespace Novell.CASA.GUI
public void okbuttonPreferences_clicked(object abj, EventArgs args) public void okbuttonPreferences_clicked(object abj, EventArgs args)
{ {
Logger.DbgLog("GUI:CasaMain.okbuttonPreferences_clicked() - BEGIN"); Logger.DbgLog("GUI:CasaMain.okbuttonPreferences_clicked() - BEGIN");
bool bCloseDialog = true;
string[] storeID = new string[]{""}; string[] storeID = new string[]{""};
@ -1757,7 +1758,7 @@ namespace Novell.CASA.GUI
Common.IS_MOZILLA = checkbuttonMozilla.Active; Common.IS_MOZILLA = checkbuttonMozilla.Active;
Common.IS_GNOMEKEYRING = checkbuttonGnomeKeyring.Active; Common.IS_GNOMEKEYRING = checkbuttonGnomeKeyring.Active;
Common.IS_KDEWALLET = checkbuttonKdeWallet.Active; Common.IS_KDEWALLET = checkbuttonKdeWallet.Active;
dialogPreferences.Destroy();
/// FIREFOX /// FIREFOX
if(Common.IS_FIREFOX) if(Common.IS_FIREFOX)
@ -1841,11 +1842,17 @@ namespace Novell.CASA.GUI
string sOldDir = Common.GetUserPersistentDir(config); string sOldDir = Common.GetUserPersistentDir(config);
try try
{ {
if (MoveMiCASAFiles(sOldDir, sNewDir)) string sMoveMessage = MoveMiCASAFiles(sOldDir, sNewDir);
if (sMoveMessage.Equals("Success"))
{ {
// save off selected directory // save off selected directory
Common.SetUserPersistentDir(config, sNewDir); Common.SetUserPersistentDir(config, sNewDir);
CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Files moved from\r\n" + sOldDir + "\r\nto\r\n" + sNewDir); CommonGUI.DisplayMessage(Gtk.MessageType.Info, "Files moved from\r\n" + sOldDir + "\r\nto\r\n" + sNewDir);
}
else
{
CommonGUI.DisplayMessage(Gtk.MessageType.Warning, sMoveMessage);
bCloseDialog = false;
} }
} }
catch (Exception e) catch (Exception e)
@ -1854,6 +1861,11 @@ namespace Novell.CASA.GUI
} }
config.WriteConfig(); config.WriteConfig();
if (bCloseDialog)
{
dialogPreferences.Destroy();
}
Logger.DbgLog("GUI:CasaMain.okbuttonPreferences_clicked() - END"); Logger.DbgLog("GUI:CasaMain.okbuttonPreferences_clicked() - END");
} }
@ -2225,8 +2237,13 @@ namespace Novell.CASA.GUI
} }
} }
private bool MoveMiCASAFiles(string sOldDirectory, string sNewDirectory) private string MoveMiCASAFiles(string sOldDirectory, string sNewDirectory)
{ {
if (sNewDirectory == null || sNewDirectory.Length == 0)
{
return "No persistent directory entered";
}
if ((sOldDirectory != null) && (sNewDirectory != null)) if ((sOldDirectory != null) && (sNewDirectory != null))
{ {
if (!sOldDirectory.Equals(sNewDirectory)) if (!sOldDirectory.Equals(sNewDirectory))
@ -2235,10 +2252,13 @@ namespace Novell.CASA.GUI
ChangePersistentDir cpd = new ChangePersistentDir(sOldDirectory, sNewDirectory); ChangePersistentDir cpd = new ChangePersistentDir(sOldDirectory, sNewDirectory);
cpd = (ChangePersistentDir)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_CHANGE_PERSIST_DIR, cpd); cpd = (ChangePersistentDir)MiCasaRequestReply.Send(MiCasaRequestReply.VERB_CHANGE_PERSIST_DIR, cpd);
if (cpd.GetErrorMessage().Equals("Success")) if (cpd.GetErrorMessage().Equals("Success"))
return true; return "Success";
else
return cpd.GetErrorMessage();
} }
} }
return false;
return null;
} }

View File

@ -441,9 +441,16 @@ public class Common
} }
internal static string GetUserName() internal static string GetUserName()
{
if (Common.IS_LINUX)
{
return Environment.GetEnvironmentVariable("USER");
}
else
{ {
return Environment.GetEnvironmentVariable("USERNAME"); return Environment.GetEnvironmentVariable("USERNAME");
} }
}
internal static string GetUserHomeDir() internal static string GetUserHomeDir()

View File

@ -29,7 +29,7 @@ namespace Novell.CASA.GUI
public const int ACTION_CHOOSE_DIR = 3; public const int ACTION_CHOOSE_DIR = 3;
#region Glade Widgets #region Glade Widgets
[Glade.Widget] [Glade.Widget]
Gtk.Dialog dialogFileChooser, Gtk.Dialog dialogFileChooser,
@ -52,7 +52,7 @@ namespace Novell.CASA.GUI
[Glade.Widget] [Glade.Widget]
Gtk.Menu menuDeleteDirFile; Gtk.Menu menuDeleteDirFile;
#endregion #endregion
public FileChooser(int action) public FileChooser(int action)
{ {
@ -157,8 +157,8 @@ namespace Novell.CASA.GUI
while (m_bFileChoosing) while (m_bFileChoosing)
{ {
// Flush pending events to keep the GUI reponsive // Flush pending events to keep the GUI reponsive
while (Gtk.Application.EventsPending ()) while (Gtk.Application.EventsPending())
Gtk.Application.RunIteration (); Gtk.Application.RunIteration();
Thread.Sleep(100); Thread.Sleep(100);
} }
} }
@ -203,15 +203,15 @@ namespace Novell.CASA.GUI
dialogFileChooser.Title = "Save secrets to ...."; dialogFileChooser.Title = "Save secrets to ....";
} }
#if LINUX #if LINUX
tsDrives.AppendValues("/home"); tsDrives.AppendValues("/home/.casa/"+Common.GetUserName());
tsDrives.AppendValues(Common.GetUserHomeDir());
tsDrives.AppendValues("/media"); tsDrives.AppendValues("/media");
#else #else
// show logical drives // show logical drives
string[] drives = Directory.GetLogicalDrives(); string[] drives = Directory.GetLogicalDrives();
for (int i=0; i<drives.Length; i++) for (int i = 0; i < drives.Length; i++)
{ {
tsDrives.AppendValues(drives[i]); tsDrives.AppendValues(drives[i]);
} }
@ -229,15 +229,15 @@ namespace Novell.CASA.GUI
// hook up the model // hook up the model
TreeViewColumn col1 = new TreeViewColumn("", new Gtk.CellRendererPixbuf(), "pixbuf", 0); TreeViewColumn col1 = new TreeViewColumn("", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
treeviewListing.AppendColumn(col1); treeviewListing.AppendColumn(col1);
treeviewListing.AppendColumn("Name",new CellRendererText(),"text",1); treeviewListing.AppendColumn("Name", new CellRendererText(), "text", 1);
treeviewListing.AppendColumn("Size",new CellRendererText(),"text",2); treeviewListing.AppendColumn("Size", new CellRendererText(), "text", 2);
treeviewListing.AppendColumn("Date Modified",new CellRendererText(),"text",3); treeviewListing.AppendColumn("Date Modified", new CellRendererText(), "text", 3);
treeviewListing.Model = ts; treeviewListing.Model = ts;
// hook up the events // hook up the events
treeviewListing.RowActivated +=new RowActivatedHandler(treeviewListing_RowActivated); treeviewListing.RowActivated += new RowActivatedHandler(treeviewListing_RowActivated);
treeviewListing.MoveCursor +=new MoveCursorHandler(treeviewListing_MoveCursor); treeviewListing.MoveCursor += new MoveCursorHandler(treeviewListing_MoveCursor);
treeviewListing.ButtonReleaseEvent +=new ButtonReleaseEventHandler(treeviewListing_ButtonReleaseEvent); treeviewListing.ButtonReleaseEvent += new ButtonReleaseEventHandler(treeviewListing_ButtonReleaseEvent);
DisplayDirectory(); DisplayDirectory();
DisplayFileListing(); DisplayFileListing();
@ -267,18 +267,18 @@ namespace Novell.CASA.GUI
DirectoryInfo dirInfo = new DirectoryInfo(m_currentDirectory); DirectoryInfo dirInfo = new DirectoryInfo(m_currentDirectory);
DirectoryInfo[] dirs = dirInfo.GetDirectories(); DirectoryInfo[] dirs = dirInfo.GetDirectories();
for (int i=0; i<dirs.Length; i++) for (int i = 0; i < dirs.Length; i++)
{ {
//if (dirs[i].Name.StartsWith(".")) continue; //if (dirs[i].Name.StartsWith(".")) continue;
ts.AppendValues(new Gdk.Pixbuf (Common.IMAGE_PATH + "folder.png"), dirs[i].Name, "", "File folder"); ts.AppendValues(new Gdk.Pixbuf(Common.IMAGE_PATH + "folder.png"), dirs[i].Name, "", "File folder");
} }
if (m_iAction < FileChooser.ACTION_CHOOSE_DIR) if (m_iAction < FileChooser.ACTION_CHOOSE_DIR)
{ {
FileInfo[] files = dirInfo.GetFiles(m_currentFilter); FileInfo[] files = dirInfo.GetFiles(m_currentFilter);
for (int i=0; i<files.Length; i++) for (int i = 0; i < files.Length; i++)
{ {
ts.AppendValues(new Gdk.Pixbuf (Common.IMAGE_PATH + "CASA_16.png"), files[i].Name, (files[i].Length/1000).ToString() + " KB", files[i].LastWriteTime.ToShortDateString() + " " + files[i].LastWriteTime.ToShortTimeString()); ts.AppendValues(new Gdk.Pixbuf(Common.IMAGE_PATH + "CASA_16.png"), files[i].Name, (files[i].Length / 1000).ToString() + " KB", files[i].LastWriteTime.ToShortDateString() + " " + files[i].LastWriteTime.ToShortTimeString());
} }
} }
} }
@ -366,7 +366,7 @@ namespace Novell.CASA.GUI
try try
{ {
if( treeviewFavorites.Selection.GetSelected (out model, out iter) ) if (treeviewFavorites.Selection.GetSelected(out model, out iter))
{ {
selected = (string)model.GetValue(iter, 0); selected = (string)model.GetValue(iter, 0);
SetCurrentDirectory(selected); SetCurrentDirectory(selected);
@ -452,16 +452,16 @@ namespace Novell.CASA.GUI
//Console.WriteLine("Button released"); //Console.WriteLine("Button released");
DisplaySelectedFile(); DisplaySelectedFile();
if( 3 == args.Event.Button ) if (3 == args.Event.Button)
{ {
try try
{ {
Logger.DbgLog("GUI:MiCasa.OnRightClicked() - Context menu opened."); Logger.DbgLog("GUI:MiCasa.OnRightClicked() - Context menu opened.");
Glade.XML gxmlTemp = new Glade.XML (Common.GladeFile, "menuDeleteDirFile", null); Glade.XML gxmlTemp = new Glade.XML(Common.GladeFile, "menuDeleteDirFile", null);
gxmlTemp.Autoconnect (this); gxmlTemp.Autoconnect(this);
menuDeleteDirFile.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime); menuDeleteDirFile.Popup(null, null, null, IntPtr.Zero, 3, Gtk.Global.CurrentEventTime);
} }
catch(Exception exp) catch (Exception exp)
{ {
Logger.DbgLog("GUI:MiCasa.OnRightClicked() - EXCEPTION:" + exp.ToString()); Logger.DbgLog("GUI:MiCasa.OnRightClicked() - EXCEPTION:" + exp.ToString());
} }
@ -502,9 +502,9 @@ namespace Novell.CASA.GUI
try try
{ {
if( treeviewListing.Selection.GetSelected (out model, out iter) ) if (treeviewListing.Selection.GetSelected(out model, out iter))
{ {
selected = (string) model.GetValue(iter, 1); selected = (string)model.GetValue(iter, 1);
entrySelectedFile.Text = selected; entrySelectedFile.Text = selected;
} }
} }
@ -519,8 +519,7 @@ namespace Novell.CASA.GUI
{ {
if (buttonNewFolder != null) if (buttonNewFolder != null)
{ {
if ((m_currentDirectory.Equals("/home/")) || if ((m_currentDirectory.Equals("/home/.casa/")) ||
(m_currentDirectory.Equals("/home/.casa/")) ||
(m_currentDirectory.Equals("/media/"))) (m_currentDirectory.Equals("/media/")))
{ {
buttonNewFolder.Sensitive = false; buttonNewFolder.Sensitive = false;
@ -538,7 +537,8 @@ namespace Novell.CASA.GUI
{ {
if (buttonUP != null) if (buttonUP != null)
{ {
if ((m_currentDirectory.Equals("/home/")) || if ((m_currentDirectory.Equals(Common.GetUserHomeDir() + "/")) ||
(m_currentDirectory.Equals("/home/.casa/" + Common.GetUserName() + "/")) ||
(m_currentDirectory.Equals("/media/"))) (m_currentDirectory.Equals("/media/")))
{ {
buttonUP.Sensitive = false; buttonUP.Sensitive = false;