SVDRP MOVC

Message ID 1125218075.6330.4.camel@wopr.deltab.de
State New
Headers

Commit Message

Andreas Brachold Aug. 28, 2005, 8:34 a.m. UTC
  Hi,

here a patch to implement MOVC on SVDRP...

Andreas
  

Patch

--- svdrp.c.orig	2005-08-07 16:20:41.000000000 +0200
+++ svdrp.c	2005-08-28 10:27:32.000000000 +0200
@@ -965,8 +965,61 @@ 
 
 void cSVDRP::CmdMOVC(const char *Option)
 {
-  //TODO combine this with menu action (timers must be updated)
-  Reply(502, "MOVC not yet implemented");
+  if (!*Option) {
+    Reply(501, "Error in channel settings");
+    return;
+  }
+
+  if (Channels.BeingEdited() || Timers.BeingEdited()) {
+    Reply(550, "Channels or Timers are being edited - try again later");
+    return;
+  }
+
+  char *tail;
+  int From = strtol(Option, &tail, 10);
+  if (!tail || tail == Option) {
+    Reply(501, "Error in channel settings");
+    return;
+  }
+
+  tail = skipspace(tail);
+  if (!tail || tail == Option) {
+    Reply(501, "Error in channel settings");
+    return;
+  }
+
+  int To = strtol(tail, NULL, 10);
+  int CurrentChannelNr = cDevice::CurrentChannel();
+  cChannel *CurrentChannel = Channels.GetByNumber(CurrentChannelNr);
+  cChannel *FromChannel = Channels.GetByNumber(From);
+  if(!FromChannel) {
+    Reply(501, "Channel \"%d\" not defined", From);
+    return;
+  }
+
+  cChannel *ToChannel = Channels.GetByNumber(To);
+  if(!ToChannel) {
+    Reply(501, "Channel \"%d\" not defined", To);
+    return;
+  }
+
+  int FromNumber = FromChannel->Number();
+  int ToNumber = ToChannel->Number();
+  if(FromNumber == ToNumber) {
+    Reply(501, "Can't move Channel to same postion");
+    return;
+  }
+
+  Channels.Move(FromChannel, ToChannel);
+  Channels.ReNumber();
+  Channels.SetModified(true);
+
+  if (CurrentChannel && CurrentChannel->Number() != CurrentChannelNr)
+        Channels.SwitchTo(CurrentChannel->Number());
+
+  isyslog("channel %d moved to %d", FromNumber, ToNumber);
+  Reply(250, "Channel \"%d\" moved to \"%d\"", From, To);
+
 }
 
 void cSVDRP::CmdMOVT(const char *Option)