summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/highlight/highlightpreferences.cpp
blob: 5e8da39c3a682addbc834737c4c35e4dfdbb2a0b (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
/***************************************************************************
                          highlightpreferences.cpp  -  description
                             -------------------
    begin                : mar 14 2003
    copyright            : (C) 2003 by Olivier Goffart
    email                : ogoffart @ kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqlayout.h>
#include <tqcheckbox.h>

#include <kcombobox.h>
#include <klineedit.h>
#include <kparts/componentfactory.h>
#include <klocale.h>
#include <klistview.h>
#include <kgenericfactory.h>
#include <kcolorbutton.h>
#include <kinputdialog.h>
#include <kurlrequester.h>
#include <kregexpeditorinterface.h>
#include <kdebug.h>

#include "filter.h"
#include "highlightplugin.h"
#include "highlightconfig.h"
#include "highlightprefsbase.h"
#include "highlightpreferences.h"

typedef KGenericFactory<HighlightPreferences> HighlightPreferencesFactory;
K_EXPORT_COMPONENT_FACTORY( kcm_kopete_highlight, HighlightPreferencesFactory( "kcm_kopete_highlight" )  )

HighlightPreferences::HighlightPreferences(TQWidget *parent, const char* /*name*/, const TQStringList &args)
							: KCModule(HighlightPreferencesFactory::instance(), parent, args)
{
	donttouch=true;
	( new TQVBoxLayout( this ) )->setAutoAdd( true );
	preferencesDialog = new HighlightPrefsUI(this);
	m_config = new HighlightConfig;

	connect(preferencesDialog->m_list , TQT_SIGNAL(selectionChanged()) , this , TQT_SLOT(slotCurrentFilterChanged()));
	connect(preferencesDialog->m_list , TQT_SIGNAL(doubleClicked ( TQListViewItem *, const TQPoint &, int )) , this , TQT_SLOT(slotRenameFilter()));
	connect(preferencesDialog->m_add , TQT_SIGNAL(pressed()) , this , TQT_SLOT(slotAddFilter()));
	connect(preferencesDialog->m_remove , TQT_SIGNAL(pressed()) , this , TQT_SLOT(slotRemoveFilter()));
	connect(preferencesDialog->m_rename , TQT_SIGNAL(pressed()) , this , TQT_SLOT(slotRenameFilter()));
	connect(preferencesDialog->m_editregexp , TQT_SIGNAL(pressed()) , this , TQT_SLOT(slotEditRegExp()));

	//Maybe here i should use a slot per widget, but i am too lazy
	connect(preferencesDialog->m_case , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_regexp , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_setImportance , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_setBG , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_setFG , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_search , TQT_SIGNAL(textChanged(const TQString&)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_sound , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_soundFN , TQT_SIGNAL(textChanged(const TQString&)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_raise , TQT_SIGNAL(stateChanged(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_search , TQT_SIGNAL(textChanged(const TQString&)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_importance , TQT_SIGNAL(activated(int)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_FG , TQT_SIGNAL(changed(const TQColor&)) , this , TQT_SLOT(slotSomethingHasChanged()));
	connect(preferencesDialog->m_BG , TQT_SIGNAL(changed(const TQColor&)) , this , TQT_SLOT(slotSomethingHasChanged()));

	load();
	donttouch=false;
}

HighlightPreferences::~HighlightPreferences()
{
	delete m_config;
}

void HighlightPreferences::load()
{
	m_config->load();
	donttouch=true;
	preferencesDialog->m_list->clear();
	m_filterItems.clear();

	TQPtrList<Filter> filters=m_config->filters();
	TQPtrListIterator<Filter> it( filters );
	Filter *f;
	bool first=true;
	while ( (f=it.current()) != 0 )
	{
		++it;
		TQListViewItem* lvi= new TQListViewItem(preferencesDialog->m_list);
		lvi->setText(0,f->displayName );
		m_filterItems.insert(lvi,f);
		if(first)
			preferencesDialog->m_list->setSelected(lvi, true);
		first=false;
	}
	donttouch=false;
	emit KCModule::changed(false);
}

void HighlightPreferences::save()
{
	m_config->save();
	emit KCModule::changed(false);
}


void HighlightPreferences::slotCurrentFilterChanged()
{
	donttouch=true;
	Filter *current;
	if(!preferencesDialog->m_list->selectedItem() || !(current=m_filterItems[preferencesDialog->m_list->selectedItem()]))
	{
		preferencesDialog->m_search->setEnabled(false);
		preferencesDialog->m_case->setEnabled(false);
		preferencesDialog->m_regexp->setEnabled(false);
		preferencesDialog->m_importance->setEnabled(false);
		preferencesDialog->m_setImportance->setEnabled(false);
		preferencesDialog->m_BG->setEnabled(false);
		preferencesDialog->m_setBG->setEnabled(false);
		preferencesDialog->m_FG->setEnabled(false);
		preferencesDialog->m_setFG->setEnabled(false);
		preferencesDialog->m_soundFN->setEnabled(false);
		preferencesDialog->m_sound->setEnabled(false);
		preferencesDialog->m_raise->setEnabled(false);
		preferencesDialog->m_editregexp->setEnabled(false);
		preferencesDialog->m_rename->setEnabled(false);
		preferencesDialog->m_remove->setEnabled(false);
		donttouch=false;
		return;
	}
	
	preferencesDialog->m_rename->setEnabled(true);
	preferencesDialog->m_remove->setEnabled(true);
	
	preferencesDialog->m_search->setEnabled(true);
	preferencesDialog->m_case->setEnabled(true);
	preferencesDialog->m_regexp->setEnabled(true);
	preferencesDialog->m_setImportance->setEnabled(true);
	preferencesDialog->m_setBG->setEnabled(true);
	preferencesDialog->m_setFG->setEnabled(true);
	preferencesDialog->m_sound->setEnabled(true);
	preferencesDialog->m_raise->setEnabled(true);


	preferencesDialog->m_search->setText(current->search);
	preferencesDialog->m_case->setChecked(current->caseSensitive);
	preferencesDialog->m_regexp->setChecked(current->isRegExp);
	preferencesDialog->m_editregexp->setEnabled(current->isRegExp);
	preferencesDialog->m_importance->setCurrentItem(current->importance);
	preferencesDialog->m_setImportance->setChecked(current->setImportance);
	preferencesDialog->m_importance->setEnabled(current->setImportance);
	preferencesDialog->m_BG->setColor(current->BG);
	preferencesDialog->m_setBG->setChecked(current->setBG);
	preferencesDialog->m_BG->setEnabled(current->setBG);
	preferencesDialog->m_FG->setColor(current->FG);
	preferencesDialog->m_setFG->setChecked(current->setFG);
	preferencesDialog->m_FG->setEnabled(current->setFG);
	preferencesDialog->m_soundFN->setURL(current->soundFN);
	preferencesDialog->m_sound->setChecked(current->playSound);
	preferencesDialog->m_raise->setChecked(current->raiseView);
	preferencesDialog->m_soundFN->setEnabled(current->playSound);

	donttouch=false;
}

void HighlightPreferences::slotAddFilter()
{
	Filter *filtre=m_config->newFilter();
	TQListViewItem* lvi= new TQListViewItem(preferencesDialog->m_list);
	lvi->setText(0,filtre->displayName );
	m_filterItems.insert(lvi,filtre);
	preferencesDialog->m_list->setSelected(lvi, true);
}

void HighlightPreferences::slotRemoveFilter()
{
	TQListViewItem *lvi=preferencesDialog->m_list->selectedItem();
	if(!lvi)
		return;
	Filter *current=m_filterItems[lvi];
	if(!current)
		return;

	m_filterItems.remove(lvi);
	delete lvi;
	m_config->removeFilter(current);
	emit KCModule::changed(true);
}

void HighlightPreferences::slotRenameFilter()
{
	TQListViewItem *lvi=preferencesDialog->m_list->selectedItem();
	if(!lvi)
		return;
	Filter *current=m_filterItems[lvi];
	if(!current)
		return;

	bool ok;
	TQString newname = KInputDialog::getText(
		i18n( "Rename Filter" ), i18n( "Please enter the new name for the filter:" ), current->displayName, &ok );
	if( !ok )
		return;
	current->displayName=newname;
	lvi->setText(0,newname);
	emit KCModule::changed(true);
}


void HighlightPreferences::slotSomethingHasChanged()
{
	Filter *current;
	if(donttouch || !preferencesDialog->m_list->selectedItem() || !(current=m_filterItems[preferencesDialog->m_list->selectedItem()]))
		return;

	current->search=preferencesDialog->m_search->text();
	current->caseSensitive=preferencesDialog->m_case->isChecked();
	current->isRegExp=preferencesDialog->m_regexp->isChecked();
	preferencesDialog->m_editregexp->setEnabled(current->isRegExp);
	current->importance=preferencesDialog->m_importance->currentItem();
	current->setImportance=preferencesDialog->m_setImportance->isChecked();
	preferencesDialog->m_importance->setEnabled(current->setImportance);
	current->BG=preferencesDialog->m_BG->color();
	current->setBG=preferencesDialog->m_setBG->isChecked();
	preferencesDialog->m_BG->setEnabled(current->setBG);
	current->FG=preferencesDialog->m_FG->color();
	current->setFG=preferencesDialog->m_setFG->isChecked();
	preferencesDialog->m_FG->setEnabled(current->setFG);
	current->soundFN=preferencesDialog->m_soundFN->url();
	current->playSound=preferencesDialog->m_sound->isChecked();
	preferencesDialog->m_soundFN->setEnabled(current->playSound);
	current->raiseView=preferencesDialog->m_raise->isChecked();

	emit KCModule::changed(true);
}

void HighlightPreferences::slotEditRegExp()
{
	TQDialog *editorDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>( "KRegExpEditor/KRegExpEditor" );
	if ( editorDialog )
	{
		// kdeutils was installed, so the dialog was found fetch the editor interface
		KRegExpEditorInterface *editor = static_cast<KRegExpEditorInterface *>( editorDialog->qt_cast( "KRegExpEditorInterface" ) );
		Q_ASSERT( editor ); // This should not fail!
		// now use the editor.
		editor->setRegExp(preferencesDialog->m_search->text());

		// Finally exec the dialog
		if(editorDialog->exec() == TQDialog::Accepted )
		{
			preferencesDialog->m_search->setText(editor->regExp());
		}

	}
	else
	{
		// Don't offer the dialog.
	}
}

#include "highlightpreferences.moc"

// vim: set noet ts=4 sts=4 sw=4: