kaddressbook

locationmap.cpp

00001 /*
00002     This file is part of KAddressbook.
00003     Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <kapplication.h>
00025 #include <kconfig.h>
00026 #include <kdeversion.h>
00027 #include <kglobal.h>
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <kstaticdeleter.h>
00031 #include <kurl.h>
00032 
00033 #include "kabprefs.h"
00034 #include "locationmap.h"
00035 
00036 LocationMap *LocationMap::mSelf = 0;
00037 static KStaticDeleter<LocationMap> locationMapDeleter;
00038 
00039 LocationMap::LocationMap()
00040 {
00041 }
00042 
00043 LocationMap::~LocationMap()
00044 {
00045 }
00046 
00047 LocationMap *LocationMap::instance()
00048 {
00049   if ( !mSelf )
00050     locationMapDeleter.setObject( mSelf, new LocationMap );
00051 
00052   return mSelf;
00053 }
00054 
00055 void LocationMap::showAddress( const KABC::Address &addr )
00056 {
00057   KURL url( createUrl( addr ) );
00058   if ( url.isEmpty() )
00059     return;
00060 
00061   kapp->invokeBrowser( url.url() );
00062 }
00063 
00064 QString LocationMap::createUrl( const KABC::Address &addr )
00065 {
00075   QString urlTemplate = KABPrefs::instance()->locationMapURL().arg( KGlobal::locale()->country() );
00076   if ( urlTemplate.isEmpty() ) {
00077     KMessageBox::error( 0, i18n( "No service provider available for map lookup!\nPlease add one in the configuration dialog." ) );
00078     return QString::null;
00079   }
00080 
00081 #if KDE_VERSION >= 319
00082   return urlTemplate.replace( "%s", addr.street() ).
00083                      replace( "%r", addr.region() ).
00084                      replace( "%l", addr.locality() ).
00085                      replace( "%z", addr.postalCode() ).
00086                      replace( "%c", addr.countryToISO( addr.country() ) );
00087 #else
00088   return urlTemplate.replace( "%s", addr.street() ).
00089                      replace( "%r", addr.region() ).
00090                      replace( "%l", addr.locality() ).
00091                      replace( "%z", addr.postalCode() ).
00092                      replace( "%c", "" );
00093 #endif
00094 }
00095 
00096 #include "locationmap.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys