summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxport
authorzautrix <zautrix>2005-04-27 23:23:17 (UTC)
committer zautrix <zautrix>2005-04-27 23:23:17 (UTC)
commit1540fc9be514330c76c999562fcf3e6bc1e2ffbb (patch) (side-by-side diff)
treeade066f57be45f0d9783c0efa4e869fee337dd51 /kaddressbook/xxport
parent3978688cbe832e2b72c8048b96c9a7c43ce11bc9 (diff)
downloadkdepimpi-1540fc9be514330c76c999562fcf3e6bc1e2ffbb.zip
kdepimpi-1540fc9be514330c76c999562fcf3e6bc1e2ffbb.tar.gz
kdepimpi-1540fc9be514330c76c999562fcf3e6bc1e2ffbb.tar.bz2
csv fixes
Diffstat (limited to 'kaddressbook/xxport') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/csvimportdialog.cpp73
-rw-r--r--kaddressbook/xxport/csvimportdialog.h4
2 files changed, 61 insertions, 16 deletions
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp
index cc55a24..41e2612 100644
--- a/kaddressbook/xxport/csvimportdialog.cpp
+++ b/kaddressbook/xxport/csvimportdialog.cpp
@@ -122,6 +122,7 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization );
mTypeMap.insert( KABC::Addressee::noteLabel(), Note );
mTypeMap.insert( KABC::Addressee::urlLabel(), URL );
+ mTypeMap.insert( KABC::Addressee::categoryLabel(), Categories );
mCustomCounter = mTypeMap.count();
int count = mCustomCounter;
@@ -139,6 +140,8 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
this, SLOT( textChanged ( const QString& ) ) );
connect( mComboLine, SIGNAL( activated( const QString& ) ),
this, SLOT( lineSelected( const QString& ) ) );
+ connect( mComboCodec, SIGNAL( activated( const QString& ) ),
+ this, SLOT( codecChanged( const QString& ) ) );
connect( mComboQuote, SIGNAL( activated( const QString& ) ),
this, SLOT( textquoteSelected( const QString& ) ) );
connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ),
@@ -249,9 +252,15 @@ KABC::AddresseeList CSVImportDialog::contacts() const
a.setOrganization( value );
break;
case Note:
- a.setNote( value );
+ if ( a.note().isEmpty() )
+ a.setNote( value );
+ else {
+ a.setNote( a.note()+"\n"+value );
+ }
+ break;
+ case Categories:
+ a.insertCategory( value );
break;
-
case HomePhone:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Home );
@@ -385,7 +394,7 @@ void CSVImportDialog::initGUI()
mUrlRequester->setFilter( "*.csv" );
hbox->addWidget( mUrlRequester );
- layout->addMultiCellLayout( hbox, 0, 0, 0, 1 );
+ layout->addMultiCellLayout( hbox, 0, 0, 0, 2 );
// Delimiter: comma, semicolon, tab, space, other
mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page );
@@ -394,7 +403,7 @@ void CSVImportDialog::initGUI()
mDelimiterBox->layout()->setMargin( marginHint() );
QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() );
delimiterLayout->setAlignment( Qt::AlignTop );
- layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 );
+ layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 );
mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox );
mRadioComma->setChecked( true );
@@ -424,21 +433,27 @@ void CSVImportDialog::initGUI()
mComboQuote->insertItem( i18n( "'" ), 1 );
mComboQuote->insertItem( i18n( "None" ), 2 );
layout->addWidget( mComboQuote, 3, 0 );
-
+ mComboCodec = new QComboBox( false, page );
+ mComboCodec->insertItem( i18n( "UTF8" ), 0 );
+ mComboCodec->insertItem( i18n( "LATIN1" ), 1 );
+ mComboCodec->insertItem( i18n( "LOCALE" ), 2 );
+ layout->addWidget( mComboCodec, 3, 2 );
label = new QLabel( i18n( "Start at line:" ), page );
layout->addWidget( label, 2, 1 );
label = new QLabel( i18n( "Textquote:" ), page );
layout->addWidget( label, 2, 0 );
+ label = new QLabel( i18n( "Codec:" ), page );
+ layout->addWidget( label, 2, 2 );
mIgnoreDuplicates = new QCheckBox( page );
mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) );
- layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 1 );
+ layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 2 );
mTable = new QTable( 0, 0, page );
mTable->setSelectionMode( QTable::NoSelection );
//mTable->horizontalHeader()->hide();
- layout->addMultiCellWidget( mTable, 5, 5, 0, 1 );
+ layout->addMultiCellWidget( mTable, 5, 5, 0, 2 );
/*US
setButtonText( User1, i18n( "Apply Template" ) );
setButtonText( User2, i18n( "Save Template" ) );
@@ -450,7 +465,7 @@ void CSVImportDialog::initGUI()
findButton( User2 )->setEnabled( false );
#ifdef DESKTOP_VERSION
- resize( 500, 300 );
+ resize( 640, 480 );
#else
showMaximized();
#endif
@@ -483,10 +498,23 @@ void CSVImportDialog::fillTable()
clearTable();
row = column = 1;
- mData = QString( mFileArray );
+ if ( mComboCodec->currentItem () == 0 ) {
+ mData = QString::fromUtf8( mFileArray.data() );
+ } else if ( mComboCodec->currentItem () == 1 ) {
+ mData = QString::fromLatin1( mFileArray.data() );
+ } else {
+ mData = QString::fromLocal8Bit( mFileArray.data() );
+ }
QTextStream inputStream( mData, IO_ReadOnly );
- inputStream.setEncoding( QTextStream::Locale );
+
+ if ( mComboCodec->currentItem () == 0 ) {
+ inputStream.setEncoding( QTextStream::UnicodeUTF8 );
+ } else if ( mComboCodec->currentItem () == 1 ) {
+ inputStream.setEncoding( QTextStream::Latin1 );
+ } else {
+ inputStream.setEncoding( QTextStream::Locale );
+ }
int maxColumn = 0;
while ( !inputStream.atEnd() ) {
@@ -608,9 +636,14 @@ void CSVImportDialog::fillTable()
//US begin
QStringList keys;
+ uint iii = 0, count = mTypeMap.count();
+ while ( iii < count ) {
+ keys << "dummy";
+ ++iii;
+ }
QMap<QString, uint>::ConstIterator it;
for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it)
- keys << it.key();
+ keys[( it.data() )] = it.key();
//US end
for ( column = 0; column < mTable->numCols(); ++column ) {
@@ -682,6 +715,10 @@ void CSVImportDialog::textChanged ( const QString& )
mRadioOther->setChecked ( true );
delimiterClicked( 4 ); // other
}
+void CSVImportDialog::codecChanged ( const QString& )
+{
+ fillTable();
+}
void CSVImportDialog::delimiterClicked( int id )
{
@@ -754,7 +791,7 @@ void CSVImportDialog::applyTemplate()
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
{
- qDebug("for ");
+
//US KSimpleConfig config( *it, true );
KConfig config( *it );
@@ -765,12 +802,12 @@ void CSVImportDialog::applyTemplate()
templates.append( config.readEntry( "Name" ) );
fileMap.insert( config.readEntry( "Name" ), *it );
}
- qDebug("weiter ");
+
// let the user chose, what to take
bool ok = false;
QString tmp;
tmp = QInputDialog::getItem( i18n( "Template Selection" ),
- i18n( "Please select a template, that matches the CSV file." ),
+ i18n( "Please select a template\nthat matches the CSV file." ),
templates, 0, false, &ok, this );
if ( !ok )
@@ -820,7 +857,7 @@ void CSVImportDialog::saveTemplate()
if ( fileName.isEmpty() )
return;
- if ( !fileName.contains( ".desktop" ) )
+ if ( !fileName.contains( ".desktop" ) )
fileName += ".desktop";
QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) );
@@ -860,6 +897,8 @@ QString CSVImportDialog::getText( int row, int col )
uint CSVImportDialog::posToType( int pos ) const
{
+ return pos;
+#if 0
uint counter = 0;
QMap<QString, uint>::ConstIterator it;
for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter )
@@ -867,10 +906,13 @@ uint CSVImportDialog::posToType( int pos ) const
return it.data();
return 0;
+#endif
}
int CSVImportDialog::typeToPos( uint type ) const
{
+ return type;
+#if 0
uint counter = 0;
QMap<QString, uint>::ConstIterator it;
for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter )
@@ -878,6 +920,7 @@ int CSVImportDialog::typeToPos( uint type ) const
return counter;
return -1;
+#endif
}
void CSVImportDialog::ignoreDuplicatesChanged( int )
diff --git a/kaddressbook/xxport/csvimportdialog.h b/kaddressbook/xxport/csvimportdialog.h
index 545b5f9..5f55ab2 100644
--- a/kaddressbook/xxport/csvimportdialog.h
+++ b/kaddressbook/xxport/csvimportdialog.h
@@ -68,6 +68,7 @@ class CSVImportDialog : public KDialogBase
void ignoreDuplicatesChanged( int );
void setFile( const QString& );
void urlChanged( const QString& );
+ void codecChanged ( const QString& );
void applyTemplate();
void saveTemplate();
@@ -81,7 +82,7 @@ class CSVImportDialog : public KDialogBase
BusinessAddressPostalCode, BusinessAddressCountry,
BusinessAddressLabel,
HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone,
- Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL
+ Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL, Categories
};
QTable* mTable;
@@ -94,6 +95,7 @@ class CSVImportDialog : public KDialogBase
QLineEdit* mDelimiterEdit;
QComboBox* mComboLine;
QComboBox* mComboQuote;
+ QComboBox* mComboCodec;
QCheckBox* mIgnoreDuplicates;
KURLRequester* mUrlRequester;