Mailing List archive

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

[vdr] vdr-1.2.1-calendar-patch



Hi,

As I like the calendar-patch, I made a diff vor the latest vdr-1.2.1.
Maybe you like it. (I do!)

I have not coded this patch, just adjusted, so it fits to newer 
vdr-versions (some bits shameless stolen from vdr-"nessy"-version, that I 
can't use 'cause I only own a Nova and a DXR3).  

This is what it looks like:
http://www.vdrportal.de/board/gallery/details.php?image_id=29

to patch (well, you know how to do this, but anyway):
cd /your/vdr-1.2.1/dir/
patch -p1 -E < /path/to/patch/vdr-1.2.1-calendar.diff

To see the calendar:
Press Menu - Schedule
(direkt call like the green button gives the old schedule; that's not a bug 
but a feature!) 

Frank (aka Taros666)














diff -U 3 -H -b -B -d -N -a -- vdr-1.2.1/Makefile vdr-1.2.1calendar/Makefile
--- vdr-1.2.1/Makefile	Mon Jan  6 13:28:09 2003
+++ vdr-1.2.1calendar/Makefile	Mon Jun  9 20:20:48 2003
@@ -41,6 +41,8 @@
 OSDFONT = -adobe-helvetica-medium-r-normal--23-*-100-100-p-*-iso8859-1
 FIXFONT = -adobe-courier-bold-r-normal--25-*-100-100-m-*-iso8859-1
 
+DEFINES += -DCALENDER
+
 ifndef NO_KBD
 DEFINES += -DREMOTE_KBD
 endif
Common subdirectories: vdr-1.2.1/PLUGINS and vdr-1.2.1calendar/PLUGINS
diff -U 3 -H -b -B -d -N -a -- vdr-1.2.1/i18n.c vdr-1.2.1calendar/i18n.c
--- vdr-1.2.1/i18n.c	Mon Jun  9 20:22:55 2003
+++ vdr-1.2.1calendar/i18n.c	Mon Jun  9 20:50:07 2003
@@ -328,7 +328,7 @@
     "Què fan ara?",
   },
   { "What's on next?",
-    "Was läuft als nächstes?",
+    "Was als nächstes?",
     "Kaj sledi?",
     "Prossimi programmi",
     "Wat komt er hierna?",
Common subdirectories: vdr-1.2.1/libdtv and vdr-1.2.1calendar/libdtv
diff -U 3 -H -b -B -d -N -a -- vdr-1.2.1/menu.c vdr-1.2.1calendar/menu.c
--- vdr-1.2.1/menu.c	Mon Jun  9 20:22:55 2003
+++ vdr-1.2.1calendar/menu.c	Mon Jun  9 21:37:42 2003
@@ -26,6 +26,9 @@
 #include "status.h"
 #include "timers.h"
 #include "videodir.h"
+#ifdef CALENDER
+#include <assert.h>
+#endif // CALENDER
 
 #define MENUTIMEOUT     120 // seconds
 #define MAXWAIT4EPGINFO   3 // seconds
@@ -1172,6 +1175,399 @@
   return state;
 }
 
