Browse Source

Change what appears in the menubar!

v1.2.2
Abhishek Banthia 9 years ago
parent
commit
649af6d2ee
  1. BIN
      Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate
  2. 178
      Clocker/Appearance Tab/CLAppearanceView.xib
  3. 62
      Clocker/Appearance Tab/CLAppearanceViewController.m
  4. 20
      Clocker/ApplicationDelegate.m
  5. 2
      Clocker/Custom Table Cell Views/CLTimezoneCellView.h
  6. 14
      Clocker/Custom Table Cell Views/CLTimezoneCellView.m
  7. 47
      Clocker/MenubarController.m
  8. 12
      Clocker/Model/CLTimezoneData.h
  9. 88
      Clocker/Model/CLTimezoneData.m
  10. 26
      Clocker/Panel.xib
  11. 163
      Clocker/PanelController.m
  12. 60
      Clocker/Preferences/CLPreferencesView.xib
  13. 2
      Clocker/Preferences/CLPreferencesViewController.h
  14. 231
      Clocker/Preferences/CLPreferencesViewController.m
  15. 2
      Clocker/StatusItemView.h
  16. 65
      Clocker/StatusItemView.m
  17. 4
      Clocker/Utilities/CommonStrings.h
  18. 4
      Clocker/Utilities/CommonStrings.m

BIN
Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate generated

Binary file not shown.

178
Clocker/Appearance Tab/CLAppearanceView.xib

