diff -Nru vdr-1.6.0/config.c vdr-1.6.0-sortrec_v3b/config.c --- vdr-1.6.0/config.c 2008-04-07 21:13:43.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/config.c 2008-04-07 21:16:59.000000000 +0200 @@ -256,6 +256,8 @@ UseVps = 0; VpsMargin = 120; RecordingDirs = 1; + RecordingsSortMode = 0; + RecordingsSortDirsFirst = 0; VideoDisplayFormat = 1; VideoFormat = 0; UpdateChannels = 5; @@ -435,6 +437,8 @@ else if (!strcasecmp(Name, "UseVps")) UseVps = atoi(Value); else if (!strcasecmp(Name, "VpsMargin")) VpsMargin = atoi(Value); else if (!strcasecmp(Name, "RecordingDirs")) RecordingDirs = atoi(Value); + else if (!strcasecmp(Name, "RecordingsSortMode")) RecordingsSortMode = atoi(Value); + else if (!strcasecmp(Name, "RecordingsSortDirsFirst")) RecordingsSortDirsFirst = atoi(Value); else if (!strcasecmp(Name, "VideoDisplayFormat")) VideoDisplayFormat = atoi(Value); else if (!strcasecmp(Name, "VideoFormat")) VideoFormat = atoi(Value); else if (!strcasecmp(Name, "UpdateChannels")) UpdateChannels = atoi(Value); @@ -524,6 +528,8 @@ Store("UseVps", UseVps); Store("VpsMargin", VpsMargin); Store("RecordingDirs", RecordingDirs); + Store("RecordingsSortMode", RecordingsSortMode); + Store("RecordingsSortDirsFirst", RecordingsSortDirsFirst); Store("VideoDisplayFormat", VideoDisplayFormat); Store("VideoFormat", VideoFormat); Store("UpdateChannels", UpdateChannels); diff -Nru vdr-1.6.0/config.h vdr-1.6.0-sortrec_v3b/config.h --- vdr-1.6.0/config.h 2008-04-07 21:13:43.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/config.h 2008-04-07 21:17:21.000000000 +0200 @@ -273,6 +273,8 @@ int InitialVolume; int EmergencyExit; int ShowRecDate, ShowRecTime, ShowRecLength, ShowProgressBar, MenuCmdPosition; + int RecordingsSortMode; + int RecordingsSortDirsFirst; int __EndData__; cSetup(void); cSetup& operator= (const cSetup &s); diff -Nru vdr-1.6.0/menu.c vdr-1.6.0-sortrec_v3b/menu.c --- vdr-1.6.0/menu.c 2008-04-07 21:13:43.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/menu.c 2008-04-07 21:21:10.000000000 +0200 @@ -2338,6 +2338,12 @@ eOSState state = cOsdMenu::ProcessKey(Key); if (state == osUnknown) { + const char *RecordingsSortModeTexts[MAXSORTMODES]; + RecordingsSortModeTexts[0] = tr("main dir alphabetically, subdirs flexible"); + RecordingsSortModeTexts[1] = tr("main dir by date, subdirs flexible"); + RecordingsSortModeTexts[2] = tr("all alphabetically"); + RecordingsSortModeTexts[3] = tr("all by date"); + switch (Key) { case kPlay: case kOk: return Play(); @@ -2346,11 +2352,14 @@ case kYellow: return Delete(); case kInfo: case kBlue: return Info(); - case k0: DirOrderState = !DirOrderState; + case k0: Setup.RecordingsSortMode = ++Setup.RecordingsSortMode % MAXSORTMODES; Set(true); + Skins.Message(mtStatus, cString::sprintf("%s %d: %s", tr("Sorting"), Setup.RecordingsSortMode, RecordingsSortModeTexts[Setup.RecordingsSortMode])); return osContinue; case k8: return Rename(); - case k9: + case k9: Recordings.ToggleSortOrder(); + Set(true); + return osContinue; case k1...k7: return Commands(Key); case kNone: if (Recordings.StateChanged(recordingsState)) Set(true); @@ -2940,12 +2949,19 @@ // --- cMenuSetupRecord ------------------------------------------------------ class cMenuSetupRecord : public cMenuSetupBase { +private: + const char *RecordingsSortModeTexts[MAXSORTMODES]; public: cMenuSetupRecord(void); }; cMenuSetupRecord::cMenuSetupRecord(void) { + RecordingsSortModeTexts[0] = tr("main dir alphabetically, subdirs flexible"); + RecordingsSortModeTexts[1] = tr("main dir by date, subdirs flexible"); + RecordingsSortModeTexts[2] = tr("all alphabetically"); + RecordingsSortModeTexts[3] = tr("all by date"); + SetSection(tr("Recording")); Add(new cMenuEditIntItem( tr("Setup.Recording$Margin at start (min)"), &data.MarginStart)); Add(new cMenuEditIntItem( tr("Setup.Recording$Margin at stop (min)"), &data.MarginStop)); @@ -2965,6 +2981,8 @@ Add(new cMenuEditBoolItem(tr("Setup.Recording$Show date"), &data.ShowRecDate)); Add(new cMenuEditBoolItem(tr("Setup.Recording$Show time"), &data.ShowRecTime)); Add(new cMenuEditBoolItem(tr("Setup.Recording$Show length"), &data.ShowRecLength)); + Add(new cMenuEditStraItem(tr("Setup.Recording$Sort recordings by"), &data.RecordingsSortMode, MAXSORTMODES, RecordingsSortModeTexts)); + Add(new cMenuEditBoolItem(tr("Setup.Recording$Sort directories before recordings"), &data.RecordingsSortDirsFirst)); } // --- cMenuSetupReplay ------------------------------------------------------ diff -Nru vdr-1.6.0/po/de_DE.po vdr-1.6.0-sortrec_v3b/po/de_DE.po --- vdr-1.6.0/po/de_DE.po 2008-04-07 21:13:43.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/po/de_DE.po 2008-04-07 21:21:37.000000000 +0200 @@ -1049,3 +1049,24 @@ msgid "Setup.Recording$Show length" msgstr "Länge der Aufnahme anzeigen" + +msgid "Setup.Recording$Sort recordings by" +msgstr "Aufnahmen sortieren nach" + +msgid "Setup.Recording$Sort directories before recordings" +msgstr "Verzeichnisse vor Aufnahmen einsortieren" + +msgid "main dir alphabetically, subdirs flexible" +msgstr "Alphabet für Haupt-, flexibel für Unterverzeichnisse" + +msgid "main dir by date, subdirs flexible" +msgstr "Datum für Haupt-, flexibel für Unterverzeichnisse" + +msgid "all alphabetically" +msgstr "alles alphabetisch" + +msgid "all by date" +msgstr "alles nach Datum" + +msgid "Sorting" +msgstr "Sortierung" diff -Nru vdr-1.6.0/po/fr_FR.po vdr-1.6.0-sortrec_v3b/po/fr_FR.po --- vdr-1.6.0/po/fr_FR.po 2008-04-07 21:13:43.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/po/fr_FR.po 2008-04-07 21:28:57.000000000 +0200 @@ -1055,3 +1055,24 @@ msgid "Setup.Recording$Show length" msgstr "Montrer la longueur de l'enregistrement" + +msgid "Setup.Recording$Sort recordings by" +msgstr "Trier les enregistrements par" + +msgid "Setup.Recording$Sort directories before recordings" +msgstr "Trier les répertoires avant les enregistrements" + +msgid "main dir alphabetically, subdirs flexible" +msgstr "Rep. principal par ordre alpha, sous-rep. flexible" + +msgid "main dir by date, subdirs flexible" +msgstr "Rep. principal par date, sous-rep. flexible" + +msgid "all alphabetically" +msgstr "Tous par odre alpha" + +msgid "all by date" +msgstr "Tous par date" + +msgid "Sorting" +msgstr "Tri" diff -Nru vdr-1.6.0/README.sortrec vdr-1.6.0-sortrec_v3b/README.sortrec --- vdr-1.6.0/README.sortrec 1970-01-01 01:00:00.000000000 +0100 +++ vdr-1.6.0-sortrec_v3b/README.sortrec 2008-04-07 21:28:14.000000000 +0200 @@ -0,0 +1,48 @@ +Sort Recordings patch for VDR +----------------------------- +Copyright (C) 2005 Frank99 @vdr-portal.de +Copyright (C) 2006-2008 Christoph Haubrich + +Released under the same license as VDR itself, for details see vdr.c or +http://firefly.vdr-developer.org/patches + +This patch changes the sort behaviour of the recordings menu. It is based +on the patch available here: http://www.vdr-portal.de/board/thread.php?threadid=36031 +Required for this patch is the liemikuutio-patch for VDR which can be found here: +http://www.saunalahti.fi/%7Erahrenbe/vdr/patches/ + +There are four sorting modes available after this patch is applied: + +mode behaviour for behaviour for + main directory sub directories +-------------------------------------------------------------------------- + 0 alphabetically if special character(*) is found alphabetically, + else by date + 1 by date if special character(*) is found alphabetically, + else by date + 2 alphabetically alphabetically + 3 by date by date + +(*) if the name of a subdirectory ends with one of ".-$" (dot, hyphen, dollar sign) + it is sorted alphabetically in sort mode 0 and 1 + +Sort mode 0 with none of the special characters at the end of any subdir +corresponds to the default sorting mode of the original VDR. + +The sorting mode can be switched through in the recording menu with the '0' key +(0->1->2->3->0->...), a default for startup can be set in the setup->recordings menu. + +Additionally the sort order (ascending/descending) can be toggled by the '9' key +(which is always set to ascending after a restart) + +If you like the to see subdirectories before recordings you can select to put +directories first in the setup->recordings menu. + +If you would like the sorting to ignore a leading '%' (as normally displayed before +cutted recordings) you can achive this by setting the environment variable LC_COLLATE +properly (eg. LC_COLLATE=de_DE@euo in runvdr for germany). + +History: +2006-08-13 v3, sortrec release for VDR 1.4.1 and liemikuutio 1.8 +2007-01-28 v3a, moved #ifdef from optimized-rename-patch to sortrec +2008-03-29 v3b, removed ASCII-170 and ASCII-183 to make sortrec Utf8-ready diff -Nru vdr-1.6.0/recording.c vdr-1.6.0-sortrec_v3b/recording.c --- vdr-1.6.0/recording.c 2008-04-07 20:59:19.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/recording.c 2008-04-07 21:33:27.000000000 +0200 @@ -493,7 +493,10 @@ { resume = RESUME_NOT_INITIALIZED; titleBuffer = NULL; - sortBuffer = NULL; + for (int i = 0; i < MAXSORTMODES; i++) { + sortBuffer[i] = NULL; + lastDirsFirst[i] = -1; + } fileName = NULL; name = NULL; fileSizeMB = -1; // unknown @@ -550,7 +553,10 @@ fileSizeMB = -1; // unknown deleted = 0; titleBuffer = NULL; - sortBuffer = NULL; + for (int i = 0; i < MAXSORTMODES; i++) { + sortBuffer[i] = NULL; + lastDirsFirst[i] = -1; + } fileName = strdup(FileName); FileName += strlen(VideoDirectory) + 1; char *p = strrchr(FileName, '/'); @@ -641,7 +647,9 @@ cRecording::~cRecording() { free(titleBuffer); - free(sortBuffer); + for (int i = 0; i < MAXSORTMODES; i++) { + free(sortBuffer[i]); + } free(fileName); free(name); delete info; @@ -662,22 +670,32 @@ } t++; } - if (s1 && s2) + if (s1 && s2) { + if (Setup.RecordingsSortDirsFirst) + *s1 = 'b'; + + if ((Setup.RecordingsSortMode <= 1 && s1 != s && !strchr(".-$", *(s1 - 1))) || + (Setup.RecordingsSortMode == 1 && s1 == s) || + (Setup.RecordingsSortMode == 3)) memmove(s1 + 1, s2, t - s2 + 1); + } return s; } char *cRecording::SortName(void) const { - if (!sortBuffer) { - char *s = StripEpisodeName(strdup(FileName() + strlen(VideoDirectory) + 1)); + if (!sortBuffer[Setup.RecordingsSortMode] || + lastDirsFirst[Setup.RecordingsSortMode] != Setup.RecordingsSortDirsFirst) { + free(sortBuffer[Setup.RecordingsSortMode]); + lastDirsFirst[Setup.RecordingsSortMode] = Setup.RecordingsSortDirsFirst; + char *s = StripEpisodeName(strdup(FileName() + strlen(VideoDirectory))); strreplace(s, '/', 'a'); // some locales ignore '/' when sorting int l = strxfrm(NULL, s, 0) + 1; - sortBuffer = MALLOC(char, l); - strxfrm(sortBuffer, s, l); + sortBuffer[Setup.RecordingsSortMode] = MALLOC(char, l); + strxfrm(sortBuffer[Setup.RecordingsSortMode], s, l); free(s); } - return sortBuffer; + return sortBuffer[Setup.RecordingsSortMode]; } int cRecording::GetResume(void) const @@ -692,9 +710,7 @@ int cRecording::Compare(const cListObject &ListObject) const { cRecording *r = (cRecording *)&ListObject; - if (DirOrderState) - return strcasecmp(FileName(), r->FileName()); - return strcasecmp(SortName(), r->SortName()); + return Recordings.GetSortOrder() * strcasecmp(SortName(), r->SortName()); } const char *cRecording::FileName(void) const @@ -926,8 +942,10 @@ fileName = strdup(newFileName); free(name); name = strdup(newName); - free(sortBuffer); - sortBuffer = NULL; + for (int i = 0; i < MAXSORTMODES; i++) { + free(sortBuffer[i]); + sortBuffer[i] = NULL; + } free(titleBuffer); titleBuffer = NULL; } @@ -949,6 +967,7 @@ deleted = Deleted; lastUpdate = 0; state = 0; + SortOrder = 1; } cRecordings::~cRecordings() diff -Nru vdr-1.6.0/recording.h vdr-1.6.0-sortrec_v3b/recording.h --- vdr-1.6.0/recording.h 2008-04-07 20:59:19.000000000 +0200 +++ vdr-1.6.0-sortrec_v3b/recording.h 2008-04-07 21:35:00.000000000 +0200 @@ -63,12 +63,16 @@ bool Write(FILE *f, const char *Prefix = "") const; }; +#define SORTRECORDINGSVERSNUM 3 +#define MAXSORTMODES 4 + class cRecording : public cListObject { friend class cRecordings; private: mutable int resume; mutable char *titleBuffer; - mutable char *sortBuffer; + mutable char *sortBuffer[MAXSORTMODES]; + mutable char lastDirsFirst[MAXSORTMODES]; mutable char *fileName; mutable char *name; mutable int fileSizeMB; @@ -118,6 +122,7 @@ bool deleted; time_t lastUpdate; int state; + int SortOrder; const char *UpdateFileName(void); void Refresh(bool Foreground = false); void ScanVideoDir(const char *DirName, bool Foreground = false, int LinkLevel = 0); @@ -148,6 +153,8 @@ void AddByName(const char *FileName, bool TriggerUpdate = true); void DelByName(const char *FileName); int TotalFileSizeMB(void); ///< Only for deleted recordings! + void ToggleSortOrder(void) { SortOrder *= -1; } + const int GetSortOrder(void) { return SortOrder; } }; extern cRecordings Recordings;