Browse Source

Finished code for Pref Window. Included Circular Progress Indicator. Removed Autolayout for Prefs XIB, no more warnings. Added Reddit API class structure.

Thomas Buck 10 years ago
parent
commit
78f73fd7eb

+ 6
- 0
RedditBar.xcodeproj/project.pbxproj View File

@@ -9,6 +9,7 @@
9 9
 /* Begin PBXBuildFile section */
10 10
 		E9341914184A1A1A00D03488 /* StateModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E9341913184A1A1A00D03488 /* StateModel.m */; };
11 11
 		E934191B184A47DE00D03488 /* Prefs.xib in Resources */ = {isa = PBXBuildFile; fileRef = E9341919184A47DE00D03488 /* Prefs.xib */; };
12
+		E9B6773E184B73DC00850559 /* Reddit.m in Sources */ = {isa = PBXBuildFile; fileRef = E9B6773D184B73DC00850559 /* Reddit.m */; };
12 13
 		E9CF1F21184961010004AE02 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E9CF1F20184961010004AE02 /* Cocoa.framework */; };
13 14
 		E9CF1F2B184961010004AE02 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E9CF1F29184961010004AE02 /* InfoPlist.strings */; };
14 15
 		E9CF1F2D184961010004AE02 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E9CF1F2C184961010004AE02 /* main.m */; };
@@ -39,6 +40,8 @@
39 40
 		E9341912184A1A1A00D03488 /* StateModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StateModel.h; sourceTree = "<group>"; };
40 41
 		E9341913184A1A1A00D03488 /* StateModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StateModel.m; sourceTree = "<group>"; };
41 42
 		E934191A184A47DE00D03488 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Prefs.xib; sourceTree = "<group>"; };
43
+		E9B6773C184B73DC00850559 /* Reddit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reddit.h; sourceTree = "<group>"; };
44
+		E9B6773D184B73DC00850559 /* Reddit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reddit.m; sourceTree = "<group>"; };
42 45
 		E9CF1F1D184961010004AE02 /* RedditBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RedditBar.app; sourceTree = BUILT_PRODUCTS_DIR; };
43 46
 		E9CF1F20184961010004AE02 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
44 47
 		E9CF1F23184961010004AE02 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -131,6 +134,8 @@
131 134
 				E9CF1F551849654F0004AE02 /* icon.png */,
132 135
 				E9CF1F32184961010004AE02 /* AppDelegate.h */,
133 136
 				E9CF1F33184961010004AE02 /* AppDelegate.m */,
137
+				E9B6773C184B73DC00850559 /* Reddit.h */,
138
+				E9B6773D184B73DC00850559 /* Reddit.m */,
134 139
 				E9341912184A1A1A00D03488 /* StateModel.h */,
135 140
 				E9341913184A1A1A00D03488 /* StateModel.m */,
136 141
 				E9CF1F35184961020004AE02 /* MainMenu.xib */,
@@ -295,6 +300,7 @@
295 300
 				E9341914184A1A1A00D03488 /* StateModel.m in Sources */,
296 301
 				E9CF1F2D184961010004AE02 /* main.m in Sources */,
297 302
 				E9CF1F5C1849685C0004AE02 /* PrefController.m in Sources */,
303
+				E9B6773E184B73DC00850559 /* Reddit.m in Sources */,
298 304
 			);
299 305
 			runOnlyForDeploymentPostprocessing = 0;
300 306
 		};

+ 2
- 0
RedditBar/AppDelegate.h View File

@@ -9,6 +9,7 @@
9 9
 #import <Cocoa/Cocoa.h>
10 10
 #import "PrefController.h"
11 11
 #import "StateModel.h"
12
+#import "Reddit.h"
12 13
 
13 14
 @interface AppDelegate : NSObject <NSApplicationDelegate>
14 15
 
@@ -20,6 +21,7 @@
20 21
 @property (atomic, retain) NSImage *statusHighlightImage;
21 22
 @property (atomic, retain) PrefController *prefWindow;
22 23
 @property (atomic, retain) StateModel *currentState;
24
+@property (atomic, retain) Reddit *api;
23 25
 
24 26
 -(IBAction)showPreferences:(id)sender;
25 27
 -(IBAction)showAbout:(id)sender;

+ 21
- 21
RedditBar/AppDelegate.m View File

@@ -10,7 +10,23 @@
10 10
 
11 11
 @implementation AppDelegate
12 12
 
13
-@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, prefWindow, currentState, application;
13
+@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, prefWindow, currentState, application, api;
14
+
15
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
16
+    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
17
+    NSBundle *bundle = [NSBundle mainBundle];
18
+    statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
19
+    statusHighlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon-alt" ofType:@"png"]];
20
+    [statusItem setImage:statusImage];
21
+    [statusItem setAlternateImage:statusHighlightImage];
22
+    [statusItem setMenu:statusMenu];
23
+    [statusItem setToolTip:@"Reddit Bar"];
24
+    [statusItem setHighlightMode:YES];
25
+    currentState = [[StateModel alloc] init];
26
+    [self defaultPreferences];
27
+    [self loadPreferences];
28
+    [self reloadListWithOptions];
29
+}
14 30
 
15 31
 -(void)defaultPreferences {
16 32
     NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
@@ -41,23 +57,9 @@
41 57
     [currentState setLength:[store integerForKey:@"length"]];
42 58
 }
43 59
 
44
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
45
-    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
46
-    NSBundle *bundle = [NSBundle mainBundle];
47
-    statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon" ofType:@"png"]];
48
-    statusHighlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"icon-alt" ofType:@"png"]];
49
-    [statusItem setImage:statusImage];
50
-    [statusItem setAlternateImage:statusHighlightImage];
51
-    [statusItem setMenu:statusMenu];
52
-    [statusItem setToolTip:@"Reddit Bar"];
53
-    [statusItem setHighlightMode:YES];
60
+-(void)reloadListWithOptions {
61
+    api = [[Reddit alloc] initWithUsername:currentState.username Modhash:currentState.modhash];
54 62
     
55
-    [self defaultPreferences];
56
-    currentState = [[StateModel alloc] init];
57
-    [self loadPreferences]; // Fill currentState
58
-    
59
-    // TODO apply currentState
60
-    // TODO reload menu list
61 63
 }
62 64
 
63 65
 -(IBAction)showPreferences:(id)sender {
@@ -79,10 +81,8 @@
79 81
     currentState.useSubsciptions = subscriptions;
80 82
     currentState.subreddits = [subreddits componentsSeparatedByString: @"\n"];
81 83
     currentState.length = length;
82
-    [self savePreferences]; // write currentState
83
-    
84
-    // TODO apply currentState
85
-    // TODO reload menu list
84
+    [self savePreferences];
85
+    [self reloadListWithOptions];
86 86
 }
87 87
 
88 88
 @end

+ 24
- 67
RedditBar/Base.lproj/Prefs.xib View File

@@ -1,5 +1,5 @@
1 1
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
3 3
     <dependencies>
4 4
         <deployment defaultVersion="1080" identifier="macosx"/>
5 5
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
@@ -11,6 +11,7 @@
11 11
                 <outlet property="lengthFormat" destination="zpc-oG-upp" id="AKk-rK-pM3"/>
12 12
                 <outlet property="lengthStepper" destination="jxz-fQ-M1L" id="NK5-G4-9UJ"/>
13 13
                 <outlet property="password" destination="ARP-lb-J16" id="EDd-om-ciF"/>
14
+                <outlet property="progress" destination="vz0-tR-n1f" id="t06-dO-WKY"/>
14 15
                 <outlet property="subreddits" destination="EhP-FS-8dT" id="td1-kv-jQm"/>
15 16
                 <outlet property="subscriptions" destination="vW5-Cp-Bm1" id="gja-K0-7Uh"/>
16 17
                 <outlet property="username" destination="0mi-88-o94" id="4bB-K2-q5m"/>
@@ -19,7 +20,7 @@
19 20
         </customObject>
20 21
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
21 22
         <customObject id="-3" userLabel="Application"/>
22
-        <window title="Reddit Bar Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" animationBehavior="default" id="1">
23
+        <window title="RedditBar Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" animationBehavior="default" id="1">
23 24
             <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
24 25
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
25 26
             <rect key="contentRect" x="196" y="240" width="340" height="339"/>
@@ -28,7 +29,7 @@
28 29
                 <rect key="frame" x="0.0" y="0.0" width="340" height="339"/>
