Sfoglia il codice sorgente

Finished PM functionality. Bumped Version to 1.2.0

Thomas Buck 11 anni fa
parent
commit
59fd20bcaa

+ 6
- 3
RedditBar/AppDelegate.h Vedi File

@@ -36,6 +36,8 @@
36 36
 @property (atomic, retain) IBOutlet NSMenu *statusMenu;
37 37
 @property (atomic, retain) IBOutlet NSApplication *application;
38 38
 @property (atomic, retain) IBOutlet NSMenuItem *firstMenuItem;
39
+@property (atomic, retain) IBOutlet NSMenuItem *PMItem;
40
+@property (atomic, retain) IBOutlet NSMenuItem *PMSeparator;
39 41
 
40 42
 @property (atomic, retain) NSStatusItem *statusItem;
41 43
 @property (atomic, retain) NSImage *statusImage;
@@ -52,16 +54,17 @@
52 54
 
53 55
 -(IBAction)showPreferences:(id)sender;
54 56
 -(IBAction)showAbout:(id)sender;
55
-- (IBAction)reloadCompleteList:(id)sender;
56
-- (IBAction)reloadNextList:(id)sender;
57
+-(IBAction)reloadCompleteList:(id)sender;
58
+-(IBAction)reloadNextList:(id)sender;
57 59
 -(IBAction)linkToOpen:(id)sender;
60
+-(IBAction)openUnread:(id)sender;
58 61
 
59 62
 -(void)reloadListWithOptions;
60 63
 -(void)reloadListIsAuthenticatedCallback;
61 64
 -(void)reloadListNotAuthenticatedCallback;
62 65
 -(void)reloadListHasSubredditsCallback:(NSArray *)items;
63 66
 -(void)reloadListHasFrontpageCallback:(NSArray *)items;
64
--(void)readPMsCallback:(NSArray *)items;
67
+-(void)readPMsCallback:(NSNumber *)items;
65 68
 
66 69
 -(void)prefReturnName:(NSString *)name Modhash:(NSString *)modhash subscriptions:(Boolean)subscriptions subreddits:(NSString *)subreddits length:(NSInteger)length printSubs:(Boolean)showSubreddits titleLength:(NSInteger)titleLength refresh:(NSInteger)refreshInterval;
67 70
 

+ 14
- 5
RedditBar/AppDelegate.m Vedi File

@@ -30,7 +30,7 @@
30 30
 
31 31
 @implementation AppDelegate
32 32
 
33
-@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, orangeredImage, orangeredHighlightImage, prefWindow, currentState, application, api, firstMenuItem, menuItems, redditItems, lastFullName, refreshTimer;
33
+@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, orangeredImage, orangeredHighlightImage, prefWindow, currentState, application, api, firstMenuItem, menuItems, redditItems, lastFullName, refreshTimer, PMItem, PMSeparator;
34 34
 
35 35
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
36 36
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
@@ -63,14 +63,18 @@
63 63
     [NSThread detachNewThreadSelector:@selector(readPMs:) toTarget:api withObject:self];
64 64
 }
65 65
 
66
--(void)readPMsCallback:(NSArray *)items {
67
-    if (items == nil) {
66
+-(void)readPMsCallback:(NSNumber *)items {
67
+    if ((items == nil) || ([items integerValue] == 0)) {
68 68
         [statusItem setImage:statusImage];
69 69
         [statusItem setAlternateImage:statusHighlightImage];
70
+        [PMItem setHidden:TRUE];
71
+        [PMSeparator setHidden:TRUE];
70 72
     } else {
71 73
         [statusItem setImage:orangeredImage];
72 74
         [statusItem setAlternateImage:orangeredHighlightImage];
73
-        // TODO put PMs in menu?!
75
+        [PMItem setTitle:[NSString stringWithFormat:NSLocalizedString(@"You've got %ld unread PMs!", @"PM message"), (long)items.integerValue]];
76
+        [PMItem setHidden:FALSE];
77
+        [PMSeparator setHidden:FALSE];
74 78
     }
75 79
 }
76 80
 
@@ -175,6 +179,11 @@
175 179
     }
176 180
 }
