unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

AppModel.swift (2192B)

      1 //
      2 //  AppModel.swift
      3 //  UnrealIRCd
      4 //
      5 //  Created by Travis McArthur on 7/18/15.
      6 //  Copyright (c) 2015 UnrealIRCd Team. All rights reserved.
      7 //
      8 
      9 import Foundation
     10 import AppKit
     11 
     12 class AppModel : ChangeNotifierDelegate
     13 {
     14     var menuItem : NSStatusItem
     15     static let logoName = "logo.png"
     16     static let helpURL = "https://www.unrealircd.org/docs/UnrealIRCd_6_documentation"
     17     var daemonModel : DaemonModel
     18     var configurationModel : ConfigurationModel
     19     var windowController : NSWindowController?
     20     var mainMenu : NSMenu
     21     
     22     init(menu: NSMenu)
     23     {
     24         menuItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1/*NSVariableStatusItemLength*/)
     25         mainMenu = menu
     26         menuItem.image = NSImage(named: AppModel.logoName)
     27         menuItem.menu = menu
     28         
     29         daemonModel = DaemonModel()
     30         configurationModel = ConfigurationModel()
     31 
     32         daemonModel.attachChangeDelegate(self)
     33     }
     34     
     35     func launchHelp()
     36     {
     37         if let url = NSURL(string: AppModel.helpURL)
     38         {
     39             NSWorkspace.sharedWorkspace().openURL(url)
     40         }
     41     }
     42     
     43     func showPreferences()
     44     {
     45         windowController!.showWindow(self)
     46     }
     47     
     48     func startup()
     49     {
     50         if configurationModel.shouldAutoStartDaemon
     51         {
     52             daemonModel.start()
     53         }
     54         
     55         
     56         let storyboard = NSStoryboard(name: "Main", bundle:nil)
     57         let controller = storyboard!.instantiateControllerWithIdentifier("Configuration") as! WindowController?
     58         assert(controller != nil, "Unable to load window from XIB")
     59         controller?.setupModels(daemonModel, configurationModel: configurationModel)
     60         windowController = controller
     61     }
     62     
     63     func shutdown()
     64     {
     65         daemonModel.stop()
     66         exit(0)
     67     }
     68     
     69     func startDaemon()
     70     {
     71         daemonModel.start()
     72     }
     73     
     74     func stopDaemon()
     75     {
     76         daemonModel.stop()
     77     }
     78     
     79     func modelChanged(model: ChangeNotifier)
     80     {
     81         let daemonStatus = daemonModel.isRunning
     82         mainMenu.itemWithTitle("Start UnrealIRCd")?.enabled = !daemonStatus
     83         mainMenu.itemWithTitle("Stop UnrealIRCd")?.enabled = daemonStatus
     84     }
     85     
     86 }