X-Git-Url: http://cgit.babelmonkeys.de/?p=mpdbot.git;a=blobdiff_plain;f=src%2Fmpdbot.m;h=8ef781b51057eb7dc1a0ccb2df1a30ae30b03701;hp=eb92876880af712e30f7ee333ce276ed681dea54;hb=HEAD;hpb=fb736d0ba5442efc5a592aa5389f2ac3280b755b diff --git a/src/mpdbot.m b/src/mpdbot.m index eb92876..8ef781b 100644 --- a/src/mpdbot.m +++ b/src/mpdbot.m @@ -31,6 +31,7 @@ @interface AppDelegate: OFObject { PEPThread *pepper; + MPDConnection *mpdConn; } @end @@ -40,6 +41,12 @@ OF_APPLICATION_DELEGATE(AppDelegate) - (void)applicationDidFinishLaunching { XMPPConnection *conn; + + OFString *mpd_host; + uint16_t mpd_port; + OFString *mpd_port_string; + + OFDictionary *environment = [OFApplication environment]; OFArray *arguments = [OFApplication arguments]; conn = [[XMPPConnection alloc] init]; @@ -56,6 +63,20 @@ OF_APPLICATION_DELEGATE(AppDelegate) conn.password = [arguments objectAtIndex: 2]; conn.resource = @"ObjXMPP"; + mpd_host = [environment objectForKey: @"MPD_HOST"]; + if (mpd_host == nil) + mpd_host = @"localhost"; + + mpd_port_string = [environment objectForKey: @"MPD_PORT"]; + if (mpd_port_string && [mpd_port_string decimalValue] <= UINT16_MAX) + mpd_port = (uint16_t) [mpd_port_string decimalValue]; + else + mpd_port = 6600; + + mpdConn = [[MPDConnection alloc] initWithHost: mpd_host + port: mpd_port]; + [mpdConn connect]; + @try { [conn connect]; [conn handleConnection]; @@ -107,8 +128,7 @@ OF_APPLICATION_DELEGATE(AppDelegate) stringValue] isEqual: @"pubsub"] && [[[identity attributeForName: @"type"] stringValue] isEqual: @"pep"]) { - pepper = [[PEPThread alloc] - initWithObject: conn]; + pepper = [[PEPThread alloc] initWithObject: conn]; [pepper start]; return YES; @@ -131,6 +151,15 @@ OF_APPLICATION_DELEGATE(AppDelegate) } } +- (void)connection: (XMPPConnection*)conn + didReceiveMessage: (XMPPMessage*)mesg +{ + if ([mesg.body isEqual: @"pause"]) { + [mpdConn send: @"pause"]; + [mpdConn response]; + } +} + - (void)connectionWasClosed: (XMPPConnection*)conn { [of_stdout writeLine: @"Connection was closed!"];