177 181
 
182
+-(IBAction)openUnread:(id)sender {
183
+    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.reddit.com/message/unread"]];
184
+    [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(refreshTick:) userInfo:nil repeats:NO];
185
+}
186
+
178 187
 -(void)clearMenuItems {
179 188
     if (menuItems != nil) {
180 189
         for (NSUInteger i = 0; i < [menuItems count]; i++) {
@@ -189,7 +198,7 @@
189 198
     for (NSUInteger i = 0; i < [array count]; i++) {
190 199
         NSMenuItem *item = [self prepareItemForMenu:[array objectAtIndex:i]];
191 200
         [items addObject:item];
192
-        [statusMenu insertItem:item atIndex:i];
201
+        [statusMenu insertItem:item atIndex:(i + 2)];
193 202
     }
194 203
     menuItems = items;
195 204
 }

+ 3
- 0
RedditBar/Base.lproj/MainMenu.strings Vedi File

@@ -5,6 +5,9 @@
5 5
 /* Class = "NSMenuItem"; title = "About RedditBar"; ObjectID = "4ah-qP-9eP"; */
6 6
 "4ah-qP-9eP.title" = "About RedditBar";
7 7
 
8
+/* Class = "NSMenuItem"; title = "PMs..."; ObjectID = "IM8-KI-MAc"; */
9
+"IM8-KI-MAc.title" = "PMs...";
10
+
8 11
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
9 12
 "bQG-wq-9Zw.title" = "Reload";
10 13
 

+ 10
- 1
RedditBar/Base.lproj/MainMenu.xib Vedi 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="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
3 3
     <dependencies>
4 4
         <deployment defaultVersion="1080" identifier="macosx"/>
5 5
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
@@ -14,6 +14,8 @@
14 14
         <customObject id="-3" userLabel="Application"/>
15 15
         <customObject id="494" customClass="AppDelegate">
16 16
             <connections>
17
+                <outlet property="PMItem" destination="IM8-KI-MAc" id="X1H-cL-0kE"/>
18
+                <outlet property="PMSeparator" destination="5L0-zz-YIh" id="2X3-PW-1G9"/>
17 19
                 <outlet property="application" destination="-3" id="1K5-sF-Im7"/>
18 20
                 <outlet property="firstMenuItem" destination="jfb-mv-iN9" id="2QT-D1-leO"/>
19 21
                 <outlet property="statusMenu" destination="fuB-VS-nSq" id="AZY-3d-h8G"/>
@@ -22,6 +24,13 @@
22 24
         <customObject id="420" customClass="NSFontManager"/>
23 25
         <menu id="fuB-VS-nSq" userLabel="StatusItem">
24 26
             <items>
27
+                <menuItem title="PMs..." hidden="YES" enabled="NO" id="IM8-KI-MAc">
28
+                    <modifierMask key="keyEquivalentModifierMask"/>
29
+                    <connections>
30
+                        <action selector="openUnread:" target="494" id="zdP-DS-AdX"/>
31
+                    </connections>
32
+                </menuItem>
33
+                <menuItem isSeparatorItem="YES" hidden="YES" id="5L0-zz-YIh"/>
25 34
                 <menuItem title="Loading..." enabled="NO" id="jfb-mv-iN9">
26 35
                     <modifierMask key="keyEquivalentModifierMask"/>
27 36
                 </menuItem>

+ 65
- 48
RedditBar/Reddit.m Vedi File

@@ -101,6 +101,51 @@ NSString *subredditFormat = @" [r/%@]";
101 101
     }
102 102
 }
103 103
 
