Fix const + PostNotification() + RegisterNotification()

This commit is contained in:
relikd
2019-08-11 13:21:30 +02:00
parent b081564eca
commit a6c8198234
19 changed files with 69 additions and 56 deletions

View File

@@ -71,9 +71,7 @@
url = [url substringFromIndex:2];
}
if ([scheme isEqualToString:@"feed"]) {
[FeedDownload autoDownloadAndParseURL:url successBlock:^{
[self reopenPreferencesIfOpen];
}];
[FeedDownload autoDownloadAndParseURL:url successBlock:nil];
}
}

View File

@@ -29,7 +29,7 @@
/// UTI type used for opml files
static const NSPasteboardType UTI_OPML = @"org.opml";
static NSPasteboardType const UTI_OPML = @"org.opml";
#pragma mark - NSImageName constants
@@ -54,37 +54,45 @@ static NSImageName const RSSImageMenuItemUnread = @"RSSImageMenuItemUnread";
#pragma mark - NSNotificationName constants
/// Helper method calls @c (defaultCenter)postNotification:
NS_INLINE void PostNotification(NSNotificationName name, id obj) { [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj]; }
NS_INLINE void RegisterNotification(NSNotificationName name, SEL action, id observer) { [[NSNotificationCenter defaultCenter] addObserver:observer selector:action name:name object:nil]; }
/**
@c notification.object is @c NSNumber of type @c NSUInteger.
Represents number of feeds that are proccessed in background update. Sends @c 0 when all downloads are finished.
*/
static const NSNotificationName kNotificationBackgroundUpdateInProgress = @"baRSS-notification-background-update-in-progress";
static NSNotificationName const kNotificationBackgroundUpdateInProgress = @"baRSS-notification-background-update-in-progress";
/**
@c notification.object is @c NSManagedObjectID of type @c FeedGroup.
Called whenever a new feed group was created in @c autoDownloadAndParseURL:
*/
static NSNotificationName const kNotificationGroupInserted = @"baRSS-notification-group-inserted";
/**
@c notification.object is @c NSManagedObjectID of type @c Feed.
Called whenever download of a feed finished and object was modified (not if statusCode 304).
*/
static const NSNotificationName kNotificationFeedUpdated = @"baRSS-notification-feed-updated";
static NSNotificationName const kNotificationFeedUpdated = @"baRSS-notification-feed-updated";
/**
@c notification.object is @c NSManagedObjectID of type @c Feed.
Called whenever the icon attribute of an item was updated.
*/
static const NSNotificationName kNotificationFeedIconUpdated = @"baRSS-notification-feed-icon-updated";
static NSNotificationName const kNotificationFeedIconUpdated = @"baRSS-notification-feed-icon-updated";
/**
@c notification.object is @c NSNumber of type @c BOOL.
@c YES if network became reachable. @c NO on connection lost.
*/
static const NSNotificationName kNotificationNetworkStatusChanged = @"baRSS-notification-network-status-changed";
static NSNotificationName const kNotificationNetworkStatusChanged = @"baRSS-notification-network-status-changed";
/**
@c notification.object is @c NSNumber of type @c NSInteger.
Represents a relative change (e.g., negative if items were marked read)
*/
static const NSNotificationName kNotificationTotalUnreadCountChanged = @"baRSS-notification-total-unread-count-changed";
static NSNotificationName const kNotificationTotalUnreadCountChanged = @"baRSS-notification-total-unread-count-changed";
/**
@c notification.object is either @c nil or @c NSNumber of type @c NSInteger.
If new count is known an absoulte number is passed.
Else @c nil if count has to be fetched from core data.
*/
static const NSNotificationName kNotificationTotalUnreadCountReset = @"baRSS-notification-total-unread-count-reset";
static NSNotificationName const kNotificationTotalUnreadCountReset = @"baRSS-notification-total-unread-count-reset";
#pragma mark - Internal

View File

@@ -97,7 +97,7 @@
diff += [self insertArticles:localSet withRemoteSet:obj.articles]; // insert new in correct order
// Get new total article count and post unread-count-change notification
if (flag && diff != 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:@(diff)];
PostNotification(kNotificationTotalUnreadCountChanged, @(diff));
}
}

View File

