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