summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/datacd/k3bdataitem.h
blob: 043a0d551de3f3ee5c2dabf4cbff6b86f144c63d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* 
 *
 * $Id: k3bdataitem.h 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program 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.
 * See the file "COPYING" for the exact licensing terms.
 */


#ifndef K3BDATAITEM_H
#define K3BDATAITEM_H


class K3bDirItem;
class K3bDataDoc;

#include <tqstring.h>

#include <kio/global.h>

#include <k3bmsf.h>
#include "k3b_export.h"


/**
  *@author Sebastian Trueg
  */
class LIBK3B_EXPORT K3bDataItem
{
 public: 
  K3bDataItem( K3bDataDoc* doc, K3bDataItem* parent = 0, int flags = 0 );

  /**
   * Default copy constructor.
   *
   * The result is an exact copy except that no parent dir it set and, thus, also no doc.
   */
  K3bDataItem( const K3bDataItem& );

  virtual ~K3bDataItem();

  /**
   * Return an exact copy of this data item.
   *
   * The result is an exact copy except that no parent dir it set and, thus, also no doc.
   *
   * Implementations should use the default constructor.
   */
  virtual K3bDataItem* copy() const = 0;
	
  K3bDirItem* parent() { return m_parentDir; }
  K3bDirItem* getParent() const { return m_parentDir; }

  /**
   * Remove this item from it's parent and return a pointer to it.
   */
  K3bDataItem* take();
	
  K3bDataDoc* doc() const { return m_doc; }
  virtual const TQString& k3bName() const;
  virtual void setK3bName( const TQString& );

  /** 
   * returns the path as defined by the k3b-hierachy, NOT starting with a slash
   * (since this is used for graft-points!) 
   * directories have a trailing "/"
   */
  virtual TQString k3bPath() const;

  /**
   * Returns the name of the item as used on the CD or DVD image.
   *
   * This is only valid after a call to @p K3bDataDoc::prepareFilenames()
   */
  const TQString& writtenName() const { return m_writtenName; }

  /**
   * \return the pure name used in the Iso9660 tree.
   *
   * This is only valid after a call to @p K3bDataDoc::prepareFilenames()
   */
  const TQString& iso9660Name() const { return m_rawIsoName; }

  /**
   * Returns the path of the item as written to the CD or DVD image.
   *
   * This is suited to be used for mkisofs graftpoints.
   *
   * This is only valid after a call to @p K3bDataDoc::prepareFilenames()
   */
  virtual TQString writtenPath() const;

  virtual TQString iso9660Path() const;

  /**
   * Used to set the written name by @p K3bDataDoc::prepareFilenames()
   */
  void setWrittenName( const TQString& s ) { m_writtenName = s; }

  /**
   * Used to set the pure Iso9660 name by @p K3bDataDoc::prepareFilenames()
   */
  void setIso9660Name( const TQString& s ) { m_rawIsoName = s; }

  virtual K3bDataItem* nextSibling() const;
	
  /** returns the path to the file on the local filesystem */
  virtual TQString localPath() const { return TQString(); }

  /**
   * The size of the item
   */
  KIO::filesize_t size() const;

  /**
   * \return The number of blocks (2048 bytes) occupied by this item.
   *         This value equals to ceil(size()/2048)
   */
  K3b::Msf blocks() const;

  /** 
   * \returne the dir of the item (or the item itself if it is a dir)
   */
  virtual K3bDirItem* getDirItem() const { return getParent(); }

  virtual void reparent( K3bDirItem* );

  // FIXME: use all these flags and make the isXXX methods
  // non-virtual. Then move the parent()->addDataItem call
  // to the K3bDataItem constructor
  enum ItemFlags {
    DIR = 0x1,
    FILE = 0x2,
    SPECIALFILE = 0x4,
    SYMLINK = 0x8,
    OLD_SESSION = 0x10,
    BOOT_IMAGE = 0x11
  };

  int flags() const;

  virtual bool isDir() const { return false; }
  virtual bool isFile() const { return false; }
  virtual bool isSpecialFile() const { return false; }
  virtual bool isSymLink() const { return false; }	
  virtual bool isFromOldSession() const { return false; }
  bool isBootItem() const;

  bool hideOnRockRidge() const;
  bool hideOnJoliet() const;

  virtual void setHideOnRockRidge( bool b );
  virtual void setHideOnJoliet( bool b );

  virtual long sortWeight() const { return m_sortWeight; }
  virtual void setSortWeight( long w ) { m_sortWeight = w; }

  virtual int depth() const;

  virtual bool isValid() const { return true; }

  // these are all needed for special fileitems like
  // imported sessions or the movix filesystem
  virtual bool isRemoveable() const { return m_bRemoveable; }
  virtual bool isMoveable() const { return m_bMovable; }
  virtual bool isRenameable() const { return m_bRenameable; }
  virtual bool isHideable() const { return m_bHideable; }
  virtual bool writeToCd() const { return m_bWriteToCd; }
  virtual const TQString& extraInfo() const { return m_extraInfo; }

  void setRenameable( bool b ) { m_bRenameable = b; }
  void setMoveable( bool b ) { m_bMovable = b; }
  void setRemoveable( bool b ) { m_bRemoveable = b; }
  void setHideable( bool b ) { m_bHideable = b; }
  void setWriteToCd( bool b ) { m_bWriteToCd = b; }
  void setExtraInfo( const TQString& i ) { m_extraInfo = i; }

 protected:
  virtual KIO::filesize_t itemSize( bool followSymlinks ) const = 0;

  /**
   * \param followSymlinks If true symlinks will be followed and their
   *                       size equals the size of the file they are
   *                       pointing to.
   *
   * \return The number of blocks (2048 bytes) occupied by this item.
   */
  virtual K3b::Msf itemBlocks( bool followSymlinks ) const;

  TQString m_k3bName;

  void setFlags( int flags );

 private:
  class Private;
  Private* d;

  TQString m_writtenName;
  TQString m_rawIsoName;

  K3bDataDoc* m_doc;
  K3bDirItem* m_parentDir;

  bool m_bHideOnRockRidge;
  bool m_bHideOnJoliet;
  bool m_bRemoveable;
  bool m_bRenameable;
  bool m_bMovable;
  bool m_bHideable;
  bool m_bWriteToCd;
  TQString m_extraInfo;

  long m_sortWeight;

  friend class K3bDirItem;
};

#endif