]> git.vomp.tv Git - vompclient.git/commitdiff
New recordings managager to support multi level dir structure and more in
authorChris Tallon <chris@vomp.tv>
Sun, 14 May 2006 18:44:51 +0000 (18:44 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 14 May 2006 18:44:51 +0000 (18:44 +0000)
future

15 files changed:
Makefile
directory.cc
directory.h
recman.cc [new file with mode: 0644]
recman.h [new file with mode: 0644]
recording.cc
recording.h
vdr.cc
vdr.h
vrecordinglist.cc
vrecordinglist.h
vrecordingmenu.cc
vvideorec.cc
vwelcome.cc
vwelcome.h

index 926f887de6d3906179e443b41b9a2762ef5a9a17..4213a86c3cc8d1813f2f0c7b80a36add5021e66e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ CROSSLIBS = ../jpeg-6b/libjpeg.a
 
 OBJECTS1 = main.o command.o log.o tcp.o dsock.o thread.o timers.o i18n.o               \
            message.o messagequeue.o                                                    \
-           vdr.o recording.o channel.o rectimer.o event.o directory.o                  \
+           vdr.o recman.o recording.o channel.o rectimer.o event.o directory.o         \
            player.o vfeed.o afeed.o afeedr.o                                           \
                                         demuxer.o demuxervdr.o stream.o draintarget.o                               \
            viewman.o box.o region.o colour.o view.o                                    \
index 6b9d636cc8aecbdfcd14a98d3a0fbb15424226b7..b96f458d80fcec144c49d8c4db02be8d5aad2a16 100644 (file)
 
 #include "directory.h"
 
-ULONG Directory::totalSpace = 0;
-ULONG Directory::freeSpace = 0;
-ULONG Directory::usedPercent = 0;
-
-Directory::Directory()
+Directory::Directory(char* newName)
 {
-  name = NULL;
-
-  isRoot = 0;
   index = -1;
+
+  name = new char[strlen(newName) + 1];
+  strcpy(name, newName);
+
+  parent = NULL;
 }
 
 Directory::~Directory()
 {
   if (name) delete[] name;
+  name = NULL;
   index = -1; // just in case
   UINT i;
 
@@ -51,12 +50,6 @@ Directory::~Directory()
   recList.clear();
 }
 
-void Directory::setName(char* newName)
-{
-  name = new char[strlen(newName) + 1];
-  strcpy(name, newName);
-}
-
 Directory* Directory::getDirByName(char* dirName)
 {
   for(UINT i = 0; i < dirList.size(); i++)
@@ -71,4 +64,14 @@ ULONG Directory::getNumRecordings()
   return recList.size();
 }
 
-// FIXME make an add function in here that adds recs to the end of the list
+void Directory::sort()
+{
+  // Sort the directory order
+  ::sort(dirList.begin(), dirList.end(), DirectorySorter());
+
+  // Sort the recordings order
+  ::sort(recList.begin(), recList.end(), RecordingSorter());
+
+  // Now get the dirs to sort themselves! oh I love recursion.
+  for(UINT i = 0; i < dirList.size(); i++) dirList[i]->sort();
+}
index c2cd9dad136218e0c983c2171aa2774102841b98..f70aad16319abe8fa4f300edffd4ea4982315641 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <stdio.h>
 #include <vector>
+#include <algorithm>
 using namespace std;
 
 #include "defines.h"
@@ -35,26 +36,43 @@ typedef vector<Recording*> RecordingList;
 class Directory
 {
   public:
-    Directory();
+    Directory(char* newName);
     ~Directory();
 
-    void setName(char* newName);
     Directory* getDirByName(char* dirName);
-    void setFreeSpace(ULLONG);
     ULONG getNumRecordings();
+    void sort();
 
-    UCHAR isRoot;
     char* name;
 
     int index;
 
+    Directory* parent;
     DirectoryList dirList;
     RecordingList recList;
 
-    static ULONG totalSpace;
-    static ULONG freeSpace;
-    static ULONG usedPercent;
+};
 
+struct DirectorySorter
+{
+  bool operator() (const Directory* a, const Directory* b)
+  {
+    int c = strcmp(b->name, a->name);
+    if (c > 0) return true;
+    return false;
+  }
+};
+
+struct RecordingSorter
+{
+  bool operator() (const Recording* a, const Recording* b)
+  {
+    int c = strcmp(b->getProgName(), a->getProgName());
+    if (c > 0) return true;
+    if (c < 0) return false;
+
+    return a->getStartTime() < b->getStartTime();
+  }
 };
 
 #endif
diff --git a/recman.cc b/recman.cc
new file mode 100644 (file)
index 0000000..0c66350
--- /dev/null
+++ b/recman.cc
@@ -0,0 +1,213 @@
+/*
+    Copyright 2006 Chris Tallon
+
+    This file is part of VOMP.
+
+    VOMP is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    VOMP is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with VOMP; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "recman.h"
+#include "vdr.h"
+
+RecMan::RecMan()
+{
+  totalSpace = 0;
+  freeSpace = 0;
+  usedPercent = 0;
+
+  rootDir = new Directory("/");
+  currentDir = rootDir;
+}
+
+RecMan::~RecMan()
+{
+  delete rootDir;
+}
+
+void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent)
+{
+  totalSpace = ttotalSpace;
+  freeSpace = tfreeSpace;
+  usedPercent = tusedPercent;
+}
+
+void RecMan::addEntry(ULONG startTime, char* name, char* fileName)
+{
+  Recording* rec = new Recording();
+  rec->setStartTime(startTime);
+  rec->setFileName(fileName);
+
+  // And now for the directory structure & prog name
+
+  printf("%lu %s %s\n", startTime, name, fileName);
+
+  char* c;
+  char* d;
+  stack<char*> dirNamesStack;
+  char* oneDirName;
+  bool gotProgName = false;
+  for(c = (name + strlen(name) - 1); c >= name; c--)
+  {
+    if ((*c == '~') || (c == name))
+    {
+      // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
+      if (c == name) d = name;
+      else d = c + 1;
+
+      if (!gotProgName)
+      {
+        printf("Got prog name '%s'\n", d);
+        rec->setProgName(d); // will copy from d to end of string
+        *c = '\0';
+        gotProgName = true;
+      }
+      else
+      {
+        // get the dir
+        oneDirName = new char[strlen(d) + 1];
+        strcpy(oneDirName, d);
+        dirNamesStack.push(oneDirName);
+        *c = '\0';
+      }
+    }
+  }
+
+  Directory* targetDirectory = rootDir;
+  Directory* getDir;
+
+  while(!dirNamesStack.empty())
+  {
+    oneDirName = dirNamesStack.top();
+    if (!oneDirName) break;
+
+    getDir = targetDirectory->getDirByName(oneDirName);
+    if (getDir)
+    {
+      targetDirectory = getDir;
+    }
+    else
+    {
+      printf("making new dir '%s'\n", oneDirName);
+      getDir = new Directory(oneDirName); // Make a new directory
+      getDir->parent = targetDirectory;
+      targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
+      targetDirectory = getDir; // Make the new dir the target
+    }
+
+    dirNamesStack.pop();
+    delete[] oneDirName;
+  }
+
+  targetDirectory->recList.push_back(rec);
+
+  // Sort it all.
+  rootDir->sort();
+}
+
+ULONG RecMan::getTotalSpace()
+{
+  return totalSpace;
+}
+
+ULONG RecMan::getFreeSpace()
+{
+  return freeSpace;
+}
+
+ULONG RecMan::getUsedPercent()
+{
+  return usedPercent;
+}
+
+int RecMan::deleteRecording(Recording* rec)
+{
+  int success = 0;
+
+  for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
+  {
+    if (*i == rec)
+    {
+      success = VDR::getInstance()->deleteRecording(rec->getFileName());
+      if (success == 1)
+      {
+        currentDir->recList.erase(i);
+        delete rec;
+      }
+      break;
+    }
+  }
+
+  return success;
+}
+
+bool RecMan::isSubDir()
+{
+  return (currentDir != rootDir);
+}
+
+bool RecMan::down(Directory* downDir)
+{
+  // Check dir is in currentDir
+  for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
+  {
+    if (*i == downDir)
+    {
+      currentDir = downDir;
+      return true;
+    }
+  }
+  return false;
+}
+
+bool RecMan::up()
+{
+  if (!isSubDir()) return false;
+
+  Directory* oldDir = currentDir;
+  currentDir = currentDir->parent;
+
+  if (oldDir->getNumRecordings() == 0)
+  {
+    // delete the olddir
+    Directory* tempdir;
+    for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
+    {
+      tempdir = *i;
+      if (tempdir == oldDir)
+      {
+        currentDir->dirList.erase(i);
+        delete tempdir;
+        break;
+      }
+    }
+  }
+
+  return true;
+}
+
+char* RecMan::getCurDirName()
+{
+  return currentDir->name;
+}
+
+DirectoryList* RecMan::getDirectories()
+{
+  return &currentDir->dirList;
+}
+
+RecordingList* RecMan::getRecordings()
+{
+  return &currentDir->recList;
+}
diff --git a/recman.h b/recman.h
new file mode 100644 (file)
index 0000000..915cb1d
--- /dev/null
+++ b/recman.h
@@ -0,0 +1,60 @@
+/*
+    Copyright 2006 Chris Tallon
+
+    This file is part of VOMP.
+
+    VOMP is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    VOMP is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with VOMP; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#ifndef RECMAN_H
+#define RECMAN_H
+
+#include <stack>
+
+#include "directory.h"
+#include "recording.h"
+
+class RecMan
+{
+  public:
+    RecMan();
+    ~RecMan();
+
+    void setStats(ULONG totalSpace, ULONG freeSpace, ULONG usedPercent);
+    void addEntry(ULONG startTime, char* name, char* filename); // modifies name
+    int deleteRecording(Recording* rec);
+
+    // State functions
+    bool isSubDir();
+    bool up();
+    bool down(Directory* downDir);
+    char* getCurDirName();
+    DirectoryList* getDirectories();
+    RecordingList* getRecordings();
+
+    ULONG getTotalSpace();
+    ULONG getFreeSpace();
+    ULONG getUsedPercent();
+
+  private:
+    ULONG totalSpace;
+    ULONG freeSpace;
+    ULONG usedPercent;
+
+    Directory* rootDir;
+    Directory* currentDir;
+};
+
+#endif
index 2b28d543fc62dfe7848c567f3ef403e26d38720a..365b5322f2fa71d8efd7ef247080f2a1e78a641b 100644 (file)
 Recording::Recording()
 {
   start = 0;
-  dirName = NULL;
   progName = NULL;
   fileName = NULL;
-
   index = -1;
 }
 
 Recording::~Recording()
 {
-  if (dirName) delete[] dirName;
-  if (progName) delete[] progName;
-  if (fileName) delete[] fileName;
+  if (progName) { free(progName); progName = NULL; }
+  if (fileName) { free(fileName); fileName = NULL; }
   index = -1; // just in case
 }
 
-int Recording::isInDir()
+ULONG Recording::getStartTime() const
 {
-//  if (strstr(name, "~")) return 1;
-//  else return 0;
-  return (dirName != NULL);
+  return start;
 }
 
-char* Recording::getDirName()
+char* Recording::getProgName() const
 {
-/*  char* sub = strstr(name, "~");
-  if (!sub) return NULL;
+  return progName;
+}
 
-  char* dirName = new char[sub - name + 1];
-  memcpy(dirName, name, sub - name);
-  dirName[sub - name] = '\0';
-  return dirName;
-*/
-  return dirName;
+char* Recording::getFileName() const
+{
+  return fileName;
 }
 
-char* Recording::getProgName() const
+void Recording::setStartTime(ULONG tstartTime)
 {
-  return progName;
+  start = tstartTime;
 }
 
-void Recording::setName(char* name)
+void Recording::setProgName(char* tProgName)
 {
-  char* sub = strstr(name, "~");
+  if (progName) free(progName);
 
-  if (sub) // Its in a dir
+  if (asprintf(&progName, tProgName) == -1)
   {
-    dirName = new char[sub - name + 1];
-    memcpy(dirName, name, sub - name);
-    dirName[sub - name] = '\0';
-
-    sub++;
-    int sublen = strlen(sub);
-    progName = new char[sublen + 1];
-    memcpy(progName, sub, strlen(sub));
-    progName[sublen] = '\0';
+    free(progName);
+    progName = NULL;
   }
-  else
+}
+
+void Recording::setFileName(char* tFileName)
+{
+  if (fileName) free(fileName);
+
+  if (asprintf(&fileName, tFileName) == -1)
   {
-    int len = strlen(name);
-    progName = new char[len + 1];
-    memcpy(progName, name, len);
-    progName[len] = '\0';
+    free(fileName);
+    fileName = NULL;
   }
 }
index 0d65eda37e2f51ae9d9018b6eb9ba84e9ecb79d1..ba6ddd9fc54f8914357059d1ca21609505a9295a 100644 (file)
@@ -22,7 +22,9 @@
 #define RECORDING_H
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include "defines.h"
 
 class Recording
 {
@@ -30,20 +32,21 @@ class Recording
     Recording();
     ~Recording();
 
-    void setName(char* name);
+    void setStartTime(ULONG startTime);
+    void setProgName(char* progName);
+    void setFileName(char* fileName);
 
-    int isInDir();
-    char* getDirName();
+    ULONG getStartTime() const;
     char* getProgName() const;
-
-    unsigned long start;
-    char* fileName;
+    char* getFileName() const;
 
     int index;
 
   private:
-    char* dirName;
+    ULONG start;
     char* progName;
+    char* fileName;
+
 };
 
 #endif
diff --git a/vdr.cc b/vdr.cc
index 4ddf1bfb539ce6a3d9b2e311e50c27c1c9e06690..7ec9857251df2f39caf1e109350a78ba826035d8 100644 (file)
--- a/vdr.cc
+++ b/vdr.cc
@@ -321,7 +321,7 @@ int VDR::doLogin()
   return 1;
 }
 
