data.h
author nathan
Sun, 12 Dec 2010 11:31:54 +0100
branchtrunk
changeset 38 79b272a68eb4
parent 29 640ce9201139
permissions -rw-r--r--
fix compile without OGG library
     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 extern char *aprintf(const char *fmt, ...) __attribute__ ((format (printf,1,2)));
    35 
    36 // ----------------------------------------------------------------
    37 
    38 class cScanDir {
    39 protected:
    40   enum eScanType { stFile, stDir };
    41   virtual void DoItem(cFileSource *src, const char *subdir, const char *name)=0;
    42 public:
    43   virtual ~cScanDir() {}
    44   bool ScanDir(cFileSource *src, const char *subdir, eScanType type, const char * const *spec, const char * const *excl, bool recursiv);
    45   };
    46 
    47 // ----------------------------------------------------------------
    48 
    49 enum eObjType { otDir, otParent, otFile, otBase };
    50 
    51 class cFileObj : public cListObject {
    52 private:
    53   cFileSource *source;
    54   char *subdir, *name, *path, *fpath;
    55   eObjType type;
    56   //
    57   void Set(void);
    58   void MakeFullName(char **fp, const char *Name);
    59 public:
    60   cFileObj(cFileSource *Source, const char *Subdir, const char *Name, const eObjType Type);
    61   cFileObj(const cFileObj *obj);
    62   virtual ~cFileObj();
    63   virtual int Compare(const cListObject &ListObject) const;
    64   void SetName(const char *Name);
    65   void SplitAndSet(const char *Path);
    66   bool GuessType(void);
    67   //
    68   bool Exists(void);
    69   bool TestName(const char *newName);
    70   bool Rename(const char *newName);
    71   bool Create(const char *newName);
    72   bool Delete(void);
    73   //
    74   inline const char *Name(void) const { return name; }
    75   inline const char *Subdir(void) const { return subdir; }
    76   inline cFileSource *Source(void) const { return source; }
    77   inline eObjType Type(void) const { return type; }
    78   inline const char *Path(void) const { return path; }
    79   inline const char *FullPath(void) const { return fpath; }
    80   };
    81 
    82 // ----------------------------------------------------------------
    83 
    84 class cDirList : public cScanDir, public cList<cFileObj> {
    85 private:
    86   eObjType otype;
    87 protected:
    88   virtual void DoItem(cFileSource *src, const char *subdir, const char *name);
    89 public:
    90   bool Load(cFileSource *src, const char *subdir, const char * const *excl=0);
    91   };
    92 
    93 // ----------------------------------------------------------------
    94 
    95 class cFileSource : public cListObject {
    96 private:
    97   enum eAction { acMount, acUnmount, acEject, acStatus };
    98   char *basedir, *realbasedir;
    99   char *description;
   100   char **include;
   101   bool needsmount;
   102   int useCount, incCount;
   103   // remember last browse position
   104   char *browsedir, *browseparent;
   105   //
   106   void Set(const char *Basedir, const char *Description, const bool NeedsMount, const char *Include);
   107   bool Action(eAction act);
   108   void ClearRemember(void);
   109   void Clear(void);
   110 public:
   111   cFileSource(void);
   112   cFileSource(const char *Basedir, const char *Description, const bool NeedsMount, const char *Include=0);
   113   ~cFileSource();
   114   bool Parse(char *s);
   115   bool Mount(void);
   116   bool Unmount(void);
   117   bool Eject(void);
   118   bool Status(void);
   119   void Block(void) { useCount++; }
   120   void Unblock(void) { useCount--; }
   121   void SetRemember(const char *dir, const char *parent);
   122   bool GetRemember(char * &dir, char * &parent);
   123   inline const char *BaseDir(void) const { return basedir; }
   124   inline const char *RealBaseDir(void) const { return realbasedir; }
   125   inline const char *Description(void) const { return description; }
   126   inline const char * const * Include(void) const { return include; }
   127   inline bool NeedsMount(void) const { return needsmount; }
   128   };
   129 
   130 #endif //___DATA_H