@@ -89,7 +89,7 @@
fa.unread = !fa.unread;
[StoreCoordinator saveContext:moc andParent:YES];
NSNumber *num = (fa.unread ? @+1 : @-1);
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:num];
PostNotification(kNotificationTotalUnreadCountChanged, num);
}
[moc reset];
}

View File

@@ -22,7 +22,7 @@
#import "FeedMeta+CoreDataClass.h"
static const int32_t kDefaultFeedRefreshInterval = 30 * 60;
static int32_t const kDefaultFeedRefreshInterval = 30 * 60;
@interface FeedMeta (Ext)
// HTTP response

View File

@@ -23,7 +23,7 @@
#import <Foundation/Foundation.h>
#import "DBv1+CoreDataModel.h"
static const int dbFileVersion = 1; // update in case database structure changes
static int const dbFileVersion = 1; // update in case database structure changes
@interface StoreCoordinator : NSObject
// Managing contexts

View File

@@ -205,7 +205,7 @@ NS_INLINE void DrawGradient(CGContextRef c, CGFloat size, NSColor *color) {
[rgbColor getHue:&h saturation:&s brightness:&b alpha:&a];
} @catch (NSException *e) {}
static const CGFloat impact = 0.3;
static CGFloat const impact = 0.3;
NSColor *darker = [NSColor colorWithHue:h saturation:(s + impact > 1 ? 1 : s + impact) brightness:b alpha:a];
NSColor *lighter = [NSColor colorWithHue:h saturation:(s - impact < 0 ? 0 : s - impact) brightness:b alpha:a];
const void* cgColors[] = {

View File

@@ -330,7 +330,7 @@ static BOOL _nextUpdateIsForced = NO;
}
[StoreCoordinator saveContext:moc andParent:YES];
if (needsNotification)
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationFeedUpdated object:oid];
PostNotification(kNotificationFeedUpdated, oid);
if (block) block(success);
}];
}
@@ -353,6 +353,7 @@ static BOOL _nextUpdateIsForced = NO;
[StoreCoordinator saveContext:moc andParent:YES];
[moc reset];
if (successful) {
PostNotification(kNotificationGroupInserted, f.group.objectID);
[self scheduleUpdateForUpcomingFeeds];
if (block) block();
}
@@ -388,7 +389,7 @@ static BOOL _nextUpdateIsForced = NO;
*/
+ (void)batchDownloadFeeds:(NSArray<Feed*> *)list favicons:(BOOL)fav showErrorAlert:(BOOL)alert finally:(nullable os_block_t)block {
_isUpdating = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationBackgroundUpdateInProgress object:@(list.count)];
PostNotification(kNotificationBackgroundUpdateInProgress, @(list.count));
dispatch_group_t group = dispatch_group_create();
for (Feed *f in list) {
dispatch_group_enter(group);
@@ -399,7 +400,7 @@ static BOOL _nextUpdateIsForced = NO;
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
if (block) block();
_isUpdating = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationBackgroundUpdateInProgress object:@(0)];
PostNotification(kNotificationBackgroundUpdateInProgress, @(0));
});
}
@@ -426,7 +427,7 @@ static BOOL _nextUpdateIsForced = NO;
Feed *f = [moc objectWithID:oid];
if (f && [f setIconImage:img]) {
[StoreCoordinator saveContext:moc andParent:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationFeedIconUpdated object:oid];
PostNotification(kNotificationFeedIconUpdated, oid);
}
if (block) block();
}];
@@ -549,7 +550,7 @@ static BOOL _nextUpdateIsForced = NO;
static void networkReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void *object) {
if (_reachability == NULL) return;
_isReachable = [FeedDownload hasConnectivity:flags];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationNetworkStatusChanged object:@(_isReachable)];
PostNotification(kNotificationNetworkStatusChanged, @(_isReachable));
if (_isReachable) {
[FeedDownload resumeUpdates];
} else {

View File

@@ -24,7 +24,7 @@
#import <QuartzCore/QuartzCore.h>
static const TimeUnitType _values[] = {
static TimeUnitType const _values[] = {
TimeUnitYears,
TimeUnitWeeks,
TimeUnitDays,

View File

@@ -22,23 +22,23 @@
#import <Cocoa/Cocoa.h>
/***/ static const CGFloat PAD_WIN = 20; // window padding
/***/ static const CGFloat PAD_L = 16;
/***/ static const CGFloat PAD_M = 8;
/***/ static const CGFloat PAD_S = 4;
/***/ static const CGFloat PAD_XS = 2;
/***/ static CGFloat const PAD_WIN = 20; // window padding
/***/ static CGFloat const PAD_L = 16;
/***/ static CGFloat const PAD_M = 8;
/***/ static CGFloat const PAD_S = 4;
/***/ static CGFloat const PAD_XS = 2;
/***/ static const CGFloat HEIGHT_LABEL = 17;
/***/ static const CGFloat HEIGHT_LABEL_SMALL = 14;
/***/ static const CGFloat HEIGHT_INPUTFIELD = 21;
/***/ static const CGFloat HEIGHT_BUTTON = 21;
/***/ static const CGFloat HEIGHT_INLINEBUTTON = 16;
/***/ static const CGFloat HEIGHT_POPUP = 21;
/***/ static const CGFloat HEIGHT_SPINNER = 16;
/***/ static const CGFloat HEIGHT_CHECKBOX = 14;
/***/ static CGFloat const HEIGHT_LABEL = 17;
/***/ static CGFloat const HEIGHT_LABEL_SMALL = 14;
/***/ static CGFloat const HEIGHT_INPUTFIELD = 21;
/***/ static CGFloat const HEIGHT_BUTTON = 21;
/***/ static CGFloat const HEIGHT_INLINEBUTTON = 16;
/***/ static CGFloat const HEIGHT_POPUP = 21;
/***/ static CGFloat const HEIGHT_SPINNER = 16;
/***/ static CGFloat const HEIGHT_CHECKBOX = 14;
/// Static variable to calculate origin center coordinate in its @c superview. The value of this var isn't used.
static const CGFloat CENTER = -0.015625;
static CGFloat const CENTER = -0.015625;
/// Calculate @c origin.y going down from the top border of its @c superview
NS_INLINE CGFloat YFromTop(NSView *view) { return NSHeight(view.superview.frame) - NSMinY(view.frame) - view.alignmentRectInsets.bottom; }

View File

@@ -60,7 +60,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>10141</string>
<string>10158</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.news</string>
<key>LSMinimumSystemVersion</key>

View File

@@ -30,8 +30,8 @@
@end
/***/ static const CGFloat IconSize = 18;
/***/ static const CGFloat colWidth = (IconSize + PAD_M); // checkbox column width
/***/ static CGFloat const IconSize = 18;
/***/ static CGFloat const colWidth = (IconSize + PAD_M); // checkbox column width
@implementation SettingsAppearanceView
@@ -63,8 +63,8 @@
/// Create new entry with 1-3 checkboxes and a descriptive label
- (NSTextField*)entry:(char*)m label:(NSString*)text {
static const char* scope[] = { "global", "group", "feed" };
static const char* ident[] = { "TintMenuBarIcon", "UpdateAll", "OpenUnread", "MarkRead", "MarkUnread", "UnreadCount", "TickMark", "ShortNames", "LimitArticles" };
static char* const scope[] = { "global", "group", "feed" };
static char* const ident[] = { "TintMenuBarIcon", "UpdateAll", "OpenUnread", "MarkRead", "MarkUnread", "UnreadCount", "TickMark", "ShortNames", "LimitArticles" };
CGFloat y = PAD_WIN + IconSize + PAD_S + self.row * (PAD_S + HEIGHT_LABEL);
// Add checkboxes: row 0 - 8, col 0 - 2

View File

@@ -40,7 +40,7 @@
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
CGFloat x = NSWidth(labels.frame) + PAD_S;
static const CGFloat rowHeight = PAD_S + HEIGHT_INPUTFIELD;
static CGFloat const rowHeight = PAD_S + HEIGHT_INPUTFIELD;
[labels placeIn:self x:0 yTop:0];
// 1. row

View File

@@ -48,9 +48,10 @@
- (void)viewDidLoad {
[super viewDidLoad];
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(feedUpdated:) name:kNotificationFeedUpdated object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(feedUpdated:) name:kNotificationFeedIconUpdated object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateInProgress:) name:kNotificationBackgroundUpdateInProgress object:nil];
RegisterNotification(kNotificationFeedUpdated, @selector(feedUpdated:), self);
RegisterNotification(kNotificationFeedIconUpdated, @selector(feedUpdated:), self);
RegisterNotification(kNotificationGroupInserted, @selector(groupInserted:), self);
RegisterNotification(kNotificationBackgroundUpdateInProgress, @selector(updateInProgress:), self);
}
- (void)dealloc {
@@ -162,6 +163,11 @@
}
}
/// Callback method fired when feed is inserted via a 'feed://' url
- (void)groupInserted:(NSNotification*)notify {
[self.dataStore fetch:self];
}
#pragma mark - Activity Spinner & Status Info

View File

@@ -49,7 +49,7 @@
- (void)fixCache:(NSButton *)sender {
NSUInteger deleted = [StoreCoordinator deleteUnreferenced];
[StoreCoordinator restoreFeedIndexPaths];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountReset object:nil];
PostNotification(kNotificationTotalUnreadCountReset, nil);
// show only if >0, but hey, this button will vanish anyway ...
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = [NSString stringWithFormat:@"Removed %lu unreferenced core data entries.", deleted];

View File

@@ -31,9 +31,9 @@
/// Designated initializer. 'Done' and 'Cancel' buttons will be added automatically.
- (instancetype)initWithView:(NSView*)content {
static const NSInteger minWidth = 320;
static const NSInteger maxWidth = 1200;
static const CGFloat contentOffsetY = PAD_WIN + HEIGHT_BUTTON + PAD_L;
static NSInteger const minWidth = 320;
static NSInteger const maxWidth = 1200;
static CGFloat const contentOffsetY = PAD_WIN + HEIGHT_BUTTON + PAD_L;
NSInteger w = [[NSUserDefaults standardUserDefaults] integerForKey:@"modalSheetWidth"];
if (w < minWidth) w = minWidth;

View File

@@ -45,8 +45,8 @@
// TODO: move unread counts to status item and keep in sync when changing feeds in preferences
self.unreadMap = [[MapUnreadTotal alloc] initWithCoreData: [StoreCoordinator countAggregatedUnread]];
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(feedUpdated:) name:kNotificationFeedUpdated object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(feedIconUpdated:) name:kNotificationFeedIconUpdated object:nil];
RegisterNotification(kNotificationFeedUpdated, @selector(feedUpdated:), self);
RegisterNotification(kNotificationFeedIconUpdated, @selector(feedIconUpdated:), self);
return self;
}