-Directory* VDR::getRecordingsList()
+bool VDR::getRecordingsList(RecMan* recman)
 {
   UCHAR buffer[8];
 
@@ -340,7 +340,7 @@ Directory* VDR::getRecordingsList()
   {
     disconnect();
     MUTEX_UNLOCK(&mutex);
-    return NULL;
+    return false;
   }
 
   // reply
@@ -348,73 +348,31 @@ Directory* VDR::getRecordingsList()
   if (!getPacket())
   {
     MUTEX_UNLOCK(&mutex);
-    return NULL;
+    return false;
   }
 
-  Directory* recDir = new Directory();
-  recDir->setName("/");
-  recDir->isRoot = 1;
-
-  Directory::totalSpace = extractULONG();
-  Directory::freeSpace = extractULONG();
-  Directory::usedPercent = extractULONG();
+  recman->setStats(extractULONG(), extractULONG(), extractULONG());
 
-  char* string;
+  ULONG start;
+  char* name;
+  char* fileName;
 
   while (packetPos < packetLength)
   {
-    Recording* rec = new Recording();
-
-    rec->start = extractULONG();
-
-    string = extractString();
-    rec->setName(string);
-    delete[] string;
-
-    rec->fileName = extractString();
-
-    if(rec->isInDir())
-    {
-      char* dirName = rec->getDirName();
-
-      Directory* d = recDir->getDirByName(dirName);
-      if (!d)
-      {
-        d = new Directory();
-        d->setName(dirName);
-//        Log::getInstance()->log("VDR", Log::DEBUG, "Added a new directory = %s", d->name);
-        recDir->dirList.push_back(d);
-      }
+    start = extractULONG();
+    name = extractString();
+    fileName = extractString();
 
-      d->recList.push_back(rec);
-    }
-    else
-    {
-      recDir->recList.push_back(rec);
-    }
+    recman->addEntry(start, name, fileName);
 
-//    Log::getInstance()->log("VDR", Log::DEBUG, "%s", rec->fileName);
+    delete[] name;
+    delete[] fileName;
   }
 
   freePacket();
   MUTEX_UNLOCK(&mutex);
-  // Sort the directory order
-  sort(recDir->dirList.begin(), recDir->dirList.end(), DirectorySorter());
-
-  // Sort all the sub lists
 
-  Directory* sortDir;
-  DirectoryList::iterator i;
-  for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
-  {
-    sortDir = *i;
-    sort(sortDir->recList.begin(), sortDir->recList.end(), RecordingSorter());
-  }
-
-  // Sort the root level list
-  sort(recDir->recList.begin(), recDir->recList.end(), RecordingSorter());
-
-  return recDir;
+  return true;
 }
 
 int VDR::deleteRecording(char* fileName)
