<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,6 +16,8 @@ OSX.ruby_thread_switcher_stop
 
 class ApplicationController &lt; OSX::NSObject
 
+	ACCOUNT_MENUITEM_POS = 2
+
 	ib_outlet :preferencesWindow
 	ib_outlet :menu
 	ib_action :openInbox
@@ -36,6 +38,8 @@ class ApplicationController &lt; OSX::NSObject
 		@check_icon = NSImage.alloc.initWithContentsOfFile(bundle.pathForResource_ofType('check', 'tiff'))
 		@error_icon = NSImage.alloc.initWithContentsOfFile(bundle.pathForResource_ofType('error', 'tiff'))
 		
+		@cached_results = {}
+		
 		@status_item.setImage(@app_icon)
 		
 		setupDefaults
@@ -52,21 +56,19 @@ class ApplicationController &lt; OSX::NSObject
 		GNPreferences::setupDefaults
 	end
 	
-	def	openInbox
-		username = GNPreferences.alloc.init.username
-		account_domain = username.split(&quot;@&quot;)
+	def	openInbox(sender)
+		openInboxForAccount(sender.menu.title)
+	end
+	
+	def	openInboxForAccount(account)
+		account_domain = account.split(&quot;@&quot;)
 		
 		inbox_url = (account_domain.length == 2 &amp;&amp; account_domain[1] != &quot;gmail.com&quot;) ? 
 			&quot;https://mail.google.com/a/#{account_domain[1]}&quot; : &quot;https://mail.google.com/mail&quot;
 		NSWorkspace.sharedWorkspace.openURL(NSURL.URLWithString(inbox_url))
 	end
 	
-	def	checkMail
-		preferences = GNPreferences.alloc.init	
-		username = preferences.username
-		password = preferences.password
-		return unless username.length &gt; 0 &amp;&amp; password.length &gt; 0
-		
+	def	checkMail		
 		@status_item.setToolTip(&quot;checking mail...&quot;)
 		@status_item.setImage(@check_icon)
 				
@@ -75,7 +77,12 @@ class ApplicationController &lt; OSX::NSObject
 		@checker.setCurrentDirectoryPath(@checker_path.stringByDeletingLastPathComponent)
 		@checker.setLaunchPath(@checker_path)
 
-		args = NSArray.arrayWithObjects(username, password, nil)
+		args = NSMutableArray.alloc.init
+		GNPreferences.alloc.init.accounts.each do |a|
+			args.addObject(a.username.to_s)
+			args.addObject(a.password.to_s)
+		end
+
 		@checker.setArguments(args)		
 		
 		pipe = NSPipe.alloc.init
@@ -97,42 +104,41 @@ class ApplicationController &lt; OSX::NSObject
 				NSUTF8StringEncoding
 			)
 		)
-		#TODO: switch to multiple accounts check and display results in menus
+		
+		removeAccountMenuItems
+		@mail_count = 0
+		
+		menu_position = ACCOUNT_MENUITEM_POS
 		results.each do |k, v|
-			
+			addAccountMenuItem(k, v, menu_position)
+			menu_position += 1
 		end
-
-		result = results[GNPreferences.alloc.init.username.to_s].split(&quot;\n&quot;)
-		mail_count = result.shift
 		
