summaryrefslogtreecommitdiffstats
path: root/src/k9copy.cpp
blob: b7ec0c047191ba3e325b501e2f31d303a08cfebe (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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
//
// C++ Implementation: k9copy
//
// Description:
//
//
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "k9main.h"
#include "k9copy.h"
#include "k9settings.h"
#include "k9playbackoptions.h"
#include "k9langselect.h"
#include "k9config.h"
#include <tdeversion.h>
#include <kstatusbar.h>
#include <tdestdaccel.h>
#include <tdeaction.h>
#include <kstdaction.h>
#include <kdockwidget.h>
#include <tdemdidefines.h>
#include <tdemdichildarea.h>
#include <tqframe.h>
#include <kkeydialog.h>
#include <kedittoolbar.h>
#include <klibloader.h>
#include "kviewmpeg2.h"
#include "k9titlefactor.h"
#include <tqdom.h>
#include <ksimpleconfig.h>
#include "k9mp4title.h"
#include "k9tools.h"
#include "k9importfiles.h"
#include "k9import.h"
#include "k9menuedit.h"
#include "k9chapteredit.h"
#include "k9newtitle.h"
#include "k9menu.h"
#include <kdockwidget.h>
#include <kiconloader.h>

k9Copy::k9Copy()
        : KMdiMainFrm( 0, "k9Copy" ,KMdi::IDEAlMode ) {
    // tell the TDEMainWindow that this is indeed the main widget
    m_k9MainView=NULL;
    m_k9ImportView=NULL;
    m_chapterEdit=NULL;

   // accept dnd
    setAcceptDrops(true);

    // then, setup our actions
    setupActions();

    // and a status bar
    statusBar()->show();
    statusBar()->insertFixedItem("",sbFactor,TRUE);
    statusBar()->setItemFixed(sbFactor,100);
    statusBar()->insertItem("",sbMessage,1,FALSE);
    statusBar()->setItemAlignment(sbMessage,AlignLeft | AlignVCenter);

    // Apply the create the main window and ask the mainwindow to
    // automatically save settings if changed: window size, toolbar
    // position, icon size, etc.  Also to add actions for the statusbar
    // toolbar, and keybindings if necessary.
    resize(TQSize(800,600));

    setToolviewStyle(KMdi::TextAndIcon);
    createCopyWindows();
    backupAction->setChecked(true);
    //createImportWindows();
}


void k9Copy::createCopyWindows() {
    saveDock();
    if (m_k9ImportView) {
        m_k9ImportView->close();
        m_k9Import=NULL;
        m_k9ImportView=NULL;
    }
    removeToolWindows();

    m_actions["open"]->setEnabled(true);
    m_actions["quit"]->setEnabled(true);
    m_actions["preferences"]->setEnabled(true);
    m_actions["playtitle"]->setEnabled(true);
    m_actions["copy"]->setEnabled(true);
    m_actions["create"]->setEnabled(false);
    m_actions["mp4"]->setEnabled(true);
    m_actions["eject"]->setEnabled(true);


    k9Config config;
    m_useXine=config.getUseMplayer();

    m_useDvdAuthor=config.getUseDvdAuthor();

    if (config.getPrefVersion() != VERSION) {
        initCodecs();
        config.read();
        config.setPrefVersion(VERSION);
        config.save();
    }

    m_k9Main=new k9Main(this,0,&m_drives);
    m_k9MainView=createWrapper( m_k9Main,"","");
    addWindow(m_k9MainView, KMdi::StandardAdd);

    m_options=new k9PlaybackOptions(m_k9Main,this);
    KMdiToolViewAccessor *acc;
    acc=addToolWindow(m_options, KDockWidget::DockRight, getMainDockWidget(),0,i18n("DVD playback options"),i18n("DVD playback options"));
    acc->show();

    m_ToolViews.append(acc);

    m_lang=new k9LangSelect(m_k9Main,this);
    acc=addToolWindow(m_lang, KDockWidget::DockRight, getMainDockWidget(),0,i18n("Selection"),i18n("Selection"));
    m_ToolViews.append(acc);

    if (m_useXine) {
        m_mp2=new K9Mplayer(TQT_TQOBJECT(this));
    } else
        m_mp2=new kViewMPEG2();

    m_previewAcc=addToolWindow(m_mp2,KDockWidget::DockRight,getMainDockWidget(),0,i18n("Preview"),i18n("Preview"));
    m_ToolViews.append(m_previewAcc);

    connect(m_k9Main,TQT_SIGNAL(showPreview( k9DVD*, k9DVDTitle*,int )),m_mp2,TQT_SLOT(open( k9DVD*, k9DVDTitle*,int )));
    connect(m_k9Main,TQT_SIGNAL(stopPreview()),m_mp2,TQT_SLOT(bStopClick()));

    m_factors =new k9TitleFactor( this);
    m_factors->setUseDvdAuthor(m_useDvdAuthor);
    int h=m_factors->height();
    acc=addToolWindow(m_factors,KDockWidget::DockBottom,getMainDockWidget(),10,i18n("Shrink Factor"),i18n("Shrink Factor"));
    m_ToolViews.append(acc);

    connect(m_k9Main,TQT_SIGNAL(SelectionChanged( k9DVD*,bool )),m_factors,TQT_SLOT(SelectionChanged( k9DVD*,bool )));
    connect(m_k9Main,TQT_SIGNAL(changedTitle( k9DVDTitle* )),m_factors,TQT_SLOT(changedTitle( k9DVDTitle* )));

    KDockWidget *dw=dockManager->findWidgetParentDock (m_factors);
    dw->setForcedFixedHeight(h);

    addMp4TitleOptions();

    // allow the view to change the statusbar and caption

    connect(m_k9Main, TQT_SIGNAL(changeStatusbar(const TQString&,int )),
            this,   TQT_SLOT(changeStatusbar(const TQString&,int)));
    connect(m_k9Main, TQT_SIGNAL(changeCaption(const TQString&)),
            this,   TQT_SLOT(changeCaption(const TQString&)));

    setAutoSaveSettings();
    KSimpleConfig settings("K9Copy");
    if (settings.hasGroup("dock"))
        dockManager->readConfig((TDEConfig*)&settings,"dock");
}

void k9Copy::removeToolWindows() {
    for (KMdiToolViewAccessor *acc=m_ToolViews.first();acc;acc=m_ToolViews.next()) {
        deleteToolWindow(acc);
    }
    m_ToolViews.clear();
}

void k9Copy::createImportWindows() {
    saveDock();
    if (m_k9MainView) {
        m_k9MainView->close();
        m_k9Main=NULL;
        m_k9MainView=NULL;
    }

    removeToolWindows();
  
    m_actions["open"]->setEnabled(false);
    m_actions["quit"]->setEnabled(true);
    m_actions["preferences"]->setEnabled(true);
    m_actions["playtitle"]->setEnabled(false);
    m_actions["copy"]->setEnabled(false);
    m_actions["create"]->setEnabled(false);
    m_actions["mp4"]->setEnabled(false);
    m_actions["eject"]->setEnabled(false);
  
    KMdiToolViewAccessor *acc;
    m_k9Import=new k9Import(this,0,&m_drives);
    m_k9ImportView=createWrapper( m_k9Import,"","");
    addWindow(m_k9ImportView, KMdi::StandardAdd);
    
    m_menuEdit=new k9MenuEdit(this,0,m_k9Import->getNewDVD()->getRootMenu()->getCanvas());
    m_menuEdit->setIcon(SmallIcon("edit"));
    acc=addToolWindow(m_menuEdit, KDockWidget::DockRight, getMainDockWidget(),20,i18n("Edit menu"),i18n("Edit Menu"));
    m_ToolViews.append(acc);

    connect (m_k9Import,TQT_SIGNAL(titleSelected(k9Title*)),m_menuEdit,TQT_SLOT(titleSelected(k9Title*)));
    connect (m_k9Import,TQT_SIGNAL(rootSelected(k9NewDVD*)),m_menuEdit,TQT_SLOT(rootSelected(k9NewDVD*)));
    m_k9Import->setMenuEdit(m_menuEdit);

    m_newTitle=new k9NewTitle(this);
    m_newTitle->setK9Import(m_k9Import);
    m_newTitle->setIcon(SmallIcon("fileimport"));
    acc=addToolWindow(m_newTitle, KDockWidget::DockBottom, getMainDockWidget(),20,i18n("Add title"),i18n("Add title"));
    m_ToolViews.append(acc);
    acc->show();


    m_chapterEdit =new k9ChapterEdit(this);
    m_chapterEdit->setIcon(SmallIcon("title"));
    acc=addToolWindow(m_chapterEdit, KDockWidget::DockBottom, getMainDockWidget(),20,i18n("Chapter properties"),i18n("Chapter properties"));
    m_ToolViews.append(acc);
    connect(m_k9Import,TQT_SIGNAL(aviFileSelected(k9AviFile*)),m_chapterEdit,TQT_SLOT(setAviFile(k9AviFile*)));



    // allow the view to change the statusbar and caption
/*
    connect(m_k9Main, TQT_SIGNAL(changeStatusbar(const TQString&,int )),
            this,   TQT_SLOT(changeStatusbar(const TQString&,int)));
    connect(m_k9Main, TQT_SIGNAL(changeCaption(const TQString&)),
            this,   TQT_SLOT(changeCaption(const TQString&)));
*/
    setAutoSaveSettings();
    KSimpleConfig settings("K9Copy");
    if (settings.hasGroup("dockImport"))
        dockManager->readConfig((TDEConfig*)&settings,"dockImport");

    m_k9Import->init();

}


k9Copy::~k9Copy() {
    k9Config config;
    if (config.getPrefDelTmpFiles())
        k9Tools::clearOutput(config.getPrefOutput()+"/dvd");
}

void k9Copy::initCodecs() {
    k9VideoCodecs v(0,0);
    v.reset();
    k9AudioCodecs a(0,0);
    a.reset();
}

bool k9Copy::queryClose   (    ) {
    return true;
}

void k9Copy::setupActions() {

    m_actions["open"]=KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(fileOpen()), actionCollection());
    m_actions["quit"]=KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(quit()), actionCollection());
    m_actions["preferences"]=KStdAction::preferences(TQT_TQOBJECT(this),TQT_SLOT(preferences()),actionCollection());
    KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureKeys()), actionCollection());
    KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureToolbars()), actionCollection());


    setStandardToolBarMenuEnabled(TRUE);
    createStandardStatusBarAction();

    PlayTitleAction = new TDEAction(i18n("Play title"), 0,
                                  TQT_TQOBJECT(this), TQT_SLOT(ActionPlayTitle()),
                                  actionCollection(), "PlayTitle");
    m_actions["playtitle"]=PlayTitleAction;

    TQImage img;
    img.loadFromData( img_preview, sizeof( img_preview ), "PNG" );
    PlayTitleAction->setIconSet(TQIconSet(img));

    CopyAction = new TDEAction(i18n("Copy"), 0,
                             TQT_TQOBJECT(this), TQT_SLOT(ActionCopy()),
                             actionCollection(), "Copy");
    m_actions["copy"]=CopyAction;
    CopyAction->setIcon("dvdcopy");


    mkMpeg2Action = new TDEAction(i18n("Extract MPEG2"),0,
                              TQT_TQOBJECT(this), TQT_SLOT(ActionMpeg2()),
                              actionCollection(),"MakeMPEG2");
    m_actions["mp2"]=mkMpeg2Action;

    mkMpeg2Action->setIcon("mpeg");

    mkMP4Action = new TDEAction(i18n("Create MPEG-4"),0,
                              TQT_TQOBJECT(this), TQT_SLOT(ActionMP4()),
                              actionCollection(),"MakeMPEG4");
    m_actions["mp4"]=mkMP4Action;

    mkMP4Action->setIcon("mp4");

    ejectAction = new TDEAction(i18n("Eject"),0,
                              TQT_TQOBJECT(this), TQT_SLOT(ActionEject()),
                              actionCollection() , "Eject");
    ejectAction->setIcon("player_eject");

    m_actions["eject"]=ejectAction;

    
    backupAction= new TDERadioAction(i18n("DVD Backup"),0,
                              TQT_TQOBJECT(this), TQT_SLOT(ActionBackup()),
                              actionCollection(), "backup");
    backupAction->setExclusiveGroup("mode");
    m_actions["backup"]=backupAction;

    authorAction= new TDERadioAction(i18n("DVD Author"),0,
                              TQT_TQOBJECT(this), TQT_SLOT(ActionAuthor()),
                              actionCollection(), "author");
    authorAction->setExclusiveGroup("mode");
    m_actions["author"]=authorAction;

    m_actions["create"]= new TDEAction(i18n("Create DVD"),0,
                              TQT_TQOBJECT(this), TQT_SLOT(ActionCreate()),
                              actionCollection(), "Create");
    m_actions["create"]->setIcon("author");

    createGUI(0);

}