104
+-(void)readFrontpage:(id)parent {
105
+    NSHTTPURLResponse *response;
106
+    
107
+    NSString *after = ((AppDelegate *)parent).lastFullName;
108
+    Boolean showSubreddits = ((AppDelegate *)parent).currentState.showSubreddit;
109
+    NSString *url;
110
+    if (after == nil)
111
+        url = [NSString stringWithFormat:@"hot.json?limit=%ld", (long)length];
112
+    else
113
+        url = [NSString stringWithFormat:@"hot.json?limit=%ld&after=%@", (long)length, after];
114
+        
115
+    NSData *data = [self queryAPI:url withResponse:&response];
116
+    if ((data == nil) || ([response statusCode] != 200)) {
117
+        [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:nil waitUntilDone:false];
118
+    } else {
119
+        [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:[self convertJSONToItemArray:data ShowSubs:showSubreddits] waitUntilDone:false];
120
+    }
121
+}
122
+
123
+-(void)readSubreddits:(id)parent {
124
+    NSMutableString *subs = [NSMutableString stringWithString:@"r/"];
125
+    for (NSUInteger i = 0; i < [subreddits count]; i++) {
126
+        [subs appendString:[subreddits objectAtIndex:i]];
127
+        if (i < ([subreddits count] - 1)) {
128
+            [subs appendString:@"+"];
129
+        }
130
+    }
131
+    
132
+    NSString *after = ((AppDelegate *)parent).lastFullName;
133
+    Boolean showSubreddits = ((AppDelegate *)parent).currentState.showSubreddit;
134
+    NSString *url;
135
+    if (after == nil)
136
+        url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld", subs, (long)length];
137
+    else
138
+        url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld&after=%@", subs, (long)length, after];
139
+    
140
+    NSHTTPURLResponse *response;
141
+    NSData *data = [self queryAPI:url withResponse:&response];
142
+    if ((data == nil) || ([response statusCode] != 200)) {
143
+        [(AppDelegate *)parent performSelectorOnMainThread:@selector(reloadListHasSubredditsCallback:) withObject:nil waitUntilDone:FALSE];
144
+    } else {
145
+        [(AppDelegate *)parent performSelectorOnMainThread:@selector(reloadListHasSubredditsCallback:) withObject:[self convertJSONToItemArray:data ShowSubs:showSubreddits] waitUntilDone:FALSE];
146
+    }
147
+}
148
+
104 149
 -(NSArray *)convertJSONToItemArray:(NSData *)data ShowSubs:(Boolean)showSubs {
105 150
     NSError *error;
106 151
     NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
@@ -108,7 +153,7 @@ NSString *subredditFormat = @" [r/%@]";
108 153
     if (dat == nil)
109 154
         return nil;
110 155
     NSArray *children = [dat valueForKey:@"children"];
111
-    if (children == nil)
156
+    if ((children == nil) || ([children count] == 0))
112 157
         return nil;
113 158
     
114 159
     NSMutableArray *array = [NSMutableArray arrayWithCapacity:[children count]];
@@ -126,17 +171,17 @@ NSString *subredditFormat = @" [r/%@]";
126 171
         NSString *subreddit = [NSString stringWithFormat:subredditFormat, [current valueForKey:@"subreddit"]];
127 172
         NSInteger maxLen = titleLength;
128 173
         if ([subreddit length] >= titleLength)
129
-            showSubs = FALSE;
174
+        showSubs = FALSE;
130 175
         if (showSubs)
131
-            maxLen -= [subreddit length];
176
+        maxLen -= [subreddit length];
132 177
         if ([name length] > maxLen)
133
-            name = [NSString stringWithFormat:@"%@%@", [name substringToIndex:(maxLen - [replaceTextForTitle length])], replaceTextForTitle];
178
+        name = [NSString stringWithFormat:@"%@%@", [name substringToIndex:(maxLen - [replaceTextForTitle length])], replaceTextForTitle];
134 179
         if (showSubs)
135
-            name = [NSString stringWithFormat:@"%@%@", name, subreddit];
180
+        name = [NSString stringWithFormat:@"%@%@", name, subreddit];
136 181
         RedditItem *r = [RedditItem itemWithName:name Link:link Comments:comments Self:isSelf];
137 182
         NSString *fullName = [current valueForKey:@"title"];
138 183
         if (showSubs)
139
-            fullName = [NSString stringWithFormat:@"%@%@", fullName, subreddit];
184
+        fullName = [NSString stringWithFormat:@"%@%@", fullName, subreddit];
140 185
         [r setFullName:fullName];
141 186
         [array insertObject:r atIndex:i];
142 187
         
@@ -148,57 +193,29 @@ NSString *subredditFormat = @" [r/%@]";
148 193
     return array;
149 194
 }
