summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxport/csvimportdialog.cpp
Side-by-side diff
Diffstat (limited to 'kaddressbook/xxport/csvimportdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/csvimportdialog.cpp66
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
@@ -18,54 +18,58 @@
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
-#include <qbuttongroup.h>
+#include <q3buttongroup.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#ifdef DESKTOP_VERSION
#include <qinputdialog.h>
#else
#include <qtcompat/qinputdialog.h>
#endif
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
-#include <qtable.h>
+#include <q3table.h>
#include <qlayout.h>
-#include <qtextstream.h>
+#include <q3textstream.h>
#include <qfile.h>
+//Added by qt3to4:
+#include <Q3HBoxLayout>
+#include <Q3ValueList>
+#include <Q3GridLayout>
#include <kapplication.h>
#include <kdebug.h>
#include <kdialogbase.h>
#include <kfiledialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <kglobal.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kurlrequester.h>
#ifdef DESKTOP_VERSION
-#include "qtable.h"
+#include "q3table.h"
#else
#include "qcombotableitem.h"
#endif
#include "csvimportdialog.h"
CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
const char * name )
: KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 |
User2, Ok, parent, name, true, true ),
mAdjustRows( false ),
mStartLine( 0 ),
mTextQuote( '"' ),
@@ -152,50 +156,50 @@ CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ),
this, SLOT( setFile( const QString& ) ) );
connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ),
this, SLOT( urlChanged( const QString& ) ) );
connect( this, SIGNAL( user1Clicked() ),
this, SLOT( applyTemplate() ) );
connect( this, SIGNAL( user2Clicked() ),
this, SLOT( saveTemplate() ) );
// if ( QApplication::desktop()->width() < 321 )
- QIconSet icon = SmallIcon("filesave");
+ QIcon icon = SmallIcon("filesave");
findButton( User2 )->setIconSet (icon ) ;
icon = SmallIcon("fileopen");
findButton( User1 )->setIconSet (icon ) ;
int wid = findButton( User2 )->sizeHint().height();
findButton( User2 )->setMaximumWidth( wid+4 );
findButton( User1 )->setMaximumWidth( wid+4 );
}
CSVImportDialog::~CSVImportDialog()
{
}
KABC::AddresseeList CSVImportDialog::contacts() const
{
KABC::AddresseeList contacts;
for ( int row = 1; row < mTable->numRows(); ++row ) {
KABC::Addressee a;
bool emptyRow = true;
KABC::Address addrHome( KABC::Address::Home );
KABC::Address addrWork( KABC::Address::Work );
for ( int col = 0; col < mTable->numCols(); ++col ) {
- QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) );
+ Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, col ) );
if ( !item ) {
qDebug( "ERROR: item cast failed" );
continue;
}
QString value = mTable->text( row, col );
if ( !value.isEmpty() )
emptyRow = false;
switch ( posToType( item->currentItem() ) )
{
@@ -220,25 +224,25 @@ KABC::AddresseeList CSVImportDialog::contacts() const
case Suffix:
a.setSuffix( value );
break;
case NickName:
a.setNickName( value );
break;
case Birthday:
//US
//the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) );
// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ?
{
QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate
- a.setBirthday(dt);
+ a.setBirthday(QDateTime(dt));
}
break;
case Email:
if ( !value.isEmpty() )
a.insertEmail( value, true );
break;
case Role:
a.setRole( value );
break;
case Title:
a.setTitle( value );
break;
@@ -373,44 +377,44 @@ KABC::AddresseeList CSVImportDialog::contacts() const
if ( !emptyRow && !a.isEmpty() )
contacts.append( a );
}
return contacts;
}
void CSVImportDialog::initGUI()
{
QWidget* page = plainPage();
- QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(),
+ Q3GridLayout *layout = new Q3GridLayout( page, 1, 1, marginHintSmall(),
spacingHintSmall() );
- QHBoxLayout *hbox = new QHBoxLayout();
+ Q3HBoxLayout *hbox = new Q3HBoxLayout();
hbox->setSpacing( spacingHint() );
QLabel *label = new QLabel( i18n( "File to import:" ), page );
hbox->addWidget( label );
mUrlRequester = new KURLRequester( page );
mUrlRequester->setFilter( "*.csv" );
hbox->addWidget( mUrlRequester );
layout->addMultiCellLayout( hbox, 0, 0, 0, 2 );
// Delimiter: comma, semicolon, tab, space, other
- mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page );
+ mDelimiterBox = new Q3ButtonGroup( i18n( "Delimiter" ), page );
mDelimiterBox->setColumnLayout( 0, Qt::Vertical );
mDelimiterBox->layout()->setSpacing( spacingHint() );
mDelimiterBox->layout()->setMargin( marginHint() );
- QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() );
+ Q3GridLayout *delimiterLayout = new Q3GridLayout( mDelimiterBox->layout() );
delimiterLayout->setAlignment( Qt::AlignTop );
layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 2 );
mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox );
mRadioComma->setChecked( true );
delimiterLayout->addWidget( mRadioComma, 0, 0 );
mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox );
delimiterLayout->addWidget( mRadioSemicolon, 0, 1 );
mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox );
delimiterLayout->addWidget( mRadioTab, 1, 0 );
@@ -441,26 +445,26 @@ void CSVImportDialog::initGUI()
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, 2 );
- mTable = new QTable( 0, 0, page );
- mTable->setSelectionMode( QTable::NoSelection );
+ mTable = new Q3Table( 0, 0, page );
+ mTable->setSelectionMode( Q3Table::NoSelection );
//mTable->horizontalHeader()->hide();
layout->addMultiCellWidget( mTable, 5, 5, 0, 2 );
/*US
setButtonText( User1, i18n( "Apply Template" ) );
setButtonText( User2, i18n( "Save Template" ) );
*/
enableButtonOK( false );
findButton( User1 )->setEnabled( false );
findButton( User2 )->setEnabled( false );
@@ -474,68 +478,68 @@ void CSVImportDialog::initGUI()
void CSVImportDialog::fillTable()
{
int row, column;
bool lastCharDelimiter = false;
bool ignoreDups = mIgnoreDuplicates->isChecked();
enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD,
S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START;
QChar x;
QString field = "";
// store previous assignment
- QValueList<int> mTypeOld = mTypeStore;
+ Q3ValueList<int> mTypeOld = mTypeStore;
mTypeStore.clear();
for ( column = 0; column < mTable->numCols(); ++column ) {
- QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) );
+ Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0, column ) );
if ( !item || mClearTypeStore )
mTypeStore.append( typeToPos( Undefined ) );
else if ( item )
mTypeStore.append( item->currentItem() );
}
clearTable();
row = column = 1;
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 );
+ Q3TextStream inputStream( mData, QIODevice::ReadOnly );
if ( mComboCodec->currentItem () == 0 ) {
- inputStream.setEncoding( QTextStream::UnicodeUTF8 );
+ inputStream.setEncoding( Q3TextStream::UnicodeUTF8 );
} else if ( mComboCodec->currentItem () == 1 ) {
- inputStream.setEncoding( QTextStream::Latin1 );
+ inputStream.setEncoding( Q3TextStream::Latin1 );
} else {
- inputStream.setEncoding( QTextStream::Locale );
+ inputStream.setEncoding( Q3TextStream::Locale );
}
int maxColumn = 0;
while ( !inputStream.atEnd() ) {
inputStream >> x; // read one char
if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly
switch ( state ) {
case S_START :
if ( x == mTextQuote ) {
state = S_QUOTED_FIELD;
- } else if ( x == mDelimiter ) {
+ } else if ( QString(x) == mDelimiter ) {
if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
++column;
lastCharDelimiter = true;
} else if ( x == '\n' ) {
++row;
column = 1;
} else {
field += x;
state = S_MAYBE_NORMAL_FIELD;
}
break;
case S_QUOTED_FIELD :
@@ -552,81 +556,81 @@ void CSVImportDialog::fillTable()
++column;
lastCharDelimiter = true;
}
state = S_START;
} else {
field += x;
}
break;
case S_MAYBE_END_OF_QUOTED_FIELD :
if ( x == mTextQuote ) {
field += x;
state = S_QUOTED_FIELD;
- } else if ( x == mDelimiter || x == '\n' ) {
+ } else if ( QString(x) == mDelimiter || x == '\n' ) {
setText( row - mStartLine + 1, column, field );
field = "";
if ( x == '\n' ) {
++row;
column = 1;
} else {
if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
++column;
lastCharDelimiter = true;
}
state = S_START;
} else {
state = S_END_OF_QUOTED_FIELD;
}
break;
case S_END_OF_QUOTED_FIELD :
- if ( x == mDelimiter || x == '\n' ) {
+ if ( QString(x) == mDelimiter || x == '\n' ) {
setText( row - mStartLine + 1, column, field );
field = "";
if ( x == '\n' ) {
++row;
column = 1;
} else {
if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
++column;
lastCharDelimiter = true;
}
state = S_START;
} else {
state = S_END_OF_QUOTED_FIELD;
}
break;
case S_MAYBE_NORMAL_FIELD :
if ( x == mTextQuote ) {
field = "";
state = S_QUOTED_FIELD;
break;
}
case S_NORMAL_FIELD :
- if ( x == mDelimiter || x == '\n' ) {
+ if ( QString(x) == mDelimiter || x == '\n' ) {
setText( row - mStartLine + 1, column, field );
field = "";
if ( x == '\n' ) {
++row;
column = 1;
} else {
if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
++column;
lastCharDelimiter = true;
}
state = S_START;
} else {
field += x;
}
}
- if ( x != mDelimiter )
+ if ( QString(x) != mDelimiter )
lastCharDelimiter = false;
if ( column > maxColumn )
maxColumn = column;
}
// file with only one line without '\n'
if ( field.length() > 0 ) {
setText( row - mStartLine + 1, column, field );
++row;
field = "";
}
@@ -640,25 +644,25 @@ void CSVImportDialog::fillTable()
while ( iii < count ) {
keys << "dummy";
++iii;
}
QMap<QString, uint>::ConstIterator it;
for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it)
keys[( it.data() )] = it.key();
//US end
for ( column = 0; column < mTable->numCols(); ++column ) {
//US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() );
- QComboTableItem *item = new QComboTableItem( mTable, keys );
+ Q3ComboTableItem *item = new Q3ComboTableItem( mTable, keys );
mTable->setItem( 0, column, item );
if ( column < mTypeStore.count() )
item->setCurrentItem( mTypeStore[ column ] );
else
item->setCurrentItem( typeToPos( Undefined ) );
mTable->adjustColumn( column );
}
}
void CSVImportDialog::clearTable()
{
@@ -755,25 +759,25 @@ void CSVImportDialog::textquoteSelected( const QString& mark )
void CSVImportDialog::lineSelected( const QString& line )
{
mStartLine = line.toInt() - 1;
fillTable();
}
void CSVImportDialog::slotOk()
{
bool assigned = false;
for ( int column = 0; column < mTable->numCols(); ++column ) {
- QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
+ Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0,
column ) );
if ( item && posToType( item->currentItem() ) != Undefined )
assigned = true;
}
if ( assigned )
KDialogBase::slotOk();
else
KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) );
}
void CSVImportDialog::applyTemplate()
@@ -827,25 +831,25 @@ void CSVImportDialog::applyTemplate()
textquoteSelected( mComboQuote->currentText() );
// create the column map
config.setGroup( "csv column map" );
for ( uint i = 0; i < numColumns; ++i ) {
int col = config.readNumEntry( QString::number( i ) );
columnMap.insert( i, col );
}
// apply the column map
for ( uint column = 0; column < columnMap.count(); ++column ) {
int type = columnMap[ column ];
- QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
+ Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0,
column ) );
if ( item )
item->setCurrentItem( typeToPos( type ) );
}
}
void CSVImportDialog::saveTemplate()
{
/*US
QString fileName = KFileDialog::getSaveFileName(
locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ),
"*.desktop", this );
@@ -869,25 +873,25 @@ void CSVImportDialog::saveTemplate()
config.setGroup( "General" );
config.writeEntry( "Columns", mTable->numCols() );
config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) );
config.writeEntry( "DelimiterOther", mDelimiterEdit->text() );
config.writeEntry( "QuoteType", mComboQuote->currentItem() );
config.setGroup( "Misc" );
config.writeEntry( "Name", name );
config.setGroup( "csv column map" );
for ( uint column = 0; column < mTable->numCols(); ++column ) {
- QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
+ Q3ComboTableItem *item = static_cast<Q3ComboTableItem*>( mTable->item( 0,
column ) );
if ( item )
config.writeEntry( QString::number( column ), posToType(
item->currentItem() ) );
else
config.writeEntry( QString::number( column ), 0 );
}
config.sync();
}
QString CSVImportDialog::getText( int row, int col )
@@ -925,25 +929,25 @@ int CSVImportDialog::typeToPos( uint type ) const
void CSVImportDialog::ignoreDuplicatesChanged( int )
{
fillTable();
}
void CSVImportDialog::setFile( const QString &fileName )
{
if ( fileName.isEmpty() )
return;
QFile file( fileName );
- if ( !file.open( IO_ReadOnly ) ) {
+ if ( !file.open( QIODevice::ReadOnly ) ) {
KMessageBox::sorry( this, i18n( "Cannot open input file!" ) );
file.close();
return;
}
mFileArray = file.readAll();
file.close();
mClearTypeStore = true;
clearTable();
mTable->setNumCols( 0 );
mTable->setNumRows( 0 );
@@ -955,15 +959,15 @@ void CSVImportDialog::setFile( const QString &fileName )
void CSVImportDialog::urlChanged( const QString &file )
{
bool state = !file.isEmpty();
enableButtonOK( state );
findButton( User1 )->setEnabled( state );
findButton( User2 )->setEnabled( state );
}
-#ifndef KAB_EMBEDDED
-#include <csvimportdialog.moc>
+#ifndef KAB_EMBEDDED_
+#include <moc_csvimportdialog.cpp>
#endif //KAB_EMBEDDED