OSDN Git Service

RAD-497 minimize to tray
[radegast/radegast.git] / Radegast / GUI / Dialogs / MainForm.cs
index d9a816f..d4be299 100644 (file)
@@ -1,6 +1,6 @@
 // 
 // Radegast Metaverse Client
-// Copyright (c) 2009-2012, Radegast Development Team
+// Copyright (c) 2009-2014, Radegast Development Team
 // All rights reserved.
 // 
 // Redistribution and use in source and binary forms, with or without
@@ -34,7 +34,14 @@ using System.Drawing;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Timers;
+#if (COGBOT_LIBOMV || USE_STHREADS)
+using ThreadPoolUtil;
+using Thread = ThreadPoolUtil.Thread;
+using ThreadPool = ThreadPoolUtil.ThreadPool;
+using Monitor = ThreadPoolUtil.Monitor;
+#endif
 using System.Threading;
+
 using System.Windows.Forms;
 using System.Resources;
 using System.IO;
@@ -126,6 +133,7 @@ namespace Radegast
         private bool AutoPilotActive = false;
         private TransparentButton btnDialogNextControl;
         private MediaConsole mediaConsole;
+        private SlUriParser uriParser;
         #endregion
 
         #region Constructor and disposal
@@ -205,7 +213,7 @@ namespace Radegast
                 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
                 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
             }