150 195
 
151
--(void)readFrontpage:(id)parent {
152
-    NSHTTPURLResponse *response;
153
-    
154
-    NSString *after = ((AppDelegate *)parent).lastFullName;
155
-    Boolean showSubreddits = ((AppDelegate *)parent).currentState.showSubreddit;
156
-    NSString *url;
157
-    if (after == nil)
158
-        url = [NSString stringWithFormat:@"hot.json?limit=%ld", (long)length];
159
-    else
160
-        url = [NSString stringWithFormat:@"hot.json?limit=%ld&after=%@", (long)length, after];
161
-        
162
-    NSData *data = [self queryAPI:url withResponse:&response];
163
-    if ((data == nil) || ([response statusCode] != 200)) {
164
-        [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:nil waitUntilDone:false];
165
-    } else {
166
-        [parent performSelectorOnMainThread:@selector(reloadListHasFrontpageCallback:) withObject:[self convertJSONToItemArray:data ShowSubs:showSubreddits] waitUntilDone:false];
167
-    }
196
+-(NSNumber *)messagesCount:(NSData *)data {
197
+    NSError *error;
198
+    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
199
+    NSDictionary *dat = [json valueForKey:@"data"];
200
+    if (dat == nil)
201
+        return nil;
202
+    NSArray *children = [dat valueForKey:@"children"];
203
+    if (children == nil)
204
+        return nil;
205
+    return [NSNumber numberWithInteger:[children count]];
168 206
 }
169 207
 
170
--(void)readSubreddits:(id)parent {
171
-    NSMutableString *subs = [NSMutableString stringWithString:@"r/"];
172
-    for (NSUInteger i = 0; i < [subreddits count]; i++) {
173
-        [subs appendString:[subreddits objectAtIndex:i]];
174
-        if (i < ([subreddits count] - 1)) {
175
-            [subs appendString:@"+"];
176
-        }
177
-    }
178
-    
179
-    NSString *after = ((AppDelegate *)parent).lastFullName;
180
-    Boolean showSubreddits = ((AppDelegate *)parent).currentState.showSubreddit;
181
-    NSString *url;
182
-    if (after == nil)
183
-        url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld", subs, (long)length];
184
-    else
185
-        url = [NSString stringWithFormat:@"%@/hot.json?limit=%ld&after=%@", subs, (long)length, after];
186
-    
208
+-(void)readPMs:(id)parent {
209
+    NSString *url = @"message/unread.json";
187 210
     NSHTTPURLResponse *response;
188 211
     NSData *data = [self queryAPI:url withResponse:&response];
189 212
     if ((data == nil) || ([response statusCode] != 200)) {
190
-        [(AppDelegate *)parent performSelectorOnMainThread:@selector(reloadListHasSubredditsCallback:) withObject:nil waitUntilDone:FALSE];
213
+        [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:nil waitUntilDone:FALSE];
191 214
     } else {
192
-        [(AppDelegate *)parent performSelectorOnMainThread:@selector(reloadListHasSubredditsCallback:) withObject:[self convertJSONToItemArray:data ShowSubs:showSubreddits] waitUntilDone:FALSE];
215
+        [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:[self messagesCount:data] waitUntilDone:FALSE];
193 216
     }
194 217
 }
195 218
 
196
--(void)readPMs:(id)parent {
197
-    // TODO read PMs
198
-    // Fill NSArray with RedditItems for each PM, or return nil if none
199
-    [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:nil waitUntilDone:FALSE];
200
-}
201
-
202 219
 -(void)isAuthenticatedNewModhash:(id)parent {
203 220
     NSHTTPURLResponse *response;
204 221
     NSData *dat = [self queryAPI:@"api/me.json" withResponse:&response];

+ 2
- 2
RedditBar/RedditBar-Info.plist Vedi File

@@ -17,11 +17,11 @@
17 17
 	<key>CFBundlePackageType</key>
18 18
 	<string>APPL</string>
19 19
 	<key>CFBundleShortVersionString</key>
20
-	<string>1.1.0</string>
20
+	<string>1.2.0</string>
21 21
 	<key>CFBundleSignature</key>
22 22
 	<string>????</string>
23 23
 	<key>CFBundleVersion</key>
24
-	<string>249</string>
24
+	<string>259</string>
25 25
 	<key>LSApplicationCategoryType</key>
26 26
 	<string>public.app-category.utilities</string>
27 27
 	<key>LSMinimumSystemVersion</key>

+ 2
- 0
RedditBar/de.lproj/Localizable.strings Vedi File

@@ -49,3 +49,5 @@
49 49
 /* Pref API Error */
50 50
 "Wrong Username or Password!" = "Falscher Nutzername oder falsches Passwort!";
51 51
 
52
+/* PM message */
53
+"You've got %ld unread PMs!" = "%ld ungelesene PMs!";

+ 4
- 1
RedditBar/de.lproj/MainMenu.strings Vedi File

@@ -2,7 +2,10 @@
2 2
 "1lW-9C-xt6.title" = "Einstellungen...";
3 3
 
4 4
 /* Class = "NSMenuItem"; title = "About RedditBar"; ObjectID = "4ah-qP-9eP"; */
5
-"4ah-qP-9eP.title" = "About RedditBar";
5
+"4ah-qP-9eP.title" = "Über RedditBar";
6
+
7
+/* Class = "NSMenuItem"; title = "PMs..."; ObjectID = "IM8-KI-MAc"; */
8
+"IM8-KI-MAc.title" = "PMs...";
6 9
 
7 10
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
8 11
 "bQG-wq-9Zw.title" = "Neu laden";

BIN
RedditBar/en.lproj/Localizable.strings Vedi File


+ 3
- 0
RedditBar/en.lproj/MainMenu.strings Vedi File

@@ -4,6 +4,9 @@
4 4
 /* Class = "NSMenuItem"; title = "About RedditBar"; ObjectID = "4ah-qP-9eP"; */
5 5
 "4ah-qP-9eP.title" = "About RedditBar";
6 6
 
7
+/* Class = "NSMenuItem"; title = "PMs..."; ObjectID = "IM8-KI-MAc"; */
8
+"IM8-KI-MAc.title" = "PMs...";
9
+
7 10
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
8 11
 "bQG-wq-9Zw.title" = "Reload";
9 12
 

+ 3
- 0
RedditBarTests/de.lproj/MainMenu.strings Vedi File

@@ -4,6 +4,9 @@
4 4
 /* Class = "NSMenuItem"; title = "About RedditBar"; ObjectID = "4ah-qP-9eP"; */
5 5
 "4ah-qP-9eP.title" = "About RedditBar";
6 6
 
7
+/* Class = "NSMenuItem"; title = "PMs..."; ObjectID = "IM8-KI-MAc"; */
8
+"IM8-KI-MAc.title" = "PMs...";
9
+
7 10
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
8 11
 "bQG-wq-9Zw.title" = "Reload";
9 12
 

+ 3
- 0
RedditBarTests/en.lproj/MainMenu.strings Vedi File

@@ -4,6 +4,9 @@
4 4
 /* Class = "NSMenuItem"; title = "About RedditBar"; ObjectID = "4ah-qP-9eP"; */
5 5
 "4ah-qP-9eP.title" = "About RedditBar";
6 6
 
7
+/* Class = "NSMenuItem"; title = "PMs..."; ObjectID = "IM8-KI-MAc"; */
8
+"IM8-KI-MAc.title" = "PMs...";
9
+
7 10
 /* Class = "NSMenuItem"; title = "Reload"; ObjectID = "bQG-wq-9Zw"; */
8 11
 "bQG-wq-9Zw.title" = "Reload";
9 12
 

Loading…
Annulla
Salva