summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/datacd/k3bdataitem.cpp
blob: f5ce21df1d4d1d941d1abcb39030dc77e99182cd (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
/* 
 *
 * $Id: k3bdataitem.cpp 659634 2007-04-30 14:51:32Z 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.
 */


#include "k3bdataitem.h"
#include "k3bdiritem.h"
#include "k3bdatadoc.h"
#include <kdebug.h>

#include <math.h>


class K3bDataItem::Private
{
public:
  int flags;
};


K3bDataItem::K3bDataItem( K3bDataDoc* doc, K3bDataItem* parent, int flags )
  : m_bHideOnRockRidge(false),
    m_bHideOnJoliet(false),
    m_bRemoveable(true),
    m_bRenameable(true),
    m_bMovable(true),
    m_bHideable(true),
    m_bWriteToCd(true),
    m_sortWeight(0)
{
  d = new Private;
  d->flags = flags;

  m_doc = doc;
  m_bHideOnRockRidge = m_bHideOnJoliet = false;

  if( parent )
    m_parentDir = parent->getDirItem();
  else
    m_parentDir = 0;
}


K3bDataItem::K3bDataItem( const K3bDataItem& item )
  : m_k3bName( item.m_k3bName ),
    m_doc( 0 ),
    m_parentDir( 0 ),
    m_bHideOnRockRidge( item.m_bHideOnRockRidge ),
    m_bHideOnJoliet( item.m_bHideOnJoliet ),
    m_bRemoveable( item.m_bRemoveable ),
    m_bRenameable( item.m_bRenameable ),
    m_bMovable( item.m_bMovable ),
    m_bHideable( item.m_bHideable ),
    m_bWriteToCd( item.m_bWriteToCd ),
    m_extraInfo( item.m_extraInfo ),
    m_sortWeight( item.m_sortWeight )
{
  d = new Private;
  d->flags = item.d->flags;
}


K3bDataItem::~K3bDataItem()
{
  delete d;
}


void K3bDataItem::setFlags( int flags )
{
  d->flags = flags;
}


bool K3bDataItem::isBootItem() const
{
  return d->flags & BOOT_IMAGE;
}


KIO::filesize_t K3bDataItem::size() const
{
  return itemSize( m_doc 
		   ? m_doc->isoOptions().followSymbolicLinks() || 
		   !m_doc->isoOptions().createRockRidge()
		   : false );
}


K3b::Msf K3bDataItem::blocks() const
{
  return itemBlocks( m_doc 
		     ? m_doc->isoOptions().followSymbolicLinks() || 
		     !m_doc->isoOptions().createRockRidge()
		     : false );
}


K3b::Msf K3bDataItem::itemBlocks( bool followSymbolicLinks ) const
{
  return (long)::ceil( (double)itemSize( followSymbolicLinks ) / 2048.0 );
}


void K3bDataItem::setK3bName( const TQString& name ) {
    if ( name != m_k3bName ) {
  // test for not-allowed characters
  if( name.contains('/') ) {
    kdDebug() << "(K3bDataItem) name contained invalid characters!" << endl;
    return;
  }
   
  if( parent() ) {
    K3bDataItem* item = parent()->find( name );
    if( item && item != this ) {
      kdDebug() << "(K3bDataItem) item with that name already exists." << endl;
      return;
    }
  }

  m_k3bName = name;
        m_doc->setModified();
}
}


const TQString& K3bDataItem::k3bName() const
{
  return m_k3bName;
}


K3bDataItem* K3bDataItem::take()
{
  if( parent() )
    parent()->takeDataItem( this );

  return this;
}


TQString K3bDataItem::k3bPath() const
{
  if( !getParent() )
    return TQString();  // the root item is the only one not having a parent
  else if( isDir() )
    return getParent()->k3bPath() + k3bName() + "/";
  else
    return getParent()->k3bPath() + k3bName();
}


TQString K3bDataItem::writtenPath() const
{
  if( !getParent() )
    return TQString();  // the root item is the only one not having a parent
  else if( isDir() )
    return getParent()->writtenPath() + writtenName() + "/";
  else
    return getParent()->writtenPath() + writtenName();
}


TQString K3bDataItem::iso9660Path() const
{
  if( !getParent() )
    return TQString();  // the root item is the only one not having a parent
  else if( isDir() )
    return getParent()->iso9660Path() + iso9660Name() + "/";
  else
    return getParent()->iso9660Path() + iso9660Name();
}


K3bDataItem* K3bDataItem::nextSibling() const
{
  K3bDataItem* item = const_cast<K3bDataItem*>(this); // urg, but we know that we don't mess with it, so...
  K3bDirItem* parentItem = getParent();
	
  while( parentItem ) {
    if( K3bDataItem* i = parentItem->nextChild( item ) )
      return i;
		
    item = parentItem;
    parentItem = item->getParent();
  }

  return 0;
}


void K3bDataItem::reparent( K3bDirItem* newParent )
{
  // addDataItem will do all the stuff including taking this
  newParent->addDataItem( this );
}


bool K3bDataItem::hideOnRockRidge() const
{ 
  if( !isHideable() )
    return false;
  if( getParent() )
    return m_bHideOnRockRidge || getParent()->hideOnRockRidge();
  else 
    return m_bHideOnRockRidge;
}


bool K3bDataItem::hideOnJoliet() const
{
  if( !isHideable() )
    return false;
  if( getParent() ) 
    return m_bHideOnJoliet || getParent()->hideOnJoliet();
  else
    return m_bHideOnJoliet;
}


void K3bDataItem::setHideOnRockRidge( bool b )
{
  // there is no use in changing the value if 
  // it is already set by the parent
    if( ( !getParent() || !getParent()->hideOnRockRidge() ) &&
        b != m_bHideOnRockRidge ) {
    m_bHideOnRockRidge = b;
        if ( m_doc )
            m_doc->setModified();
}
}


void K3bDataItem::setHideOnJoliet( bool b ) 
{ 
  // there is no use in changing the value if 
  // it is already set by the parent
    if( ( !getParent() || !getParent()->hideOnJoliet() ) &&
        b != m_bHideOnJoliet ) {
    m_bHideOnJoliet = b;
    if ( m_doc )
        m_doc->setModified();
}
}


int K3bDataItem::depth() const
{
  if( getParent() )
    return getParent()->depth() + 1;
  else
    return 0;
}