data.h
author nathan
Sat, 29 Dec 2007 14:49:09 +0100
branchtrunk
changeset 2 4c1f7b705009
parent 0 474a1293c3c0
child 22 93aaf15c145a
permissions -rw-r--r--
release 0.10.1
     1 /*
     2  * MP3/MPlayer plugin to VDR (C++)
     3  *
     4  * (C) 2001-2006 Stefan Huelswitt <s.huelswitt@gmx.de>
     5  *
     6  * This code is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
    10  *
    11  * This code is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    19  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
    20  */
    21 
    22 #ifndef ___DATA_H
    23 #define ___DATA_H
    24 
    25 #include <vdr/tools.h>
    26 
    27 // ----------------------------------------------------------------
    28 
    29 class cFileSource;
    30 
    31 extern char *Quote(const char *str);
    32 extern char *AddPath(const char *dir, const char *filename);
    33 extern bool CheckVDRVersion(int Version, int Major, int Minor, const char *text=0);
    34 
    35 // ----------------------------------------------------------------
    36 
    37 class cScanDir {
    38 protected:
    39   enum eScanType { stFile, stDir };
    40   virtual void DoItem(cFileSource *src, const char *subdir, const char *name)=0;
    41 public:
    42   virtual ~cScanDir() {}
    43   bool ScanDir(cFileSource *src, const char *subdir, eScanType type, const char * const *spec, const char * const *excl, bool recursiv);
    44   };
    45 
    46 // ----------------------------------------------------------------
    47 
    48 enum eObjType { otDir, otParent, otFile, otBase };
    49 
    50 class cFileObj : public cListObject {
    51 private:
    52   cFileSource *source;
    53   char *subdir, *name, *path, *fpath;
    54   eObjType type;
    55   //
    56   void Set(void);
    57   void MakeFullName(char **fp, const char *Name);
    58 public:
    59   cFileObj(cFileSource *Source, const char *Subdir, const char *Name, const eObjType Type);
    60   cFileObj(const cFileObj *obj);
    61   virtual ~cFileObj();
    62 #if APIVERSNUM >= 10315
    63   virtual int Compare(const cListObject &ListObject) const;
    64 #else
    65   virtual bool operator<(const cListObject &ListObject);
    66 #endif
    67   void SetName(const char *Name);
    68   void SplitAndSet(const char *Path);
    69   bool GuessType(void);
    70   //
    71   bool Exists(void);
    72   bool TestName(const char *newName);
    73   bool Rename(const char *newName);
    74   bool Create(const char *newName);
    75   bool Delete(void);
    76   //
    77   inline const char *Name(void) const { return name; }
    78   inline const char *Subdir(void) const { return subdir; }
    79   inline cFileSource *Source(void) const { return source; }
    80   inline eObjType Type(void) const { return type; }
    81   inline const char *Path(void) const { return path; }
    82   inline const char *FullPath(void) const { return fpath; }
    83   };
    84 
    85 // ----------------------------------------------------------------
    86 
    87 class cDirList : public cScanDir, public cList<cFileObj> {
    88 private:
    89   eObjType otype;
    90 protected:
    91   virtual void DoItem(cFileSource *src, const char *subdir, const char *name);
    92 public:
    93   bool Load(cFileSource *src, const char *subdir, const char * const *excl=0);
    94   };
    95 
    96 // ----------------------------------------------------------------
    97 
    98 class cFileSource : public cListObject {
    99 private:
   100   enum eAction { acMount, acUnmount, acEject, acStatus };
   101   char *basedir, *realbasedir;
   102   char *description;
   103   char **include;
   104   bool needsmount;
   105   int useCount, incCount;
   106   // remember last browse position
   107   char *browsedir, *browseparent;
   108   //
   109   void Set(const char *Basedir, const char *Description, const bool NeedsMount, const char *Include);
   110   bool Action(eAction act);
   111   void ClearRemember(void);
   112   void Clear(void);
   113 public:
   114   cFileSource(void);
   115   cFileSource(const char *Basedir, const char *Description, const bool NeedsMount, const char *Include=0);
   116   ~cFileSource();
   117   bool Parse(char *s);
   118   bool Mount(void);
   119   bool Unmount(void);
   120   bool Eject(void);
   121   bool Status(void);
   122   void Block(void) { useCount++; }
   123   void Unblock(void) { useCount--; }
   124   void SetRemember(const char *dir, const char *parent);
   125   bool GetRemember(char * &dir, char * &parent);
   126   inline const char *BaseDir(void) const { return basedir; }
   127   inline const char *RealBaseDir(void) const { return realbasedir; }
   128   inline const char *Description(void) const { return description; }
   129   inline const char * const * Include(void) const { return include; }
   130   inline bool NeedsMount(void) const { return needsmount; }
   131   };
   132 
   133 #endif //___DATA_H