Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: [PATCH] vdr-1.3.18: sort channels by source



Luca Olivetti wrote:
This patch adds three more sort order, like the original ones but grouped by source. Additionally the source is always visible, so you know in advance if the dish is going to move.
Oops, wrong patch. This is the correct one.

Bye
--
- Yo también quiero una Europa libre de Patentes de Software  -
- I want a Software Patents Free Europe too! And you?         -
---------------------------------------------------------------
  EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es
--- 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());

Attachment: signature.asc
Description: OpenPGP digital signature


Home | Main Index | Thread Index