@@ -649,14 +607,14 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
   return toReturn;
 }
 
-ULLONG VDR::streamRecording(Recording* rec)
+ULLONG VDR::streamRecording(char* fileName)
 {
-  unsigned long totalLength = 8 + strlen(rec->fileName) + 1;
+  unsigned long totalLength = 8 + strlen(fileName) + 1;
   UCHAR* buffer = new UCHAR[totalLength];
 
   *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
   *(unsigned long*)&buffer[4] = htonl(VDR_STREAMRECORDING);
-  strcpy((char*)&buffer[8], rec->fileName);
+  strcpy((char*)&buffer[8], fileName);
 
   MUTEX_LOCK(&mutex);
   if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
diff --git a/vdr.h b/vdr.h
index aeb7b58cf14586af6bf1537147ce758af104a532..228acdc737031c38d06c4a3cbb6758dd76cb07d2 100644 (file)
--- a/vdr.h
+++ b/vdr.h
 #include "log.h"
 #include "dsock.h"
 #include "tcp.h"
-#include "directory.h"
-#include "recording.h"
 #include "channel.h"
 #include "event.h"
 #include "rectimer.h"
+#include "recman.h"
 
 using namespace std;
 
@@ -70,27 +69,6 @@ struct ServerSorter
   }
 };
 