-            
+
             if (client != null)
             {
                 UnregisterClientEvents(client);
@@ -279,6 +287,7 @@ namespace Radegast
         public void InitializeControls()
         {
             InitializeTabsConsole();
+            uriParser = new SlUriParser();
 
             if (instance.MediaManager.SoundSystemAvailable)
             {
@@ -329,7 +338,7 @@ namespace Radegast
             {
                 if (InAutoReconnect)
                 {
-                    if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
+                    if (instance.GlobalSettings["auto_reconnect"].AsBoolean() && e.FailReason != "tos")
                         BeginAutoReconnect();
                     else
                         InAutoReconnect = false;
@@ -338,7 +347,9 @@ namespace Radegast
             else if (e.Status == LoginStatus.Success)
             {
                 InAutoReconnect = false;
-                tsb3D.Enabled =  tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
+                reconnectToolStripMenuItem.Enabled = false;
+                loginToolStripMenuItem.Enabled = false;
+                tsb3D.Enabled = tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
                 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
                     tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = true;
 
@@ -354,6 +365,7 @@ namespace Radegast
                 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = false;
 
             reconnectToolStripMenuItem.Enabled = true;
+            loginToolStripMenuItem.Enabled = true;
             InAutoReconnect = false;
 
             if (statusTimer != null)
@@ -469,8 +481,9 @@ namespace Radegast
                 tlblMoneyBalance.Text = client.Self.Balance.ToString();
                 icoHealth.Text = client.Self.Health.ToString() + "%";
 
+                var cs = client.Network.CurrentSim;
                 tlblRegionInfo.Text =
-                    client.Network.CurrentSim.Name +
+                    (cs == null ? "No region" : cs.Name) +
                     " (" + Math.Floor(client.Self.SimPosition.X).ToString() + ", " +
                     Math.Floor(client.Self.SimPosition.Y).ToString() + ", " +
                     Math.Floor(client.Self.SimPosition.Z).ToString() + ")";
@@ -760,6 +773,14 @@ namespace Radegast
 
         private Dictionary<UUID, frmGroupInfo> shownGroupProfiles = new Dictionary<UUID, frmGroupInfo>();
 
+        public void ShowGroupProfile(UUID id)
+        {
+            ShowGroupProfile(new OpenMetaverse.Group()
+            {
+                ID = id,
+            });
+        }
+
         public void ShowGroupProfile(AvatarGroup group)
         {
             ShowGroupProfile(new OpenMetaverse.Group()
@@ -773,6 +794,12 @@ namespace Radegast
 
         public void ShowGroupProfile(OpenMetaverse.Group group)
         {
+            if (InvokeRequired)
+            {
+                BeginInvoke(new MethodInvoker(() => ShowGroupProfile(group)));
+                return;
+            }
+
             lock (shownGroupProfiles)
             {
                 frmGroupInfo profile = null;
@@ -802,6 +829,12 @@ namespace Radegast
             }
         }
 
+        public bool ProcessSecondlifeURI(string link)
+        {
+            uriParser.ExecuteLink(link);
+            return true;
+        }
+
         public void ProcessLink(string link)
         {
             ProcessLink(link, false);
@@ -809,6 +842,17 @@ namespace Radegast
 
         public bool ProcessLink(string link, bool onlyMap)
         {
+            var pos = link.IndexOf(RRichTextBox.LinkSeparator);
+            if (pos > 0)
+            {
+                link = link.Substring(pos + 1);
+            }
+
+            if (link.StartsWith("secondlife://") || link.StartsWith("[secondlife://"))
+            {
+                return ProcessSecondlifeURI(link);
+            }
+
             if (!link.Contains("://"))
             {
                 link = "http://" + link;
@@ -877,6 +921,8 @@ namespace Radegast
                 return;
             }
 
+            Control active = TabsConsole.FindFocusedControl(this);
+
             FormFlash.StartFlash(this);
             pnlDialog.Visible = true;
             pnlDialog.BringToFront();
@@ -895,6 +941,11 @@ namespace Radegast
             ResizeNotificationByControl(control);
 
             btnDialogNextControl.Visible = notifications.Count > 1;
+
+            if (active != null)
+            {
+                active.Focus();
+            }
         }
 
         public void RemoveNotification(Control control)
@@ -979,7 +1030,8 @@ namespace Radegast
 
         private void importObjectToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            PrimDeserializer.ImportFromFile(client);
+            //PrimDeserializer.ImportFromFile(client);
+            DisplayImportConsole();
         }
 
         private void autopilotToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1023,14 +1075,44 @@ namespace Radegast
 
         }
 
+        int filesDeleted;
+
+        private void deleteFolder(DirectoryInfo dir)
+        {
+            foreach (var file in dir.GetFiles())
+            {
+                try 
+                {
+                    file.Delete();
+                    filesDeleted++;
+                }
+                catch { }
+            }
+
+            foreach (var subDir in dir.GetDirectories())
+            {
+                deleteFolder(subDir);
+            }
+
+            try { dir.Delete(); }
+            catch { }
+        }
+
         private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            ThreadPool.QueueUserWorkItem(sync => client.Assets.Cache.Clear());
+            WorkPool.QueueUserWorkItem(sync =>
+            {
+                filesDeleted = 0;
+                try { deleteFolder(new DirectoryInfo(client.Settings.ASSET_CACHE_DIR)); }
+                catch { }
+                Logger.DebugLog("Wiped out " + filesDeleted + " files from the cache directory.");
+            });
+            instance.Names.CleanCache();
         }
 
         private void rebakeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            client.Appearance.RequestSetAppearance(true);
+            instance.COF.RebakeTextures();
         }
 
         public void MapToCurrentLocation()
@@ -1137,6 +1219,11 @@ namespace Radegast
             ProcessLink("http://jira.openmetaverse.org/browse/RAD");
         }
 
+        private void accessibilityGuideToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            ProcessLink("http://radegast.org/wiki/Accessibility_Guide");
+        }
+
         private void aboutRadegastToolStripMenuItem_Click(object sender, EventArgs e)
         {
             (new frmAbout(instance)).ShowDialog();
@@ -1328,7 +1415,10 @@ namespace Radegast
 
         private void reconnectToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            instance.Reconnect();
+            if (!client.Network.Connected)
+            {
+                instance.Reconnect();
+            }
         }
 
         private frmKeyboardShortcuts keyboardShortcutsForm = null;
@@ -1389,13 +1479,14 @@ namespace Radegast
         {
             if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"].AsBoolean())
             {
-                if (TabConsole.TabExists("scene_window") && !TabConsole.Tabs["scene_window"].Detached )
+                if (TabConsole.TabExists("scene_window") && !TabConsole.Tabs["scene_window"].Detached)
                 {
                     TabConsole.Tabs["scene_window"].Close();
                 }
                 ShowInTaskbar = false;
                 trayIcon.Visible = true;
-                FormBorderStyle = FormBorderStyle.SizableToolWindow;
+                trayIcon.BalloonTipText = "Radegast is runnig in the background";
+                trayIcon.ShowBalloonTip(2000);
             }
         }
 
@@ -1404,7 +1495,6 @@ namespace Radegast
             WindowState = FormWindowState.Normal;
             ShowInTaskbar = true;
             trayIcon.Visible = false;
-            FormBorderStyle = FormBorderStyle.Sizable;
         }
 
         private void ctxTreyRestore_Click(object sender, EventArgs e)
@@ -1422,7 +1512,7 @@ namespace Radegast
             TabConsole.DisplayNotificationInChat("Teleporting home...");
             client.Self.RequestTeleport(UUID.Zero);
         }
+
         private void stopAllAnimationsToolStripMenuItem_Click(object sender, EventArgs e)
         {
             instance.State.StopAllAnimations();
@@ -1442,6 +1532,55 @@ namespace Radegast
             }
         }
 
