summaryrefslogtreecommitdiff
path: root/recording.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2012-06-09 14:32:29 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2012-06-09 14:32:29 +0200
commit440c119b0a80d40d05f48613de46f367597a3f29 (patch)
treec2cfc9d7ab6a9c0d0670866d5af5248b6f9df8cf /recording.c
parent0b6c96a5159962c9263166613ee594bf89ae0a60 (diff)
downloadvdr-440c119b0a80d40d05f48613de46f367597a3f29.tar.gz
vdr-440c119b0a80d40d05f48613de46f367597a3f29.tar.bz2
Implemented sort mode for recordings
Diffstat (limited to 'recording.c')
-rw-r--r--recording.c66
1 files changed, 55 insertions, 11 deletions
diff --git a/recording.c b/recording.c
index 2a73645c..d13225be 100644
--- a/recording.c
+++ b/recording.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: recording.c 2.56 2012/06/03 09:51:27 kls Exp $
+ * $Id: recording.c 2.57 2012/06/09 13:57:30 kls Exp $
*/
#include "recording.h"
@@ -53,6 +53,8 @@
#define INFOFILESUFFIX "/info"
#define MARKSFILESUFFIX "/marks"
+#define SORTMODEFILE ".sort"
+
#define MINDISKSPACE 1024 // MB
#define REMOVECHECKDELTA 60 // seconds between checks for removing deleted files
@@ -610,7 +612,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
{
resume = RESUME_NOT_INITIALIZED;
titleBuffer = NULL;
- sortBuffer = NULL;
+ sortBufferName = sortBufferTime = NULL;
fileName = NULL;
name = NULL;
fileSizeMB = -1; // unknown
@@ -683,7 +685,7 @@ cRecording::cRecording(const char *FileName)
numFrames = -1;
deleted = 0;
titleBuffer = NULL;
- sortBuffer = NULL;
+ sortBufferName = sortBufferTime = NULL;
FileName = fileName = strdup(FileName);
if (*(fileName + strlen(fileName) - 1) == '/')
*(fileName + strlen(fileName) - 1) = 0;
@@ -795,7 +797,8 @@ cRecording::cRecording(const char *FileName)
cRecording::~cRecording()
{
free(titleBuffer);
- free(sortBuffer);
+ free(sortBufferName);
+ free(sortBufferTime);
free(fileName);
free(name);
delete info;
@@ -816,22 +819,27 @@ char *cRecording::StripEpisodeName(char *s)
}
t++;
}
- if (s1 && s2)
- memmove(s1 + 1, s2, t - s2 + 1);
+ if (s1 && s2) {
+ s1++;
+ memmove(s1, s2, t - s2 + 1);
+ *s1 = 0xFF; // sorts folders before plain recordings
+ }
return s;
}
char *cRecording::SortName(void) const
{
- if (!sortBuffer) {
- char *s = StripEpisodeName(strdup(FileName() + strlen(VideoDirectory) + 1));
+ char **sb = (RecordingsSortMode == rsmName) ? &sortBufferName : &sortBufferTime;
+ if (!*sb) {
+ char *s = (RecordingsSortMode == rsmName) ? strdup(FileName() + strlen(VideoDirectory) + 1)
+ : StripEpisodeName(strdup(FileName() + strlen(VideoDirectory) + 1));
strreplace(s, '/', 'a'); // some locales ignore '/' when sorting
int l = strxfrm(NULL, s, 0) + 1;
- sortBuffer = MALLOC(char, l);
- strxfrm(sortBuffer, s, l);
+ *sb = MALLOC(char, l);
+ strxfrm(*sb, s, l);
free(s);
}
- return sortBuffer;
+ return *sb;
}
int cRecording::GetResume(void) const
@@ -2133,3 +2141,39 @@ int ReadFrame(cUnbufferedFile *f, uchar *b, int Length, int Max)
LOG_ERROR;
return r;
}
+
+// --- Recordings Sort Mode --------------------------------------------------
+
+eRecordingsSortMode RecordingsSortMode = rsmName;
+
+bool HasRecordingsSortMode(const char *Directory)
+{
+ return access(AddDirectory(Directory, SORTMODEFILE), R_OK) == 0;
+}
+
+void GetRecordingsSortMode(const char *Directory)
+{
+ if (FILE *f = fopen(AddDirectory(Directory, SORTMODEFILE), "r")) {
+ char buf[8];
+ if (fgets(buf, sizeof(buf), f))
+ RecordingsSortMode = eRecordingsSortMode(constrain(atoi(buf), 0, int(rsmTime)));
+ fclose(f);
+ }
+}
+
+void SetRecordingsSortMode(const char *Directory, eRecordingsSortMode SortMode)
+{
+ if (FILE *f = fopen(AddDirectory(Directory, SORTMODEFILE), "w")) {
+ fputs(cString::sprintf("%d\n", SortMode), f);
+ fclose(f);
+ }
+}
+
+void IncRecordingsSortMode(const char *Directory)
+{
+ GetRecordingsSortMode(Directory);
+ RecordingsSortMode = eRecordingsSortMode(int(RecordingsSortMode) + 1);
+ if (RecordingsSortMode > rsmTime)
+ RecordingsSortMode = eRecordingsSortMode(0);
+ SetRecordingsSortMode(Directory, RecordingsSortMode);
+}