File:  [mozdev] / chimera / MainController.mm
Revision 1.11: download - view: text, annotated - select for diffs - revision graph
Tue Feb 5 00:34:14 2002 UTC (17 years, 8 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Offline mode is implemented.

    1: /*
    2:  *  MainController.mm
    3:  */
    4: 
    5: #import "MainController.h"
    6: #import "BrowserWindowController.h"
    7: 
    8: #include "nsCOMPtr.h"
    9: #include "nsIServiceManager.h"
   10: #include "nsIIOService.h"
   11: 
   12: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
   13: 
   14: @implementation MainController
   15: 
   16: -(void)awakeFromNib
   17: {
   18:     [self newWindow: self];
   19:     
   20:     // Initialize offline mode.
   21:     mOffline = NO;
   22:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   23:     if (!ioService)
   24:         return;
   25:     PRBool offline = PR_FALSE;
   26:     ioService->GetOffline(&offline);
   27:     mOffline = offline;
   28:     
   29:     // Set the menu item's text to "Go Online" if we're currently
   30:     // offline.
   31:     if (mOffline)
   32:         [mOfflineMenuItem setTitle: @"Go Online"];
   33: }
   34: 
   35: -(IBAction)newWindow:(id)aSender
   36: {
   37:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
   38:     [controller focusURLBar];
   39: }
   40: 
   41: -(IBAction) openFile:(id)aSender
   42: {
   43:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
   44:     [openPanel setCanChooseFiles: YES];
   45:     [openPanel setCanChooseDirectories: NO];
   46:     [openPanel setAllowsMultipleSelection: NO];
   47:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
   48:                                                 @"txt",@"text",
   49:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
   50:                                                 nil];
   51:     int result = [openPanel runModalForTypes: array];
   52:     if (result == NSOKButton) {
   53:         NSArray* urlArray = [openPanel URLs];
   54:         if ([urlArray count] == 0)
   55:             return;
   56:         NSURL* url = [urlArray objectAtIndex: 0];
   57:         NSWindow* keyWindow = [mApplication keyWindow];
   58:         if (keyWindow)
   59:             return [[keyWindow windowController] loadURL: url];
   60:         else
   61:             [self openBrowserWindowWithURL: url];
   62:     }
   63: }
   64: 
   65: -(IBAction) openLocation:(id)aSender
   66: {
   67:     NSWindow* keyWindow = [mApplication keyWindow];
   68:     if (!keyWindow) {
   69:       [self openBrowserWindowWithURLString: @"about:blank"];
   70:       keyWindow = [mApplication keyWindow];
   71:     }
   72:     
   73:     [[keyWindow windowController] performAppropriateLocationAction];
   74: }
   75: 
   76: -(IBAction) savePage:(id)aSender
   77: {
   78:     NSWindow* keyWindow = [mApplication keyWindow];
   79:     if (keyWindow)
   80:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
   81: }
   82: 
   83: -(IBAction) printPage:(id)aSender
   84: {
   85:     NSWindow* keyWindow = [mApplication keyWindow];
   86:     if (keyWindow)
   87:       [[keyWindow windowController] printDocument];
   88: }
   89: 
   90: -(IBAction) toggleOfflineMode:(id)aSender
   91: {
   92:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   93:     if (!ioService)
   94:         return;
   95:     PRBool offline = PR_FALSE;
   96:     ioService->GetOffline(&offline);
   97:     ioService->SetOffline(!offline);
   98:     mOffline = !offline;
   99:     
  100:     // Update the menu item text.
  101:     // Set the menu item's text to "Go Online" if we're currently
  102:     // offline.
  103:     if (mOffline)
  104:         [mOfflineMenuItem setTitle: @"Go Online"];
  105:     else
  106:         [mOfflineMenuItem setTitle: @"Work Offline"];
  107:         
  108:     // Indicate that we are working offline.
  109:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
  110: }
  111: 
  112: -(IBAction) back:(id)aSender
  113: {
  114:     [[[mApplication keyWindow] windowController] back: aSender]; 
  115: }
  116: 
  117: -(IBAction) forward:(id)aSender
  118: {
  119:     [[[mApplication keyWindow] windowController] forward: aSender]; 
  120: }
  121: 
  122: -(IBAction) reload:(id)aSender
  123: {
  124:     [[[mApplication keyWindow] windowController] reload: aSender]; 
  125: }
  126: 
  127: -(IBAction) stop:(id)aSender
  128: {
  129:     [[[mApplication keyWindow] windowController] stop: aSender]; 
  130: }
  131: 
  132: -(IBAction) home:(id)aSender
  133: {
  134:     [[[mApplication keyWindow] windowController] home: aSender];
  135: }
  136: 
  137: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
  138: {
  139:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
  140: }
  141: 
  142: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
  143: {
  144: 	BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  145:     [browser loadURL: aURL];
  146: 	[browser showWindow: self];
  147:     return browser;
  148: }
  149: 
  150: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>