@ -15,11 +15,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="439" height="335"/>
<rect key="frame" x="0.0" y="0.0" width="439" height="463"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="iVw-cq-zLz">
<rect key="frame" x="198" y="235" width="44" height="18"/>
<rect key="frame" x="198" y="349" width="44" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="2DP-wK-Ga8"/>
<constraint firstAttribute="width" constant="40" id="KEa-ei-G2i"/>
@ -31,7 +31,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5TC-RQ-gzI">
<rect key="frame" x="183" y="297" width="74" height="18"/>
<rect key="frame" x="183" y="411" width="74" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="gWc-u4-D8E"/>
<constraint firstAttribute="width" constant="70" id="nh0-5K-Aa0"/>
@ -43,7 +43,7 @@
</textFieldCell>
</textField>
<segmentedControl toolTip="Choose a theme for the main panel!" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5tI-fU-0lZ">
<rect key="frame" x="158" y="204" width="124" height="24"/>
<rect key="frame" x="158" y="318" width="124" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="dW5-vG-EwD"/>
</constraints>
@ -60,7 +60,7 @@
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="YQi-x8-6f8">
<rect key="frame" x="175" y="173" width="89" height="18"/>
<rect key="frame" x="175" y="287" width="89" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="eY8-bV-QLM"/>
<constraint firstAttribute="width" constant="85" id="n8S-fR-UtY"/>
@ -71,25 +71,8 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="1eh-BT-2fK">
<rect key="frame" x="98" y="142" width="244" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="uU1-9Q-cqa"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="ZV9-ih-faz">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<segments>
<segment label="Show Relative Dates"/>
<segment label="Show actual day" selected="YES" tag="1"/>
</segments>
</segmentedCell>
<connections>
<action selector="changeRelativeDayDisplay:" target="-2" id="7Af-BH-qFq"/>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.relativeDate" id="eKo-sG-1eE"/>
</connections>
</segmentedControl>
<segmentedControl toolTip="Select a time-format!" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OrL-Ix-fmY">
<rect key="frame" x="102" y="266" width="236" height="24"/>
<rect key="frame" x="102" y="380" width="236" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="232" id="uOJ-Mi-Fin"/>
</constraints>
@ -106,23 +89,64 @@
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3d9-qg-dNb">
<rect key="frame" x="130" y="111" width="179" height="18"/>
<rect key="frame" x="130" y="173" width="179" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="MdL-Dh-02n"/>
<constraint firstAttribute="width" constant="175" id="hHO-Wa-gmc"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Show Sunrise, Sunset Time (Beta)" id="ZP5-1i-Bm8">
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Menubar Display Options" id="ZP5-1i-Bm8">
<font key="font" size="12" name="SFUIDisplay-Regular"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pqa-Qg-U8Y">
<rect key="frame" x="130" y="146" width="179" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="175" id="B2I-0j-0W0"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Show Date of Favourite Place" id="IAe-wr-MUG">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="atA-2r-FXV">
<rect key="frame" x="180" y="80" width="80" height="24"/>
<rect key="frame" x="179" y="118" width="84" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="76" id="dEg-kt-bk1"/>
<constraint firstAttribute="height" constant="21" id="ttW-aD-dh3"/>
<constraint firstAttribute="height" constant="21" id="BqM-4F-6Ta"/>
<constraint firstAttribute="width" constant="80" id="ZeK-lO-tUa"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="rIg-AP-wGG">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<segments>
<segment label="Yes" selected="YES"/>
<segment label="No" tag="1"/>
</segments>
</segmentedCell>
<connections>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.showDate" id="Qee-Dc-Piu"/>
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kEn-QZ-niZ">
<rect key="frame" x="130" y="97" width="179" height="18"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="2fd-f6-8cD"/>
<constraint firstAttribute="width" constant="175" id="D0w-xz-gkw"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Show Day of Favourite Place" id="I99-Wp-1Iq">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XwV-hy-YiP">
<rect key="frame" x="178" y="69" width="84" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="80" id="dBz-ZQ-BF1"/>
<constraint firstAttribute="height" constant="21" id="y8c-hZ-MtI"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="18N-XQ-ANm">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<segments>
<segment label="Yes"/>
@ -130,11 +154,11 @@
</segments>
</segmentedCell>
<connections>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.displaySuntime" id="rkd-Nx-YEh"/>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.showDay" id="AeO-a9-xU4"/>
</connections>
</segmentedControl>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="72r-oi-X0f">
<rect key="frame" x="184" y="18" width="71" height="24"/>
<rect key="frame" x="184" y="202" width="71" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="67" id="H8w-wg-vel"/>
</constraints>
@ -149,11 +173,27 @@
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.displayFutureSlider" id="zRQ-mQ-qBp"/>
</connections>
</segmentedControl>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="1eh-BT-2fK">
<rect key="frame" x="98" y="256" width="244" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="uU1-9Q-cqa"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="ZV9-ih-faz">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<segments>
<segment label="Show Relative Dates"/>
<segment label="Show actual day" selected="YES" tag="1"/>
</segments>
</segmentedCell>
<connections>
<action selector="changeRelativeDayDisplay:" target="-2" id="7Af-BH-qFq"/>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.relativeDate" id="eKo-sG-1eE"/>
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HTZ-1V-qZb">
<rect key="frame" x="165" y="49" width="109" height="18"/>
<rect key="frame" x="165" y="233" width="109" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="105" id="1Lv-wC-hEM"/>
<constraint firstAttribute="height" constant="18" id="tK6-lZ-2AV"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Show Future Slider" id="PE4-Ua-hkI">
<font key="font" size="12" name="SFUIDisplay-Light"/>
@ -161,30 +201,92 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<box verticalHuggingPriority="750" title="Box" boxType="separator" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="MHe-dB-GZr">
<rect key="frame" x="0.0" y="193" width="439" height="5"/>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<font key="titleFont" metaFont="system"/>
</box>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LC1-Sx-uav">
<rect key="frame" x="130" y="45" width="179" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="175" id="Pdc-78-vzv"/>
<constraint firstAttribute="height" constant="18" id="hsh-i8-ULY"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Show Favourite Place Name" id="nEh-Sa-SDH">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JR8-v7-K0w">
<rect key="frame" x="178" y="17" width="84" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="Xof-eY-ZUl"/>
<constraint firstAttribute="width" constant="80" id="msH-Xd-mrp"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="SLe-HO-6so">
<font key="font" size="12" name="SFUIDisplay-Light"/>
<segments>
<segment label="Yes"/>
<segment label="No" selected="YES" tag="1"/>
</segments>
</segmentedCell>
<connections>
<binding destination="WGI-5h-l6M" name="selectedIndex" keyPath="values.showCityName" id="FYy-NU-cIr"/>
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="X5s-Mc-Yfo">
<rect key="frame" x="130" y="437" width="179" height="18"/>
<constraints>
<constraint firstAttribute="width" constant="175" id="YaE-Og-A4W"/>
<constraint firstAttribute="height" constant="18" id="bTT-ve-oW9"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Main Panel Options" id="skQ-rM-X70">
<font key="font" size="12" name="SFUIDisplay-Regular"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="5TC-RQ-gzI" firstAttribute="top" secondItem="X5s-Mc-Yfo" secondAttribute="bottom" constant="8" id="1Wi-S2-cSq"/>
<constraint firstItem="72r-oi-X0f" firstAttribute="top" secondItem="HTZ-1V-qZb" secondAttribute="bottom" constant="8" id="23z-Z7-vpe"/>
<constraint firstItem="HTZ-1V-qZb" firstAttribute="top" secondItem="atA-2r-FXV" secondAttribute="bottom" constant="15" id="55C-jv-7Rw"/>
<constraint firstItem="LC1-Sx-uav" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="2M5-Z9-HrL"/>
<constraint firstItem="MHe-dB-GZr" firstAttribute="top" secondItem="72r-oi-X0f" secondAttribute="bottom" constant="8" id="3Lr-IT-EsF"/>
<constraint firstItem="YQi-x8-6f8" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="6LU-d8-lKX"/>
<constraint firstItem="3d9-qg-dNb" firstAttribute="top" secondItem="MHe-dB-GZr" secondAttribute="bottom" constant="4" id="BZ1-zf-1At"/>
<constraint firstItem="3d9-qg-dNb" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="FBj-0N-ltc"/>
<constraint firstItem="OrL-Ix-fmY" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="JtZ-ra-RaC"/>
<constraint firstItem="kEn-QZ-niZ" firstAttribute="top" secondItem="atA-2r-FXV" secondAttribute="bottom" constant="5" id="O8m-uk-Ppx"/>
<constraint firstItem="X5s-Mc-Yfo" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="8" id="OeD-4K-q6Y"/>
<constraint firstItem="HTZ-1V-qZb" firstAttribute="top" secondItem="1eh-BT-2fK" secondAttribute="bottom" constant="7" id="Ohx-zT-4Wu"/>
<constraint firstItem="pqa-Qg-U8Y" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="PHa-pY-kHG"/>
<constraint firstItem="1eh-BT-2fK" firstAttribute="top" secondItem="YQi-x8-6f8" secondAttribute="bottom" constant="8" id="POa-Gi-Prk"/>
<constraint firstItem="atA-2r-FXV" firstAttribute="top" secondItem="3d9-qg-dNb" secondAttribute="bottom" constant="8" id="PY9-Mh-Qsb"/>
<constraint firstItem="atA-2r-FXV" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Pjx-sg-kK0"/>
<constraint firstItem="X5s-Mc-Yfo" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="PRU-TH-852"/>
<constraint firstItem="atA-2r-FXV" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" constant="1" id="Pjx-sg-kK0"/>
<constraint firstItem="XwV-hy-YiP" firstAttribute="top" secondItem="kEn-QZ-niZ" secondAttribute="bottom" constant="5" id="Qyy-6B-BBN"/>
<constraint firstItem="atA-2r-FXV" firstAttribute="top" secondItem="pqa-Qg-U8Y" secondAttribute="bottom" constant="5" id="RdE-wy-6vH"/>
<constraint firstItem="MHe-dB-GZr" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="TyR-gg-RLi"/>
<constraint firstItem="pqa-Qg-U8Y" firstAttribute="top" secondItem="3d9-qg-dNb" secondAttribute="bottom" constant="9" id="Uc0-mI-ciF"/>
<constraint firstItem="5tI-fU-0lZ" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Vkb-QV-unN"/>
<constraint firstItem="HTZ-1V-qZb" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Wet-hO-O6U"/>
<constraint firstItem="YQi-x8-6f8" firstAttribute="top" secondItem="5tI-fU-0lZ" secondAttribute="bottom" constant="15" id="WoY-W4-XuS"/>
<constraint firstItem="JR8-v7-K0w" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Wye-84-JgC"/>
<constraint firstItem="iVw-cq-zLz" firstAttribute="top" secondItem="OrL-Ix-fmY" secondAttribute="bottom" constant="15" id="XgM-Wl-Xap"/>
<constraint firstItem="iVw-cq-zLz" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="Zh8-Vn-VxM"/>
<constraint firstItem="5tI-fU-0lZ" firstAttribute="top" secondItem="iVw-cq-zLz" secondAttribute="bottom" constant="8" id="bo6-s2-Vfj"/>
<constraint firstItem="kEn-QZ-niZ" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="eU3-c4-cnM"/>
<constraint firstItem="1eh-BT-2fK" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" constant="0.5" id="fvI-By-5Ef"/>
<constraint firstItem="3d9-qg-dNb" firstAttribute="top" secondItem="1eh-BT-2fK" secondAttribute="bottom" constant="15" id="iVY-Yj-mck"/>
<constraint firstAttribute="trailing" secondItem="MHe-dB-GZr" secondAttribute="trailing" id="jL7-Cv-YuY"/>
<constraint firstItem="5TC-RQ-gzI" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="lc0-ud-Mnw"/>
<constraint firstItem="5TC-RQ-gzI" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="oI8-4L-ppf"/>
<constraint firstItem="JR8-v7-K0w" firstAttribute="top" secondItem="LC1-Sx-uav" secondAttribute="bottom" constant="5" id="pHX-KA-5RI"/>
<constraint firstItem="OrL-Ix-fmY" firstAttribute="top" secondItem="5TC-RQ-gzI" secondAttribute="bottom" constant="8" id="rpk-WN-DT9"/>
<constraint firstItem="72r-oi-X0f" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="wHU-od-8e8"/>
<constraint firstItem="XwV-hy-YiP" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="x6a-GW-bOn"/>
<constraint firstItem="LC1-Sx-uav" firstAttribute="top" secondItem="XwV-hy-YiP" secondAttribute="bottom" constant="8" id="xFV-GA-ozB"/>
</constraints>
<point key="canvasLocation" x="187" y="251"/>
<point key="canvasLocation" x="186.5" y="314.5"/>
</customView>
<userDefaultsController representsSharedInstance="YES" id="WGI-5h-l6M"/>
</objects>

62
Clocker/Appearance Tab/CLAppearanceViewController.m