-struct RecordingSorter
-{
-  bool operator() (const Recording* a, const Recording* b)
-  {
-    int c = strcmp(b->getProgName(), a->getProgName());
-    if (c > 0) return true;
-    if (c < 0) return false;
-
-    return a->start < b->start;
-  }
-};
-
-struct DirectorySorter
-{
-  bool operator() (const Directory* a, const Directory* b)
-  {
-    int c = strcmp(b->name, a->name);
-    if (c > 0) return true;
-    return false;
-  }
-};
 
 class VDR
 {
@@ -135,13 +113,13 @@ class VDR
 
     int doLogin();
 
-    Directory* getRecordingsList();
+    bool       getRecordingsList(RecMan* recman);
     char*      getRecordingSummary(char* fileName);
     int        deleteRecording(char* fileName);
-    ULLONG     streamRecording(Recording* rec);
+    ULLONG     streamRecording(char* fileName);
     ULLONG     rescanRecording();
     ULLONG     positionFromFrameNumber(ULONG frameNumber);
-       ULONG      frameNumberFromPosition(ULLONG position);
+    ULONG      frameNumberFromPosition(ULLONG position);
 
     ChannelList* getChannelsList(ULONG type);
     int          streamChannel(ULONG number);
@@ -196,7 +174,7 @@ class VDR
     const static ULONG VDR_GETTIMERS           = 14;
     const static ULONG VDR_SETTIMER            = 15;
     const static ULONG VDR_POSFROMFRAME        = 16;
-       const static ULONG VDR_FRAMEFROMPOS        = 17;
+    const static ULONG VDR_FRAMEFROMPOS        = 17;
 
     int  getPacket();
     void freePacket();
index 3965fd26c658dac35215d7b14b48582c40f64c1e..d9ae555b207cca994112a5045669368de36f6d95 100644 (file)
 
 #include "vrecordinglist.h"
 
-VRecordingList::VRecordingList(VRecordingList* tparent, Directory* tdir)
+VRecordingList::VRecordingList()
 {
-  myParent = tparent;
   viewman = ViewMan::getInstance();
-  recDir = tdir;
+  recman = NULL;
+  loading = true;
 
   create(570, 420);
   if (Video::getInstance()->getFormat() == Video::PAL)
@@ -47,39 +47,10 @@ VRecordingList::VRecordingList(VRecordingList* tparent, Directory* tdir)
 
 VRecordingList::~VRecordingList()
 {
-  if (myParent)
-  {
-    // if this is a sub, there can only be recordings. if there are none left, get this dir deleted by parent
-    if (recDir->getNumRecordings() == 0) myParent->zeroCheck();
-    // recDir is now deleted if it was empty
-  }
-  else
-  {
-    // only delete the list if this is not a sub dir window
-    delete recDir;
-  }
-}
-
-void VRecordingList::zeroCheck()
-{
-  // go through to delete 1 empty dir if necessary (there will only ever be 1)
-  Directory* dir;
-  DirectoryList::iterator i;
-  for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
-  {
-    dir = *i;
-    if (dir->getNumRecordings() == 0)
-    {
-      delete dir;
-      recDir->dirList.erase(i);
-      break;
-    }
-  }
-  drawData();
-  viewman->updateView(this);
+  delete recman;
 }
 
-void VRecordingList::drawData()
+void VRecordingList::drawData(bool doIndexPop)
 {
   int saveIndex = sl.getCurrentOption();
   int saveTop = sl.getTopOption();
@@ -94,89 +65,111 @@ void VRecordingList::drawData()
   char tempB[300]; // FIXME
   struct tm* btime;
 
-  Directory* dir;
+  Directory* currentSubDir;
   DirectoryList::iterator i;
-  for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++)
+  DirectoryList* dirList = recman->getDirectories();
+  for (i = dirList->begin(); i != dirList->end(); i++)
   {
-    dir = *i;
-    SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), dir->getNumRecordings(), dir->name);
-    dir->index = sl.addOption(tempA, first);
+    currentSubDir = *i;
+    SNPRINTF(tempA, 299, tr("<dir> %lu\t%s"), currentSubDir->getNumRecordings(), currentSubDir->name);
+    currentSubDir->index = sl.addOption(tempA, first);
     first = 0;
   }
 
   // FIXME convert the whole program to time_t's
 
