Skip to content

Commit

Permalink
osx: modernize objc syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Aug 2, 2023
1 parent 6262f0b commit 02f6925
Show file tree
Hide file tree
Showing 50 changed files with 414 additions and 423 deletions.
2 changes: 1 addition & 1 deletion Tests/DDBTestInitializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "playmodes.h"

@implementation DDBTestInitializer
- (id)init {
- (instancetype)init {
NSString *resPath = [NSBundle bundleForClass:self.class].resourcePath;
const char *str = resPath.UTF8String;
strcpy (dbplugindir, str);
Expand Down
8 changes: 4 additions & 4 deletions Tests/GoogleTestRunner/GTMGoogleTestRunner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// This is a SPI for dealing with skipped tests.
@interface XCTSkippedTestContext : NSObject

- (id)initWithExplanation:(NSString *)explanation
- (instancetype)initWithExplanation:(NSString *)explanation
evaluatedExpression:(NSString *)evaluatedExpression
message:(NSString *)message
sourceCodeContext:(XCTSourceCodeContext *)sourceCodeContext;
Expand Down Expand Up @@ -107,7 +107,7 @@ @interface GTMGoogleTestRunner : XCTestCase {
#endif

// The name for a test is the GoogleTest name which is "TestCase.Test"
- (id)initWithName:(NSString *)testName;
- (instancetype)initWithName:(NSString *)testName NS_DESIGNATED_INITIALIZER;
@end

namespace {
Expand Down Expand Up @@ -238,15 +238,15 @@ + (id)defaultTestSuite {
return result;
}

- (id)initWithName:(NSString *)testName {
- (instancetype)initWithName:(NSString *)testName {
// Xcode 6.1 started taking the testName from the selector instead of calling
// -name.
// So we will add selectors to GTMGoogleTestRunner.
// They should all be unique because the selectors are named cppclass.method
// Filed as radar 18798444.
Class cls = [self class];
NSString *selectorTestName = SelectorNameFromGTestName(testName);
SEL selector = sel_registerName([selectorTestName UTF8String]);
SEL selector = sel_registerName(selectorTestName.UTF8String);
Method method = class_getInstanceMethod(cls, @selector(runGoogleTest));
IMP implementation = method_getImplementation(method);
const char *encoding = method_getTypeEncoding(method);
Expand Down
4 changes: 2 additions & 2 deletions Tests/SciptableTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ @implementation ScriptableTestsDummyClass
protected:
void SetUp() override {
// FIXME: convert to C++ / make cross-platform
NSString *path = [[[NSBundle bundleForClass:ScriptableTestsDummyClass.class] resourcePath] stringByAppendingString:@"/PresetManagerData"];
strcpy (dbconfdir, [path UTF8String]);
NSString *path = [[NSBundle bundleForClass:ScriptableTestsDummyClass.class].resourcePath stringByAppendingString:@"/PresetManagerData"];
strcpy (dbconfdir, path.UTF8String);
ddb_logger_init ();
conf_init ();
conf_enable_saving (0);
Expand Down
2 changes: 1 addition & 1 deletion Tests/TaggingTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static void
copy_file(const char *from, const char *to) {
// FIXME: make portable
[NSFileManager.defaultManager copyItemAtPath:[NSString stringWithUTF8String:from] toPath:[NSString stringWithUTF8String:to] error:nil];
[NSFileManager.defaultManager copyItemAtPath:@(from) toPath:@(to) error:nil];
}

class TaggingTests: public ::testing::Test {
Expand Down
56 changes: 28 additions & 28 deletions plugins/cocoaui/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static void fileadd_begin (ddb_fileadd_data_t *data, void *user_data) {
static void fileadd_end (ddb_fileadd_data_t *data, void *user_data) {
dispatch_async(dispatch_get_main_queue(), ^{
[g_appDelegate.mainWindow.window endSheet:g_appDelegate.addFilesWindow returnCode:NSModalResponseOK];
[[[g_appDelegate mainWindow] window] makeKeyAndOrderFront:g_appDelegate];
[g_appDelegate.mainWindow.window makeKeyAndOrderFront:g_appDelegate];
});
}

Expand All @@ -165,7 +165,7 @@ static int file_added (ddb_fileadd_data_t *data, void *user_data) {
// HACK: we want to set the label asynchronously, to minimize delays,
// but we also want to avoid sending multiple labels, becuase that's meaningless.
// So we use a basic flag, to see if the label is being set already.
NSString *s = [NSString stringWithUTF8String:uri];
NSString *s = @(uri);
_settingLabel = YES;
dispatch_async(dispatch_get_main_queue(), ^{
g_appDelegate.addFilesLabel.stringValue = s;
Expand Down Expand Up @@ -339,7 +339,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(aQueue, ^{
char str[100];
add_paths([filename UTF8String], (int)[filename length], 0, str, 100);
add_paths(filename.UTF8String, (int)filename.length, 0, str, 100);
});
return YES; // assume that everything went ok
}
Expand All @@ -352,29 +352,29 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
NSArray *sortedFilenames = [filenames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
// building single paths string for the deadbeef function, paths must be separated by '\0'
NSString *paths =[sortedFilenames componentsJoinedByString:@"\0"];
add_paths([paths UTF8String], (int)[paths lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 0, str, 100);
add_paths(paths.UTF8String, (int)[paths lengthOfBytesUsingEncoding:NSUTF8StringEncoding], 0, str, 100);
});
}


- (IBAction)showMainWinAction:(id)sender {
BOOL vis = ![_mainWindow.window isVisible];
BOOL vis = !(_mainWindow.window).visible;
_mainWindow.window.isVisible = vis;
if (vis) {
[_mainWindow.window makeKeyWindow];
}
}

- (IBAction)showLogWindowAction:(id)sender {
BOOL vis = ![_logWindow.window isVisible];
BOOL vis = !(_logWindow.window).visible;
_logWindow.window.isVisible = vis;
if (vis) {
[_logWindow.window makeKeyWindow];
}
}

- (IBAction)showEqualizerWindowAction:(id)sender {
BOOL vis = ![_equalizerWindow.window isVisible];
BOOL vis = !(_equalizerWindow.window).visible;
_equalizerWindow.window.isVisible = vis;
if (vis) {
[_equalizerWindow.window makeKeyWindow];
Expand Down Expand Up @@ -429,7 +429,7 @@ - (void)openFiles:(BOOL)clear play:(BOOL)play {
openDlg.canChooseDirectories = NO;
if ( [openDlg runModal] == NSModalResponseOK )
{
NSArray* files = [openDlg URLs];
NSArray* files = openDlg.URLs;
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
if (!deadbeef->plt_add_files_begin (plt, 0)) {
if (clear) {
Expand All @@ -439,9 +439,9 @@ - (void)openFiles:(BOOL)clear play:(BOOL)play {
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(aQueue, ^{
for (NSUInteger i = 0; i < files.count; i++) {
NSString* fileName = [[files objectAtIndex:i] path];
NSString* fileName = [files[i] path];
if (fileName) {
deadbeef->plt_add_file2 (0, plt, [fileName UTF8String], NULL, NULL);
deadbeef->plt_add_file2 (0, plt, fileName.UTF8String, NULL, NULL);
}
}
deadbeef->plt_add_files_end (plt, 0);
Expand Down Expand Up @@ -474,15 +474,15 @@ - (IBAction)addFoldersAction:(id)sender {
openDlg.canChooseDirectories = YES;
if ( [openDlg runModal] == NSModalResponseOK )
{
NSArray* files = [openDlg URLs];
NSArray* files = openDlg.URLs;
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
if (!deadbeef->plt_add_files_begin (plt, 0)) {
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(aQueue, ^{
for (NSUInteger i = 0; i < files.count; i++) {
NSString *fileName = [[files objectAtIndex:i] path];
NSString *fileName = [files[i] path];
if (fileName) {
deadbeef->plt_add_dir2 (0, plt, [fileName UTF8String], NULL, NULL);
deadbeef->plt_add_dir2 (0, plt, fileName.UTF8String, NULL, NULL);
}
}
deadbeef->plt_add_files_end (plt, 0);
Expand Down Expand Up @@ -576,14 +576,14 @@ - (IBAction)sortPlaylistRandom:(id)sender {

- (IBAction)sortPlaylistCustom:(id)sender {
deadbeef->pl_lock ();
_customSortEntry.stringValue = [NSString stringWithUTF8String:deadbeef->conf_get_str_fast ("cocoaui.custom_sort_tf", "")];
_customSortEntry.stringValue = @(deadbeef->conf_get_str_fast ("cocoaui.custom_sort_tf", ""));
deadbeef->pl_unlock ();
_customSortDescending.state = deadbeef->conf_get_int ("cocoaui.sort_desc", 0) ? NSControlStateValueOn : NSControlStateValueOff;
[_mainWindow.window beginSheet:_customSortPanel completionHandler:^(NSModalResponse returnCode) {
NSInteger state = self.customSortDescending.state;
self.descendingSortMode.state = state;
deadbeef->conf_set_int ("cocoaui.sort_desc", state == NSControlStateValueOn ? 1 : 0);
deadbeef->conf_set_str ("cocoaui.custom_sort_tf", [[self.customSortEntry stringValue] UTF8String]);
deadbeef->conf_set_str ("cocoaui.custom_sort_tf", (self.customSortEntry).stringValue.UTF8String);

if (returnCode == NSModalResponseOK) {
[self sortPlaylistByTF:self.customSortEntry.stringValue.UTF8String];
Expand Down Expand Up @@ -772,9 +772,9 @@ - (void) updateDockNowPlaying {
if (it) {
deadbeef->pl_item_unref (it);
}
_dockMenuNPTitle = [[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:title] action:nil keyEquivalent:@""];
_dockMenuNPTitle = [[NSMenuItem alloc] initWithTitle:@(title) action:nil keyEquivalent:@""];
_dockMenuNPTitle.enabled = NO;
_dockMenuNPArtistAlbum = [[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:artistAlbum] action:nil keyEquivalent:@""];
_dockMenuNPArtistAlbum = [[NSMenuItem alloc] initWithTitle:@(artistAlbum) action:nil keyEquivalent:@""];
_dockMenuNPArtistAlbum.enabled = NO;
[_dockMenu insertItem:_dockMenuNPTitle atIndex:1];
[_dockMenu insertItem:_dockMenuNPArtistAlbum atIndex:2];
Expand All @@ -800,18 +800,18 @@ - (IBAction)loadPlaylistAction:(id)sender {
openDlg.canChooseDirectories = NO;
if ([openDlg runModal] == NSModalResponseOK)
{
NSArray* files = [openDlg URLs];
if ([files count] < 1) {
NSArray* files = openDlg.URLs;
if (files.count < 1) {
return;
}
NSString *fname = [[files firstObject] path];
NSString *fname = [files.firstObject path];
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(aQueue, ^{
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
if (!deadbeef->plt_add_files_begin (plt, 0)) {
deadbeef->plt_clear (plt);
int abort = 0;
deadbeef->plt_load2 (0, plt, NULL, [fname UTF8String], &abort, NULL, NULL);
deadbeef->plt_load2 (0, plt, NULL, fname.UTF8String, &abort, NULL, NULL);
deadbeef->plt_save_config (plt);
deadbeef->plt_add_files_end (plt, 0);
}
Expand All @@ -838,7 +838,7 @@ - (IBAction)savePlaylistAction:(id)sender {
const char **exts = plug[i]->extensions;
if (exts && plug[i]->save) {
for (int e = 0; exts[e]; e++) {
NSString *ext = [NSString stringWithUTF8String:exts[e]];
NSString *ext = @(exts[e]);
[types addObject:ext];

message = [message stringByAppendingString:@", "];
Expand All @@ -853,11 +853,11 @@ - (IBAction)savePlaylistAction:(id)sender {
panel.allowsOtherFileTypes = NO;

if ([panel runModal] == NSModalResponseOK) {
NSString *fname = [[panel URL] path];
NSString *fname = panel.URL.path;
if (fname) {
ddb_playlist_t *plt = deadbeef->plt_get_curr ();
if (plt) {
deadbeef->plt_save (plt, NULL, NULL, [fname UTF8String], NULL, NULL, NULL);
deadbeef->plt_save (plt, NULL, NULL, fname.UTF8String, NULL, NULL, NULL);
deadbeef->plt_unref (plt);
}
}
Expand Down Expand Up @@ -889,7 +889,7 @@ - (IBAction)showHelp:(id)sender {
}
_helpWindow.contentURL = [NSBundle.mainBundle URLForResource:@"help-cocoa" withExtension:@"txt"];

if (![_helpWindow.window isVisible]) {
if (!(_helpWindow.window).visible) {
[_helpWindow showWindow:self];
}
}
Expand All @@ -900,7 +900,7 @@ - (IBAction)showChangelog:(id)sender {
}
_helpWindow.contentURL = [NSBundle.mainBundle URLForResource:@"ChangeLog" withExtension:@""];

if (![_helpWindow.window isVisible]) {
if (!(_helpWindow.window).visible) {
[_helpWindow showWindow:self];
}
}
Expand All @@ -911,7 +911,7 @@ - (IBAction)showGPL:(id)sender {
}
_helpWindow.contentURL = [NSBundle.mainBundle URLForResource:@"COPYING" withExtension:@"GPLv2"];

if (![_helpWindow.window isVisible]) {
if (!(_helpWindow.window).visible) {
[_helpWindow showWindow:self];
}
}
Expand All @@ -922,7 +922,7 @@ - (IBAction)showLGPL:(id)sender {
}
_helpWindow.contentURL = [NSBundle.mainBundle URLForResource:@"COPYING.LGPLv2" withExtension:@"1"];

if (![_helpWindow.window isVisible]) {
if (!(_helpWindow.window).visible) {
[_helpWindow showWindow:self];
}
}
Expand Down
Loading

0 comments on commit 02f6925

Please sign in to comment.