Importing the skeleton of system tray implementation and making sure it compiles and works

There was an interesting "problem" due to automatic reference counting
(-fobjc-arc flag).  XCode includes this flag by default, so making sure
that wscript is doing the same thing.
diff --git a/osx/Info.plist b/osx/Info.plist
index 24e72d7..bafb8e6 100644
--- a/osx/Info.plist
+++ b/osx/Info.plist
@@ -2,23 +2,33 @@
 <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
 <plist version="0.9">
 <dict>
+    <key>CFBundleDevelopmentRegion</key>
+    <string>English</string>
     <key>CFBundleExecutable</key>
     <string>NDNx Control Center</string>
-    <key>CFBundleGetInfoString</key>
-    <string>Created by Waf</string>
     <key>CFBundleIconFile</key>
     <string>ndnx-main.icns</string>
     <key>CFBundleIdentifier</key>
     <string>net.named-data.control-center</string>
+    <key>CFBundleInfoDictionaryVersion</key>
+    <string>6.0</string>
+    <key>CFBundleName</key>
+    <string>NDNx Control Center</string>
     <key>CFBundlePackageType</key>
     <string>APPL</string>
     <key>CFBundleSignature</key>
     <string>????</string>
-    <key>NOTE</key>
-    <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
+    <key>CFBundleShortVersionString</key>
+    <string>0.0.1</string>
+    <key>LSMinimumSystemVersion</key>
+    <string>10.6</string>
+    <key>CFBundleVersion</key>
+    <string>1</string>
+    <key>NSMainNibFile</key>
+    <string>MainMenu</string>
     <key>NSPrincipalClass</key>
     <string>NSApplication</string>
-    <!-- <key>LSUIElement</key> -->
-    <!-- <string>1</string> -->
+    <key>LSUIElement</key>
+    <string>1</string>
 </dict>
 </plist>
diff --git a/osx/MainMenu.xib b/osx/MainMenu.xib
new file mode 100644
index 0000000..c8a70f5
--- /dev/null
+++ b/osx/MainMenu.xib
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+    <dependencies>
+        <deployment defaultVersion="1080" identifier="macosx"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4510"/>
+    </dependencies>
+    <objects>
+        <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
+            <connections>
+                <outlet property="delegate" destination="494" id="495"/>
+            </connections>
+        </customObject>
+        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+        <customObject id="-3" userLabel="Application"/>
+        <customObject id="494" customClass="MenuDelegate">
+            <connections>
+                <outlet property="statusMenu" destination="ovl-jc-kIR" id="dlz-Qz-Ia0"/>
+            </connections>
+        </customObject>
+        <customObject id="420" customClass="NSFontManager"/>
+        <menu id="ovl-jc-kIR">
+            <items>
+                <menuItem title="start" id="yhj-L6-nZL">
+                    <modifierMask key="keyEquivalentModifierMask"/>
+                </menuItem>
+                <menuItem title="stop" id="TvT-OR-oT4">
+                    <modifierMask key="keyEquivalentModifierMask"/>
+                </menuItem>
+                <menuItem title="ndnstatus" id="Tap-5m-ZRP">
+                    <modifierMask key="keyEquivalentModifierMask"/>
+                </menuItem>
+                <menuItem title="Item" id="17X-uc-n9i">
+                    <modifierMask key="keyEquivalentModifierMask"/>
+                </menuItem>
+            </items>
+        </menu>
+    </objects>
+</document>
diff --git a/osx/ndnx-main.icns b/osx/Resources/ndnx-main.icns
similarity index 100%
rename from osx/ndnx-main.icns
rename to osx/Resources/ndnx-main.icns
Binary files differ
diff --git a/osx/ndnx-tray.icns b/osx/Resources/ndnx-tray.icns
similarity index 100%
rename from osx/ndnx-tray.icns
rename to osx/Resources/ndnx-tray.icns
Binary files differ
diff --git a/osx/main.mm b/osx/main.mm
index edc5186..c306608 100644
--- a/osx/main.mm
+++ b/osx/main.mm
@@ -3,11 +3,12 @@
  * @copyright See LICENCE for copyright and license information.
  *
  * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
  */
 
 #import <Cocoa/Cocoa.h>
 
-int main(int argc, char *argv[])
+int main(int argc, const char **argv)
 {
-    return NSApplicationMain(argc, (const char **)argv);
+  return NSApplicationMain (argc, argv);
 }
