From 64df902cf71a8ee258fb85f6be26248f399aa01f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 27 Jan 2013 01:05:15 -0600 Subject: Rename a number of libraries and executables to avoid conflicts with KDE4 --- libtdepim/CMakeLists.txt | 4 +- libtdepim/Makefile.am | 4 +- libtdepim/addresseeview.cpp | 4 +- libtdepim/cfgc/README | 2 +- libtdepim/cfgc/autoexample.cpp | 2 +- libtdepim/cfgc/example.cpp | 2 +- libtdepim/cfgc/exampleprefs_base.kcfgc | 2 +- libtdepim/completionordereditor.h | 2 +- libtdepim/csshelper.cpp | 2 +- libtdepim/groupwarejob.cpp | 2 +- libtdepim/groupwarejob.h | 2 +- libtdepim/kaccount.cpp | 2 +- libtdepim/kcmdesignerfields.cpp | 4 +- libtdepim/kconfigpropagator.cpp | 289 --------------- libtdepim/kconfigpropagator.h | 165 --------- libtdepim/kconfigwizard.cpp | 197 ----------- libtdepim/kconfigwizard.h | 110 ------ libtdepim/kfileio.cpp | 390 --------------------- libtdepim/kfileio.h | 105 ------ libtdepim/kfoldertree.cpp | 2 +- libtdepim/kimportdialog.cpp | 2 +- libtdepim/komposer/core/core.cpp | 2 +- libtdepim/komposer/core/komposerconfig.desktop | 2 +- libtdepim/komposer/core/settings.kcfgc | 2 +- .../komposer/plugins/default/defaulteditor.cpp | 2 +- libtdepim/kpimprefs.cpp | 2 +- libtdepim/kpimprefs.h | 2 +- libtdepim/kprefsdialog.cpp | 2 +- libtdepim/kprefsdialog.h | 4 +- libtdepim/kresourceprefs.h | 2 +- libtdepim/ldapclient.cpp | 2 +- libtdepim/ldapclient.h | 4 +- libtdepim/ldapsearchdialog.cpp | 2 +- libtdepim/recentaddresses.cpp | 2 +- libtdepim/tdeconfigpropagator.cpp | 289 +++++++++++++++ libtdepim/tdeconfigpropagator.h | 165 +++++++++ libtdepim/tdeconfigwizard.cpp | 197 +++++++++++ libtdepim/tdeconfigwizard.h | 110 ++++++ libtdepim/tdefileio.cpp | 390 +++++++++++++++++++++ libtdepim/tdefileio.h | 105 ++++++ libtdepim/tdepartsdesignerplugin/CMakeLists.txt | 2 +- libtdepim/tests/myconfig.kcfgc | 2 +- libtdepim/tests/testdistrlist.cpp | 4 +- libtdepim/tests/testwizard.cpp | 2 +- 44 files changed, 1295 insertions(+), 1295 deletions(-) delete mode 100644 libtdepim/kconfigpropagator.cpp delete mode 100644 libtdepim/kconfigpropagator.h delete mode 100644 libtdepim/kconfigwizard.cpp delete mode 100644 libtdepim/kconfigwizard.h delete mode 100644 libtdepim/kfileio.cpp delete mode 100644 libtdepim/kfileio.h create mode 100644 libtdepim/tdeconfigpropagator.cpp create mode 100644 libtdepim/tdeconfigpropagator.h create mode 100644 libtdepim/tdeconfigwizard.cpp create mode 100644 libtdepim/tdeconfigwizard.h create mode 100644 libtdepim/tdefileio.cpp create mode 100644 libtdepim/tdefileio.h (limited to 'libtdepim') diff --git a/libtdepim/CMakeLists.txt b/libtdepim/CMakeLists.txt index 84f57a93f..2c79e018b 100644 --- a/libtdepim/CMakeLists.txt +++ b/libtdepim/CMakeLists.txt @@ -79,10 +79,10 @@ tde_add_library( tdepim SHARED AUTOMOC kimportdialog.cpp kvcarddrag.cpp sidebarextension.cpp infoextension.cpp addressesdialog.cpp addresspicker.ui addresseeview.cpp maillistdrag.cpp interfaces/MailTransportServiceIface.skel - interfaces/AddressBookServiceIface.skel kconfigpropagator.cpp kconfigwizard.cpp + interfaces/AddressBookServiceIface.skel tdeconfigpropagator.cpp tdeconfigwizard.cpp weaver.cpp weaverextensions.cpp weaverlogger.cpp pluginloaderbase.cpp addresseelineedit.cpp addresseelineedit.skel kdatepickerpopup.cpp - kfileio.cpp clicklineedit.cpp configmanager.cpp collectingprocess.cpp + tdefileio.cpp clicklineedit.cpp configmanager.cpp collectingprocess.cpp ldapclient.cpp overlaywidget.cpp progressmanager.cpp progressdialog.cpp statusbarprogresswidget.cpp ssllabel.cpp completionordereditor.cpp resourceabc.cpp diffalgo.cpp addresseediffalgo.cpp calendardiffalgo.cpp diff --git a/libtdepim/Makefile.am b/libtdepim/Makefile.am index 24942c728..7b690c8b2 100644 --- a/libtdepim/Makefile.am +++ b/libtdepim/Makefile.am @@ -14,10 +14,10 @@ libtdepim_la_SOURCES = \ addressesdialog.cpp addresspicker.ui addresseeview.cpp \ maillistdrag.cpp MailTransportServiceIface.skel \ AddressBookServiceIface.skel \ - kconfigpropagator.cpp kconfigwizard.cpp \ + tdeconfigpropagator.cpp tdeconfigwizard.cpp \ weaver.cpp weaverextensions.cpp weaverlogger.cpp \ pluginloaderbase.cpp addresseelineedit.cpp addresseelineedit.skel \ - kdatepickerpopup.cpp kfileio.cpp \ + kdatepickerpopup.cpp tdefileio.cpp \ clicklineedit.cpp configmanager.cpp \ collectingprocess.cpp ldapclient.cpp \ overlaywidget.cpp progressmanager.cpp progressdialog.cpp \ diff --git a/libtdepim/addresseeview.cpp b/libtdepim/addresseeview.cpp index 559f01713..ef754e819 100644 --- a/libtdepim/addresseeview.cpp +++ b/libtdepim/addresseeview.cpp @@ -30,11 +30,11 @@ #include #include #include -#include +#include #include #include #include -#include +#include #include #include #include diff --git a/libtdepim/cfgc/README b/libtdepim/cfgc/README index 720ea2126..05dcdf354 100644 --- a/libtdepim/cfgc/README +++ b/libtdepim/cfgc/README @@ -1,5 +1,5 @@ This directory contains text and example code for automatic creation of -configuration dialogs based on TDEConfigSkeleton, kconfig_compiler and +configuration dialogs based on TDEConfigSkeleton, tdeconfig_compiler and KPrefsDialog. If you have questions or comments please contact Cornelius Schumacher diff --git a/libtdepim/cfgc/autoexample.cpp b/libtdepim/cfgc/autoexample.cpp index 595d195b8..8f5d08e8d 100644 --- a/libtdepim/cfgc/autoexample.cpp +++ b/libtdepim/cfgc/autoexample.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/libtdepim/cfgc/example.cpp b/libtdepim/cfgc/example.cpp index 28c093784..d3f068799 100644 --- a/libtdepim/cfgc/example.cpp +++ b/libtdepim/cfgc/example.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include diff --git a/libtdepim/cfgc/exampleprefs_base.kcfgc b/libtdepim/cfgc/exampleprefs_base.kcfgc index 36e5ed4e6..6cc9a9231 100644 --- a/libtdepim/cfgc/exampleprefs_base.kcfgc +++ b/libtdepim/cfgc/exampleprefs_base.kcfgc @@ -1,4 +1,4 @@ -# Code generation options for kconfig_compiler +# Code generation options for tdeconfig_compiler File=exampleprefs_base.kcfg ClassName=ExamplePrefsBase Singleton=true diff --git a/libtdepim/completionordereditor.h b/libtdepim/completionordereditor.h index a755d1734..e13ce3130 100644 --- a/libtdepim/completionordereditor.h +++ b/libtdepim/completionordereditor.h @@ -32,7 +32,7 @@ #define COMPLETIONORDEREDITOR_H #include -#include +#include class KPushButton; class KListView; diff --git a/libtdepim/csshelper.cpp b/libtdepim/csshelper.cpp index 3c0ba38d0..d2180e1a2 100644 --- a/libtdepim/csshelper.cpp +++ b/libtdepim/csshelper.cpp @@ -31,7 +31,7 @@ #include "csshelper.h" -#include +#include #include #include #include diff --git a/libtdepim/groupwarejob.cpp b/libtdepim/groupwarejob.cpp index 22c9b7aa4..bbe443fc0 100644 --- a/libtdepim/groupwarejob.cpp +++ b/libtdepim/groupwarejob.cpp @@ -21,7 +21,7 @@ #include "groupwarejob.h" -#include +#include #include using namespace TDEIO; diff --git a/libtdepim/groupwarejob.h b/libtdepim/groupwarejob.h index 2fc2069b0..17561b36f 100644 --- a/libtdepim/groupwarejob.h +++ b/libtdepim/groupwarejob.h @@ -21,7 +21,7 @@ #ifndef KIO_GROUPWAREJOB_H #define KIO_GROUPWAREJOB_H -#include +#include namespace TDEIO { diff --git a/libtdepim/kaccount.cpp b/libtdepim/kaccount.cpp index f8fd61cf4..86cf4cfca 100644 --- a/libtdepim/kaccount.cpp +++ b/libtdepim/kaccount.cpp @@ -32,7 +32,7 @@ #include "kaccount.h" -#include +#include KAccount::KAccount( const uint id, const TQString &name, const Type type ) : mId( id ), mName( name ), mType( type ) diff --git a/libtdepim/kcmdesignerfields.cpp b/libtdepim/kcmdesignerfields.cpp index bb870b11f..72613f158 100644 --- a/libtdepim/kcmdesignerfields.cpp +++ b/libtdepim/kcmdesignerfields.cpp @@ -44,10 +44,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include "kcmdesignerfields.h" diff --git a/libtdepim/kconfigpropagator.cpp b/libtdepim/kconfigpropagator.cpp deleted file mode 100644 index a231f9638..000000000 --- a/libtdepim/kconfigpropagator.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kconfigpropagator.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -TDEConfigPropagator::Change::~Change() -{ -} - -TDEConfigPropagator::ChangeConfig::ChangeConfig() - : TDEConfigPropagator::Change( i18n("Change Config Value") ), - hideValue( false ) -{ -} - -TQString TDEConfigPropagator::ChangeConfig::arg1() const -{ - return file + "/" + group + "/" + name; -} - -TQString TDEConfigPropagator::ChangeConfig::arg2() const -{ - if ( hideValue ) return "*"; - else return value; -} - -void TDEConfigPropagator::ChangeConfig::apply() -{ - TDEConfig cfg( file ); - cfg.setGroup( group ); - cfg.writeEntry( name, value ); - - cfg.sync(); -} - -TDEConfigPropagator::TDEConfigPropagator() - : mSkeleton( 0 ) -{ - init(); -} - -TDEConfigPropagator::TDEConfigPropagator( TDEConfigSkeleton *skeleton, - const TQString &kcfgFile ) - : mSkeleton( skeleton ), mKcfgFile( kcfgFile ) -{ - init(); - - readKcfgFile(); -} - -void TDEConfigPropagator::init() -{ - mChanges.setAutoDelete( true ); -} - -void TDEConfigPropagator::readKcfgFile() -{ - TQString filename = locate( "kcfg", mKcfgFile ); - if ( filename.isEmpty() ) { - kdError() << "Unable to find kcfg file '" << mKcfgFile << "'" << endl; - return; - } - - TQFile input( filename ); - TQDomDocument doc; - TQString errorMsg; - int errorRow; - int errorCol; - if ( !doc.setContent( &input, &errorMsg, &errorRow, &errorCol ) ) { - kdError() << "Parse error in " << mKcfgFile << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; - return; - } - - TQDomElement cfgElement = doc.documentElement(); - - if ( cfgElement.isNull() ) { - kdError() << "No document in kcfg file" << endl; - return; - } - - mRules.clear(); - - TQDomNode n; - for ( n = cfgElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { - TQDomElement e = n.toElement(); - - TQString tag = e.tagName(); - - if ( tag == "propagation" ) { - Rule rule = parsePropagation( e ); - mRules.append( rule ); - } else if ( tag == "condition" ) { - Condition condition = parseCondition( e ); - TQDomNode n2; - for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { - TQDomElement e2 = n2.toElement(); - if ( e2.tagName() == "propagation" ) { - Rule rule = parsePropagation( e2 ); - rule.condition = condition; - mRules.append( rule ); - } else { - kdError() << "Unknow tag: " << e2.tagName() << endl; - } - } - } - } -} - -TDEConfigPropagator::Rule TDEConfigPropagator::parsePropagation( const TQDomElement &e ) -{ - Rule r; - - TQString source = e.attribute( "source" ); - parseConfigEntryPath( source, r.sourceFile, r.sourceGroup, r.sourceEntry ); - - TQString target = e.attribute( "target" ); - parseConfigEntryPath( target, r.targetFile, r.targetGroup, r.targetEntry ); - - r.hideValue = e.hasAttribute( "hidevalue" ) && - e.attribute( "hidevalue" ) == "true"; - - return r; -} - -void TDEConfigPropagator::parseConfigEntryPath( const TQString &path, - TQString &file, - TQString &group, - TQString &entry ) -{ - TQStringList p = TQStringList::split( "/", path ); - - if ( p.count() != 3 ) { - kdError() << "Path has to be of form file/group/entry" << endl; - file = TQString(); - group = TQString(); - entry = TQString(); - return; - } - - file = p[ 0 ]; - group = p[ 1 ]; - entry = p[ 2 ]; - - return; -} - -TDEConfigPropagator::Condition TDEConfigPropagator::parseCondition( const TQDomElement &e ) -{ - Condition c; - - TQString key = e.attribute( "key" ); - - parseConfigEntryPath( key, c.file, c.group, c.key ); - - c.value = e.attribute( "value" ); - - c.isValid = true; - - return c; -} - -void TDEConfigPropagator::commit() -{ - updateChanges(); - - Change *c; - for( c = mChanges.first(); c; c = mChanges.next() ) { - c->apply(); - } -} - -TDEConfigSkeletonItem *TDEConfigPropagator::findItem( const TQString &group, - const TQString &name ) -{ -// kdDebug() << "TDEConfigPropagator::findItem()" << endl; - - if ( !mSkeleton ) return 0; - - TDEConfigSkeletonItem::List items = mSkeleton->items(); - TDEConfigSkeletonItem::List::ConstIterator it; - for( it = items.begin(); it != items.end(); ++it ) { -// kdDebug() << " Item: " << (*it)->name() << " Type: " -// << (*it)->property().typeName() << endl; - if ( (*it)->group() == group && (*it)->name() == name ) { - break; - } - } - if ( it == items.end() ) return 0; - else return *it; -} - -TQString TDEConfigPropagator::itemValueAsString( TDEConfigSkeletonItem *item ) -{ - TQVariant p = item->property(); - - if ( p.type() == TQVariant::Bool ) { - if ( p.toBool() ) return "true"; - else return "false"; - } - - return p.toString(); -} - -void TDEConfigPropagator::updateChanges() -{ - mChanges.clear(); - - Rule::List::ConstIterator it; - for( it = mRules.begin(); it != mRules.end(); ++it ) { - Rule r = *it; - Condition c = r.condition; - if ( c.isValid ) { - TDEConfigSkeletonItem *item = findItem( c.group, c.key ); - kdDebug() << "Item " << c.group << "/" << c.key << ":" << endl; - if ( !item ) { - kdError() << " Item not found." << endl; - } else { - TQString value = itemValueAsString( item ); - kdDebug() << " Value: " << value << endl; - if ( value != c.value ) { - continue; - } - } - } - - TDEConfigSkeletonItem *item = findItem( r.sourceGroup, r.sourceEntry ); - if ( !item ) { - kdError() << "Item " << r.sourceGroup << "/" << r.sourceEntry - << " not found." << endl; - continue; - } - TQString value = itemValueAsString( item ); - - TDEConfig target( r.targetFile ); - target.setGroup( r.targetGroup ); - TQString targetValue = target.readEntry( r.targetEntry ); - if ( r.hideValue ) targetValue = KStringHandler::obscure( targetValue ); - if ( targetValue != value ) { - ChangeConfig *change = new ChangeConfig(); - change->file = r.targetFile; - change->group = r.targetGroup; - change->name = r.targetEntry; - if ( r.hideValue ) value = KStringHandler::obscure( value ); - change->value = value; - change->hideValue = r.hideValue; - mChanges.append( change ); - } - } - - addCustomChanges( mChanges ); -} - -TDEConfigPropagator::Change::List TDEConfigPropagator::changes() -{ - return mChanges; -} - -TDEConfigPropagator::Rule::List TDEConfigPropagator::rules() -{ - return mRules; -} diff --git a/libtdepim/kconfigpropagator.h b/libtdepim/kconfigpropagator.h deleted file mode 100644 index 92f9565f2..000000000 --- a/libtdepim/kconfigpropagator.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KCONFIGPROPAGATOR_H -#define KCONFIGPROPAGATOR_H - -#include -#include -#include -#include - -#include - -class TDEConfigSkeleton; -class TDEConfigSkeletonItem; - -class KDE_EXPORT TDEConfigPropagator -{ - public: - - /** - Create TDEConfigPropagator object without associated source configuration. - */ - TDEConfigPropagator(); - /** - Create TDEConfigPropagator object. - - @param skeleton TDEConfigSkeleton object used as source for the propagation - @param kcfgFile file name of kcfg file containing the propagation rules - */ - TDEConfigPropagator( TDEConfigSkeleton *skeleton, const TQString &kcfgFile ); - virtual ~TDEConfigPropagator() {} - - TDEConfigSkeleton *skeleton() { return mSkeleton; } - - /* - Commit changes according to propagation rules. - */ - void commit(); - - class KDE_EXPORT Condition - { - public: - Condition() : isValid( false ) {} - - TQString file; - TQString group; - TQString key; - TQString value; - - bool isValid; - }; - - class KDE_EXPORT Rule - { - public: - typedef TQValueList List; - - Rule() : hideValue( false ) {} - - TQString sourceFile; - TQString sourceGroup; - TQString sourceEntry; - - TQString targetFile; - TQString targetGroup; - TQString targetEntry; - - Condition condition; - - bool hideValue; - }; - - class KDE_EXPORT Change - { - public: - typedef TQPtrList List; - - Change( const TQString &title ) : mTitle( title ) {} - virtual ~Change(); - - void setTitle( const TQString &title ) { mTitle = title; } - TQString title() const { return mTitle; } - - virtual TQString arg1() const { return TQString(); } - virtual TQString arg2() const { return TQString(); } - - virtual void apply() = 0; - - private: - TQString mTitle; - }; - - class KDE_EXPORT ChangeConfig : public Change - { - public: - ChangeConfig(); - ~ChangeConfig() {} - - TQString arg1() const; - TQString arg2() const; - - void apply(); - - TQString file; - TQString group; - TQString name; - TQString label; - TQString value; - bool hideValue; - }; - - void updateChanges(); - - Change::List changes(); - - Rule::List rules(); - - protected: - void init(); - - /** - Implement this function in a subclass if you want to add changes which - can't be expressed as propagations in the kcfg file. - */ - virtual void addCustomChanges( Change::List & ) {} - - TDEConfigSkeletonItem *findItem( const TQString &group, const TQString &name ); - - TQString itemValueAsString( TDEConfigSkeletonItem * ); - - void readKcfgFile(); - - Rule parsePropagation( const TQDomElement &e ); - Condition parseCondition( const TQDomElement &e ); - - void parseConfigEntryPath( const TQString &path, TQString &file, - TQString &group, TQString &entry ); - - private: - TDEConfigSkeleton *mSkeleton; - TQString mKcfgFile; - - Rule::List mRules; - Change::List mChanges; -}; - -#endif diff --git a/libtdepim/kconfigwizard.cpp b/libtdepim/kconfigwizard.cpp deleted file mode 100644 index c2baafcc7..000000000 --- a/libtdepim/kconfigwizard.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kconfigwizard.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -TDEConfigWizard::TDEConfigWizard( TQWidget *parent, - char *name, bool modal ) - : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, - name, modal ), - mPropagator( 0 ), mChangesPage( 0 ) -{ - init(); -} - -TDEConfigWizard::TDEConfigWizard( TDEConfigPropagator *propagator, TQWidget *parent, - char *name, bool modal ) - : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, - name, modal ), - mPropagator( propagator ), mChangesPage( 0 ) -{ - init(); -} - -TDEConfigWizard::~TDEConfigWizard() -{ - delete mPropagator; -} - -void TDEConfigWizard::init() -{ - connect( this, TQT_SIGNAL( aboutToShowPage( TQWidget * ) ), - TQT_SLOT( slotAboutToShowPage( TQWidget * ) ) ); - - TQTimer::singleShot( 0, this, TQT_SLOT( readConfig() ) ); -} - -void TDEConfigWizard::setPropagator( TDEConfigPropagator *p ) -{ - mPropagator = p; -} - -void TDEConfigWizard::slotAboutToShowPage( TQWidget *page ) -{ - if ( page == mChangesPage ) { - updateChanges(); - } -} - -TQFrame *TDEConfigWizard::createWizardPage( const TQString &title ) -{ - return addPage( title ); -} - -void TDEConfigWizard::setupRulesPage() -{ - TQFrame *topFrame = addPage( i18n("Rules") ); - TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); - - mRuleView = new TQListView( topFrame ); - topLayout->addWidget( mRuleView ); - - mRuleView->addColumn( i18n("Source") ); - mRuleView->addColumn( i18n("Target") ); - mRuleView->addColumn( i18n("Condition") ); - - updateRules(); -} - -void TDEConfigWizard::updateRules() -{ - if ( !mPropagator ) { - kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl; - return; - } - - mRuleView->clear(); - - TDEConfigPropagator::Rule::List rules = mPropagator->rules(); - TDEConfigPropagator::Rule::List::ConstIterator it; - for( it = rules.begin(); it != rules.end(); ++it ) { - TDEConfigPropagator::Rule r = *it; - TQString source = r.sourceFile + "/" + r.sourceGroup + "/" + - r.sourceEntry; - TQString target = r.targetFile + "/" + r.targetGroup + "/" + - r.targetEntry; - TQString condition; - TDEConfigPropagator::Condition c = r.condition; - if ( c.isValid ) { - condition = c.file + "/" + c.group + "/" + c.key + " = " + c.value; - } - new TQListViewItem( mRuleView, source, target, condition ); - } -} - -void TDEConfigWizard::setupChangesPage() -{ - TQFrame *topFrame = addPage( i18n("Changes") ); - TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); - - mChangeView = new TQListView( topFrame ); - topLayout->addWidget( mChangeView ); - - mChangeView->addColumn( i18n("Action") ); - mChangeView->addColumn( i18n("Option") ); - mChangeView->addColumn( i18n("Value") ); - mChangeView->setSorting( -1 ); - - mChangesPage = topFrame; -} - -void TDEConfigWizard::updateChanges() -{ - kdDebug() << "TDEConfigWizard::updateChanges()" << endl; - - if ( !mPropagator ) { - kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl; - return; - } - - usrWriteConfig(); - - mPropagator->updateChanges(); - - mChangeView->clear(); - - TDEConfigPropagator::Change::List changes = mPropagator->changes(); - TDEConfigPropagator::Change *c; - for( c = changes.first(); c; c = changes.next() ) { - new TQListViewItem( mChangeView, mChangeView->lastItem(), c->title(), c->arg1(), c->arg2() ); - } -} - -void TDEConfigWizard::readConfig() -{ - kdDebug() << "TDEConfigWizard::readConfig()" << endl; - - int result = KMessageBox::warningContinueCancel( this, - i18n("Please make sure that the programs which are " - "configured by the wizard do not run in parallel to the wizard; " - "otherwise, changes done by the wizard could be lost."), - i18n("Warning"), i18n("Run Wizard Now"), "warning_running_instances" ); - if ( result != KMessageBox::Continue ) kapp->quit(); - - usrReadConfig(); -} - -void TDEConfigWizard::slotOk() -{ - TQString error = validate(); - if ( error.isNull() ) { - usrWriteConfig(); - - if ( !mPropagator ) { - kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl; - return; - } else { - if ( mPropagator->skeleton() ) { - mPropagator->skeleton()->writeConfig(); - } - mPropagator->commit(); - } - - accept(); - } else { - KMessageBox::sorry( this, error ); - } -} - -#include "kconfigwizard.moc" diff --git a/libtdepim/kconfigwizard.h b/libtdepim/kconfigwizard.h deleted file mode 100644 index a06849ecc..000000000 --- a/libtdepim/kconfigwizard.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - This file is part of libtdepim. - - Copyright (c) 2003 Cornelius Schumacher - - 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KCONFIGWIZARD_H -#define KCONFIGWIZARD_H - -#include -#include -#include - -class TQListView; - -/** - @short Configuration wizard base class -*/ -class KDE_EXPORT TDEConfigWizard : public KDialogBase -{ - Q_OBJECT - - public: - /** - Create wizard. You have to set a propgator with setPropagator() later. - */ - TDEConfigWizard( TQWidget *parent = 0, char *name = 0, bool modal = false ); - /** - Create wizard for given TDEConfigPropagator. The wizard takes ownership of - the propagator. - */ - TDEConfigWizard( TDEConfigPropagator *propagator, TQWidget *parent = 0, - char *name = 0, bool modal = false ); - /** - Destructor. - */ - virtual ~TDEConfigWizard(); - - /** - Set propagator the wizard operates on. - */ - void setPropagator( TDEConfigPropagator * ); - /** - Return propagator the wizard operates on. - */ - TDEConfigPropagator *propagator() { return mPropagator; } - - /** - Create wizard page with given title. - */ - TQFrame *createWizardPage( const TQString &title ); - - /** - Use this function to read the configuration from the TDEConfigSkeleton - object to the GUI. - */ - virtual void usrReadConfig() = 0; - - /** - This function is called when the wizard is finished. You have to save all - settings from the GUI to the TDEConfigSkeleton object here, so that the - TDEConfigPropagator can take them up from there. - */ - virtual void usrWriteConfig() = 0; - - /** - Validates the supplied data. Returns a appropiate error when some data - is invalid. Return TQString() if all data is valid. - */ - virtual TQString validate() { return TQString(); } - - protected slots: - void readConfig(); - - void slotOk(); - - void slotAboutToShowPage( TQWidget *page ); - - protected: - void init(); - - void setupRulesPage(); - void updateRules(); - void setupChangesPage(); - void updateChanges(); - - private: - TDEConfigPropagator *mPropagator; - - TQListView *mRuleView; - TQListView *mChangeView; - - TQWidget *mChangesPage; -}; - -#endif diff --git a/libtdepim/kfileio.cpp b/libtdepim/kfileio.cpp deleted file mode 100644 index fa963e167..000000000 --- a/libtdepim/kfileio.cpp +++ /dev/null @@ -1,390 +0,0 @@ -// kfileio.cpp -// Author: Stefan Taferner -// License: GPL - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace KPIM { - -//----------------------------------------------------------------------------- -static void msgDialog(const TQString &msg) -{ - KMessageBox::sorry(0, msg, i18n("File I/O Error")); -} - - -//----------------------------------------------------------------------------- -KDE_EXPORT TQCString kFileToString(const TQString &aFileName, bool aEnsureNL, bool aVerbose) -{ - TQCString result; - TQFileInfo info(aFileName); - unsigned int readLen; - unsigned int len = info.size(); - TQFile file(aFileName); - - //assert(aFileName!=0); - if( aFileName.isEmpty() ) - return ""; - - if (!info.exists()) - { - if (aVerbose) - msgDialog(i18n("The specified file does not exist:\n%1").arg(aFileName)); - return TQCString(); - } - if (info.isDir()) - { - if (aVerbose) - msgDialog(i18n("This is a folder and not a file:\n%1").arg(aFileName)); - return TQCString(); - } - if (!info.isReadable()) - { - if (aVerbose) - msgDialog(i18n("You do not have read permissions " - "to the file:\n%1").arg(aFileName)); - return TQCString(); - } - if (len <= 0) return TQCString(); - - if (!file.open(IO_Raw|IO_ReadOnly)) - { - if (aVerbose) switch(file.status()) - { - case IO_ReadError: - msgDialog(i18n("Could not read file:\n%1").arg(aFileName)); - break; - case IO_OpenError: - msgDialog(i18n("Could not open file:\n%1").arg(aFileName)); - break; - default: - msgDialog(i18n("Error while reading file:\n%1").arg(aFileName)); - } - return TQCString(); - } - - result.resize(len + (int)aEnsureNL + 1); - readLen = file.readBlock(result.data(), len); - if (aEnsureNL && result[len-1]!='\n') - { - result[len++] = '\n'; - readLen++; - } - result[len] = '\0'; - - if (readLen < len) - { - TQString msg = i18n("Could only read %1 bytes of %2.") - .arg(readLen).arg(len); - msgDialog(msg); - return TQCString(); - } - - return result; -} - -//----------------------------------------------------------------------------- -#if 0 // unused -TQByteArray kFileToBytes(const TQString &aFileName, bool aVerbose) -{ - TQByteArray result; - TQFileInfo info(aFileName); - unsigned int readLen; - unsigned int len = info.size(); - TQFile file(aFileName); - - //assert(aFileName!=0); - if( aFileName.isEmpty() ) - return result; - - if (!info.exists()) - { - if (aVerbose) - msgDialog(i18n("The specified file does not exist:\n%1") - .arg(aFileName)); - return result; - } - if (info.isDir()) - { - if (aVerbose) - msgDialog(i18n("This is a folder and not a file:\n%1") - .arg(aFileName)); - return result; - } - if (!info.isReadable()) - { - if (aVerbose) - msgDialog(i18n("You do not have read permissions " - "to the file:\n%1").arg(aFileName)); - return result; - } - if (len <= 0) return result; - - if (!file.open(IO_Raw|IO_ReadOnly)) - { - if (aVerbose) switch(file.status()) - { - case IO_ReadError: - msgDialog(i18n("Could not read file:\n%1").arg(aFileName)); - break; - case IO_OpenError: - msgDialog(i18n("Could not open file:\n%1").arg(aFileName)); - break; - default: - msgDialog(i18n("Error while reading file:\n%1").arg(aFileName)); - } - return result; - } - - result.resize(len); - readLen = file.readBlock(result.data(), len); - kdDebug(5300) << TQString( "len %1" ).arg(len) << endl; - - if (readLen < len) - { - TQString msg; - msg = i18n("Could only read %1 bytes of %2.") - .arg(readLen).arg(len); - msgDialog(msg); - return result; - } - - return result; -} -#endif - -//----------------------------------------------------------------------------- -KDE_EXPORT bool kBytesToFile(const char* aBuffer, int len, - const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) -{ - // TODO: use KSaveFile - TQFile file(aFileName); - int writeLen, rc; - - //assert(aFileName!=0); - if(aFileName.isEmpty()) - return FALSE; - - if (file.exists()) - { - if (aAskIfExists) - { - TQString str; - str = i18n("File %1 exists.\nDo you want to replace it?") - .arg(aFileName); - rc = KMessageBox::warningContinueCancel(0, - str, i18n("Save to File"), i18n("&Replace")); - if (rc != KMessageBox::Continue) return FALSE; - } - if (aBackup) - { - // make a backup copy - // TODO: use KSaveFile::backupFile() - TQString bakName = aFileName; - bakName += '~'; - TQFile::remove(bakName); - if( !TQDir::current().rename(aFileName, bakName) ) - { - // failed to rename file - if (!aVerbose) return FALSE; - rc = KMessageBox::warningContinueCancel(0, - i18n("Failed to make a backup copy of %1.\nContinue anyway?") - .arg(aFileName), - i18n("Save to File"), KStdGuiItem::save() ); - if (rc != KMessageBox::Continue) return FALSE; - } - } - } - - if (!file.open(IO_Raw|IO_WriteOnly|IO_Truncate)) - { - if (aVerbose) switch(file.status()) - { - case IO_WriteError: - msgDialog(i18n("Could not write to file:\n%1").arg(aFileName)); - break; - case IO_OpenError: - msgDialog(i18n("Could not open file for writing:\n%1") - .arg(aFileName)); - break; - default: - msgDialog(i18n("Error while writing file:\n%1").arg(aFileName)); - } - return FALSE; - } - - writeLen = file.writeBlock(aBuffer, len); - - if (writeLen < 0) - { - if (aVerbose) - msgDialog(i18n("Could not write to file:\n%1").arg(aFileName)); - return FALSE; - } - else if (writeLen < len) - { - TQString msg = i18n("Could only write %1 bytes of %2.") - .arg(writeLen).arg(len); - if (aVerbose) - msgDialog(msg); - return FALSE; - } - - return TRUE; -} - -KDE_EXPORT bool kCStringToFile(const TQCString& aBuffer, const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) -{ - return kBytesToFile(aBuffer, aBuffer.length(), aFileName, aAskIfExists, - aBackup, aVerbose); -} - -KDE_EXPORT bool kByteArrayToFile(const TQByteArray& aBuffer, const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) -{ - return kBytesToFile(aBuffer, aBuffer.size(), aFileName, aAskIfExists, - aBackup, aVerbose); -} - - -TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, - const bool recursive, const bool wantItReadable, - const bool wantItWritable ) -{ - // First we have to find out which type the toCheck is. This can be - // a directory (follow if recursive) or a file (check permissions). - // Symlinks are followed as expected. - TQFileInfo fiToCheck(toCheck); - fiToCheck.setCaching(false); - TQCString toCheckEnc = TQFile::encodeName(toCheck); - TQString error; - struct stat statbuffer; - - if ( !fiToCheck.exists() ) { - error.append( i18n("%1 does not exist") - .arg(toCheck) + "\n"); - } - - // check the access bit of a folder. - if ( fiToCheck.isDir() ) { - if ( stat( toCheckEnc,&statbuffer ) != 0 ) { - kdDebug() << "wantItA: Can't read perms of " << toCheck << endl; - } - TQDir g( toCheck ); - if ( !g.isReadable() ) { - if ( chmod( toCheckEnc, statbuffer.st_mode + S_IXUSR ) != 0 ) { - error.append( i18n("%1 is not accessible and that is " - "unchangeable.").arg(toCheck) + "\n"); - } else { - kdDebug() << "Changed access bit for " << toCheck << endl; - } - } - } - - // For each file or folder we can check if the file is readable - // and writable, as requested. - if ( fiToCheck.isFile() || fiToCheck.isDir() ) { - - if ( !fiToCheck.isReadable() && wantItReadable ) { - // Get the current permissions. No need to do anything with an - // error, it will het added to errors anyhow, later on. - if ( stat(toCheckEnc,&statbuffer) != 0 ) { - kdDebug() << "wantItR: Can't read perms of " << toCheck << endl; - } - - // Lets try changing it. - if ( chmod( toCheckEnc, statbuffer.st_mode + S_IRUSR ) != 0 ) { - error.append( i18n("%1 is not readable and that is unchangeable.") - .arg(toCheck) + "\n"); - } else { - kdDebug() << "Changed the read bit for " << toCheck << endl; - } - } - - if ( !fiToCheck.isWritable() && wantItWritable ) { - // Gets the current persmissions. Needed because it can be changed - // curing previous operation. - if (stat(toCheckEnc,&statbuffer) != 0) { - kdDebug() << "wantItW: Can't read perms of " << toCheck << endl; - } - - // Lets try changing it. - if ( chmod (toCheckEnc, statbuffer.st_mode + S_IWUSR ) != 0 ) { - error.append( i18n("%1 is not writable and that is unchangeable.") - .arg(toCheck) + "\n"); - } else { - kdDebug() << "Changed the write bit for " << toCheck << endl; - } - } - } - - // If it is a folder and recursive is true, then we check the contents of - // the folder. - if ( fiToCheck.isDir() && recursive ){ - TQDir g(toCheck); - // First check if the folder is readable for us. If not, we get - // some ugly crashes. - if ( !g.isReadable() ){ - error.append(i18n("Folder %1 is inaccessible.").arg(toCheck) + "\n"); - } else { - const TQFileInfoList *list = g.entryInfoList(); - TQFileInfoListIterator it( *list ); - TQFileInfo *fi; - while ((fi = it.current()) != 0) { - TQString newToCheck = toCheck + "/" + fi->fileName(); - TQFileInfo fiNewToCheck(newToCheck); - if ( fi->fileName() != "." && fi->fileName() != ".." ) { - error.append ( checkAndCorrectPermissionsIfPossible( newToCheck, - recursive, wantItReadable, wantItWritable) ); - } - ++it; - } - } - } - return error; -} - -bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, - const TQString &toCheck, const bool recursive, const bool wantItReadable, - const bool wantItWritable ) -{ - TQString error = checkAndCorrectPermissionsIfPossible(toCheck, recursive, - wantItReadable, wantItWritable); - // There is no KMessageBox with Retry, Cancel and Details. - // so, I can't provide a functionality to recheck. So it now - // it is just a warning. - if ( !error.isEmpty() ) { - kdDebug() << "checkPermissions found:" << error << endl; - KMessageBox::detailedSorry(parent, - i18n("Some files or folders do not have " - "the right permissions, please correct them " - "manually."), - error, i18n("Permissions Check"), false); - return false; - } else { - return true; - } -} - -} diff --git a/libtdepim/kfileio.h b/libtdepim/kfileio.h deleted file mode 100644 index 15db09338..000000000 --- a/libtdepim/kfileio.h +++ /dev/null @@ -1,105 +0,0 @@ -/* Load / save entire (local) files with nice diagnostics dialog messages. - * These functions load/save the whole buffer in one i/o call, so they - * should be pretty efficient. - * - * Author: Stefan Taferner - * This code is under GPL. - */ -#ifndef kpim_kfileio_h -#define kpim_kfileio_h - -#include -#include - -#include - -class TQString; - -namespace KPIM { - -/** Load a file. Returns a pointer to the memory-block that contains - * the loaded file. Returns a null string if the file could not be loaded. - * If withDialogs is FALSE no warning dialogs are opened if there are - * problems. - * The string returned is always zero-terminated and therefore one - * byte longer than the file itself. - * If ensureNewline is TRUE the string will always have a trailing newline. - */ -TQCString kFileToString(const TQString &fileName, bool ensureNewline=true, - bool withDialogs=true) KDE_EXPORT; - -// unused -//TQByteArray kFileToBytes(const TQString &fileName, bool withDialogs=true); - - -/** Save a file. If withDialogs is FALSE no warning dialogs are opened if - * there are problems. Returns TRUE on success and FALSE on failure. - * Replaces existing files without warning if askIfExists==FALSE. - * Makes a copy if the file exists to filename~ if createBackup==TRUE. - */ -bool kBytesToFile(const char* aBuffer, int len, - const TQString &aFileName, - bool aAskIfExists, bool aBackup, bool aVerbose) KDE_EXPORT; - -bool kCStringToFile(const TQCString& buffer, const TQString &fileName, - bool askIfExists=false, bool createBackup=true, - bool withDialogs=true) KDE_EXPORT; -/** Does not stop at NUL */ -KDE_EXPORT bool kByteArrayToFile(const TQByteArray& buffer, const TQString &fileName, - bool askIfExists=false, bool createBackup=true, - bool withDialogs=true) KDE_EXPORT; - - - /** - * Checks and corrects the permissions of a file or folder, and if requested - * all files and folders below. It gives back a list of files which do not - * have the right permissions. This list can be used to show to the user. - * - * @param toCheck The file or folder of which the permissions should - * be checked. - * @param recursive Set to true, it will check the contents of a folder - * for the permissions recursively. If false only - * toCheck will be checked. - * @param wantItReadable Set to true, it will check for read permissions. - * If the read permissions are not available, there will - * be a attempt to correct this. - * @param wantItWritable Set to true, it will check for write permissions. - * If the write permissions are not available, there - * will be a attempt to correct this. - * @return It will return a string with all files and folders which do not - * have the right permissions. If empty, then all permissions are ok. - */ -TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, - const bool recursive, const bool wantItReadable, - const bool wantItWritable ); - - /** - * Checks and corrects the permissions of a file or folder, and if requested - * all files and folders below. If the permissions are not ok, it tries to correct - * them. If that fails then a warning with detailled information is given. - * - * @param parent If parent is 0, then the message box becomes an - * application-global modal dialog box. If parent - * is a widget, the message box becomes modal - * relative to parent. - * @param toCheck The file or folder of which the permissions should - * be checked. - * @param recursive Set to true, it will check the contents of a folder - * for the permissions recursively. If false only - * toCheck will be checked. - * @param wantItReadable Set to true, it will check for read permissions. - * If the read permissions are not available, there will - * be a attempt to correct this. - * @param wantItWritable Set to true, it will check for write permissions. - * If the write permissions are not available, there - * will be a attempt to correct this. - * @return It will return true if all permissions in the end are ok. If false - * then the permissions are not ok and it was not possible to correct - * all errors. - */ -bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, - const TQString &toCheck, const bool recursive, const bool wantItReadable, - const bool wantItWritable ); -} - -#endif /*kpim_kfileio_h*/ diff --git a/libtdepim/kfoldertree.cpp b/libtdepim/kfoldertree.cpp index 5cad23656..58961ddc6 100644 --- a/libtdepim/kfoldertree.cpp +++ b/libtdepim/kfoldertree.cpp @@ -2,7 +2,7 @@ #include "kfoldertree.h" #include -#include +#include #include #include #include diff --git a/libtdepim/kimportdialog.cpp b/libtdepim/kimportdialog.cpp index e07ef00ac..df1181ed1 100644 --- a/libtdepim/kimportdialog.cpp +++ b/libtdepim/kimportdialog.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include "kimportdialog.h" #include "kimportdialog.moc" diff --git a/libtdepim/komposer/core/core.cpp b/libtdepim/komposer/core/core.cpp index 945c22311..a2f5fd003 100644 --- a/libtdepim/komposer/core/core.cpp +++ b/libtdepim/komposer/core/core.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libtdepim/komposer/core/komposerconfig.desktop b/libtdepim/komposer/core/komposerconfig.desktop index 5ceb12582..ab5239b08 100644 --- a/libtdepim/komposer/core/komposerconfig.desktop +++ b/libtdepim/komposer/core/komposerconfig.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Exec=kcmshell komposerconfig +Exec=tdecmshell komposerconfig Icon=komposer Type=Application Terminal=false diff --git a/libtdepim/komposer/core/settings.kcfgc b/libtdepim/komposer/core/settings.kcfgc index fc98478a9..a4c881006 100644 --- a/libtdepim/komposer/core/settings.kcfgc +++ b/libtdepim/komposer/core/settings.kcfgc @@ -1,4 +1,4 @@ -# Code generation options for kconfig_compiler +# Code generation options for tdeconfig_compiler File=komposer.kcfg NameSpace=Komposer ClassName=Config diff --git a/libtdepim/komposer/plugins/default/defaulteditor.cpp b/libtdepim/komposer/plugins/default/defaulteditor.cpp index 105650eb0..426e4c01b 100644 --- a/libtdepim/komposer/plugins/default/defaulteditor.cpp +++ b/libtdepim/komposer/plugins/default/defaulteditor.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include diff --git a/libtdepim/kpimprefs.cpp b/libtdepim/kpimprefs.cpp index 9ae04cfaf..02e397361 100644 --- a/libtdepim/kpimprefs.cpp +++ b/libtdepim/kpimprefs.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include diff --git a/libtdepim/kpimprefs.h b/libtdepim/kpimprefs.h index 051b0f2fb..dd180c970 100644 --- a/libtdepim/kpimprefs.h +++ b/libtdepim/kpimprefs.h @@ -23,7 +23,7 @@ #include -#include +#include #include class TQString; diff --git a/libtdepim/kprefsdialog.cpp b/libtdepim/kprefsdialog.cpp index 577692506..230962cb2 100644 --- a/libtdepim/kprefsdialog.cpp +++ b/libtdepim/kprefsdialog.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include "ktimeedit.h" #include "kdateedit.h" diff --git a/libtdepim/kprefsdialog.h b/libtdepim/kprefsdialog.h index 6774d96d7..3e331b180 100644 --- a/libtdepim/kprefsdialog.h +++ b/libtdepim/kprefsdialog.h @@ -30,8 +30,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/libtdepim/kresourceprefs.h b/libtdepim/kresourceprefs.h index 968d86a9e..1954f19c1 100644 --- a/libtdepim/kresourceprefs.h +++ b/libtdepim/kresourceprefs.h @@ -22,7 +22,7 @@ #ifndef KRESOURCEPREFS_H #define KRESOURCEPREFS_H -#include +#include #include class TQString; diff --git a/libtdepim/ldapclient.cpp b/libtdepim/ldapclient.cpp index 9f1a6fd8e..32202b3da 100644 --- a/libtdepim/ldapclient.cpp +++ b/libtdepim/ldapclient.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libtdepim/ldapclient.h b/libtdepim/ldapclient.h index 502937299..789b46054 100644 --- a/libtdepim/ldapclient.h +++ b/libtdepim/ldapclient.h @@ -31,9 +31,9 @@ #include #include -#include +#include #include -#include +#include #include diff --git a/libtdepim/ldapsearchdialog.cpp b/libtdepim/ldapsearchdialog.cpp index fe67137b1..586e9011d 100644 --- a/libtdepim/ldapsearchdialog.cpp +++ b/libtdepim/ldapsearchdialog.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libtdepim/recentaddresses.cpp b/libtdepim/recentaddresses.cpp index bbd7d29a9..eb4660a3b 100644 --- a/libtdepim/recentaddresses.cpp +++ b/libtdepim/recentaddresses.cpp @@ -31,7 +31,7 @@ #include "libemailfunctions/email.h" #include -#include +#include #include #include diff --git a/libtdepim/tdeconfigpropagator.cpp b/libtdepim/tdeconfigpropagator.cpp new file mode 100644 index 000000000..f6f482402 --- /dev/null +++ b/libtdepim/tdeconfigpropagator.cpp @@ -0,0 +1,289 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdeconfigpropagator.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +TDEConfigPropagator::Change::~Change() +{ +} + +TDEConfigPropagator::ChangeConfig::ChangeConfig() + : TDEConfigPropagator::Change( i18n("Change Config Value") ), + hideValue( false ) +{ +} + +TQString TDEConfigPropagator::ChangeConfig::arg1() const +{ + return file + "/" + group + "/" + name; +} + +TQString TDEConfigPropagator::ChangeConfig::arg2() const +{ + if ( hideValue ) return "*"; + else return value; +} + +void TDEConfigPropagator::ChangeConfig::apply() +{ + TDEConfig cfg( file ); + cfg.setGroup( group ); + cfg.writeEntry( name, value ); + + cfg.sync(); +} + +TDEConfigPropagator::TDEConfigPropagator() + : mSkeleton( 0 ) +{ + init(); +} + +TDEConfigPropagator::TDEConfigPropagator( TDEConfigSkeleton *skeleton, + const TQString &kcfgFile ) + : mSkeleton( skeleton ), mKcfgFile( kcfgFile ) +{ + init(); + + readKcfgFile(); +} + +void TDEConfigPropagator::init() +{ + mChanges.setAutoDelete( true ); +} + +void TDEConfigPropagator::readKcfgFile() +{ + TQString filename = locate( "kcfg", mKcfgFile ); + if ( filename.isEmpty() ) { + kdError() << "Unable to find kcfg file '" << mKcfgFile << "'" << endl; + return; + } + + TQFile input( filename ); + TQDomDocument doc; + TQString errorMsg; + int errorRow; + int errorCol; + if ( !doc.setContent( &input, &errorMsg, &errorRow, &errorCol ) ) { + kdError() << "Parse error in " << mKcfgFile << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; + return; + } + + TQDomElement cfgElement = doc.documentElement(); + + if ( cfgElement.isNull() ) { + kdError() << "No document in kcfg file" << endl; + return; + } + + mRules.clear(); + + TQDomNode n; + for ( n = cfgElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + TQDomElement e = n.toElement(); + + TQString tag = e.tagName(); + + if ( tag == "propagation" ) { + Rule rule = parsePropagation( e ); + mRules.append( rule ); + } else if ( tag == "condition" ) { + Condition condition = parseCondition( e ); + TQDomNode n2; + for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { + TQDomElement e2 = n2.toElement(); + if ( e2.tagName() == "propagation" ) { + Rule rule = parsePropagation( e2 ); + rule.condition = condition; + mRules.append( rule ); + } else { + kdError() << "Unknow tag: " << e2.tagName() << endl; + } + } + } + } +} + +TDEConfigPropagator::Rule TDEConfigPropagator::parsePropagation( const TQDomElement &e ) +{ + Rule r; + + TQString source = e.attribute( "source" ); + parseConfigEntryPath( source, r.sourceFile, r.sourceGroup, r.sourceEntry ); + + TQString target = e.attribute( "target" ); + parseConfigEntryPath( target, r.targetFile, r.targetGroup, r.targetEntry ); + + r.hideValue = e.hasAttribute( "hidevalue" ) && + e.attribute( "hidevalue" ) == "true"; + + return r; +} + +void TDEConfigPropagator::parseConfigEntryPath( const TQString &path, + TQString &file, + TQString &group, + TQString &entry ) +{ + TQStringList p = TQStringList::split( "/", path ); + + if ( p.count() != 3 ) { + kdError() << "Path has to be of form file/group/entry" << endl; + file = TQString(); + group = TQString(); + entry = TQString(); + return; + } + + file = p[ 0 ]; + group = p[ 1 ]; + entry = p[ 2 ]; + + return; +} + +TDEConfigPropagator::Condition TDEConfigPropagator::parseCondition( const TQDomElement &e ) +{ + Condition c; + + TQString key = e.attribute( "key" ); + + parseConfigEntryPath( key, c.file, c.group, c.key ); + + c.value = e.attribute( "value" ); + + c.isValid = true; + + return c; +} + +void TDEConfigPropagator::commit() +{ + updateChanges(); + + Change *c; + for( c = mChanges.first(); c; c = mChanges.next() ) { + c->apply(); + } +} + +TDEConfigSkeletonItem *TDEConfigPropagator::findItem( const TQString &group, + const TQString &name ) +{ +// kdDebug() << "TDEConfigPropagator::findItem()" << endl; + + if ( !mSkeleton ) return 0; + + TDEConfigSkeletonItem::List items = mSkeleton->items(); + TDEConfigSkeletonItem::List::ConstIterator it; + for( it = items.begin(); it != items.end(); ++it ) { +// kdDebug() << " Item: " << (*it)->name() << " Type: " +// << (*it)->property().typeName() << endl; + if ( (*it)->group() == group && (*it)->name() == name ) { + break; + } + } + if ( it == items.end() ) return 0; + else return *it; +} + +TQString TDEConfigPropagator::itemValueAsString( TDEConfigSkeletonItem *item ) +{ + TQVariant p = item->property(); + + if ( p.type() == TQVariant::Bool ) { + if ( p.toBool() ) return "true"; + else return "false"; + } + + return p.toString(); +} + +void TDEConfigPropagator::updateChanges() +{ + mChanges.clear(); + + Rule::List::ConstIterator it; + for( it = mRules.begin(); it != mRules.end(); ++it ) { + Rule r = *it; + Condition c = r.condition; + if ( c.isValid ) { + TDEConfigSkeletonItem *item = findItem( c.group, c.key ); + kdDebug() << "Item " << c.group << "/" << c.key << ":" << endl; + if ( !item ) { + kdError() << " Item not found." << endl; + } else { + TQString value = itemValueAsString( item ); + kdDebug() << " Value: " << value << endl; + if ( value != c.value ) { + continue; + } + } + } + + TDEConfigSkeletonItem *item = findItem( r.sourceGroup, r.sourceEntry ); + if ( !item ) { + kdError() << "Item " << r.sourceGroup << "/" << r.sourceEntry + << " not found." << endl; + continue; + } + TQString value = itemValueAsString( item ); + + TDEConfig target( r.targetFile ); + target.setGroup( r.targetGroup ); + TQString targetValue = target.readEntry( r.targetEntry ); + if ( r.hideValue ) targetValue = KStringHandler::obscure( targetValue ); + if ( targetValue != value ) { + ChangeConfig *change = new ChangeConfig(); + change->file = r.targetFile; + change->group = r.targetGroup; + change->name = r.targetEntry; + if ( r.hideValue ) value = KStringHandler::obscure( value ); + change->value = value; + change->hideValue = r.hideValue; + mChanges.append( change ); + } + } + + addCustomChanges( mChanges ); +} + +TDEConfigPropagator::Change::List TDEConfigPropagator::changes() +{ + return mChanges; +} + +TDEConfigPropagator::Rule::List TDEConfigPropagator::rules() +{ + return mRules; +} diff --git a/libtdepim/tdeconfigpropagator.h b/libtdepim/tdeconfigpropagator.h new file mode 100644 index 000000000..92f9565f2 --- /dev/null +++ b/libtdepim/tdeconfigpropagator.h @@ -0,0 +1,165 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KCONFIGPROPAGATOR_H +#define KCONFIGPROPAGATOR_H + +#include +#include +#include +#include + +#include + +class TDEConfigSkeleton; +class TDEConfigSkeletonItem; + +class KDE_EXPORT TDEConfigPropagator +{ + public: + + /** + Create TDEConfigPropagator object without associated source configuration. + */ + TDEConfigPropagator(); + /** + Create TDEConfigPropagator object. + + @param skeleton TDEConfigSkeleton object used as source for the propagation + @param kcfgFile file name of kcfg file containing the propagation rules + */ + TDEConfigPropagator( TDEConfigSkeleton *skeleton, const TQString &kcfgFile ); + virtual ~TDEConfigPropagator() {} + + TDEConfigSkeleton *skeleton() { return mSkeleton; } + + /* + Commit changes according to propagation rules. + */ + void commit(); + + class KDE_EXPORT Condition + { + public: + Condition() : isValid( false ) {} + + TQString file; + TQString group; + TQString key; + TQString value; + + bool isValid; + }; + + class KDE_EXPORT Rule + { + public: + typedef TQValueList List; + + Rule() : hideValue( false ) {} + + TQString sourceFile; + TQString sourceGroup; + TQString sourceEntry; + + TQString targetFile; + TQString targetGroup; + TQString targetEntry; + + Condition condition; + + bool hideValue; + }; + + class KDE_EXPORT Change + { + public: + typedef TQPtrList List; + + Change( const TQString &title ) : mTitle( title ) {} + virtual ~Change(); + + void setTitle( const TQString &title ) { mTitle = title; } + TQString title() const { return mTitle; } + + virtual TQString arg1() const { return TQString(); } + virtual TQString arg2() const { return TQString(); } + + virtual void apply() = 0; + + private: + TQString mTitle; + }; + + class KDE_EXPORT ChangeConfig : public Change + { + public: + ChangeConfig(); + ~ChangeConfig() {} + + TQString arg1() const; + TQString arg2() const; + + void apply(); + + TQString file; + TQString group; + TQString name; + TQString label; + TQString value; + bool hideValue; + }; + + void updateChanges(); + + Change::List changes(); + + Rule::List rules(); + + protected: + void init(); + + /** + Implement this function in a subclass if you want to add changes which + can't be expressed as propagations in the kcfg file. + */ + virtual void addCustomChanges( Change::List & ) {} + + TDEConfigSkeletonItem *findItem( const TQString &group, const TQString &name ); + + TQString itemValueAsString( TDEConfigSkeletonItem * ); + + void readKcfgFile(); + + Rule parsePropagation( const TQDomElement &e ); + Condition parseCondition( const TQDomElement &e ); + + void parseConfigEntryPath( const TQString &path, TQString &file, + TQString &group, TQString &entry ); + + private: + TDEConfigSkeleton *mSkeleton; + TQString mKcfgFile; + + Rule::List mRules; + Change::List mChanges; +}; + +#endif diff --git a/libtdepim/tdeconfigwizard.cpp b/libtdepim/tdeconfigwizard.cpp new file mode 100644 index 000000000..026c85991 --- /dev/null +++ b/libtdepim/tdeconfigwizard.cpp @@ -0,0 +1,197 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdeconfigwizard.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +TDEConfigWizard::TDEConfigWizard( TQWidget *parent, + char *name, bool modal ) + : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, + name, modal ), + mPropagator( 0 ), mChangesPage( 0 ) +{ + init(); +} + +TDEConfigWizard::TDEConfigWizard( TDEConfigPropagator *propagator, TQWidget *parent, + char *name, bool modal ) + : KDialogBase( TreeList, i18n("Configuration Wizard"), Ok|Cancel, Ok, parent, + name, modal ), + mPropagator( propagator ), mChangesPage( 0 ) +{ + init(); +} + +TDEConfigWizard::~TDEConfigWizard() +{ + delete mPropagator; +} + +void TDEConfigWizard::init() +{ + connect( this, TQT_SIGNAL( aboutToShowPage( TQWidget * ) ), + TQT_SLOT( slotAboutToShowPage( TQWidget * ) ) ); + + TQTimer::singleShot( 0, this, TQT_SLOT( readConfig() ) ); +} + +void TDEConfigWizard::setPropagator( TDEConfigPropagator *p ) +{ + mPropagator = p; +} + +void TDEConfigWizard::slotAboutToShowPage( TQWidget *page ) +{ + if ( page == mChangesPage ) { + updateChanges(); + } +} + +TQFrame *TDEConfigWizard::createWizardPage( const TQString &title ) +{ + return addPage( title ); +} + +void TDEConfigWizard::setupRulesPage() +{ + TQFrame *topFrame = addPage( i18n("Rules") ); + TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); + + mRuleView = new TQListView( topFrame ); + topLayout->addWidget( mRuleView ); + + mRuleView->addColumn( i18n("Source") ); + mRuleView->addColumn( i18n("Target") ); + mRuleView->addColumn( i18n("Condition") ); + + updateRules(); +} + +void TDEConfigWizard::updateRules() +{ + if ( !mPropagator ) { + kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl; + return; + } + + mRuleView->clear(); + + TDEConfigPropagator::Rule::List rules = mPropagator->rules(); + TDEConfigPropagator::Rule::List::ConstIterator it; + for( it = rules.begin(); it != rules.end(); ++it ) { + TDEConfigPropagator::Rule r = *it; + TQString source = r.sourceFile + "/" + r.sourceGroup + "/" + + r.sourceEntry; + TQString target = r.targetFile + "/" + r.targetGroup + "/" + + r.targetEntry; + TQString condition; + TDEConfigPropagator::Condition c = r.condition; + if ( c.isValid ) { + condition = c.file + "/" + c.group + "/" + c.key + " = " + c.value; + } + new TQListViewItem( mRuleView, source, target, condition ); + } +} + +void TDEConfigWizard::setupChangesPage() +{ + TQFrame *topFrame = addPage( i18n("Changes") ); + TQVBoxLayout *topLayout = new TQVBoxLayout( topFrame ); + + mChangeView = new TQListView( topFrame ); + topLayout->addWidget( mChangeView ); + + mChangeView->addColumn( i18n("Action") ); + mChangeView->addColumn( i18n("Option") ); + mChangeView->addColumn( i18n("Value") ); + mChangeView->setSorting( -1 ); + + mChangesPage = topFrame; +} + +void TDEConfigWizard::updateChanges() +{ + kdDebug() << "TDEConfigWizard::updateChanges()" << endl; + + if ( !mPropagator ) { + kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl; + return; + } + + usrWriteConfig(); + + mPropagator->updateChanges(); + + mChangeView->clear(); + + TDEConfigPropagator::Change::List changes = mPropagator->changes(); + TDEConfigPropagator::Change *c; + for( c = changes.first(); c; c = changes.next() ) { + new TQListViewItem( mChangeView, mChangeView->lastItem(), c->title(), c->arg1(), c->arg2() ); + } +} + +void TDEConfigWizard::readConfig() +{ + kdDebug() << "TDEConfigWizard::readConfig()" << endl; + + int result = KMessageBox::warningContinueCancel( this, + i18n("Please make sure that the programs which are " + "configured by the wizard do not run in parallel to the wizard; " + "otherwise, changes done by the wizard could be lost."), + i18n("Warning"), i18n("Run Wizard Now"), "warning_running_instances" ); + if ( result != KMessageBox::Continue ) kapp->quit(); + + usrReadConfig(); +} + +void TDEConfigWizard::slotOk() +{ + TQString error = validate(); + if ( error.isNull() ) { + usrWriteConfig(); + + if ( !mPropagator ) { + kdError() << "TDEConfigWizard: No TDEConfigPropagator set." << endl; + return; + } else { + if ( mPropagator->skeleton() ) { + mPropagator->skeleton()->writeConfig(); + } + mPropagator->commit(); + } + + accept(); + } else { + KMessageBox::sorry( this, error ); + } +} + +#include "tdeconfigwizard.moc" diff --git a/libtdepim/tdeconfigwizard.h b/libtdepim/tdeconfigwizard.h new file mode 100644 index 000000000..7eaaeda95 --- /dev/null +++ b/libtdepim/tdeconfigwizard.h @@ -0,0 +1,110 @@ +/* + This file is part of libtdepim. + + Copyright (c) 2003 Cornelius Schumacher + + 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KCONFIGWIZARD_H +#define KCONFIGWIZARD_H + +#include +#include +#include + +class TQListView; + +/** + @short Configuration wizard base class +*/ +class KDE_EXPORT TDEConfigWizard : public KDialogBase +{ + Q_OBJECT + + public: + /** + Create wizard. You have to set a propgator with setPropagator() later. + */ + TDEConfigWizard( TQWidget *parent = 0, char *name = 0, bool modal = false ); + /** + Create wizard for given TDEConfigPropagator. The wizard takes ownership of + the propagator. + */ + TDEConfigWizard( TDEConfigPropagator *propagator, TQWidget *parent = 0, + char *name = 0, bool modal = false ); + /** + Destructor. + */ + virtual ~TDEConfigWizard(); + + /** + Set propagator the wizard operates on. + */ + void setPropagator( TDEConfigPropagator * ); + /** + Return propagator the wizard operates on. + */ + TDEConfigPropagator *propagator() { return mPropagator; } + + /** + Create wizard page with given title. + */ + TQFrame *createWizardPage( const TQString &title ); + + /** + Use this function to read the configuration from the TDEConfigSkeleton + object to the GUI. + */ + virtual void usrReadConfig() = 0; + + /** + This function is called when the wizard is finished. You have to save all + settings from the GUI to the TDEConfigSkeleton object here, so that the + TDEConfigPropagator can take them up from there. + */ + virtual void usrWriteConfig() = 0; + + /** + Validates the supplied data. Returns a appropiate error when some data + is invalid. Return TQString() if all data is valid. + */ + virtual TQString validate() { return TQString(); } + + protected slots: + void readConfig(); + + void slotOk(); + + void slotAboutToShowPage( TQWidget *page ); + + protected: + void init(); + + void setupRulesPage(); + void updateRules(); + void setupChangesPage(); + void updateChanges(); + + private: + TDEConfigPropagator *mPropagator; + + TQListView *mRuleView; + TQListView *mChangeView; + + TQWidget *mChangesPage; +}; + +#endif diff --git a/libtdepim/tdefileio.cpp b/libtdepim/tdefileio.cpp new file mode 100644 index 000000000..ad899351f --- /dev/null +++ b/libtdepim/tdefileio.cpp @@ -0,0 +1,390 @@ +// tdefileio.cpp +// Author: Stefan Taferner +// License: GPL + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +namespace KPIM { + +//----------------------------------------------------------------------------- +static void msgDialog(const TQString &msg) +{ + KMessageBox::sorry(0, msg, i18n("File I/O Error")); +} + + +//----------------------------------------------------------------------------- +KDE_EXPORT TQCString kFileToString(const TQString &aFileName, bool aEnsureNL, bool aVerbose) +{ + TQCString result; + TQFileInfo info(aFileName); + unsigned int readLen; + unsigned int len = info.size(); + TQFile file(aFileName); + + //assert(aFileName!=0); + if( aFileName.isEmpty() ) + return ""; + + if (!info.exists()) + { + if (aVerbose) + msgDialog(i18n("The specified file does not exist:\n%1").arg(aFileName)); + return TQCString(); + } + if (info.isDir()) + { + if (aVerbose) + msgDialog(i18n("This is a folder and not a file:\n%1").arg(aFileName)); + return TQCString(); + } + if (!info.isReadable()) + { + if (aVerbose) + msgDialog(i18n("You do not have read permissions " + "to the file:\n%1").arg(aFileName)); + return TQCString(); + } + if (len <= 0) return TQCString(); + + if (!file.open(IO_Raw|IO_ReadOnly)) + { + if (aVerbose) switch(file.status()) + { + case IO_ReadError: + msgDialog(i18n("Could not read file:\n%1").arg(aFileName)); + break; + case IO_OpenError: + msgDialog(i18n("Could not open file:\n%1").arg(aFileName)); + break; + default: + msgDialog(i18n("Error while reading file:\n%1").arg(aFileName)); + } + return TQCString(); + } + + result.resize(len + (int)aEnsureNL + 1); + readLen = file.readBlock(result.data(), len); + if (aEnsureNL && result[len-1]!='\n') + { + result[len++] = '\n'; + readLen++; + } + result[len] = '\0'; + + if (readLen < len) + { + TQString msg = i18n("Could only read %1 bytes of %2.") + .arg(readLen).arg(len); + msgDialog(msg); + return TQCString(); + } + + return result; +} + +//----------------------------------------------------------------------------- +#if 0 // unused +TQByteArray kFileToBytes(const TQString &aFileName, bool aVerbose) +{ + TQByteArray result; + TQFileInfo info(aFileName); + unsigned int readLen; + unsigned int len = info.size(); + TQFile file(aFileName); + + //assert(aFileName!=0); + if( aFileName.isEmpty() ) + return result; + + if (!info.exists()) + { + if (aVerbose) + msgDialog(i18n("The specified file does not exist:\n%1") + .arg(aFileName)); + return result; + } + if (info.isDir()) + { + if (aVerbose) + msgDialog(i18n("This is a folder and not a file:\n%1") + .arg(aFileName)); + return result; + } + if (!info.isReadable()) + { + if (aVerbose) + msgDialog(i18n("You do not have read permissions " + "to the file:\n%1").arg(aFileName)); + return result; + } + if (len <= 0) return result; + + if (!file.open(IO_Raw|IO_ReadOnly)) + { + if (aVerbose) switch(file.status()) + { + case IO_ReadError: + msgDialog(i18n("Could not read file:\n%1").arg(aFileName)); + break; + case IO_OpenError: + msgDialog(i18n("Could not open file:\n%1").arg(aFileName)); + break; + default: + msgDialog(i18n("Error while reading file:\n%1").arg(aFileName)); + } + return result; + } + + result.resize(len); + readLen = file.readBlock(result.data(), len); + kdDebug(5300) << TQString( "len %1" ).arg(len) << endl; + + if (readLen < len) + { + TQString msg; + msg = i18n("Could only read %1 bytes of %2.") + .arg(readLen).arg(len); + msgDialog(msg); + return result; + } + + return result; +} +#endif + +//----------------------------------------------------------------------------- +KDE_EXPORT bool kBytesToFile(const char* aBuffer, int len, + const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) +{ + // TODO: use KSaveFile + TQFile file(aFileName); + int writeLen, rc; + + //assert(aFileName!=0); + if(aFileName.isEmpty()) + return FALSE; + + if (file.exists()) + { + if (aAskIfExists) + { + TQString str; + str = i18n("File %1 exists.\nDo you want to replace it?") + .arg(aFileName); + rc = KMessageBox::warningContinueCancel(0, + str, i18n("Save to File"), i18n("&Replace")); + if (rc != KMessageBox::Continue) return FALSE; + } + if (aBackup) + { + // make a backup copy + // TODO: use KSaveFile::backupFile() + TQString bakName = aFileName; + bakName += '~'; + TQFile::remove(bakName); + if( !TQDir::current().rename(aFileName, bakName) ) + { + // failed to rename file + if (!aVerbose) return FALSE; + rc = KMessageBox::warningContinueCancel(0, + i18n("Failed to make a backup copy of %1.\nContinue anyway?") + .arg(aFileName), + i18n("Save to File"), KStdGuiItem::save() ); + if (rc != KMessageBox::Continue) return FALSE; + } + } + } + + if (!file.open(IO_Raw|IO_WriteOnly|IO_Truncate)) + { + if (aVerbose) switch(file.status()) + { + case IO_WriteError: + msgDialog(i18n("Could not write to file:\n%1").arg(aFileName)); + break; + case IO_OpenError: + msgDialog(i18n("Could not open file for writing:\n%1") + .arg(aFileName)); + break; + default: + msgDialog(i18n("Error while writing file:\n%1").arg(aFileName)); + } + return FALSE; + } + + writeLen = file.writeBlock(aBuffer, len); + + if (writeLen < 0) + { + if (aVerbose) + msgDialog(i18n("Could not write to file:\n%1").arg(aFileName)); + return FALSE; + } + else if (writeLen < len) + { + TQString msg = i18n("Could only write %1 bytes of %2.") + .arg(writeLen).arg(len); + if (aVerbose) + msgDialog(msg); + return FALSE; + } + + return TRUE; +} + +KDE_EXPORT bool kCStringToFile(const TQCString& aBuffer, const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) +{ + return kBytesToFile(aBuffer, aBuffer.length(), aFileName, aAskIfExists, + aBackup, aVerbose); +} + +KDE_EXPORT bool kByteArrayToFile(const TQByteArray& aBuffer, const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) +{ + return kBytesToFile(aBuffer, aBuffer.size(), aFileName, aAskIfExists, + aBackup, aVerbose); +} + + +TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, + const bool recursive, const bool wantItReadable, + const bool wantItWritable ) +{ + // First we have to find out which type the toCheck is. This can be + // a directory (follow if recursive) or a file (check permissions). + // Symlinks are followed as expected. + TQFileInfo fiToCheck(toCheck); + fiToCheck.setCaching(false); + TQCString toCheckEnc = TQFile::encodeName(toCheck); + TQString error; + struct stat statbuffer; + + if ( !fiToCheck.exists() ) { + error.append( i18n("%1 does not exist") + .arg(toCheck) + "\n"); + } + + // check the access bit of a folder. + if ( fiToCheck.isDir() ) { + if ( stat( toCheckEnc,&statbuffer ) != 0 ) { + kdDebug() << "wantItA: Can't read perms of " << toCheck << endl; + } + TQDir g( toCheck ); + if ( !g.isReadable() ) { + if ( chmod( toCheckEnc, statbuffer.st_mode + S_IXUSR ) != 0 ) { + error.append( i18n("%1 is not accessible and that is " + "unchangeable.").arg(toCheck) + "\n"); + } else { + kdDebug() << "Changed access bit for " << toCheck << endl; + } + } + } + + // For each file or folder we can check if the file is readable + // and writable, as requested. + if ( fiToCheck.isFile() || fiToCheck.isDir() ) { + + if ( !fiToCheck.isReadable() && wantItReadable ) { + // Get the current permissions. No need to do anything with an + // error, it will het added to errors anyhow, later on. + if ( stat(toCheckEnc,&statbuffer) != 0 ) { + kdDebug() << "wantItR: Can't read perms of " << toCheck << endl; + } + + // Lets try changing it. + if ( chmod( toCheckEnc, statbuffer.st_mode + S_IRUSR ) != 0 ) { + error.append( i18n("%1 is not readable and that is unchangeable.") + .arg(toCheck) + "\n"); + } else { + kdDebug() << "Changed the read bit for " << toCheck << endl; + } + } + + if ( !fiToCheck.isWritable() && wantItWritable ) { + // Gets the current persmissions. Needed because it can be changed + // curing previous operation. + if (stat(toCheckEnc,&statbuffer) != 0) { + kdDebug() << "wantItW: Can't read perms of " << toCheck << endl; + } + + // Lets try changing it. + if ( chmod (toCheckEnc, statbuffer.st_mode + S_IWUSR ) != 0 ) { + error.append( i18n("%1 is not writable and that is unchangeable.") + .arg(toCheck) + "\n"); + } else { + kdDebug() << "Changed the write bit for " << toCheck << endl; + } + } + } + + // If it is a folder and recursive is true, then we check the contents of + // the folder. + if ( fiToCheck.isDir() && recursive ){ + TQDir g(toCheck); + // First check if the folder is readable for us. If not, we get + // some ugly crashes. + if ( !g.isReadable() ){ + error.append(i18n("Folder %1 is inaccessible.").arg(toCheck) + "\n"); + } else { + const TQFileInfoList *list = g.entryInfoList(); + TQFileInfoListIterator it( *list ); + TQFileInfo *fi; + while ((fi = it.current()) != 0) { + TQString newToCheck = toCheck + "/" + fi->fileName(); + TQFileInfo fiNewToCheck(newToCheck); + if ( fi->fileName() != "." && fi->fileName() != ".." ) { + error.append ( checkAndCorrectPermissionsIfPossible( newToCheck, + recursive, wantItReadable, wantItWritable) ); + } + ++it; + } + } + } + return error; +} + +bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, + const TQString &toCheck, const bool recursive, const bool wantItReadable, + const bool wantItWritable ) +{ + TQString error = checkAndCorrectPermissionsIfPossible(toCheck, recursive, + wantItReadable, wantItWritable); + // There is no KMessageBox with Retry, Cancel and Details. + // so, I can't provide a functionality to recheck. So it now + // it is just a warning. + if ( !error.isEmpty() ) { + kdDebug() << "checkPermissions found:" << error << endl; + KMessageBox::detailedSorry(parent, + i18n("Some files or folders do not have " + "the right permissions, please correct them " + "manually."), + error, i18n("Permissions Check"), false); + return false; + } else { + return true; + } +} + +} diff --git a/libtdepim/tdefileio.h b/libtdepim/tdefileio.h new file mode 100644 index 000000000..e90451315 --- /dev/null +++ b/libtdepim/tdefileio.h @@ -0,0 +1,105 @@ +/* Load / save entire (local) files with nice diagnostics dialog messages. + * These functions load/save the whole buffer in one i/o call, so they + * should be pretty efficient. + * + * Author: Stefan Taferner + * This code is under GPL. + */ +#ifndef kpim_tdefileio_h +#define kpim_tdefileio_h + +#include +#include + +#include + +class TQString; + +namespace KPIM { + +/** Load a file. Returns a pointer to the memory-block that contains + * the loaded file. Returns a null string if the file could not be loaded. + * If withDialogs is FALSE no warning dialogs are opened if there are + * problems. + * The string returned is always zero-terminated and therefore one + * byte longer than the file itself. + * If ensureNewline is TRUE the string will always have a trailing newline. + */ +TQCString kFileToString(const TQString &fileName, bool ensureNewline=true, + bool withDialogs=true) KDE_EXPORT; + +// unused +//TQByteArray kFileToBytes(const TQString &fileName, bool withDialogs=true); + + +/** Save a file. If withDialogs is FALSE no warning dialogs are opened if + * there are problems. Returns TRUE on success and FALSE on failure. + * Replaces existing files without warning if askIfExists==FALSE. + * Makes a copy if the file exists to filename~ if createBackup==TRUE. + */ +bool kBytesToFile(const char* aBuffer, int len, + const TQString &aFileName, + bool aAskIfExists, bool aBackup, bool aVerbose) KDE_EXPORT; + +bool kCStringToFile(const TQCString& buffer, const TQString &fileName, + bool askIfExists=false, bool createBackup=true, + bool withDialogs=true) KDE_EXPORT; +/** Does not stop at NUL */ +KDE_EXPORT bool kByteArrayToFile(const TQByteArray& buffer, const TQString &fileName, + bool askIfExists=false, bool createBackup=true, + bool withDialogs=true) KDE_EXPORT; + + + /** + * Checks and corrects the permissions of a file or folder, and if requested + * all files and folders below. It gives back a list of files which do not + * have the right permissions. This list can be used to show to the user. + * + * @param toCheck The file or folder of which the permissions should + * be checked. + * @param recursive Set to true, it will check the contents of a folder + * for the permissions recursively. If false only + * toCheck will be checked. + * @param wantItReadable Set to true, it will check for read permissions. + * If the read permissions are not available, there will + * be a attempt to correct this. + * @param wantItWritable Set to true, it will check for write permissions. + * If the write permissions are not available, there + * will be a attempt to correct this. + * @return It will return a string with all files and folders which do not + * have the right permissions. If empty, then all permissions are ok. + */ +TQString checkAndCorrectPermissionsIfPossible( const TQString &toCheck, + const bool recursive, const bool wantItReadable, + const bool wantItWritable ); + + /** + * Checks and corrects the permissions of a file or folder, and if requested + * all files and folders below. If the permissions are not ok, it tries to correct + * them. If that fails then a warning with detailled information is given. + * + * @param parent If parent is 0, then the message box becomes an + * application-global modal dialog box. If parent + * is a widget, the message box becomes modal + * relative to parent. + * @param toCheck The file or folder of which the permissions should + * be checked. + * @param recursive Set to true, it will check the contents of a folder + * for the permissions recursively. If false only + * toCheck will be checked. + * @param wantItReadable Set to true, it will check for read permissions. + * If the read permissions are not available, there will + * be a attempt to correct this. + * @param wantItWritable Set to true, it will check for write permissions. + * If the write permissions are not available, there + * will be a attempt to correct this. + * @return It will return true if all permissions in the end are ok. If false + * then the permissions are not ok and it was not possible to correct + * all errors. + */ +bool checkAndCorrectPermissionsIfPossibleWithErrorHandling( TQWidget *parent, + const TQString &toCheck, const bool recursive, const bool wantItReadable, + const bool wantItWritable ); +} + +#endif /*kpim_tdefileio_h*/ diff --git a/libtdepim/tdepartsdesignerplugin/CMakeLists.txt b/libtdepim/tdepartsdesignerplugin/CMakeLists.txt index 01bba1d8c..043d4526a 100644 --- a/libtdepim/tdepartsdesignerplugin/CMakeLists.txt +++ b/libtdepim/tdepartsdesignerplugin/CMakeLists.txt @@ -27,6 +27,6 @@ link_directories( tde_add_kpart( tdepartsdesignerplugin AUTOMOC SOURCES tdepartsdesignerplugin.cpp - LINK tdeparts-shared kio-shared + LINK tdeparts-shared tdeio-shared DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/designer ) diff --git a/libtdepim/tests/myconfig.kcfgc b/libtdepim/tests/myconfig.kcfgc index 35e26c996..451a9ec13 100644 --- a/libtdepim/tests/myconfig.kcfgc +++ b/libtdepim/tests/myconfig.kcfgc @@ -1,4 +1,4 @@ -# Code generation options for kconfig_compiler +# Code generation options for tdeconfig_compiler File=propagator_test.kcfg ClassName=MyConfig Singleton=true diff --git a/libtdepim/tests/testdistrlist.cpp b/libtdepim/tests/testdistrlist.cpp index 895dc5371..75c4d5574 100644 --- a/libtdepim/tests/testdistrlist.cpp +++ b/libtdepim/tests/testdistrlist.cpp @@ -26,8 +26,8 @@ using KPIM::DistributionList; #include #include #include -#include -#include +#include +#include #include #include diff --git a/libtdepim/tests/testwizard.cpp b/libtdepim/tests/testwizard.cpp index 1e404165e..9858a0920 100644 --- a/libtdepim/tests/testwizard.cpp +++ b/libtdepim/tests/testwizard.cpp @@ -21,7 +21,7 @@ #include "myconfig.h" -#include +#include #include #include -- cgit v1.2.1