void k9Copy::setActions( bool enabled) {
    if (m_k9MainView) {
        m_actions["open"]->setEnabled(enabled);
        m_actions["quit"]->setEnabled(enabled);
        m_actions["preferences"]->setEnabled(enabled);
        m_actions["playtitle"]->setEnabled(enabled);
        m_actions["copy"]->setEnabled(enabled);
        m_actions["mp4"]->setEnabled(enabled);
        m_actions["mp2"]->setEnabled(enabled);
        m_actions["eject"]->setEnabled(enabled);
        m_mp2->setEnabled(enabled);
        m_mp4->setEnabled(enabled);
        m_factors->setEnabled(enabled);
        m_lang->setEnabled(enabled);
        m_options->setEnabled(enabled);
    } else {
        m_actions["create"]->setEnabled(enabled);
        m_menuEdit->setEnabled(enabled);
        m_newTitle->setEnabled(enabled);
        m_chapterEdit->setEnabled(enabled);
        m_k9Import->setEnabled(enabled);
    }


}

void k9Copy::optionsConfigureKeys() {
    KKeyDialog::configure(actionCollection());
}

void k9Copy::optionsConfigureToolbars() {
    // use the standard toolbar editor
    saveMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
    KEditToolbar dlg(factory());
    connect(&dlg,TQT_SIGNAL(newToolbarConfig()),this,TQT_SLOT(newToolbarConfig()));
    dlg.exec();
}

