summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/configdlg.cpp
blob: 648ad528965ef009b510421737bb9f64bbd364d1 (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
#include "configdlg.h"

#include <opie2/odebug.h>
#include <opie2/opimcontact.h>
#include <opie2/opimcontactfields.h>
#include <opie2/oresource.h>

#include <qcheckbox.h>
#include <qradiobutton.h>
#include <qlistbox.h>
#include <qpushbutton.h>

ConfigDlg::ConfigDlg( QWidget *parent, const char *name):
	ConfigDlg_Base(parent, name, true )
{
	contFields = Opie::OPimContactFields::trfields();

	// We add all Fields into the Listbox
	for (uint i=0; i < contFields.count(); i++) {
		allFieldListBox->insertItem( contFields[i] );
	}

	// Reset Widget Flags: This was not changeable by designer :(
	setWFlags ( WStyle_ContextHelp );

	// Set Pics to Buttons and Tabs
	m_upButton->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) );
	m_downButton->setPixmap( Opie::Core::OResource::loadPixmap( "down", Opie::Core::OResource::SmallIcon ) );
	m_addButton->setPixmap( Opie::Core::OResource::loadPixmap( "addressbook/add", Opie::Core::OResource::SmallIcon ) );
	m_removeButton->setPixmap( Opie::Core::OResource::loadPixmap( "addressbook/sub", Opie::Core::OResource::SmallIcon ) );

	// Get the translation maps between Field ID and translated strings
	m_mapStrToID = Opie::OPimContactFields::trFieldsToId();
	m_mapIDToStr = Opie::OPimContactFields::idToTrFields();

	connect ( m_addButton, SIGNAL( clicked() ), this, SLOT( slotItemAdd() ) );
	connect ( m_removeButton, SIGNAL( clicked() ), this, SLOT( slotItemRemove() ) );
	connect ( m_upButton, SIGNAL( clicked() ), this, SLOT( slotItemUp() ) );
	connect ( m_downButton, SIGNAL( clicked() ), this, SLOT( slotItemDown() ) );
}

void ConfigDlg::slotItemUp()
{
	odebug << "void ConfigDlg::slotItemUp()" << oendl;

	int i = fieldListBox->currentItem();
	if ( i > 0 ) {
		QString item = fieldListBox->currentText();
		fieldListBox->removeItem( i );
		fieldListBox->insertItem( item, i-1 );
		fieldListBox->setCurrentItem( i-1 );
	}

}

void ConfigDlg::slotItemDown()
{
	odebug << "void ConfigDlg::slotItemDown()" << oendl;

	int i = fieldListBox->currentItem();
	if ( i < (int)fieldListBox->count() - 1 ) {
		QString item = fieldListBox->currentText();
		fieldListBox->removeItem( i );
		fieldListBox->insertItem( item, i+1 );
		fieldListBox->setCurrentItem( i+1 );
	}
}

void ConfigDlg::slotItemAdd()
{
	odebug << "void ConfigDlg::slotItemAdd()" << oendl;

	int i = allFieldListBox->currentItem();
	if ( i > 0 ) {
		QString item = allFieldListBox->currentText();
		odebug << "Adding " << item << oendl;
		fieldListBox->insertItem( item );
	}
}

void ConfigDlg::slotItemRemove()
{
	odebug << "void ConfigDlg::slotItemRemove()" << oendl;

	int i = fieldListBox->currentItem();
	if ( i > 0 ) {
		fieldListBox->removeItem( i );
	}
}

void ConfigDlg::setConfig( const AbConfig& cnf )
{
	m_config = cnf;

	m_useRegExp->setChecked( m_config.useRegExp() );
	m_useWildCard->setChecked( m_config.useWildCards() );
	m_useQtMail->setChecked( m_config.useQtMail() );
	m_useOpieMail->setChecked( m_config.useOpieMail() );
	m_useCaseSensitive->setChecked( m_config.beCaseSensitive() );

	switch( m_config.fontSize() ){
	case 0:
		m_smallFont->setChecked( true );
		m_normalFont->setChecked( false );
		m_largeFont->setChecked( false );
		break;
	case 1:
		m_smallFont->setChecked( false );
		m_normalFont->setChecked( true );
		m_largeFont->setChecked( false );
		break;
	case 2:
		m_smallFont->setChecked( false );
		m_normalFont->setChecked( false );
		m_largeFont->setChecked( true );
		break;
	}

	for( uint i = 0; i < m_config.orderList().count(); i++ ) {
	        fieldListBox -> insertItem ( m_mapIDToStr[ m_config.orderList()[i] ] );
	}

	m_fixedBars->setChecked( m_config.fixedBars() );
	m_moveBars->setChecked( !m_config.fixedBars() );
}

AbConfig ConfigDlg::getConfig()
{
	m_config.setUseRegExp( m_useRegExp->isOn() );
	m_config.setUseWildCards( m_useWildCard->isOn() );
	m_config.setUseQtMail( m_useQtMail->isOn() );
	m_config.setUseOpieMail( m_useOpieMail->isOn() );
	m_config.setBeCaseSensitive( m_useCaseSensitive->isChecked() );

	if ( m_smallFont->isChecked() )
		m_config.setFontSize( 0 );
	if ( m_normalFont->isChecked() )
		m_config.setFontSize( 1 );
	if ( m_largeFont->isChecked() )
		m_config.setFontSize( 2 );

	QValueList<int> orderlist;
	for( int i = 0; i < (int)fieldListBox->count(); i++ ) {
	        orderlist.append( m_mapStrToID[ fieldListBox->text(i) ] );
	}
	m_config.setOrderList( orderlist );

	m_config.setFixedBars( m_fixedBars->isChecked() );

	return m_config;
}