<commit_before>#include "systemnotifier.h"
#include "mac/Reachability.h"
#include <Cocoa/Cocoa.h>

@interface CocoaSystemNotifier : NSObject
@end

class SystemNotifierPrivate
{
public:
    Reachability* reachability;
    CocoaSystemNotifier* notifier;
};

@implementation CocoaSystemNotifier
- (id)init
{
    self = [super init];

    if (self) {
        [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
            selector: @selector(receiveSleepNote:)
            name: NSWorkspaceWillSleepNotification object: nil];
        [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
            selector: @selector(receiveWakeNote:)
            name: NSWorkspaceDidWakeNotification object: nil];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(receiveNetworkNote:)
            name: kReachabilityChangedNotification object: nil];
    }
    return self;
}

- (void) receiveSleepNote: (NSNotification*) note
{
    Q_UNUSED(note);
    QMetaObject::invokeMethod(SystemNotifier::instance(), "sleep");
}

- (void) receiveWakeNote: (NSNotification*) note
{
    Q_UNUSED(note);
    QMetaObject::invokeMethod(SystemNotifier::instance(), "wake");
}

- (void) receiveNetworkNote: (NSNotification* )note
{
    Reachability* reachability = [note object];
    NSParameterAssert([reachability isKindOfClass: [Reachability class]]);
    BOOL offline = [reachability connectionRequired];
    QMetaObject::invokeMethod(SystemNotifier::instance(), offline ? "offline" : "online");
}
@end

void SystemNotifier::initialize()
{
    d = new SystemNotifierPrivate;

    d->notifier = [[CocoaSystemNotifier alloc] init];
    CFRetain(d->notifier);
    [d->notifier release];

    d->reachability = [[Reachability reachabilityForInternetConnection] retain];
    [d->reachability startNotifier];
}

void SystemNotifier::uninitialize()
{
    CFRelease(d->notifier);
}
<commit_msg>SystemNotifier for Mac: fix retain/release<commit_after>#include "systemnotifier.h"
#include "mac/Reachability.h"
#include <Cocoa/Cocoa.h>

@interface CocoaSystemNotifier : NSObject
@end

class SystemNotifierPrivate
{
public:
    Reachability* reachability;
    CocoaSystemNotifier* notifier;
};

@implementation CocoaSystemNotifier
- (id)init
{
    self = [super init];

    if (self) {
        [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
            selector: @selector(receiveSleepNote:)
            name: NSWorkspaceWillSleepNotification object: nil];
        [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
            selector: @selector(receiveWakeNote:)
            name: NSWorkspaceDidWakeNotification object: nil];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(receiveNetworkNote:)
            name: kReachabilityChangedNotification object: nil];
    }
    return self;
}

- (void) receiveSleepNote: (NSNotification*) note
{
    Q_UNUSED(note);
    QMetaObject::invokeMethod(SystemNotifier::instance(), "sleep");
}

- (void) receiveWakeNote: (NSNotification*) note
{
    Q_UNUSED(note);
    QMetaObject::invokeMethod(SystemNotifier::instance(), "wake");
}

- (void) receiveNetworkNote: (NSNotification* )note
{
    Reachability* reachability = [note object];
    NSParameterAssert([reachability isKindOfClass: [Reachability class]]);
    BOOL offline = [reachability connectionRequired];
    QMetaObject::invokeMethod(SystemNotifier::instance(), offline ? "offline" : "online");
}
@end

void SystemNotifier::initialize()
{
    d = new SystemNotifierPrivate;
    d->notifier = [[CocoaSystemNotifier alloc] init];
    d->reachability = [[Reachability reachabilityForInternetConnection] retain];
    [d->reachability startNotifier];
}

void SystemNotifier::uninitialize()
{
    [d->notifier release];
    [d->reachability release];
    delete d;
}

{'fraction_non_alphanumeric': 0.11622525070712265, 'fraction_numerical': 0.0, 'mean_word_length': 4.5177304964539005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1079400', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1129, 'n_words': 236}