[vdr] Re: Reducing clutter in channels.conf

Lauri Tischler lwgt at iki.fi
Mon Jul 18 17:41:46 CEST 2005


Malcolm Caldwell wrote:

> Also, I like the sorting ability now in the channels menu.  I would like
> one more option: sort by source, where source is the value defined in
> sources.conf (eg the satellite names etc).  In my setup this would be
> quite useful.  (Sort by provider is not quite good enough - most c-band
> channels seem to have a provider of 'default provider' :) )

There's a patch for that, by Luca Olivetti.
-------------- next part --------------
--- menu.c.sortbysource	2005-01-09 16:42:26.532491562 +0100
+++ menu.c	2005-01-09 18:37:29.606277755 +0100
@@ -328,14 +328,14 @@
 
 class cMenuChannelItem : public cOsdItem {
 public:
-  enum eChannelSortMode { csmNumber, csmName, csmProvider };
+  enum eChannelSortMode { csmNumber, csmName, csmProvider, csmSourceNumber, csmSourceName, csmSourceProvider };
 private:
   static eChannelSortMode sortMode;
   cChannel *channel;
 public:
   cMenuChannelItem(cChannel *Channel);
   static void SetSortMode(eChannelSortMode SortMode) { sortMode = SortMode; }
-  static void IncSortMode(void) { sortMode = eChannelSortMode((sortMode == csmProvider) ? csmNumber : sortMode + 1); }
+  static void IncSortMode(void) { sortMode = eChannelSortMode((sortMode == csmSourceProvider) ? csmNumber : sortMode + 1); }
   virtual int Compare(const cListObject &ListObject) const;
   virtual void Set(void);
   cChannel *Channel(void) { return channel; }
@@ -352,10 +352,42 @@
   Set();
 }
 
+int snum(int source)
+{
+  int stype = (source & cSource::st_Mask);
+  // arbitrary order: sat, cable, terrestrial, none
+  int r;
+  switch(stype) {
+    case cSource::stCable: 
+      r=0x7FF0;
+      break;
+    case cSource::stTerr:
+      r=0x7FF2;
+      break;
+    case cSource::stSat: 
+      r=source & cSource::st_Pos;
+      if (source & cSource::st_Neg) r*=-1;
+      break;
+    default:  //stNone or unknown
+      r=0x7FFF;  
+  }
+  return r;    
+}
+
 int cMenuChannelItem::Compare(const cListObject &ListObject) const
 {
   cMenuChannelItem *p = (cMenuChannelItem *)&ListObject;
   int r = -1;
+  if (sortMode >= csmSourceNumber) {
+     int rsource = snum(channel->Source()) - snum(p->channel->Source());
+     if (sortMode == csmSourceProvider && rsource  == 0)
+        r = strcoll(channel->Provider(), p->channel->Provider());
+     if ((sortMode == csmSourceName || r == 0) && rsource == 0)
+        r = strcoll(channel->Name(), p->channel->Name());
+     if ((sortMode == csmSourceNumber || r == 0) && rsource == 0)
+        r = channel->Number() - p->channel->Number();
+     return ((rsource == 0) ? r : rsource);
+  }
   if (sortMode == csmProvider)
      r = strcoll(channel->Provider(), p->channel->Provider());
   if (sortMode == csmName || r == 0)
@@ -369,10 +401,10 @@
 {
   char *buffer = NULL;
   if (!channel->GroupSep()) {
-     if (sortMode == csmProvider)
-        asprintf(&buffer, "%d\t%s - %s", channel->Number(), channel->Provider(), channel->Name());
+     if (sortMode == csmProvider || sortMode == csmSourceProvider)
+        asprintf(&buffer, "%d\t%s %c %s - %s", channel->Number(), *cSource::ToString(channel->Source()), (sortMode >= csmSourceNumber) ? '*' : '-', channel->Provider(), channel->Name());
      else
-        asprintf(&buffer, "%d\t%s", channel->Number(), channel->Name());
+        asprintf(&buffer, "%d\t%s %c %s", channel->Number(), *cSource::ToString(channel->Source()), (sortMode >= csmSourceNumber) ? '*' : '-', channel->Name());
      }
   else
      asprintf(&buffer, "---\t%s ----------------------------------------------------------------", channel->Name());


More information about the vdr mailing list