diff --git a/osx/menu-delegate.h b/osx/menu-delegate.h
new file mode 100644
index 0000000..6aa434f
--- /dev/null
+++ b/osx/menu-delegate.h
@@ -0,0 +1,17 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * @copyright See LICENCE for copyright and license information.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface MenuDelegate : NSObject <NSApplicationDelegate>
+{
+  IBOutlet NSMenu *statusMenu;
+  NSStatusItem * statusItem;
+}
+ 
+@end
diff --git a/osx/menu-delegate.mm b/osx/menu-delegate.mm
new file mode 100644
index 0000000..8418f6f
--- /dev/null
+++ b/osx/menu-delegate.mm
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * @copyright See LICENCE for copyright and license information.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
+ */
+
+#import "menu-delegate.h"
+
+@implementation MenuDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+  // Insert code here to initialize your application
+}
+
+// -(void)dealloc
+// {
+//   [statusItem release];
+//   [super dealloc];
+// }
+
+-(void)awakeFromNib
+{
+  statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
+  [statusItem setTitle:@"X"];
+  [statusItem setMenu:statusMenu];
+  [statusItem setHighlightMode:YES];
+}
+
+@end
diff --git a/osx/sparkle-auto-update.mm b/osx/sparkle-auto-update.mm
index a1dc5c0..a515a79 100644
--- a/osx/sparkle-auto-update.mm
+++ b/osx/sparkle-auto-update.mm
@@ -21,7 +21,7 @@
 SparkleAutoUpdate::SparkleAutoUpdate(const char *updateUrl)
 {
   d = new Private;
-  d->updater = [[SUUpdater sharedUpdater] retain];
+  d->updater = [SUUpdater sharedUpdater];
   NSURL *url = [NSURL URLWithString: [NSString stringWithCString:updateUrl encoding:NSASCIIStringEncoding]];
   [d->updater setFeedURL: url];
   [d->updater setAutomaticallyChecksForUpdates: YES];
@@ -30,7 +30,7 @@
 
 SparkleAutoUpdate::~SparkleAutoUpdate()
 {
-  [d->updater release];
+  // [d->updater release];
   delete d;
   // presummably SUUpdater handles garbage collection
 }
diff --git a/waf b/waf
index cacc63a..4e6ad6e 100755
--- a/waf
+++ b/waf
Binary files differ
diff --git a/waf-tools/sparkle.py b/waf-tools/sparkle.py
index 67cf6d9..3d628aa 100644
--- a/waf-tools/sparkle.py
+++ b/waf-tools/sparkle.py
@@ -7,8 +7,8 @@
 @conf
 def check_sparkle_base (self, *k, **kw):
   self.check_cxx (framework_name="Sparkle", header_name=["Foundation/Foundation.h", "AppKit/AppKit.h"],
-                  uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE',
-                  compile_filename='test.mm', use="OSX_FOUNDATION OSX_APPKIT",
+                  uselib_store='SPARKLE', define_name='HAVE_SPARKLE',
+                  compile_filename='test.mm', use="FOUNDATION APPKIT",
                   *k,
                   **kw
                   )
diff --git a/wscript b/wscript
index 6f0c6b9..53d044b 100644
--- a/wscript
+++ b/wscript
@@ -16,10 +16,18 @@
         return -1
 
     if Utils.unversioned_sys_platform () == "darwin":
-        conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', compile_filename='test.mm')
-        conf.check_cxx(framework_name='AppKit',     uselib_store='OSX_APPKIT',     compile_filename='test.mm')
-        conf.check_cxx(framework_name='Cocoa',      uselib_store='OSX_COCOA',     compile_filename='test.mm')
+        conf.find_program('ibtool', var='IBTOOL', mandatory=False)
 
+        conf.check_cxx(framework_name='Foundation', uselib_store='FOUNDATION', compile_filename='test.mm')
+        conf.check_cxx(framework_name='AppKit',     uselib_store='APPKIT',     compile_filename='test.mm')
+        conf.check_cxx(framework_name='Cocoa',      uselib_store='COCOA',      compile_filename='test.mm')
+
+        conf.env.ARCH_OSX = 'x86_64'
+        conf.env.CXXFLAGS_OSX += ['-fobjc-arc', '-mmacosx-version-min=10.8']
+        conf.env.LINKFLAGS_OSX += ['-mmacosx-version-min=10.8']
+        
+        conf.env.MACOSX_DEPLOYMENT_TARGET = '10.8'
+        
         conf.load('sparkle')
 
 def build (bld):
@@ -32,17 +40,50 @@
             target = "NDNx Control Center",
             features=['cxxprogram', 'cxx'],
             includes = "osx",
-            mac_app = "NDNx Control Center.app",
-            source = bld.path.ant_glob ('osx/**/*.mm'),
-            use = "OSX_FOUNDATION OSX_APPKIT OSX_COCOA OSX_SPARKLE",
+            source = bld.path.ant_glob (['osx/**/*.mm', 'osx/MainMenu.xib']),
+            
+            mac_app = True,
+            use = "OSX COCOA FOUNDATION APPKIT SPARKLE",
 
-            mac_plist = bld.path.find_resource('osx/Info.plist').read (),
-            mac_resources = 'osx/ndnx-main.icns osx/ndnx-tray.icns',
+            mac_plist = 'osx/Info.plist',
+            mac_resources = 'osx/Resources/ndnx-main.icns osx/Resources/ndnx-tray.icns',
             mac_frameworks = "osx/Frameworks/Sparkle.framework",
             )
 
+        
 from waflib import TaskGen
 @TaskGen.extension('.mm')
 def m_hook(self, node):
     """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing."""
     return self.create_compiled_task('cxx', node)
+
+@TaskGen.extension('.m')
+def m_hook(self, node):
+    """Alias .m files to be compiled the same as .c files, gcc/clang will do the right thing."""
+    return self.create_compiled_task('c', node)
+
+
+def bundle_name_for_output(name):
+	k = name.rfind('.')
+	if k >= 0:
+		name = name[:k] + '.app'
+	else:
+		name = name + '.app'
+	return name
+
+@TaskGen.extension('.xib')
+def xib(self,node):
+    out = node.change_ext ('.nib')
+
+    name = self.path.get_bld ().find_or_declare (bundle_name_for_output(self.target))
+    resources = name.find_or_declare(['Contents', 'Resources'])
+    resources.mkdir()
+    real_out = resources.make_node (out.name)
+
+    self.create_task('xib', node, real_out)
+    inst_to = getattr(self, 'install_path', '/Applications') + '/%s/Resources' % name
+    self.bld.install_as (inst_to + '/%s' % real_out.name, real_out)
+        
+class xib(Task.Task):
+    color='PINK'
+    run_str = '${IBTOOL} --errors --warnings --notices --minimum-deployment-target 10.8 --output-format human-readable-text  --compile ${TGT} ${SRC}'