mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-06 06:03:23 +01:00
Add mDNS service publishing on Mac.
This commit is contained in:
parent
0e226cc34b
commit
7d09548243
@ -843,6 +843,7 @@ optional_source(APPLE
|
||||
core/mac_startup.mm
|
||||
core/scoped_nsautorelease_pool.mm
|
||||
devices/macdevicelister.mm
|
||||
networkremote/bonjour.mm
|
||||
ui/globalshortcutgrabber.mm
|
||||
ui/macscreensaver.cpp
|
||||
ui/macsystemtrayicon.mm
|
||||
|
26
src/networkremote/bonjour.h
Normal file
26
src/networkremote/bonjour.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef BONJOUR_H
|
||||
#define BONJOUR_H
|
||||
|
||||
#include "zeroconf.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
@class NetServicePublicationDelegate;
|
||||
#else
|
||||
class NetServicePublicationDelegate;
|
||||
#endif // __OBJC__
|
||||
|
||||
class Bonjour : public Zeroconf {
|
||||
public:
|
||||
Bonjour();
|
||||
virtual ~Bonjour();
|
||||
virtual void Publish(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
quint16 port);
|
||||
|
||||
private:
|
||||
NetServicePublicationDelegate* delegate_;
|
||||
};
|
||||
|
||||
#endif // BONJOUR_H
|
65
src/networkremote/bonjour.mm
Normal file
65
src/networkremote/bonjour.mm
Normal file
@ -0,0 +1,65 @@
|
||||
#include "bonjour.h"
|
||||
|
||||
#import <Foundation/NSNetServices.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#include "core/logging.h"
|
||||
|
||||
@interface NetServicePublicationDelegate : NSObject<NSNetServiceDelegate> {
|
||||
}
|
||||
|
||||
- (void)netServiceWillPublish:(NSNetService*)netService;
|
||||
- (void)netService:(NSNetService*)netService
|
||||
didNotPublish:(NSDictionary*)errorDict;
|
||||
- (void)netServiceDidStop:(NSNetService*)netService;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NetServicePublicationDelegate
|
||||
|
||||
- (void)netServiceWillPublish: (NSNetService*)netService {
|
||||
qLog(Debug) << "Publishing:" << [[netService name] UTF8String];
|
||||
}
|
||||
|
||||
- (void)netService: (NSNetService*)netServie didNotPublish: (NSDictionary*)errorDict {
|
||||
qLog(Debug) << "Failed to publish remote service with Bonjour";
|
||||
NSLog(@"%@", errorDict);
|
||||
}
|
||||
|
||||
- (void)netServiceDidStop: (NSNetService*)netService {
|
||||
qLog(Debug) << "Unpublished:" << [[netService name] UTF8String];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace {
|
||||
|
||||
NSString* NSStringFromQString(const QString& s) {
|
||||
return [[NSString alloc] initWithUTF8String: s.toUtf8().constData()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Bonjour::Bonjour()
|
||||
: delegate_([[NetServicePublicationDelegate alloc] init]) {
|
||||
}
|
||||
|
||||
Bonjour::~Bonjour() {
|
||||
[delegate_ release];
|
||||
}
|
||||
|
||||
void Bonjour::Publish(
|
||||
const QString& domain,
|
||||
const QString& type,
|
||||
const QString& name,
|
||||
quint16 port) {
|
||||
NSNetService* service = [[NSNetService alloc]
|
||||
initWithDomain: NSStringFromQString(domain)
|
||||
type: NSStringFromQString(type)
|
||||
name: NSStringFromQString(name)
|
||||
port: port];
|
||||
if (service) {
|
||||
[service setDelegate: delegate_];
|
||||
[service publish];
|
||||
}
|
||||
}
|
@ -6,6 +6,10 @@
|
||||
#include "avahi.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_DARWIN
|
||||
#include "bonjour.h"
|
||||
#endif
|
||||
|
||||
Zeroconf* Zeroconf::sInstance = NULL;
|
||||
|
||||
Zeroconf::~Zeroconf() {
|
||||
@ -17,6 +21,9 @@ Zeroconf* Zeroconf::GetZeroconf() {
|
||||
#ifdef HAVE_DBUS
|
||||
sInstance = new Avahi;
|
||||
#endif // HAVE_DBUS
|
||||
#ifdef Q_OS_DARWIN
|
||||
sInstance = new Bonjour;
|
||||
#endif
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user