29 30
                 <autoresizingMask key="autoresizingMask"/>
30 31
                 <subviews>
31
-                    <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0mi-88-o94">
32
+                    <textField verticalHuggingPriority="750" id="0mi-88-o94">
32 33
                         <rect key="frame" x="120" y="299" width="200" height="22"/>
33 34
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
34 35
                         <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="xlI-hU-MqM">
@@ -37,19 +38,16 @@
37 38
                             <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
38 39
                         </textFieldCell>
39 40
                     </textField>
40
-                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="f72-fM-yQc">
41
-                        <rect key="frame" x="18" y="302" width="96" height="17"/>
41
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="f72-fM-yQc">
42
+                        <rect key="frame" x="18" y="304" width="96" height="17"/>
42 43
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
43
-                        <constraints>
44
-                            <constraint firstAttribute="width" constant="92" id="NaA-TF-vqk"/>
45
-                        </constraints>
46 44
                         <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Username: " id="GTO-OP-MYS">
47 45
                             <font key="font" metaFont="system"/>
48 46
                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
49 47
                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
50 48
                         </textFieldCell>
51 49
                     </textField>
52
-                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JMQ-a6-DKC">
50
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="JMQ-a6-DKC">
53 51
                         <rect key="frame" x="18" y="270" width="96" height="17"/>
54 52
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
55 53
                         <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Password:" id="m11-YF-fEa">
@@ -58,19 +56,16 @@
58 56
                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
59 57
                         </textFieldCell>
60 58
                     </textField>
61
-                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="qFP-pd-32c">
62
-                        <rect key="frame" x="6" y="52" width="96" height="17"/>
59
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="qFP-pd-32c">
60
+                        <rect key="frame" x="18" y="52" width="96" height="17"/>
63 61
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
64
-                        <constraints>
65
-                            <constraint firstAttribute="width" constant="92" id="y5l-ux-awZ"/>
66
-                        </constraints>
67 62
                         <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Items:" id="FNJ-RL-DXT">
68 63
                             <font key="font" metaFont="system"/>
69 64
                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
70 65
                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
71 66
                         </textFieldCell>
72 67
                     </textField>
73
-                    <secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ARP-lb-J16">
68
+                    <secureTextField verticalHuggingPriority="750" id="ARP-lb-J16">
74 69
                         <rect key="frame" x="120" y="267" width="200" height="22"/>
75 70
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
76 71
                         <secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="We7-pG-rAt">
@@ -82,12 +77,9 @@
82 77
                             </allowedInputSourceLocales>
83 78
                         </secureTextFieldCell>
84 79
                     </secureTextField>
85
-                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="qwZ-cF-1JN">
80
+                    <button verticalHuggingPriority="750" id="qwZ-cF-1JN">
86 81
                         <rect key="frame" x="224" y="13" width="102" height="32"/>
87 82
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
88
-                        <constraints>
89
-                            <constraint firstAttribute="width" constant="90" id="6O3-yW-gA0"/>
90
-                        </constraints>
91 83
                         <buttonCell key="cell" type="push" title="Save" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Mqa-FJ-C43">
92 84
                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
93 85
                             <font key="font" metaFont="system"/>
@@ -96,12 +88,9 @@
96 88
                             <action selector="buttonSave:" target="-2" id="thy-nQ-Nld"/>
97 89
                         </connections>
98 90
                     </button>
99
-                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vO2-NN-i1n">
91
+                    <button verticalHuggingPriority="750" id="vO2-NN-i1n">
100 92
                         <rect key="frame" x="14" y="13" width="102" height="32"/>
101 93
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
102
-                        <constraints>
103
-                            <constraint firstAttribute="width" constant="90" id="ZXJ-Cb-INd"/>
104
-                        </constraints>
105 94
                         <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="TjO-Z6-Vng">
106 95
                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
107 96
                             <font key="font" metaFont="system"/>
@@ -113,7 +102,7 @@ Gw
113 102
                             <action selector="performClose:" target="1" id="A62-EW-ZrT"/>
114 103
                         </connections>
115 104
                     </button>
116
-                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="R9P-ZH-hHZ">
105
+                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="R9P-ZH-hHZ">
117 106
                         <rect key="frame" x="18" y="235" width="96" height="17"/>
