summaryrefslogtreecommitdiffstats
path: root/src/klamdoptions.cpp
blob: 875d248110a537d13d6782fbab70d1f891cacb67 (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
/****************************************************************************
** Form implementation generated from reading ui file 'klamdoptions.ui'
**
** Created: Sun Mar 6 14:20:47 2005
**      by: The User Interface Compiler ($Id: klamdoptions.cpp,v 1.1.1.1 2006/02/03 20:35:02 hoganrobert Exp $)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/

#include "klamdoptions.h"

#include <qvariant.h>
#include <qpushbutton.h>
#include <kpushbutton.h>
#include <kdialog.h>
#include <kmessagebox.h>
#include <qgroupbox.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <kconfig.h>
#include <klocale.h>

const char *check_desc3[] = {
    "1",
    "2",
    "3",
    "4",
    "5",
    0
};

/*
 *  Constructs a KlamdOptions as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
KlamdOptions::KlamdOptions( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
    if ( !name )
	setName( "KlamdOptions" );
    setModal( TRUE );

    OK = new KPushButton( this, "OK" );
    OK->setGeometry( QRect( 80, 220, 86, 31 ) );
    OK->setDefault( TRUE );

    connect( OK, SIGNAL(clicked()),
		SLOT(updateSettings()) );

    Cancel = new KPushButton( this, "Cancel" );
    Cancel->setGeometry( QRect( 180, 220, 86, 31 ) );
    Cancel->setDefault( FALSE );

    connect( Cancel, SIGNAL(clicked()),
		SLOT(close()) );

    AdvOptions = new KDialog( this, "AdvOptions" );
    AdvOptions->setGeometry( QRect( 590, 470, 20, 20 ) );

    QWidget* privateLayoutWidget = new QWidget( this, "layout7" );
    privateLayoutWidget->setGeometry( QRect( 10, 10, 333, 200 ) );
    layout7 = new QGridLayout( privateLayoutWidget, 1, 1, 11, 6, "layout7"); 

    Archives = new QGroupBox( privateLayoutWidget, "Archives" );

    MaxSize = new QComboBox( FALSE, Archives, "MaxSize" );
    MaxSize->insertStrList(check_desc3);
    MaxSize->adjustSize();

    MaxSize->setGeometry( QRect( 170, 20, 40, 21 ) );

    ScanArchives = new QCheckBox( Archives, "ScanArchives" );
    ScanArchives->setGeometry( QRect( 20, 20, 150, 21 ) );
    connect( ScanArchives, SIGNAL(toggled(bool)),MaxSize,
		SLOT(setEnabled(bool)) );

    textLabel1 = new QLabel( Archives, "textLabel1" );
    textLabel1->setGeometry( QRect( 230, 20, 70, 21 ) );

    layout7->addWidget( Archives, 1, 0 );

    ScanFilesWhen = new QGroupBox( privateLayoutWidget, "ScanFilesWhen" );

    QWidget* privateLayoutWidget_2 = new QWidget( ScanFilesWhen, "layout6" );
    privateLayoutWidget_2->setGeometry( QRect( 20, 20, 140, 60 ) );
    layout6 = new QGridLayout( privateLayoutWidget_2, 1, 1, 11, 6, "layout6"); 

    Created = new QCheckBox( privateLayoutWidget_2, "Created" );

    layout6->addWidget( Created, 0, 0 );
    connect( Created, SIGNAL(clicked()),
		SLOT(warn()) );

    Executed = new QCheckBox( privateLayoutWidget_2, "Executed" );

    layout6->addWidget( Executed, 2, 0 );

    QWidget* privateLayoutWidget_3 = new QWidget( ScanFilesWhen, "layout7" );
    privateLayoutWidget_3->setGeometry( QRect( 181, 20, 90, 60 ) );
    layout7_2 = new QGridLayout( privateLayoutWidget_3, 1, 1, 11, 6, "layout7_2"); 

    Opened = new QCheckBox( privateLayoutWidget_3, "Opened" );

    layout7_2->addWidget( Opened, 0, 0 );

    Closed = new QCheckBox( privateLayoutWidget_3, "Closed" );

    layout7_2->addWidget( Closed, 1, 0 );

    connect( Created, SIGNAL(toggled(bool)),Opened,
		SLOT(setDisabled(bool)) );
    connect( Created, SIGNAL(toggled(bool)),Closed,
		SLOT(setDisabled(bool)) );

    layout7->addWidget( ScanFilesWhen, 0, 0 );
    languageChange();
    resize( QSize(351, 270).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
    
    fetchSettings();
}

/*
 *  Destroys the object and frees any allocated resources
 */
KlamdOptions::~KlamdOptions()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void KlamdOptions::languageChange()
{
    setCaption( tr( "Advanced Options" ) );
    OK->setText( tr( "OK" ) );
    Cancel->setText( tr( "Cancel" ) );
    Archives->setTitle( tr( "Archives" ) );
    ScanArchives->setText( tr( "Scan Archives up to" ) );
    textLabel1->setText( tr( "MB in size" ) );
    ScanFilesWhen->setTitle( tr( "Scan Files When They Are:" ) );
    Created->setText( tr( "Created/Modified" ) );
    Executed->setText( tr( "Executed" ) );
    Opened->setText( tr( "Opened" ) );
    Closed->setText( tr( "Closed" ) );
}

void KlamdOptions::updateSettings()
{
	KConfig* config = KGlobal::config();
	config->setGroup("Klamd");

	config->writeEntry("Enabled", "No");

	if (Created->isChecked())
		config->writeEntry("Created", "Yes");
	else
		config->writeEntry("Created", "No");

	if (Executed->isChecked())
		config->writeEntry("Executed", "Yes");
	else
		config->writeEntry("Executed", "No");
	
	if (Opened->isChecked())
		config->writeEntry("Opened", "Yes");
	else
		config->writeEntry("Opened", "No");
	
	if (Closed->isChecked())
		config->writeEntry("Closed", "Yes");
	else
		config->writeEntry("Closed", "No");
	
	if (ScanArchives->isChecked()){
		config->writeEntry("ScanArchives", "Yes");
		config->writeEntry("MaxSize", MaxSize->currentText());
	}else
		config->writeEntry("ScanArchives", "No");
	
	config->sync();
	close();
}

void KlamdOptions::fetchSettings()
{
	config = KGlobal::config();
	config->setGroup("Klamd");


	if (config->readEntry("Executed") == "Yes")
		Executed->setChecked(true);
	else
		Executed->setChecked(false);

	if (config->readEntry("Opened") == "Yes")
		Opened->setChecked(true);
	else
		Opened->setChecked(false);

	if (config->readEntry("Closed") == "Yes")
		Closed->setChecked(true);
	else
		Closed->setChecked(false);

	if (config->readEntry("Created") == "Yes"){
		Created->setChecked(true);
		Opened->setEnabled(false);
		Closed->setEnabled(false);
	}else
		Created->setChecked(false);
		
	if (config->readEntry("ScanArchives") == "Yes"){
		ScanArchives->setChecked(true);
		MaxSize->setEnabled(true);
		MaxSize->setCurrentText(config->readEntry("MaxSize"));
	}else{
		ScanArchives->setChecked(false);
		MaxSize->setEnabled(false);
	
	}

	
}

void KlamdOptions::warn()
{

	if (Created->isChecked()){
		KMessageBox::information (this,i18n("<p>This option allows for faster, more usable auto-scanning. It is experimental, however, and there are some potential security risks. For more information, see http://klamav.sourceforge.net/index.php?content=ka_security_notes</p>"),"Warning","show");
	}
	

}

#include "klamdoptions.moc"