]> git.vomp.tv Git - vompclient.git/commitdiff
Recordings sort order
authorChris Tallon <chris@vomp.tv>
Fri, 29 Dec 2006 23:49:59 +0000 (23:49 +0000)
committerChris Tallon <chris@vomp.tv>
Fri, 29 Dec 2006 23:49:59 +0000 (23:49 +0000)
directory.cc
directory.h
recman.cc
recman.h
voptionsmenu.cc
vrecordinglist.cc
vrecordinglist.h

index 13ce2d3a1cebabfaa3d4b6348b9d8aa786f69153..cc7f27567cbee318c37090ab43f25a470c4064a9 100644 (file)
@@ -69,14 +69,17 @@ ULONG Directory::getNumRecordings()
   return total;
 }
 
-void Directory::sort()
+void Directory::sort(bool chronoSortOrder)
 {
   // Sort the directory order
   ::sort(dirList.begin(), dirList.end(), DirectorySorter());
 
   // Sort the recordings order
-  ::sort(recList.begin(), recList.end(), RecordingSorter());
+  if (chronoSortOrder)
+    ::sort(recList.begin(), recList.end(), RecordingSorterChrono());
+  else
+    ::sort(recList.begin(), recList.end(), RecordingSorterAlpha());
 
   // Now get the dirs to sort themselves! oh I love recursion.
-  for(UINT i = 0; i < dirList.size(); i++) dirList[i]->sort();
+  for(UINT i = 0; i < dirList.size(); i++) dirList[i]->sort(chronoSortOrder);
 }
index f70aad16319abe8fa4f300edffd4ea4982315641..330e79afbbc7db22569b5c3e06c4e317a47af8a8 100644 (file)
@@ -41,7 +41,7 @@ class Directory
 
     Directory* getDirByName(char* dirName);
     ULONG getNumRecordings();
-    void sort();
+    void sort(bool chronoSortOrder);
 
     char* name;
 
@@ -63,7 +63,7 @@ struct DirectorySorter
   }
 };
 
-struct RecordingSorter
+struct RecordingSorterAlpha
 {
   bool operator() (const Recording* a, const Recording* b)
   {
@@ -75,4 +75,12 @@ struct RecordingSorter
   }
 };
 
+struct RecordingSorterChrono
+{
+  bool operator() (const Recording* a, const Recording* b)
+  {
+    return a->getStartTime() < b->getStartTime();
+  }
+};
+
 #endif
index 11afd4d7fcc7fc121a21a1c340f832b17ce052b9..e46da9548ef84c34cea97cdc47209b535b197e4f 100644 (file)
--- a/recman.cc
+++ b/recman.cc
@@ -29,6 +29,8 @@ RecMan::RecMan()
 
   rootDir = new Directory("/");
   currentDir = rootDir;
+
+  chronoSortOrder = false;
 }
 
 RecMan::~RecMan()
@@ -107,9 +109,6 @@ void RecMan::addEntry(ULONG startTime, char* name, char* fileName)
   }
 
   targetDirectory->recList.push_back(rec);
-
-  // Sort it all.
-  rootDir->sort();
 }
 
 ULONG RecMan::getTotalSpace()
@@ -179,7 +178,7 @@ int RecMan::moveRecording(Recording* toMove, Directory* toDir)
 
         currentDir->recList.erase(i);
         toDir->recList.push_back(toMove);
-        toDir->sort();
+        toDir->sort(chronoSortOrder);
       }
       break;
     }
@@ -253,3 +252,19 @@ Directory* RecMan::getRootDir()
 {
   return rootDir;
 }
+
+void RecMan::setSortOrderChron()
+{
+  chronoSortOrder = true;
+}
+
+void RecMan::toggleSortOrder()
+{
+  chronoSortOrder = !chronoSortOrder;
+}
+
+void RecMan::sort()
+{
+  Log::getInstance()->log("RecMan", Log::DEBUG, "Sort");
+  rootDir->sort(chronoSortOrder);
+}
index 68b8691a7969a942ffc6899328a8e5546262f4b6..f34c55b8e9d633bc152e7c5ec248348f81549b51 100644 (file)
--- a/recman.h
+++ b/recman.h
@@ -38,8 +38,11 @@ class RecMan
     RecMan();
     ~RecMan();
 