@ -10,10 +10,12 @@
#import "ApplicationDelegate.h"
#import "PanelController.h"
#import "CommonStrings.h"
#import "CLTimezoneData.h"
@interface CLAppearanceViewController ()
@property (weak) IBOutlet NSSegmentedControl *timeFormat;
@property (weak) IBOutlet NSSegmentedControl *theme;
@property (weak) IBOutlet NSSegmentedControl *menuOptions;
@end
@ -27,6 +29,13 @@
[self.view setWantsLayer:YES]; // view's backing store is using a Core Animation Layer
[self.view setLayer:viewLayer];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSNumber *shouldCityBeShown = [userDefaults objectForKey:@"shouldCityBeShown"];
NSNumber *shouldDayBeShown = [userDefaults objectForKey:@"shouldDayBeShown"];
[self.menuOptions setSelected:shouldDayBeShown.boolValue forSegment:0];
[self.menuOptions setSelected:shouldCityBeShown.boolValue forSegment:1];
}
- (IBAction)timeFormatSelectionChanged:(id)sender
@ -87,4 +96,57 @@
});
}
- (NSImage *)imageWithSubviewsWithTextField:(NSTextField *)textField
{
NSSize mySize = textField.bounds.size;
NSSize imgSize = NSMakeSize( mySize.width, mySize.height );
NSBitmapImageRep *bir = [textField bitmapImageRepForCachingDisplayInRect:[textField bounds]];
[bir setSize:imgSize];
[textField cacheDisplayInRect:[textField bounds] toBitmapImageRep:bir];
NSImage* image = [[NSImage alloc]initWithSize:imgSize];
[image addRepresentation:bir];
return image;
}
- (NSImage *)textWithTextField:(NSTextField *)textField
{
NSString *myString = textField.stringValue;
unsigned char *string = (unsigned char *) [myString UTF8String];
NSSize mySize = NSMakeSize(50,100); //or measure the string
NSBitmapImageRep *bir = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:&string
pixelsWide:mySize.width pixelsHigh:mySize.height
bitsPerSample:8
samplesPerPixel:3 // or 4 with alpha
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0
bytesPerRow:0 // 0 == determine automatically
bitsPerPixel:0]; // 0 == determine automatically
//draw text using -(void)drawInRect:(NSRect)aRect withAttributes:(NSDictionary *)attributes
NSImage* image = [[NSImage alloc]initWithSize:mySize];
[image addRepresentation:bir];
return image;
}
- (IBAction)changeMenuBarDisplayPreferences:(id)sender
{
NSSegmentedControl *segmentedControl = (NSSegmentedControl *)sender;
NSNumber *shouldDayBeShown = [NSNumber numberWithBool:[segmentedControl isSelectedForSegment:0]];
NSNumber *shouldCityBeShown = [NSNumber numberWithBool:[segmentedControl isSelectedForSegment:1]];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:shouldDayBeShown forKey:@"shouldDayBeShown"];
[userDefaults setObject:shouldCityBeShown forKey:@"shouldCityBeShown"];
}
@end

20
Clocker/ApplicationDelegate.m

@ -83,11 +83,6 @@ void *kContextActivePanel = &kContextActivePanel;
[[NSUserDefaults standardUserDefaults] setObject:@"Default" forKey:CLThemeKey];
}
NSNumber *displaySuntimings = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplaySunTimingKey];
if (displaySuntimings == nil) {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:1] forKey:CLDisplaySunTimingKey];
}
NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey];
if (displayFutureSlider == nil) {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:0] forKey:CLDisplayFutureSliderKey];
@ -102,6 +97,21 @@ void *kContextActivePanel = &kContextActivePanel;
if (relativeDate == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLRelativeDateKey];
}
NSNumber *showDayInMenuBar = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowDayInMenu];
if (showDayInMenuBar == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowDayInMenu];
}
NSNumber *showDateInMenu = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowDateInMenu];
if (showDateInMenu == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@1 forKey:CLShowDateInMenu];
}
NSNumber *showCityInMenu = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowCityInMenu];
if (showCityInMenu == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowCityInMenu];
}
// Install icon into the menu bar
self.menubarController = [[MenubarController alloc] init];

2
Clocker/Custom Table Cell Views/CLTimezoneCellView.h

@ -13,8 +13,6 @@
@property (weak) IBOutlet NSTextField *customName;
@property (weak) IBOutlet NSTextField *relativeDate;
@property (weak) IBOutlet NSTextField *time;
@property (weak) IBOutlet NSImageView *sunImage;
@property (weak) IBOutlet NSTextField *sunTime;
@property (nonatomic) NSInteger rowNumber;
- (void)updateTextColorWithColor:(NSColor *)color andCell:(CLTimezoneCellView*)cell;

14
Clocker/Custom Table Cell Views/CLTimezoneCellView.m

@ -39,15 +39,18 @@
if ([[sender superview] isKindOfClass:[self class]]) {
CLTimezoneCellView *cellView = (CLTimezoneCellView *)[sender superview];
CLTimezoneData *dataObject = panelController.defaultPreferences[cellView.rowNumber];
CLTimezoneData *newDataObject = [dataObject mutableCopy];
NSData *dataObject = panelController.defaultPreferences[cellView.rowNumber];
NSData *newDataObject = [dataObject mutableCopy];
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:newDataObject];
for (CLTimezoneData *object in panelController.defaultPreferences) {
if ([object.formattedAddress isEqualToString:customLabelValue]) {
for (NSData *object in panelController.defaultPreferences)
{
CLTimezoneData *timeObject = [CLTimezoneData getCustomObject:object];
if ([timeObject.formattedAddress isEqualToString:customLabelValue]) {
return;
}
}
newDataObject.customLabel = (customLabelValue.length > 0) ? customLabelValue : CLEmptyString;
timezoneObject.customLabel = (customLabelValue.length > 0) ? customLabelValue : CLEmptyString;
[panelController.defaultPreferences replaceObjectAtIndex:cellView.rowNumber withObject:newDataObject];
[[NSUserDefaults standardUserDefaults] setObject:panelController.defaultPreferences forKey:CLDefaultPreferenceKey];
@ -64,7 +67,6 @@
cell.relativeDate.textColor = color;
cell.customName.textColor = color;
cell.time.textColor = color;
cell.sunTime.textColor = color;
}
- (void)setUpAutoLayoutWithCell:(CLTimezoneCellView *)cell

47
Clocker/MenubarController.m

@ -2,6 +2,8 @@
#import "MenubarController.h"
#import "StatusItemView.h"
#import "CLTimezoneData.h"
#import "ApplicationDelegate.h"
@implementation MenubarController
@ -15,15 +17,56 @@
if (self != nil)
{
// Install status item into the menu bar
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:STATUS_ITEM_VIEW_WIDTH];
NSData *dataObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"favouriteTimezone"];
NSString *menuTitle = [NSString new];
if (dataObject) {
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:dataObject];
menuTitle = [timezoneObject getMenuTitle];
}
NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, STATUS_ITEM_VIEW_WIDTH, 18)];
textField.backgroundColor = [NSColor whiteColor];
textField.bordered = NO;
textField.textColor = [NSColor blackColor];
textField.alignment = NSTextAlignmentCenter;
textField.stringValue = (menuTitle.length > 0) ? menuTitle : @"Icon";
[textField sizeToFit];
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:textField.frame.size.width+3];
_statusItemView = [[StatusItemView alloc] initWithStatusItem:statusItem];
_statusItemView.image = [NSImage imageNamed:@"Status"];
_statusItemView.image = [self imageWithSubviewsWithTextField:textField];
_statusItemView.alternateImage = [NSImage imageNamed:@"StatusHighlighted"];
_statusItemView.action = @selector(togglePanel:);
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateIconDisplay)
userInfo:nil
repeats:YES];
}
return self;
}
- (void)updateIconDisplay
{
[self.statusItemView setNeedsDisplay:YES];
}
- (NSImage *)imageWithSubviewsWithTextField:(NSTextField *)textField
{
NSSize mySize = textField.bounds.size;
NSSize imgSize = NSMakeSize( mySize.width, mySize.height );
NSBitmapImageRep *bir = [textField bitmapImageRepForCachingDisplayInRect:[textField bounds]];
[bir setSize:imgSize];
[textField cacheDisplayInRect:[textField bounds] toBitmapImageRep:bir];
NSImage* image = [[NSImage alloc]initWithSize:imgSize];
[image addRepresentation:bir];
return image;
}
- (void)dealloc
{
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];

