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

#define REFRESH_WIDTH     40
#define REFRESH_DEFAULT    5
#define REFRESH_MIN        1
#define REFRESH_MAX      300

#define TICK_WIDTH        40
#define TICK_DEFAULT       5
#define TICK_MIN           1
#define TICK_MAX         300

#define DEFAULT_CAPACITY  16

#define DEFAULTS_FEED @"feed"
#define DEFAULTS_WINS @"windows"

#define ATTR_NAME     @"name"
#define ATTR_URL      @"url"
#define ATTR_PRXUSE   @"useproxy"
#define ATTR_PRXHOST  @"proxyhost"
#define ATTR_PRXPORT  @"proxyport"
#define ATTR_UNTAG    @"untag"
#define ATTR_BROWSE   @"browse"
#define ATTR_FG       @"foreground"
#define ATTR_BG       @"background"
#define ATTR_FONTNAME @"fontname"
#define ATTR_FONTSIZE @"fontsize"
#define ATTR_REFRESH  @"refresh"
#define ATTR_TICK     @"tick"
#define ATTR_FRAME    @"frame"

typedef enum {
    MENU_ADDUPDATE = 64,
    MENU_INSTANTIATE,
    MENU_REMOVE,
    MENU_TEXT,
    MENU_BROWSE,
    MENU_LINK,
    MENU_SHOWALL,
    MENU_UPDATE,
    MENU_INFO,
    MENU_EDIT,
    MENU_FORMAT,
    MENU_FEEDS,
    MENU_ARTICLE,
    MENU_HIDE,
    MENU_QUIT
} MENU_TAG;

@interface Controller : NSObject
{
    NSPanel *feedsPanel;

    NSBrowser *browser;

    NSTextField *name, *url, *untag, *browse;

    NSButton *useproxy;
    NSFormCell *proxyhost, *proxyport;

    NSColorWell *foreground, *background;
    NSText *fontdisp;

    NSTextField *refresh, *tick;

    int updated;
    NSArray *sorted;
    NSMutableDictionary *feeds;

    NSMutableArray *windows;
}

+ debugAllocation;

+ (Controller *)sharedController;

- createFeedsPanel;

- colorChanged:(id)sender;
- changeFont:(id)sender;

- (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column;
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell 
	  atRow:(int)row column:(int)column;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)applicationWillTerminate:(NSNotification *)aNotification;

- updateSortedAndSynchronize:(BOOL)flag;

- makeTickerWindow:(NSDictionary *)attr title:(NSString *)title;

- addOrUpdateFeed:(id)sender;
- instantiateFeed:(id)sender;
- removeFeed:(id)sender;
- setFeed:(id)sender;

- displayFeedsPanel:(id)sender;

- controllerTick;
- (void)windowWillClose:(NSNotification *)aNotification;

- (void)taskDidTerminate:(NSNotification *)aNotification;

- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem;

@end
