summaryrefslogtreecommitdiffstats
path: root/kdat/OptionsDlg.cpp
blob: 22d730495cd67a09e40d48712b3e4295eaca509b (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
// $Id$
//
// KDat - a tar-based DAT archiver
// Copyright (C) 1998-2000  Sean Vyain, svyain@mail.tds.net
// Copyright (C) 2001-2002  Lawrence Widman, kdat@cardiothink.com
//
// 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 <stdlib.h>

#include "Options.h"
#include "OptionsDlg.h"
#include "OptionsDlgWidget.h"

#include <tqcheckbox.h>

#include <kcombobox.h>
#include <klineedit.h>
#include <knuminput.h>
#include <tdeapplication.h>
#include <tdelocale.h>
#include <tdeglobal.h>

#include "OptionsDlg.moc"
OptionsDlg::OptionsDlg( TQWidget* parent, const char* name )
        : KDialogBase( Swallow, i18n ("Options"), Ok | Apply | Cancel, 
		Ok, parent, name, true, true ), apply (0)
{
	_baseWidget = new OptionsDlgWidget ( 0 );
	setMainWidget (_baseWidget);
	
	connect( _baseWidget, TQ_SIGNAL( valueChanged () ), this, TQ_SLOT( slotChanged() ) );

    connect( this, TQ_SIGNAL( okClicked () ), this, TQ_SLOT( slotOK() ) );
    connect( this, TQ_SIGNAL( applyClicked() ), this, TQ_SLOT( slotApply() ) );
    connect( this, TQ_SIGNAL( cancelClicked() ), this, TQ_SLOT( slotCancel() ) );

    int size = Options::instance()->getDefaultTapeSize();
    if ( ( size >= 1024*1024 ) && ( size % ( 1024*1024 ) == 0 ) ) {
        // GB
        size /= 1024*1024;
        _baseWidget->_defaultTapeSizeUnits->setCurrentItem( 1 );
    } else {
        // MB
        size /= 1024;
        _baseWidget->_defaultTapeSizeUnits->setCurrentItem( 0 );
    }
    _baseWidget->_defaultTapeSize->setValue( size );

    _baseWidget->_tapeBlockSize->setValue( Options::instance()->getTapeBlockSize() );

    _baseWidget->_tapeDevice->setText( Options::instance()->getTapeDevice() );
    _baseWidget->_tarCommand->setText( Options::instance()->getTarCommand() );
    _baseWidget->_loadOnMount->setChecked( Options::instance()->getLoadOnMount() );
    _baseWidget->_lockOnMount->setChecked( Options::instance()->getLockOnMount() );
    _baseWidget->_ejectOnUnmount->setChecked( Options::instance()->getEjectOnUnmount() );
    _baseWidget->_variableBlockSize->setChecked( Options::instance()->getVariableBlockSize() );

    enableButtonApply ( false );
    configChanged = false;
}

OptionsDlg::~OptionsDlg()
{
}

void OptionsDlg::slotChanged()
{
    enableButtonApply ( true );
    configChanged = true;
}

void OptionsDlg::slotOK()
{
    if( configChanged )
        slotApply();
    accept();
}

void OptionsDlg::slotApply()
{
    int size = _baseWidget->_defaultTapeSize->value();
    if ( _baseWidget->_defaultTapeSizeUnits->currentItem() == 0 ) {
        // MB
        size *= 1024;
    } else {
        // GB
        size *= 1024*1024;
    }
    Options::instance()->setDefaultTapeSize( size );

    Options::instance()->setTapeBlockSize( _baseWidget->_tapeBlockSize->value() );

    Options::instance()->setTapeDevice( _baseWidget->_tapeDevice->text() );

    Options::instance()->setTarCommand( _baseWidget->_tarCommand->text() );

    Options::instance()->setLoadOnMount( _baseWidget->_loadOnMount->isChecked() );

    Options::instance()->setLockOnMount( _baseWidget->_lockOnMount->isChecked() );

    Options::instance()->setEjectOnUnmount( _baseWidget->_ejectOnUnmount->isChecked() );

    Options::instance()->setVariableBlockSize( _baseWidget->_variableBlockSize->isChecked() );

    Options::instance()->sync();
    enableButtonApply( false );
    configChanged = false;
}

void OptionsDlg::slotCancel()
{
    reject();
}