summaryrefslogtreecommitdiffstats
path: root/libk9copy/k9dvdtitle.cpp
blob: cfe80192d25a4303fe5617754b7db71cbfed319e (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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/**************************************************************************
*   Copyright (C) 2005 by Jean-Michel Petit                               *
*   [email protected]                                                  *
*                                                                         *
*   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.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
***************************************************************************/

#include "k9dvdtitle.h"

#include <tqapplication.h>

#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tqvaluelist.h>
#include "k9dvdtitleset.h"
#include "k9titleencopt.h"

//*******************k9DVDAudioStream**************
k9DVDAudioStream::k9DVDAudioStream() {
    size_mb=0;
    selected=false;
}

/** Read property of TQString format. */
const TQString& k9DVDAudioStream::getformat() {
    return format;
}

/** Read property of TQString frequency. */
const TQString& k9DVDAudioStream::getfrequency() {
    return frequency;
}
/** Read property of TQString quantization. */
const TQString& k9DVDAudioStream::getquantization() {
    return quantization;
}
/** Read property of int channels. */
const int& k9DVDAudioStream::getchannels() {
    return channels;
}
/** Read property of int appMode. */
const int& k9DVDAudioStream::getappMode() {
    return appMode;
}
/** Read property of TQString content. */
const TQString& k9DVDAudioStream::getcontent() {
    return content;
}

/** Read property of float size_mb. */
const float& k9DVDAudioStream::getsize_mb() {
    return size_mb;
}


/** Read property of bool selected. */
const bool& k9DVDAudioStream::getselected() {
    return selected;
}
/** Write property of bool selected. */
void k9DVDAudioStream::setselected( const bool& _newVal) {
    bool before=title->isSelected();
    selected = _newVal;
    title->gettitleset()->setAudio(getID(),_newVal);
    title->gettitleset()->updateSelection();
    bool after=title->isSelected();
    if (after!=before)
    	title->selectChapters( after);
}

/** Read property of TQString langCod. */
const TQString& k9DVDAudioStream::getlangCod() {
    return langCod;
}
/** Read property of TQString language. */
const TQString& k9DVDAudioStream::getlanguage() {
    return language;
}

k9DVDTitle * k9DVDAudioStream::gettitle() {
	return title;
}

int k9DVDAudioStream::getID() {
    return(id);
}

//*******************k9DVDSubtitle *******************

k9DVDSubtitle::k9DVDSubtitle() {
    size_mb=0;
    selected=false;
}


/** Read property of TQString langCod. */
const TQString& k9DVDSubtitle::getlangCod() {
    return langCod;
}
/** Read property of TQString language. */
const TQString& k9DVDSubtitle::getlanguage() {
    return language;
}
/** Read property of int num. */
const int& k9DVDSubtitle::getnum() {
    return num;
}
/** Read property of TQString content. */
const TQString& k9DVDSubtitle::getcontent() {
    return content;
}

/** Read property of bool selected. */
const bool& k9DVDSubtitle::getselected() {
    return selected;
}
/** Write property of bool selected. */
void k9DVDSubtitle::setselected( const bool& _newVal) {
    bool before=title->isSelected();
    selected = _newVal;
    title->gettitleset()->updateSelection();
    bool after=title->isSelected();
    if (after!=before)
    	title->selectChapters(after);
}

/** Read property of float size_mb. */
const float& k9DVDSubtitle::getsize_mb() {
    return size_mb;
}

k9DVDTitle * k9DVDSubtitle::gettitle() {
	return title;
}


/*!
\fn k9DVDSubtitle::getID()
*/
TQValueList<int>& k9DVDSubtitle::getID() {
    return id;
}


//************************* k9DVDTitle ***************************

/** No descriptions */
k9DVDAudioStream* k9DVDTitle::addAudioStream() {
    k9DVDAudioStream *auds;
    auds = new k9DVDAudioStream;
    auds->title=this;
    audioStreams.append(auds);
    return(auds);
}

/** No descriptions */
k9DVDSubtitle* k9DVDTitle::addSubtitle(int num) {
    k9DVDSubtitle *subt;
    subt = new k9DVDSubtitle;
    subt->title=this;
    subt->num=num;
    subtitles.append(subt);
    return(subt);
}

/** No descriptions */
k9DVDChapter* k9DVDTitle::addChapter(int num) {
    k9DVDChapter *chap;
    chap = new k9DVDChapter;
    chap->m_title=this;
    chap->num = num;
    chap->id=k9DVDChapter::getcptChapter();
    chapters.append(chap);
    return(chap);
}

k9DVDChapter* k9DVDTitle::getChapter(int num) {
    return (k9DVDChapter*)chapters.at(num);
}

/** No descriptions */
k9DVDAudioStream *k9DVDTitle::getaudioStream(int num) {
    return (k9DVDAudioStream*)audioStreams.at(num);
}


/** Read property of int chapterCount. */
const int& k9DVDTitle::getchapterCount() {
    return chapterCount;
}
/** Read property of int streamCount. */
const int& k9DVDTitle::getstreamCount() {
    return streamCount;
}

/** Read property of int audioStreamCount. */
const int& k9DVDTitle::getaudioStreamCount() {
    return audioStreamCount;
}

/** Read property of int audioStreamCount. */
const int& k9DVDTitle::getsubPictureCount() {
    return subPictureCount;
}
/** Read property of int streamCount. */
const TQTime& k9DVDTitle::getlength() {
    return length;
}

/** Read property of int streamCount. */
const int& k9DVDTitle::getnumTitle() {
    return numTitle;
}

/** No descriptions */
k9DVDSubtitle *k9DVDTitle::getsubtitle(int num) {
    return (k9DVDSubtitle*)subtitles.at(num);
}

/** Read property of float size_mb. */
const float& k9DVDTitle::getsize_mb() {
    return size_mb;
}

const float k9DVDTitle::gettotalsize_mb() {
    float size =size_mb;
    for (uint i=0;i<m_titles.count();i++) {
         k9DVDTitle *tmp=m_titles.at(i);
   	 size +=tmp->getsize_mb();
    }
    return size;

}

//If _selected=true, returns the size of selected chapters, otherwise returns size of
//unselected ones
const float k9DVDTitle::getChaptersSize_mb(bool _selected){
   return (getChaptersSize(_selected)/512);
}

//If _selected=true, returns the size of selected chapters, otherwise returns size of
//unselected ones
const uint64_t k9DVDTitle::getChaptersSize(bool _selected){
	uint64_t total=0;
	for (int i=0;i<chapterCount ;i++) {
		k9DVDChapter *chap = getChapter( i);
		if (chap->getSelected()==_selected) {
			total+= chap->getsectors();
		}
	}
	for (uint i=0;i<m_titles.count();i++) {
		k9DVDTitle * title=m_titles.at(i);
		total+=title->getChaptersSize(_selected);
	}
	return total;

}

const float k9DVDTitle::gettotalvideosize_mb() {
    float size =videosize_mb;
    for (uint i=0;i<m_titles.count();i++) {
         k9DVDTitle *tmp=m_titles.at(i);
 	 size+=tmp->getvideosize_mb();
    }
    return size;

}


TQTime k9DVDTitle::gettotallength() {
    TQTime totalTime=getlength();
    for (uint i=0;i<m_titles.count();i++) {
         k9DVDTitle *tmp=m_titles.at(i);
	 TQTime t;
	 int msecs= t.msecsTo(tmp->getlength());
	 totalTime=totalTime.addMSecs(msecs);
    }
    return totalTime;

}

TQTime k9DVDTitle::getSelectedLength() {
    TQTime totalTime(0,0);
    for (k9DVDChapter *chapter=chapters.first();chapter;chapter=chapters.next()) {
    	if (chapter->getSelected()) {
		TQTime t;
		int msecs= t.msecsTo(chapter->getlength());
		totalTime=totalTime.addMSecs(msecs);
    	}
    }
    
    
    for (uint i=0;i<m_titles.count();i++) {
         k9DVDTitle *tmp=m_titles.at(i);
         TQPtrList <k9DVDChapter> tchapters=tmp->getChapters();
          for (k9DVDChapter *chapter=tchapters.first();chapter;chapter=tchapters.next()) {
		if (chapter->getSelected()) {
			TQTime t;
			int msecs= t.msecsTo(chapter->getlength());
			totalTime=totalTime.addMSecs(msecs);
		}
	}           
    }
    return totalTime;

}


/** Read property of float videosize_mb. */
const float& k9DVDTitle::getvideosize_mb() {
    return videosize_mb;
}


/** Read property of int VTS. */
const int& k9DVDTitle::getVTS() {
    return VTS;
}
/** Read property of int TTN. */
const int& k9DVDTitle::getTTN() {
    return TTN;
}
/** Read property of float FPS. */
const float& k9DVDTitle::getFPS() {
    return FPS;
}
/** Read property of TQString format. */
const TQString& k9DVDTitle::getformat() {
    return format;
}
/** Read property of TQString aspectRatio. */
const TQString& k9DVDTitle::getaspectRatio() {
    return aspectRatio;
}
/** Read property of TQString width. */
const TQString& k9DVDTitle::getwidth() {
    return width;
}
/** Read property of TQString height. */
const TQString& k9DVDTitle::getheight() {
    return height;
}
/** Read property of TQString palette. */
void k9DVDTitle::getpalette(int i,TQString & c) {
    c=*palette.at(i);
}
/** Read property of TQString DF. */
const TQString& k9DVDTitle::getDF() {
    return DF;
}
/** Read property of int angleCount. */
const int& k9DVDTitle::getangleCount() {
    return angleCount;
}


bool k9DVDTitle::isSelected() {
    k9DVDAudioStream *l_auds;
    k9DVDSubtitle *l_sub;
    uint i;

    if (forceSelection)
        return true;

    for (i=0;i<audioStreams.count();i++) {
        l_auds=getaudioStream(i);
        if (l_auds->getselected()) {
            return(true);
        }
    }

    for (i=0;i<subtitles.count();i++) {
        l_sub=getsubtitle(i);
        if (l_sub->getselected()) {
            return(true);
        }
    }
    return(false);
}

 void k9DVDTitle::setforceSelection(bool _state) { 
	bool before=isSelected();
	forceSelection = _state;    
	gettitleset()->updateSelection();
	bool after=isSelected();
	if (after!=before) {
	    selectChapters(after);
	    emit selectionChanged();
	}
}


/** Read property of TQString name. */
const TQString& k9DVDTitle::getname() {
    return name;
}
/** Write property of TQString name. */
void k9DVDTitle::setname( const TQString& _newVal) {
    name = _newVal;
}

/*!
\fn k9DVDTitle::getpgc()
*/
int k9DVDTitle::getpgc() {
    return(pgc);
}


/*!
\fn k9DVDTitle::setNextTitle(k9DVDTitle * nextTitle)
*/
void k9DVDTitle::setnextTitle(k9DVDTitle * nTitle) {
    nextTitle=nTitle;
}


/*!
\fn k9DVDTitle::getnextTitle()
*/
k9DVDTitle* k9DVDTitle::getnextTitle() {
    return nextTitle;
}


k9DVDAudioStream* k9DVDTitle::getDefAudio() const {
    return m_defAudio;
}


void k9DVDTitle::setDefAudio(k9DVDAudioStream* _value) {
    m_defAudio = _value;
    m_defAudioSet = true;
}


k9DVDSubtitle* k9DVDTitle::getDefSubtitle() const {
    return m_defSubtitle;
}


void k9DVDTitle::setDefSubtitle(k9DVDSubtitle* _value) {
    m_defSubtitle = _value;
    m_defSubtitleSet=true;
}


k9DVDTitle::k9DVDTitle() {
    audioStreams.setAutoDelete(true);
    chapters.setAutoDelete(true);
    subtitles.setAutoDelete(true);
    size_mb=0;
    videosize_mb=0;
    vobusize_mb=0;
    nextTitle=NULL;
    m_defAudio=NULL;
    m_defSubtitle=NULL;
    m_defAudioSet=false;
    m_defSubtitleSet=false;
    forceSelection=false;
    m_forceFactor=false;
    m_factor=0;
    m_encOpt=NULL;
}

k9TitleEncOpt* k9DVDTitle::getEncOpt()  { 
  if (!m_encOpt)
  	m_encOpt=new k9TitleEncOpt(this);
  return m_encOpt;
  
}


void k9DVDTitle::selectChapters(bool _state) {
    for (int i=0;i < chapterCount;i++) {
	getChapter(i)->setSelected( _state);    
    }
    
    for (uint iTitle=0;iTitle<m_titles.count();iTitle++) {
	k9DVDTitle * title=m_titles.at(iTitle);
	title->selectChapters(_state);     
    }
}

#include "k9dvdtitle.moc"