+    void setSortOrderChron();
+    void toggleSortOrder();
     void setStats(ULONG totalSpace, ULONG freeSpace, ULONG usedPercent);
     void addEntry(ULONG startTime, char* name, char* filename); // modifies name
+    void sort();
     int deleteRecording(Recording* rec);
     int moveRecording(Recording* toMove, Directory* toDir);
 
@@ -65,6 +68,8 @@ class RecMan
     Directory* rootDir;
     Directory* currentDir;
 
+    bool chronoSortOrder;
+
     void constructPath(char* target, Directory* dir) ;
 };
 
index d5d90dff8a38ff7764008df25a1d56dbd1d21239..7bc1c726072e9d69c467ce72ece7c5395d510b75 100644 (file)
@@ -290,7 +290,7 @@ void VOptionsMenu::doApplyChanges(map<int,int>* changedOptions)
 
 void VOptionsMenu::doGeneral()
 {
-  static const int numOptions = 7;
+  static const int numOptions = 8;
 
   static const char* options1[] = {"Old", "New"};
   static const char* options3[] = {"RGB+composite", "S-Video"};
@@ -298,6 +298,7 @@ void VOptionsMenu::doGeneral()
   static const char* options5[] = {"Chop sides", "Letterbox"};
   static const char* options6[] = {"On", "Off", "Last state"};
   static const char* options7[] = {"All", "FTA only"};
+  static const char* options15[] = {"Alphabetical", "Chronological"};
 
   const static OPTIONDATA optionData[numOptions] =
   {
@@ -308,6 +309,7 @@ void VOptionsMenu::doGeneral()
     {5, "16:9 on 4:3 display mode", "TV",      "Widemode",         OPTIONTYPE_TEXT, 2, 0, 0, options5 },
     {6, "Power state after bootup", "General", "Power After Boot", OPTIONTYPE_TEXT, 3, 0, 0, options6 },
     {7, "Display channels",         "General", "Channels",         OPTIONTYPE_TEXT, 2, 0, 0, options7 },
+    {15, "Recordings sort order",   "General", "Recordings Sort Order", OPTIONTYPE_TEXT, 2, 0, 0, options15 },
   };
 
   // As all the above data is const static, it can be sent to the new View, this stack frame can
index 8c821fd49f8d65a914b8ce4cf9807e7b3da89aad..ce3b7d91242180bf0757796d56953d42f7ca765c 100644 (file)
@@ -465,7 +465,13 @@ int VRecordingList::handleCommand(int command)
       if (doPlay(true)) return 2;
       return 1;
     }
-
+    case Remote::LEFT:
+    case Remote::RIGHT:
+    case Remote::ZERO:
+    {
+      reSort();
+      return 2;
+    }
   }
   // stop command getting to any more views
   return 1;
@@ -473,14 +479,35 @@ int VRecordingList::handleCommand(int command)
 
 bool VRecordingList::load()
 {
+  VDR* vdr = VDR::getInstance();
+
   recman = new RecMan();
-  bool success = VDR::getInstance()->getRecordingsList(recman);
+  bool success = vdr->getRecordingsList(recman);
   if (success)
   {
     loading = false;
+
+    char* defaultSortOrder = vdr->configLoad("General", "Recordings Sort Order");
+    if (defaultSortOrder)
+    {
+      if (!STRCASECMP(defaultSortOrder, "Chronological")) recman->setSortOrderChron();
+      delete[] defaultSortOrder;
+    }
+
+    recman->sort();
+
     draw();
     viewman->updateView(this);
   }
 
   return success;
 }
+
+void VRecordingList::reSort()
+{
+  recman->toggleSortOrder();
+  recman->sort();
+  sl.clear();
+  draw();
+  viewman->updateView(this);
+}
index b5355cc250b82971d3d8753599d8dc81322f5179..eaf6bd81767651780e12b9cbd46aec57835474e9 100644 (file)
@@ -70,6 +70,7 @@ class VRecordingList : public View
     int doPlay(bool resume);
     void doMoveRecording(Directory* toDir);
     Recording* getCurrentOptionRecording();
+    void reSort();
 
     stack<int> slIndexStack;
 };