View File

@@ -53,9 +53,9 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainMenuWillOpen) name:NSMenuDidBeginTrackingNotification object:self.statusItem.menu];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainMenuDidClose) name:NSMenuDidEndTrackingNotification object:self.statusItem.menu];
// Some icon unread count notification callback methods
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChanged:) name:kNotificationNetworkStatusChanged object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(unreadCountChanged:) name:kNotificationTotalUnreadCountChanged object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(unreadCountReset:) name:kNotificationTotalUnreadCountReset object:nil];
RegisterNotification(kNotificationNetworkStatusChanged, @selector(networkChanged:), self);
RegisterNotification(kNotificationTotalUnreadCountChanged, @selector(unreadCountChanged:), self);
RegisterNotification(kNotificationTotalUnreadCountReset, @selector(unreadCountReset:), self);
return self;
}

View File

@@ -151,8 +151,8 @@ typedef NS_ENUM(NSInteger, MenuItemTag) {
/// Check user preferences for preferred display style.
- (BOOL)allowDisplayOfHeaderItem:(MenuItemTag)tag {
static const char * A[] = {"", "global", "feed", "group"};
static const char * B[] = {"", "MarkRead", "MarkUnread", "OpenUnread"};
static char* const A[] = {"", "global", "feed", "group"};
static char* const B[] = {"", "MarkRead", "MarkUnread", "OpenUnread"};
int idx = (self.isMainMenu ? 1 : (self.isFeedMenu ? 2 : 3));
return [UserPrefs defaultYES:[NSString stringWithFormat:@"%s%s", A[idx], B[tag & 3]]]; // first 2 bits
}
@@ -210,7 +210,7 @@ typedef NS_ENUM(NSInteger, MenuItemTag) {
[StoreCoordinator saveContext:moc andParent:YES];
[moc reset];
NSNumber *num = [NSNumber numberWithInteger: (markRead ? -1 : +1) * (NSInteger)list.count ];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:num];
PostNotification(kNotificationTotalUnreadCountChanged, num);
}
}