summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addresssettings.cpp
blob: e7c22102035460bec1762bc9b996eb19904e66ea (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
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
**
** This file is part of Qt Palmtop Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/


#include "addresssettings.h"

#include <qpe/config.h>
#include <qpe/contact.h>

#include <qfile.h>
#include <qlistbox.h>

#include <stdlib.h>

AddressSettings::AddressSettings( QWidget *parent, const char *name )
     : AddressSettingsBase( parent, name, TRUE )
{
    init();
}

AddressSettings::~AddressSettings()
{
}

void AddressSettings::init()
{
    QStringList slFields = Contact::trfields();
    // Make this match what is in initFields
    slFields.remove( tr("Name Title") );
    slFields.remove( tr("First Name") );
    slFields.remove( tr("Last Name") );
    slFields.remove( tr("File As") );
    slFields.remove( tr("Default Email") );
    slFields.remove( tr("Notes") );
    slFields.remove( tr("Gender") );


    for( QStringList::Iterator it = slFields.begin();
	 it != slFields.end(); ++it ) {
	fieldListBox->insertItem( *it );
    }

    Config cfg( "AddressBook" );

    cfg.setGroup( "Version" );
    int version;
    version = cfg.readNumEntry( "version" );
    if ( version >= ADDRESSVERSION ) {
	int i = 0;
	int p = 0;
	cfg.setGroup( "ImportantCategory" );
	QString zn = cfg.readEntry( "Category" + QString::number(i),
				    QString::null );
	while ( !zn.isNull() ) {
	    for ( int m = i; m < (int)fieldListBox->count(); m++ ) {
		if ( fieldListBox->text( m ) == zn ) {
		    if ( m != p ) {
			fieldListBox->removeItem( m );
			fieldListBox->insertItem( zn, p );
		    }
		    p++;
		    break;
		}
	    }
	    zn = cfg.readEntry( "Category" + QString::number(++i),
				QString::null );
	}

	fieldListBox->setCurrentItem( 0 );
    } else {
	QString str;
	str = getenv("HOME");

	str += "/Settings/AddressBook.conf";
	QFile::remove( str );
    }
}

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

void AddressSettings::itemDown()
{
    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 AddressSettings::accept()
{
    save();
    QDialog::accept();
}


void AddressSettings::save()
{
    Config cfg( "AddressBook" );
    cfg.setGroup( "Version" );
    // *** To change the version change it here...
    cfg.writeEntry( "version", QString::number(ADDRESSVERSION) );
    cfg.setGroup( "ImportantCategory" );

    for ( int i = 0; i < (int)fieldListBox->count(); i++ ) {
	cfg.writeEntry( "Category"+QString::number(i), fieldListBox->text(i) );
    }
}