+        public void DisplayExportConsole(uint localID)
+        {
+            if (InvokeRequired)
+            {
+                if (IsHandleCreated || !instance.MonoRuntime)
+                    BeginInvoke(new MethodInvoker(() => DisplayExportConsole(localID)));
+                return;
+            }
+
+            if (tabsConsole.TabExists("export console"))
+            {
+                tabsConsole.Tabs["export console"].Close();
+            }
+            RadegastTab tab = tabsConsole.AddTab("export console", "Export Object", new ExportConsole(client, localID));
+            tab.Select();
+        }
+
+        public void DisplayImportConsole()
+        {
+            if (TabConsole.TabExists("import console"))
+            {
+                TabConsole.Tabs["import console"].Select();
+            }
+            else
+            {
+                RadegastTab tab = tabsConsole.AddTab("import console", "Import Object", new ImportConsole(client));
+                tab.AllowClose = false;
+                tab.AllowHide = true;
+                tab.Select();
+            }
+        }
+
+        public void DisplayColladaConsole(Primitive prim)
+        {
+            if (InvokeRequired)
+            {
+                if (IsHandleCreated || !instance.MonoRuntime)
+                    BeginInvoke(new MethodInvoker(() => DisplayColladaConsole(prim)));
+                return;
+            }
+
+            if (tabsConsole.TabExists("collada console"))
+            {
+                tabsConsole.Tabs["collada console"].Close();
+            }
+            RadegastTab tab = tabsConsole.AddTab("collada console", "Export Collada", new ExportCollada(instance, prim));
+            tab.Select();
+        }
+
         private void regionParcelToolStripMenuItem_Click(object sender, EventArgs e)
         {
             DisplayRegionParcelConsole();
@@ -1449,6 +1588,7 @@ namespace Radegast
 
         private void tlblParcel_Click(object sender, EventArgs e)
         {
+            if (!client.Network.Connected) return;
             DisplayRegionParcelConsole();
         }
 
@@ -1486,7 +1626,7 @@ namespace Radegast
         private void myAttachmentsToolStripMenuItem_Click(object sender, EventArgs e)
         {
             Avatar av = client.Network.CurrentSim.ObjectsAvatars.Find((Avatar a) => { return a.ID == client.Self.AgentID; });
-            
+
             if (av == null)
             {
                 tabsConsole.DisplayNotificationInChat("Unable to find my avatar!", ChatBufferTextStyle.Error);
@@ -1526,5 +1666,54 @@ namespace Radegast
                 }
             }
         }
+
+        private void loginToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            // We are logging in without exiting the client
+            // Mark last run as successful
+            instance.MarkEndExecution();
+            TabConsole.InitializeMainTab();
+            TabConsole.Tabs["login"].Select();
+        }
+
+        private void setMaturityLevel(string level)
+        {
+            client.Self.SetAgentAccess(level, res =>
+            {
+                if (res.Success)
+                {
+                    tabsConsole.DisplayNotificationInChat("Successfully changed maturity access level to " + res.NewLevel);
+                }
+                else
+                {
+                    tabsConsole.DisplayNotificationInChat("Failed to change maturity access level.", ChatBufferTextStyle.Error);
+                }
+            });
+        }
+
+        private void pGToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            setMaturityLevel("PG");
+        }
+
+        private void matureToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            setMaturityLevel("M");
+        }
+
+        private void adultToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            setMaturityLevel("A");
+        }
+
+        private void uploadmeshToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            if (!tabsConsole.TabExists("mesh upload console"))
+            {
+                tabsConsole.AddTab("mesh upload console", "Upload mesh", new MeshUploadConsole(instance));
+            }
+            tabsConsole.Tabs["mesh upload console"].Select();
+        }
+
     }
 }
\ No newline at end of file