summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/xxport/csvimportdialog.cpp4
-rw-r--r--microkde/kresources/configpage.cpp6
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,417 +1,421 @@
/*
This file is part of KAddressBook.
Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
based on the code of KSpread's CSV Import Dialog
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
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 <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 <qlayout.h>
#include <qtextstream.h>
#include <qfile.h>
#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"
#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( '"' ),
mDelimiter( "," ),
mAddressBook( ab )
{
initGUI();
mTypeMap.insert( i18n( "Undefined" ), Undefined );
mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName );
mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName );
mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName );
mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName );
mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix );
mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix );
mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName );
mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday );
mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet );
mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(),
HomeAddressLocality );
mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion );
mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(),
HomeAddressPostalCode );
mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(),
HomeAddressCountry );
mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel );
mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(),
BusinessAddressStreet );
mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(),
BusinessAddressLocality );
mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(),
BusinessAddressRegion );
mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(),
BusinessAddressPostalCode );
mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(),
BusinessAddressCountry );
mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(),
BusinessAddressLabel );
mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone );
mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone );
mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone );
mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax );
mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax );
mTypeMap.insert( KABC::Addressee::carPhoneLabel(), CarPhone );
mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn );
mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager );
mTypeMap.insert( KABC::Addressee::emailLabel(), Email );
mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer );
mTypeMap.insert( KABC::Addressee::titleLabel(), Title );
mTypeMap.insert( KABC::Addressee::roleLabel(), Role );
mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization );
mTypeMap.insert( KABC::Addressee::noteLabel(), Note );
mTypeMap.insert( KABC::Addressee::urlLabel(), URL );
mCustomCounter = mTypeMap.count();
int count = mCustomCounter;
KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory );
KABC::Field::List::Iterator it;
for ( it = fields.begin(); it != fields.end(); ++it, ++count )
mTypeMap.insert( (*it)->label(), count );
connect( mDelimiterBox, SIGNAL( clicked( int ) ),
this, SLOT( delimiterClicked( int ) ) );
connect( mDelimiterEdit, SIGNAL( returnPressed() ),
this, SLOT( returnPressed() ) );
connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ),
this, SLOT( textChanged ( const QString& ) ) );
connect( mComboLine, SIGNAL( activated( const QString& ) ),
this, SLOT( lineSelected( const QString& ) ) );
connect( mComboQuote, SIGNAL( activated( const QString& ) ),
this, SLOT( textquoteSelected( const QString& ) ) );
connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ),
this, SLOT( ignoreDuplicatesChanged( int ) ) );
connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ),
this, SLOT( setFile( const QString& ) ) );
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");
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 ) );
if ( !item ) {
qDebug( "ERROR: item cast failed" );
continue;
}
QString value = mTable->text( row, col );
if ( !value.isEmpty() )
emptyRow = false;
switch ( posToType( item->currentItem() ) )
{
case Undefined:
continue;
break;
case FormattedName:
a.setFormattedName( value );
break;
case GivenName:
a.setGivenName( value );
break;
case FamilyName:
a.setFamilyName( value );
break;
case AdditionalName:
a.setAdditionalName( value );
break;
case Prefix:
a.setPrefix( value );
break;
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);
}
break;
case Email:
if ( !value.isEmpty() )
a.insertEmail( value, true );
break;
case Role:
a.setRole( value );
break;
case Title:
a.setTitle( value );
break;
case Mailer:
a.setMailer( value );
break;
case URL:
a.setUrl( value );
break;
case Organization:
a.setOrganization( value );
break;
case Note:
a.setNote( value );
break;
case HomePhone:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Home );
a.insertPhoneNumber( number );
}
break;
case BusinessPhone:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Work );
a.insertPhoneNumber( number );
}
break;
case MobilePhone:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell );
a.insertPhoneNumber( number );
}
break;
case HomeFax:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Home |
KABC::PhoneNumber::Fax );
a.insertPhoneNumber( number );
}
break;
case BusinessFax:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Work |
KABC::PhoneNumber::Fax );
a.insertPhoneNumber( number );
}
break;
case CarPhone:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Car );
a.insertPhoneNumber( number );
}
break;
case Isdn:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn );
a.insertPhoneNumber( number );
}
break;
case Pager:
if ( !value.isEmpty() ) {
KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager );
a.insertPhoneNumber( number );
}
break;
case HomeAddressStreet:
addrHome.setStreet( value );
break;
case HomeAddressLocality:
addrHome.setLocality( value );
break;
case HomeAddressRegion:
addrHome.setRegion( value );
break;
case HomeAddressPostalCode:
addrHome.setPostalCode( value );
break;
case HomeAddressCountry:
addrHome.setCountry( value );
break;
case HomeAddressLabel:
addrHome.setLabel( value );
break;
case BusinessAddressStreet:
addrWork.setStreet( value );
break;
case BusinessAddressLocality:
addrWork.setLocality( value );
break;
case BusinessAddressRegion:
addrWork.setRegion( value );
break;
case BusinessAddressPostalCode:
addrWork.setPostalCode( value );
break;
case BusinessAddressCountry:
addrWork.setCountry( value );
break;
case BusinessAddressLabel:
addrWork.setLabel( value );
break;
default:
KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory );
KABC::Field::List::Iterator it;
int counter = 0;
for ( it = fields.begin(); it != fields.end(); ++it ) {
if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) )
{
(*it)->setValue( a, value );
continue;
}
++counter;
}
break;
}
}
if ( !addrHome.isEmpty() )
a.insertAddress( addrHome );
if ( !addrWork.isEmpty() )
a.insertAddress( addrWork );
if ( !emptyRow && !a.isEmpty() )
contacts.append( a );
}
return contacts;
}
void CSVImportDialog::initGUI()
{
QWidget* page = plainPage();
QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(),
spacingHintSmall() );
QHBoxLayout *hbox = new QHBoxLayout();
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, 1 );
// Delimiter: comma, semicolon, tab, space, other
mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page );
mDelimiterBox->setColumnLayout( 0, Qt::Vertical );
mDelimiterBox->layout()->setSpacing( spacingHint() );
mDelimiterBox->layout()->setMargin( marginHint() );
QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() );
delimiterLayout->setAlignment( Qt::AlignTop );
layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 );
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 );
mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox );
delimiterLayout->addWidget( mRadioSpace, 1, 1 );
mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox );
delimiterLayout->addWidget( mRadioOther, 0, 2 );
mDelimiterEdit = new QLineEdit( mDelimiterBox );
delimiterLayout->addWidget( mDelimiterEdit, 1, 2 );
mComboLine = new QComboBox( false, page );
mComboLine->insertItem( i18n( "1" ) );
layout->addWidget( mComboLine, 3, 1 );
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,419 +1,423 @@
/*
This file is part of libkresources.
Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
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 <qgroupbox.h>
+
+#ifdef DESKTOP_VERSION
#include <qinputdialog.h>
+#else
+#include <qtcompat/qinputdialog.h>
+#endif
#include <qlabel.h>
#include <qlayout.h>
-
#include <kapplication.h>
#include <kcombobox.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <ksimpleconfig.h>
#include <kstandarddirs.h>
#include <kurlrequester.h>
#include <klistview.h>
#include <kbuttonbox.h>
//US #include <ktrader.h>
#include "resource.h"
#include "configdialog.h"
#include "configpage.h"
//US
#include <qpushbutton.h>
#include <qfile.h>
#include <kglobal.h>
using namespace KRES;
class ConfigViewItem : public QCheckListItem
{
public:
ConfigViewItem( QListView *parent, Resource* resource ) :
QCheckListItem( parent, resource->resourceName(), CheckBox ),
mResource( resource ),
mIsStandard( false )
{
setText( 1, mResource->type() );
setOn( mResource->isActive() );
}
void setStandard( bool value )
{
setText( 2, ( value ? i18n( "Yes" ) : QString::null ) );
mIsStandard = value;
}
bool standard() const { return mIsStandard; }
bool readOnly() const { return mResource->readOnly(); }
Resource *resource() { return mResource; }
private:
Resource* mResource;
bool mIsStandard;
};
ConfigPage::ConfigPage( QWidget *parent, const char *name )
: QWidget( parent, name ),
mCurrentManager( 0 ),
mCurrentConfig( 0 )
{
setCaption( i18n( "Resource Configuration" ) );
QVBoxLayout *mainLayout = new QVBoxLayout( this );
QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this );
groupBox->setColumnLayout(0, Qt::Vertical );
groupBox->layout()->setSpacing( 3 );
groupBox->layout()->setMargin( 5 );
QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 );
//US mFamilyCombo = new KComboBox( false, groupBox );
mFamilyCombo = new KComboBox( groupBox );
groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 );
mListView = new KListView( groupBox );
mListView->setAllColumnsShowFocus( true );
mListView->addColumn( i18n( "Name" ) );
mListView->addColumn( i18n( "Type" ) );
mListView->addColumn( i18n( "Standard" ) );
//US groupBoxLayout->addWidget( mListView, 1, 0 );
groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 );
mAddButton = new QPushButton( i18n( "&Add..." ), groupBox );
groupBoxLayout->addWidget( mAddButton, 2, 0 );
mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox );
groupBoxLayout->addWidget( mRemoveButton, 2, 1 );
mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox );
groupBoxLayout->addWidget( mEditButton, 3, 0 );
mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox );
groupBoxLayout->addWidget( mStandardButton, 3, 1 );
mRemoveButton->setEnabled( false );
mEditButton->setEnabled( false );
mStandardButton->setEnabled( false );
connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) );
connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) );
connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) );
connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) );
mainLayout->addWidget( groupBox );
connect( mFamilyCombo, SIGNAL( activated( int ) ),
SLOT( slotFamilyChanged( int ) ) );
connect( mListView, SIGNAL( selectionChanged() ),
SLOT( slotSelectionChanged() ) );
connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
SLOT( slotItemClicked( QListViewItem * ) ) );
mLastItem = 0;
//US mConfig = new KConfig( "kcmkresourcesrc" );
mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") );
mConfig->setGroup( "General" );
load();
}
ConfigPage::~ConfigPage()
{
QValueList<ResourcePageInfo>::Iterator it;
for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) {
(*it).mManager->removeListener( this );
delete (*it).mManager;
delete (*it).mConfig;
}
mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() );
delete mConfig;
mConfig = 0;
}
void ConfigPage::load()
{
kdDebug(5650) << "ConfigPage::load()" << endl;
mListView->clear();
//US we remove the dynamic pluginloader, and set the one family we need (contact) manually.
//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" );
//US KTrader::OfferList::ConstIterator it;
//US for ( it = plugins.begin(); it != plugins.end(); ++it ) {
//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" );
//US QString family = tmp.toString();
QStringList families;
families << "contact";
for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it )
{
QString family = (*it);
if ( !family.isEmpty() ) {
if ( !mFamilyMap.contains( family ) ) {
mCurrentManager = new Manager<Resource>( family );
if ( mCurrentManager ) {
mFamilyMap.append( family );
mCurrentManager->addListener( this );
ResourcePageInfo info;
info.mManager = mCurrentManager;
QString configDir = KGlobal::dirs()->saveLocation( "config" );
//QString configDir = KStandardDirs::appDir() + "/config";
if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) {
info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) );
} else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) {
info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) );
} else {
QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) );
info.mConfig = new KConfig( configFile );
}
info.mManager->readConfig( info.mConfig );
mInfoMap.append( info );
}
}
}
}
mCurrentManager = 0;
mFamilyCombo->insertStringList( mFamilyMap );
int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 );
mFamilyCombo->setCurrentItem( currentFamily );
slotFamilyChanged( currentFamily );
}
void ConfigPage::save()
{
saveResourceSettings();
QValueList<ResourcePageInfo>::Iterator it;
for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it )
(*it).mManager->writeConfig( (*it).mConfig );
emit changed( false );
}
void ConfigPage::defaults()
{
}
void ConfigPage::slotFamilyChanged( int pos )
{
if ( pos < 0 || pos >= (int)mFamilyMap.count() )
return;
saveResourceSettings();
mFamily = mFamilyMap[ pos ];
//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1());
mCurrentManager = mInfoMap[ pos ].mManager;
mCurrentConfig = mInfoMap[ pos ].mConfig;
if ( !mCurrentManager )
kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl;
mListView->clear();
if ( mCurrentManager->isEmpty() ) {
//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager );
defaults();
}
Resource *standardResource = mCurrentManager->standardResource();
//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1());
Manager<Resource>::Iterator it;
for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) {
ConfigViewItem *item = new ConfigViewItem( mListView, *it );
if ( *it == standardResource )
item->setStandard( true );
}
if ( mListView->childCount() == 0 ) {
//US qDebug("ConfigPage::slotFamilyChanged 4.5 ");
defaults();
emit changed( true );
mCurrentManager->writeConfig( mCurrentConfig );
} else {
//US qDebug("ConfigPage::slotFamilyChanged 4.6 ");
if ( !standardResource ) {
KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) );
//US qDebug("ConfigPage::slotFamilyChanged 4.7" );
}
emit changed( false );
}
}
void ConfigPage::slotAdd()
{
if ( !mCurrentManager )
return;
QStringList types = mCurrentManager->resourceTypeNames();
QStringList descs = mCurrentManager->resourceTypeDescriptions();
bool ok = false;
QString desc;
desc = QInputDialog::getItem( i18n( "Resource Configuration" ),
i18n( "Select type of the new resource:" ), descs, 0,
false, &ok, this );
if ( !ok )
return;
QString type = types[ descs.findIndex( desc ) ];
// Create new resource
Resource *resource = mCurrentManager->createResource( type );
if ( !resource ) {
KMessageBox::error( this, i18n("Unable to create resource of type '%1'.")
.arg( type ) );
return;
}
resource->setResourceName( type + "-resource" );
ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
if ( dlg.exec() ) {
mCurrentManager->add( resource );
ConfigViewItem *item = new ConfigViewItem( mListView, resource );
mLastItem = item;
// if there are only read-only resources we'll set this resource
// as standard resource
if ( !resource->readOnly() ) {
bool onlyReadOnly = true;
QListViewItem *it = mListView->firstChild();
while ( it != 0 ) {
ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it );
if ( !confIt->readOnly() && confIt != item )
onlyReadOnly = false;
it = it->itemBelow();
}
if ( onlyReadOnly )
item->setStandard( true );
}
emit changed( true );
} else {
delete resource;
resource = 0;
}
}
void ConfigPage::slotRemove()
{
if ( !mCurrentManager )
return;
QListViewItem *item = mListView->currentItem();
ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item );
if ( !confItem )
return;
if ( confItem->standard() ) {
KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) );
return;
}
mCurrentManager->remove( confItem->resource() );
if ( item == mLastItem )
mLastItem = 0;
mListView->takeItem( item );
delete item;
emit changed( true );
}
void ConfigPage::slotEdit()
{
if ( !mCurrentManager )
return;
QListViewItem *item = mListView->currentItem();
ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
if ( !configItem )
return;
Resource *resource = configItem->resource();
ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
if ( dlg.exec() ) {
configItem->setText( 0, resource->resourceName() );
configItem->setText( 1, resource->type() );
if ( configItem->standard() && configItem->readOnly() ) {
KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) );
configItem->setStandard( false );
}
mCurrentManager->resourceChanged( resource );
emit changed( true );
}
}
void ConfigPage::slotStandard()
{
if ( !mCurrentManager )
return;