12
Clocker/Model/CLTimezoneData.h

@ -14,12 +14,13 @@
@property (strong, nonatomic) NSString *customLabel;
@property (strong, nonatomic) NSString *formattedAddress;
@property (strong, nonatomic) NSString *place_id;
@property (strong, nonatomic) NSString *sunriseTime;
@property (strong, nonatomic) NSString *sunsetTime;
@property (strong, nonatomic) NSString *timezoneID;
@property (strong, nonatomic) NSString *latitude;
@property (strong, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSDate *nextUpdate;
@property (strong, nonatomic) NSNumber *isFavourite;
+ (instancetype)getCustomObject:(NSData *)encodedData;
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (BOOL)saveObjectToPreferences:(CLTimezoneData *)object;
@ -28,8 +29,11 @@
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date;
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue;
- (void)getTimeZoneForLatitude:(NSString *)latitude andLongitude:(NSString *)longitude andDataObject:(CLTimezoneData *)dataObject;
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell;
- (NSString *)formatStringShouldContainCity:(BOOL)value;
+ (instancetype)getCustomObject:(NSData *)encodedData;
- (NSString *)getMenuTitle;
/*
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell;
*/
@end

88
Clocker/Model/CLTimezoneData.m

@ -19,13 +19,12 @@
if (self == [super init])
{
self.customLabel = dictionary[CLCustomLabel];
self.sunriseTime = CLEmptyString;
self.sunsetTime = CLEmptyString;
self.timezoneID = dictionary[CLTimezoneID];
self.latitude = dictionary[@"latitude"];
self.longitude = dictionary[@"longitude"];
self.place_id = dictionary[CLPlaceIdentifier];
self.formattedAddress = dictionary[CLTimezoneName];
self.isFavourite = [NSNumber numberWithInt:NSOffState];
}
return self;
@ -55,11 +54,9 @@
[coder encodeObject:self.place_id forKey:@"place_id"];
[coder encodeObject:self.formattedAddress forKey:@"formattedAddress"];
[coder encodeObject:self.customLabel forKey:@"customLabel"];
[coder encodeObject:self.sunriseTime forKey:@"sunriseTime"];
[coder encodeObject:self.sunsetTime forKey:@"sunsetTime"];
[coder encodeObject:self.timezoneID forKey:@"timezoneID"];
[coder encodeObject:self.nextUpdate forKey:@"nextUpdate"];
[coder encodeObject:self.isFavourite forKey:@"isFavourite"];
}
- (instancetype)initWithCoder:(NSCoder *)coder
@ -69,10 +66,9 @@
self.place_id = [coder decodeObjectForKey:@"place_id"];
self.formattedAddress = [coder decodeObjectForKey:@"formattedAddress"];
self.customLabel = [coder decodeObjectForKey:@"customLabel"];
self.sunsetTime = [coder decodeObjectForKey:@"sunsetTime"];
self.sunriseTime = [coder decodeObjectForKey:@"sunriseTime"];
self.timezoneID = [coder decodeObjectForKey:@"timezoneID"];
self.nextUpdate = [coder decodeObjectForKey:@"nextUpdate"];
self.isFavourite = [coder decodeObjectForKey:@"isFavourite"];
}
return self;
@ -80,14 +76,13 @@
-(NSString *)description
{
return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nSunrise: %@\nSunset: %@\nPlaceID: %@", self.timezoneID,
return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nPlaceID: %@\nisFavourite: %@", self.timezoneID,
self.formattedAddress,
self.customLabel,
self.latitude,
self.longitude,
self.sunriseTime,
self.sunsetTime,
self.place_id];
self.place_id,
self.isFavourite];
}
- (NSString *)formatStringShouldContainCity:(BOOL)value
@ -119,8 +114,14 @@
}
/*
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell
{
if (!self.shouldFetchSunTimings) {
return CLEmptyString;
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *sunTime = [formatter dateFromString:self.sunriseTime];
@ -152,7 +153,7 @@
[NSImage imageNamed:@"Sunset"] : [NSImage imageNamed:@"White Sunset"];
return [self.sunsetTime substringFromIndex:11];
}
}
}*/
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
{
@ -218,13 +219,10 @@
newDataObject.formattedAddress = self.formattedAddress;
newDataObject.latitude = self.latitude;
newDataObject.longitude = self.longitude;
newDataObject.sunriseTime = self.sunriseTime;
newDataObject.sunsetTime = self.sunsetTime;
newDataObject.customLabel = self.customLabel;
newDataObject.place_id = self.place_id;
newDataObject.nextUpdate = tomorrowMidnight;
newDataObject.isFavourite = [NSNumber numberWithInt:NSOffState];
PanelController *panelController;
@ -329,10 +327,11 @@
CLTimezoneData *newDataObject = [dataObject mutableCopy];
/*
if (json[@"sunrise"] && json[@"sunset"]) {
newDataObject.sunriseTime = json[@"sunrise"];
newDataObject.sunsetTime = json[@"sunset"];
}
}*/
NSUInteger units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSDateComponents *comps = [[NSCalendar currentCalendar] components:units fromDate:newDataObject.nextUpdate];
@ -421,6 +420,61 @@
}
}
- (NSString *)getMenuTitle
{
NSMutableString *menuTitle = [NSMutableString new];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSNumber *shouldCityBeShown = [userDefaults objectForKey:CLShowCityInMenu];
NSNumber *shouldDayBeShown = [userDefaults objectForKey:CLShowDayInMenu];
NSNumber *shouldDateBeShown = [userDefaults objectForKey:CLShowDateInMenu];
if (shouldCityBeShown.boolValue == 0)
{
[menuTitle appendString:self.formattedAddress];
}
if (shouldDayBeShown.boolValue == 0)
{
NSString *substring = [self getDateForTimeZoneWithFutureSliderValue:0];
substring = [substring substringToIndex:3];
if (menuTitle.length > 0)
{
[menuTitle appendFormat:@" %@",substring.capitalizedString];
}
else
{
[menuTitle appendString:substring.capitalizedString];
}
}
if (shouldDateBeShown.boolValue == 0)
{
NSString *date = [[NSDate date] formattedDateWithFormat:@"MMM dd" timeZone:[NSTimeZone timeZoneWithName:self.timezoneID] locale:[NSLocale currentLocale]];
if (menuTitle.length > 0)
{
[menuTitle appendFormat:@" %@",date];
}
else
{
[menuTitle appendString:date];
}
}
if (menuTitle.length > 0)
{
[menuTitle appendFormat:@" %@",[self getTimeForTimeZoneWithFutureSliderValue:0]];
}
else
{
[menuTitle appendString:[self getTimeForTimeZoneWithFutureSliderValue:0]];
}
return menuTitle;
}
@end

