diff options
Diffstat (limited to 'kaddressbook/common')
-rw-r--r-- | kaddressbook/common/Makefile.am | 12 | ||||
-rw-r--r-- | kaddressbook/common/filter.cpp | 219 | ||||
-rw-r--r-- | kaddressbook/common/filter.h | 160 | ||||
-rw-r--r-- | kaddressbook/common/kabprefs.cpp | 82 | ||||
-rw-r--r-- | kaddressbook/common/kabprefs.h | 86 | ||||
-rw-r--r-- | kaddressbook/common/kabprefs_base.kcfgc | 11 | ||||
-rw-r--r-- | kaddressbook/common/kaddressbook.kcfg | 93 | ||||
-rw-r--r-- | kaddressbook/common/locationmap.cpp | 96 | ||||
-rw-r--r-- | kaddressbook/common/locationmap.h | 51 |
9 files changed, 810 insertions, 0 deletions
diff --git a/kaddressbook/common/Makefile.am b/kaddressbook/common/Makefile.am new file mode 100644 index 000000000..63a0951d8 --- /dev/null +++ b/kaddressbook/common/Makefile.am @@ -0,0 +1,12 @@ +INCLUDES= -I$(top_srcdir)/kaddressbook/interfaces \ + -I$(top_srcdir) \ + $(all_includes) + +METASOURCES = AUTO + +noinst_LTLIBRARIES = libkabcommon.la +libkabcommon_la_SOURCES = kabprefs.cpp kabprefs_base.kcfgc locationmap.cpp filter.cpp +libkabcommon_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -no-undefined +libkabcommon_la_LIBADD = $(top_builddir)/kaddressbook/interfaces/libkabinterfaces.la \ + $(top_builddir)/libkdepim/libkdepim.la +noinst_HEADERS = filter.h kabprefs.h diff --git a/kaddressbook/common/filter.cpp b/kaddressbook/common/filter.cpp new file mode 100644 index 000000000..ccac46ef8 --- /dev/null +++ b/kaddressbook/common/filter.cpp @@ -0,0 +1,219 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Mike Pilone <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kconfig.h> +#include <kdebug.h> + +#include "kabprefs.h" + +#include "filter.h" + +Filter::Filter() + : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ), + mInternal( false ), mIsEmpty( true ) +{ +} + +Filter::Filter( const QString &name ) + : mName( name ), mMatchRule( Matching ), mEnabled( true ), + mInternal( false ), mIsEmpty( false ) +{ +} + +Filter::~Filter() +{ +} + +void Filter::setName( const QString &name ) +{ + mName = name; + + mIsEmpty = false; +} + +const QString &Filter::name() const +{ + return mName; +} + +bool Filter::isInternal() const +{ + return mInternal; +} + +void Filter::apply( KABC::Addressee::List &addresseeList ) +{ + KABC::Addressee::List::Iterator iter; + for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) { + if ( filterAddressee( *iter ) ) + ++iter; + else + iter = addresseeList.erase( iter ); + } +} + +bool Filter::filterAddressee( const KABC::Addressee &a ) const +{ + QStringList::ConstIterator iter; + iter = mCategoryList.begin(); + // empty filter always matches + + if ( iter == mCategoryList.end() ) { + if ( mMatchRule == Matching ) + return true; + else { + if ( a.categories().empty() ) + return true; + else + return false; + } + } + + for ( ; iter != mCategoryList.end(); ++iter ) { + if ( a.hasCategory( *iter ) ) + return ( mMatchRule == Matching ); + } + + return !( mMatchRule == Matching ); +} + +void Filter::setEnabled( bool on ) +{ + mEnabled = on; + + mIsEmpty = false; +} + +bool Filter::isEnabled() const +{ + return mEnabled; +} + +void Filter::setCategories( const QStringList &list ) +{ + mCategoryList = list; + + mIsEmpty = false; +} + +const QStringList &Filter::categories() const +{ + return mCategoryList; +} + +void Filter::save( KConfig *config ) +{ + config->writeEntry( "Name", mName ); + config->writeEntry( "Enabled", mEnabled ); + config->writeEntry( "Categories", mCategoryList ); + config->writeEntry( "MatchRule", (int)mMatchRule ); +} + +void Filter::restore( KConfig *config ) +{ + mName = config->readEntry( "Name", "<internal error>" ); + mEnabled = config->readBoolEntry( "Enabled", true ); + mCategoryList = config->readListEntry( "Categories" ); + mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching ); + + mIsEmpty = false; +} + +void Filter::save( KConfig *config, const QString &baseGroup, Filter::List &list ) +{ + { + KConfigGroupSaver s( config, baseGroup ); + + // remove the old filters + uint count = config->readNumEntry( "Count" ); + for ( uint i = 0; i < count; ++i ) + config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); + + } + + int index = 0; + Filter::List::Iterator iter; + for ( iter = list.begin(); iter != list.end(); ++iter ) { + if ( !(*iter).mInternal ) { + KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ) + .arg( index ) ); + (*iter).save( config ); + index++; + } + } + + KConfigGroupSaver s( config, baseGroup ); + config->writeEntry( "Count", index ); +} + +Filter::List Filter::restore( KConfig *config, const QString &baseGroup ) +{ + Filter::List list; + int count = 0; + Filter f; + + { + KConfigGroupSaver s( config, baseGroup ); + count = config->readNumEntry( "Count", 0 ); + } + + for ( int i = 0; i < count; i++ ) { + { + KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) ); + f.restore( config ); + } + + list.append( f ); + } + + const QStringList cats = KABPrefs::instance()->customCategories(); + for ( QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) { + Filter filter; + filter.mName = *it; + filter.mEnabled = true; + filter.mCategoryList = *it; + filter.mMatchRule = Matching; + filter.mInternal = true; + filter.mIsEmpty = false; + list.append( filter ); + } + + return list; +} + +void Filter::setMatchRule( MatchRule rule ) +{ + mMatchRule = rule; + + mIsEmpty = false; +} + +Filter::MatchRule Filter::matchRule() const +{ + return mMatchRule; +} + +bool Filter::isEmpty() const +{ + return mIsEmpty; +} diff --git a/kaddressbook/common/filter.h b/kaddressbook/common/filter.h new file mode 100644 index 000000000..9251c5c17 --- /dev/null +++ b/kaddressbook/common/filter.h @@ -0,0 +1,160 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Mike Pilone <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef FILTER_H +#define FILTER_H + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> + +#include <kabc/addressee.h> +#include <kconfig.h> + +/** + Filter for AddressBook related objects (Addressees) + + @todo This class should be switched to use shared data. + */ +class Filter +{ + public: + typedef QValueList<Filter> List; + + enum MatchRule { Matching = 0, NotMatching = 1 }; + + Filter(); + Filter( const QString& name ); + ~Filter(); + + /** + Set the name of the filter. + */ + void setName( const QString &name ); + + /** + @return The name of the filter. + */ + const QString &name() const; + + /** + @return Whether the filter is an internal one. + */ + bool isInternal() const; + + /** + Apply the filter to the addressee list. All addressees not passing + the filter criterias will be removed from the list. + + If the MatchRule is NotMatch, then all the addressees matching the + filter will be removed from the list. + */ + void apply( KABC::Addressee::List &addresseeList ); + + /** + Apply the filter to the addressee. + + @return True if the addressee passes the criteria, false otherwise. + The return values are opposite if the MatchRule is NotMatch. + */ + bool filterAddressee( const KABC::Addressee &a ) const; + + /** + Enable or disable the filter + */ + void setEnabled( bool on ); + + /** + @return True if this filter is enabled, false otherwise. + */ + bool isEnabled() const; + + /** + Set the list of categories. This list is used to filter addressees. + */ + void setCategories( const QStringList &list ); + + /** + @return The list of categories. + */ + const QStringList &categories() const; + + /** + Saves the filter to the config file. The group should already be set. + */ + void save( KConfig *config ); + + /** + Loads the filter from the config file. The group should already be set. + */ + void restore( KConfig *config ); + + /** + Saves a list of filters to the config file. + + @param config The config file to use + @param baseGroup The base groupname to use. The number of filters + will be written to this group, then a _1, _2, etc + will be append for each filter saved. + @param list The list of filters to be saved. + */ + static void save( KConfig *config, const QString &baseGroup, Filter::List &list ); + + /** + Restores a list of filters from a config file. + + @param config The config file to read from. + @param baseGroup The base group name to be used to find the filters + + @return The list of filters. + */ + static Filter::List restore( KConfig *config, const QString &baseGroup ); + + /** + Sets the filter rule. If the rule is Filter::Matching (default), + then the filter will return true on items that match the filter. + If the rule is Filter::NotMatching, then the filter will return + true on items that do not match the filter. + */ + void setMatchRule( MatchRule rule ); + + /** + @return The current match rule. + */ + MatchRule matchRule() const; + + /** + @return true if the category list is empty. + */ + bool isEmpty() const; + + private: + QString mName; + QStringList mCategoryList; + MatchRule mMatchRule; + bool mEnabled; + bool mInternal; + bool mIsEmpty; +}; + +#endif diff --git a/kaddressbook/common/kabprefs.cpp b/kaddressbook/common/kabprefs.cpp new file mode 100644 index 000000000..e8402d562 --- /dev/null +++ b/kaddressbook/common/kabprefs.cpp @@ -0,0 +1,82 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Mike Pilone <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kconfig.h> +#include <klocale.h> +#include <kstaticdeleter.h> + +#include "kabprefs.h" + +KABPrefs *KABPrefs::mInstance = 0; +static KStaticDeleter<KABPrefs> staticDeleter; + +KABPrefs::KABPrefs() + : KABPrefsBase() +{ + KConfigSkeleton::setCurrentGroup( "General" ); + + QStringList defaultMap; + defaultMap << "http://maps.google.com/maps?f=q&hl=%1&q=%n,%l,%s"; + addItemString( "LocationMapURL", mLocationMapURL, defaultMap[ 0 ] ); + addItemStringList( "LocationMapURLs", mLocationMapURLs, defaultMap ); +} + +KABPrefs::~KABPrefs() +{ +} + +KABPrefs *KABPrefs::instance() +{ + if ( !mInstance ) { + staticDeleter.setObject( mInstance, new KABPrefs() ); + mInstance->readConfig(); + } + + return mInstance; +} + +void KABPrefs::setCategoryDefaults() +{ + mCustomCategories.clear(); + mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" ) + << i18n( "Customer" ) << i18n( "Friend" ); +} + +void KABPrefs::usrReadConfig() +{ + config()->setGroup( "General" ); + mCustomCategories = config()->readListEntry( "Custom Categories" ); + if ( mCustomCategories.isEmpty() ) + setCategoryDefaults(); + + KPimPrefs::usrReadConfig(); +} + + +void KABPrefs::usrWriteConfig() +{ + config()->setGroup( "General" ); + config()->writeEntry( "Custom Categories", mCustomCategories ); + + KPimPrefs::usrWriteConfig(); +} diff --git a/kaddressbook/common/kabprefs.h b/kaddressbook/common/kabprefs.h new file mode 100644 index 000000000..3c2db1522 --- /dev/null +++ b/kaddressbook/common/kabprefs.h @@ -0,0 +1,86 @@ +/* + This file is part of KAddressBook. + Copyright (c) 2002 Mike Pilone <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef KABPREFS_H +#define KABPREFS_H + +#include <qstringlist.h> +#include <kdepimmacros.h> +#include "kabprefs_base.h" + +class KConfig; + +class KDE_EXPORT KABPrefs : public KABPrefsBase +{ + public: + virtual ~KABPrefs(); + + static KABPrefs *instance(); + + void usrReadConfig(); + void usrWriteConfig(); + + void setLocationMapURL( const QString &locationMapURL ) + { + if ( !isImmutable( QString::fromLatin1( "LocationMapURL" ) ) ) + mLocationMapURL = locationMapURL; + } + + QString locationMapURL() const + { + return mLocationMapURL; + } + + void setLocationMapURLs( const QStringList &locationMapURLs ) + { + if ( !isImmutable( QString::fromLatin1( "LocationMapURLs" ) ) ) + mLocationMapURLs = locationMapURLs; + } + + QStringList locationMapURLs() const + { + return mLocationMapURLs; + } + + QStringList customCategories() const + { + return mCustomCategories; + } + + void setCustomCategories(const QStringList & s) + { + mCustomCategories = s; + } + + void setCategoryDefaults(); + + private: + KABPrefs(); + + static KABPrefs *mInstance; + + QString mLocationMapURL; + QStringList mLocationMapURLs; +}; + +#endif diff --git a/kaddressbook/common/kabprefs_base.kcfgc b/kaddressbook/common/kabprefs_base.kcfgc new file mode 100644 index 000000000..cca2c9337 --- /dev/null +++ b/kaddressbook/common/kabprefs_base.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=kaddressbook.kcfg +ClassName=KABPrefsBase +Singleton=false +Mutators=true +Inherits=KPimPrefs +IncludeFiles=libkdepim/kpimprefs.h +MemberVariables=public +GlobalEnums=true +ItemAccessors=true +SetUserTexts=true diff --git a/kaddressbook/common/kaddressbook.kcfg b/kaddressbook/common/kaddressbook.kcfg new file mode 100644 index 000000000..37e6ff0a6 --- /dev/null +++ b/kaddressbook/common/kaddressbook.kcfg @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="kaddressbookrc"/> + + <group name="General"> + <entry type="Bool" name="AutomaticNameParsing"> + <label>Automatic name parsing for new addressees</label> + <whatsthis></whatsthis> + <default>true</default> + </entry> + <entry type="Int" name="CurrentIncSearchField"> + <default>0</default> + </entry> + <entry type="String" name="PhoneHookApplication"> + <label>Phone</label> + <whatsthis></whatsthis> + </entry> + <entry type="String" name="FaxHookApplication"> + <label>Fax</label> + <whatsthis></whatsthis> + <default>kdeprintfax --phone %N</default> + </entry> + <entry type="String" name="SMSHookApplication"> + <label>SMS</label> + <whatsthis>The script used to send a GSM SMS text message to the mobile phone</whatsthis> + </entry> + </group> + + <group name="Views"> + <entry type="Bool" name="HonorSingleClick"> + <label>Honor KDE single click</label> + <whatsthis></whatsthis> + <default>false</default> + </entry> + <entry type="String" name="CurrentView"> + <default>Default Table View</default> + </entry> + <entry type="StringList" name="ViewNames"> + <default>Default Table View</default> + </entry> + </group> + + <group name="MainWindow"> + <entry type="Bool" name="JumpButtonBarVisible"> + <default>false</default> + </entry> + <entry type="Bool" name="DetailsPageVisible"> + <default>true</default> + </entry> + <entry type="IntList" name="DetailsSplitter"> + </entry> + <entry type="IntList" name="LeftSplitter"> + </entry> + <entry type="Bool" name="ContactListAboveExtensions"> + <default>true</default> + <whatsthis>If true, the contact list will be placed above the extensions on the left (distribution list editor etc.) instead of in the middle of the main window</whatsthis> + + </entry> + </group> + + <group name="ExtensionsGeneral"> + <entry type="String" name="CurrentExtension"> + <default>resourceselection</default> + </entry> + <entry type="StringList" name="activeExtensions"> + <default>distribution_list_editor_ng,resourceselection</default> + </entry> + <entry type="IntList" name="ExtensionsSplitterSizes"/> + </group> + + <group name="Filters"> + <entry type="Int" name="CurrentFilter"> + <default>0</default> + </entry> + </group> + + <group name="AddresseeEditor"> + <entry type="Enum" name="EditorType"> + <choices> + <choice name="FullEditor"/> + <choice name="SimpleEditor"/> + </choices> + <default>FullEditor</default> + </entry> + <entry type="StringList" name="GlobalCustomFields"> + </entry> + <entry type="StringList" name="AdvancedCustomFields"> + </entry> + </group> +</kcfg> diff --git a/kaddressbook/common/locationmap.cpp b/kaddressbook/common/locationmap.cpp new file mode 100644 index 000000000..92bdfaab1 --- /dev/null +++ b/kaddressbook/common/locationmap.cpp @@ -0,0 +1,96 @@ +/* + This file is part of KAddressbook. + Copyright (c) 2004 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include <kapplication.h> +#include <kconfig.h> +#include <kdeversion.h> +#include <kglobal.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kstaticdeleter.h> +#include <kurl.h> + +#include "kabprefs.h" +#include "locationmap.h" + +LocationMap *LocationMap::mSelf = 0; +static KStaticDeleter<LocationMap> locationMapDeleter; + +LocationMap::LocationMap() +{ +} + +LocationMap::~LocationMap() +{ +} + +LocationMap *LocationMap::instance() +{ + if ( !mSelf ) + locationMapDeleter.setObject( mSelf, new LocationMap ); + + return mSelf; +} + +void LocationMap::showAddress( const KABC::Address &addr ) +{ + KURL url( createUrl( addr ) ); + if ( url.isEmpty() ) + return; + + kapp->invokeBrowser( url.url() ); +} + +QString LocationMap::createUrl( const KABC::Address &addr ) +{ + /** + This method makes substitutions for the following place holders: + %s street + %r region + %l locality + %z zip code + %c country (in ISO format) + */ + + QString urlTemplate = KABPrefs::instance()->locationMapURL().arg( KGlobal::locale()->country() ); + if ( urlTemplate.isEmpty() ) { + KMessageBox::error( 0, i18n( "No service provider available for map lookup!\nPlease add one in the configuration dialog." ) ); + return QString::null; + } + +#if KDE_VERSION >= 319 + return urlTemplate.replace( "%s", addr.street() ). + replace( "%r", addr.region() ). + replace( "%l", addr.locality() ). + replace( "%z", addr.postalCode() ). + replace( "%c", addr.countryToISO( addr.country() ) ); +#else + return urlTemplate.replace( "%s", addr.street() ). + replace( "%r", addr.region() ). + replace( "%l", addr.locality() ). + replace( "%z", addr.postalCode() ). + replace( "%c", "" ); +#endif +} + +#include "locationmap.moc" diff --git a/kaddressbook/common/locationmap.h b/kaddressbook/common/locationmap.h new file mode 100644 index 000000000..82300d9df --- /dev/null +++ b/kaddressbook/common/locationmap.h @@ -0,0 +1,51 @@ +/* + This file is part of KAddressbook. + Copyright (c) 2004 Tobias Koenig <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this program + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef LOCATIONMAP_H +#define LOCATIONMAP_H + +#include <kabc/address.h> +#include <qobject.h> +#include <qstring.h> + +class LocationMap : public QObject +{ + Q_OBJECT + + public: + static LocationMap *instance(); + ~LocationMap(); + + public slots: + void showAddress( const KABC::Address& ); + + protected: + LocationMap(); + + private: + QString createUrl( const KABC::Address& ); + + static LocationMap *mSelf; +}; + +#endif |