+#ifdef CALENDER
+
+static int CompareSchedules(const void *p1, const void *p2)
+{
+
+  int c1nr=9999; // there should be no one with more than 9999 channels
+  int c2nr=9999;
+  
+  cChannel *c2 = Channels.GetByChannelID((*(const cSchedule **)p2)->GetChannelID());
+  if( c2 ) c2nr = c2->Number();
+
+  cChannel *c1 = Channels.GetByChannelID((*(const cSchedule **)p1)->GetChannelID());
+  if( c1 ) c1nr = c1->Number();
+
+  return
+    c1nr - c2nr; 
+}
+
+// --- cMenuWhatsOnCalItem ------------------------------------------------------
+
+#define cMenuWhatsOnCalStart (120) 
+#define cMenuWhatsOnCalSize  (500)
+#define cMenuWhatsOnCalTimeIntervall (2*60*60) // in seconds 
+#define cMenuWhatsOnCalinter (60*30)
+
+class cMenuWhatsOnCalItem : public cOsdItem {
+public:
+  //  const cEventInfo *eventInfo;
+  cMenuWhatsOnCalItem(const cSchedule *Schedule, time_t *now);
+  ~cMenuWhatsOnCalItem();
+  virtual void Display(int Offset = -1, eDvbColor FgColor = clrWhite, eDvbColor BgColor = clrBackground);
+ protected:
+  cBitmap *progressBar;
+  bool showProgressBar;
+  float percent;
+#define MAX_SPLITS 50  
+  
+  int maxelem;
+  int von[MAX_SPLITS],bis[MAX_SPLITS],now_in_pixel;
+  const char *title[MAX_SPLITS]; 
+  
+private:
+  void DrawProgressBar(eDvbColor FgColor, eDvbColor BgColor);
+  void CalcNew(void);
+  time_t *now;
+ 
+ public:
+  const cSchedule *schedule;
+};
+
+cMenuWhatsOnCalItem::~cMenuWhatsOnCalItem(){
+  /*  if( progressBar )
+      delete progressBar;*/
+}
+
+static void WriteTexttoBitmap(cBitmap *bitm,const char *text,int posx,int maxx,bool center,eDvbColor FgColor, eDvbColor BgColor){
+  
+  int maxlen = maxx-posx-6;
+  // count size of text;
+      
+  int count=0;
+  while(text[count] != '\0' && maxlen > 0){
+    maxlen -= cOsd::Width(text[count]);
+    count++;
+  }
+  if( maxlen < 0 ) // string is to big 
+    count--;       // else string is small enough
+  
+  // center the text:
+  if( maxlen < 0 || !center ) maxlen=0;
+  
+  if( count > 0 ){
+    char *shortertext= NULL;
+    asprintf(&shortertext, "%.*s", count , text);
+    bitm->Text(posx+3+(maxlen/2),1,shortertext , FgColor ,BgColor); 
+  }
+}
+
+void cMenuWhatsOnCalItem::DrawProgressBar(eDvbColor FgColor, eDvbColor BgColor)
+{
+  assert(progressBar != NULL ); 
+
+  int width = progressBar->Width();
+  int height = progressBar->Height();
+
+  progressBar->Fill(0, 0, width-1, height-1, BgColor);
+
+  // Write Text first ( clears lines with big fonts )
+  // write the text into the cells
+  for(int i=0;i<maxelem;i++){
+    WriteTexttoBitmap(progressBar,title[i],von[i],bis[i],true,FgColor,BgColor);
+  }
+
+  for(int x=0;x<width;x++) {
+    progressBar->SetPixel(x, 0, FgColor);
+    progressBar->SetPixel(x, 1, FgColor);
+
+    progressBar->SetPixel(x,height-1, FgColor);
+    progressBar->SetPixel(x,height-2, FgColor);
+
+  }
+  
+  // draw the splits 
+  for(int i=0;i<maxelem;i++){
+    for(int y=0;y<progressBar->Height();y++){
+      if(von[i] > 0 ){
+        progressBar->SetPixel(von[i], y, FgColor);
+        progressBar->SetPixel(von[i]-1, y, FgColor);
+      }
+      if(bis[i] < width-1 ){
+        progressBar->SetPixel(bis[i], y, FgColor);
+        progressBar->SetPixel(bis[i]+1, y, FgColor);
+      }
+    } 
+  }
+
+  // Draw NOW-LINE
+  if(now_in_pixel != -1){
+    for(int y=0;y<(progressBar->Height()-1);y+=4){
+      progressBar->SetPixel(now_in_pixel, y, FgColor);
+      progressBar->SetPixel(now_in_pixel,   y+1, FgColor);
+      if( now_in_pixel+1 < progressBar->Width()-1){
+        progressBar->SetPixel(now_in_pixel+1, y, FgColor);
+        progressBar->SetPixel(now_in_pixel+1, y+1, FgColor);
+      }
+    }
+  }
+
+
+}
+void cMenuWhatsOnCalItem::CalcNew(void){
+  
+  maxelem=0;
+  
+  now_in_pixel =(int) (((float)( time(NULL) - (*now) )*(float)cMenuWhatsOnCalSize)/ (float)cMenuWhatsOnCalTimeIntervall) ;
+  
+  if (  now_in_pixel < 0 )  now_in_pixel =-1;
+  if (  now_in_pixel >cMenuWhatsOnCalSize)  now_in_pixel =-1;
+  
+ 
+  for(int i=0;i< schedule->NumEvents(); i++){
+    const cEventInfo *inf; 
+    inf = schedule->GetEventNumber(i);
+    if( inf ){ 
+      
+      title[maxelem]=inf->GetTitle();
+      long starttime = inf->GetTime() - (*now);
+      von[maxelem] =(int)( ((float)starttime*(float)cMenuWhatsOnCalSize) / (float)cMenuWhatsOnCalTimeIntervall) ;
+      if(von[maxelem]<0) von[maxelem]=0;
+      if(von[maxelem]>cMenuWhatsOnCalSize) von[maxelem]=cMenuWhatsOnCalSize;
+      
+      long endtime = inf->GetTime() - (*now) + inf->GetDuration() ;
+      bis[maxelem] =(int)( ((float)endtime*(float)cMenuWhatsOnCalSize) / (float)cMenuWhatsOnCalTimeIntervall) ;
+      if(bis[maxelem]>cMenuWhatsOnCalSize) bis[maxelem] = cMenuWhatsOnCalSize;
+      if(bis[maxelem]<0) bis[maxelem]=0;
+      
+      if((starttime >= 0 && starttime < (cMenuWhatsOnCalTimeIntervall)) ||
+         (endtime   >= 0 && endtime   < (cMenuWhatsOnCalTimeIntervall))){
+        
+        assert ( maxelem < MAX_SPLITS );
+        maxelem++;
+      }
+    }
+  }
+}
+
+cMenuWhatsOnCalItem::cMenuWhatsOnCalItem(const cSchedule *Schedule,
+                                   time_t *Now)
+{
+  now=Now;
+  schedule=Schedule;
+  progressBar = NULL;
+  
+  char *buffer = NULL;
+  cChannel *channel = Channels.GetByChannelID(schedule->GetChannelID());
+  asprintf(&buffer, "%.*s", 10, channel ? channel->Name() : "???");
+  SetText(buffer, false);
+  
+  progressBar = new cBitmap(cMenuWhatsOnCalSize, 27, 2);
+}
+
+void cMenuWhatsOnCalItem::Display(int Offset, eDvbColor FgColor, eDvbColor BgColor)
+{
+  // DISPLAY this ITEM with aktual time.
+  CalcNew();
+  // DRAW it on Screen
+  cOsdItem::Display(Offset, FgColor, BgColor);
+  
+  if( progressBar){
+    DrawProgressBar(userColor ? fgColor : FgColor, userColor ? bgColor : BgColor);
+    Interface->SetBitmap(cMenuWhatsOnCalStart, (offset+2)*27, *progressBar); 
+  }
+}
+// --- cMenuWhatsOnCal ----------------------------------------------------------
+class cMenuWhatsOnCal : public cOsdMenu {
+private:
+ 
+  eOSState Switch(void);
+  static time_t jetzt;
+  static int currentChannel;
+  cBitmap *timeLine;
+  void ChangeTimeLine(eDvbColor FgColor=clrWhite, eDvbColor BgColor=clrBackground);
+public:
+  cMutexLock mutexLock;
+  cMenuWhatsOnCal();
+  ~cMenuWhatsOnCal();
+  static int CurrentChannel(void) { return currentChannel; }
+  static void SetCurrentChannel(int ChannelNr) { currentChannel = ChannelNr; }
+  virtual eOSState ProcessKey(eKeys Key);
+  };
+
+time_t cMenuWhatsOnCal::jetzt=0;
+int cMenuWhatsOnCal::currentChannel=0;
+
+#define cMenuWhatsOnCalMore 30 
+
+cMenuWhatsOnCal::~cMenuWhatsOnCal(){
+  /* if(timeLine)
+     delete timeLine ; */
+}
+
+void cMenuWhatsOnCal::ChangeTimeLine(eDvbColor FgColor, eDvbColor BgColor){
+
+  if(timeLine){
+    int width = timeLine->Width();
+    int height = timeLine->Height();
+    timeLine->Fill(0, 0, width-1, height-1, BgColor);
+    /*    
+          // BORDER OF IMAGE
+          for(int x=0;x<width;x++){
+          timeLine->SetPixel(x,0,FgColor);
+          timeLine->SetPixel(x,height-1,FgColor);
+          }
+          for(int y=0;y<height;y++){
+          timeLine->SetPixel(0,y,FgColor);
+          timeLine->SetPixel(width-1,y,FgColor);
+          }
+    */
+            
+    int interv =  (cMenuWhatsOnCalSize*cMenuWhatsOnCalinter)/cMenuWhatsOnCalTimeIntervall;
+    time_t j = jetzt;  // hope this copys 
+    
+    int sizetime =  (cOsd::Width('5')*5)/2;
+  
+
+    // insert times
+    for(int x=cMenuWhatsOnCalMore;x<width;x+=(interv)){ // entry every 30 Minutes.
+      if( (x-sizetime) > 0 && (x+sizetime) < (width-1) ){
+        timeLine->SetPixel(x+1, height-2, FgColor);
+        timeLine->SetPixel(x+1, height-3, FgColor);
+        timeLine->SetPixel(x-1, height-2, FgColor);
+        timeLine->SetPixel(x-1, height-3, FgColor);
+        timeLine->SetPixel(x, height-4, FgColor);
+        // write timestamp here 
+        static char szTime[25];
+        struct tm tm_r;
+        strftime(szTime, sizeof(szTime), "%R", localtime_r(&j, &tm_r));
+        // printf("Time: %s \n", szTime);
+        
+        WriteTexttoBitmap(timeLine,szTime,x-sizetime,width,false,FgColor,BgColor);
+      }
+      j +=cMenuWhatsOnCalinter;
+    }
+    
+    // draw line  
+    for(int x=cMenuWhatsOnCalMore;x<width;x++){
+      timeLine->SetPixel(x, height-1, FgColor);
+      timeLine->SetPixel(x, height-2, FgColor);
+    }
+    
+    SetTitleTime( tr("What's on now?") ,timeLine,cMenuWhatsOnCalStart-cMenuWhatsOnCalMore,27);
+  }
+}
+
+
+cMenuWhatsOnCal::cMenuWhatsOnCal()
+  :cOsdMenu( tr("What's on now?") , 12, 6){
+
+  const cSchedules *Schedules;
+
+  Schedules = cSIProcessor::Schedules(mutexLock);
+  currentChannel = Channels.GetByNumber(cDevice::CurrentChannel())->Number();
+  
+  // get into "jetzt" a time which is roundet ( 15 min ) 
+  jetzt = time(NULL); 
+  jetzt -= 60*10;     // startline should be not at start 
+  // try this one ???? 
+  bool timok=true; 
+  do{
+    static char szTime[25];
+    struct tm tm_r;
+    strftime(szTime, sizeof(szTime), "%R", localtime_r(&jetzt, &tm_r));
+    if( ( szTime[3] == '1' && szTime[4] == '5') 
+        ||  ( szTime[3] == '0' && szTime[4] == '0') 
+        ||  ( szTime[3] == '3' && szTime[4] == '0')
+        ||  ( szTime[3] == '4' && szTime[4] == '5')  ) timok=false;
+    else
+      jetzt -=60;
+  }while( timok );
+  // tried it this way -> but could be done better 
+  
+  timeLine=NULL;
+  timeLine = new cBitmap(cMenuWhatsOnCalSize+cMenuWhatsOnCalMore, 27, 2);
+  ChangeTimeLine();
+  
+  const cSchedule *Schedule = Schedules->First();
+  // const cEventInfo **pArray = NULL;
+  const cSchedule **pArray = NULL;
+  
+  int num = 0;
+  while (Schedule) {
+    pArray = (const cSchedule **)realloc(pArray, (num + 1) * sizeof(cSchedule *));
+    
+    if( Schedule->GetPresentEvent() ){ // if there exist an event -> ad to array
+      // check if we can get a channel NAME ( XXX )
+      // I thougt that this must always work , but doesn't 
+      cChannel *c = Channels.GetByChannelID(Schedule->GetChannelID());
+      if( c ){
+        pArray[num] = Schedule;
+        num++;
+      }
+    }
+    Schedule = (const cSchedule *)Schedules->Next(Schedule);
+  }
+  
+  qsort(pArray, num, sizeof(cSchedule *),CompareSchedules);
+  // Channels sorted 
+  
+  for (int a = 0; a < num; a++)
+    if( pArray[a] )
+      Add(new cMenuWhatsOnCalItem(pArray[a], &jetzt), Channels.GetByChannelID(pArray[a]->GetChannelID())->Number() ==  currentChannel);
+  
+  SetHelp(NULL, tr("Back") , tr("Next"), tr("Switch"));
+  // delete all things never used
+  delete pArray;
+}
+
+eOSState cMenuWhatsOnCal::Switch(void)
+{
+  cMenuWhatsOnCalItem *item = (cMenuWhatsOnCalItem *)Get(Current());
+  if (item) {
+    cChannel *channel =  Channels.GetByChannelID(item->schedule->GetChannelID());
+    //   Channels.GetByNumber(item->eventInfo->GetChannelNumber());
+    //if (channel && channel->Switch()){
+    if (channel ){
+      // printf("\nSwitched to Channel %d ",channel->number);
+      return osEnd;
+    }
+  }
+  Interface->Error(tr("Can't switch channel!"));
+  return osContinue;
+}
+
+eOSState cMenuWhatsOnCal::ProcessKey(eKeys Key)
+{
+  eOSState state = cOsdMenu::ProcessKey(Key);
+
+  if (state == osUnknown) {
+    switch (Key) {
+    case kYellow:
+      jetzt += (30*60);//  30 Minutes time back 
+      ChangeTimeLine();
+      Display();
+      return osContinue;  
+      break;
+    case kGreen: // set time into future 
+      jetzt -= (30*60);
+      ChangeTimeLine();
+      Display();
+      return osContinue;
+      break;
+      
+    case kBlue:
+      return Switch();
+      break;
+      
+      // XXX DOESNT , WORK ALLWAYS XXX
+      // should show Listing of Programms on this Channel
+    case kOk:
+    	return osSchedule;
+        break;
+
+      break;
+
+
+     default:
+       break;
+     }
+  }
+  return state;
+}
+ 
+#endif // CALENDER
 // --- cMenuWhatsOnItem ------------------------------------------------------
 
 class cMenuWhatsOnItem : public cOsdItem {
@@ -2449,7 +2845,7 @@
 
   // Basic menu items:
 
-  Add(new cOsdItem(hk(tr("Schedule")),   osSchedule));
+  Add(new cOsdItem(hk(tr("Schedule")),   osScheduleEPG));
   Add(new cOsdItem(hk(tr("Channels")),   osChannels));
   Add(new cOsdItem(hk(tr("Timers")),     osTimers));
   Add(new cOsdItem(hk(tr("Recordings")), osRecordings));
@@ -2516,6 +2912,9 @@
 
   switch (state) {
     case osSchedule:   return AddSubMenu(new cMenuSchedule);
+#ifdef CALENDER
+    case osScheduleEPG:  return AddSubMenu(new cMenuWhatsOnCal); 
+#endif
     case osChannels:   return AddSubMenu(new cMenuChannels);
     case osTimers:     return AddSubMenu(new cMenuTimers);
     case osRecordings: return AddSubMenu(new cMenuRecordings);
diff -U 3 -H -b -B -d -N -a -- vdr-1.2.1/osd.c vdr-1.2.1calendar/osd.c
--- vdr-1.2.1/osd.c	Mon Jun  9 20:22:55 2003
+++ vdr-1.2.1calendar/osd.c	Mon Jun  9 20:08:51 2003
@@ -382,6 +382,15 @@
      title = strdup(Title);
 }
 
+#ifdef CALENDER
+void cOsdMenu::SetTitleTime(const char *Title, cBitmap *TitleTime, int Tlx,int Tly,bool ShowDate){
+  SetTitle(Title, ShowDate);
+  titleTimeLine=TitleTime;
+  titleTimeLiney=Tly;
+  titleTimeLinex=Tlx;
+}
+#endif // CALENDER
+
 void cOsdMenu::SetHelp(const char *Red, const char *Green, const char *Yellow, const char *Blue)
 {
   // strings are NOT copied - must be constants!!!
@@ -426,6 +435,10 @@
   Interface->Clear();
   Interface->SetCols(cols);
   Interface->Title(title);
+#ifdef CALENDER
+  if (titleTimeLine)
+    Interface->SetBitmap(titleTimeLinex, titleTimeLiney, *titleTimeLine);
+#endif // CALENDER
   Interface->Help(helpRed, helpGreen, helpYellow, helpBlue);
   int count = Count();
   if (count > 0) {
diff -U 3 -H -b -B -d -N -a -- vdr-1.2.1/osd.h vdr-1.2.1calendar/osd.h
--- vdr-1.2.1/osd.h	Mon Apr 21 12:27:41 2003
+++ vdr-1.2.1calendar/osd.h	Mon Jun  9 20:11:39 2003
@@ -50,6 +50,9 @@
                 osUser8,
                 osUser9,
                 osUser10,
+#ifdef CALENDER
+                osScheduleEPG,
+#endif
               };
 
 class cOsd {
@@ -91,9 +94,9 @@
 class cOsdItem : public cListObject {
 private:
   char *text;
-  int offset;
   eOSState state;
 protected:
+  int offset;
   bool fresh;
   bool userColor;
   eDvbColor fgColor, bgColor;
@@ -137,6 +140,10 @@
   char *status;
   int digit;
   bool hasHotkeys;
+#ifdef CALENDER
+  cBitmap *titleTimeLine;
+  int titleTimeLiney,titleTimeLinex;
+#endif // CALENDER
 protected:
   bool visible;
   const char *hk(const char *s);
@@ -157,6 +164,9 @@
   bool HasSubMenu(void) { return subMenu; }
   void SetStatus(const char *s);
   void SetTitle(const char *Title, bool ShowDate = true);
+#ifdef CALENDER
+  void SetTitleTime(const char *Title,cBitmap *TitleTime, int Tlx,int Tly,bool ShowDate = true);
+#endif // CALENDER
   void SetHelp(const char *Red, const char *Green = NULL, const char *Yellow = NULL, const char *Blue = NULL);
   virtual void Del(int Index);
 public:

Home | Main Index | Thread Index