Diffstat (limited to 'core/pim/addressbook/addresssettings.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/addressbook/addresssettings.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/core/pim/addressbook/addresssettings.cpp b/core/pim/addressbook/addresssettings.cpp new file mode 100644 index 0000000..e7c2210 --- a/dev/null +++ b/core/pim/addressbook/addresssettings.cpp | |||
@@ -0,0 +1,136 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qt Palmtop Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | |||
22 | #include "addresssettings.h" | ||
23 | |||
24 | #include <qpe/config.h> | ||
25 | #include <qpe/contact.h> | ||
26 | |||
27 | #include <qfile.h> | ||
28 | #include <qlistbox.h> | ||
29 | |||
30 | #include <stdlib.h> | ||
31 | |||
32 | AddressSettings::AddressSettings( QWidget *parent, const char *name ) | ||
33 | : AddressSettingsBase( parent, name, TRUE ) | ||
34 | { | ||
35 | init(); | ||
36 | } | ||
37 | |||
38 | AddressSettings::~AddressSettings() | ||
39 | { | ||
40 | } | ||
41 | |||
42 | void AddressSettings::init() | ||
43 | { | ||
44 | QStringList slFields = Contact::trfields(); | ||
45 | // Make this match what is in initFields | ||
46 | slFields.remove( tr("Name Title") ); | ||
47 | slFields.remove( tr("First Name") ); | ||
48 | slFields.remove( tr("Last Name") ); | ||
49 | slFields.remove( tr("File As") ); | ||
50 | slFields.remove( tr("Default Email") ); | ||
51 | slFields.remove( tr("Notes") ); | ||
52 | slFields.remove( tr("Gender") ); | ||
53 | |||
54 | |||
55 | for( QStringList::Iterator it = slFields.begin(); | ||
56 | it != slFields.end(); ++it ) { | ||
57 | fieldListBox->insertItem( *it ); | ||
58 | } | ||
59 | |||
60 | Config cfg( "AddressBook" ); | ||
61 | |||
62 | cfg.setGroup( "Version" ); | ||
63 | int version; | ||
64 | version = cfg.readNumEntry( "version" ); | ||
65 | if ( version >= ADDRESSVERSION ) { | ||
66 | int i = 0; | ||
67 | int p = 0; | ||
68 | cfg.setGroup( "ImportantCategory" ); | ||
69 | QString zn = cfg.readEntry( "Category" + QString::number(i), | ||
70 | QString::null ); | ||
71 | while ( !zn.isNull() ) { | ||
72 | for ( int m = i; m < (int)fieldListBox->count(); m++ ) { | ||
73 | if ( fieldListBox->text( m ) == zn ) { | ||
74 | if ( m != p ) { | ||
75 | fieldListBox->removeItem( m ); | ||
76 | fieldListBox->insertItem( zn, p ); | ||
77 | } | ||
78 | p++; | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | zn = cfg.readEntry( "Category" + QString::number(++i), | ||
83 | QString::null ); | ||
84 | } | ||
85 | |||
86 | fieldListBox->setCurrentItem( 0 ); | ||
87 | } else { | ||
88 | QString str; | ||
89 | str = getenv("HOME"); | ||
90 | |||
91 | str += "/Settings/AddressBook.conf"; | ||
92 | QFile::remove( str ); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | void AddressSettings::itemUp() | ||
97 | { | ||
98 | int i = fieldListBox->currentItem(); | ||
99 | if ( i > 0 ) { | ||
100 | QString item = fieldListBox->currentText(); | ||
101 | fieldListBox->removeItem( i ); | ||
102 | fieldListBox->insertItem( item, i-1 ); | ||
103 | fieldListBox->setCurrentItem( i-1 ); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | void AddressSettings::itemDown() | ||
108 | { | ||
109 | int i = fieldListBox->currentItem(); | ||
110 | if ( i < (int)fieldListBox->count() - 1 ) { | ||
111 | QString item = fieldListBox->currentText(); | ||
112 | fieldListBox->removeItem( i ); | ||
113 | fieldListBox->insertItem( item, i+1 ); | ||
114 | fieldListBox->setCurrentItem( i+1 ); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | void AddressSettings::accept() | ||
119 | { | ||
120 | save(); | ||
121 | QDialog::accept(); | ||
122 | } | ||
123 | |||
124 | |||
125 | void AddressSettings::save() | ||
126 | { | ||
127 | Config cfg( "AddressBook" ); | ||
128 | cfg.setGroup( "Version" ); | ||
129 | // *** To change the version change it here... | ||
130 | cfg.writeEntry( "version", QString::number(ADDRESSVERSION) ); | ||
131 | cfg.setGroup( "ImportantCategory" ); | ||
132 | |||
133 | for ( int i = 0; i < (int)fieldListBox->count(); i++ ) { | ||
134 | cfg.writeEntry( "Category"+QString::number(i), fieldListBox->text(i) ); | ||
135 | } | ||
136 | } | ||