summaryrefslogtreecommitdiffstats
path: root/libk9copy/k9dvdtitleset.cpp
blob: eb295ac25a7e579fa114368092f760ab3d9bda1e (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
//
// C++ Implementation: k9dvdtitleset
//
// Description:
//
//
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

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

k9DVDTitleset::k9DVDTitleset( uint _num,uint32_t _size) { 
  m_num=_num;
  m_size=_size;
  m_selected=false;
  m_updating=false;
  for (uint i=0;i<8;i++)
    m_audioStreams[i]=false;
};


const TQString k9DVDTitleset::getsize_mb()
{
  double size_mb=(double)m_size /512;
  TQString c;
  c.sprintf("%.2f",size_mb);
  return c;
}

int k9DVDTitleset::getnum()
{
  return m_num;
}

void k9DVDTitleset::add(k9DVDTitle * _title)
{
  titles.append(_title);
}

int k9DVDTitleset::count()
{
  return titles.count();
}

k9DVDTitle * k9DVDTitleset::gettitle(uint _pos)
{
  return titles.at(_pos);
}

uint32_t k9DVDTitleset::getsize()
{
  return m_size;
}

bool k9DVDTitleset::getselected()
{
  return m_selected;
}

void k9DVDTitleset::setselected(bool _state)
{
  // selectionner / d�electionner tous les titres
  for (int i=0; i<count();i++)
  {
    k9DVDTitle *title=titles.at(i);
    for (int j=0; j <title->getaudioStreamCount();j++)
      title->getaudioStream(j)->setselected(_state);
    for (int j=0;j<title->getsubPictureCount();j++)
      title->getsubtitle(j)->setselected(_state);
    title->setforceSelection(_state);
  }
  m_selected=_state;;
}

void k9DVDTitleset::updateSelection()
{
  if (m_updating)
    return;
  m_updating=true;


  bool selected=m_selected;
  m_selected=false;
  //check if at least on title is selected
  for (int i=0; i<count() && (!m_selected);i++)
  {
    k9DVDTitle *title=titles.at(i);
    if (title->isSelected() && title->getIndexed())
      m_selected=true;
  }

  //if titleset selected, we select all features. otherwise they are unselected
   if (selected !=m_selected)
    for (int i=0; i<count();i++)
    {
      k9DVDTitle *title=titles.at(i);
      //FIXED : parts of title selection
      if (title->getIndexed() && title->isSelected())
        for (uint iTitle=0;iTitle <title->getTitles().count();iTitle++)
        {
          k9DVDTitle *title2=title->getTitles().at(iTitle);
          for (int j=0; j <title2->getaudioStreamCount();j++) 
            title2->getaudioStream(j)->setselected(title->getaudioStream(j)->getselected());
          for (int j=0;j<title2->getsubPictureCount();j++)
            title2->getsubtitle(j)->setselected(title2->getsubtitle(j)->getselected());
          title2->setforceSelection(true);
        }
    }
  m_updating=false;
}

void k9DVDTitleset::setAudio(int _id,bool _selected) {
    m_audioStreams[_id -1]=_selected;
}

int k9DVDTitleset::getNewAudioStreamId(int _oldId) {
    int newId=0;
    //Returns the new stream Id, only if the stream is selected. Otherwise, returns 0
    if (m_audioStreams[_oldId-1]) {
/*        for (int i=0; i<_oldId;i++) {
            if (m_audioStreams[i])
                newId++;
        }
*/
        return _oldId;
    }
    return newId;
}