data.h
author nathan
Tue, 03 Feb 2009 20:33:04 +0800
branchtrunk
changeset 22 93aaf15c145a
parent 0 474a1293c3c0
child 29 640ce9201139
permissions -rw-r--r--
remove compatibility for VDR < 1.4.5
     1 /*
     2  * MP3/MPlayer plugin to VDR (C++)
     3  *
     4  * (C) 2001-2009 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   virtual int Compare(const cListObject &ListObject) const;
    63   void SetName(const char *Name);
    64   void SplitAndSet(const char *Path);
    65   bool GuessType(void);
    66   //
    67   bool Exists(void);
    68   bool TestName(const char *newName);
    69   bool Rename(const char *newName);
    70   bool Create(const char *newName);
    71   bool Delete(void);
    72   //
    73   inline const char *Name(void) const { return name; }
    74   inline const char *Subdir(void) const { return subdir; }
    75   inline cFileSource *Source(void) const { return source; }
    76   inline eObjType Type(void) const { return type; }
    77   inline const char *Path(void) const { return path; }
    78   inline const char *FullPath(void) const { return fpath; }
    79   };
    80 
    81 // ----------------------------------------------------------------
    82 
    83 class cDirList : public cScanDir, public cList<cFileObj> {
    84 private:
    85   eObjType otype;
    86 protected:
    87   virtual void DoItem(cFileSource *src, const char *subdir, const char *name);
    88 public:
    89   bool Load(cFileSource *src, const char *subdir, const char * const *excl=0);
    90   };
    91 
    92 // ----------------------------------------------------------------
    93 
    94 class cFileSource : public cListObject {
    95 private:
    96   enum eAction { acMount, acUnmount, acEject, acStatus };
    97   char *basedir, *realbasedir;
    98   char *description;
    99   char **include;
   100   bool needsmount;
   101   int useCount, incCount;
   102   // remember last browse position
   103   char *browsedir, *browseparent;
   104   //
   105   void Set(const char *Basedir, const char *Description, const bool NeedsMount, const char *Include);
   106   bool Action(eAction act);
   107   void ClearRemember(void);
   108   void Clear(void);
   109 public:
   110   cFileSource(void);
   111   cFileSource(const char *Basedir, const char *Description, const bool NeedsMount, const char *Include=0);
   112   ~cFileSource();
   113   bool Parse(char *s);
   114   bool Mount(void);
   115   bool Unmount(void);
   116   bool Eject(void);
   117   bool Status(void);
   118   void Block(void) { useCount++; }
   119   void Unblock(void) { useCount--; }
   120   void SetRemember(const char *dir, const char *parent);
   121   bool GetRemember(char * &dir, char * &parent);
   122   inline const char *BaseDir(void) const { return basedir; }
   123   inline const char *RealBaseDir(void) const { return realbasedir; }
   124   inline const char *Description(void) const { return description; }
   125   inline const char * const * Include(void) const { return include; }
   126   inline bool NeedsMount(void) const { return needsmount; }
   127   };
   128 
   129 #endif //___DATA_H