-  Recording* rec;
-  for (UINT j = 0; j < recDir->recList.size(); j++)
+  Recording* currentRec;
+  RecordingList::iterator j;
+  RecordingList* recList = recman->getRecordings();
+  for (j = recList->begin(); j != recList->end(); j++)
   {
-    rec = recDir->recList[j];
-    btime = localtime((time_t*)&rec->start);
+    currentRec = *j;
+    time_t recStartTime = (time_t)currentRec->getStartTime();
+    btime = localtime(&recStartTime);
 #ifndef _MSC_VER
     strftime(tempA, 299, "%0d/%0m %0H:%0M ", btime);
 #else
     strftime(tempA, 299, "%d/%m %H:%M ", btime);
 #endif
-    sprintf(tempB, "%s\t%s", tempA, rec->getProgName());
-    rec->index = sl.addOption(tempB, first);
+    sprintf(tempB, "%s\t%s", tempA, currentRec->getProgName());
+    currentRec->index = sl.addOption(tempB, first);
     first = 0;
   }
 
-  sl.hintSetCurrent(saveIndex);
-  sl.hintSetTop(saveTop);
+  if (doIndexPop)
+  {
+    sl.hintSetCurrent(slIndexStack.top());
+    slIndexStack.pop();
+  }
+  else
+  {
+    sl.hintSetCurrent(saveIndex);
+    sl.hintSetTop(saveTop);
+  }
   sl.draw();
   doShowingBar();
 }
 
