author | zautrix <zautrix> | 2005-02-01 12:22:08 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-01 12:22:08 (UTC) |
commit | 3295269ea601147ea60ba4d20ad225048d9d47c0 (patch) (unidiff) | |
tree | d3bd36c91a0687257bb6b3fac464631770d7f79b | |
parent | d1aa72f683fb264cca6936a8119d0abe9b310325 (diff) | |
download | kdepimpi-3295269ea601147ea60ba4d20ad225048d9d47c0.zip kdepimpi-3295269ea601147ea60ba4d20ad225048d9d47c0.tar.gz kdepimpi-3295269ea601147ea60ba4d20ad225048d9d47c0.tar.bz2 |
fixes
-rw-r--r-- | kaddressbook/xxport/csvimportdialog.cpp | 4 | ||||
-rw-r--r-- | microkde/kresources/configpage.cpp | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp index 1093f9c..cc55a24 100644 --- a/kaddressbook/xxport/csvimportdialog.cpp +++ b/kaddressbook/xxport/csvimportdialog.cpp | |||
@@ -1,922 +1,926 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (C) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (C) 2003 Tobias Koenig <tokoe@kde.org> |
4 | based on the code of KSpread's CSV Import Dialog | 4 | based on the code of KSpread's CSV Import Dialog |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | 29 | ||
30 | #include <qbuttongroup.h> | 30 | #include <qbuttongroup.h> |
31 | #include <qcheckbox.h> | 31 | #include <qcheckbox.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | #ifdef DESKTOP_VERSION | ||
33 | #include <qinputdialog.h> | 34 | #include <qinputdialog.h> |
35 | #else | ||
36 | #include <qtcompat/qinputdialog.h> | ||
37 | #endif | ||
34 | #include <qlabel.h> | 38 | #include <qlabel.h> |
35 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
36 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
37 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
38 | #include <qtable.h> | 42 | #include <qtable.h> |
39 | #include <qlayout.h> | 43 | #include <qlayout.h> |
40 | #include <qtextstream.h> | 44 | #include <qtextstream.h> |
41 | #include <qfile.h> | 45 | #include <qfile.h> |
42 | 46 | ||
43 | #include <kapplication.h> | 47 | #include <kapplication.h> |
44 | #include <kdebug.h> | 48 | #include <kdebug.h> |
45 | #include <kdialogbase.h> | 49 | #include <kdialogbase.h> |
46 | #include <kfiledialog.h> | 50 | #include <kfiledialog.h> |
47 | #include <klineedit.h> | 51 | #include <klineedit.h> |
48 | #include <klocale.h> | 52 | #include <klocale.h> |
49 | #include <kglobal.h> | 53 | #include <kglobal.h> |
50 | #include <kmessagebox.h> | 54 | #include <kmessagebox.h> |
51 | #include <kstandarddirs.h> | 55 | #include <kstandarddirs.h> |
52 | #include <kurlrequester.h> | 56 | #include <kurlrequester.h> |
53 | 57 | ||
54 | #ifdef DESKTOP_VERSION | 58 | #ifdef DESKTOP_VERSION |
55 | #include "qtable.h" | 59 | #include "qtable.h" |
56 | #else | 60 | #else |
57 | #include "qcombotableitem.h" | 61 | #include "qcombotableitem.h" |
58 | #endif | 62 | #endif |
59 | #include "csvimportdialog.h" | 63 | #include "csvimportdialog.h" |
60 | 64 | ||
61 | CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, | 65 | CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, |
62 | const char * name ) | 66 | const char * name ) |
63 | : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 | | 67 | : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 | |
64 | User2, Ok, parent, name, true, true ), | 68 | User2, Ok, parent, name, true, true ), |
65 | mAdjustRows( false ), | 69 | mAdjustRows( false ), |
66 | mStartLine( 0 ), | 70 | mStartLine( 0 ), |
67 | mTextQuote( '"' ), | 71 | mTextQuote( '"' ), |
68 | mDelimiter( "," ), | 72 | mDelimiter( "," ), |
69 | mAddressBook( ab ) | 73 | mAddressBook( ab ) |
70 | { | 74 | { |
71 | initGUI(); | 75 | initGUI(); |
72 | 76 | ||
73 | mTypeMap.insert( i18n( "Undefined" ), Undefined ); | 77 | mTypeMap.insert( i18n( "Undefined" ), Undefined ); |
74 | mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName ); | 78 | mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName ); |
75 | mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName ); | 79 | mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName ); |
76 | mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName ); | 80 | mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName ); |
77 | mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName ); | 81 | mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName ); |
78 | mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix ); | 82 | mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix ); |
79 | mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix ); | 83 | mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix ); |
80 | mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName ); | 84 | mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName ); |
81 | mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday ); | 85 | mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday ); |
82 | 86 | ||
83 | mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet ); | 87 | mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet ); |
84 | mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(), | 88 | mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(), |
85 | HomeAddressLocality ); | 89 | HomeAddressLocality ); |
86 | mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion ); | 90 | mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion ); |
87 | mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(), | 91 | mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(), |
88 | HomeAddressPostalCode ); | 92 | HomeAddressPostalCode ); |
89 | mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(), | 93 | mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(), |
90 | HomeAddressCountry ); | 94 | HomeAddressCountry ); |
91 | mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel ); | 95 | mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel ); |
92 | 96 | ||
93 | mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(), | 97 | mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(), |
94 | BusinessAddressStreet ); | 98 | BusinessAddressStreet ); |
95 | mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(), | 99 | mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(), |
96 | BusinessAddressLocality ); | 100 | BusinessAddressLocality ); |
97 | mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(), | 101 | mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(), |
98 | BusinessAddressRegion ); | 102 | BusinessAddressRegion ); |
99 | mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(), | 103 | mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(), |
100 | BusinessAddressPostalCode ); | 104 | BusinessAddressPostalCode ); |
101 | mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(), | 105 | mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(), |
102 | BusinessAddressCountry ); | 106 | BusinessAddressCountry ); |
103 | mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(), | 107 | mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(), |
104 | BusinessAddressLabel ); | 108 | BusinessAddressLabel ); |
105 | 109 | ||
106 | mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone ); | 110 | mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone ); |
107 | mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone ); | 111 | mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone ); |
108 | mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone ); | 112 | mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone ); |
109 | mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax ); | 113 | mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax ); |
110 | mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax ); | 114 | mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax ); |
111 | mTypeMap.insert( KABC::Addressee::carPhoneLabel(), CarPhone ); | 115 | mTypeMap.insert( KABC::Addressee::carPhoneLabel(), CarPhone ); |
112 | mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn ); | 116 | mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn ); |
113 | mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager ); | 117 | mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager ); |
114 | mTypeMap.insert( KABC::Addressee::emailLabel(), Email ); | 118 | mTypeMap.insert( KABC::Addressee::emailLabel(), Email ); |
115 | mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer ); | 119 | mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer ); |
116 | mTypeMap.insert( KABC::Addressee::titleLabel(), Title ); | 120 | mTypeMap.insert( KABC::Addressee::titleLabel(), Title ); |
117 | mTypeMap.insert( KABC::Addressee::roleLabel(), Role ); | 121 | mTypeMap.insert( KABC::Addressee::roleLabel(), Role ); |
118 | mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization ); | 122 | mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization ); |
119 | mTypeMap.insert( KABC::Addressee::noteLabel(), Note ); | 123 | mTypeMap.insert( KABC::Addressee::noteLabel(), Note ); |
120 | mTypeMap.insert( KABC::Addressee::urlLabel(), URL ); | 124 | mTypeMap.insert( KABC::Addressee::urlLabel(), URL ); |
121 | 125 | ||
122 | mCustomCounter = mTypeMap.count(); | 126 | mCustomCounter = mTypeMap.count(); |
123 | int count = mCustomCounter; | 127 | int count = mCustomCounter; |
124 | 128 | ||
125 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); | 129 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); |
126 | KABC::Field::List::Iterator it; | 130 | KABC::Field::List::Iterator it; |
127 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) | 131 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) |
128 | mTypeMap.insert( (*it)->label(), count ); | 132 | mTypeMap.insert( (*it)->label(), count ); |
129 | 133 | ||
130 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), | 134 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), |
131 | this, SLOT( delimiterClicked( int ) ) ); | 135 | this, SLOT( delimiterClicked( int ) ) ); |
132 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), | 136 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), |
133 | this, SLOT( returnPressed() ) ); | 137 | this, SLOT( returnPressed() ) ); |
134 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), | 138 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), |
135 | this, SLOT( textChanged ( const QString& ) ) ); | 139 | this, SLOT( textChanged ( const QString& ) ) ); |
136 | connect( mComboLine, SIGNAL( activated( const QString& ) ), | 140 | connect( mComboLine, SIGNAL( activated( const QString& ) ), |
137 | this, SLOT( lineSelected( const QString& ) ) ); | 141 | this, SLOT( lineSelected( const QString& ) ) ); |
138 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), | 142 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), |
139 | this, SLOT( textquoteSelected( const QString& ) ) ); | 143 | this, SLOT( textquoteSelected( const QString& ) ) ); |
140 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), | 144 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), |
141 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); | 145 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); |
142 | 146 | ||
143 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), | 147 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), |
144 | this, SLOT( setFile( const QString& ) ) ); | 148 | this, SLOT( setFile( const QString& ) ) ); |
145 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), | 149 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), |
146 | this, SLOT( setFile( const QString& ) ) ); | 150 | this, SLOT( setFile( const QString& ) ) ); |
147 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), | 151 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), |
148 | this, SLOT( urlChanged( const QString& ) ) ); | 152 | this, SLOT( urlChanged( const QString& ) ) ); |
149 | 153 | ||
150 | connect( this, SIGNAL( user1Clicked() ), | 154 | connect( this, SIGNAL( user1Clicked() ), |
151 | this, SLOT( applyTemplate() ) ); | 155 | this, SLOT( applyTemplate() ) ); |
152 | 156 | ||
153 | connect( this, SIGNAL( user2Clicked() ), | 157 | connect( this, SIGNAL( user2Clicked() ), |
154 | this, SLOT( saveTemplate() ) ); | 158 | this, SLOT( saveTemplate() ) ); |
155 | 159 | ||
156 | // if ( QApplication::desktop()->width() < 321 ) | 160 | // if ( QApplication::desktop()->width() < 321 ) |
157 | QIconSet icon = SmallIcon("filesave"); | 161 | QIconSet icon = SmallIcon("filesave"); |
158 | 162 | ||
159 | findButton( User2 )->setIconSet (icon ) ; | 163 | findButton( User2 )->setIconSet (icon ) ; |
160 | icon = SmallIcon("fileopen"); | 164 | icon = SmallIcon("fileopen"); |
161 | findButton( User1 )->setIconSet (icon ) ; | 165 | findButton( User1 )->setIconSet (icon ) ; |
162 | int wid = findButton( User2 )->sizeHint().height(); | 166 | int wid = findButton( User2 )->sizeHint().height(); |
163 | findButton( User2 )->setMaximumWidth( wid+4 ); | 167 | findButton( User2 )->setMaximumWidth( wid+4 ); |
164 | findButton( User1 )->setMaximumWidth( wid+4 ); | 168 | findButton( User1 )->setMaximumWidth( wid+4 ); |
165 | } | 169 | } |
166 | 170 | ||
167 | CSVImportDialog::~CSVImportDialog() | 171 | CSVImportDialog::~CSVImportDialog() |
168 | { | 172 | { |
169 | } | 173 | } |
170 | 174 | ||
171 | KABC::AddresseeList CSVImportDialog::contacts() const | 175 | KABC::AddresseeList CSVImportDialog::contacts() const |
172 | { | 176 | { |
173 | KABC::AddresseeList contacts; | 177 | KABC::AddresseeList contacts; |
174 | 178 | ||
175 | for ( int row = 1; row < mTable->numRows(); ++row ) { | 179 | for ( int row = 1; row < mTable->numRows(); ++row ) { |
176 | KABC::Addressee a; | 180 | KABC::Addressee a; |
177 | bool emptyRow = true; | 181 | bool emptyRow = true; |
178 | KABC::Address addrHome( KABC::Address::Home ); | 182 | KABC::Address addrHome( KABC::Address::Home ); |
179 | KABC::Address addrWork( KABC::Address::Work ); | 183 | KABC::Address addrWork( KABC::Address::Work ); |
180 | for ( int col = 0; col < mTable->numCols(); ++col ) { | 184 | for ( int col = 0; col < mTable->numCols(); ++col ) { |
181 | 185 | ||
182 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) ); | 186 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) ); |
183 | 187 | ||
184 | if ( !item ) { | 188 | if ( !item ) { |
185 | qDebug( "ERROR: item cast failed" ); | 189 | qDebug( "ERROR: item cast failed" ); |
186 | continue; | 190 | continue; |
187 | } | 191 | } |
188 | 192 | ||
189 | QString value = mTable->text( row, col ); | 193 | QString value = mTable->text( row, col ); |
190 | if ( !value.isEmpty() ) | 194 | if ( !value.isEmpty() ) |
191 | emptyRow = false; | 195 | emptyRow = false; |
192 | 196 | ||
193 | switch ( posToType( item->currentItem() ) ) | 197 | switch ( posToType( item->currentItem() ) ) |
194 | { | 198 | { |
195 | case Undefined: | 199 | case Undefined: |
196 | continue; | 200 | continue; |
197 | break; | 201 | break; |
198 | case FormattedName: | 202 | case FormattedName: |
199 | a.setFormattedName( value ); | 203 | a.setFormattedName( value ); |
200 | break; | 204 | break; |
201 | case GivenName: | 205 | case GivenName: |
202 | a.setGivenName( value ); | 206 | a.setGivenName( value ); |
203 | break; | 207 | break; |
204 | case FamilyName: | 208 | case FamilyName: |
205 | a.setFamilyName( value ); | 209 | a.setFamilyName( value ); |
206 | break; | 210 | break; |
207 | case AdditionalName: | 211 | case AdditionalName: |
208 | a.setAdditionalName( value ); | 212 | a.setAdditionalName( value ); |
209 | break; | 213 | break; |
210 | case Prefix: | 214 | case Prefix: |
211 | a.setPrefix( value ); | 215 | a.setPrefix( value ); |
212 | break; | 216 | break; |
213 | case Suffix: | 217 | case Suffix: |
214 | a.setSuffix( value ); | 218 | a.setSuffix( value ); |
215 | break; | 219 | break; |
216 | case NickName: | 220 | case NickName: |
217 | a.setNickName( value ); | 221 | a.setNickName( value ); |
218 | break; | 222 | break; |
219 | case Birthday: | 223 | case Birthday: |
220 | //US | 224 | //US |
221 | //the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); | 225 | //the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); |
222 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? | 226 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? |
223 | { | 227 | { |
224 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate | 228 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate |
225 | a.setBirthday(dt); | 229 | a.setBirthday(dt); |
226 | } | 230 | } |
227 | break; | 231 | break; |
228 | case Email: | 232 | case Email: |
229 | if ( !value.isEmpty() ) | 233 | if ( !value.isEmpty() ) |
230 | a.insertEmail( value, true ); | 234 | a.insertEmail( value, true ); |
231 | break; | 235 | break; |
232 | case Role: | 236 | case Role: |
233 | a.setRole( value ); | 237 | a.setRole( value ); |
234 | break; | 238 | break; |
235 | case Title: | 239 | case Title: |
236 | a.setTitle( value ); | 240 | a.setTitle( value ); |
237 | break; | 241 | break; |
238 | case Mailer: | 242 | case Mailer: |
239 | a.setMailer( value ); | 243 | a.setMailer( value ); |
240 | break; | 244 | break; |
241 | case URL: | 245 | case URL: |
242 | a.setUrl( value ); | 246 | a.setUrl( value ); |
243 | break; | 247 | break; |
244 | case Organization: | 248 | case Organization: |
245 | a.setOrganization( value ); | 249 | a.setOrganization( value ); |
246 | break; | 250 | break; |
247 | case Note: | 251 | case Note: |
248 | a.setNote( value ); | 252 | a.setNote( value ); |
249 | break; | 253 | break; |
250 | 254 | ||
251 | case HomePhone: | 255 | case HomePhone: |
252 | if ( !value.isEmpty() ) { | 256 | if ( !value.isEmpty() ) { |
253 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home ); | 257 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home ); |
254 | a.insertPhoneNumber( number ); | 258 | a.insertPhoneNumber( number ); |
255 | } | 259 | } |
256 | break; | 260 | break; |
257 | case BusinessPhone: | 261 | case BusinessPhone: |
258 | if ( !value.isEmpty() ) { | 262 | if ( !value.isEmpty() ) { |
259 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work ); | 263 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work ); |
260 | a.insertPhoneNumber( number ); | 264 | a.insertPhoneNumber( number ); |
261 | } | 265 | } |
262 | break; | 266 | break; |
263 | case MobilePhone: | 267 | case MobilePhone: |
264 | if ( !value.isEmpty() ) { | 268 | if ( !value.isEmpty() ) { |
265 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell ); | 269 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell ); |
266 | a.insertPhoneNumber( number ); | 270 | a.insertPhoneNumber( number ); |
267 | } | 271 | } |
268 | break; | 272 | break; |
269 | case HomeFax: | 273 | case HomeFax: |
270 | if ( !value.isEmpty() ) { | 274 | if ( !value.isEmpty() ) { |
271 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home | | 275 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Home | |
272 | KABC::PhoneNumber::Fax ); | 276 | KABC::PhoneNumber::Fax ); |
273 | a.insertPhoneNumber( number ); | 277 | a.insertPhoneNumber( number ); |
274 | } | 278 | } |
275 | break; | 279 | break; |
276 | case BusinessFax: | 280 | case BusinessFax: |
277 | if ( !value.isEmpty() ) { | 281 | if ( !value.isEmpty() ) { |
278 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work | | 282 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Work | |
279 | KABC::PhoneNumber::Fax ); | 283 | KABC::PhoneNumber::Fax ); |
280 | a.insertPhoneNumber( number ); | 284 | a.insertPhoneNumber( number ); |
281 | } | 285 | } |
282 | break; | 286 | break; |
283 | case CarPhone: | 287 | case CarPhone: |
284 | if ( !value.isEmpty() ) { | 288 | if ( !value.isEmpty() ) { |
285 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Car ); | 289 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Car ); |
286 | a.insertPhoneNumber( number ); | 290 | a.insertPhoneNumber( number ); |
287 | } | 291 | } |
288 | break; | 292 | break; |
289 | case Isdn: | 293 | case Isdn: |
290 | if ( !value.isEmpty() ) { | 294 | if ( !value.isEmpty() ) { |
291 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn ); | 295 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn ); |
292 | a.insertPhoneNumber( number ); | 296 | a.insertPhoneNumber( number ); |
293 | } | 297 | } |
294 | break; | 298 | break; |
295 | case Pager: | 299 | case Pager: |
296 | if ( !value.isEmpty() ) { | 300 | if ( !value.isEmpty() ) { |
297 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager ); | 301 | KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager ); |
298 | a.insertPhoneNumber( number ); | 302 | a.insertPhoneNumber( number ); |
299 | } | 303 | } |
300 | break; | 304 | break; |
301 | 305 | ||
302 | case HomeAddressStreet: | 306 | case HomeAddressStreet: |
303 | addrHome.setStreet( value ); | 307 | addrHome.setStreet( value ); |
304 | break; | 308 | break; |
305 | case HomeAddressLocality: | 309 | case HomeAddressLocality: |
306 | addrHome.setLocality( value ); | 310 | addrHome.setLocality( value ); |
307 | break; | 311 | break; |
308 | case HomeAddressRegion: | 312 | case HomeAddressRegion: |
309 | addrHome.setRegion( value ); | 313 | addrHome.setRegion( value ); |
310 | break; | 314 | break; |
311 | case HomeAddressPostalCode: | 315 | case HomeAddressPostalCode: |
312 | addrHome.setPostalCode( value ); | 316 | addrHome.setPostalCode( value ); |
313 | break; | 317 | break; |
314 | case HomeAddressCountry: | 318 | case HomeAddressCountry: |
315 | addrHome.setCountry( value ); | 319 | addrHome.setCountry( value ); |
316 | break; | 320 | break; |
317 | case HomeAddressLabel: | 321 | case HomeAddressLabel: |
318 | addrHome.setLabel( value ); | 322 | addrHome.setLabel( value ); |
319 | break; | 323 | break; |
320 | 324 | ||
321 | case BusinessAddressStreet: | 325 | case BusinessAddressStreet: |
322 | addrWork.setStreet( value ); | 326 | addrWork.setStreet( value ); |
323 | break; | 327 | break; |
324 | case BusinessAddressLocality: | 328 | case BusinessAddressLocality: |
325 | addrWork.setLocality( value ); | 329 | addrWork.setLocality( value ); |
326 | break; | 330 | break; |
327 | case BusinessAddressRegion: | 331 | case BusinessAddressRegion: |
328 | addrWork.setRegion( value ); | 332 | addrWork.setRegion( value ); |
329 | break; | 333 | break; |
330 | case BusinessAddressPostalCode: | 334 | case BusinessAddressPostalCode: |
331 | addrWork.setPostalCode( value ); | 335 | addrWork.setPostalCode( value ); |
332 | break; | 336 | break; |
333 | case BusinessAddressCountry: | 337 | case BusinessAddressCountry: |
334 | addrWork.setCountry( value ); | 338 | addrWork.setCountry( value ); |
335 | break; | 339 | break; |
336 | case BusinessAddressLabel: | 340 | case BusinessAddressLabel: |
337 | addrWork.setLabel( value ); | 341 | addrWork.setLabel( value ); |
338 | break; | 342 | break; |
339 | default: | 343 | default: |
340 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); | 344 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); |
341 | KABC::Field::List::Iterator it; | 345 | KABC::Field::List::Iterator it; |
342 | 346 | ||
343 | int counter = 0; | 347 | int counter = 0; |
344 | for ( it = fields.begin(); it != fields.end(); ++it ) { | 348 | for ( it = fields.begin(); it != fields.end(); ++it ) { |
345 | if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) ) | 349 | if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) ) |
346 | { | 350 | { |
347 | (*it)->setValue( a, value ); | 351 | (*it)->setValue( a, value ); |
348 | continue; | 352 | continue; |
349 | } | 353 | } |
350 | ++counter; | 354 | ++counter; |
351 | } | 355 | } |
352 | break; | 356 | break; |
353 | } | 357 | } |
354 | } | 358 | } |
355 | 359 | ||
356 | if ( !addrHome.isEmpty() ) | 360 | if ( !addrHome.isEmpty() ) |
357 | a.insertAddress( addrHome ); | 361 | a.insertAddress( addrHome ); |
358 | if ( !addrWork.isEmpty() ) | 362 | if ( !addrWork.isEmpty() ) |
359 | a.insertAddress( addrWork ); | 363 | a.insertAddress( addrWork ); |
360 | 364 | ||
361 | if ( !emptyRow && !a.isEmpty() ) | 365 | if ( !emptyRow && !a.isEmpty() ) |
362 | contacts.append( a ); | 366 | contacts.append( a ); |
363 | } | 367 | } |
364 | 368 | ||
365 | return contacts; | 369 | return contacts; |
366 | } | 370 | } |
367 | 371 | ||
368 | void CSVImportDialog::initGUI() | 372 | void CSVImportDialog::initGUI() |
369 | { | 373 | { |
370 | QWidget* page = plainPage(); | 374 | QWidget* page = plainPage(); |
371 | 375 | ||
372 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), | 376 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), |
373 | spacingHintSmall() ); | 377 | spacingHintSmall() ); |
374 | QHBoxLayout *hbox = new QHBoxLayout(); | 378 | QHBoxLayout *hbox = new QHBoxLayout(); |
375 | hbox->setSpacing( spacingHint() ); | 379 | hbox->setSpacing( spacingHint() ); |
376 | 380 | ||
377 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); | 381 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); |
378 | hbox->addWidget( label ); | 382 | hbox->addWidget( label ); |
379 | 383 | ||
380 | mUrlRequester = new KURLRequester( page ); | 384 | mUrlRequester = new KURLRequester( page ); |
381 | mUrlRequester->setFilter( "*.csv" ); | 385 | mUrlRequester->setFilter( "*.csv" ); |
382 | hbox->addWidget( mUrlRequester ); | 386 | hbox->addWidget( mUrlRequester ); |
383 | 387 | ||
384 | layout->addMultiCellLayout( hbox, 0, 0, 0, 1 ); | 388 | layout->addMultiCellLayout( hbox, 0, 0, 0, 1 ); |
385 | 389 | ||
386 | // Delimiter: comma, semicolon, tab, space, other | 390 | // Delimiter: comma, semicolon, tab, space, other |
387 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); | 391 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); |
388 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); | 392 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); |
389 | mDelimiterBox->layout()->setSpacing( spacingHint() ); | 393 | mDelimiterBox->layout()->setSpacing( spacingHint() ); |
390 | mDelimiterBox->layout()->setMargin( marginHint() ); | 394 | mDelimiterBox->layout()->setMargin( marginHint() ); |
391 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); | 395 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); |
392 | delimiterLayout->setAlignment( Qt::AlignTop ); | 396 | delimiterLayout->setAlignment( Qt::AlignTop ); |
393 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 ); | 397 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 ); |
394 | 398 | ||
395 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); | 399 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); |
396 | mRadioComma->setChecked( true ); | 400 | mRadioComma->setChecked( true ); |
397 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); | 401 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); |
398 | 402 | ||
399 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); | 403 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); |
400 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); | 404 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); |
401 | 405 | ||
402 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); | 406 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); |
403 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); | 407 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); |
404 | 408 | ||
405 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); | 409 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); |
406 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); | 410 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); |
407 | 411 | ||
408 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); | 412 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); |
409 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); | 413 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); |
410 | 414 | ||
411 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); | 415 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); |
412 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); | 416 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); |
413 | 417 | ||
414 | mComboLine = new QComboBox( false, page ); | 418 | mComboLine = new QComboBox( false, page ); |
415 | mComboLine->insertItem( i18n( "1" ) ); | 419 | mComboLine->insertItem( i18n( "1" ) ); |
416 | layout->addWidget( mComboLine, 3, 1 ); | 420 | layout->addWidget( mComboLine, 3, 1 ); |
417 | 421 | ||
418 | mComboQuote = new QComboBox( false, page ); | 422 | mComboQuote = new QComboBox( false, page ); |
419 | mComboQuote->insertItem( i18n( "\"" ), 0 ); | 423 | mComboQuote->insertItem( i18n( "\"" ), 0 ); |
420 | mComboQuote->insertItem( i18n( "'" ), 1 ); | 424 | mComboQuote->insertItem( i18n( "'" ), 1 ); |
421 | mComboQuote->insertItem( i18n( "None" ), 2 ); | 425 | mComboQuote->insertItem( i18n( "None" ), 2 ); |
422 | layout->addWidget( mComboQuote, 3, 0 ); | 426 | layout->addWidget( mComboQuote, 3, 0 ); |
423 | 427 | ||
424 | label = new QLabel( i18n( "Start at line:" ), page ); | 428 | label = new QLabel( i18n( "Start at line:" ), page ); |
425 | layout->addWidget( label, 2, 1 ); | 429 | layout->addWidget( label, 2, 1 ); |
426 | 430 | ||
427 | label = new QLabel( i18n( "Textquote:" ), page ); | 431 | label = new QLabel( i18n( "Textquote:" ), page ); |
428 | layout->addWidget( label, 2, 0 ); | 432 | layout->addWidget( label, 2, 0 ); |
429 | 433 | ||
430 | mIgnoreDuplicates = new QCheckBox( page ); | 434 | mIgnoreDuplicates = new QCheckBox( page ); |
431 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); | 435 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); |
432 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 1 ); | 436 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 1 ); |
433 | 437 | ||
434 | mTable = new QTable( 0, 0, page ); | 438 | mTable = new QTable( 0, 0, page ); |
435 | mTable->setSelectionMode( QTable::NoSelection ); | 439 | mTable->setSelectionMode( QTable::NoSelection ); |
436 | //mTable->horizontalHeader()->hide(); | 440 | //mTable->horizontalHeader()->hide(); |
437 | layout->addMultiCellWidget( mTable, 5, 5, 0, 1 ); | 441 | layout->addMultiCellWidget( mTable, 5, 5, 0, 1 ); |
438 | /*US | 442 | /*US |
439 | setButtonText( User1, i18n( "Apply Template" ) ); | 443 | setButtonText( User1, i18n( "Apply Template" ) ); |
440 | setButtonText( User2, i18n( "Save Template" ) ); | 444 | setButtonText( User2, i18n( "Save Template" ) ); |
441 | */ | 445 | */ |
442 | 446 | ||
443 | enableButtonOK( false ); | 447 | enableButtonOK( false ); |
444 | 448 | ||
445 | findButton( User1 )->setEnabled( false ); | 449 | findButton( User1 )->setEnabled( false ); |
446 | findButton( User2 )->setEnabled( false ); | 450 | findButton( User2 )->setEnabled( false ); |
447 | 451 | ||
448 | #ifdef DESKTOP_VERSION | 452 | #ifdef DESKTOP_VERSION |
449 | resize( 500, 300 ); | 453 | resize( 500, 300 ); |
450 | #else | 454 | #else |
451 | showMaximized(); | 455 | showMaximized(); |
452 | #endif | 456 | #endif |
453 | } | 457 | } |
454 | 458 | ||
455 | void CSVImportDialog::fillTable() | 459 | void CSVImportDialog::fillTable() |
456 | { | 460 | { |
457 | int row, column; | 461 | int row, column; |
458 | bool lastCharDelimiter = false; | 462 | bool lastCharDelimiter = false; |
459 | bool ignoreDups = mIgnoreDuplicates->isChecked(); | 463 | bool ignoreDups = mIgnoreDuplicates->isChecked(); |
460 | enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, | 464 | enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, |
461 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; | 465 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; |
462 | 466 | ||
463 | QChar x; | 467 | QChar x; |
464 | QString field = ""; | 468 | QString field = ""; |
465 | 469 | ||
466 | // store previous assignment | 470 | // store previous assignment |
467 | QValueList<int> mTypeOld = mTypeStore; | 471 | QValueList<int> mTypeOld = mTypeStore; |
468 | 472 | ||
469 | mTypeStore.clear(); | 473 | mTypeStore.clear(); |
470 | for ( column = 0; column < mTable->numCols(); ++column ) { | 474 | for ( column = 0; column < mTable->numCols(); ++column ) { |
471 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); | 475 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); |
472 | 476 | ||
473 | if ( !item || mClearTypeStore ) | 477 | if ( !item || mClearTypeStore ) |
474 | mTypeStore.append( typeToPos( Undefined ) ); | 478 | mTypeStore.append( typeToPos( Undefined ) ); |
475 | else if ( item ) | 479 | else if ( item ) |
476 | mTypeStore.append( item->currentItem() ); | 480 | mTypeStore.append( item->currentItem() ); |
477 | } | 481 | } |
478 | 482 | ||
479 | clearTable(); | 483 | clearTable(); |
480 | 484 | ||
481 | row = column = 1; | 485 | row = column = 1; |
482 | mData = QString( mFileArray ); | 486 | mData = QString( mFileArray ); |
483 | 487 | ||
484 | QTextStream inputStream( mData, IO_ReadOnly ); | 488 | QTextStream inputStream( mData, IO_ReadOnly ); |
485 | inputStream.setEncoding( QTextStream::Locale ); | 489 | inputStream.setEncoding( QTextStream::Locale ); |
486 | 490 | ||
487 | int maxColumn = 0; | 491 | int maxColumn = 0; |
488 | while ( !inputStream.atEnd() ) { | 492 | while ( !inputStream.atEnd() ) { |
489 | inputStream >> x; // read one char | 493 | inputStream >> x; // read one char |
490 | 494 | ||
491 | if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly | 495 | if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly |
492 | 496 | ||
493 | switch ( state ) { | 497 | switch ( state ) { |
494 | case S_START : | 498 | case S_START : |
495 | if ( x == mTextQuote ) { | 499 | if ( x == mTextQuote ) { |
496 | state = S_QUOTED_FIELD; | 500 | state = S_QUOTED_FIELD; |
497 | } else if ( x == mDelimiter ) { | 501 | } else if ( x == mDelimiter ) { |
498 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 502 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
499 | ++column; | 503 | ++column; |
500 | lastCharDelimiter = true; | 504 | lastCharDelimiter = true; |
501 | } else if ( x == '\n' ) { | 505 | } else if ( x == '\n' ) { |
502 | ++row; | 506 | ++row; |
503 | column = 1; | 507 | column = 1; |
504 | } else { | 508 | } else { |
505 | field += x; | 509 | field += x; |
506 | state = S_MAYBE_NORMAL_FIELD; | 510 | state = S_MAYBE_NORMAL_FIELD; |
507 | } | 511 | } |
508 | break; | 512 | break; |
509 | case S_QUOTED_FIELD : | 513 | case S_QUOTED_FIELD : |
510 | if ( x == mTextQuote ) { | 514 | if ( x == mTextQuote ) { |
511 | state = S_MAYBE_END_OF_QUOTED_FIELD; | 515 | state = S_MAYBE_END_OF_QUOTED_FIELD; |
512 | } else if ( x == '\n' ) { | 516 | } else if ( x == '\n' ) { |
513 | setText( row - mStartLine + 1, column, field ); | 517 | setText( row - mStartLine + 1, column, field ); |
514 | field = ""; | 518 | field = ""; |
515 | if ( x == '\n' ) { | 519 | if ( x == '\n' ) { |
516 | ++row; | 520 | ++row; |
517 | column = 1; | 521 | column = 1; |
518 | } else { | 522 | } else { |
519 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 523 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
520 | ++column; | 524 | ++column; |
521 | lastCharDelimiter = true; | 525 | lastCharDelimiter = true; |
522 | } | 526 | } |
523 | state = S_START; | 527 | state = S_START; |
524 | } else { | 528 | } else { |
525 | field += x; | 529 | field += x; |
526 | } | 530 | } |
527 | break; | 531 | break; |
528 | case S_MAYBE_END_OF_QUOTED_FIELD : | 532 | case S_MAYBE_END_OF_QUOTED_FIELD : |
529 | if ( x == mTextQuote ) { | 533 | if ( x == mTextQuote ) { |
530 | field += x; | 534 | field += x; |
531 | state = S_QUOTED_FIELD; | 535 | state = S_QUOTED_FIELD; |
532 | } else if ( x == mDelimiter || x == '\n' ) { | 536 | } else if ( x == mDelimiter || x == '\n' ) { |
533 | setText( row - mStartLine + 1, column, field ); | 537 | setText( row - mStartLine + 1, column, field ); |
534 | field = ""; | 538 | field = ""; |
535 | if ( x == '\n' ) { | 539 | if ( x == '\n' ) { |
536 | ++row; | 540 | ++row; |
537 | column = 1; | 541 | column = 1; |
538 | } else { | 542 | } else { |
539 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 543 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
540 | ++column; | 544 | ++column; |
541 | lastCharDelimiter = true; | 545 | lastCharDelimiter = true; |
542 | } | 546 | } |
543 | state = S_START; | 547 | state = S_START; |
544 | } else { | 548 | } else { |
545 | state = S_END_OF_QUOTED_FIELD; | 549 | state = S_END_OF_QUOTED_FIELD; |
546 | } | 550 | } |
547 | break; | 551 | break; |
548 | case S_END_OF_QUOTED_FIELD : | 552 | case S_END_OF_QUOTED_FIELD : |
549 | if ( x == mDelimiter || x == '\n' ) { | 553 | if ( x == mDelimiter || x == '\n' ) { |
550 | setText( row - mStartLine + 1, column, field ); | 554 | setText( row - mStartLine + 1, column, field ); |
551 | field = ""; | 555 | field = ""; |
552 | if ( x == '\n' ) { | 556 | if ( x == '\n' ) { |
553 | ++row; | 557 | ++row; |
554 | column = 1; | 558 | column = 1; |
555 | } else { | 559 | } else { |
556 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 560 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
557 | ++column; | 561 | ++column; |
558 | lastCharDelimiter = true; | 562 | lastCharDelimiter = true; |
559 | } | 563 | } |
560 | state = S_START; | 564 | state = S_START; |
561 | } else { | 565 | } else { |
562 | state = S_END_OF_QUOTED_FIELD; | 566 | state = S_END_OF_QUOTED_FIELD; |
563 | } | 567 | } |
564 | break; | 568 | break; |
565 | case S_MAYBE_NORMAL_FIELD : | 569 | case S_MAYBE_NORMAL_FIELD : |
566 | if ( x == mTextQuote ) { | 570 | if ( x == mTextQuote ) { |
567 | field = ""; | 571 | field = ""; |
568 | state = S_QUOTED_FIELD; | 572 | state = S_QUOTED_FIELD; |
569 | break; | 573 | break; |
570 | } | 574 | } |
571 | case S_NORMAL_FIELD : | 575 | case S_NORMAL_FIELD : |
572 | if ( x == mDelimiter || x == '\n' ) { | 576 | if ( x == mDelimiter || x == '\n' ) { |
573 | setText( row - mStartLine + 1, column, field ); | 577 | setText( row - mStartLine + 1, column, field ); |
574 | field = ""; | 578 | field = ""; |
575 | if ( x == '\n' ) { | 579 | if ( x == '\n' ) { |
576 | ++row; | 580 | ++row; |
577 | column = 1; | 581 | column = 1; |
578 | } else { | 582 | } else { |
579 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 583 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
580 | ++column; | 584 | ++column; |
581 | lastCharDelimiter = true; | 585 | lastCharDelimiter = true; |
582 | } | 586 | } |
583 | state = S_START; | 587 | state = S_START; |
584 | } else { | 588 | } else { |
585 | field += x; | 589 | field += x; |
586 | } | 590 | } |
587 | } | 591 | } |
588 | if ( x != mDelimiter ) | 592 | if ( x != mDelimiter ) |
589 | lastCharDelimiter = false; | 593 | lastCharDelimiter = false; |
590 | 594 | ||
591 | if ( column > maxColumn ) | 595 | if ( column > maxColumn ) |
592 | maxColumn = column; | 596 | maxColumn = column; |
593 | } | 597 | } |
594 | 598 | ||
595 | // file with only one line without '\n' | 599 | // file with only one line without '\n' |
596 | if ( field.length() > 0 ) { | 600 | if ( field.length() > 0 ) { |
597 | setText( row - mStartLine + 1, column, field ); | 601 | setText( row - mStartLine + 1, column, field ); |
598 | ++row; | 602 | ++row; |
599 | field = ""; | 603 | field = ""; |
600 | } | 604 | } |
601 | 605 | ||
602 | adjustRows( row - mStartLine ); | 606 | adjustRows( row - mStartLine ); |
603 | mTable->setNumCols( maxColumn ); | 607 | mTable->setNumCols( maxColumn ); |
604 | 608 | ||
605 | //US begin | 609 | //US begin |
606 | QStringList keys; | 610 | QStringList keys; |
607 | QMap<QString, uint>::ConstIterator it; | 611 | QMap<QString, uint>::ConstIterator it; |
608 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) | 612 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) |
609 | keys << it.key(); | 613 | keys << it.key(); |
610 | //US end | 614 | //US end |
611 | 615 | ||
612 | for ( column = 0; column < mTable->numCols(); ++column ) { | 616 | for ( column = 0; column < mTable->numCols(); ++column ) { |
613 | 617 | ||
614 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); | 618 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); |
615 | QComboTableItem *item = new QComboTableItem( mTable, keys ); | 619 | QComboTableItem *item = new QComboTableItem( mTable, keys ); |
616 | mTable->setItem( 0, column, item ); | 620 | mTable->setItem( 0, column, item ); |
617 | if ( column < mTypeStore.count() ) | 621 | if ( column < mTypeStore.count() ) |
618 | item->setCurrentItem( mTypeStore[ column ] ); | 622 | item->setCurrentItem( mTypeStore[ column ] ); |
619 | else | 623 | else |
620 | item->setCurrentItem( typeToPos( Undefined ) ); | 624 | item->setCurrentItem( typeToPos( Undefined ) ); |
621 | 625 | ||
622 | mTable->adjustColumn( column ); | 626 | mTable->adjustColumn( column ); |
623 | } | 627 | } |
624 | } | 628 | } |
625 | 629 | ||
626 | void CSVImportDialog::clearTable() | 630 | void CSVImportDialog::clearTable() |
627 | { | 631 | { |
628 | for ( int row = 0; row < mTable->numRows(); ++row ) | 632 | for ( int row = 0; row < mTable->numRows(); ++row ) |
629 | for ( int column = 0; column < mTable->numCols(); ++column ) | 633 | for ( int column = 0; column < mTable->numCols(); ++column ) |
630 | mTable->clearCell( row, column ); | 634 | mTable->clearCell( row, column ); |
631 | } | 635 | } |
632 | 636 | ||
633 | void CSVImportDialog::fillComboBox() | 637 | void CSVImportDialog::fillComboBox() |
634 | { | 638 | { |
635 | mComboLine->clear(); | 639 | mComboLine->clear(); |
636 | for ( int row = 1; row < mTable->numRows() + 1; ++row ) | 640 | for ( int row = 1; row < mTable->numRows() + 1; ++row ) |
637 | mComboLine->insertItem( QString::number( row ), row - 1 ); | 641 | mComboLine->insertItem( QString::number( row ), row - 1 ); |
638 | } | 642 | } |
639 | 643 | ||
640 | void CSVImportDialog::setText( int row, int col, const QString& text ) | 644 | void CSVImportDialog::setText( int row, int col, const QString& text ) |
641 | { | 645 | { |
642 | if ( row < 1 ) // skipped by the user | 646 | if ( row < 1 ) // skipped by the user |
643 | return; | 647 | return; |
644 | 648 | ||
645 | if ( mTable->numRows() < row ) { | 649 | if ( mTable->numRows() < row ) { |
646 | mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations | 650 | mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations |
647 | mAdjustRows = true; | 651 | mAdjustRows = true; |
648 | } | 652 | } |
649 | 653 | ||
650 | if ( mTable->numCols() < col ) | 654 | if ( mTable->numCols() < col ) |
651 | mTable->setNumCols( col + 50 ); // We add 50 at a time to limit recalculation | 655 | mTable->setNumCols( col + 50 ); // We add 50 at a time to limit recalculation |
652 | 656 | ||
653 | mTable->setText( row - 1, col - 1, text ); | 657 | mTable->setText( row - 1, col - 1, text ); |
654 | } | 658 | } |
655 | 659 | ||
656 | /* | 660 | /* |
657 | * Called after the first fillTable() when number of rows are unknown. | 661 | * Called after the first fillTable() when number of rows are unknown. |
658 | */ | 662 | */ |
659 | void CSVImportDialog::adjustRows( int rows ) | 663 | void CSVImportDialog::adjustRows( int rows ) |
660 | { | 664 | { |
661 | if ( mAdjustRows ) { | 665 | if ( mAdjustRows ) { |
662 | mTable->setNumRows( rows ); | 666 | mTable->setNumRows( rows ); |
663 | mAdjustRows = false; | 667 | mAdjustRows = false; |
664 | } | 668 | } |
665 | } | 669 | } |
666 | 670 | ||
667 | void CSVImportDialog::returnPressed() | 671 | void CSVImportDialog::returnPressed() |
668 | { | 672 | { |
669 | if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 ) | 673 | if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 ) |
670 | return; | 674 | return; |
671 | 675 | ||
672 | mDelimiter = mDelimiterEdit->text(); | 676 | mDelimiter = mDelimiterEdit->text(); |
673 | fillTable(); | 677 | fillTable(); |
674 | } | 678 | } |
675 | 679 | ||
676 | void CSVImportDialog::textChanged ( const QString& ) | 680 | void CSVImportDialog::textChanged ( const QString& ) |
677 | { | 681 | { |
678 | mRadioOther->setChecked ( true ); | 682 | mRadioOther->setChecked ( true ); |
679 | delimiterClicked( 4 ); // other | 683 | delimiterClicked( 4 ); // other |
680 | } | 684 | } |
681 | 685 | ||
682 | void CSVImportDialog::delimiterClicked( int id ) | 686 | void CSVImportDialog::delimiterClicked( int id ) |
683 | { | 687 | { |
684 | switch ( id ) { | 688 | switch ( id ) { |
685 | case 0: // comma | 689 | case 0: // comma |
686 | mDelimiter = ","; | 690 | mDelimiter = ","; |
687 | break; | 691 | break; |
688 | case 4: // other | 692 | case 4: // other |
689 | mDelimiter = mDelimiterEdit->text(); | 693 | mDelimiter = mDelimiterEdit->text(); |
690 | break; | 694 | break; |
691 | case 2: // tab | 695 | case 2: // tab |
692 | mDelimiter = "\t"; | 696 | mDelimiter = "\t"; |
693 | break; | 697 | break; |
694 | case 3: // space | 698 | case 3: // space |
695 | mDelimiter = " "; | 699 | mDelimiter = " "; |
696 | break; | 700 | break; |
697 | case 1: // semicolon | 701 | case 1: // semicolon |
698 | mDelimiter = ";"; | 702 | mDelimiter = ";"; |
699 | break; | 703 | break; |
700 | } | 704 | } |
701 | 705 | ||
702 | fillTable(); | 706 | fillTable(); |
703 | } | 707 | } |
704 | 708 | ||
705 | void CSVImportDialog::textquoteSelected( const QString& mark ) | 709 | void CSVImportDialog::textquoteSelected( const QString& mark ) |
706 | { | 710 | { |
707 | if ( mComboQuote->currentItem() == 2 ) | 711 | if ( mComboQuote->currentItem() == 2 ) |
708 | mTextQuote = 0; | 712 | mTextQuote = 0; |
709 | else | 713 | else |
710 | mTextQuote = mark[ 0 ]; | 714 | mTextQuote = mark[ 0 ]; |
711 | 715 | ||
712 | fillTable(); | 716 | fillTable(); |
713 | } | 717 | } |
714 | 718 | ||
715 | void CSVImportDialog::lineSelected( const QString& line ) | 719 | void CSVImportDialog::lineSelected( const QString& line ) |
716 | { | 720 | { |
717 | mStartLine = line.toInt() - 1; | 721 | mStartLine = line.toInt() - 1; |
718 | fillTable(); | 722 | fillTable(); |
719 | } | 723 | } |
720 | 724 | ||
721 | void CSVImportDialog::slotOk() | 725 | void CSVImportDialog::slotOk() |
722 | { | 726 | { |
723 | bool assigned = false; | 727 | bool assigned = false; |
724 | 728 | ||
725 | for ( int column = 0; column < mTable->numCols(); ++column ) { | 729 | for ( int column = 0; column < mTable->numCols(); ++column ) { |
726 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 730 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
727 | column ) ); | 731 | column ) ); |
728 | if ( item && posToType( item->currentItem() ) != Undefined ) | 732 | if ( item && posToType( item->currentItem() ) != Undefined ) |
729 | assigned = true; | 733 | assigned = true; |
730 | } | 734 | } |
731 | 735 | ||
732 | if ( assigned ) | 736 | if ( assigned ) |
733 | KDialogBase::slotOk(); | 737 | KDialogBase::slotOk(); |
734 | else | 738 | else |
735 | KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) ); | 739 | KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) ); |
736 | } | 740 | } |
737 | 741 | ||
738 | void CSVImportDialog::applyTemplate() | 742 | void CSVImportDialog::applyTemplate() |
739 | { | 743 | { |
740 | QMap<uint,int> columnMap; | 744 | QMap<uint,int> columnMap; |
741 | QMap<QString, QString> fileMap; | 745 | QMap<QString, QString> fileMap; |
742 | QStringList templates; | 746 | QStringList templates; |
743 | 747 | ||
744 | // load all template files | 748 | // load all template files |
745 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + | 749 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + |
746 | "/csv-templates/*.desktop", true, true ); | 750 | "/csv-templates/*.desktop", true, true ); |
747 | */ | 751 | */ |
748 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + | 752 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + |
749 | "/csv-templates/*.desktop", true, true ); | 753 | "/csv-templates/*.desktop", true, true ); |
750 | 754 | ||
751 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 755 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
752 | { | 756 | { |
753 | qDebug("for "); | 757 | qDebug("for "); |
754 | //US KSimpleConfig config( *it, true ); | 758 | //US KSimpleConfig config( *it, true ); |
755 | KConfig config( *it ); | 759 | KConfig config( *it ); |
756 | 760 | ||
757 | if ( !config.hasGroup( "csv column map" ) ) | 761 | if ( !config.hasGroup( "csv column map" ) ) |
758 | continue; | 762 | continue; |
759 | 763 | ||
760 | config.setGroup( "Misc" ); | 764 | config.setGroup( "Misc" ); |
761 | templates.append( config.readEntry( "Name" ) ); | 765 | templates.append( config.readEntry( "Name" ) ); |
762 | fileMap.insert( config.readEntry( "Name" ), *it ); | 766 | fileMap.insert( config.readEntry( "Name" ), *it ); |
763 | } | 767 | } |
764 | qDebug("weiter "); | 768 | qDebug("weiter "); |
765 | // let the user chose, what to take | 769 | // let the user chose, what to take |
766 | bool ok = false; | 770 | bool ok = false; |
767 | QString tmp; | 771 | QString tmp; |
768 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), | 772 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), |
769 | i18n( "Please select a template, that matches the CSV file." ), | 773 | i18n( "Please select a template, that matches the CSV file." ), |
770 | templates, 0, false, &ok, this ); | 774 | templates, 0, false, &ok, this ); |
771 | 775 | ||
772 | if ( !ok ) | 776 | if ( !ok ) |
773 | return; | 777 | return; |
774 | 778 | ||
775 | //US KSimpleConfig config( fileMap[ tmp ], true ); | 779 | //US KSimpleConfig config( fileMap[ tmp ], true ); |
776 | KConfig config( fileMap[ tmp ] ); | 780 | KConfig config( fileMap[ tmp ] ); |
777 | config.setGroup( "General" ); | 781 | config.setGroup( "General" ); |
778 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); | 782 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); |
779 | uint numColumns = (uint)config.readNumEntry( "Columns" ); | 783 | uint numColumns = (uint)config.readNumEntry( "Columns" ); |
780 | 784 | ||
781 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); | 785 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); |
782 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); | 786 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); |
783 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); | 787 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); |
784 | int quoteType = config.readNumEntry( "QuoteType" ); | 788 | int quoteType = config.readNumEntry( "QuoteType" ); |
785 | mComboQuote->setCurrentItem( quoteType ); | 789 | mComboQuote->setCurrentItem( quoteType ); |
786 | textquoteSelected( mComboQuote->currentText() ); | 790 | textquoteSelected( mComboQuote->currentText() ); |
787 | 791 | ||
788 | // create the column map | 792 | // create the column map |
789 | config.setGroup( "csv column map" ); | 793 | config.setGroup( "csv column map" ); |
790 | for ( uint i = 0; i < numColumns; ++i ) { | 794 | for ( uint i = 0; i < numColumns; ++i ) { |
791 | int col = config.readNumEntry( QString::number( i ) ); | 795 | int col = config.readNumEntry( QString::number( i ) ); |
792 | columnMap.insert( i, col ); | 796 | columnMap.insert( i, col ); |
793 | } | 797 | } |
794 | 798 | ||
795 | // apply the column map | 799 | // apply the column map |
796 | for ( uint column = 0; column < columnMap.count(); ++column ) { | 800 | for ( uint column = 0; column < columnMap.count(); ++column ) { |
797 | int type = columnMap[ column ]; | 801 | int type = columnMap[ column ]; |
798 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 802 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
799 | column ) ); | 803 | column ) ); |
800 | if ( item ) | 804 | if ( item ) |
801 | item->setCurrentItem( typeToPos( type ) ); | 805 | item->setCurrentItem( typeToPos( type ) ); |
802 | } | 806 | } |
803 | } | 807 | } |
804 | 808 | ||
805 | void CSVImportDialog::saveTemplate() | 809 | void CSVImportDialog::saveTemplate() |
806 | { | 810 | { |
807 | /*US | 811 | /*US |
808 | QString fileName = KFileDialog::getSaveFileName( | 812 | QString fileName = KFileDialog::getSaveFileName( |
809 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), | 813 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), |
810 | "*.desktop", this ); | 814 | "*.desktop", this ); |
811 | */ | 815 | */ |
812 | QString fileName = KFileDialog::getSaveFileName( | 816 | QString fileName = KFileDialog::getSaveFileName( |
813 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ | 817 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ |
814 | "*.desktop",i18n("Save file name") , this ); | 818 | "*.desktop",i18n("Save file name") , this ); |
815 | 819 | ||
816 | if ( fileName.isEmpty() ) | 820 | if ( fileName.isEmpty() ) |
817 | return; | 821 | return; |
818 | 822 | ||
819 | if ( !fileName.contains( ".desktop" ) ) | 823 | if ( !fileName.contains( ".desktop" ) ) |
820 | fileName += ".desktop"; | 824 | fileName += ".desktop"; |
821 | 825 | ||
822 | QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) ); | 826 | QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) ); |
823 | 827 | ||
824 | if ( name.isEmpty() ) | 828 | if ( name.isEmpty() ) |
825 | return; | 829 | return; |
826 | 830 | ||
827 | KConfig config( fileName ); | 831 | KConfig config( fileName ); |
828 | config.setGroup( "General" ); | 832 | config.setGroup( "General" ); |
829 | config.writeEntry( "Columns", mTable->numCols() ); | 833 | config.writeEntry( "Columns", mTable->numCols() ); |
830 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); | 834 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); |
831 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); | 835 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); |
832 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); | 836 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); |
833 | 837 | ||
834 | config.setGroup( "Misc" ); | 838 | config.setGroup( "Misc" ); |
835 | config.writeEntry( "Name", name ); | 839 | config.writeEntry( "Name", name ); |
836 | 840 | ||
837 | config.setGroup( "csv column map" ); | 841 | config.setGroup( "csv column map" ); |
838 | 842 | ||
839 | for ( uint column = 0; column < mTable->numCols(); ++column ) { | 843 | for ( uint column = 0; column < mTable->numCols(); ++column ) { |
840 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 844 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, |
841 | column ) ); | 845 | column ) ); |
842 | if ( item ) | 846 | if ( item ) |
843 | config.writeEntry( QString::number( column ), posToType( | 847 | config.writeEntry( QString::number( column ), posToType( |
844 | item->currentItem() ) ); | 848 | item->currentItem() ) ); |
845 | else | 849 | else |
846 | config.writeEntry( QString::number( column ), 0 ); | 850 | config.writeEntry( QString::number( column ), 0 ); |
847 | } | 851 | } |
848 | 852 | ||
849 | config.sync(); | 853 | config.sync(); |
850 | } | 854 | } |
851 | 855 | ||
852 | QString CSVImportDialog::getText( int row, int col ) | 856 | QString CSVImportDialog::getText( int row, int col ) |
853 | { | 857 | { |
854 | return mTable->text( row, col ); | 858 | return mTable->text( row, col ); |
855 | } | 859 | } |
856 | 860 | ||
857 | uint CSVImportDialog::posToType( int pos ) const | 861 | uint CSVImportDialog::posToType( int pos ) const |
858 | { | 862 | { |
859 | uint counter = 0; | 863 | uint counter = 0; |
860 | QMap<QString, uint>::ConstIterator it; | 864 | QMap<QString, uint>::ConstIterator it; |
861 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 865 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
862 | if ( counter == (uint)pos ) | 866 | if ( counter == (uint)pos ) |
863 | return it.data(); | 867 | return it.data(); |
864 | 868 | ||
865 | return 0; | 869 | return 0; |
866 | } | 870 | } |
867 | 871 | ||
868 | int CSVImportDialog::typeToPos( uint type ) const | 872 | int CSVImportDialog::typeToPos( uint type ) const |
869 | { | 873 | { |
870 | uint counter = 0; | 874 | uint counter = 0; |
871 | QMap<QString, uint>::ConstIterator it; | 875 | QMap<QString, uint>::ConstIterator it; |
872 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 876 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
873 | if ( it.data() == type ) | 877 | if ( it.data() == type ) |
874 | return counter; | 878 | return counter; |
875 | 879 | ||
876 | return -1; | 880 | return -1; |
877 | } | 881 | } |
878 | 882 | ||
879 | void CSVImportDialog::ignoreDuplicatesChanged( int ) | 883 | void CSVImportDialog::ignoreDuplicatesChanged( int ) |
880 | { | 884 | { |
881 | fillTable(); | 885 | fillTable(); |
882 | } | 886 | } |
883 | 887 | ||
884 | void CSVImportDialog::setFile( const QString &fileName ) | 888 | void CSVImportDialog::setFile( const QString &fileName ) |
885 | { | 889 | { |
886 | if ( fileName.isEmpty() ) | 890 | if ( fileName.isEmpty() ) |
887 | return; | 891 | return; |
888 | 892 | ||
889 | QFile file( fileName ); | 893 | QFile file( fileName ); |
890 | if ( !file.open( IO_ReadOnly ) ) { | 894 | if ( !file.open( IO_ReadOnly ) ) { |
891 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); | 895 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); |
892 | file.close(); | 896 | file.close(); |
893 | return; | 897 | return; |
894 | } | 898 | } |
895 | 899 | ||
896 | mFileArray = file.readAll(); | 900 | mFileArray = file.readAll(); |
897 | file.close(); | 901 | file.close(); |
898 | 902 | ||
899 | mClearTypeStore = true; | 903 | mClearTypeStore = true; |
900 | clearTable(); | 904 | clearTable(); |
901 | mTable->setNumCols( 0 ); | 905 | mTable->setNumCols( 0 ); |
902 | mTable->setNumRows( 0 ); | 906 | mTable->setNumRows( 0 ); |
903 | fillTable(); | 907 | fillTable(); |
904 | mClearTypeStore = false; | 908 | mClearTypeStore = false; |
905 | 909 | ||
906 | fillComboBox(); | 910 | fillComboBox(); |
907 | } | 911 | } |
908 | 912 | ||
909 | void CSVImportDialog::urlChanged( const QString &file ) | 913 | void CSVImportDialog::urlChanged( const QString &file ) |
910 | { | 914 | { |
911 | bool state = !file.isEmpty(); | 915 | bool state = !file.isEmpty(); |
912 | 916 | ||
913 | enableButtonOK( state ); | 917 | enableButtonOK( state ); |
914 | 918 | ||
915 | findButton( User1 )->setEnabled( state ); | 919 | findButton( User1 )->setEnabled( state ); |
916 | findButton( User2 )->setEnabled( state ); | 920 | findButton( User2 )->setEnabled( state ); |
917 | 921 | ||
918 | } | 922 | } |
919 | 923 | ||
920 | #ifndef KAB_EMBEDDED | 924 | #ifndef KAB_EMBEDDED |
921 | #include <csvimportdialog.moc> | 925 | #include <csvimportdialog.moc> |
922 | #endif //KAB_EMBEDDED | 926 | #endif //KAB_EMBEDDED |
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp index 011e47e..fc7a42e 100644 --- a/microkde/kresources/configpage.cpp +++ b/microkde/kresources/configpage.cpp | |||
@@ -1,530 +1,534 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkresources. | 2 | This file is part of libkresources. |
3 | 3 | ||
4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> | 5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> |
6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
7 | 7 | ||
8 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either | 10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. | 11 | version 2 of the License, or (at your option) any later version. |
12 | 12 | ||
13 | This library is distributed in the hope that it will be useful, | 13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Library General Public License for more details. | 16 | Library General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. | 21 | Boston, MA 02111-1307, USA. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <qgroupbox.h> | 31 | #include <qgroupbox.h> |
32 | |||
33 | #ifdef DESKTOP_VERSION | ||
32 | #include <qinputdialog.h> | 34 | #include <qinputdialog.h> |
35 | #else | ||
36 | #include <qtcompat/qinputdialog.h> | ||
37 | #endif | ||
33 | #include <qlabel.h> | 38 | #include <qlabel.h> |
34 | #include <qlayout.h> | 39 | #include <qlayout.h> |
35 | |||
36 | #include <kapplication.h> | 40 | #include <kapplication.h> |
37 | #include <kcombobox.h> | 41 | #include <kcombobox.h> |
38 | #include <kdebug.h> | 42 | #include <kdebug.h> |
39 | #include <klocale.h> | 43 | #include <klocale.h> |
40 | #include <kmessagebox.h> | 44 | #include <kmessagebox.h> |
41 | #include <ksimpleconfig.h> | 45 | #include <ksimpleconfig.h> |
42 | #include <kstandarddirs.h> | 46 | #include <kstandarddirs.h> |
43 | #include <kurlrequester.h> | 47 | #include <kurlrequester.h> |
44 | #include <klistview.h> | 48 | #include <klistview.h> |
45 | #include <kbuttonbox.h> | 49 | #include <kbuttonbox.h> |
46 | //US #include <ktrader.h> | 50 | //US #include <ktrader.h> |
47 | 51 | ||
48 | #include "resource.h" | 52 | #include "resource.h" |
49 | #include "configdialog.h" | 53 | #include "configdialog.h" |
50 | 54 | ||
51 | #include "configpage.h" | 55 | #include "configpage.h" |
52 | 56 | ||
53 | //US | 57 | //US |
54 | #include <qpushbutton.h> | 58 | #include <qpushbutton.h> |
55 | #include <qfile.h> | 59 | #include <qfile.h> |
56 | #include <kglobal.h> | 60 | #include <kglobal.h> |
57 | 61 | ||
58 | using namespace KRES; | 62 | using namespace KRES; |
59 | 63 | ||
60 | class ConfigViewItem : public QCheckListItem | 64 | class ConfigViewItem : public QCheckListItem |
61 | { | 65 | { |
62 | public: | 66 | public: |
63 | ConfigViewItem( QListView *parent, Resource* resource ) : | 67 | ConfigViewItem( QListView *parent, Resource* resource ) : |
64 | QCheckListItem( parent, resource->resourceName(), CheckBox ), | 68 | QCheckListItem( parent, resource->resourceName(), CheckBox ), |
65 | mResource( resource ), | 69 | mResource( resource ), |
66 | mIsStandard( false ) | 70 | mIsStandard( false ) |
67 | { | 71 | { |
68 | setText( 1, mResource->type() ); | 72 | setText( 1, mResource->type() ); |
69 | setOn( mResource->isActive() ); | 73 | setOn( mResource->isActive() ); |
70 | } | 74 | } |
71 | 75 | ||
72 | void setStandard( bool value ) | 76 | void setStandard( bool value ) |
73 | { | 77 | { |
74 | setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); | 78 | setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); |
75 | mIsStandard = value; | 79 | mIsStandard = value; |
76 | } | 80 | } |
77 | 81 | ||
78 | bool standard() const { return mIsStandard; } | 82 | bool standard() const { return mIsStandard; } |
79 | bool readOnly() const { return mResource->readOnly(); } | 83 | bool readOnly() const { return mResource->readOnly(); } |
80 | 84 | ||
81 | Resource *resource() { return mResource; } | 85 | Resource *resource() { return mResource; } |
82 | 86 | ||
83 | private: | 87 | private: |
84 | Resource* mResource; | 88 | Resource* mResource; |
85 | 89 | ||
86 | bool mIsStandard; | 90 | bool mIsStandard; |
87 | }; | 91 | }; |
88 | 92 | ||
89 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) | 93 | ConfigPage::ConfigPage( QWidget *parent, const char *name ) |
90 | : QWidget( parent, name ), | 94 | : QWidget( parent, name ), |
91 | mCurrentManager( 0 ), | 95 | mCurrentManager( 0 ), |
92 | mCurrentConfig( 0 ) | 96 | mCurrentConfig( 0 ) |
93 | { | 97 | { |
94 | setCaption( i18n( "Resource Configuration" ) ); | 98 | setCaption( i18n( "Resource Configuration" ) ); |
95 | 99 | ||
96 | QVBoxLayout *mainLayout = new QVBoxLayout( this ); | 100 | QVBoxLayout *mainLayout = new QVBoxLayout( this ); |
97 | 101 | ||
98 | QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); | 102 | QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); |
99 | groupBox->setColumnLayout(0, Qt::Vertical ); | 103 | groupBox->setColumnLayout(0, Qt::Vertical ); |
100 | groupBox->layout()->setSpacing( 3 ); | 104 | groupBox->layout()->setSpacing( 3 ); |
101 | groupBox->layout()->setMargin( 5 ); | 105 | groupBox->layout()->setMargin( 5 ); |
102 | QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); | 106 | QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); |
103 | 107 | ||
104 | //US mFamilyCombo = new KComboBox( false, groupBox ); | 108 | //US mFamilyCombo = new KComboBox( false, groupBox ); |
105 | mFamilyCombo = new KComboBox( groupBox ); | 109 | mFamilyCombo = new KComboBox( groupBox ); |
106 | groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); | 110 | groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); |
107 | 111 | ||
108 | mListView = new KListView( groupBox ); | 112 | mListView = new KListView( groupBox ); |
109 | mListView->setAllColumnsShowFocus( true ); | 113 | mListView->setAllColumnsShowFocus( true ); |
110 | mListView->addColumn( i18n( "Name" ) ); | 114 | mListView->addColumn( i18n( "Name" ) ); |
111 | mListView->addColumn( i18n( "Type" ) ); | 115 | mListView->addColumn( i18n( "Type" ) ); |
112 | mListView->addColumn( i18n( "Standard" ) ); | 116 | mListView->addColumn( i18n( "Standard" ) ); |
113 | 117 | ||
114 | //US groupBoxLayout->addWidget( mListView, 1, 0 ); | 118 | //US groupBoxLayout->addWidget( mListView, 1, 0 ); |
115 | groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); | 119 | groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); |
116 | 120 | ||
117 | 121 | ||
118 | mAddButton = new QPushButton( i18n( "&Add..." ), groupBox ); | 122 | mAddButton = new QPushButton( i18n( "&Add..." ), groupBox ); |
119 | groupBoxLayout->addWidget( mAddButton, 2, 0 ); | 123 | groupBoxLayout->addWidget( mAddButton, 2, 0 ); |
120 | mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox ); | 124 | mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox ); |
121 | groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); | 125 | groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); |
122 | mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox ); | 126 | mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox ); |
123 | groupBoxLayout->addWidget( mEditButton, 3, 0 ); | 127 | groupBoxLayout->addWidget( mEditButton, 3, 0 ); |
124 | mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox ); | 128 | mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox ); |
125 | groupBoxLayout->addWidget( mStandardButton, 3, 1 ); | 129 | groupBoxLayout->addWidget( mStandardButton, 3, 1 ); |
126 | 130 | ||
127 | mRemoveButton->setEnabled( false ); | 131 | mRemoveButton->setEnabled( false ); |
128 | mEditButton->setEnabled( false ); | 132 | mEditButton->setEnabled( false ); |
129 | mStandardButton->setEnabled( false ); | 133 | mStandardButton->setEnabled( false ); |
130 | 134 | ||
131 | 135 | ||
132 | connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); | 136 | connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); |
133 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); | 137 | connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); |
134 | connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); | 138 | connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); |
135 | connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); | 139 | connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); |
136 | 140 | ||
137 | 141 | ||
138 | mainLayout->addWidget( groupBox ); | 142 | mainLayout->addWidget( groupBox ); |
139 | 143 | ||
140 | connect( mFamilyCombo, SIGNAL( activated( int ) ), | 144 | connect( mFamilyCombo, SIGNAL( activated( int ) ), |
141 | SLOT( slotFamilyChanged( int ) ) ); | 145 | SLOT( slotFamilyChanged( int ) ) ); |
142 | connect( mListView, SIGNAL( selectionChanged() ), | 146 | connect( mListView, SIGNAL( selectionChanged() ), |
143 | SLOT( slotSelectionChanged() ) ); | 147 | SLOT( slotSelectionChanged() ) ); |
144 | connect( mListView, SIGNAL( clicked( QListViewItem * ) ), | 148 | connect( mListView, SIGNAL( clicked( QListViewItem * ) ), |
145 | SLOT( slotItemClicked( QListViewItem * ) ) ); | 149 | SLOT( slotItemClicked( QListViewItem * ) ) ); |
146 | 150 | ||
147 | mLastItem = 0; | 151 | mLastItem = 0; |
148 | 152 | ||
149 | //US mConfig = new KConfig( "kcmkresourcesrc" ); | 153 | //US mConfig = new KConfig( "kcmkresourcesrc" ); |
150 | mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); | 154 | mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); |
151 | mConfig->setGroup( "General" ); | 155 | mConfig->setGroup( "General" ); |
152 | 156 | ||
153 | load(); | 157 | load(); |
154 | } | 158 | } |
155 | 159 | ||
156 | ConfigPage::~ConfigPage() | 160 | ConfigPage::~ConfigPage() |
157 | { | 161 | { |
158 | QValueList<ResourcePageInfo>::Iterator it; | 162 | QValueList<ResourcePageInfo>::Iterator it; |
159 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { | 163 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { |
160 | (*it).mManager->removeListener( this ); | 164 | (*it).mManager->removeListener( this ); |
161 | delete (*it).mManager; | 165 | delete (*it).mManager; |
162 | delete (*it).mConfig; | 166 | delete (*it).mConfig; |
163 | } | 167 | } |
164 | 168 | ||
165 | mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); | 169 | mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); |
166 | delete mConfig; | 170 | delete mConfig; |
167 | mConfig = 0; | 171 | mConfig = 0; |
168 | } | 172 | } |
169 | 173 | ||
170 | void ConfigPage::load() | 174 | void ConfigPage::load() |
171 | { | 175 | { |
172 | kdDebug(5650) << "ConfigPage::load()" << endl; | 176 | kdDebug(5650) << "ConfigPage::load()" << endl; |
173 | 177 | ||
174 | mListView->clear(); | 178 | mListView->clear(); |
175 | 179 | ||
176 | //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. | 180 | //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. |
177 | 181 | ||
178 | //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); | 182 | //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); |
179 | //US KTrader::OfferList::ConstIterator it; | 183 | //US KTrader::OfferList::ConstIterator it; |
180 | //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 184 | //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
181 | //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); | 185 | //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); |
182 | //US QString family = tmp.toString(); | 186 | //US QString family = tmp.toString(); |
183 | QStringList families; | 187 | QStringList families; |
184 | families << "contact"; | 188 | families << "contact"; |
185 | 189 | ||
186 | 190 | ||
187 | for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) | 191 | for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) |
188 | { | 192 | { |
189 | QString family = (*it); | 193 | QString family = (*it); |
190 | if ( !family.isEmpty() ) { | 194 | if ( !family.isEmpty() ) { |
191 | if ( !mFamilyMap.contains( family ) ) { | 195 | if ( !mFamilyMap.contains( family ) ) { |
192 | mCurrentManager = new Manager<Resource>( family ); | 196 | mCurrentManager = new Manager<Resource>( family ); |
193 | if ( mCurrentManager ) { | 197 | if ( mCurrentManager ) { |
194 | mFamilyMap.append( family ); | 198 | mFamilyMap.append( family ); |
195 | mCurrentManager->addListener( this ); | 199 | mCurrentManager->addListener( this ); |
196 | 200 | ||
197 | ResourcePageInfo info; | 201 | ResourcePageInfo info; |
198 | info.mManager = mCurrentManager; | 202 | info.mManager = mCurrentManager; |
199 | QString configDir = KGlobal::dirs()->saveLocation( "config" ); | 203 | QString configDir = KGlobal::dirs()->saveLocation( "config" ); |
200 | //QString configDir = KStandardDirs::appDir() + "/config"; | 204 | //QString configDir = KStandardDirs::appDir() + "/config"; |
201 | if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { | 205 | if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { |
202 | info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); | 206 | info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); |
203 | } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { | 207 | } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { |
204 | info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); | 208 | info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); |
205 | } else { | 209 | } else { |
206 | QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); | 210 | QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); |
207 | info.mConfig = new KConfig( configFile ); | 211 | info.mConfig = new KConfig( configFile ); |
208 | } | 212 | } |
209 | info.mManager->readConfig( info.mConfig ); | 213 | info.mManager->readConfig( info.mConfig ); |
210 | 214 | ||
211 | mInfoMap.append( info ); | 215 | mInfoMap.append( info ); |
212 | } | 216 | } |
213 | } | 217 | } |
214 | } | 218 | } |
215 | } | 219 | } |
216 | mCurrentManager = 0; | 220 | mCurrentManager = 0; |
217 | 221 | ||
218 | mFamilyCombo->insertStringList( mFamilyMap ); | 222 | mFamilyCombo->insertStringList( mFamilyMap ); |
219 | 223 | ||
220 | int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); | 224 | int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); |
221 | mFamilyCombo->setCurrentItem( currentFamily ); | 225 | mFamilyCombo->setCurrentItem( currentFamily ); |
222 | slotFamilyChanged( currentFamily ); | 226 | slotFamilyChanged( currentFamily ); |
223 | } | 227 | } |
224 | 228 | ||
225 | void ConfigPage::save() | 229 | void ConfigPage::save() |
226 | { | 230 | { |
227 | saveResourceSettings(); | 231 | saveResourceSettings(); |
228 | 232 | ||
229 | QValueList<ResourcePageInfo>::Iterator it; | 233 | QValueList<ResourcePageInfo>::Iterator it; |
230 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) | 234 | for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) |
231 | (*it).mManager->writeConfig( (*it).mConfig ); | 235 | (*it).mManager->writeConfig( (*it).mConfig ); |
232 | 236 | ||
233 | emit changed( false ); | 237 | emit changed( false ); |
234 | } | 238 | } |
235 | 239 | ||
236 | void ConfigPage::defaults() | 240 | void ConfigPage::defaults() |
237 | { | 241 | { |
238 | } | 242 | } |
239 | 243 | ||
240 | void ConfigPage::slotFamilyChanged( int pos ) | 244 | void ConfigPage::slotFamilyChanged( int pos ) |
241 | { | 245 | { |
242 | if ( pos < 0 || pos >= (int)mFamilyMap.count() ) | 246 | if ( pos < 0 || pos >= (int)mFamilyMap.count() ) |
243 | return; | 247 | return; |
244 | 248 | ||
245 | saveResourceSettings(); | 249 | saveResourceSettings(); |
246 | 250 | ||
247 | mFamily = mFamilyMap[ pos ]; | 251 | mFamily = mFamilyMap[ pos ]; |
248 | 252 | ||
249 | //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); | 253 | //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); |
250 | 254 | ||
251 | mCurrentManager = mInfoMap[ pos ].mManager; | 255 | mCurrentManager = mInfoMap[ pos ].mManager; |
252 | mCurrentConfig = mInfoMap[ pos ].mConfig; | 256 | mCurrentConfig = mInfoMap[ pos ].mConfig; |
253 | 257 | ||
254 | if ( !mCurrentManager ) | 258 | if ( !mCurrentManager ) |
255 | kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; | 259 | kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; |
256 | 260 | ||
257 | mListView->clear(); | 261 | mListView->clear(); |
258 | 262 | ||
259 | if ( mCurrentManager->isEmpty() ) { | 263 | if ( mCurrentManager->isEmpty() ) { |
260 | //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); | 264 | //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); |
261 | 265 | ||
262 | defaults(); | 266 | defaults(); |
263 | } | 267 | } |
264 | 268 | ||
265 | Resource *standardResource = mCurrentManager->standardResource(); | 269 | Resource *standardResource = mCurrentManager->standardResource(); |
266 | 270 | ||
267 | //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); | 271 | //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); |
268 | 272 | ||
269 | 273 | ||
270 | Manager<Resource>::Iterator it; | 274 | Manager<Resource>::Iterator it; |
271 | for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { | 275 | for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { |
272 | ConfigViewItem *item = new ConfigViewItem( mListView, *it ); | 276 | ConfigViewItem *item = new ConfigViewItem( mListView, *it ); |
273 | if ( *it == standardResource ) | 277 | if ( *it == standardResource ) |
274 | item->setStandard( true ); | 278 | item->setStandard( true ); |
275 | } | 279 | } |
276 | 280 | ||
277 | if ( mListView->childCount() == 0 ) { | 281 | if ( mListView->childCount() == 0 ) { |
278 | //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); | 282 | //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); |
279 | 283 | ||
280 | defaults(); | 284 | defaults(); |
281 | emit changed( true ); | 285 | emit changed( true ); |
282 | mCurrentManager->writeConfig( mCurrentConfig ); | 286 | mCurrentManager->writeConfig( mCurrentConfig ); |
283 | } else { | 287 | } else { |
284 | //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); | 288 | //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); |
285 | 289 | ||
286 | if ( !standardResource ) { | 290 | if ( !standardResource ) { |
287 | KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); | 291 | KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); |
288 | 292 | ||
289 | //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); | 293 | //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); |
290 | 294 | ||
291 | } | 295 | } |
292 | 296 | ||
293 | emit changed( false ); | 297 | emit changed( false ); |
294 | } | 298 | } |
295 | } | 299 | } |
296 | 300 | ||
297 | void ConfigPage::slotAdd() | 301 | void ConfigPage::slotAdd() |
298 | { | 302 | { |
299 | if ( !mCurrentManager ) | 303 | if ( !mCurrentManager ) |
300 | return; | 304 | return; |
301 | 305 | ||
302 | QStringList types = mCurrentManager->resourceTypeNames(); | 306 | QStringList types = mCurrentManager->resourceTypeNames(); |
303 | QStringList descs = mCurrentManager->resourceTypeDescriptions(); | 307 | QStringList descs = mCurrentManager->resourceTypeDescriptions(); |
304 | bool ok = false; | 308 | bool ok = false; |
305 | 309 | ||
306 | QString desc; | 310 | QString desc; |
307 | 311 | ||
308 | desc = QInputDialog::getItem( i18n( "Resource Configuration" ), | 312 | desc = QInputDialog::getItem( i18n( "Resource Configuration" ), |
309 | i18n( "Select type of the new resource:" ), descs, 0, | 313 | i18n( "Select type of the new resource:" ), descs, 0, |
310 | false, &ok, this ); | 314 | false, &ok, this ); |
311 | 315 | ||
312 | if ( !ok ) | 316 | if ( !ok ) |
313 | return; | 317 | return; |
314 | 318 | ||
315 | QString type = types[ descs.findIndex( desc ) ]; | 319 | QString type = types[ descs.findIndex( desc ) ]; |
316 | 320 | ||
317 | // Create new resource | 321 | // Create new resource |
318 | Resource *resource = mCurrentManager->createResource( type ); | 322 | Resource *resource = mCurrentManager->createResource( type ); |
319 | if ( !resource ) { | 323 | if ( !resource ) { |
320 | KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") | 324 | KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") |
321 | .arg( type ) ); | 325 | .arg( type ) ); |
322 | return; | 326 | return; |
323 | } | 327 | } |
324 | 328 | ||
325 | resource->setResourceName( type + "-resource" ); | 329 | resource->setResourceName( type + "-resource" ); |
326 | 330 | ||
327 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); | 331 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); |
328 | 332 | ||
329 | if ( dlg.exec() ) { | 333 | if ( dlg.exec() ) { |
330 | mCurrentManager->add( resource ); | 334 | mCurrentManager->add( resource ); |
331 | 335 | ||
332 | ConfigViewItem *item = new ConfigViewItem( mListView, resource ); | 336 | ConfigViewItem *item = new ConfigViewItem( mListView, resource ); |
333 | 337 | ||
334 | mLastItem = item; | 338 | mLastItem = item; |
335 | 339 | ||
336 | // if there are only read-only resources we'll set this resource | 340 | // if there are only read-only resources we'll set this resource |
337 | // as standard resource | 341 | // as standard resource |
338 | if ( !resource->readOnly() ) { | 342 | if ( !resource->readOnly() ) { |
339 | bool onlyReadOnly = true; | 343 | bool onlyReadOnly = true; |
340 | QListViewItem *it = mListView->firstChild(); | 344 | QListViewItem *it = mListView->firstChild(); |
341 | while ( it != 0 ) { | 345 | while ( it != 0 ) { |
342 | ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); | 346 | ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); |
343 | if ( !confIt->readOnly() && confIt != item ) | 347 | if ( !confIt->readOnly() && confIt != item ) |
344 | onlyReadOnly = false; | 348 | onlyReadOnly = false; |
345 | 349 | ||
346 | it = it->itemBelow(); | 350 | it = it->itemBelow(); |
347 | } | 351 | } |
348 | 352 | ||
349 | if ( onlyReadOnly ) | 353 | if ( onlyReadOnly ) |
350 | item->setStandard( true ); | 354 | item->setStandard( true ); |
351 | } | 355 | } |
352 | 356 | ||
353 | emit changed( true ); | 357 | emit changed( true ); |
354 | } else { | 358 | } else { |
355 | delete resource; | 359 | delete resource; |
356 | resource = 0; | 360 | resource = 0; |
357 | } | 361 | } |
358 | } | 362 | } |
359 | 363 | ||
360 | void ConfigPage::slotRemove() | 364 | void ConfigPage::slotRemove() |
361 | { | 365 | { |
362 | if ( !mCurrentManager ) | 366 | if ( !mCurrentManager ) |
363 | return; | 367 | return; |
364 | 368 | ||
365 | QListViewItem *item = mListView->currentItem(); | 369 | QListViewItem *item = mListView->currentItem(); |
366 | ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); | 370 | ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); |
367 | 371 | ||
368 | if ( !confItem ) | 372 | if ( !confItem ) |
369 | return; | 373 | return; |
370 | 374 | ||
371 | if ( confItem->standard() ) { | 375 | if ( confItem->standard() ) { |
372 | KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); | 376 | KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); |
373 | return; | 377 | return; |
374 | } | 378 | } |
375 | 379 | ||
376 | mCurrentManager->remove( confItem->resource() ); | 380 | mCurrentManager->remove( confItem->resource() ); |
377 | 381 | ||
378 | if ( item == mLastItem ) | 382 | if ( item == mLastItem ) |
379 | mLastItem = 0; | 383 | mLastItem = 0; |
380 | 384 | ||
381 | mListView->takeItem( item ); | 385 | mListView->takeItem( item ); |
382 | delete item; | 386 | delete item; |
383 | 387 | ||
384 | emit changed( true ); | 388 | emit changed( true ); |
385 | } | 389 | } |
386 | 390 | ||
387 | void ConfigPage::slotEdit() | 391 | void ConfigPage::slotEdit() |
388 | { | 392 | { |
389 | if ( !mCurrentManager ) | 393 | if ( !mCurrentManager ) |
390 | return; | 394 | return; |
391 | 395 | ||
392 | QListViewItem *item = mListView->currentItem(); | 396 | QListViewItem *item = mListView->currentItem(); |
393 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); | 397 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); |
394 | if ( !configItem ) | 398 | if ( !configItem ) |
395 | return; | 399 | return; |
396 | 400 | ||
397 | Resource *resource = configItem->resource(); | 401 | Resource *resource = configItem->resource(); |
398 | 402 | ||
399 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); | 403 | ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); |
400 | 404 | ||
401 | if ( dlg.exec() ) { | 405 | if ( dlg.exec() ) { |
402 | configItem->setText( 0, resource->resourceName() ); | 406 | configItem->setText( 0, resource->resourceName() ); |
403 | configItem->setText( 1, resource->type() ); | 407 | configItem->setText( 1, resource->type() ); |
404 | 408 | ||
405 | if ( configItem->standard() && configItem->readOnly() ) { | 409 | if ( configItem->standard() && configItem->readOnly() ) { |
406 | KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); | 410 | KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); |
407 | configItem->setStandard( false ); | 411 | configItem->setStandard( false ); |
408 | } | 412 | } |
409 | 413 | ||
410 | mCurrentManager->resourceChanged( resource ); | 414 | mCurrentManager->resourceChanged( resource ); |
411 | emit changed( true ); | 415 | emit changed( true ); |
412 | } | 416 | } |
413 | } | 417 | } |
414 | 418 | ||
415 | void ConfigPage::slotStandard() | 419 | void ConfigPage::slotStandard() |
416 | { | 420 | { |
417 | if ( !mCurrentManager ) | 421 | if ( !mCurrentManager ) |
418 | return; | 422 | return; |
419 | 423 | ||
420 | ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); | 424 | ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); |
421 | if ( !item ) | 425 | if ( !item ) |
422 | return; | 426 | return; |
423 | 427 | ||
424 | if ( item->readOnly() ) { | 428 | if ( item->readOnly() ) { |
425 | KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); | 429 | KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); |
426 | return; | 430 | return; |
427 | } | 431 | } |
428 | 432 | ||
429 | if ( !item->isOn() ) { | 433 | if ( !item->isOn() ) { |
430 | KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); | 434 | KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); |
431 | return; | 435 | return; |
432 | } | 436 | } |
433 | 437 | ||
434 | QListViewItem *it = mListView->firstChild(); | 438 | QListViewItem *it = mListView->firstChild(); |
435 | while ( it != 0 ) { | 439 | while ( it != 0 ) { |
436 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); | 440 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); |
437 | if ( configItem->standard() ) | 441 | if ( configItem->standard() ) |
438 | configItem->setStandard( false ); | 442 | configItem->setStandard( false ); |
439 | it = it->itemBelow(); | 443 | it = it->itemBelow(); |
440 | } | 444 | } |
441 | 445 | ||
442 | item->setStandard( true ); | 446 | item->setStandard( true ); |
443 | mCurrentManager->setStandardResource( item->resource() ); | 447 | mCurrentManager->setStandardResource( item->resource() ); |
444 | emit changed( true ); | 448 | emit changed( true ); |
445 | 449 | ||
446 | } | 450 | } |
447 | 451 | ||
448 | void ConfigPage::slotSelectionChanged() | 452 | void ConfigPage::slotSelectionChanged() |
449 | { | 453 | { |
450 | bool state = ( mListView->currentItem() != 0 ); | 454 | bool state = ( mListView->currentItem() != 0 ); |
451 | 455 | ||
452 | mRemoveButton->setEnabled( state ); | 456 | mRemoveButton->setEnabled( state ); |
453 | mEditButton->setEnabled( state ); | 457 | mEditButton->setEnabled( state ); |
454 | mStandardButton->setEnabled( state ); | 458 | mStandardButton->setEnabled( state ); |
455 | } | 459 | } |
456 | 460 | ||
457 | void ConfigPage::resourceAdded( Resource* resource ) | 461 | void ConfigPage::resourceAdded( Resource* resource ) |
458 | { | 462 | { |
459 | qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1()); | 463 | qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1()); |
460 | ConfigViewItem *item = new ConfigViewItem( mListView, resource ); | 464 | ConfigViewItem *item = new ConfigViewItem( mListView, resource ); |
461 | 465 | ||
462 | // FIXME: this sucks. This should be in the config file, | 466 | // FIXME: this sucks. This should be in the config file, |
463 | // or application-dependent, in which case it's always Off | 467 | // or application-dependent, in which case it's always Off |
464 | item->setOn( false ); | 468 | item->setOn( false ); |
465 | 469 | ||
466 | mLastItem = item; | 470 | mLastItem = item; |
467 | 471 | ||
468 | emit changed( true ); | 472 | emit changed( true ); |
469 | } | 473 | } |
470 | 474 | ||
471 | void ConfigPage::resourceModified( Resource* resource ) | 475 | void ConfigPage::resourceModified( Resource* resource ) |
472 | { | 476 | { |
473 | qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1()); | 477 | qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1()); |
474 | } | 478 | } |
475 | 479 | ||
476 | void ConfigPage::resourceDeleted( Resource* resource ) | 480 | void ConfigPage::resourceDeleted( Resource* resource ) |
477 | { | 481 | { |
478 | qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); | 482 | qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); |
479 | } | 483 | } |
480 | 484 | ||
481 | void ConfigPage::slotItemClicked( QListViewItem *item ) | 485 | void ConfigPage::slotItemClicked( QListViewItem *item ) |
482 | { | 486 | { |
483 | ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); | 487 | ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); |
484 | if ( !configItem ) return; | 488 | if ( !configItem ) return; |
485 | 489 | ||
486 | if ( configItem->standard() && !configItem->isOn() ) { | 490 | if ( configItem->standard() && !configItem->isOn() ) { |
487 | KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); | 491 | KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); |
488 | configItem->setOn( true ); | 492 | configItem->setOn( true ); |
489 | return; | 493 | return; |
490 | } | 494 | } |
491 | 495 | ||
492 | if ( configItem->isOn() != configItem->resource()->isActive() ) { | 496 | if ( configItem->isOn() != configItem->resource()->isActive() ) { |
493 | emit changed( true ); | 497 | emit changed( true ); |
494 | } | 498 | } |
495 | } | 499 | } |
496 | 500 | ||
497 | void ConfigPage::saveResourceSettings() | 501 | void ConfigPage::saveResourceSettings() |
498 | { | 502 | { |
499 | //qDebug("ConfigPage::saveResourceSettings() begin"); | 503 | //qDebug("ConfigPage::saveResourceSettings() begin"); |
500 | 504 | ||
501 | if ( mCurrentManager ) { | 505 | if ( mCurrentManager ) { |
502 | 506 | ||
503 | QListViewItem *item = mListView->firstChild(); | 507 | QListViewItem *item = mListView->firstChild(); |
504 | while ( item ) { | 508 | while ( item ) { |
505 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); | 509 | ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); |
506 | 510 | ||
507 | // check if standard resource | 511 | // check if standard resource |
508 | if ( configItem->standard() && !configItem->readOnly() && | 512 | if ( configItem->standard() && !configItem->readOnly() && |
509 | configItem->isOn() ) { | 513 | configItem->isOn() ) { |
510 | 514 | ||
511 | mCurrentManager->setStandardResource( configItem->resource() ); | 515 | mCurrentManager->setStandardResource( configItem->resource() ); |
512 | } | 516 | } |
513 | 517 | ||
514 | // check if active or passive resource | 518 | // check if active or passive resource |
515 | configItem->resource()->setActive( configItem->isOn() ); | 519 | configItem->resource()->setActive( configItem->isOn() ); |
516 | 520 | ||
517 | item = item->nextSibling(); | 521 | item = item->nextSibling(); |
518 | } | 522 | } |
519 | mCurrentManager->writeConfig( mCurrentConfig ); | 523 | mCurrentManager->writeConfig( mCurrentConfig ); |
520 | 524 | ||
521 | if ( !mCurrentManager->standardResource() ) | 525 | if ( !mCurrentManager->standardResource() ) |
522 | KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); | 526 | KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); |
523 | } | 527 | } |
524 | 528 | ||
525 | //qDebug("ConfigPage::saveResourceSettings() end"); | 529 | //qDebug("ConfigPage::saveResourceSettings() end"); |
526 | 530 | ||
527 | } | 531 | } |
528 | 532 | ||
529 | //US #include "configpage.moc" | 533 | //US #include "configpage.moc" |
530 | 534 | ||