summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/datacd/k3bdatadoc.h
blob: eccbde9ad8b61828d3bebde034a3f2f3881e03fc (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/* 
 *
 * $Id: k3bdatadoc.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 K3BDATADOC_H
#define K3BDATADOC_H

#include <k3bdoc.h>
#include <k3bdataitem.h>

#include "k3bisooptions.h"

#include <tqptrlist.h>
#include <tqfileinfo.h>
#include <tqstringlist.h>

#include <kurl.h>
#include <kio/global.h>
#include "k3b_export.h"

class K3bDataItem;
class K3bRootItem;
class K3bDirItem;
class K3bFileItem;
class K3bJob;
class K3bBootItem;
class K3bFileCompilationSizeHandler;

class KProgressDialog;
//class K3bView;
class KConfig;
class TQString;
class TQStringList;
class TQWidget;
class TQDomDocument;
class TQDomElement;
class K3bIso9660Directory;

namespace K3bDevice {
  class Device;
  class DeviceHandler;
}


/**
 *@author Sebastian Trueg
 */

class LIBK3B_EXPORT K3bDataDoc : public K3bDoc
{
  Q_OBJECT
  TQ_OBJECT

 public:
  K3bDataDoc( TQObject* tqparent = 0 );
  virtual ~K3bDataDoc();

  virtual int type() const { return DATA; }
  virtual TQString typeString() const;

  virtual TQString name() const;

  enum MultiSessionMode { 
    /**
     * Let the K3bDataJob decide if to close the CD or not.
     * The decision is based on the state of the inserted media
     * (appendable/closed), the size of the project (will it fill 
     * up the CD?), and the free space on the inserted media.
     */
    AUTO,
    NONE, 
    START, 
    CONTINUE, 
    FINISH
  };

  K3bRootItem* root() const { return m_root; }

  virtual bool newDocument();
  virtual KIO::filesize_t size() const;

  /**
   * This is used for multisession where size() also returnes the imported session's size
   */
  virtual KIO::filesize_t burningSize() const;
  virtual K3b::Msf length() const;
  virtual K3b::Msf burningLength() const;

  /**
   * Simply deletes the item if it is removable (meaning isRemovable() returns true.
   * Be aware that you can remove items simply by deleting them even if isRemovable()
   * returns false.
   */
  void removeItem( K3bDataItem* item );

  /**
   * Simply calls reparent.
   */
  void moveItem( K3bDataItem* item, K3bDirItem* newParent );
  void moveItems( TQPtrList<K3bDataItem> itemList, K3bDirItem* newParent );

  K3bDirItem* addEmptyDir( const TQString& name, K3bDirItem* tqparent );
	
  TQString treatWhitespace( const TQString& );
	
  virtual K3bBurnJob* newBurnJob( K3bJobHandler* hdl, TQObject* tqparent = 0 );
	
  MultiSessionMode multiSessionMode() const { return m_multisessionMode; }
  void setMultiSessionMode( MultiSessionMode mode );

  int dataMode() const { return m_dataMode; }
  void setDataMode( int m ) { m_dataMode = m; }

  void setVerifyData( bool b ) { m_verifyData = b; }
  bool verifyData() const { return m_verifyData; }

  static bool nameAlreadyInDir( const TQString&, K3bDirItem* );

  /**
   * Most of the options that map to the mkisofs parameters are grouped
   * together in the K3bIsoOptions class to allow easy saving to and loading
   * from a KConfig object.
   */
  const K3bIsoOptions& isoOptions() const { return m_isoOptions; }
  void setIsoOptions( const K3bIsoOptions& );

  const TQPtrList<K3bBootItem>& bootImages() { return m_bootImages; }
  K3bDataItem* bootCataloge() { return m_bootCataloge; }

  K3bDirItem* bootImageDir();

  /**
   * Create a boot item and also create a boot cataloge file in case none
   * exists in the project.
   *
   * Calling this method has the same effect like creating a new K3bBootItem 
   * instance manually and then calling createBootCatalogeItem.
   *
   * \return The new boot item on success or 0 in case a file with the same
   *         name already exists.
   */
  K3bBootItem* createBootItem( const TQString& filename, K3bDirItem* bootDir = 0 );

  /**
   * Create a new boot catalog item.
   * For now this is not called automatically for internal reasons.
   *
   * Call this if you create boot items manually instead of using createBootItem.
   *
   * The boot catalog is automatically deleted once the last boot item is removed
   * from the doc.
   *
   * \return The new boot catalog item or the old one if it already exists.
   */
  K3bDataItem* createBootCatalogeItem( K3bDirItem* bootDir );

  /**
   * This will prepare the filenames as written to the image.
   * These filenames are saved in K3bDataItem::writtenName
   */
  void prepareFilenames();

  /**
   * Returns true if filenames need to be cut due to the limitations of Joliet.
   *
   * This is only valid after a call to @p prepareFilenames()
   */
  bool needToCutFilenames() const { return m_needToCutFilenames; }

  const TQValueList<K3bDataItem*>& needToCutFilenameItems() const { return m_needToCutFilenameItems; }

  /**
   * Imports a session into the project. This will create K3bSessionImportItems
   * and properly set the imported session size.
   * Some settings will be adjusted to the imported session (joliet, rr).
   * 
   * Be aware that this method is blocking.
   *
   * \return true if the old session was successfully imported, false if no
   *         session could be found.
   *
   * \see clearImportedSession()
   */
  bool importSession( K3bDevice::Device* );

  bool sessionImported() const;

  /**
   * Searches for an item by it's local path.
   *
   * NOT IMPLEMENTED YET!
   *
   * \return The items that correspond to the specified local path.
   */
  TQValueList<K3bDataItem*> findItemByLocalPath( const TQString& path ) const;

 public slots:
  virtual void addUrls( const KURL::List& urls );

  /**
   * Add urls syncroneously
   * This method adds files recursively including symlinks, hidden, and system files.
   * If a file already exists the new file's name will be appended a number.
   */
  virtual void addUrls( const KURL::List& urls, K3bDirItem* dir );

  void clearImportedSession();

  /**
   * Just a convience method to prevent using setIsoOptions for this
   * often used value.
   */
  void setVolumeID( const TQString& );

 signals:
  void itemRemoved( K3bDataItem* );
  void itemAdded( K3bDataItem* );

 protected:
  /** reimplemented from K3bDoc */
  virtual bool loadDocumentData( TQDomElement* root );
  /** reimplemented from K3bDoc */
  virtual bool saveDocumentData( TQDomElement* );

  void saveDocumentDataOptions( TQDomElement& optionsElem );
  void saveDocumentDataHeader( TQDomElement& headerElem );
  bool loadDocumentDataOptions( TQDomElement optionsElem );
  bool loadDocumentDataHeader( TQDomElement optionsElem );

  K3bFileCompilationSizeHandler* m_sizeHandler;

  //  K3bFileCompilationSizeHandler* m_oldSessionSizeHandler;
  KIO::filesize_t m_oldSessionSize;

 private:
  void prepareFilenamesInDir( K3bDirItem* dir );
  void createSessionImportItems( const K3bIso9660Directory*, K3bDirItem* tqparent );

  /**
   * used by K3bDirItem to inform about removed items.
   */
  void itemRemovedFromDir( K3bDirItem* tqparent, K3bDataItem* removedItem );
  void itemAddedToDir( K3bDirItem* tqparent, K3bDataItem* addedItem );

  /**
   * load recursivly
   */
  bool loadDataItem( TQDomElement& e, K3bDirItem* tqparent );
  /**
   * save recursivly
   */
  void saveDataItem( K3bDataItem* item, TQDomDocument* doc, TQDomElement* tqparent );

  void informAboutNotFoundFiles();

  TQStringList m_notFoundFiles;
  TQStringList m_noPermissionFiles;

  K3bRootItem* m_root;

  int m_dataMode;

  bool m_verifyData;

  KIO::filesize_t m_size;
		
  K3bIsoOptions m_isoOptions;

  MultiSessionMode m_multisessionMode;
  TQPtrList<K3bDataItem> m_oldSession;

  // boot cd stuff
  K3bDataItem* m_bootCataloge;
  TQPtrList<K3bBootItem> m_bootImages;

  bool m_bExistingItemsReplaceAll;
  bool m_bExistingItemsIgnoreAll;

  bool m_needToCutFilenames;
  TQValueList<K3bDataItem*> m_needToCutFilenameItems;

  friend class K3bMixedDoc;
  friend class K3bDirItem;
};

#endif