void k9Copy::newToolbarConfig() {
    // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
    // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
    createGUI(0);

    applyMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
}

void k9Copy::fileOpen() {
    m_k9Main->Open();

}


void k9Copy::addMp4TitleOptions() {
    m_mp4=new k9MP4Title(this);
    m_ToolViews.append(addToolWindow(m_mp4,KDockWidget::DockBottom,getMainDockWidget(),10,i18n("MPEG4 Encoding options"),i18n("MPEG4 Encoding Options")));
    connect(m_k9Main,TQT_SIGNAL(changedTitle( k9DVDTitle* )),m_mp4,TQT_SLOT(titleChanged( k9DVDTitle* )));
    connect(m_k9Main,TQT_SIGNAL(SelectionChanged( k9DVD*,bool )),m_mp4,TQT_SLOT(selectionChanged( k9DVD*,bool )));

}

void k9Copy::preferences() {
    k9settings settings(this,i18n("Settings"));
    settings.exec();
    k9Config config;
    m_useXine=config.getUseMplayer();

    if (m_k9MainView) {
        m_k9Main->readSettings();
        m_mp2->close();
        deleteToolWindow(m_previewAcc);
        m_ToolViews.removeRef(m_previewAcc);

        if (m_useXine)
            m_mp2=new K9Mplayer(TQT_TQOBJECT(this));
        else
            m_mp2=new kViewMPEG2();
        m_previewAcc=addToolWindow(m_mp2,KDockWidget::DockRight,getMainDockWidget(),0,i18n("Preview"),i18n("Preview"));
        m_ToolViews.append(m_previewAcc);
        //kViewMPEG2 * v=(kViewMPEG2*) m_mp2;
        connect(m_k9Main,TQT_SIGNAL(showPreview( k9DVD*, k9DVDTitle*,int )),m_mp2,TQT_SLOT(open( k9DVD*, k9DVDTitle*,int )));
        connect(m_k9Main,TQT_SIGNAL(stopPreview()),m_mp2,TQT_SLOT(bStopClick()));
    
        m_mp4->load();
    }
}