26
Clocker/Panel.xib

@ -98,44 +98,18 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7zS-Nt-MMx">
<rect key="frame" x="82" y="11" width="19" height="21"/>
<constraints>
<constraint firstAttribute="width" constant="19" id="8ld-PK-Xtr"/>
<constraint firstAttribute="height" constant="21" id="D4F-wd-Y1z"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="LEc-9r-Xb6"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kga-Kt-F29">
<rect key="frame" x="102" y="14" width="38" height="15"/>
<constraints>
<constraint firstAttribute="height" constant="15" id="O7I-i9-V4C"/>
<constraint firstAttribute="width" constant="34" id="sm2-xn-PVC"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" placeholderString="" id="5Wm-Xi-fiE">
<font key="font" size="9" name="SFUIDisplay-Regular"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="QUd-7D-q14" firstAttribute="leading" secondItem="qbN-ba-fho" secondAttribute="leading" constant="10" id="0Qz-Ev-efP"/>
<constraint firstItem="7zS-Nt-MMx" firstAttribute="top" secondItem="etF-33-bCB" secondAttribute="bottom" constant="1" id="GXm-Gn-d7P"/>
<constraint firstItem="etF-33-bCB" firstAttribute="top" secondItem="qbN-ba-fho" secondAttribute="top" constant="5" id="Lct-kG-usb"/>
<constraint firstItem="kga-Kt-F29" firstAttribute="top" secondItem="etF-33-bCB" secondAttribute="bottom" constant="4" id="M2S-Fb-VV8"/>
<constraint firstItem="vnv-J2-7r1" firstAttribute="centerY" secondItem="qbN-ba-fho" secondAttribute="centerY" constant="-8" id="TuQ-gE-ZUh"/>
<constraint firstItem="QUd-7D-q14" firstAttribute="top" secondItem="etF-33-bCB" secondAttribute="bottom" constant="2" id="VO6-Zn-eA3"/>
<constraint firstItem="etF-33-bCB" firstAttribute="leading" secondItem="qbN-ba-fho" secondAttribute="leading" constant="9" id="ueW-ow-ZRq"/>
<constraint firstItem="7zS-Nt-MMx" firstAttribute="leading" secondItem="QUd-7D-q14" secondAttribute="trailing" id="vZ8-mD-p3a"/>
<constraint firstItem="kga-Kt-F29" firstAttribute="leading" secondItem="7zS-Nt-MMx" secondAttribute="trailing" constant="3" id="yxq-jA-jVe"/>
<constraint firstAttribute="trailing" secondItem="vnv-J2-7r1" secondAttribute="trailing" constant="8" id="zXo-eA-0bQ"/>
</constraints>
<connections>
<outlet property="customName" destination="etF-33-bCB" id="6Yz-qc-WmD"/>
<outlet property="relativeDate" destination="QUd-7D-q14" id="Ath-zr-bGo"/>
<outlet property="sunImage" destination="7zS-Nt-MMx" id="U1Z-8x-dVx"/>
<outlet property="sunTime" destination="kga-Kt-F29" id="rTz-qB-NS8"/>
<outlet property="textField" destination="etF-33-bCB" id="6fd-cc-Qq2"/>
<outlet property="time" destination="vnv-J2-7r1" id="XFD-GQ-9CD"/>
</connections>

163
Clocker/PanelController.m

@ -335,17 +335,7 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
cell.rowNumber = row;
cell.customName.stringValue = [dataObject formatStringShouldContainCity:YES];
NSNumber *displaySuntimings = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplaySunTimingKey];
if ([displaySuntimings isEqualToNumber:[NSNumber numberWithInteger:0]] && dataObject.sunriseTime && dataObject.sunsetTime) {
cell.sunTime.stringValue = [dataObject getFormattedSunriseOrSunsetTimeAndSunImage:cell];
}
else
{
cell.sunImage.image = nil;
cell.sunTime.stringValue = CLEmptyString;
}
NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey];
if ([displayFutureSlider isEqualToNumber:[NSNumber numberWithInteger:0]])
{
@ -517,155 +507,6 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
[NSApp postEvent:newEvent atStart:NO];
}
- (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger
{
if (weekdayInteger > 7) {
weekdayInteger = weekdayInteger - 7;
}
switch (weekdayInteger) {
case 1:
return @"Sunday";
break;
case 2:
return @"Monday";
break;
case 3:
return @"Tuesday";
break;
case 4:
return @"Wednesday";
break;
case 5:
return @"Thursday";
break;
case 6:
return @"Friday";
break;
case 7:
return @"Saturday";
break;
default:
return @"Error";
break;
}
}
- (void)getTimeZoneForLatitude:(NSString *)latitude andLongitude:(NSString *)longitude andDataObject:(CLTimezoneData *)dataObject
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
if (networkStatus == NotReachable)
{
//Could not fetch data
return;
}
NSString *urlString = [NSString stringWithFormat:@"http://api.geonames.org/timezoneJSON?lat=%@&lng=%@&username=abhishaker17", latitude, longitude];
NSURL *url = [NSURL URLWithString:urlString];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"GET";
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSError *error = nil;
if (!error) {
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
if (httpResp.statusCode == 200)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:nil];
if (json.count == 0) {
//No results found
return;
}
if ([json[@"status"][@"message"]
isEqualToString:@"the hourly limit of 2000 credits for abhishaker17 has been exceeded. Please throttle your requests or use the commercial service."])
{
return;
}
CLTimezoneData *newDataObject = [[CLTimezoneData alloc] init];
newDataObject.timezoneID = dataObject.timezoneID;
newDataObject.formattedAddress = dataObject.formattedAddress;
newDataObject.latitude = dataObject.latitude;
newDataObject.longitude = dataObject.longitude;
newDataObject.sunriseTime = dataObject.sunriseTime;
newDataObject.sunsetTime = dataObject.sunsetTime;
newDataObject.customLabel = dataObject.customLabel;
newDataObject.place_id = dataObject.place_id;
newDataObject.nextUpdate = dataObject.nextUpdate;
if (json[@"sunrise"] && json[@"sunset"]) {
newDataObject.sunriseTime = json[@"sunrise"];
newDataObject.sunsetTime = json[@"sunset"];
}
NSUInteger units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
NSDateComponents *comps = [[NSCalendar currentCalendar] components:units fromDate:dataObject.nextUpdate];
comps.day = comps.day + 1;
NSDate *tomorrowMidnight = [[NSCalendar currentCalendar] dateFromComponents:comps];
newDataObject.nextUpdate = tomorrowMidnight;
NSArray *defaultPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey];
if (defaultPreference == nil)
{
defaultPreference = [[NSMutableArray alloc] init];
}
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:defaultPreference];
for (NSMutableDictionary *timeDictionary in self.defaultPreferences) {
if ([dataObject.place_id isEqualToString:timeDictionary[CLPlaceIdentifier]]) {
[newArray replaceObjectAtIndex:[self.defaultPreferences indexOfObject:dataObject] withObject:newDataObject];
}
}
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey];
[self.mainTableview reloadData];
});
}
}
else
{
//error
}
}];
[dataTask resume];
}
}
- (void)updatePanelColor
{
NSString *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
@ -680,7 +521,7 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
self.window.alphaValue = 1;
}
}
@end