118 107
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
119 108
                         <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Subreddits:" id="Cmr-7n-CaG">
@@ -122,8 +111,8 @@ Gw
122 111
                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
123 112
                         </textFieldCell>
124 113
                     </textField>
125
-                    <scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8ew-wY-1Yh">
126
-                        <rect key="frame" x="20" y="77" width="300" height="150"/>
114
+                    <scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="8ew-wY-1Yh">
115
+                        <rect key="frame" x="20" y="79" width="300" height="150"/>
127 116
                         <autoresizingMask key="autoresizingMask"/>
128 117
                         <clipView key="contentView" copiesOnScroll="NO" id="ENU-Jw-8fO">
129 118
                             <rect key="frame" x="1" y="1" width="298" height="148"/>
@@ -151,7 +140,7 @@ Gw
151 140
                             <autoresizingMask key="autoresizingMask"/>
152 141
                         </scroller>
153 142
                     </scrollView>
154
-                    <button translatesAutoresizingMaskIntoConstraints="NO" id="XZM-90-hQ8">
143
+                    <button id="XZM-90-hQ8">
155 144
                         <rect key="frame" x="118" y="234" width="204" height="18"/>
156 145
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
157 146
                         <buttonCell key="cell" type="check" title="Subscriptions" bezelStyle="regularSquare" imagePosition="overlaps" alignment="right" state="on" inset="2" id="vW5-Cp-Bm1">
@@ -162,12 +151,9 @@ Gw
162 151
                             <action selector="toggleSubs:" target="-2" id="TPd-6W-xQv"/>
163 152
                         </connections>
164 153
                     </button>
165
-                    <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="MAv-jO-hIv">
166
-                        <rect key="frame" x="120" y="49" width="96" height="22"/>
154
+                    <textField verticalHuggingPriority="750" id="MAv-jO-hIv">
155
+                        <rect key="frame" x="120" y="49" width="57" height="22"/>
167 156
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
168
-                        <constraints>
169
-                            <constraint firstAttribute="width" constant="96" id="Q7V-Gm-EfI"/>
170
-                        </constraints>
171 157
                         <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" alignment="right" title="10" drawsBackground="YES" id="0SD-Tf-uZS">
172 158
                             <font key="font" metaFont="system"/>
173 159
                             <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@@ -178,48 +164,19 @@ Gw
178 164
                             <outlet property="formatter" destination="zpc-oG-upp" id="cw1-hM-34K"/>
179 165
                         </connections>
180 166
                     </textField>
181
-                    <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jxz-fQ-M1L">
182
-                        <rect key="frame" x="221" y="46" width="19" height="27"/>
167
+                    <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" id="jxz-fQ-M1L">
168
+                        <rect key="frame" x="182" y="46" width="19" height="27"/>
183 169
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
184 170
                         <stepperCell key="cell" continuous="YES" alignment="left" maxValue="100" id="Gba-jV-Ouh"/>
185 171
                         <connections>
186 172
                             <action selector="lengthDidChange:" target="-2" id="CJm-58-seM"/>
187 173
                         </connections>
188 174
                     </stepper>
175
+                    <progressIndicator canDrawConcurrently="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" id="vz0-tR-n1f">
176
+                        <rect key="frame" x="267" y="49" width="16" height="16"/>
177
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
178
+                    </progressIndicator>
189 179
                 </subviews>
