[PATCH] toggle between recordings sort order with 0 key

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

 



Hi

Attached is a patch which allows to toggle the sort order
of recordings in the recording menu with vdr-1.7.27 between
- name
- date
- recording length

by pressing 0 key. At least I have found this to be very useful
feature when trying to find a just made recording from which you
do not know/remember the exact name to search from the long list of
recordings.

The thing I do not like in the patch is that the user must know this "0"
key as all 4 colors are already reserved in VDR for other functions in
recordings menu. (play, go to beginning, delete and info).
But I do not know any better way to handle this at the moment.

Patch got inspiration from
http://www.u32.de/vdr-1.3.37-simple_record_sort-0.1.diff
originally submitted by Walter Koch some years ago.

Mika
>From d15458f012c5463648ee25b163284f1db14d5f1c Mon Sep 17 00:00:00 2001
From: Mika Laitio <lamikr@xxxxxxxxxx>
Date: Sun, 20 May 2012 19:45:40 +0300
Subject: [PATCH] toggle between recordings sort order with 0 key

By default the recordings are sorted in the
recordings menu in alphabetical order just like
previously. But now the user can toggle between
following sorting rules by pressing the 0 key:
- sort by recordings name
- sort by recordings date
- sort by recordings length

Patch got inspiration from
http://www.u32.de/vdr-1.3.37-simple_record_sort-0.1.diff
originally submitted by Walter Koch.

Signed-off-by: Mika Laitio <lamikr@xxxxxxxxxx>
---
 menu.c      |   11 +++++++++++
 recording.c |   30 +++++++++++++++++++++++++++++-
 recording.h |    2 ++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/menu.c b/menu.c
index ad1cac3..4fcb16d 100644
--- a/menu.c
+++ b/menu.c
@@ -2470,6 +2470,17 @@ eOSState cMenuRecordings::ProcessKey(eKeys Key)
        case kInfo:
        case kBlue:   return Info();
        case k1...k9: return Commands(Key);
+       case k0:      SortingRule++;
+                     if (SortingRule >= 3)
+                        SortingRule = 0;
+                     if (SortingRule == 0)
+                       Skins.Message(mtInfo, tr("Sorting recordings by name"));
+                     else if (SortingRule == 1)
+                       Skins.Message(mtInfo, tr("Sorting recordings by date"));
+                     else
+                       Skins.Message(mtInfo, tr("Sorting recordings by length"));
+                     Set(true);
+                     return osContinue;
        case kNone:   if (Recordings.StateChanged(recordingsState))
                         Set(true);
                      break;
diff --git a/recording.c b/recording.c
index e1f7ec9..42d554d 100644
--- a/recording.c
+++ b/recording.c
@@ -68,6 +68,7 @@
 
 bool VfatFileSystem = false;
 int InstanceId = 0;
+int SortingRule = 0;
 
 cRecordings DeletedRecordings(true);
 
@@ -842,7 +843,21 @@ int cRecording::GetResume(void) const
 int cRecording::Compare(const cListObject &ListObject) const
 {
   cRecording *r = (cRecording *)&ListObject;
-  return strcasecmp(SortName(), r->SortName());
+  int ret;
+
+  switch(SortingRule) {
+    // sort by recording name
+    case 0:
+    default:ret = strcasecmp(SortName(), r->SortName());
+            break;
+    // sort by recording date that is stored in BaseFileName
+    case 1: ret = strcasecmp(BaseFileName(), r->BaseFileName());
+            break;
+    // sort by recording length
+    case 2: ret = (LengthInSeconds() > r->LengthInSeconds());
+            break;
+  }
+  return ret; 
 }
 
 const char *cRecording::FileName(void) const
@@ -860,6 +875,19 @@ const char *cRecording::FileName(void) const
   return fileName;
 }
 
+const char *cRecording::BaseFileName(void) const
+{
+  const char *s;
+  const char *fullname;
+
+  fullname = FileName();
+  s = strrchr(fullname, '/');
+  if (s)
+    return s + 1;
+  else
+    return fullname;
+}
+
 const char *cRecording::Title(char Delimiter, bool NewIndicator, int Level) const
 {
   char New = NewIndicator && IsNew() ? '*' : ' ';
diff --git a/recording.h b/recording.h
index 5f94ee2..37e970f 100644
--- a/recording.h
+++ b/recording.h
@@ -26,6 +26,7 @@
 
 extern bool VfatFileSystem;
 extern int InstanceId;
+extern int SortingRule; 
 
 void RemoveDeletedRecordings(void);
 void AssertFreeDiskSpace(int Priority = 0, bool Force = false);
@@ -118,6 +119,7 @@ public:
   virtual int Compare(const cListObject &ListObject) const;
   const char *Name(void) const { return name; }
   const char *FileName(void) const;
+  const char *BaseFileName(void) const;
   const char *Title(char Delimiter = ' ', bool NewIndicator = false, int Level = -1) const;
   const cRecordingInfo *Info(void) const { return info; }
   const char *PrefixFileName(char Prefix);
-- 
1.7.10

_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux