Back to index

lightning-sunbird  0.9+nobinonly
app.cs
Go to the documentation of this file.
00001 /* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * 
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Manticore.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Silverstone Interactive.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Ben Goodger <ben@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 namespace Silverstone.Manticore.App 
00041 {
00042   using System;
00043   using System.ComponentModel;
00044   using System.Drawing;
00045   using System.Windows.Forms;
00046   using System.Collections;
00047 
00048   using Silverstone.Manticore.Browser;
00049   using Silverstone.Manticore.Core;
00050   
00051   public class ManticoreApp
00052   {
00053     public ManticoreApp()
00054     {
00055       if (!RestoreSession()) 
00056         BrowserWindow.OpenBrowser();
00057 
00058       Application.Run();
00059     }
00060 
00061     public void Quit() 
00062     {
00063       // Save Session
00064       SaveSession();
00065       
00066       // Flush preferences to disk.
00067       ServiceManager.Preferences.FlushUserPreferences();
00068       
00069       Application.Exit();
00070     }
00071 
00076     private void SaveSession()
00077     {
00078       if (ServiceManager.Preferences.GetIntPref("browser.homepage.mode") == 2) {
00079         bool isLastPageOnly = ServiceManager.Preferences.GetIntPref("browser.session.windowmode") == 0;
00080         WindowMediator wm = ServiceManager.WindowMediator;
00081         IEnumerator browsers = wm.GetEnumeratorForType("BrowserWindow");
00082         int count = 0;
00083         while (browsers.MoveNext()) {
00084           if (isLastPageOnly && count > 0) {
00085             // XXX need to |getMostRecentWindow| instead of just taking the first. 
00086             break;
00087           }
00088 
00089           BrowserWindow currWindow = browsers.Current as BrowserWindow;
00090           String pref = "browser.session.windows.";
00091           pref += currWindow.Type + count++;
00092           ServiceManager.Preferences.SetStringPref(pref, currWindow.URL);
00093           ServiceManager.Preferences.SetIntPref(pref + ".left", currWindow.Left);
00094           ServiceManager.Preferences.SetIntPref(pref + ".top", currWindow.Top);
00095           ServiceManager.Preferences.SetIntPref(pref + ".width", currWindow.Width);
00096           ServiceManager.Preferences.SetIntPref(pref + ".height", currWindow.Height);
00097         }
00098         // XXX need to save session histories. 
00099       }
00100     }
00101 
00106     private bool RestoreSession()
00107     {
00108       if (ServiceManager.Preferences.GetIntPref("browser.homepage.mode") == 2) {
00109         IEnumerator branch = ServiceManager.Preferences.GetBranch("browser.session.windows");
00110         while (branch.MoveNext()) {
00111           String pref = branch.Current as String;
00112           String url = ServiceManager.Preferences.GetStringPref(pref);
00113           int x = ServiceManager.Preferences.GetIntPref(pref + ".left");
00114           int y = ServiceManager.Preferences.GetIntPref(pref + ".top");
00115           int width = ServiceManager.Preferences.GetIntPref(pref + ".width");
00116           int height = ServiceManager.Preferences.GetIntPref(pref + ".height");
00117        
00118           // Create a new browser with the applicable url at the applicable
00119           // location. 
00120           BrowserWindow window = BrowserWindow.OpenBrowserWithURL(url);
00121           window.Location = new Point(x, y);
00122           window.Size = new Size(width, height);
00123         }
00124         // XXX need to reinit session histories. 
00125         ServiceManager.Preferences.RemoveBranch("browser.session.windows");
00126         return true;
00127       }
00128       return false;
00129     }
00130 
00131     [STAThread]
00132     public static void Main(string[] args) 
00133     {
00134       ServiceManager.mApp = new ManticoreApp();
00135     }
00136   }
00137 }
00138