/*
 *  main.m: main function of Ticker.app
 *
 *  Copyright (c) 2006 Free Software Foundation, Inc.
 *  
 *  Author: Marko Riedel
 *  Date: March 2006
 *
 *  With code fragments from MemoryPanel, ImageViewer, Finger, GDraw 
 *  and GShisen.
 *
 *  This sample program is part of GNUstep.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

#import "HeadlineView.h"
#import "Controller.h"

int main(int argc, const char **argv, char** env)
{
   NSAutoreleasePool *pool;
   NSApplication *app;

   pool = [NSAutoreleasePool new];
   GSDebugAllocationActive(YES);

   app = [NSApplication sharedApplication];

   //
   // Create the Menu 
   //

   NSMenu *mainMenu;
   NSMenu *menu;
   NSMenuItem *menuItem;

   // Main Menu
   mainMenu = AUTORELEASE ([NSMenu new]);

   // Info SubMenu
   menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: _(@"Info") 
			action: NULL 
			keyEquivalent: @""];
   [menuItem setTag:MENU_INFO];
   menu = AUTORELEASE ([NSMenu new]);
   [mainMenu setSubmenu: menu forItem: menuItem];
   [menu addItemWithTitle: _(@"Info Panel...") 
	 action: @selector (orderFrontStandardInfoPanel:) 
	 keyEquivalent: @""];
   [menu addItemWithTitle: _(@"Preferences...") 
	 action: @selector (runPreferencesPanel:) 
	 keyEquivalent: @""];
   [menu addItemWithTitle: _(@"Help...") 
	 action: @selector (orderFrontHelpPanel:)
	 keyEquivalent: @"?"];

   // Edit SubMenu
   menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: _(@"Edit") 
			action: NULL 
			keyEquivalent: @""];
   [menuItem setTag:MENU_EDIT];
   menu = AUTORELEASE ([NSMenu new]);
   [mainMenu setSubmenu: menu forItem: menuItem];
   [menu addItemWithTitle: _(@"Cut") 
	 action: @selector(cut:)
	 keyEquivalent: @"x"];
   [menu addItemWithTitle: _(@"Copy") 
	 action: @selector(copy:)
	 keyEquivalent: @"c"];
   [menu addItemWithTitle: _(@"Paste") 
	 action: @selector(paste:)
	 keyEquivalent: @"v"];
   [menu addItemWithTitle: _(@"Delete") 
	 action: @selector(delete:)
	 keyEquivalent: @""];

   menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: _(@"Format") 
			action: NULL
			keyEquivalent: @""];
   [menuItem setTag:MENU_FORMAT];
   menu = [[NSFontManager sharedFontManager] fontMenu: YES];
   [mainMenu setSubmenu: menu forItem: menuItem];
   [menu addItemWithTitle: _(@"Color") 
	   action: @selector(orderFrontColorPanel:)
	   keyEquivalent: @"c"];

   menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: _(@"Feeds") 
			action: NULL
			keyEquivalent: @""];
   [menuItem setTag:MENU_FEEDS];
   menu = AUTORELEASE ([NSMenu new]);
   [mainMenu setSubmenu: menu forItem: menuItem];
   [menu addItemWithTitle: _(@"Administer feeds...") 
	 action: @selector (displayFeedsPanel:) 
	 keyEquivalent: @""];
   [[menu addItemWithTitle: _(@"Add/Update") 
	   action: @selector(addOrUpdateFeed:)
	  keyEquivalent: @""] setTag:MENU_ADDUPDATE];
   [[menu addItemWithTitle: _(@"Instantiate") 
	   action: @selector(instantiateFeed:)
	  keyEquivalent: @""] setTag:MENU_INSTANTIATE];
   [[menu addItemWithTitle: _(@"Remove") 
	   action: @selector(removeFeed:)
	  keyEquivalent: @""] setTag:MENU_REMOVE];
   
   menuItem = (NSMenuItem *)[mainMenu addItemWithTitle: _(@"Article") 
			action: NULL
			keyEquivalent: @""];
   [menuItem setTag:MENU_ARTICLE];
   [mainMenu setSubmenu:[[HeadlineView defaultMenu] copy] 
	     forItem: menuItem];

   // Hide MenuItem
   [[mainMenu addItemWithTitle: _(@"Hide") 
	     action: @selector (hide:)
	      keyEquivalent: @"h"] setTag:MENU_HIDE];

   // Quit MenuItem
   [[mainMenu addItemWithTitle: _(@"Quit") 
	     action: @selector (terminate:)
	      keyEquivalent: @"q"] setTag:MENU_QUIT];	

   [app setMainMenu: mainMenu];

   Controller *controller;
   controller = [Controller new];
   [app setDelegate: controller];

   NSApplicationMain(argc, argv);

   [[NSUserDefaults standardUserDefaults] synchronize];

   // RELEASE (controller);
   // RELEASE (pool);
   return 0;
}