190
-                <constraints>
191
-                    <constraint firstItem="f72-fM-yQc" firstAttribute="top" secondItem="2" secondAttribute="top" constant="20" symbolic="YES" id="29D-Aw-Hsq"/>
192
-                    <constraint firstItem="R9P-ZH-hHZ" firstAttribute="leading" secondItem="JMQ-a6-DKC" secondAttribute="leading" id="37a-j4-cea"/>
193
-                    <constraint firstItem="qFP-pd-32c" firstAttribute="centerY" secondItem="jxz-fQ-M1L" secondAttribute="centerY" id="7Cf-YA-CG9"/>
194
-                    <constraint firstItem="XZM-90-hQ8" firstAttribute="trailing" secondItem="ARP-lb-J16" secondAttribute="trailing" id="7Na-cW-VbT"/>
195
-                    <constraint firstItem="8ew-wY-1Yh" firstAttribute="trailing" secondItem="XZM-90-hQ8" secondAttribute="trailing" id="7bq-Le-SlA"/>
196
-                    <constraint firstItem="qFP-pd-32c" firstAttribute="top" secondItem="8ew-wY-1Yh" secondAttribute="bottom" constant="8" symbolic="YES" id="7uB-Kt-r8c"/>
197
-                    <constraint firstItem="ARP-lb-J16" firstAttribute="leading" secondItem="JMQ-a6-DKC" secondAttribute="trailing" constant="8" symbolic="YES" id="ANm-KU-ah0"/>
198
-                    <constraint firstItem="qFP-pd-32c" firstAttribute="centerY" secondItem="MAv-jO-hIv" secondAttribute="centerY" id="C6t-id-Y7F"/>
199
-                    <constraint firstItem="0mi-88-o94" firstAttribute="leading" secondItem="f72-fM-yQc" secondAttribute="trailing" constant="8" symbolic="YES" id="DeX-3f-5VX"/>
200
-                    <constraint firstItem="R9P-ZH-hHZ" firstAttribute="baseline" secondItem="XZM-90-hQ8" secondAttribute="baseline" id="Dyr-Lq-Ctl"/>
201
-                    <constraint firstItem="vO2-NN-i1n" firstAttribute="baseline" secondItem="qwZ-cF-1JN" secondAttribute="baseline" id="Ess-AZ-MVK"/>
202
-                    <constraint firstItem="R9P-ZH-hHZ" firstAttribute="leading" secondItem="8ew-wY-1Yh" secondAttribute="leading" id="G3T-Ry-7uZ"/>
203
-                    <constraint firstItem="vO2-NN-i1n" firstAttribute="leading" secondItem="8ew-wY-1Yh" secondAttribute="leading" id="IsT-wH-jxK"/>
204
-                    <constraint firstAttribute="trailing" secondItem="0mi-88-o94" secondAttribute="trailing" constant="20" symbolic="YES" id="LZn-1N-eno"/>
205
-                    <constraint firstItem="f72-fM-yQc" firstAttribute="centerY" secondItem="0mi-88-o94" secondAttribute="centerY" id="LfD-Yu-zn8"/>
206
-                    <constraint firstItem="ARP-lb-J16" firstAttribute="leading" secondItem="0mi-88-o94" secondAttribute="leading" id="OYT-lx-Poi"/>
207
-                    <constraint firstItem="f72-fM-yQc" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="20" symbolic="YES" id="OiS-Rj-NBY"/>
208
-                    <constraint firstItem="XZM-90-hQ8" firstAttribute="leading" secondItem="R9P-ZH-hHZ" secondAttribute="trailing" constant="8" symbolic="YES" id="VL7-JL-apE"/>
209
-                    <constraint firstItem="vO2-NN-i1n" firstAttribute="top" secondItem="qFP-pd-32c" secondAttribute="bottom" constant="11" id="VdU-PT-I2v"/>
210
-                    <constraint firstItem="ARP-lb-J16" firstAttribute="leading" secondItem="XZM-90-hQ8" secondAttribute="leading" id="Vre-Lj-q0h"/>
211
-                    <constraint firstItem="jxz-fQ-M1L" firstAttribute="leading" secondItem="MAv-jO-hIv" secondAttribute="trailing" constant="8" symbolic="YES" id="Zpj-hy-F01"/>
212
-                    <constraint firstItem="ARP-lb-J16" firstAttribute="top" secondItem="0mi-88-o94" secondAttribute="bottom" constant="10" symbolic="YES" id="bI0-EE-Uau"/>
213
-                    <constraint firstItem="qFP-pd-32c" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="8" id="cqi-Wn-sxQ"/>
214
-                    <constraint firstItem="f72-fM-yQc" firstAttribute="leading" secondItem="JMQ-a6-DKC" secondAttribute="leading" id="fRq-oc-Xhi"/>
215
-                    <constraint firstItem="8ew-wY-1Yh" firstAttribute="top" secondItem="R9P-ZH-hHZ" secondAttribute="bottom" constant="8" symbolic="YES" id="fxf-FX-XZd"/>
216
-                    <constraint firstItem="8ew-wY-1Yh" firstAttribute="trailing" secondItem="qwZ-cF-1JN" secondAttribute="trailing" id="gAk-07-mMq"/>
217
-                    <constraint firstItem="MAv-jO-hIv" firstAttribute="leading" secondItem="qFP-pd-32c" secondAttribute="trailing" constant="20" id="hJP-mL-zrr"/>
218
-                    <constraint firstItem="XZM-90-hQ8" firstAttribute="top" secondItem="ARP-lb-J16" secondAttribute="bottom" constant="17" id="hf0-Vf-fvN"/>
219
-                    <constraint firstItem="JMQ-a6-DKC" firstAttribute="centerY" secondItem="ARP-lb-J16" secondAttribute="centerY" id="pYP-d0-eKw"/>
220
-                    <constraint firstItem="0mi-88-o94" firstAttribute="trailing" secondItem="ARP-lb-J16" secondAttribute="trailing" id="qtc-EY-7HS"/>
221
-                    <constraint firstAttribute="bottom" secondItem="vO2-NN-i1n" secondAttribute="bottom" constant="20" symbolic="YES" id="ynT-D2-t44"/>
222
-                </constraints>
223 180
             </view>
