summaryrefslogtreecommitdiff
path: root/mymenurenamerecording.c
blob: 646813e1f67d1ea7e83d0a6f8b3ea68455869048 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * See the README file for copyright information and how to reach the author.
 *
 */

#include <vdr/videodir.h>
#include <vdr/menu.h>
#include <vdr/remote.h>
#include "mymenurecordings.h"
#include "tools.h"

myMenuRenameRecording::myMenuRenameRecording(cRecording *Recording,myMenuRecordings *MenuRecordings):cOsdMenu(tr("Rename recording"),12)
{
 recording=Recording;
 priority=recording->priority;
 lifetime=recording->lifetime;
 menurecordings=MenuRecordings;
 
 char *p=strrchr(recording->Name(),'~');
 if(p)
 {
  strn0cpy(name,++p,sizeof(name));
  strn0cpy(path,recording->Name(),sizeof(path));
  
  p=strrchr(path,'~');
  if(p)
   *p=0;
 }
 else
 {
  strn0cpy(name,recording->Name(),sizeof(name));
  strn0cpy(path,"",sizeof(path));
 }
 Add(new cMenuEditStrItem(tr("Name"),name,sizeof(name),tr(FileNameChars)));
 Add(new cMenuEditIntItem(tr("Priority"),&priority,0,MAXPRIORITY));
 Add(new cMenuEditIntItem(tr("Lifetime"),&lifetime,0,MAXLIFETIME));
// cRemote::Put(kRight);
}

eOSState myMenuRenameRecording::ProcessKey(eKeys Key)
{
 eOSState state=cOsdMenu::ProcessKey(Key);
 if(state==osUnknown) // ==osContinue)
 {
  if(Key==kOk)
  {
   char *buffer;
   char *newfilename;
   
   if(strlen(path))
    asprintf(&buffer,"%s~%s",path,name);
   else
    asprintf(&buffer,"%s",name);
   
//   asprintf(&newfilename,"%s/%s/%s",VideoDirectory,ExchangeChars(buffer,true),strrchr(recording->FileName(),'/')+1);
   struct tm tm_r;
   struct tm *t=localtime_r(&recording->start, &tm_r);
   asprintf(&newfilename,"%s/%s/%d-%02d-%02d.%02d.%02d.%02d.%02d.rec",
                         VideoDirectory,
                         ExchangeChars(buffer,true),
                         t->tm_year+1900,
                         t->tm_mon+1,
                         t->tm_mday,
                         t->tm_hour,
                         t->tm_min,
                         priority,lifetime);

   if(MoveVideoFile(recording,newfilename))
   {
    menurecordings->Set(true);
    state=osBack;
   }
   else
   {
    Skins.Message(mtError,tr("Error while accessing recording!"));
    state=osContinue;
   }
   free(buffer);
   free(newfilename);
  }
//  if(Key==kBack)
//   return osBack;
 }
 return state;
}