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


#include "k9newtitle.h"
#include "k9import.h"
#include <tqradiobutton.h>
#include <knuminput.h>
#include <ktimewidget.h>
#include <k9avidecode.h>
#include <tdelocale.h>
#include "k9menu.h"
#include "k9menubutton.h"
#include "kpushbutton.h"
#include <tdemessagebox.h>
#include <kcursor.h>
k9NewTitle::k9NewTitle(TQWidget* parent, const char* name, WFlags fl)
        : newTitle(parent,name,fl) {
    m_fileName="";
}

k9NewTitle::~k9NewTitle() {}

/*$SPECIALIZATION$*/

void k9NewTitle::fileSelected(const TQString &_fileName) {
    m_fileName=_fileName;
    k9AviDecode fileInfo(0,0);
    fileInfo.open(m_fileName);
    double duration=fileInfo.getDuration();
    fileInfo.close();
    TQTime t(0,0,0);
    t=t.addSecs(duration); 
    lTotalTime->setText(t.toString("hh:mm:ss"));
    bAdd->setEnabled(true);
}

void k9NewTitle::drawImage (TQImage *_image) {
    m_image=*_image;
}

void k9NewTitle::bAddClicked() {
    k9Config config;
    k9AviDecode fileInfo(0,0);
    if (!fileInfo.open(m_fileName)) {
        KMessageBox::error(this,fileInfo.getError(),i18n("Add title"));
        return;
    }
    this->setCursor(KCursor::waitCursor());

    k9LvItemImport * item=new k9LvItemImport(m_k9Import->getRoot(),k9LvItemImport::TITLE);
    item->setOpen(true);
    k9Title *title=new k9Title( m_k9Import->getNewDVD());
    item->setText(0,i18n("title %1").arg(title->getNum() +1));

    connect( title->getButton(),TQT_SIGNAL(sigsetImage(k9MenuButton*, const TQImage&)),m_k9Import,TQT_SLOT(buttonUpdated(k9MenuButton*, const TQImage&)));
    item->setTitle(title);


    connect(&fileInfo,TQT_SIGNAL(drawFrame(TQImage*)),this,TQT_SLOT(drawImage(TQImage*)));



    TQTime t;
    m_k9Import->getRoot()->listView()->setColumnWidthMode(0,TQListView::Maximum);
    item->setText(1,t.addSecs(fileInfo.getDuration()).toString("hh:mm:ss"));

    double increment = 5*60;
    int maxCh;
    if (rbLength->isOn()) {
        TQTime t;
        increment=t.secsTo(twLength->time());
        maxCh=999;
    }

    if (rbNumber->isOn()) {
        increment=fileInfo.getDuration() /nbChapters->value();
        maxCh=nbChapters->value();
    }

    double pos=0;
    k9AviFile *last=NULL;
    int width=config.getPrefButtonWidth();
    int height=config.getPrefButtonHeight();
    int left=-width+20;
    int top=50;

    int i=-1;
    while ( pos <fileInfo.getDuration() && i <maxCh-1){    
    //fileInfo.open(m_fileName);
        i++;
        fileInfo.readFrame(pos);
        k9AviFile *file=new k9AviFile(title,0);
        file->setImage(m_image);
        if (i==0)
            title->getButton()->setImage(m_image);

        file->setPrevious(last);
        if (last !=NULL)
            last->setNext(file);
        last=file;

        file->setFileName(m_fileName);
        file->setStart(t.addMSecs(pos*1000));
        pos+=increment;
        file->setEnd(t.addMSecs(TQMIN(pos,fileInfo.getDuration()) *1000));
        k9LvItemImport * itemch=new k9LvItemImport(item,k9LvItemImport::CHAPTER);
        itemch->setText(0,i18n("chapter %1").arg(i+1));
        itemch->setText(1,file->getStart().toString("hh:mm:ss") +" - "+file->getEnd().toString("hh:mm:ss") );
        itemch->setAviFile(file);
        itemch->setTitle(title);
        itemch->setPixmap(0,TQPixmap(m_image.smoothScale(50,40)));
        connect(file,TQT_SIGNAL(aviFileUpdated(k9AviFile*)),m_k9Import,TQT_SLOT(aviFileUpdated(k9AviFile*)));

        k9MenuButton *btn=title->getMenu()->addButton();
        btn->setNum(i+1);
        //_title->setButton(btn);
        btn->setImage(m_image);
        left +=width+10;
        if (left +width >720) {
            left=30;
            top+=height+25;
        }
        btn->setTop(top);
        btn->setLeft(left);
        btn->setWidth(width);
        btn->setHeight(height);
        btn->setScript(TQString("jump title 1 chapter %1 ;").arg(i+1));
        btn->setTextPosition(k9MenuButton::BOTTOM);
        btn->setText(i18n("chapter %1").arg(i+1));
        btn->setColor(config.getPrefButtonTextColor());
        btn->setFont(config.getPrefButtonFont());
        connect(file,TQT_SIGNAL(imageChanged(const TQImage&)),btn,TQT_SLOT(setImage(const TQImage&)));

    }
    title->getMenu()->setEndScript("call vmgm menu;");
    fileInfo.close();
    m_k9Import->lvDVD->setSortColumn(0);
    m_k9Import->lvDVD->sort();
    m_k9Import->setEnableCreate(true);
    m_k9Import->updateTotalTime();
    this->setCursor(KCursor::arrowCursor());
}

void k9NewTitle::rbNumberClicked() {
    twLength->setEnabled(false);
    nbChapters->setEnabled(true);
}

void k9NewTitle::rbLengthClicked() {
    twLength->setEnabled(true);
    nbChapters->setEnabled(false);

}

#include "k9newtitle.moc"



void k9NewTitle::setK9Import ( k9Import* _value ) {
    m_k9Import = _value;
}