void k9Copy::ActionCopy() {
    if (m_useXine)
        ((K9Mplayer*)m_mp2)->bStopClick();
    else
        ((kViewMPEG2*)m_mp2)->bStopClick();
    m_k9Main->Copy();
}

void k9Copy::ActionPlayTitle() {
    m_previewAcc->show();
    m_k9Main->PreviewTitle();

}

void k9Copy::ActionMP4() {
    m_k9Main->CreateMP4();
}

void k9Copy::ActionMpeg2() {
    m_k9Main->extractMPEG2();
}

void k9Copy::ActionEject() {
    m_k9Main->eject();
}

void k9Copy::ActionBackup() {
   createCopyWindows();
}

void k9Copy::ActionAuthor() {
    createImportWindows();
}

void k9Copy::ActionCreate() {
    m_k9Import->execute();
}

KMdiToolViewAccessor * k9Copy::setToolWindow(TQWidget *_widget,KDockWidget::DockPosition _pos,const TQString &tabToolTip,const TQString &tabCaption) {
    KMdiToolViewAccessor *acc=addToolWindow(_widget, _pos, getMainDockWidget(),0,tabToolTip,tabCaption);
    m_ToolViews.append(acc);
    return acc;
}

void k9Copy::removeToolWindow(KMdiToolViewAccessor *toolWin) {
    deleteToolWindow(toolWin);
    m_ToolViews.removeRef(toolWin);
}