60
Clocker/Preferences/CLPreferencesView.xib

@ -137,14 +137,14 @@ CA
<rect key="frame" x="0.0" y="0.0" width="345" height="320"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="22" horizontalPageScroll="10" verticalLineScroll="22" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LM9-75-vkc">
<rect key="frame" x="8" y="28" width="329" height="257"/>
<scrollView focusRingType="none" misplaced="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="22" horizontalPageScroll="10" verticalLineScroll="22" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LM9-75-vkc">
<rect key="frame" x="8" y="28" width="329" height="230"/>
<clipView key="contentView" id="Z7L-Ef-90Z">
<rect key="frame" x="0.0" y="0.0" width="329" height="257"/>
<rect key="frame" x="0.0" y="0.0" width="329" height="230"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" rowHeight="20" headerView="85y-4a-860" id="Q0t-hQ-orw">
<rect key="frame" x="0.0" y="0.0" width="329" height="234"/>
<rect key="frame" x="0.0" y="0.0" width="329" height="207"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -199,21 +199,6 @@ CA
<autoresizingMask key="autoresizingMask"/>
</tableHeaderView>
</scrollView>
<searchField toolTip="Search a timezone" wantsLayer="YES" focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="biT-6m-ElR">
<rect key="frame" x="8" y="288" width="283" height="24"/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" focusRingType="none" placeholderString="Enter a city, state, country name" drawsBackground="YES" usesSingleLineMode="YES" id="ijc-z6-99E">
<font key="font" size="13" name="SFUIDisplay-Light"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</searchFieldCell>
<connections>
<binding destination="-2" name="editable" keyPath="self.activityInProgress" id="qG8-46-bev">
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
</dictionary>
</binding>
</connections>
</searchField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KFC-NV-5A3">
<rect key="frame" x="102" y="4" width="230" height="20"/>
<constraints>
@ -225,8 +210,8 @@ CA
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wb6-yr-Pw4">
<rect key="frame" x="11" y="135" width="321" height="20"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Wb6-yr-Pw4">
<rect key="frame" x="11" y="124" width="321" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="QQQ-at-c1H"/>
</constraints>
@ -236,8 +221,8 @@ CA
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="ifx-PO-gfq">
<rect key="frame" x="164" y="160" width="16" height="16"/>
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" misplaced="YES" maxValue="100" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="ifx-PO-gfq">
<rect key="frame" x="164" y="149" width="16" height="16"/>
<connections>
<binding destination="-2" name="hidden" keyPath="self.activityInProgress" id="9pA-XX-dhd">
<dictionary key="options">
@ -280,19 +265,22 @@ CA
</binding>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2ez-Np-rIM">
<rect key="frame" x="288" y="283" width="58" height="32"/>
<buttonCell key="cell" type="push" title="Go" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="sbL-Gc-NTj">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<searchField toolTip="Search a timezone" wantsLayer="YES" focusRingType="none" verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="biT-6m-ElR">
<rect key="frame" x="8" y="288" width="329" height="24"/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" focusRingType="none" placeholderString="Enter a city, state, country name" drawsBackground="YES" usesSingleLineMode="YES" id="ijc-z6-99E">
<font key="font" size="13" name="SFUIDisplay-Light"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</searchFieldCell>
<connections>
<action selector="filterArray:" target="-2" id="KTU-QP-smI"/>
<action selector="filterArray:" target="-2" id="MWr-sX-24E"/>
<binding destination="-2" name="editable" keyPath="self.activityInProgress" id="qG8-46-bev">
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
</dictionary>
</binding>
</connections>
</button>
</searchField>
</subviews>
<constraints>
<constraint firstItem="KFC-NV-5A3" firstAttribute="leading" secondItem="cyZ-cL-S7a" secondAttribute="trailing" constant="4" id="1i8-FW-qYz"/>
@ -300,7 +288,6 @@ DQ
<constraint firstItem="LM9-75-vkc" firstAttribute="top" secondItem="biT-6m-ElR" secondAttribute="bottom" constant="3" id="DZR-XO-6sm"/>
<constraint firstItem="Wb6-yr-Pw4" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="13" id="Ezn-kD-zu1"/>
<constraint firstAttribute="bottom" secondItem="KFC-NV-5A3" secondAttribute="bottom" constant="4" id="FWx-F1-VK8"/>
<constraint firstItem="85y-4a-860" firstAttribute="top" secondItem="2ez-Np-rIM" secondAttribute="bottom" constant="5" id="Gft-hZ-8vM"/>
<constraint firstItem="hp6-CH-WJs" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="8" id="Oir-hL-Og8"/>
<constraint firstItem="Wb6-yr-Pw4" firstAttribute="top" secondItem="ifx-PO-gfq" secondAttribute="bottom" constant="5" id="Pha-iy-RTE"/>
<constraint firstItem="ifx-PO-gfq" firstAttribute="centerX" secondItem="Q0t-hQ-orw" secondAttribute="centerX" id="QOS-0E-N10"/>
@ -308,12 +295,9 @@ DQ
<constraint firstAttribute="trailing" secondItem="Wb6-yr-Pw4" secondAttribute="trailing" constant="15" id="RgE-qx-qrq"/>
<constraint firstItem="biT-6m-ElR" firstAttribute="top" secondItem="kXo-nl-oxR" secondAttribute="top" constant="8" id="Y7N-oR-3KY"/>
<constraint firstItem="LM9-75-vkc" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="8" id="ZJc-ws-AZR"/>
<constraint firstItem="2ez-Np-rIM" firstAttribute="top" secondItem="kXo-nl-oxR" secondAttribute="top" constant="9" id="fdw-te-IzK"/>
<constraint firstItem="cyZ-cL-S7a" firstAttribute="leading" secondItem="hp6-CH-WJs" secondAttribute="trailing" constant="2" id="g8m-TW-fLo"/>
<constraint firstAttribute="bottom" secondItem="hp6-CH-WJs" secondAttribute="bottom" constant="5" id="hEn-h1-my5"/>
<constraint firstItem="2ez-Np-rIM" firstAttribute="leading" secondItem="biT-6m-ElR" secondAttribute="trailing" constant="3" id="hq2-I2-ol4"/>
<constraint firstItem="biT-6m-ElR" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="8" id="nhU-xR-AW2"/>
<constraint firstAttribute="trailing" secondItem="2ez-Np-rIM" secondAttribute="trailing" constant="5" id="p9u-rt-s1o"/>
<constraint firstAttribute="trailing" secondItem="LM9-75-vkc" secondAttribute="trailing" constant="8" id="pMs-Ol-hsh"/>
<constraint firstItem="Wb6-yr-Pw4" firstAttribute="centerY" secondItem="Q0t-hQ-orw" secondAttribute="centerY" id="uio-eQ-cpc"/>
</constraints>

