From a6c81982344c241465a4f01a60ac15eae3d81e6d Mon Sep 17 00:00:00 2001 From: relikd Date: Sun, 11 Aug 2019 13:21:30 +0200 Subject: [PATCH] Fix const + PostNotification() + RegisterNotification() --- baRSS/AppHook.m | 4 +-- baRSS/Constants.h | 22 ++++++++++----- baRSS/Core Data/Feed+Ext.m | 2 +- baRSS/Core Data/FeedArticle+Ext.m | 2 +- baRSS/Core Data/FeedMeta+Ext.h | 2 +- baRSS/Core Data/StoreCoordinator.h | 2 +- baRSS/Helper/DrawImage.m | 2 +- baRSS/Helper/FeedDownload.m | 11 ++++---- baRSS/Helper/NSDate+Ext.m | 2 +- baRSS/Helper/NSView+Ext.h | 28 +++++++++---------- baRSS/Info.plist | 2 +- .../Appearance Tab/SettingsAppearanceView.m | 8 +++--- .../Preferences/Feeds Tab/ModalFeedEditView.m | 2 +- baRSS/Preferences/Feeds Tab/SettingsFeeds.m | 12 ++++++-- .../Preferences/General Tab/SettingsGeneral.m | 2 +- baRSS/Preferences/Helper/ModalSheet.m | 6 ++-- baRSS/Status Bar Menu/BarMenu.m | 4 +-- baRSS/Status Bar Menu/BarStatusItem.m | 6 ++-- baRSS/Status Bar Menu/NSMenu+Ext.m | 6 ++-- 19 files changed, 69 insertions(+), 56 deletions(-) diff --git a/baRSS/AppHook.m b/baRSS/AppHook.m index 82aff9f..a101479 100644 --- a/baRSS/AppHook.m +++ b/baRSS/AppHook.m @@ -71,9 +71,7 @@ url = [url substringFromIndex:2]; } if ([scheme isEqualToString:@"feed"]) { - [FeedDownload autoDownloadAndParseURL:url successBlock:^{ - [self reopenPreferencesIfOpen]; - }]; + [FeedDownload autoDownloadAndParseURL:url successBlock:nil]; } } diff --git a/baRSS/Constants.h b/baRSS/Constants.h index 4db8e63..b517b36 100644 --- a/baRSS/Constants.h +++ b/baRSS/Constants.h @@ -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 diff --git a/baRSS/Core Data/Feed+Ext.m b/baRSS/Core Data/Feed+Ext.m index 7a5179e..7c136f2 100644 --- a/baRSS/Core Data/Feed+Ext.m +++ b/baRSS/Core Data/Feed+Ext.m @@ -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)); } } diff --git a/baRSS/Core Data/FeedArticle+Ext.m b/baRSS/Core Data/FeedArticle+Ext.m index acaf4ed..c7fe946 100644 --- a/baRSS/Core Data/FeedArticle+Ext.m +++ b/baRSS/Core Data/FeedArticle+Ext.m @@ -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]; } diff --git a/baRSS/Core Data/FeedMeta+Ext.h b/baRSS/Core Data/FeedMeta+Ext.h index ae649cc..460c8a4 100644 --- a/baRSS/Core Data/FeedMeta+Ext.h +++ b/baRSS/Core Data/FeedMeta+Ext.h @@ -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 diff --git a/baRSS/Core Data/StoreCoordinator.h b/baRSS/Core Data/StoreCoordinator.h index 9897487..e12f127 100644 --- a/baRSS/Core Data/StoreCoordinator.h +++ b/baRSS/Core Data/StoreCoordinator.h @@ -23,7 +23,7 @@ #import #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 diff --git a/baRSS/Helper/DrawImage.m b/baRSS/Helper/DrawImage.m index ce174ac..931c1a7 100644 --- a/baRSS/Helper/DrawImage.m +++ b/baRSS/Helper/DrawImage.m @@ -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[] = { diff --git a/baRSS/Helper/FeedDownload.m b/baRSS/Helper/FeedDownload.m index 838939f..292c329 100644 --- a/baRSS/Helper/FeedDownload.m +++ b/baRSS/Helper/FeedDownload.m @@ -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 *)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 { diff --git a/baRSS/Helper/NSDate+Ext.m b/baRSS/Helper/NSDate+Ext.m index 65b482d..e401715 100644 --- a/baRSS/Helper/NSDate+Ext.m +++ b/baRSS/Helper/NSDate+Ext.m @@ -24,7 +24,7 @@ #import -static const TimeUnitType _values[] = { +static TimeUnitType const _values[] = { TimeUnitYears, TimeUnitWeeks, TimeUnitDays, diff --git a/baRSS/Helper/NSView+Ext.h b/baRSS/Helper/NSView+Ext.h index b32212b..d3d81fd 100644 --- a/baRSS/Helper/NSView+Ext.h +++ b/baRSS/Helper/NSView+Ext.h @@ -22,23 +22,23 @@ #import -/***/ 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; } diff --git a/baRSS/Info.plist b/baRSS/Info.plist index d5b784e..484e181 100644 --- a/baRSS/Info.plist +++ b/baRSS/Info.plist @@ -60,7 +60,7 @@ CFBundleVersion - 10141 + 10158 LSApplicationCategoryType public.app-category.news LSMinimumSystemVersion diff --git a/baRSS/Preferences/Appearance Tab/SettingsAppearanceView.m b/baRSS/Preferences/Appearance Tab/SettingsAppearanceView.m index 87ce8b0..90c2624 100644 --- a/baRSS/Preferences/Appearance Tab/SettingsAppearanceView.m +++ b/baRSS/Preferences/Appearance Tab/SettingsAppearanceView.m @@ -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 diff --git a/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m b/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m index 5fb8171..cfd76d6 100644 --- a/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m +++ b/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m @@ -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 diff --git a/baRSS/Preferences/Feeds Tab/SettingsFeeds.m b/baRSS/Preferences/Feeds Tab/SettingsFeeds.m index a5fda42..2ece0a2 100644 --- a/baRSS/Preferences/Feeds Tab/SettingsFeeds.m +++ b/baRSS/Preferences/Feeds Tab/SettingsFeeds.m @@ -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 diff --git a/baRSS/Preferences/General Tab/SettingsGeneral.m b/baRSS/Preferences/General Tab/SettingsGeneral.m index 5f441d5..67b9439 100644 --- a/baRSS/Preferences/General Tab/SettingsGeneral.m +++ b/baRSS/Preferences/General Tab/SettingsGeneral.m @@ -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]; diff --git a/baRSS/Preferences/Helper/ModalSheet.m b/baRSS/Preferences/Helper/ModalSheet.m index 274de8d..c17f008 100644 --- a/baRSS/Preferences/Helper/ModalSheet.m +++ b/baRSS/Preferences/Helper/ModalSheet.m @@ -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; diff --git a/baRSS/Status Bar Menu/BarMenu.m b/baRSS/Status Bar Menu/BarMenu.m index 6652fa4..de1036f 100644 --- a/baRSS/Status Bar Menu/BarMenu.m +++ b/baRSS/Status Bar Menu/BarMenu.m @@ -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; } diff --git a/baRSS/Status Bar Menu/BarStatusItem.m b/baRSS/Status Bar Menu/BarStatusItem.m index a9a03da..f31d191 100644 --- a/baRSS/Status Bar Menu/BarStatusItem.m +++ b/baRSS/Status Bar Menu/BarStatusItem.m @@ -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; } diff --git a/baRSS/Status Bar Menu/NSMenu+Ext.m b/baRSS/Status Bar Menu/NSMenu+Ext.m index be65202..b646019 100644 --- a/baRSS/Status Bar Menu/NSMenu+Ext.m +++ b/baRSS/Status Bar Menu/NSMenu+Ext.m @@ -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); } }