Permalink
Browse files

Connection status indication

1. Added indication for connection status using different status item icons for online/offline
2. Fix compilation error in utils
3. Change default icon name
  • Loading branch information...
BinyaminSharet committed Apr 23, 2012
1 parent d93986a commit 99a4c08cd7ff7178a1e9e91c10f480cea0320129
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 823BAB491545BD0500C98751 /* icon_offline.png in Resources */ = {isa = PBXBuildFile; fileRef = 823BAB481545BD0500C98751 /* icon_offline.png */; };
824A924E15324356002033A7 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 824A924D15324356002033A7 /* Cocoa.framework */; };
824A925815324356002033A7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 824A925615324356002033A7 /* InfoPlist.strings */; };
824A925A15324356002033A7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 824A925915324356002033A7 /* main.m */; };
@@ -27,7 +28,7 @@
82A68A7D1539C3EE008DA2E8 /* SettingsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 82A68A7C1539C3EA008DA2E8 /* SettingsWindow.xib */; };
82A68A801539C9E5008DA2E8 /* SettingsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 82A68A7F1539C9E5008DA2E8 /* SettingsWindowController.m */; };
82B7849A15355BFF0097863D /* PersistantData.m in Sources */ = {isa = PBXBuildFile; fileRef = 82B7849915355BFF0097863D /* PersistantData.m */; };
- 82B784A31535835A0097863D /* stackoverflow.png in Resources */ = {isa = PBXBuildFile; fileRef = 82B784A21535835A0097863D /* stackoverflow.png */; };
+ 82B784A31535835A0097863D /* icon_online.png in Resources */ = {isa = PBXBuildFile; fileRef = 82B784A21535835A0097863D /* icon_online.png */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -41,6 +42,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 823BAB481545BD0500C98751 /* icon_offline.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_offline.png; sourceTree = "<group>"; };
824A924915324356002033A7 /* SONotifier.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SONotifier.app; sourceTree = BUILT_PRODUCTS_DIR; };
824A924D15324356002033A7 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
824A925015324356002033A7 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -80,7 +82,7 @@
82B7849815355BFF0097863D /* PersistantData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PersistantData.h; sourceTree = "<group>"; };
82B7849915355BFF0097863D /* PersistantData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PersistantData.m; sourceTree = "<group>"; };
82B7849C1535610C0097863D /* Globals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Globals.h; sourceTree = "<group>"; };
- 82B784A21535835A0097863D /* stackoverflow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = stackoverflow.png; sourceTree = "<group>"; };
+ 82B784A21535835A0097863D /* icon_online.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_online.png; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -209,7 +211,8 @@
82B7849D153581ED0097863D /* Shared */ = {
isa = PBXGroup;
children = (
- 82B784A21535835A0097863D /* stackoverflow.png */,
+ 823BAB481545BD0500C98751 /* icon_offline.png */,
+ 82B784A21535835A0097863D /* icon_online.png */,
);
name = Shared;
sourceTree = "<group>";
@@ -287,8 +290,9 @@
824A925815324356002033A7 /* InfoPlist.strings in Resources */,
824A925E15324356002033A7 /* Credits.rtf in Resources */,
824A926415324357002033A7 /* MainMenu.xib in Resources */,
- 82B784A31535835A0097863D /* stackoverflow.png in Resources */,
+ 82B784A31535835A0097863D /* icon_online.png in Resources */,
82A68A7D1539C3EE008DA2E8 /* SettingsWindow.xib in Resources */,
+ 823BAB491545BD0500C98751 /* icon_offline.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -44,12 +44,14 @@ @implementation BaseMenu
@synthesize delegate;
+- (void) setStatusIconWithImagePath:(NSString *) image_name {
+ NSString* imageName = [[NSBundle mainBundle] pathForResource:image_name ofType:@"png"];
+ NSImage* imageObj = [[[NSImage alloc] initWithContentsOfFile:imageName] autorelease];
+ [statusItem setImage:imageObj];
+}
- (void) initStatusItem {
- NSString* imageName = [[NSBundle mainBundle] pathForResource:@"stackoverflow" ofType:@"png"];
- NSImage* imageObj = [[NSImage alloc] initWithContentsOfFile:imageName];
- [statusItem setImage:imageObj];
- [imageObj release];
+ [self setStatusIconWithImagePath:RESOURCE_NAME_ICON_OFFLINE];
[statusItem setHighlightMode:YES];
[statusItem setEnabled:YES];
[statusItem setTarget:self];
@@ -122,6 +124,7 @@ - (void) updateUiForFailingWithProblem:(NSNumber *)number {
[[[statusItem menu] itemAtIndex:SM_INDEX_CONNECTION_STATUS] setTitle:CONNECTION_CONNECTING];
break;
}
+ [self setStatusIconWithImagePath:RESOURCE_NAME_ICON_OFFLINE];
}
- (void) updateFailedForProblem:(UPDATE_PROBLEMS)problem {
@@ -202,6 +205,7 @@ - (void) updateReputationInfoWithData:(UserData *) data {
[menuItem setTitle:[NSString stringWithFormat:@"Rep: %@", [data reputation]]];
}
else {
+
[menuItem setTitle:[NSString stringWithFormat:@"Rep: %@ (%@)", [data reputation], offset]];
}
@@ -227,6 +231,8 @@ - (void) updateUiWithUserData:(UserData *) data {
}
- (void) updateUiWithSiteData:(SiteData *) data {
+ [self setStatusIconWithImagePath:RESOURCE_NAME_ICON_ONLINE];
+
NSMenu * menu = [[[statusItem menu] itemAtIndex:SM_INDEX_NEW_QUESTIONS] submenu];
[menu removeAllItems];
NSArray * newestQuestionsArray = [data newestQuestions];
View
@@ -20,6 +20,10 @@
#ifndef SONotifier_Globals_h
#define SONotifier_Globals_h
+// ***** Source names ***** //
+#define RESOURCE_NAME_ICON_ONLINE @"icon_online"
+#define RESOURCE_NAME_ICON_OFFLINE @"icon_offline"
+
// ***** NSUserDefaults keys ***** //
#define DATA_KEY_UPDATE_INTERVAL @"com_bsharet_sonotifier_update_interval"
#define DATA_KEY_USER_ID @"com_bsharet_sonotifier_user_id"
@@ -33,18 +33,17 @@ - (NSAttributedString *) createTitleFromDictionary:(NSDictionary *)dict {
NSNumber * reputation = [dict objectForKey:API_KEY_REPUTATION_CHANGE];
repColor = ([reputation intValue] > 0) ? [NSColor greenColor] : [NSColor redColor];
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSFont fontWithName:@"Helvetica" size:14], NSFontAttributeName,
+ [NSFont fontWithName:@"Helvetica" size:15], NSFontAttributeName,
repColor, NSForegroundColorAttributeName,
nil];
current = [[[NSAttributedString alloc]
initWithString:[NSString stringWithFormat:@"%@\t", reputation]
attributes:attributes] autorelease];
[finalStr appendAttributedString:current];
attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSFont fontWithName:@"Helvetica" size:14], NSFontAttributeName,
+ [NSFont fontWithName:@"Helvetica" size:15], NSFontAttributeName,
nil];
- title = [Utils decorateStringWithThreeDots:[dict objectForKey:API_KEY_REPUTATION_TITLE]
- limitedForLength:50];
+ title = [Utils string:[dict objectForKey:API_KEY_REPUTATION_TITLE] limitedToLength:50];
current = [[[NSAttributedString alloc]
initWithString:title attributes:attributes] autorelease];
[finalStr appendAttributedString:current];
@@ -25,8 +25,7 @@ @implementation QuestionMenuItem
@synthesize url;
- (NSString *) createTitleFromDictionary:(NSDictionary *) dict {
- return [Utils decorateStringWithThreeDots:[dict objectForKey:API_KEY_QUESTION_TITLE]
- limitedForLength:60];
+ return [Utils string:[dict objectForKey:API_KEY_QUESTION_TITLE] limitedToLength:60];
}
- (id) initFromDictionary:(NSDictionary *) dict {
View
@@ -1,16 +1,33 @@
-//
-// Utils.h
-// SONotifier
-//
-// Created by Sharet, Binyamin on 4/14/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
+/*
+ * Copyright (C) 2012 Binyamin Sharet
+ *
+ * This file is part of SONotifier.
+ *
+ * SONotifier 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SONotifier 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 SONotifier. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The methods addAppAsLoginItem and deleteAppFromLoginItem were taken from
+ * http://cocoatutorial.grapewave.com/tag/lssharedfilelist-h/
+ */
#import <Foundation/Foundation.h>
@interface Utils : NSObject {
}
-+ (NSString *) decorateStringWithThreeDots: (NSString *)string limitedForLength:(NSInteger)maxLength;
++ (NSString *) string:(NSString*)string limitedToLength:(NSInteger)maxLength;
++ (void) addAppAsLoginItem;
++ (void) deleteAppFromLoginItem;
+
@end
View
@@ -1,19 +1,73 @@
-//
-// Utils.m
-// SONotifier
-//
-// Created by Sharet, Binyamin on 4/14/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
+/*
+ * Copyright (C) 2012 Binyamin Sharet
+ *
+ * This file is part of SONotifier.
+ *
+ * SONotifier 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SONotifier 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 SONotifier. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The methods addAppAsLoginItem and deleteAppFromLoginItem were taken from
+ * http://cocoatutorial.grapewave.com/tag/lssharedfilelist-h/
+ */
#import "Utils.h"
@implementation Utils
-+ (NSString *) decorateStringWithThreeDots: (NSString *)string limitedForLength:(NSInteger)maxLength {
++ (NSString *) string:(NSString*)string limitedToLength:(NSInteger)maxLength {
if ([string length] > maxLength) {
string = [NSString stringWithFormat:@"%@...", [string substringToIndex:maxLength - 3]];
}
return string;
}
+
++ (void) addAppAsLoginItem {
+ NSString * appPath = [[NSBundle mainBundle] bundlePath];
+ CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
+ LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL,
+ kLSSharedFileListSessionLoginItems, NULL);
+ if (loginItems) {
+ LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,
+ kLSSharedFileListItemLast, NULL, NULL,
+ url, NULL, NULL);
+ if (item){
+ CFRelease(item);
+ }
+ }
+
+ CFRelease(loginItems);
+}
+
++ (void) deleteAppFromLoginItem {
+ NSString * appPath = [[NSBundle mainBundle] bundlePath];
+ CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
+ LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL,
+ kLSSharedFileListSessionLoginItems, NULL);
+ if (loginItems) {
+ UInt32 seedValue;
+ NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginItems, &seedValue);
+ int i;
+ for(i = 0 ; i< [loginItemsArray count]; i++){
+ LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)[loginItemsArray
+ objectAtIndex:i];
+ if (LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*) &url, NULL) == noErr) {
+ NSString * urlPath = [(NSURL*)url path];
+ if ([urlPath compare:appPath] == NSOrderedSame){
+ LSSharedFileListItemRemove(loginItems,itemRef);
+ }
+ }
+ }
+ [loginItemsArray release];
+ }
+}
@end
@@ -1,6 +1,6 @@
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf320
-{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 TrebuchetMS;}
-{\colortbl;\red255\green255\blue255;\red255\green255\blue255;}
+{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
+{\colortbl;\red255\green255\blue255;}
\vieww9600\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720
@@ -11,10 +11,8 @@
\b Human Interface Design:
\b0 \
- Icons for the application were created by George Edison
-\f1\b\fs44 \cb2 \
-
-\f0\b0\fs24 \cb1 and taken from {\field{\*\fldinst{HYPERLINK "http://stackoverflow.quickmediasolutions.com/images/stackoverflow.png"}}{\fldrslt http://stackoverflow.quickmediasolutions.com/images/stackoverflow.png}}\
+ - Icons for the application were created by George Edison and taken from {\field{\*\fldinst{HYPERLINK "http://stackoverflow.quickmediasolutions.com/images/stackoverflow.png"}}{\fldrslt http://stackoverflow.quickmediasolutions.com/images/stackoverflow.png}}\
+ - Setting application as login item methods were taken from {\field{\*\fldinst{HYPERLINK "http://cocoatutorial.grepwave.com/tag/lssharedfilelist-h"}}{\fldrslt http://cocoatutorial.grepwave.com/tag/lssharedfilelist-h}}\
\
\b Testing:
View
Binary file not shown.
File renamed without changes.

0 comments on commit 99a4c08

Please sign in to comment.