void k9Copy::changeStatusbar(const TQString& text,int id) {
    // display the text on the statusbar
    statusBar()->changeItem(text,id);
}

void k9Copy::changeCaption(const TQString& text) {
    // display the text on the caption
    setCaption(text);
}

void k9Copy::clone( TQString _input,TQString _output) {
    show();
    m_k9Main->Clone( _input,_output);
}

void k9Copy::setInput(TQString _input) {
    m_k9Main->setInput(_input);
}

void k9Copy::setOutput(TQString _output) {
    m_k9Main->setOutput(_output);
}


void k9Copy::quit() {
    close( true);
}

void k9Copy::saveDock() {
    TDEConfig config("K9Copy");
    if (m_k9MainView) {
        dockManager->writeConfig(&config,"dock");
        m_k9Main->saveSettings();
    } else if (m_k9ImportView) {
        dockManager->writeConfig(&config,"dockImport");
    }
}

void k9Copy::closeEvent( TQCloseEvent* ce ) {
    saveDock();
    ce->accept();
    kapp->quit();
}

KDockWidget* k9Copy::getVisibleDock() {
    if (m_k9MainView) {
        KDockWidget *w= manager()->findWidgetParentDock(m_options);
        if (w->isVisible())
            return w;
    
        w= manager()->findWidgetParentDock(m_lang);
        if (w->isVisible())
            return w;
    
        w= manager()->findWidgetParentDock(m_mp2);
        if (w->isVisible())
            return w;
    } else {
        KDockWidget *w= manager()->findWidgetParentDock(m_menuEdit);
        if (w->isVisible())
            return w;
    }

    return NULL;
}

void k9Copy::setEnabledCreateDVD(bool _state) {
	m_actions["create"]->setEnabled(_state);
}

#include "k9copy.moc"