224 181
         </window>
225 182
         <numberFormatter formatterBehavior="10_0" positiveFormat="0" negativeFormat="-0" hasThousandSeparators="NO" thousandSeparator="," id="zpc-oG-upp">

+ 1
- 0
RedditBar/PrefController.h View File

@@ -19,6 +19,7 @@
19 19
 @property (atomic, retain) IBOutlet NSNumberFormatter *lengthFormat;
20 20
 @property (atomic, retain) IBOutlet NSTextField *lengthField;
21 21
 @property (atomic, retain) IBOutlet NSStepper *lengthStepper;
22
+@property (atomic, retain) IBOutlet NSProgressIndicator *progress;
22 23
 @property (atomic, retain) NSObject *parent;
23 24
 @property (atomic, retain) StateModel *state;
24 25
 @property (atomic) NSInteger length;

+ 17
- 8
RedditBar/PrefController.m View File

@@ -12,11 +12,12 @@
12 12
 @implementation PrefController
13 13
 
14 14
 NSString *modhashSetLiteral = @"__MODHASH__IS__SET__";
15
+NSString *subredditCharacters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_\n";
15 16
 
16
-@synthesize username, password, subscriptions, subreddits, win, parent, state, lengthFormat, lengthField, lengthStepper, length;
17
+@synthesize username, password, subscriptions, subreddits, win, parent, state, lengthFormat, lengthField, lengthStepper, length, progress;
17 18
 
