kaddressbook

kaddressbook_part.cpp

00001 /*
00002     This file is part of KAddressbook.
00003     Copyright (c) 2000 Cornelius Schumacher <schumacher@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 TQt, and distribute the resulting executable,
00021     without including the source code for TQt in the source distribution.
00022 */
00023 
00024 #include <tqlayout.h>
00025 
00026 #include <tdeaction.h>
00027 #include <tdeapplication.h>
00028 #include <kdebug.h>
00029 #include <kiconloader.h>
00030 #include <kinstance.h>
00031 #include <tdelocale.h>
00032 #include <tdeparts/genericfactory.h>
00033 #include <tdeparts/statusbarextension.h>
00034 #include <kstatusbar.h>
00035 
00036 #include "kabcore.h"
00037 #include "kabprefs.h"
00038 #include "kaddressbookiface.h"
00039 
00040 #include "kaddressbook_part.h"
00041 
00042 typedef KParts::GenericFactory< KAddressbookPart > KAddressbookFactory;
00043 K_EXPORT_COMPONENT_FACTORY( libkaddressbookpart, KAddressbookFactory )
00044 
00045 KAddressbookPart::KAddressbookPart( TQWidget *parentWidget, const char *widgetName,
00046                                     TQObject *parent, const char *name,
00047                                     const TQStringList & )
00048   : DCOPObject( "KAddressBookIface" ), KParts::ReadOnlyPart( parent, name )
00049 {
00050   setInstance( KAddressbookFactory::instance() );
00051 
00052   // create a canvas to insert our widget
00053   TQWidget *canvas = new TQWidget( parentWidget, widgetName );
00054   canvas->setFocusPolicy( TQ_ClickFocus );
00055   setWidget( canvas );
00056 
00057   TQVBoxLayout *topLayout = new TQVBoxLayout( canvas );
00058 
00059   TDEGlobal::iconLoader()->addAppDir( "kaddressbook" );
00060 
00061   mCore = new KABCore( this, true, canvas );
00062   mCore->restoreSettings();
00063   topLayout->addWidget( mCore->widget() );
00064 
00065   KParts::StatusBarExtension *statusBar = new KParts::StatusBarExtension( this );
00066   mCore->setStatusBar( statusBar->statusBar() );
00067 
00068   setXMLFile( "kaddressbook_part.rc" );
00069 }
00070 
00071 KAddressbookPart::~KAddressbookPart()
00072 {
00073   mCore->save();
00074   mCore->saveSettings();
00075 
00076   KABPrefs::instance()->writeConfig();
00077   closeURL();
00078 }
00079 
00080 TDEAboutData *KAddressbookPart::createAboutData()
00081 {
00082   return KABCore::createAboutData();
00083 }
00084 
00085 void KAddressbookPart::addEmail( TQString addr )
00086 {
00087   mCore->addEmail( addr );
00088 }
00089 
00090 void KAddressbookPart::importVCard( const KURL& url )
00091 {
00092   mCore->importVCard( url );
00093 }
00094 
00095 void KAddressbookPart::importVCardFromData( const TQString& vCard )
00096 {
00097   mCore->importVCardFromData( vCard );
00098 }
00099 
00100 ASYNC KAddressbookPart::showContactEditor( TQString uid )
00101 {
00102   mCore->editContact( uid );
00103 }
00104 
00105 void KAddressbookPart::newContact()
00106 {
00107   mCore->newContact();
00108 }
00109 
00110 
00111 void KAddressbookPart::newDistributionList()
00112 {
00113   mCore->newDistributionList();
00114 }
00115 
00116 TQString KAddressbookPart::getNameByPhone( TQString phone )
00117 {
00118   return mCore->getNameByPhone( phone );
00119 }
00120 
00121 void KAddressbookPart::save()
00122 {
00123   mCore->save();
00124 }
00125 
00126 void KAddressbookPart::exit()
00127 {
00128   mCore->queryClose();
00129 
00130   delete this;
00131 }
00132 
00133 bool KAddressbookPart::openURL( const KURL &url )
00134 {
00135   kdDebug(5720) << "KAddressbookPart:openFile()" << endl;
00136 
00137   mCore->widget()->show();
00138 
00139   if ( !url.isEmpty() )
00140     mCore->importVCard( url );
00141 
00142   emit setWindowCaption( url.prettyURL() );
00143 
00144   return true;
00145 }
00146 
00147 bool KAddressbookPart::openFile()
00148 {
00149   return false;
00150 }
00151 
00152 bool KAddressbookPart::handleCommandLine()
00153 {
00154   return mCore->handleCommandLine( this );
00155 }
00156 
00157 void KAddressbookPart::syncAllResources()
00158 {
00159   mCore->save();
00160   mCore->load();
00161 }
00162 
00163 void KAddressbookPart::guiActivateEvent( KParts::GUIActivateEvent *e )
00164 {
00165   kdDebug(5720) << "KAddressbookPart::guiActivateEvent" << endl;
00166   KParts::ReadOnlyPart::guiActivateEvent( e );
00167 
00168   if ( e->activated() )
00169     mCore->reinitXMLGUI();
00170 
00171   if ( !e->activated() ) {
00172     mCore->statusBar()->removeItem( 1 );
00173     mCore->statusBar()->removeItem( 2 );
00174   }
00175 }
00176 
00177 void KAddressbookPart::loadProfile( const TQString& )
00178 {
00179 }
00180 
00181 void KAddressbookPart::saveToProfile( const TQString& ) const
00182 {
00183 }
00184 
00185 #include "kaddressbook_part.moc"