toggle between recordings sort order with 0 key

Message ID 4FB9265B.5090407@pilppa.org
State New
Headers

Commit Message

Mika Laitio May 20, 2012, 5:14 p.m. UTC
  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
  

Comments

Rene Hertell June 6, 2012, 7:07 a.m. UTC | #1
Hi Mika,

Thanks for this patch! Great to get this feature back that i have been 
missing since my recent upgrade from vdr 1.6 to 1.7

Would it be possible to enhance the patch so that you would get the 
directories also sorted separately: Directories before recordings / 
directories after recordings (i prefer the latter option) sorted by 
name... :-)

Regards,

René
On 20.05.2012 20:14 , Mika Laitio wrote:
> 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
>
>
>
> _______________________________________________
> vdr mailing list
> vdr@linuxtv.org
> http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr
  
Klaus Schmidinger June 6, 2012, 7:13 a.m. UTC | #2
On 06.06.2012 09:07, René wrote:
> Hi Mika,
>
> Thanks for this patch! Great to get this feature back that i have been missing since my recent upgrade from vdr 1.6 to 1.7
>
> Would it be possible to enhance the patch so that you would get the directories also sorted separately: Directories before recordings / directories after recordings (i prefer the latter option) sorted by name... :-)

The next developer version of VDR will contain sorting of recordings.
You will be able to toggle between sorting by date or alphabetically,
and that setting will be stored separately for each folder.
When sorted by date, folders will still be in alphabetical order and
will come first.

Klaus


> On 20.05.2012 20:14 , Mika Laitio wrote:
>> 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
  
Mika Laitio June 8, 2012, 7:58 a.m. UTC | #3
On 06/06/2012 10:13 AM, Klaus Schmidinger wrote:
> The next developer version of VDR will contain sorting of recordings.
> You will be able to toggle between sorting by date or alphabetically,
> and that setting will be stored separately for each folder.
> When sorted by date, folders will still be in alphabetical order and
> will come first.

Sounds great. I have also found out that sometimes it's useful to
be able to sort also by recordings length/size. It will help if you are
lack of space or want to clean up some couple of seconds/minutes
recordings one may have made mistakenly.

Mika
  

Patch

>From d15458f012c5463648ee25b163284f1db14d5f1c Mon Sep 17 00:00:00 2001
From: Mika Laitio <lamikr@pilppa.org>
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@pilppa.org>
---
 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