Skip to content

Commit

Permalink
Merge pull request ViennaRSS#1687 from Eitot/feature/constants
Browse files Browse the repository at this point in the history
Refactor notifications constants and global variables
  • Loading branch information
josh64x2 authored May 29, 2023
2 parents 9a0ebb0 + 788da53 commit f2e296e
Show file tree
Hide file tree
Showing 31 changed files with 389 additions and 322 deletions.
4 changes: 2 additions & 2 deletions Vienna/Sources/Alerts/FeedCredentials.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (IBAction)updateCredentials:(id)sender
[self.credentialsWindow.sheetParent endSheet:self.credentialsWindow];
[self.credentialsWindow orderOut:self];

[NSNotificationCenter.defaultCenter postNotificationName:@"MA_Notify_GotAuthenticationForFolder"
[NSNotificationCenter.defaultCenter postNotificationName:MA_Notify_GotAuthenticationForFolder
object:self.folder];
}

Expand All @@ -145,7 +145,7 @@ - (IBAction)cancel:(id)sender
[self.credentialsWindow.sheetParent endSheet:self.credentialsWindow];
[self.credentialsWindow orderOut:self];

[NSNotificationCenter.defaultCenter postNotificationName:@"MA_Notify_CancelAuthenticationForFolder"
[NSNotificationCenter.defaultCenter postNotificationName:MA_Notify_CancelAuthenticationForFolder
object:self.folder];
}

Expand Down
26 changes: 13 additions & 13 deletions Vienna/Sources/Application/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,20 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNot

// Register a bunch of notifications
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleFolderSelection:) name:@"MA_Notify_FolderSelectionChange" object:nil];
[nc addObserver:self selector:@selector(handleCheckFrequencyChange:) name:@"MA_Notify_CheckFrequencyChange" object:nil];
[nc addObserver:self selector:@selector(handleEditFolder:) name:@"MA_Notify_EditFolder" object:nil];
[nc addObserver:self selector:@selector(handleRefreshStatusChange:) name:@"MA_Notify_RefreshStatus" object:nil];
[nc addObserver:self selector:@selector(handleTabChange:) name:@"MA_Notify_TabChanged" object:nil];
[nc addObserver:self selector:@selector(handleTabCountChange:) name:@"MA_Notify_TabCountChanged" object:nil];
[nc addObserver:self selector:@selector(handleFolderNameChange:) name:@"MA_Notify_FolderNameChanged" object:nil];
[nc addObserver:self selector:@selector(handleFolderSelection:) name:MA_Notify_FolderSelectionChange object:nil];
[nc addObserver:self selector:@selector(handleCheckFrequencyChange:) name:MA_Notify_CheckFrequencyChange object:nil];
[nc addObserver:self selector:@selector(handleEditFolder:) name:MA_Notify_EditFolder object:nil];
[nc addObserver:self selector:@selector(handleRefreshStatusChange:) name:MA_Notify_RefreshStatus object:nil];
[nc addObserver:self selector:@selector(handleTabChange:) name:MA_Notify_TabChanged object:nil];
[nc addObserver:self selector:@selector(handleTabCountChange:) name:MA_Notify_TabCountChanged object:nil];
[nc addObserver:self selector:@selector(handleFolderNameChange:) name:MA_Notify_FolderNameChanged object:nil];
[nc addObserver:self selector:@selector(handleDidBecomeKeyWindow:) name:NSWindowDidBecomeKeyNotification object:nil];
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_PreferenceChange" object:nil];
[nc addObserver:self selector:@selector(handleShowAppInStatusBar:) name:@"MA_Notify_ShowAppInStatusBarChanged" object:nil];
[nc addObserver:self selector:@selector(handleShowFilterBar:) name:@"MA_Notify_FilterBarChanged" object:nil];
[nc addObserver:self selector:@selector(handleUpdateUnreadCount:) name:@"MA_Notify_FoldersUpdated" object:nil];
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:MA_Notify_PreferenceChange object:nil];
[nc addObserver:self selector:@selector(handleShowAppInStatusBar:) name:MA_Notify_ShowAppInStatusBarChanged object:nil];
[nc addObserver:self selector:@selector(handleShowFilterBar:) name:MA_Notify_FilterBarChanged object:nil];
[nc addObserver:self selector:@selector(handleUpdateUnreadCount:) name:MA_Notify_FoldersUpdated object:nil];
//Open Reader Notifications
[nc addObserver:self selector:@selector(handleGoogleAuthFailed:) name:@"MA_Notify_GoogleAuthFailed" object:nil];
[nc addObserver:self selector:@selector(handleGoogleAuthFailed:) name:MA_Notify_GoogleAuthFailed object:nil];

