]> git.babelmonkeys.de Git - mpdbot.git/commitdiff
Initial command support master
authorFlorian Zeitz <florob@babelmonkeys.de>
Thu, 5 Jul 2012 22:06:14 +0000 (00:06 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Thu, 5 Jul 2012 22:06:14 +0000 (00:06 +0200)
src/PEPThread.h
src/mpdbot.m

index a752ecad6fc347d1ceae94af0145920915821c93..19663abaadb2bc07de0159850371b8e176862a89 100644 (file)
@@ -24,6 +24,6 @@
 
 @interface PEPThread: OFThread
 {
 
 @interface PEPThread: OFThread
 {
-MPDConnection *conn;
+       MPDConnection *conn;
 }
 @end
 }
 @end
index eb92876880af712e30f7ee333ce276ed681dea54..8ef781b51057eb7dc1a0ccb2df1a30ae30b03701 100644 (file)
@@ -31,6 +31,7 @@
 @interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
 {
        PEPThread *pepper;
 @interface AppDelegate: OFObject <OFApplicationDelegate, XMPPConnectionDelegate>
 {
        PEPThread *pepper;
+       MPDConnection *mpdConn;
 }
 @end
 
 }
 @end
 
@@ -40,6 +41,12 @@ OF_APPLICATION_DELEGATE(AppDelegate)
 - (void)applicationDidFinishLaunching
 {
        XMPPConnection *conn;
 - (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];
        OFArray *arguments = [OFApplication arguments];
 
        conn = [[XMPPConnection alloc] init];
@@ -56,6 +63,20 @@ OF_APPLICATION_DELEGATE(AppDelegate)
        conn.password = [arguments objectAtIndex: 2];
        conn.resource = @"ObjXMPP";
 
        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];
        @try {
                [conn connect];
                [conn handleConnection];
@@ -107,8 +128,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
                    stringValue] isEqual: @"pubsub"] &&
                    [[[identity attributeForName: @"type"] stringValue]
                    isEqual: @"pep"]) {
                    stringValue] isEqual: @"pubsub"] &&
                    [[[identity attributeForName: @"type"] stringValue]
                    isEqual: @"pep"]) {
-                       pepper = [[PEPThread alloc]
-                           initWithObject: conn];
+                       pepper = [[PEPThread alloc] initWithObject: conn];
                        [pepper start];
 
                        return YES;
                        [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!"];
 - (void)connectionWasClosed: (XMPPConnection*)conn
 {
        [of_stdout writeLine: @"Connection was closed!"];