-		if mail_count == &quot;E&quot;
-			@status_item.setToolTip(&quot;connecting error&quot;)
-			@status_item.setImage(@error_icon)
-		elsif mail_count == &quot;F&quot;
-			@status_item.setToolTip(&quot;username or password wrong&quot;)
-			@status_item.setImage(@error_icon)
+		if @mail_count &gt; 0
+			@status_item.setToolTip(&quot;#{@mail_count} unread message#{@mail_count == '1' ? '' : 's'}&quot;)
+			@status_item.setImage(@mail_icon)
+			@status_item.setTitle(@mail_count)
 		else
-			tooltip = &quot;#{mail_count} new message#{mail_count == '1' ? '' : 's'}&quot;
-			@status_item.setToolTip(tooltip)
-			if mail_count == &quot;0&quot;
-				@status_item.setTitle('') # do not show count for 0
-				@status_item.setImage(@app_icon)
-			else
-				@status_item.setTitle(mail_count)
-				@status_item.setImage(@mail_icon)
-				
-				if @result != result
-					preferences = GNPreferences.alloc.init
-					
-					if preferences.sound != GNPreferences::SOUND_NONE &amp;&amp; sound = NSSound.soundNamed(preferences.sound)
-						sound.play
-					end
-					@growl.notify(&quot;You have #{tooltip}!&quot;, result.join(&quot;\n&quot;)) if preferences.growl					
-					
-					@result = result
-				end
+			@status_item.setToolTip(&quot;&quot;)
+			@status_item.setImage(@app_icon)
+		end
+		
+		@accounts_count = menu_position - 1
+		
+		preferences = GNPreferences.alloc.init
+		should_notify = false
+		
+		results.each_key do |account|
+			cached_result = @cached_results[account]
+			if cached_result[0] != cached_result[1]
+				should_notify = true
+				@growl.notify(account, cached_result[1]) if preferences.growl	
 			end
 		end
+		
+		if should_notify &amp;&amp; preferences.sound != GNPreferences::SOUND_NONE &amp;&amp; sound = NSSound.soundNamed(preferences.sound)
+			sound.play
+		end
 	end
 
 	def	checkMailByTimer(timer)
@@ -154,5 +160,60 @@ class ApplicationController &lt; OSX::NSObject
 		@timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats(
 			GNPreferences.alloc.init.interval * 60, self, 'checkMailByTimer', nil, true)
 	end
-
+	
+	def	removeAccountMenuItems
+		if @accounts_count
+			@accounts_count.times do |t|
+				@status_item.menu.removeItemAtIndex(ACCOUNT_MENUITEM_POS)
+			end
+		end
+	end
+	
+	def	addAccountMenuItem(account_name, results, pos)
+		accountMenu = NSMenu.alloc.initWithTitle(account_name)
+		
+		#open inbox menu item
+		openInboxItem = accountMenu.addItemWithTitle_action_keyEquivalent_(&quot;Open Inbox&quot;, &quot;openInbox&quot;, &quot;&quot;)
+		openInboxItem.target = self
+		openInboxItem.enabled = true
+		
+		accountMenu.addItem(NSMenuItem.separatorItem)
+		
+		#new messages
+		result = results.split(&quot;\n&quot;)
+		mail_count = result.shift
+		
+		if mail_count == &quot;E&quot;
+			error = &quot;connection error&quot;
+			item = accountMenu.addItemWithTitle_action_keyEquivalent(error, nil, &quot;&quot;)
+			item.setImage(@error_icon)
+			cache_result(account_name, error)
+		elsif mail_count == &quot;F&quot;
+			error = &quot;username/password wrong&quot;
+			item = accountMenu.addItemWithTitle_action_keyEquivalent(error, nil, &quot;&quot;)
+			item.setImage(@error_icon)
+			cache_result(account_name, error)
+		else
+			@mail_count += mail_count.to_i
+			tooltip = &quot;#{mail_count} unread message#{mail_count == '1' ? '' : 's'}&quot;
+			result.each do |msg|
+				accountMenu.addItemWithTitle_action_keyEquivalent_(msg, nil, &quot;&quot;)
+			end
+			
+			cache_result(account_name, tooltip + &quot;\n&quot; + result.join(&quot;\n&quot;))
+		end
+		
+		#top level menu item for acount
+		accountItem = NSMenuItem.alloc.init
+		accountItem.title = account_name
+		accountItem.submenu = accountMenu
+		
+		@status_item.menu.insertItem_atIndex(accountItem, pos)
+	end
+	
+	def	cache_result(account, result)
+		@cached_results[account] ||= [&quot;&quot;, &quot;&quot;]
+		@cached_results[account][0] = @cached_results[account][1]
+		@cached_results[account][1] = result
+	end
 end</diff>
      <filename>ApplicationController.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,8 +8,8 @@
 		&lt;string key=&quot;IBDocument.HIToolboxVersion&quot;&gt;353.00&lt;/string&gt;
 		&lt;object class=&quot;NSMutableArray&quot; key=&quot;IBDocument.EditedObjectIDs&quot;&gt;
 			&lt;bool key=&quot;EncodedWithXMLCoder&quot;&gt;YES&lt;/bool&gt;
-			&lt;integer value=&quot;373&quot;/&gt;
 			&lt;integer value=&quot;488&quot;/&gt;
+			&lt;integer value=&quot;373&quot;/&gt;
 		&lt;/object&gt;
 		&lt;object class=&quot;NSArray&quot; key=&quot;IBDocument.PluginDependencies&quot;&gt;
 			&lt;bool key=&quot;EncodedWithXMLCoder&quot;&gt;YES&lt;/bool&gt;
@@ -45,6 +45,16 @@
 							&lt;string key=&quot;NSResourceName&quot;&gt;NSMenuMixedState&lt;/string&gt;
 						&lt;/object&gt;
 					&lt;/object&gt;
+					&lt;object class=&quot;NSMenuItem&quot; id=&quot;780025866&quot;&gt;
+						&lt;reference key=&quot;NSMenu&quot; ref=&quot;845846908&quot;/&gt;
+						&lt;bool key=&quot;NSIsDisabled&quot;&gt;YES&lt;/bool&gt;
+						&lt;bool key=&quot;NSIsSeparator&quot;&gt;YES&lt;/bool&gt;
+						&lt;string key=&quot;NSTitle&quot;/&gt;
+						&lt;string key=&quot;NSKeyEquiv&quot;/&gt;
+						&lt;int key=&quot;NSMnemonicLoc&quot;&gt;2147483647&lt;/int&gt;
+						&lt;reference key=&quot;NSOnImage&quot; ref=&quot;253178495&quot;/&gt;
+						&lt;reference key=&quot;NSMixedImage&quot; ref=&quot;1026465229&quot;/&gt;
+					&lt;/object&gt;
 					&lt;object class=&quot;NSMenuItem&quot; id=&quot;189338223&quot;&gt;
 						&lt;reference key=&quot;NSMenu&quot; ref=&quot;845846908&quot;/&gt;
 						&lt;bool key=&quot;NSIsDisabled&quot;&gt;YES&lt;/bool&gt;
@@ -977,6 +987,7 @@
 							&lt;reference ref=&quot;256512304&quot;/&gt;
 							&lt;reference ref=&quot;456474594&quot;/&gt;
 							&lt;reference ref=&quot;189338223&quot;/&gt;
+							&lt;reference ref=&quot;780025866&quot;/&gt;
 						&lt;/object&gt;
 						&lt;reference key=&quot;parent&quot; ref=&quot;1049&quot;/&gt;
 					&lt;/object&gt;
@@ -1410,6 +1421,11 @@
 						&lt;reference key=&quot;object&quot; ref=&quot;470048455&quot;/&gt;
 						&lt;reference key=&quot;parent&quot; ref=&quot;923777354&quot;/&gt;
 					&lt;/object&gt;
+					&lt;object class=&quot;IBObjectRecord&quot;&gt;
+						&lt;int key=&quot;objectID&quot;&gt;509&lt;/int&gt;
+						&lt;reference key=&quot;object&quot; ref=&quot;780025866&quot;/&gt;
+						&lt;reference key=&quot;parent&quot; ref=&quot;845846908&quot;/&gt;
+					&lt;/object&gt;
 				&lt;/object&gt;
 			&lt;/object&gt;
 			&lt;object class=&quot;NSMutableDictionary&quot; key=&quot;flattenedProperties&quot;&gt;
@@ -1478,13 +1494,14 @@
 					&lt;string&gt;499.IBPluginDependency&lt;/string&gt;
 					&lt;string&gt;504.IBPluginDependency&lt;/string&gt;
 					&lt;string&gt;505.IBPluginDependency&lt;/string&gt;
+					&lt;string&gt;509.IBPluginDependency&lt;/string&gt;
 				&lt;/object&gt;
 				&lt;object class=&quot;NSMutableArray&quot; key=&quot;dict.values&quot;&gt;
 					&lt;bool key=&quot;EncodedWithXMLCoder&quot;&gt;YES&lt;/bool&gt;
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilderKit&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilderKit&lt;/string&gt;
-					&lt;string&gt;{{931, 750}, {183, 103}}&lt;/string&gt;
+					&lt;string&gt;{{931, 740}, {183, 113}}&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
@@ -1543,6 +1560,7 @@
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
 					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
+					&lt;string&gt;com.apple.InterfaceBuilder.CocoaPlugin&lt;/string&gt;
 				&lt;/object&gt;
 			&lt;/object&gt;
 			&lt;object class=&quot;NSMutableDictionary&quot; key=&quot;unlocalizedProperties&quot;&gt;
@@ -1565,7 +1583,7 @@
 				&lt;/object&gt;
 			&lt;/object&gt;
 			&lt;nil key=&quot;sourceID&quot;/&gt;
-			&lt;int key=&quot;maxID&quot;&gt;508&lt;/int&gt;
+			&lt;int key=&quot;maxID&quot;&gt;509&lt;/int&gt;
 		&lt;/object&gt;
 		&lt;object class=&quot;IBClassDescriber&quot; key=&quot;IBDocument.Classes&quot;&gt;
 			&lt;object class=&quot;NSMutableArray&quot; key=&quot;referencedPartialClassDescriptions&quot;&gt;</diff>
      <filename>English.lproj/MainMenu.nib/designable.nib</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>English.lproj/MainMenu.nib/keyedobjects.nib</filename>
    </modified>
    <modified>
      <diff>@@ -21,13 +21,13 @@ class GNGrowlController &lt; OSX::NSObject
 
 	# delegate not working if :click_context not provided?
 	def growlNotifierClicked_context(sender, context)
-		@app.openInbox if @app
+		@app.openInboxForAccount(context) if @app &amp;&amp; context
 	end
 
 	def growlNotifierTimedOut_context(sender, context)
 	end
 	
 	def notify(title, desc)
-		@g.notify('new_messages', title, desc, :click_context =&gt; Time.now.to_s)
+		@g.notify('new_messages', title, desc, :click_context =&gt; title)
 	end
 end</diff>
      <filename>GNGrowlController.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f1cafba6c786ea19871643207edb79025cb8d1f0</id>
    </parent>
  </parents>
  <author>
    <name>ashchan</name>
    <email>ashchan@gmail.com</email>
  </author>
  <url>http://github.com/ashchan/gmail-notifr/commit/a91b73807ccb9956c90b6dc9a89140e6656a4ff4</url>
  <id>a91b73807ccb9956c90b6dc9a89140e6656a4ff4</id>
  <committed-date>2009-01-06T07:11:01-08:00</committed-date>
  <authored-date>2009-01-06T07:11:01-08:00</authored-date>
  <message>initial features for multiple accounts support</message>
  <tree>beb1060d6db56be7095ab923a99210602dbebc11</tree>
  <committer>
    <name>ashchan</name>
    <email>ashchan@gmail.com</email>
  </committer>
</commit>