18 19
 -(Boolean)isValidList:(NSString *)input {
19
-    NSCharacterSet *invalidChars = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_\n"] invertedSet];
20
+    NSCharacterSet *invalidChars = [[NSCharacterSet characterSetWithCharactersInString:subredditCharacters] invertedSet];
20 21
     if ([input rangeOfCharacterFromSet:invalidChars].location != NSNotFound) {
21 22
         return FALSE;
22 23
     } else {
@@ -26,16 +27,12 @@ NSString *modhashSetLiteral = @"__MODHASH__IS__SET__";
26 27
 
27 28
 -(void)showWindow:(id)sender {
28 29
     [super showWindow:sender];
29
-    
30 30
     [username setStringValue:state.username];
31
-    
32 31
     if (![state.modhash isEqualToString:@""]) {
33 32
         [password setStringValue:modhashSetLiteral];
34 33
     }
35
-    
36 34
     [subscriptions setState:[NSNumber numberWithBool:state.useSubsciptions].integerValue];
37 35
     [self toggleSubs:nil]; // Maybe the subreddits field needs to be editable
38
-    
39 36
     NSMutableString *reddits = [[NSMutableString alloc] init];
40 37
     for(int i = 0; i < [state.subreddits count]; i++) {
41 38
         if (![[state.subreddits objectAtIndex:i] isEqualToString:@""])
@@ -45,6 +42,7 @@ NSString *modhashSetLiteral = @"__MODHASH__IS__SET__";
45 42
     length = state.length;
46 43
     [lengthStepper setIntegerValue:length];
47 44
     [lengthField setIntegerValue:length];
45
+    [progress setUsesThreadedAnimation:YES];
48 46
 }
49 47
 
50 48
 -(IBAction)buttonSave:(id)sender {
@@ -70,8 +68,19 @@ NSString *modhashSetLiteral = @"__MODHASH__IS__SET__";
70 68
     
71 69
     NSString *modhash = state.modhash;
72 70
     if (![password.stringValue isEqualToString:modhashSetLiteral]) {
73
-        // TODO reauthenticate & get modhash from reddit
74
-        
71
+        [progress startAnimation:self];
72
+        Reddit *api = [[Reddit alloc] initWithUsername:username.stringValue Password:password.stringValue];
73
+        modhash = [api queryModhash];
74
+        [progress stopAnimation:self];
75
+        if ((modhash == nil) || ([modhash isEqualToString:@""])) {
76
+            NSAlert *alert = [[NSAlert alloc] init];
77
+            [alert addButtonWithTitle:@"OK"];
78
+            [alert setMessageText:@"Authentication Error"];
79
+            [alert setInformativeText:@"Wrong Username or Password!"];
80
+            [alert setAlertStyle:NSCriticalAlertStyle];
81
+            [alert beginSheetModalForWindow:win modalDelegate:nil didEndSelector:nil contextInfo:nil];
82
+            return;
83
+        }
75 84
     }
76 85
     
77 86
     Boolean subs;

+ 23
- 0
RedditBar/Reddit.h View File

@@ -0,0 +1,23 @@
1
+//
2
+//  Reddit.h
3
+//  RedditBar
4
+//
5
+//  Created by Thomas Buck on 01.12.13.
6
+//  Copyright (c) 2013 xythobuz. All rights reserved.
7
+//
8
+
9
+#import <Foundation/Foundation.h>
10
+
11
+@interface Reddit : NSObject
12
+
13
+@property (atomic, retain) NSString *username;
14
+@property (atomic, retain) NSString *modhash;
15
+@property (atomic, retain) NSString *password;
16
+
17
+-(id)initWithUsername:(NSString *)name Password:(NSString *)pass;
18
+-(NSString *)queryModhash;
19
+
20
+-(id)initWithUsername:(NSString *)name Modhash:(NSString *)hash;
21
+-(BOOL)isAuthenticated;
22
+
23
+@end

+ 44
- 0
RedditBar/Reddit.m View File

@@ -0,0 +1,44 @@
1
+//
2
+//  Reddit.m
3
+//  RedditBar
4
+//
5
+//  Created by Thomas Buck on 01.12.13.
6
+//  Copyright (c) 2013 xythobuz. All rights reserved.
7
+//
8
+
9
+#import "Reddit.h"
10
+
11
+@implementation Reddit
12
+
13
+@synthesize username, modhash, password;
14
+
15
+-(id)initWithUsername:(NSString *)name Modhash:(NSString *)hash {
16
+    self = [super init];
17
+    if (self) {
18
+        username = name;
19
+        modhash = hash;
20
+        password = nil;
21
+    }
22
+    return self;
23
+}
24
+
25
+-(id)initWithUsername:(NSString *)name Password:(NSString *)pass {
26
+    self = [super init];
27
+    if (self) {
28
+        username = name;
29
+        modhash = nil;
30
+        password = pass;
31
+    }
32
+    return self;
33
+}
34
+
35
+-(NSString *)queryModhash {
36
+    sleep(1);
37
+    return nil;
38
+}
39
+
40
+-(BOOL)isAuthenticated {
41
+    return FALSE;
42
+}
43
+
44
+@end

+ 1
- 1
RedditBar/RedditBar-Info.plist View File

@@ -21,7 +21,7 @@
21 21
 	<key>CFBundleSignature</key>
22 22
 	<string>????</string>
23 23
 	<key>CFBundleVersion</key>
24
-	<string>42</string>
24
+	<string>82</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

+ 3
- 1
RedditBar/en.lproj/Credits.rtf View File

@@ -18,4 +18,6 @@
18 18
 \b Inspired by:
19 19
 \b0 \
20 20
 	HackerBar App ({\field{\*\fldinst{HYPERLINK "http://hackerbarapp.com"}}{\fldrslt http://hackerbarapp.com}})\
21
-}
21
+	is Open Source software but requires\
22
+	a RubyMotion License, so I decided\
23
+	against forking it.}

Loading…
Cancel
Save