-void VRecordingList::draw()
+void VRecordingList::draw(bool doIndexPop)
 {
-  char title[300];
-  if (myParent)
-  {
-    SNPRINTF(title, 299, tr("Recordings - %s"), recDir->name);
-    setTitleText(title);
-  }
-  else
+  if (!loading)
   {
-    setTitleText(tr("Recordings"));
+    if (recman->isSubDir())
+    {
+      char title[300];
+      SNPRINTF(title, 299, tr("Recordings - %s"), recman->getCurDirName());
+      setTitleText(title);
+    }
+    else
+    {
+      setTitleText(tr("Recordings"));
+    }
   }
 
   View::draw();
 
-  char freeSpace[50];
-  int gigFree = Directory::freeSpace / 1024;
-  SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), Directory::usedPercent, gigFree);
-  drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
+  if (loading)
+  {
+    drawText(tr("Loading..."), 240, 180, Colour::LIGHTTEXT);
+  }
+  else
+  {
+    char freeSpace[50];
+    int gigFree = recman->getFreeSpace() / 1024;
+    SNPRINTF(freeSpace, 49, tr("%lu%% used, %iGB free"), recman->getUsedPercent(), gigFree);
+    drawTextRJ(freeSpace, 560, 5, Colour::LIGHTTEXT);
 
-  // Symbols
+    // Symbols
 
-  WSymbol w;
-  w.setSurface(surface);
+    WSymbol w;
+    w.setSurface(surface);
 
-  w.nextSymbol = WSymbol::UP;
-  w.setSurfaceOffset(20, 385);
-  w.draw();
+    w.nextSymbol = WSymbol::UP;
+    w.setSurfaceOffset(20, 385);
+    w.draw();
 
-  w.nextSymbol = WSymbol::DOWN;
-  w.setSurfaceOffset(50, 385);
-  w.draw();
+    w.nextSymbol = WSymbol::DOWN;
+    w.setSurfaceOffset(50, 385);
+    w.draw();
 
-  w.nextSymbol = WSymbol::SKIPBACK;
-  w.setSurfaceOffset(85, 385);
-  w.draw();
+    w.nextSymbol = WSymbol::SKIPBACK;
+    w.setSurfaceOffset(85, 385);
+    w.draw();
 
-  w.nextSymbol = WSymbol::SKIPFORWARD;
-  w.setSurfaceOffset(115, 385);
-  w.draw();
+    w.nextSymbol = WSymbol::SKIPFORWARD;
+    w.setSurfaceOffset(115, 385);
+    w.draw();
 
-  w.nextSymbol = WSymbol::PLAY;
-  w.setSurfaceOffset(150, 385);
-  w.draw();
+    w.nextSymbol = WSymbol::PLAY;
+    w.setSurfaceOffset(150, 385);
+    w.draw();
 
-  drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
+    drawTextRJ(tr("[ok] = menu"), 560, 385, Colour::LIGHTTEXT);
 
-  // All static stuff done
+    // All static stuff done
 
-  drawData();
+    drawData(doIndexPop);
+  }
 }
 
 void VRecordingList::doShowingBar()
