summaryrefslogtreecommitdiffstats
path: root/kaffeine/src/pref.cpp
blob: 7c61531df33f4d3fe207b5516e78762b0f50dd72 (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
/*
 * pref.cpp
 *
 * Copyright (C) 2004-2005 Jürgen Kofler <kaffeine@gmx.net>
 * Copyright (C) 2005-2007 Christophe Thommeret <hftom@free.fr>
 *
 * 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
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "pref.h"
#include "pref.moc"

#include <kglobal.h>
#include <kiconloader.h>
#include <kpushbutton.h>
#include <kfiledialog.h>
#include <kiconloader.h>
#include <klocale.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqspinbox.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqgroupbox.h>
#include <tqlineedit.h>

#include <tqtextcodec.h>

#include <kcharsets.h>

KaffeinePreferences::KaffeinePreferences() : KDialogBase(IconList,i18n("Kaffeine Setup"), Ok|Apply|Cancel, Ok)
{
	TQGroupBox *gb;
	TQVBoxLayout *vb;
	TQGridLayout *grid;
	KIconLoader *icon = new KIconLoader();

	setInitialSize(TQSize(400,400), false);

//-----------behavior----------------
	TQFrame *behavior = addPage(i18n("Behavior"), i18n("Behavior"), TDEGlobal::iconLoader()->loadIcon("kaffeine", KIcon::Panel, KIcon::SizeMedium));
	vb = new TQVBoxLayout( behavior, 6, 6 );
	gb = new TQGroupBox( "", behavior );
	grid = new TQGridLayout( gb, 1, 1, 20, 6 );
	m_pauseVideo = new TQCheckBox(i18n("Pause video when window is minimized"), gb);
	grid->addMultiCellWidget(m_pauseVideo, 0, 0, 0, 1);
	vb->addWidget( gb );

	vb->addItem( new TQSpacerItem( 20, 20, TQSizePolicy::Ignored, TQSizePolicy::Ignored ) );

//-----------appearance--------------
	TQFrame *looknfeel = addPage(i18n("Appearance"), i18n("Appearance"),TDEGlobal::iconLoader()->loadIcon("looknfeel", KIcon::Panel, KIcon::SizeMedium));
	vb = new TQVBoxLayout( looknfeel, 6, 6 );
	gb = new TQGroupBox( "", looknfeel );
	grid = new TQGridLayout( gb, 1, 1, 20, 6 );
	m_systemTray = new TQCheckBox(i18n("Embed in system tray"), gb);
	connect(m_systemTray, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEmbedInTrayToggled(bool)));
	grid->addMultiCellWidget(m_systemTray, 0, 0, 0, 1);
	m_osdTimeout = new TQSpinBox(gb);
	m_osdTimeout->setMinValue(0);
	m_osdTimeout->setMaxValue(60);
	m_osdTimeout->setSuffix(i18n(" sec"));
	m_osdTimeout->setSpecialValueText(i18n("off"));
	grid->addWidget(m_osdTimeout, 1,0);
	TQLabel* osdTimeoutLabel = new TQLabel(i18n("Duration of title announcement in system tray"), gb);
	osdTimeoutLabel->setDisabled(true);
	connect(m_systemTray, TQT_SIGNAL(toggled(bool)), osdTimeoutLabel, TQT_SLOT(setEnabled(bool)));
	grid->addWidget(osdTimeoutLabel, 1,1);
	vb->addWidget( gb );

	vb->addItem( new TQSpacerItem( 20, 20, TQSizePolicy::Ignored, TQSizePolicy::Ignored ) );

//-----------dvbclient--------------
	TQFrame *dc = addPage(i18n("DVB Client"), i18n("DVB Client"),TDEGlobal::iconLoader()->loadIcon("network_local", KIcon::Panel, KIcon::SizeMedium));
	vb = new TQVBoxLayout( dc, 6, 6 );
	m_dcEnabled = new TQCheckBox(i18n("Enable DVB client"), dc);
	vb->addWidget( m_dcEnabled );
	gb = new TQGroupBox( "", dc );
	gb->setDisabled(true);
	connect(m_dcEnabled, TQT_SIGNAL(toggled(bool)), gb, TQT_SLOT(setEnabled(bool)));
	grid = new TQGridLayout( gb, 1, 1, 20, 6 );
	TQLabel *lab = new TQLabel( i18n("Broadcast address:"), gb );
	grid->addWidget( lab, 0, 0 );
	m_dcAddress = new TQLineEdit( gb );
	grid->addWidget( m_dcAddress, 0, 1 );
	lab = new TQLabel( i18n("Broadcast port:"), gb );
	grid->addWidget( lab, 1, 0 );
	m_dcPort = new TQSpinBox( 1, 65535, 1, gb );
	grid->addWidget( m_dcPort, 1, 1 );
	lab = new TQLabel( i18n("Info port:"), gb );
	grid->addWidget( lab, 2, 0 );
	m_dcInfo = new TQSpinBox( 1, 65535, 1, gb );
	grid->addWidget( m_dcInfo, 2, 1 );

	lab = new TQLabel( i18n("Time shifting directory:"), gb );
	grid->addWidget( lab, 3, 0 );
	m_shiftDirLe = new TQLineEdit( gb );
	m_shiftDirLe->setReadOnly( true );
	grid->addWidget( m_shiftDirLe, 3, 1 );
	m_shiftDirBtn = new TQToolButton( gb );
	m_shiftDirBtn->setIconSet( icon->loadIconSet("fileopen", KIcon::Small) );
	grid->addWidget( m_shiftDirBtn, 3, 2 );
	connect( m_shiftDirBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT(setShiftDir()) );

	vb->addWidget( gb );
	vb->addItem( new TQSpacerItem( 20, 20, TQSizePolicy::Ignored, TQSizePolicy::Ignored ) );

//-----------misc----------------
	TQFrame *misc = addPage(i18n("Misc"), i18n("Miscellaneous Options"),TDEGlobal::iconLoader()->loadIcon("misc", KIcon::Panel, KIcon::SizeMedium));
	vb = new TQVBoxLayout( misc, 6, 6 );
	gb = new TQGroupBox(1, Qt::Horizontal, "", misc);
	gb->setInsideMargin(20);
	gb->setInsideSpacing(6);

	m_useAlternateEncoding = new TQCheckBox(i18n("Use alternate (non-Unicode) encoding for Meta tags"), gb);
	connect(m_useAlternateEncoding, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotUseAlternateEncodingToggled(bool)));

	m_alternateEncoding = new TQComboBox(gb);
	TQStringList codecNames = TDEGlobal::charsets()->descriptiveEncodingNames();
	codecNames.sort();
	m_alternateEncoding->insertStringList(codecNames);
	vb->addWidget( gb );

	gb = new TQGroupBox( "", misc );
	grid = new TQGridLayout( gb, 1, 1, 20, 6 );
	KPushButton* clearRecent = new KPushButton( i18n("Clear"), gb);
	clearRecent->setSizePolicy( TQSizePolicy (TQSizePolicy::Minimum, TQSizePolicy::Fixed));
	connect(clearRecent, TQT_SIGNAL(clicked()), this, TQT_SIGNAL(signalClearRecent()));
	grid->addWidget(clearRecent, 0, 0);
	TQLabel* clearLabel = new TQLabel(i18n("Clear recent files list"), gb);
	grid->addWidget(clearLabel, 0, 1);
	vb->addWidget( gb );

	vb->addItem( new TQSpacerItem( 20, 20, TQSizePolicy::Ignored, TQSizePolicy::Ignored ) );

	delete icon;

	connect(this, TQT_SIGNAL(okClicked()), TQT_SLOT(slotOkPressed()));
	connect(this, TQT_SIGNAL(applyClicked()), TQT_SLOT(slotApplyPressed()));
}

void KaffeinePreferences::setConfig(bool pauseVideo, bool tray, uint duration, bool useEncoding, const TQString& encoding)
{
	m_osdTimeout->setValue(duration);
	m_osdTimeout->setEnabled(tray);
	m_systemTray->setChecked(tray);

	bool m_useEncoding = false;
	for (int i = 0; i < m_alternateEncoding->count(); ++i) {
		if (TDEGlobal::charsets()->encodingForName(m_alternateEncoding->text(i)).lower() == encoding.lower()) {
			m_useEncoding = useEncoding;
			m_alternateEncoding->setCurrentItem(i);
			break;
		}
	}

	m_useAlternateEncoding->setChecked(m_useEncoding);
	m_alternateEncoding->setEnabled(m_useEncoding);
	m_pauseVideo->setChecked(pauseVideo);
}

void KaffeinePreferences::setDvbClient( bool enabled, const TQString &address, int port, int info, const TQString &tspath )
{
	m_dcEnabled->setChecked(enabled);
	m_dcAddress->setText(address);
	m_dcPort->setValue(port);
	m_dcInfo->setValue(info);
	m_shiftDirLe->setText(tspath);
}

void KaffeinePreferences::slotApplyPressed()
{
	emit signalEmbedSystemTray(m_systemTray->isChecked());
	emit signalUseAlternateEncoding(m_useAlternateEncoding->isChecked());
	emit signalAlternateEncoding(TDEGlobal::charsets()->encodingForName(m_alternateEncoding->currentText()));
	emit signalSetOSDTimeout(m_osdTimeout->value());
	emit signalPauseVideo(m_pauseVideo->isChecked());
	emit signalDvbClient(m_dcEnabled->isChecked(), m_dcAddress->text().stripWhiteSpace(), m_dcPort->value(), m_dcInfo->value(), m_shiftDirLe->text() );
}

void KaffeinePreferences::slotOkPressed()
{
	slotApplyPressed();
	hide();
}

void KaffeinePreferences::setShiftDir()
{
	TQString s = KFileDialog::getExistingDirectory( m_shiftDirLe->text().stripWhiteSpace() );
	if ( !s.isEmpty() )
		m_shiftDirLe->setText( s );
}

void KaffeinePreferences::slotUseAlternateEncodingToggled(bool on)
{
	m_alternateEncoding->setEnabled(on);
}

void KaffeinePreferences::slotEmbedInTrayToggled(bool on)
{
	m_osdTimeout->setEnabled(on);
}