2
Clocker/Preferences/CLPreferencesViewController.h

@ -18,6 +18,8 @@ typedef enum : NSUInteger {
@property (strong, nonatomic) NSMutableArray *selectedTimeZones;
@property (strong, nonatomic) NSMutableArray *filteredArray;
@property (atomic, assign) BOOL launchOnLogin;
@property (nonatomic, strong) NSMutableArray *timeZoneArray;
@property (nonatomic, strong) NSMutableArray *timeZoneFilteredArray;
@property (atomic, strong) NSArray *themes;
@property (nonatomic, strong) NSURLSessionDataTask *dataTask;

231
Clocker/Preferences/CLPreferencesViewController.m

@ -39,12 +39,10 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
@property (weak) IBOutlet NSTableView *timezoneTableView;
@property (strong) IBOutlet Panel *timezonePanel;
@property (weak) IBOutlet NSSegmentedControl *theme;
@property (weak) IBOutlet NSPopUpButton *fontPopUp;
@property (weak) IBOutlet NSTableView *availableTimezoneTableView;
@property (weak) IBOutlet NSSearchField *searchField;
@property (weak) IBOutlet NSSegmentedControl *timeFormat;
@property (weak) IBOutlet NSTextField *messageLabel;
@property (weak) IBOutlet NSSegmentedControl *searchCriteria;
@end
@ -66,7 +64,9 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
if (!self.filteredArray)
{
self.filteredArray = [[NSMutableArray alloc] init];
self.timeZoneArray = [[NSMutableArray alloc] initWithArray:[NSTimeZone knownTimeZoneNames]];
self.timeZoneFilteredArray = [NSMutableArray new];
self.filteredArray = [NSMutableArray new];
}
self.messageLabel.stringValue = CLEmptyString;
@ -101,9 +101,20 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
}
else
{
return self.filteredArray.count;
NSInteger searchCriteria = [self.searchCriteria selectedSegment];
if (searchCriteria == 0) {
return self.filteredArray.count;
}
else
{
if (self.searchField.stringValue.length > 0) {
return self.timeZoneFilteredArray.count;
}
return self.timeZoneArray.count;
}
}
return 0;
}
@ -131,9 +142,27 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
}
else if([[tableColumn identifier] isEqualToString:CLPreferencesAvailableTimezoneIdentifier])
{
if (row < self.filteredArray.count)
NSInteger searchCriteria = [self.searchCriteria selectedSegment];
if (searchCriteria == 0)
{
if (row < self.filteredArray.count)
{
return dataSource.formattedAddress;
}
}
else
{
return dataSource.formattedAddress;
if (self.searchField.stringValue.length > 0)
{
if (row < self.timeZoneFilteredArray.count) {
return self.timeZoneFilteredArray[row];
}
}
return self.timeZoneArray[row];
}
return nil;
@ -142,6 +171,11 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
{
return selectedDataSource.customLabel;
}
else if ([tableColumn.identifier isEqualToString:@"favouriteTimezone"])
{
return selectedDataSource.isFavourite;
}
return nil;
@ -156,18 +190,47 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
NSString *customLabelValue = [originalValue stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSMutableDictionary *timezoneDictionary = self.selectedTimeZones[row];
NSMutableDictionary *mutableTimeZoneDict = [timezoneDictionary mutableCopy];
customLabelValue.length > 0 ? [mutableTimeZoneDict setValue:customLabelValue forKey:CLCustomLabel] : [mutableTimeZoneDict setValue:CLEmptyString forKey:CLCustomLabel];
[self.selectedTimeZones replaceObjectAtIndex:row withObject:mutableTimeZoneDict];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.selectedTimeZones[row]];
dataObject.customLabel = customLabelValue.length > 0 ? customLabelValue : CLEmptyString;
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:dataObject];
[self.selectedTimeZones replaceObjectAtIndex:row withObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:self.selectedTimeZones forKey:CLDefaultPreferenceKey];
[self refreshMainTableview];
}
else
{
NSMutableArray *newArray = [NSMutableArray new];
for (NSData *object in self.selectedTimeZones)
{
CLTimezoneData *timezone = [CLTimezoneData getCustomObject:object];
timezone.isFavourite = [NSNumber numberWithInt:0];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezone];
[newArray addObject:encodedObject];
}
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:newArray[row]];
dataObject.isFavourite = object;
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:dataObject];
[newArray replaceObjectAtIndex:row withObject:encodedObject];
self.selectedTimeZones = [NSMutableArray arrayWithArray:newArray];
[[NSUserDefaults standardUserDefaults] setObject:self.selectedTimeZones forKey:CLDefaultPreferenceKey];
(dataObject.isFavourite.integerValue == 1) ?
[[NSUserDefaults standardUserDefaults] setObject:encodedObject
forKey:@"favouriteTimezone"]:
[[NSUserDefaults standardUserDefaults] setObject:nil
forKey:@"favouriteTimezone"];
[self.timezoneTableView reloadData];
}
}
- (IBAction)addTimeZone:(id)sender
{
self.searchCriteria.selectedSegment = 0;
[self.view.window beginSheet:self.timezonePanel completionHandler:nil];
}
@ -197,33 +260,91 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
return;
}
CLTimezoneData *dataObject = self.filteredArray[self.availableTimezoneTableView.selectedRow];
for (NSData *encodedData in self.selectedTimeZones)
if (self.searchCriteria.selectedSegment == 0)
{
CLTimezoneData *dataObject = self.filteredArray[self.availableTimezoneTableView.selectedRow];
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:encodedData];
NSString *name = timezoneObject.place_id;
NSString *selectedPlaceID = dataObject.place_id;
if (self.searchField.stringValue.length > 0) {
if ([name isKindOfClass:[NSString class]] &&
[name isEqualToString:selectedPlaceID])
{
self.messageLabel.stringValue = CLTimezoneAlreadySelectedError;
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(clearLabel) userInfo:nil
repeats:NO];
self.activityInProgress = NO;
return;
for (NSData *encodedData in self.selectedTimeZones)
{
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:encodedData];
NSString *name = timezoneObject.place_id;
NSString *selectedPlaceID = dataObject.place_id;
if (self.searchField.stringValue.length > 0) {
if ([name isKindOfClass:[NSString class]] &&
[name isEqualToString:selectedPlaceID])
{
self.messageLabel.stringValue = CLTimezoneAlreadySelectedError;
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(clearLabel) userInfo:nil
repeats:NO];
self.activityInProgress = NO;
return;
}
}
}
self.searchField.stringValue = CLEmptyString;
[self getTimeZoneForLatitude:dataObject.latitude
andLongitude:dataObject.longitude];
}
else
{
CLTimezoneData *data = [CLTimezoneData new];
data.isFavourite = [NSNumber numberWithInt:NSOffState];
data.customLabel = CLEmptyString;
if (self.searchField.stringValue.length > 0)
{
data.timezoneID = self.timeZoneFilteredArray[self.availableTimezoneTableView.selectedRow];
data.formattedAddress = self.timeZoneFilteredArray[self.availableTimezoneTableView.selectedRow];
}
else
{
data.timezoneID = self.timeZoneArray[self.availableTimezoneTableView.selectedRow];
data.formattedAddress = self.timeZoneArray[self.availableTimezoneTableView.selectedRow];
}
NSArray *defaultPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey];
if (defaultPreference == nil)
{
defaultPreference = [[NSMutableArray alloc] init];
}
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:data];
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:defaultPreference];
[newArray addObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey];
self.timeZoneArray = [NSMutableArray array];
self.timeZoneFilteredArray = [NSMutableArray array];
[self.availableTimezoneTableView reloadData];
[self refereshTimezoneTableView];
[self refreshMainTableview];
[self.timezonePanel close];
self.placeholderLabel.placeholderString = CLEmptyString;
self.searchField.stringValue = CLEmptyString;
self.searchField.placeholderString = @"Enter a city, state or country name";
self.availableTimezoneTableView.hidden = NO;
self.activityInProgress = NO;
}
self.searchField.stringValue = CLEmptyString;
[self getTimeZoneForLatitude:dataObject.latitude andLongitude:dataObject.longitude];
/*
PFObject *feedbackObject = [PFObject objectWithClassName:CLParseTimezoneSelectionClassIdentifier];
@ -274,6 +395,18 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[self refreshMainTableview];
}
- (IBAction)filterTimezoneArray:(id)sender
{
if (self.searchField.stringValue.length > 0) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:CLSearchPredicateKey, self.searchField.stringValue];
self.timeZoneFilteredArray = [NSMutableArray arrayWithArray:[self.timeZoneArray filteredArrayUsingPredicate:predicate]];
[self.availableTimezoneTableView reloadData];
}
}
- (IBAction)filterArray:(id)sender
{
[self clearLabel];
@ -580,4 +713,38 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
}
- (IBAction)filterSearch:(id)sender
{
if (self.searchCriteria.selectedSegment == 1)
{
if (self.searchField.stringValue.length > 0) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:CLSearchPredicateKey, self.searchField.stringValue];
self.timeZoneFilteredArray = [NSMutableArray arrayWithArray:[self.timeZoneArray filteredArrayUsingPredicate:predicate]];
[self.availableTimezoneTableView reloadData];
}
}
}
- (IBAction)searchOptions:(id)sender
{
if (self.searchCriteria.selectedSegment == 0)
{
self.searchField.placeholderString = @"Enter a city, state or country name";
}
else
{
self.timeZoneArray = [NSMutableArray arrayWithArray:[NSTimeZone knownTimeZoneNames]];
self.searchField.placeholderString = @"Enter a timezone name";
}
self.filteredArray = [NSMutableArray new];
self.searchField.stringValue = CLEmptyString;
[self.availableTimezoneTableView reloadData];
}
@end

2
Clocker/StatusItemView.h

@ -38,7 +38,7 @@
- (id)initWithStatusItem:(NSStatusItem *)statusItem;
@property (nonatomic, strong, readonly) NSStatusItem *statusItem;
@property (nonatomic, strong) NSStatusItem *statusItem;
@property (nonatomic, strong) NSImage *image;
@property (nonatomic, strong) NSImage *alternateImage;
@property (nonatomic, setter = setHighlighted:) BOOL isHighlighted;

65
Clocker/StatusItemView.m

@ -27,6 +27,8 @@
#import "StatusItemView.h"
#import "CommonStrings.h"
#import "CLTimezoneData.h"
@implementation StatusItemView
@ -61,16 +63,48 @@
{
[super drawRect:dirtyRect];
NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, self.frame.size.width, 18)];
textField.bordered = NO;
textField.alignment = NSTextAlignmentCenter;
NSData *dataObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"favouriteTimezone"];
if (dataObject)
{
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:dataObject];
textField.stringValue = [timezoneObject getMenuTitle];
}
else
{
textField.stringValue = @"Icon";
}
[textField sizeToFit];
// Set up dark mode for icon
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] isEqual: @"Dark"])
{
self.image = [NSImage imageNamed:@"StatusHighlighted"];
textField.backgroundColor = [NSColor whiteColor];
textField.textColor = [NSColor blackColor];
self.image = [self imageWithSubviewsWithTextField:textField];
}
else
{
self.image = self.isHighlighted ? [NSImage imageNamed:@"StatusHighlighted"] : [NSImage imageNamed:@"Status"];
{
textField.backgroundColor = [NSColor blackColor];
textField.textColor = [NSColor whiteColor];
self.image = [self imageWithSubviewsWithTextField:textField];
}
[self.statusItem drawStatusBarBackgroundInRect:dirtyRect withHighlight:self.isHighlighted];
NSDisableScreenUpdates();
[self.statusItem setLength:textField.frame.size.width+10];
NSEnableScreenUpdates();
CGRect newRect = CGRectMake(dirtyRect.origin.x, dirtyRect.origin.y, textField.frame.size.width+5, dirtyRect.size.height);
[self.statusItem drawStatusBarBackgroundInRect:newRect withHighlight:NO];
NSImage *icon = self.image;
NSSize iconSize = [icon size];
@ -79,9 +113,30 @@
CGFloat iconY = roundf((NSHeight(bounds) - iconSize.height) / 2);
NSPoint iconPoint = NSMakePoint(iconX, iconY);
[icon drawAtPoint:iconPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[icon drawAtPoint:iconPoint fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
}
- (NSImage *)imageWithSubviewsWithTextField:(NSTextField *)textField
{
NSSize mySize = textField.bounds.size;
NSSize imgSize = NSMakeSize( mySize.width, mySize.height );
NSBitmapImageRep *bir = [textField bitmapImageRepForCachingDisplayInRect:[textField bounds]];
[bir setSize:imgSize];
[textField cacheDisplayInRect:[textField bounds] toBitmapImageRep:bir];
NSImage* image = [[NSImage alloc]initWithSize:imgSize];
[image addRepresentation:bir];
return image;
}
#pragma mark -
#pragma mark Mouse tracking

4
Clocker/Utilities/CommonStrings.h

@ -21,7 +21,9 @@ extern NSString *const CLTimezoneID;
extern NSString *const CLPlaceIdentifier;
extern NSString *const CLRelativeDateKey;
extern NSString *const CLThemeKey;
extern NSString *const CLDisplaySunTimingKey;
extern NSString *const CLShowDayInMenu;
extern NSString *const CLShowDateInMenu;
extern NSString *const CLShowCityInMenu;
extern NSString *const CLDisplayFutureSliderKey;
@end

4
Clocker/Utilities/CommonStrings.m

@ -21,7 +21,9 @@ NSString *const CLDragSessionKey = @"public.text";
NSString *const CLCustomLabelChangedNotification = @"CLCustomLabelChangedNotification";
NSString *const CLRelativeDateKey = @"relativeDate";
NSString *const CLThemeKey = @"defaultTheme";
NSString *const CLDisplaySunTimingKey = @"displaySuntime";
NSString *const CLDisplayFutureSliderKey = @"displayFutureSlider";
NSString *const CLShowDayInMenu = @"showDay";
NSString *const CLShowDateInMenu = @"showDate";
NSString *const CLShowCityInMenu = @"showCityName";
@end

Loading…
Cancel
Save