@@ -215,18 +208,17 @@ void VRecordingList::processMessage(Message* m)
 
 void VRecordingList::doDeleteSelected()
 {
-  Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot);
   Recording* toDelete = getCurrentOptionRecording();
 
   if (toDelete)
   {
-    Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName);
+    Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->getFileName());
 
-    VDR* vdr = VDR::getInstance();
-    int success = vdr->deleteRecording(toDelete->fileName);
-    if (!vdr->isConnected())
+    int success = recman->deleteRecording(toDelete);
+    if (!VDR::getInstance()->isConnected())
     {
       Command::getInstance()->connectionLost();
+      return;
     }
 
     if (success != 1)
@@ -248,23 +240,9 @@ void VRecordingList::doDeleteSelected()
     }
     else
     {
-      delete toDelete;
-
-      for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++)
-      {
-        if (*i == toDelete)
-        {
-          recDir->recList.erase(i);
-          break;
-        }
-      }
-
-      drawData();
+      draw();
       viewman->updateView(this);
-
-      if (myParent) myParent->drawData(); // if this is not root get parent to redraw data
     }
-    Log::getInstance()->log("VRecordingList", Log::DEBUG, "Parent = %p, isRoot = %i", myParent, recDir->isRoot);
   }
 }
 
@@ -287,9 +265,12 @@ int VRecordingList::doPlay()
 int VRecordingList::doResume()
 {
   Recording* toResume = getCurrentOptionRecording();
+
+  printf("%s\n", toResume->getFileName());
+
   if (toResume)
   {
-    ULLONG position = VDR::getInstance()->getResumePoint(toResume->fileName);
+    ULLONG position = VDR::getInstance()->getResumePoint(toResume->getFileName());
 
     VVideoRec* vidrec = new VVideoRec(toResume);
     vidrec->draw();
@@ -298,18 +279,22 @@ int VRecordingList::doResume()
     vidrec->go(position);
     return 1;
   }
-  // should not get to here
+
+// should not get to here
   return 0;
 }
 
 Recording* VRecordingList::getCurrentOptionRecording()
 {
-  Recording* current;
-  for (UINT i = 0; i < recDir->recList.size(); i++)
+  Recording* currentRec;
+  RecordingList::iterator j;
+  RecordingList* recList = recman->getRecordings();
+  for (j = recList->begin(); j != recList->end(); j++)
   {
-    current = recDir->recList[i];
-    if (current->index == sl.getCurrentOption()) return current;
+    currentRec = *j;
+    if (currentRec->index == sl.getCurrentOption()) return currentRec;
   }
+
   return NULL;
 }
 
@@ -365,16 +350,21 @@ int VRecordingList::handleCommand(int command)
       if (sl.getNumOptions() == 0) return 2;
 
       // Check to see if it is a sub directory
-      Directory* curDir;
-      for(UINT i = 0; i < recDir->dirList.size(); i++)
+      Directory* currentSubDir;
+      DirectoryList::iterator i;
+      DirectoryList* dirList = recman->getDirectories();
+      for (i = dirList->begin(); i != dirList->end(); i++)
       {
-        curDir = recDir->dirList[i];
-        if (curDir->index == sl.getCurrentOption())
+        currentSubDir = *i;
+        if (currentSubDir->index == sl.getCurrentOption())
         {
-          VRecordingList* sub = new VRecordingList(this, curDir);
-          sub->draw();
-          viewman->add(sub);
-          viewman->updateView(sub);
+          if (recman->down(currentSubDir))
+          {
+            slIndexStack.push(sl.getCurrentOption());
+            sl.clear();
+            draw();
+            viewman->updateView(this);
+          }
           return 2;
         }
       }
@@ -383,7 +373,7 @@ int VRecordingList::handleCommand(int command)
       Recording* current = getCurrentOptionRecording();
       if (current)
       {
-        Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->fileName);
+        Log::getInstance()->log("VRecordingList", Log::DEBUG, "Found the option you pointed at. %s %s", current->getProgName(), current->getFileName());
 
         VRecordingMenu* v = new VRecordingMenu();
         v->setParent(this);
@@ -398,7 +388,18 @@ int VRecordingList::handleCommand(int command)
     }
     case Remote::BACK:
     {
-      return 4;
+      if (recman->isSubDir())
+      {
+        recman->up();
+        sl.clear();
+        draw(true);
+        viewman->updateView(this);
+        return 2;
+      }
+      else
+      {
+        return 4;
+      }
     }
     case Remote::PLAY:
     {
@@ -410,3 +411,18 @@ int VRecordingList::handleCommand(int command)
   // stop command getting to any more views
   return 1;
 }
