Diffstat (limited to 'kaddressbook/xxport/csvimportdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/xxport/csvimportdialog.cpp | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp index 862241e..7959cac 100644 --- a/kaddressbook/xxport/csvimportdialog.cpp +++ b/kaddressbook/xxport/csvimportdialog.cpp | |||
@@ -1,91 +1,95 @@ | |||
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 <q3buttongroup.h> |
31 | #include <qcheckbox.h> | 31 | #include <qcheckbox.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | #ifdef DESKTOP_VERSION | 33 | #ifdef DESKTOP_VERSION |
34 | #include <qinputdialog.h> | 34 | #include <qinputdialog.h> |
35 | #else | 35 | #else |
36 | #include <qtcompat/qinputdialog.h> | 36 | #include <qtcompat/qinputdialog.h> |
37 | #endif | 37 | #endif |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qtable.h> | 42 | #include <q3table.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | #include <qtextstream.h> | 44 | #include <q3textstream.h> |
45 | #include <qfile.h> | 45 | #include <qfile.h> |
46 | //Added by qt3to4: | ||
47 | #include <Q3HBoxLayout> | ||
48 | #include <Q3ValueList> | ||
49 | #include <Q3GridLayout> | ||
46 | 50 | ||
47 | #include <kapplication.h> | 51 | #include <kapplication.h> |
48 | #include <kdebug.h> | 52 | #include <kdebug.h> |
49 | #include <kdialogbase.h> | 53 | #include <kdialogbase.h> |
50 | #include <kfiledialog.h> | 54 | #include <kfiledialog.h> |
51 | #include <klineedit.h> | 55 | #include <klineedit.h> |
52 | #include <klocale.h> | 56 | #include <klocale.h> |
53 | #include <kglobal.h> | 57 | #include <kglobal.h> |
54 | #include <kmessagebox.h> | 58 | #include <kmessagebox.h> |
55 | #include <kstandarddirs.h> | 59 | #include <kstandarddirs.h> |
56 | #include <kurlrequester.h> | 60 | #include <kurlrequester.h> |
57 | 61 | ||
58 | #ifdef DESKTOP_VERSION | 62 | #ifdef DESKTOP_VERSION |
59 | #include "qtable.h" | 63 | #include "q3table.h" |
60 | #else | 64 | #else |
61 | #include "qcombotableitem.h" | 65 | #include "qcombotableitem.h" |
62 | #endif | 66 | #endif |
63 | #include "csvimportdialog.h" | 67 | #include "csvimportdialog.h" |
64 | 68 | ||
65 | CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, | 69 | CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, |
66 | const char * name ) | 70 | const char * name ) |
67 | : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 | | 71 | : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 | |
68 | User2, Ok, parent, name, true, true ), | 72 | User2, Ok, parent, name, true, true ), |
69 | mAdjustRows( false ), | 73 | mAdjustRows( false ), |
70 | mStartLine( 0 ), | 74 | mStartLine( 0 ), |
71 | mTextQuote( '"' ), | 75 | mTextQuote( '"' ), |
72 | mDelimiter( "," ), | 76 | mDelimiter( "," ), |
73 | mAddressBook( ab ) | 77 | mAddressBook( ab ) |
74 | { | 78 | { |
75 | initGUI(); | 79 | initGUI(); |
76 | 80 | ||
77 | mTypeMap.insert( i18n( "Undefined" ), Undefined ); | 81 | mTypeMap.insert( i18n( "Undefined" ), Undefined ); |
78 | mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName ); | 82 | mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName ); |
79 | mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName ); | 83 | mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName ); |
80 | mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName ); | 84 | mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName ); |
81 | mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName ); | 85 | mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName ); |
82 | mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix ); | 86 | mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix ); |
83 | mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix ); | 87 | mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix ); |
84 | mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName ); | 88 | mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName ); |
85 | mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday ); | 89 | mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday ); |
86 | 90 | ||
87 | mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet ); | 91 | mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet ); |
88 | mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(), | 92 | mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(), |
89 | HomeAddressLocality ); | 93 | HomeAddressLocality ); |
90 | mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion ); | 94 | mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion ); |
91 | mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(), | 95 | mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(), |
@@ -132,133 +136,133 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent, | |||
132 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) | 136 | for ( it = fields.begin(); it != fields.end(); ++it, ++count ) |
133 | mTypeMap.insert( (*it)->label(), count ); | 137 | mTypeMap.insert( (*it)->label(), count ); |
134 | 138 | ||
135 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), | 139 | connect( mDelimiterBox, SIGNAL( clicked( int ) ), |
136 | this, SLOT( delimiterClicked( int ) ) ); | 140 | this, SLOT( delimiterClicked( int ) ) ); |
137 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), | 141 | connect( mDelimiterEdit, SIGNAL( returnPressed() ), |
138 | this, SLOT( returnPressed() ) ); | 142 | this, SLOT( returnPressed() ) ); |
139 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), | 143 | connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ), |
140 | this, SLOT( textChanged ( const QString& ) ) ); | 144 | this, SLOT( textChanged ( const QString& ) ) ); |
141 | connect( mComboLine, SIGNAL( activated( const QString& ) ), | 145 | connect( mComboLine, SIGNAL( activated( const QString& ) ), |
142 | this, SLOT( lineSelected( const QString& ) ) ); | 146 | this, SLOT( lineSelected( const QString& ) ) ); |
143 | connect( mComboCodec, SIGNAL( activated( const QString& ) ), | 147 | connect( mComboCodec, SIGNAL( activated( const QString& ) ), |
144 | this, SLOT( codecChanged( const QString& ) ) ); | 148 | this, SLOT( codecChanged( const QString& ) ) ); |
145 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), | 149 | connect( mComboQuote, SIGNAL( activated( const QString& ) ), |
146 | this, SLOT( textquoteSelected( const QString& ) ) ); | 150 | this, SLOT( textquoteSelected( const QString& ) ) ); |
147 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), | 151 | connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ), |
148 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); | 152 | this, SLOT( ignoreDuplicatesChanged( int ) ) ); |
149 | 153 | ||
150 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), | 154 | connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ), |
151 | this, SLOT( setFile( const QString& ) ) ); | 155 | this, SLOT( setFile( const QString& ) ) ); |
152 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), | 156 | connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ), |
153 | this, SLOT( setFile( const QString& ) ) ); | 157 | this, SLOT( setFile( const QString& ) ) ); |
154 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), | 158 | connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ), |
155 | this, SLOT( urlChanged( const QString& ) ) ); | 159 | this, SLOT( urlChanged( const QString& ) ) ); |
156 | 160 | ||
157 | connect( this, SIGNAL( user1Clicked() ), | 161 | connect( this, SIGNAL( user1Clicked() ), |
158 | this, SLOT( applyTemplate() ) ); | 162 | this, SLOT( applyTemplate() ) ); |
159 | 163 | ||
160 | connect( this, SIGNAL( user2Clicked() ), | 164 | connect( this, SIGNAL( user2Clicked() ), |
161 | this, SLOT( saveTemplate() ) ); | 165 | this, SLOT( saveTemplate() ) ); |
162 | 166 | ||
163 | // if ( QApplication::desktop()->width() < 321 ) | 167 | // if ( QApplication::desktop()->width() < 321 ) |
164 | QIconSet icon = SmallIcon("filesave"); | 168 | QIcon icon = SmallIcon("filesave"); |
165 | 169 | ||
166 | findButton( User2 )->setIconSet (icon ) ; | 170 | findButton( User2 )->setIconSet (icon ) ; |
167 | icon = SmallIcon("fileopen"); | 171 | icon = SmallIcon("fileopen"); |
168 | findButton( User1 )->setIconSet (icon ) ; | 172 | findButton( User1 )->setIconSet (icon ) ; |
169 | int wid = findButton( User2 )->sizeHint().height(); | 173 | int wid = findButton( User2 )->sizeHint().height(); |
170 | findButton( User2 )->setMaximumWidth( wid+4 ); | 174 | findButton( User2 )->setMaximumWidth( wid+4 ); |
171 | findButton( User1 )->setMaximumWidth( wid+4 ); | 175 | findButton( User1 )->setMaximumWidth( wid+4 ); |
172 | } | 176 | } |
173 | 177 | ||
174 | CSVImportDialog::~CSVImportDialog() | 178 | CSVImportDialog::~CSVImportDialog() |
175 | { | 179 | { |
176 | } | 180 | } |
177 | 181 | ||
178 | KABC::AddresseeList CSVImportDialog::contacts() const | 182 | KABC::AddresseeList CSVImportDialog::contacts() const |
179 | { | 183 | { |
180 | KABC::AddresseeList contacts; | 184 | KABC::AddresseeList contacts; |
181 | 185 | ||
182 | for ( int row = 1; row < mTable->numRows(); ++row ) { | 186 | for ( int row = 1; row < mTable->numRows(); ++row ) { |
183 | KABC::Addressee a; | 187 | KABC::Addressee a; |
184 | bool emptyRow = true; | 188 | bool emptyRow = true; |
185 | KABC::Address addrHome( KABC::Address::Home ); | 189 | KABC::Address addrHome( KABC::Address::Home ); |
186 | KABC::Address addrWork( KABC::Address::Work ); | 190 | KABC::Address addrWork( KABC::Address::Work ); |
187 | for ( int col = 0; col < mTable->numCols(); ++col ) { | 191 | for ( int col = 0; col < mTable->numCols(); ++col ) { |
188 | 192 | ||
189 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) ); | 193 | Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, col ) ); |
190 | 194 | ||
191 | if ( !item ) { | 195 | if ( !item ) { |
192 | qDebug( "ERROR: item cast failed" ); | 196 | qDebug( "ERROR: item cast failed" ); |
193 | continue; | 197 | continue; |
194 | } | 198 | } |
195 | 199 | ||
196 | QString value = mTable->text( row, col ); | 200 | QString value = mTable->text( row, col ); |
197 | if ( !value.isEmpty() ) | 201 | if ( !value.isEmpty() ) |
198 | emptyRow = false; | 202 | emptyRow = false; |
199 | 203 | ||
200 | switch ( posToType( item->currentItem() ) ) | 204 | switch ( posToType( item->currentItem() ) ) |
201 | { | 205 | { |
202 | case Undefined: | 206 | case Undefined: |
203 | continue; | 207 | continue; |
204 | break; | 208 | break; |
205 | case FormattedName: | 209 | case FormattedName: |
206 | a.setFormattedName( value ); | 210 | a.setFormattedName( value ); |
207 | break; | 211 | break; |
208 | case GivenName: | 212 | case GivenName: |
209 | a.setGivenName( value ); | 213 | a.setGivenName( value ); |
210 | break; | 214 | break; |
211 | case FamilyName: | 215 | case FamilyName: |
212 | a.setFamilyName( value ); | 216 | a.setFamilyName( value ); |
213 | break; | 217 | break; |
214 | case AdditionalName: | 218 | case AdditionalName: |
215 | a.setAdditionalName( value ); | 219 | a.setAdditionalName( value ); |
216 | break; | 220 | break; |
217 | case Prefix: | 221 | case Prefix: |
218 | a.setPrefix( value ); | 222 | a.setPrefix( value ); |
219 | break; | 223 | break; |
220 | case Suffix: | 224 | case Suffix: |
221 | a.setSuffix( value ); | 225 | a.setSuffix( value ); |
222 | break; | 226 | break; |
223 | case NickName: | 227 | case NickName: |
224 | a.setNickName( value ); | 228 | a.setNickName( value ); |
225 | break; | 229 | break; |
226 | case Birthday: | 230 | case Birthday: |
227 | //US | 231 | //US |
228 | //the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); | 232 | //the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) ); |
229 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? | 233 | // But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ? |
230 | { | 234 | { |
231 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate | 235 | QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate |
232 | a.setBirthday(dt); | 236 | a.setBirthday(QDateTime(dt)); |
233 | } | 237 | } |
234 | break; | 238 | break; |
235 | case Email: | 239 | case Email: |
236 | if ( !value.isEmpty() ) | 240 | if ( !value.isEmpty() ) |
237 | a.insertEmail( value, true ); | 241 | a.insertEmail( value, true ); |
238 | break; | 242 | break; |
239 | case Role: | 243 | case Role: |
240 | a.setRole( value ); | 244 | a.setRole( value ); |
241 | break; | 245 | break; |
242 | case Title: | 246 | case Title: |
243 | a.setTitle( value ); | 247 | a.setTitle( value ); |
244 | break; | 248 | break; |
245 | case Mailer: | 249 | case Mailer: |
246 | a.setMailer( value ); | 250 | a.setMailer( value ); |
247 | break; | 251 | break; |
248 | case URL: | 252 | case URL: |
249 | a.setUrl( value ); | 253 | a.setUrl( value ); |
250 | break; | 254 | break; |
251 | case Organization: | 255 | case Organization: |
252 | a.setOrganization( value ); | 256 | a.setOrganization( value ); |
253 | break; | 257 | break; |
254 | case Note: | 258 | case Note: |
255 | if ( a.note().isEmpty() ) | 259 | if ( a.note().isEmpty() ) |
256 | a.setNote( value ); | 260 | a.setNote( value ); |
257 | else { | 261 | else { |
258 | a.setNote( a.note()+"\n"+value ); | 262 | a.setNote( a.note()+"\n"+value ); |
259 | } | 263 | } |
260 | break; | 264 | break; |
261 | case Categories: | 265 | case Categories: |
262 | a.insertCategory( value ); | 266 | a.insertCategory( value ); |
263 | break; | 267 | break; |
264 | case HomePhone: | 268 | case HomePhone: |
@@ -353,332 +357,332 @@ KABC::AddresseeList CSVImportDialog::contacts() const | |||
353 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); | 357 | KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory ); |
354 | KABC::Field::List::Iterator it; | 358 | KABC::Field::List::Iterator it; |
355 | 359 | ||
356 | int counter = 0; | 360 | int counter = 0; |
357 | for ( it = fields.begin(); it != fields.end(); ++it ) { | 361 | for ( it = fields.begin(); it != fields.end(); ++it ) { |
358 | if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) ) | 362 | if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) ) |
359 | { | 363 | { |
360 | (*it)->setValue( a, value ); | 364 | (*it)->setValue( a, value ); |
361 | break; | 365 | break; |
362 | } | 366 | } |
363 | ++counter; | 367 | ++counter; |
364 | } | 368 | } |
365 | break; | 369 | break; |
366 | } | 370 | } |
367 | } | 371 | } |
368 | 372 | ||
369 | if ( !addrHome.isEmpty() ) | 373 | if ( !addrHome.isEmpty() ) |
370 | a.insertAddress( addrHome ); | 374 | a.insertAddress( addrHome ); |
371 | if ( !addrWork.isEmpty() ) | 375 | if ( !addrWork.isEmpty() ) |
372 | a.insertAddress( addrWork ); | 376 | a.insertAddress( addrWork ); |
373 | 377 | ||
374 | if ( !emptyRow && !a.isEmpty() ) | 378 | if ( !emptyRow && !a.isEmpty() ) |
375 | contacts.append( a ); | 379 | contacts.append( a ); |
376 | } | 380 | } |
377 | 381 | ||
378 | return contacts; | 382 | return contacts; |
379 | } | 383 | } |
380 | 384 | ||
381 | void CSVImportDialog::initGUI() | 385 | void CSVImportDialog::initGUI() |
382 | { | 386 | { |
383 | QWidget* page = plainPage(); | 387 | QWidget* page = plainPage(); |
384 | 388 | ||
385 | QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(), | 389 | Q3GridLayout *layout = new Q3GridLayout( page, 1, 1, marginHintSmall(), |
386 | spacingHintSmall() ); | 390 | spacingHintSmall() ); |
387 | QHBoxLayout *hbox = new QHBoxLayout(); | 391 | Q3HBoxLayout *hbox = new Q3HBoxLayout(); |
388 | hbox->setSpacing( spacingHint() ); | 392 | hbox->setSpacing( spacingHint() ); |
389 | 393 | ||
390 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); | 394 | QLabel *label = new QLabel( i18n( "File to import:" ), page ); |
391 | hbox->addWidget( label ); | 395 | hbox->addWidget( label ); |
392 | 396 | ||
393 | mUrlRequester = new KURLRequester( page ); | 397 | mUrlRequester = new KURLRequester( page ); |
394 | mUrlRequester->setFilter( "*.csv" ); | 398 | mUrlRequester->setFilter( "*.csv" ); |
395 | hbox->addWidget( mUrlRequester ); | 399 | hbox->addWidget( mUrlRequester ); |
396 | 400 | ||
397 | layout->addMultiCellLayout( hbox, 0, 0, 0, 2 ); | 401 | layout->addMultiCellLayout( hbox, 0, 0, 0, 2 ); |
398 | 402 | ||
399 | // Delimiter: comma, semicolon, tab, space, other | 403 | // Delimiter: comma, semicolon, tab, space, other |
400 | mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page ); | 404 | mDelimiterBox = new Q3ButtonGroup( i18n( "Delimiter" ), page ); |
401 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); | 405 | mDelimiterBox->setColumnLayout( 0, Qt::Vertical ); |
402 | mDelimiterBox->layout()->setSpacing( spacingHint() ); | 406 | mDelimiterBox->layout()->setSpacing( spacingHint() ); |
403 | mDelimiterBox->layout()->setMargin( marginHint() ); | 407 | mDelimiterBox->layout()->setMargin( marginHint() ); |
404 | QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() ); | 408 | Q3GridLayout *delimiterLayout = new Q3GridLayout( mDelimiterBox->layout() ); |
405 | delimiterLayout->setAlignment( Qt::AlignTop ); | 409 | delimiterLayout->setAlignment( Qt::AlignTop ); |
406 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 ); | 410 | layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 ); |
407 | 411 | ||
408 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); | 412 | mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox ); |
409 | mRadioComma->setChecked( true ); | 413 | mRadioComma->setChecked( true ); |
410 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); | 414 | delimiterLayout->addWidget( mRadioComma, 0, 0 ); |
411 | 415 | ||
412 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); | 416 | mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox ); |
413 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); | 417 | delimiterLayout->addWidget( mRadioSemicolon, 0, 1 ); |
414 | 418 | ||
415 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); | 419 | mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox ); |
416 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); | 420 | delimiterLayout->addWidget( mRadioTab, 1, 0 ); |
417 | 421 | ||
418 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); | 422 | mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox ); |
419 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); | 423 | delimiterLayout->addWidget( mRadioSpace, 1, 1 ); |
420 | 424 | ||
421 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); | 425 | mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox ); |
422 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); | 426 | delimiterLayout->addWidget( mRadioOther, 0, 2 ); |
423 | 427 | ||
424 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); | 428 | mDelimiterEdit = new QLineEdit( mDelimiterBox ); |
425 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); | 429 | delimiterLayout->addWidget( mDelimiterEdit, 1, 2 ); |
426 | 430 | ||
427 | mComboLine = new QComboBox( false, page ); | 431 | mComboLine = new QComboBox( false, page ); |
428 | mComboLine->insertItem( i18n( "1" ) ); | 432 | mComboLine->insertItem( i18n( "1" ) ); |
429 | layout->addWidget( mComboLine, 3, 1 ); | 433 | layout->addWidget( mComboLine, 3, 1 ); |
430 | 434 | ||
431 | mComboQuote = new QComboBox( false, page ); | 435 | mComboQuote = new QComboBox( false, page ); |
432 | mComboQuote->insertItem( i18n( "\"" ), 0 ); | 436 | mComboQuote->insertItem( i18n( "\"" ), 0 ); |
433 | mComboQuote->insertItem( i18n( "'" ), 1 ); | 437 | mComboQuote->insertItem( i18n( "'" ), 1 ); |
434 | mComboQuote->insertItem( i18n( "None" ), 2 ); | 438 | mComboQuote->insertItem( i18n( "None" ), 2 ); |
435 | layout->addWidget( mComboQuote, 3, 0 ); | 439 | layout->addWidget( mComboQuote, 3, 0 ); |
436 | mComboCodec = new QComboBox( false, page ); | 440 | mComboCodec = new QComboBox( false, page ); |
437 | mComboCodec->insertItem( i18n( "UTF8" ), 0 ); | 441 | mComboCodec->insertItem( i18n( "UTF8" ), 0 ); |
438 | mComboCodec->insertItem( i18n( "LATIN1" ), 1 ); | 442 | mComboCodec->insertItem( i18n( "LATIN1" ), 1 ); |
439 | mComboCodec->insertItem( i18n( "LOCALE" ), 2 ); | 443 | mComboCodec->insertItem( i18n( "LOCALE" ), 2 ); |
440 | layout->addWidget( mComboCodec, 3, 2 ); | 444 | layout->addWidget( mComboCodec, 3, 2 ); |
441 | label = new QLabel( i18n( "Start at line:" ), page ); | 445 | label = new QLabel( i18n( "Start at line:" ), page ); |
442 | layout->addWidget( label, 2, 1 ); | 446 | layout->addWidget( label, 2, 1 ); |
443 | 447 | ||
444 | label = new QLabel( i18n( "Textquote:" ), page ); | 448 | label = new QLabel( i18n( "Textquote:" ), page ); |
445 | layout->addWidget( label, 2, 0 ); | 449 | layout->addWidget( label, 2, 0 ); |
446 | label = new QLabel( i18n( "Codec:" ), page ); | 450 | label = new QLabel( i18n( "Codec:" ), page ); |
447 | layout->addWidget( label, 2, 2 ); | 451 | layout->addWidget( label, 2, 2 ); |
448 | 452 | ||
449 | mIgnoreDuplicates = new QCheckBox( page ); | 453 | mIgnoreDuplicates = new QCheckBox( page ); |
450 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); | 454 | mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) ); |
451 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 2 ); | 455 | layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 2 ); |
452 | 456 | ||
453 | mTable = new QTable( 0, 0, page ); | 457 | mTable = new Q3Table( 0, 0, page ); |
454 | mTable->setSelectionMode( QTable::NoSelection ); | 458 | mTable->setSelectionMode( Q3Table::NoSelection ); |
455 | //mTable->horizontalHeader()->hide(); | 459 | //mTable->horizontalHeader()->hide(); |
456 | layout->addMultiCellWidget( mTable, 5, 5, 0, 2 ); | 460 | layout->addMultiCellWidget( mTable, 5, 5, 0, 2 ); |
457 | /*US | 461 | /*US |
458 | setButtonText( User1, i18n( "Apply Template" ) ); | 462 | setButtonText( User1, i18n( "Apply Template" ) ); |
459 | setButtonText( User2, i18n( "Save Template" ) ); | 463 | setButtonText( User2, i18n( "Save Template" ) ); |
460 | */ | 464 | */ |
461 | 465 | ||
462 | enableButtonOK( false ); | 466 | enableButtonOK( false ); |
463 | 467 | ||
464 | findButton( User1 )->setEnabled( false ); | 468 | findButton( User1 )->setEnabled( false ); |
465 | findButton( User2 )->setEnabled( false ); | 469 | findButton( User2 )->setEnabled( false ); |
466 | 470 | ||
467 | #ifdef DESKTOP_VERSION | 471 | #ifdef DESKTOP_VERSION |
468 | resize( 640, 480 ); | 472 | resize( 640, 480 ); |
469 | #else | 473 | #else |
470 | showMaximized(); | 474 | showMaximized(); |
471 | #endif | 475 | #endif |
472 | } | 476 | } |
473 | 477 | ||
474 | void CSVImportDialog::fillTable() | 478 | void CSVImportDialog::fillTable() |
475 | { | 479 | { |
476 | int row, column; | 480 | int row, column; |
477 | bool lastCharDelimiter = false; | 481 | bool lastCharDelimiter = false; |
478 | bool ignoreDups = mIgnoreDuplicates->isChecked(); | 482 | bool ignoreDups = mIgnoreDuplicates->isChecked(); |
479 | enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, | 483 | enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD, |
480 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; | 484 | S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START; |
481 | 485 | ||
482 | QChar x; | 486 | QChar x; |
483 | QString field = ""; | 487 | QString field = ""; |
484 | 488 | ||
485 | // store previous assignment | 489 | // store previous assignment |
486 | QValueList<int> mTypeOld = mTypeStore; | 490 | Q3ValueList<int> mTypeOld = mTypeStore; |
487 | 491 | ||
488 | mTypeStore.clear(); | 492 | mTypeStore.clear(); |
489 | for ( column = 0; column < mTable->numCols(); ++column ) { | 493 | for ( column = 0; column < mTable->numCols(); ++column ) { |
490 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) ); | 494 | Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, column ) ); |
491 | 495 | ||
492 | if ( !item || mClearTypeStore ) | 496 | if ( !item || mClearTypeStore ) |
493 | mTypeStore.append( typeToPos( Undefined ) ); | 497 | mTypeStore.append( typeToPos( Undefined ) ); |
494 | else if ( item ) | 498 | else if ( item ) |
495 | mTypeStore.append( item->currentItem() ); | 499 | mTypeStore.append( item->currentItem() ); |
496 | } | 500 | } |
497 | 501 | ||
498 | clearTable(); | 502 | clearTable(); |
499 | 503 | ||
500 | row = column = 1; | 504 | row = column = 1; |
501 | if ( mComboCodec->currentItem () == 0 ) { | 505 | if ( mComboCodec->currentItem () == 0 ) { |
502 | mData = QString::fromUtf8( mFileArray.data() ); | 506 | mData = QString::fromUtf8( mFileArray.data() ); |
503 | } else if ( mComboCodec->currentItem () == 1 ) { | 507 | } else if ( mComboCodec->currentItem () == 1 ) { |
504 | mData = QString::fromLatin1( mFileArray.data() ); | 508 | mData = QString::fromLatin1( mFileArray.data() ); |
505 | } else { | 509 | } else { |
506 | mData = QString::fromLocal8Bit( mFileArray.data() ); | 510 | mData = QString::fromLocal8Bit( mFileArray.data() ); |
507 | } | 511 | } |
508 | 512 | ||
509 | QTextStream inputStream( mData, IO_ReadOnly ); | 513 | Q3TextStream inputStream( mData, QIODevice::ReadOnly ); |
510 | 514 | ||
511 | if ( mComboCodec->currentItem () == 0 ) { | 515 | if ( mComboCodec->currentItem () == 0 ) { |
512 | inputStream.setEncoding( QTextStream::UnicodeUTF8 ); | 516 | inputStream.setEncoding( Q3TextStream::UnicodeUTF8 ); |
513 | } else if ( mComboCodec->currentItem () == 1 ) { | 517 | } else if ( mComboCodec->currentItem () == 1 ) { |
514 | inputStream.setEncoding( QTextStream::Latin1 ); | 518 | inputStream.setEncoding( Q3TextStream::Latin1 ); |
515 | } else { | 519 | } else { |
516 | inputStream.setEncoding( QTextStream::Locale ); | 520 | inputStream.setEncoding( Q3TextStream::Locale ); |
517 | } | 521 | } |
518 | 522 | ||
519 | int maxColumn = 0; | 523 | int maxColumn = 0; |
520 | while ( !inputStream.atEnd() ) { | 524 | while ( !inputStream.atEnd() ) { |
521 | inputStream >> x; // read one char | 525 | inputStream >> x; // read one char |
522 | 526 | ||
523 | if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly | 527 | if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly |
524 | 528 | ||
525 | switch ( state ) { | 529 | switch ( state ) { |
526 | case S_START : | 530 | case S_START : |
527 | if ( x == mTextQuote ) { | 531 | if ( x == mTextQuote ) { |
528 | state = S_QUOTED_FIELD; | 532 | state = S_QUOTED_FIELD; |
529 | } else if ( x == mDelimiter ) { | 533 | } else if ( QString(x) == mDelimiter ) { |
530 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 534 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
531 | ++column; | 535 | ++column; |
532 | lastCharDelimiter = true; | 536 | lastCharDelimiter = true; |
533 | } else if ( x == '\n' ) { | 537 | } else if ( x == '\n' ) { |
534 | ++row; | 538 | ++row; |
535 | column = 1; | 539 | column = 1; |
536 | } else { | 540 | } else { |
537 | field += x; | 541 | field += x; |
538 | state = S_MAYBE_NORMAL_FIELD; | 542 | state = S_MAYBE_NORMAL_FIELD; |
539 | } | 543 | } |
540 | break; | 544 | break; |
541 | case S_QUOTED_FIELD : | 545 | case S_QUOTED_FIELD : |
542 | if ( x == mTextQuote ) { | 546 | if ( x == mTextQuote ) { |
543 | state = S_MAYBE_END_OF_QUOTED_FIELD; | 547 | state = S_MAYBE_END_OF_QUOTED_FIELD; |
544 | } else if ( x == '\n' && mTextQuote.isNull() ) { | 548 | } else if ( x == '\n' && mTextQuote.isNull() ) { |
545 | setText( row - mStartLine + 1, column, field ); | 549 | setText( row - mStartLine + 1, column, field ); |
546 | field = ""; | 550 | field = ""; |
547 | if ( x == '\n' ) { | 551 | if ( x == '\n' ) { |
548 | ++row; | 552 | ++row; |
549 | column = 1; | 553 | column = 1; |
550 | } else { | 554 | } else { |
551 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 555 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
552 | ++column; | 556 | ++column; |
553 | lastCharDelimiter = true; | 557 | lastCharDelimiter = true; |
554 | } | 558 | } |
555 | state = S_START; | 559 | state = S_START; |
556 | } else { | 560 | } else { |
557 | field += x; | 561 | field += x; |
558 | } | 562 | } |
559 | break; | 563 | break; |
560 | case S_MAYBE_END_OF_QUOTED_FIELD : | 564 | case S_MAYBE_END_OF_QUOTED_FIELD : |
561 | if ( x == mTextQuote ) { | 565 | if ( x == mTextQuote ) { |
562 | field += x; | 566 | field += x; |
563 | state = S_QUOTED_FIELD; | 567 | state = S_QUOTED_FIELD; |
564 | } else if ( x == mDelimiter || x == '\n' ) { | 568 | } else if ( QString(x) == mDelimiter || x == '\n' ) { |
565 | setText( row - mStartLine + 1, column, field ); | 569 | setText( row - mStartLine + 1, column, field ); |
566 | field = ""; | 570 | field = ""; |
567 | if ( x == '\n' ) { | 571 | if ( x == '\n' ) { |
568 | ++row; | 572 | ++row; |
569 | column = 1; | 573 | column = 1; |
570 | } else { | 574 | } else { |
571 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 575 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
572 | ++column; | 576 | ++column; |
573 | lastCharDelimiter = true; | 577 | lastCharDelimiter = true; |
574 | } | 578 | } |
575 | state = S_START; | 579 | state = S_START; |
576 | } else { | 580 | } else { |
577 | state = S_END_OF_QUOTED_FIELD; | 581 | state = S_END_OF_QUOTED_FIELD; |
578 | } | 582 | } |
579 | break; | 583 | break; |
580 | case S_END_OF_QUOTED_FIELD : | 584 | case S_END_OF_QUOTED_FIELD : |
581 | if ( x == mDelimiter || x == '\n' ) { | 585 | if ( QString(x) == mDelimiter || x == '\n' ) { |
582 | setText( row - mStartLine + 1, column, field ); | 586 | setText( row - mStartLine + 1, column, field ); |
583 | field = ""; | 587 | field = ""; |
584 | if ( x == '\n' ) { | 588 | if ( x == '\n' ) { |
585 | ++row; | 589 | ++row; |
586 | column = 1; | 590 | column = 1; |
587 | } else { | 591 | } else { |
588 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 592 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
589 | ++column; | 593 | ++column; |
590 | lastCharDelimiter = true; | 594 | lastCharDelimiter = true; |
591 | } | 595 | } |
592 | state = S_START; | 596 | state = S_START; |
593 | } else { | 597 | } else { |
594 | state = S_END_OF_QUOTED_FIELD; | 598 | state = S_END_OF_QUOTED_FIELD; |
595 | } | 599 | } |
596 | break; | 600 | break; |
597 | case S_MAYBE_NORMAL_FIELD : | 601 | case S_MAYBE_NORMAL_FIELD : |
598 | if ( x == mTextQuote ) { | 602 | if ( x == mTextQuote ) { |
599 | field = ""; | 603 | field = ""; |
600 | state = S_QUOTED_FIELD; | 604 | state = S_QUOTED_FIELD; |
601 | break; | 605 | break; |
602 | } | 606 | } |
603 | case S_NORMAL_FIELD : | 607 | case S_NORMAL_FIELD : |
604 | if ( x == mDelimiter || x == '\n' ) { | 608 | if ( QString(x) == mDelimiter || x == '\n' ) { |
605 | setText( row - mStartLine + 1, column, field ); | 609 | setText( row - mStartLine + 1, column, field ); |
606 | field = ""; | 610 | field = ""; |
607 | if ( x == '\n' ) { | 611 | if ( x == '\n' ) { |
608 | ++row; | 612 | ++row; |
609 | column = 1; | 613 | column = 1; |
610 | } else { | 614 | } else { |
611 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) | 615 | if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) ) |
612 | ++column; | 616 | ++column; |
613 | lastCharDelimiter = true; | 617 | lastCharDelimiter = true; |
614 | } | 618 | } |
615 | state = S_START; | 619 | state = S_START; |
616 | } else { | 620 | } else { |
617 | field += x; | 621 | field += x; |
618 | } | 622 | } |
619 | } | 623 | } |
620 | if ( x != mDelimiter ) | 624 | if ( QString(x) != mDelimiter ) |
621 | lastCharDelimiter = false; | 625 | lastCharDelimiter = false; |
622 | 626 | ||
623 | if ( column > maxColumn ) | 627 | if ( column > maxColumn ) |
624 | maxColumn = column; | 628 | maxColumn = column; |
625 | } | 629 | } |
626 | 630 | ||
627 | // file with only one line without '\n' | 631 | // file with only one line without '\n' |
628 | if ( field.length() > 0 ) { | 632 | if ( field.length() > 0 ) { |
629 | setText( row - mStartLine + 1, column, field ); | 633 | setText( row - mStartLine + 1, column, field ); |
630 | ++row; | 634 | ++row; |
631 | field = ""; | 635 | field = ""; |
632 | } | 636 | } |
633 | 637 | ||
634 | adjustRows( row - mStartLine ); | 638 | adjustRows( row - mStartLine ); |
635 | mTable->setNumCols( maxColumn ); | 639 | mTable->setNumCols( maxColumn ); |
636 | 640 | ||
637 | //US begin | 641 | //US begin |
638 | QStringList keys; | 642 | QStringList keys; |
639 | uint iii = 0, count = mTypeMap.count(); | 643 | uint iii = 0, count = mTypeMap.count(); |
640 | while ( iii < count ) { | 644 | while ( iii < count ) { |
641 | keys << "dummy"; | 645 | keys << "dummy"; |
642 | ++iii; | 646 | ++iii; |
643 | } | 647 | } |
644 | QMap<QString, uint>::ConstIterator it; | 648 | QMap<QString, uint>::ConstIterator it; |
645 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) | 649 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it) |
646 | keys[( it.data() )] = it.key(); | 650 | keys[( it.data() )] = it.key(); |
647 | //US end | 651 | //US end |
648 | 652 | ||
649 | for ( column = 0; column < mTable->numCols(); ++column ) { | 653 | for ( column = 0; column < mTable->numCols(); ++column ) { |
650 | 654 | ||
651 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); | 655 | //US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() ); |
652 | QComboTableItem *item = new QComboTableItem( mTable, keys ); | 656 | Q3ComboTableItem *item = new Q3ComboTableItem( mTable, keys ); |
653 | mTable->setItem( 0, column, item ); | 657 | mTable->setItem( 0, column, item ); |
654 | if ( column < mTypeStore.count() ) | 658 | if ( column < mTypeStore.count() ) |
655 | item->setCurrentItem( mTypeStore[ column ] ); | 659 | item->setCurrentItem( mTypeStore[ column ] ); |
656 | else | 660 | else |
657 | item->setCurrentItem( typeToPos( Undefined ) ); | 661 | item->setCurrentItem( typeToPos( Undefined ) ); |
658 | 662 | ||
659 | mTable->adjustColumn( column ); | 663 | mTable->adjustColumn( column ); |
660 | } | 664 | } |
661 | } | 665 | } |
662 | 666 | ||
663 | void CSVImportDialog::clearTable() | 667 | void CSVImportDialog::clearTable() |
664 | { | 668 | { |
665 | for ( int row = 0; row < mTable->numRows(); ++row ) | 669 | for ( int row = 0; row < mTable->numRows(); ++row ) |
666 | for ( int column = 0; column < mTable->numCols(); ++column ) | 670 | for ( int column = 0; column < mTable->numCols(); ++column ) |
667 | mTable->clearCell( row, column ); | 671 | mTable->clearCell( row, column ); |
668 | } | 672 | } |
669 | 673 | ||
670 | void CSVImportDialog::fillComboBox() | 674 | void CSVImportDialog::fillComboBox() |
671 | { | 675 | { |
672 | mComboLine->clear(); | 676 | mComboLine->clear(); |
673 | for ( int row = 1; row < mTable->numRows() + 1; ++row ) | 677 | for ( int row = 1; row < mTable->numRows() + 1; ++row ) |
674 | mComboLine->insertItem( QString::number( row ), row - 1 ); | 678 | mComboLine->insertItem( QString::number( row ), row - 1 ); |
675 | } | 679 | } |
676 | 680 | ||
677 | void CSVImportDialog::setText( int row, int col, const QString& text ) | 681 | void CSVImportDialog::setText( int row, int col, const QString& text ) |
678 | { | 682 | { |
679 | if ( row < 1 ) // skipped by the user | 683 | if ( row < 1 ) // skipped by the user |
680 | return; | 684 | return; |
681 | 685 | ||
682 | if ( mTable->numRows() < row ) { | 686 | if ( mTable->numRows() < row ) { |
683 | mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations | 687 | mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations |
684 | mAdjustRows = true; | 688 | mAdjustRows = true; |
@@ -735,65 +739,65 @@ void CSVImportDialog::delimiterClicked( int id ) | |||
735 | case 3: // space | 739 | case 3: // space |
736 | mDelimiter = " "; | 740 | mDelimiter = " "; |
737 | break; | 741 | break; |
738 | case 1: // semicolon | 742 | case 1: // semicolon |
739 | mDelimiter = ";"; | 743 | mDelimiter = ";"; |
740 | break; | 744 | break; |
741 | } | 745 | } |
742 | 746 | ||
743 | fillTable(); | 747 | fillTable(); |
744 | } | 748 | } |
745 | 749 | ||
746 | void CSVImportDialog::textquoteSelected( const QString& mark ) | 750 | void CSVImportDialog::textquoteSelected( const QString& mark ) |
747 | { | 751 | { |
748 | if ( mComboQuote->currentItem() == 2 ) | 752 | if ( mComboQuote->currentItem() == 2 ) |
749 | mTextQuote = 0; | 753 | mTextQuote = 0; |
750 | else | 754 | else |
751 | mTextQuote = mark[ 0 ]; | 755 | mTextQuote = mark[ 0 ]; |
752 | 756 | ||
753 | fillTable(); | 757 | fillTable(); |
754 | } | 758 | } |
755 | 759 | ||
756 | void CSVImportDialog::lineSelected( const QString& line ) | 760 | void CSVImportDialog::lineSelected( const QString& line ) |
757 | { | 761 | { |
758 | mStartLine = line.toInt() - 1; | 762 | mStartLine = line.toInt() - 1; |
759 | fillTable(); | 763 | fillTable(); |
760 | } | 764 | } |
761 | 765 | ||
762 | void CSVImportDialog::slotOk() | 766 | void CSVImportDialog::slotOk() |
763 | { | 767 | { |
764 | bool assigned = false; | 768 | bool assigned = false; |
765 | 769 | ||
766 | for ( int column = 0; column < mTable->numCols(); ++column ) { | 770 | for ( int column = 0; column < mTable->numCols(); ++column ) { |
767 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 771 | Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, |
768 | column ) ); | 772 | column ) ); |
769 | if ( item && posToType( item->currentItem() ) != Undefined ) | 773 | if ( item && posToType( item->currentItem() ) != Undefined ) |
770 | assigned = true; | 774 | assigned = true; |
771 | } | 775 | } |
772 | 776 | ||
773 | if ( assigned ) | 777 | if ( assigned ) |
774 | KDialogBase::slotOk(); | 778 | KDialogBase::slotOk(); |
775 | else | 779 | else |
776 | KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) ); | 780 | KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) ); |
777 | } | 781 | } |
778 | 782 | ||
779 | void CSVImportDialog::applyTemplate() | 783 | void CSVImportDialog::applyTemplate() |
780 | { | 784 | { |
781 | QMap<uint,int> columnMap; | 785 | QMap<uint,int> columnMap; |
782 | QMap<QString, QString> fileMap; | 786 | QMap<QString, QString> fileMap; |
783 | QStringList templates; | 787 | QStringList templates; |
784 | 788 | ||
785 | // load all template files | 789 | // load all template files |
786 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + | 790 | /*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) + |
787 | "/csv-templates/*.desktop", true, true ); | 791 | "/csv-templates/*.desktop", true, true ); |
788 | */ | 792 | */ |
789 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + | 793 | QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() + |
790 | "/csv-templates/*.desktop", true, true ); | 794 | "/csv-templates/*.desktop", true, true ); |
791 | 795 | ||
792 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 796 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
793 | { | 797 | { |
794 | 798 | ||
795 | //US KSimpleConfig config( *it, true ); | 799 | //US KSimpleConfig config( *it, true ); |
796 | KConfig config( *it ); | 800 | KConfig config( *it ); |
797 | 801 | ||
798 | if ( !config.hasGroup( "csv column map" ) ) | 802 | if ( !config.hasGroup( "csv column map" ) ) |
799 | continue; | 803 | continue; |
@@ -807,163 +811,163 @@ void CSVImportDialog::applyTemplate() | |||
807 | bool ok = false; | 811 | bool ok = false; |
808 | QString tmp; | 812 | QString tmp; |
809 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), | 813 | tmp = QInputDialog::getItem( i18n( "Template Selection" ), |
810 | i18n( "Please select a template\nthat matches the CSV file." ), | 814 | i18n( "Please select a template\nthat matches the CSV file." ), |
811 | templates, 0, false, &ok, this ); | 815 | templates, 0, false, &ok, this ); |
812 | 816 | ||
813 | if ( !ok ) | 817 | if ( !ok ) |
814 | return; | 818 | return; |
815 | 819 | ||
816 | //US KSimpleConfig config( fileMap[ tmp ], true ); | 820 | //US KSimpleConfig config( fileMap[ tmp ], true ); |
817 | KConfig config( fileMap[ tmp ] ); | 821 | KConfig config( fileMap[ tmp ] ); |
818 | config.setGroup( "General" ); | 822 | config.setGroup( "General" ); |
819 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); | 823 | //US uint numColumns = config.readUnsignedNumEntry( "Columns" ); |
820 | uint numColumns = (uint)config.readNumEntry( "Columns" ); | 824 | uint numColumns = (uint)config.readNumEntry( "Columns" ); |
821 | 825 | ||
822 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); | 826 | mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) ); |
823 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); | 827 | mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) ); |
824 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); | 828 | delimiterClicked( config.readNumEntry( "DelimiterType" ) ); |
825 | int quoteType = config.readNumEntry( "QuoteType" ); | 829 | int quoteType = config.readNumEntry( "QuoteType" ); |
826 | mComboQuote->setCurrentItem( quoteType ); | 830 | mComboQuote->setCurrentItem( quoteType ); |
827 | textquoteSelected( mComboQuote->currentText() ); | 831 | textquoteSelected( mComboQuote->currentText() ); |
828 | 832 | ||
829 | // create the column map | 833 | // create the column map |
830 | config.setGroup( "csv column map" ); | 834 | config.setGroup( "csv column map" ); |
831 | for ( uint i = 0; i < numColumns; ++i ) { | 835 | for ( uint i = 0; i < numColumns; ++i ) { |
832 | int col = config.readNumEntry( QString::number( i ) ); | 836 | int col = config.readNumEntry( QString::number( i ) ); |
833 | columnMap.insert( i, col ); | 837 | columnMap.insert( i, col ); |
834 | } | 838 | } |
835 | 839 | ||
836 | // apply the column map | 840 | // apply the column map |
837 | for ( uint column = 0; column < columnMap.count(); ++column ) { | 841 | for ( uint column = 0; column < columnMap.count(); ++column ) { |
838 | int type = columnMap[ column ]; | 842 | int type = columnMap[ column ]; |
839 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 843 | Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, |
840 | column ) ); | 844 | column ) ); |
841 | if ( item ) | 845 | if ( item ) |
842 | item->setCurrentItem( typeToPos( type ) ); | 846 | item->setCurrentItem( typeToPos( type ) ); |
843 | } | 847 | } |
844 | } | 848 | } |
845 | 849 | ||
846 | void CSVImportDialog::saveTemplate() | 850 | void CSVImportDialog::saveTemplate() |
847 | { | 851 | { |
848 | /*US | 852 | /*US |
849 | QString fileName = KFileDialog::getSaveFileName( | 853 | QString fileName = KFileDialog::getSaveFileName( |
850 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), | 854 | locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ), |
851 | "*.desktop", this ); | 855 | "*.desktop", this ); |
852 | */ | 856 | */ |
853 | QString fileName = KFileDialog::getSaveFileName( | 857 | QString fileName = KFileDialog::getSaveFileName( |
854 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ | 858 | locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+ |
855 | "*.desktop",i18n("Save file name") , this ); | 859 | "*.desktop",i18n("Save file name") , this ); |
856 | 860 | ||
857 | if ( fileName.isEmpty() ) | 861 | if ( fileName.isEmpty() ) |
858 | return; | 862 | return; |
859 | 863 | ||
860 | if ( !fileName.contains( ".desktop" ) ) | 864 | if ( !fileName.contains( ".desktop" ) ) |
861 | fileName += ".desktop"; | 865 | fileName += ".desktop"; |
862 | 866 | ||
863 | QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) ); | 867 | QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) ); |
864 | 868 | ||
865 | if ( name.isEmpty() ) | 869 | if ( name.isEmpty() ) |
866 | return; | 870 | return; |
867 | 871 | ||
868 | KConfig config( fileName ); | 872 | KConfig config( fileName ); |
869 | config.setGroup( "General" ); | 873 | config.setGroup( "General" ); |
870 | config.writeEntry( "Columns", mTable->numCols() ); | 874 | config.writeEntry( "Columns", mTable->numCols() ); |
871 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); | 875 | config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) ); |
872 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); | 876 | config.writeEntry( "DelimiterOther", mDelimiterEdit->text() ); |
873 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); | 877 | config.writeEntry( "QuoteType", mComboQuote->currentItem() ); |
874 | 878 | ||
875 | config.setGroup( "Misc" ); | 879 | config.setGroup( "Misc" ); |
876 | config.writeEntry( "Name", name ); | 880 | config.writeEntry( "Name", name ); |
877 | 881 | ||
878 | config.setGroup( "csv column map" ); | 882 | config.setGroup( "csv column map" ); |
879 | 883 | ||
880 | for ( uint column = 0; column < mTable->numCols(); ++column ) { | 884 | for ( uint column = 0; column < mTable->numCols(); ++column ) { |
881 | QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, | 885 | Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, |
882 | column ) ); | 886 | column ) ); |
883 | if ( item ) | 887 | if ( item ) |
884 | config.writeEntry( QString::number( column ), posToType( | 888 | config.writeEntry( QString::number( column ), posToType( |
885 | item->currentItem() ) ); | 889 | item->currentItem() ) ); |
886 | else | 890 | else |
887 | config.writeEntry( QString::number( column ), 0 ); | 891 | config.writeEntry( QString::number( column ), 0 ); |
888 | } | 892 | } |
889 | 893 | ||
890 | config.sync(); | 894 | config.sync(); |
891 | } | 895 | } |
892 | 896 | ||
893 | QString CSVImportDialog::getText( int row, int col ) | 897 | QString CSVImportDialog::getText( int row, int col ) |
894 | { | 898 | { |
895 | return mTable->text( row, col ); | 899 | return mTable->text( row, col ); |
896 | } | 900 | } |
897 | 901 | ||
898 | uint CSVImportDialog::posToType( int pos ) const | 902 | uint CSVImportDialog::posToType( int pos ) const |
899 | { | 903 | { |
900 | return pos; | 904 | return pos; |
901 | #if 0 | 905 | #if 0 |
902 | uint counter = 0; | 906 | uint counter = 0; |
903 | QMap<QString, uint>::ConstIterator it; | 907 | QMap<QString, uint>::ConstIterator it; |
904 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 908 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
905 | if ( counter == (uint)pos ) | 909 | if ( counter == (uint)pos ) |
906 | return it.data(); | 910 | return it.data(); |
907 | 911 | ||
908 | return 0; | 912 | return 0; |
909 | #endif | 913 | #endif |
910 | } | 914 | } |
911 | 915 | ||
912 | int CSVImportDialog::typeToPos( uint type ) const | 916 | int CSVImportDialog::typeToPos( uint type ) const |
913 | { | 917 | { |
914 | return type; | 918 | return type; |
915 | #if 0 | 919 | #if 0 |
916 | uint counter = 0; | 920 | uint counter = 0; |
917 | QMap<QString, uint>::ConstIterator it; | 921 | QMap<QString, uint>::ConstIterator it; |
918 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) | 922 | for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter ) |
919 | if ( it.data() == type ) | 923 | if ( it.data() == type ) |
920 | return counter; | 924 | return counter; |
921 | 925 | ||
922 | return -1; | 926 | return -1; |
923 | #endif | 927 | #endif |
924 | } | 928 | } |
925 | 929 | ||
926 | void CSVImportDialog::ignoreDuplicatesChanged( int ) | 930 | void CSVImportDialog::ignoreDuplicatesChanged( int ) |
927 | { | 931 | { |
928 | fillTable(); | 932 | fillTable(); |
929 | } | 933 | } |
930 | 934 | ||
931 | void CSVImportDialog::setFile( const QString &fileName ) | 935 | void CSVImportDialog::setFile( const QString &fileName ) |
932 | { | 936 | { |
933 | if ( fileName.isEmpty() ) | 937 | if ( fileName.isEmpty() ) |
934 | return; | 938 | return; |
935 | 939 | ||
936 | QFile file( fileName ); | 940 | QFile file( fileName ); |
937 | if ( !file.open( IO_ReadOnly ) ) { | 941 | if ( !file.open( QIODevice::ReadOnly ) ) { |
938 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); | 942 | KMessageBox::sorry( this, i18n( "Cannot open input file!" ) ); |
939 | file.close(); | 943 | file.close(); |
940 | return; | 944 | return; |
941 | } | 945 | } |
942 | 946 | ||
943 | mFileArray = file.readAll(); | 947 | mFileArray = file.readAll(); |
944 | file.close(); | 948 | file.close(); |
945 | 949 | ||
946 | mClearTypeStore = true; | 950 | mClearTypeStore = true; |
947 | clearTable(); | 951 | clearTable(); |
948 | mTable->setNumCols( 0 ); | 952 | mTable->setNumCols( 0 ); |
949 | mTable->setNumRows( 0 ); | 953 | mTable->setNumRows( 0 ); |
950 | fillTable(); | 954 | fillTable(); |
951 | mClearTypeStore = false; | 955 | mClearTypeStore = false; |
952 | 956 | ||
953 | fillComboBox(); | 957 | fillComboBox(); |
954 | } | 958 | } |
955 | 959 | ||
956 | void CSVImportDialog::urlChanged( const QString &file ) | 960 | void CSVImportDialog::urlChanged( const QString &file ) |
957 | { | 961 | { |
958 | bool state = !file.isEmpty(); | 962 | bool state = !file.isEmpty(); |
959 | 963 | ||
960 | enableButtonOK( state ); | 964 | enableButtonOK( state ); |
961 | 965 | ||
962 | findButton( User1 )->setEnabled( state ); | 966 | findButton( User1 )->setEnabled( state ); |
963 | findButton( User2 )->setEnabled( state ); | 967 | findButton( User2 )->setEnabled( state ); |
964 | 968 | ||
965 | } | 969 | } |
966 | 970 | ||
967 | #ifndef KAB_EMBEDDED | 971 | #ifndef KAB_EMBEDDED_ |
968 | #include <csvimportdialog.moc> | 972 | #include <moc_csvimportdialog.cpp> |
969 | #endif //KAB_EMBEDDED | 973 | #endif //KAB_EMBEDDED |