// Initialize the database
if ((db = [Database sharedManager]) == nil) {
Expand Down Expand Up @@ -2539,7 +2539,7 @@ -(IBAction)setLoadFullHTMLFlag:(BOOL)loadFullHTMLPages
[folder clearFlag:VNAFolderFlagLoadFullHTML];
[[Database sharedManager] clearFlag:VNAFolderFlagLoadFullHTML forFolder:folderID];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"MA_Notify_LoadFullHTMLChange" object:@(folderID)];
[[NSNotificationCenter defaultCenter] postNotificationName:MA_Notify_LoadFullHTMLChange object:@(folderID)];
}
}

Expand Down
20 changes: 10 additions & 10 deletions Vienna/Sources/Database/Database.m
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ -(void)clearFlag:(NSUInteger)flag forFolder:(NSInteger)folderId
FMDatabaseQueue *queue = self.databaseQueue;
[queue inDatabase:^(FMDatabase *db) {
[db executeUpdate:@"UPDATE folders SET flags=? WHERE folder_id=?", @(folder.flags), @(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FoldersUpdated object:@(folderId)];
}];
}
}
Expand All @@ -577,7 +577,7 @@ -(void)setFlag:(NSUInteger)flag forFolder:(NSInteger)folderId
FMDatabaseQueue *queue = self.databaseQueue;
[queue inDatabase:^(FMDatabase *db) {
[db executeUpdate:@"UPDATE folders SET flags=? WHERE folder_id=?", @(folder.flags), @(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FoldersUpdated object:@(folderId)];
}];
}
}
Expand Down Expand Up @@ -659,7 +659,7 @@ -(BOOL)setFeedURL:(NSString *)feed_url forFolder:(NSInteger)folderId
FMDatabaseQueue *queue = self.databaseQueue;
[queue inDatabase:^(FMDatabase *db) {
[db executeUpdate:@"UPDATE rss_folders SET feed_url=? WHERE folder_id=?", feed_url, @(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FoldersUpdated object:@(folderId)];
}];
}
return YES;
Expand Down Expand Up @@ -866,7 +866,7 @@ -(NSInteger)addFolder:(NSInteger)parentId afterChild:(NSInteger)predId folderNam
}

// Send a notification when new folders are added
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FolderAdded" object:folder];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FolderAdded object:folder];
}
return newItemId;
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ -(BOOL)setName:(NSString *)newName forFolder:(NSInteger)folderId

// Send a notification that the folder has changed. It is the responsibility of the
// notifiee that they work out that the name is the part that has changed.
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FolderNameChanged" object:@(folderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FolderNameChanged object:@(folderId)];
return YES;
}

Expand Down Expand Up @@ -1142,7 +1142,7 @@ -(BOOL)setDescription:(NSString *)newDescription forFolder:(NSInteger)folderId

// Send a notification that the folder has changed. It is the responsibility of the
// notifiee that they work out that the description is the part that has changed.
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FolderDescriptionChanged"
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FolderDescriptionChanged
object:@(folderId)];
return YES;
}
Expand Down Expand Up @@ -1187,7 +1187,7 @@ -(BOOL)setHomePage:(NSString *)homePageURL forFolder:(NSInteger)folderId

// Send a notification that the folder has changed. It is the responsibility of the
// notifiee that they work out that the link is the part that has changed.
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FolderHomePageChanged"
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FolderHomePageChanged
object:@(folderId)];
return YES;
}
Expand Down Expand Up @@ -1690,7 +1690,7 @@ -(void)purgeDeletedArticles
for (Folder * folder in [self.foldersDict objectEnumerator])
[folder clearCache];

[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(self.trashFolderId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FoldersUpdated object:@(self.trashFolderId)];
}
}

Expand Down Expand Up @@ -1802,7 +1802,7 @@ -(void)updateSearchFolder:(NSInteger)folderId withFolder:(NSString *)folderName
self.smartfoldersDict[@(folderId)] = criteriaTree;

NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc vna_postNotificationOnMainThreadWithName:@"MA_Notify_ArticleListContentChange"
[nc vna_postNotificationOnMainThreadWithName:MA_Notify_ArticleListContentChange
object:@(folderId)];
}

Expand Down Expand Up @@ -2355,7 +2355,7 @@ -(void)setFolderUnreadCount:(Folder *)folder adjustment:(NSUInteger)adjustment
FMDatabaseQueue *queue = self.databaseQueue;
[queue inDatabase:^(FMDatabase *db) {
[db executeUpdate:@"UPDATE folders SET unread_count=? WHERE folder_id=?", @(newCount), @(folder.itemId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:@"MA_Notify_FoldersUpdated" object:@(folder.itemId)];
[[NSNotificationCenter defaultCenter] vna_postNotificationOnMainThreadWithName:MA_Notify_FoldersUpdated object:@(folder.itemId)];
}];

// Update childUnreadCount for parents.
Expand Down
14 changes: 7 additions & 7 deletions Vienna/Sources/Database/Field.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

#import "Field.h"

static NSString *const VNACodingKeyDisplayName = @"displayName";
static NSString *const VNACodingKeyName = @"name";
static NSString *const VNACodingKeySQLField = @"sqlField";
static NSString *const VNACodingKeyTag = @"tag";
static NSString *const VNACodingKeyType = @"type";
static NSString *const VNACodingKeyVisible = @"visible";
static NSString *const VNACodingKeyWidth = @"width";
static NSString * const VNACodingKeyDisplayName = @"displayName";
static NSString * const VNACodingKeyName = @"name";
static NSString * const VNACodingKeySQLField = @"sqlField";
static NSString * const VNACodingKeyTag = @"tag";
static NSString * const VNACodingKeyType = @"type";
static NSString * const VNACodingKeyVisible = @"visible";
static NSString * const VNACodingKeyWidth = @"width";

@implementation Field

Expand Down
4 changes: 2 additions & 2 deletions Vienna/Sources/Download window/DownloadItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

@import UniformTypeIdentifiers;

static NSString *const VNACodingKeyFilename = @"filename";
static NSString *const VNACodingKeySize = @"size";
static NSString * const VNACodingKeyFilename = @"filename";
static NSString * const VNACodingKeySize = @"size";

@interface DownloadItem ()

Expand Down
4 changes: 2 additions & 2 deletions Vienna/Sources/Download window/DownloadManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ + (BOOL)isFileDownloaded:(NSString *)filename {
// Send a notification that the specified download item has changed.
- (void)notifyDownloadItemChange:(DownloadItem *)item {
NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;
[nc postNotificationName:@"MA_Notify_DownloadsListChange" object:item];
[nc postNotificationName:MA_Notify_DownloadsListChange object:item];
}

// Delivers a user notification for the given download item.
Expand All @@ -274,7 +274,7 @@ - (void)deliverNotificationForDownloadItem:(DownloadItem *)item {
notification.userInfo = @{UserNotificationContextKey: UserNotificationContextFileDownloadCompleted,
UserNotificationFilePathKey: fileName};

[NSNotificationCenter.defaultCenter postNotificationName:@"MA_Notify_DownloadCompleted" object:fileName];
[NSNotificationCenter.defaultCenter postNotificationName:MA_Notify_DownloadCompleted object:fileName];
} else if (item.state == DownloadStateFailed) {
notification.title = NSLocalizedString(@"Download failed", @"Notification title");
notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"File %@ failed to download", @"Notification body"), fileName];
Expand Down
3 changes: 2 additions & 1 deletion Vienna/Sources/Download window/DownloadWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "DownloadWindow.h"

#import "AppController+Notifications.h"
#import "Constants.h"
#import "DownloadItem.h"
#import "DownloadManager.h"
#import "HelperFunctions.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ -(void)windowDidLoad

// Register to get notified when the download manager's list changes
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleDownloadsChange:) name:@"MA_Notify_DownloadsListChange" object:nil];
[nc addObserver:self selector:@selector(handleDownloadsChange:) name:MA_Notify_DownloadsListChange object:nil];

// Set the cell for each row
ImageAndTextCell * imageAndTextCell;
Expand Down
Loading

0 comments on commit f2e296e

Please sign in to comment.