+
+bool VRecordingList::load()
+{
+  recman = new RecMan();
+  bool success = VDR::getInstance()->getRecordingsList(recman);
+  if (success)
+  {
+    loading = false;
+    draw();
+    viewman->updateView(this);
+  }
+
+  return success;
+}
+
index 48ff61f21cb911bd5eff0a71a7569ab75b8e7e0f..45d920eceb97eeba9a0fd27456c1ec215667f55c 100644 (file)
 #include <string.h>
 #include <time.h>
 #include <vector>
+#include <stack>
 
 #include "view.h"
+#include "recman.h"
 #include "directory.h"
 #include "recording.h"
 #include "wselectlist.h"
 class VRecordingList : public View
 {
   public:
-    VRecordingList(VRecordingList* parent, Directory* dir);
+    VRecordingList();
     ~VRecordingList();
 
     int handleCommand(int command);
     void processMessage(Message* m);
-    void draw();
-
-    void drawData();
-    void zeroCheck();
+    void draw(bool doIndexPop = false);
+    bool load();
+    void drawData(bool doIndexPop = false);
 
   private:
-    VRecordingList* myParent;
-    Directory* recDir;
     ViewMan* viewman;
 
+    bool loading;
+    RecMan* recman;
+    Directory* dir;
+
     WSelectList sl;
 
     void doShowingBar();
@@ -66,6 +69,8 @@ class VRecordingList : public View
     int doPlay();
     int doResume();
     Recording* getCurrentOptionRecording();
+
+    stack<int> slIndexStack;
 };
 
 #endif
index 87ee0c330c50071ab225fdfca30ef31a5db9b471..22533aad8bd581127227dbf3aba90464ea5755aa 100644 (file)
@@ -113,7 +113,7 @@ int VRecordingMenu::handleCommand(int command)
 
       if (sl.getCurrentOption() == 2)
       {
-        char* summary = VDR::getInstance()->getRecordingSummary(rec->fileName);
+        char* summary = VDR::getInstance()->getRecordingSummary(rec->getFileName());
         if (!summary && !VDR::getInstance()->isConnected())
         {
           Command::getInstance()->connectionLost();
index 1c5582879d2b4dcd187279ca31e27a6c3a41b747..a21cd8b2498d06fbe0c36f0baeca73ecb7d97bbf 100644 (file)
@@ -95,7 +95,7 @@ void VVideoRec::draw()
 
 void VVideoRec::go(ULLONG startPosition)
 {
-  ULLONG recLength = vdr->streamRecording(myRec);
+  ULLONG recLength = vdr->streamRecording(myRec->getFileName());
   if (recLength)
   {
     doBar(0);
index fae90fce6b9135f107bfd65937dd3ccd79ea07f1..fe41d73cce58a64fd294c9fcb971625a63fb3f63 100644 (file)
@@ -250,38 +250,15 @@ void VWelcome::doRadioList()
 
 void VWelcome::doRecordingsList()
 {
-  VInfo* viewWait = new VInfo();
-  viewWait->create(460, 190);
-  if (Video::getInstance()->getFormat() == Video::PAL)
-  {
-    viewWait->setScreenPos(140, 170);
-  }
-  else
-  {
-    viewWait->setScreenPos(130, 140);
-  }
-  viewWait->setOneLiner(tr("Downloading recordings list"));
-  viewWait->draw();
-  viewman->add(viewWait);
-  viewman->updateView(viewWait);
+  VRecordingList* vrec = new VRecordingList();
+  vrec->draw();
+  viewman->add(vrec);
+  viewman->updateView(vrec);
 
-  VDR* vdr = VDR::getInstance();
-  Directory* recDir = vdr->getRecordingsList();
-
-  if (recDir)
-  {
-    VRecordingList* vrec = new VRecordingList(NULL, recDir);
-    vrec->draw();
-
-    viewman->add(vrec);
-    viewman->updateView(vrec);
-  }
-  else
+  if (!vrec->load())
   {
     Command::getInstance()->connectionLost();
   }
-
-  viewman->removeView(viewWait);
 }
 
 void VWelcome::doTimersList()
index 59ac71bde639bf2a0d6e2a4ae5604502dbb9537d..20c91d1d6c64895ea9ab10065836c451d27744d5 100644 (file)
@@ -30,7 +30,6 @@
 #include "wjpeg.h"
 #include "viewman.h"
 #include "vdr.h"
-#include "directory.h"
 #include "vchannellist.h"
 #include "vrecordinglist.h"
 #include "vtimerlist.h"