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 Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlayout.h>
00025 
00026 #include <kaction.h>
00027 #include <kapplication.h>
00028 #include <kdebug.h>
00029 #include <kiconloader.h>
00030 #include <kinstance.h>
00031 #include <klocale.h>
00032 #include <kparts/genericfactory.h>
00033 #include <kparts/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( QWidget *parentWidget, const char *widgetName,
00046                                     QObject *parent, const char *name,
00047                                     const QStringList & )
00048   : DCOPObject( "KAddressBookIface" ), KParts::ReadOnlyPart( parent, name )
00049 {
00050   setInstance( KAddressbookFactory::instance() );
00051 
00052   // create a canvas to insert our widget
00053   QWidget *canvas = new QWidget( parentWidget, widgetName );
00054   canvas->setFocusPolicy( QWidget::ClickFocus );
00055   setWidget( canvas );
00056 
00057   QVBoxLayout *topLayout = new QVBoxLayout( canvas );
00058 
00059   KGlobal::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 KAboutData *KAddressbookPart::createAboutData()
00081 {
00082   return KABCore::createAboutData();
00083 }
00084 
00085 void KAddressbookPart::addEmail( QString 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 QString& vCard )
00096 {
00097   mCore->importVCardFromData( vCard );
00098 }
00099 
00100 ASYNC KAddressbookPart::showContactEditor( QString uid )
00101 {
00102   mCore->editContact( uid );
00103 }
00104 
00105 void KAddressbookPart::newContact()
00106 {
00107   mCore->newContact();
00108 }
00109 
00110 QString KAddressbookPart::getNameByPhone( QString phone )
00111 {
00112   return mCore->getNameByPhone( phone );
00113 }
00114 
00115 void KAddressbookPart::save()
00116 {
00117   mCore->save();
00118 }
00119 
00120 void KAddressbookPart::exit()
00121 {
00122   mCore->queryClose();
00123 
00124   delete this;
00125 }
00126 
00127 bool KAddressbookPart::openURL( const KURL &url )
00128 {
00129   kdDebug(5720) << "KAddressbookPart:openFile()" << endl;
00130 
00131   mCore->widget()->show();
00132 
00133   if ( !url.isEmpty() )
00134     mCore->importVCard( url );
00135 
00136   emit setWindowCaption( url.prettyURL() );
00137 
00138   return true;
00139 }
00140 
00141 bool KAddressbookPart::openFile()
00142 {
00143   return false;
00144 }
00145 
00146 bool KAddressbookPart::handleCommandLine()
00147 {
00148   return mCore->handleCommandLine( this );
00149 }
00150 
00151 void KAddressbookPart::guiActivateEvent( KParts::GUIActivateEvent *e )
00152 {
00153   kdDebug(5720) << "KAddressbookPart::guiActivateEvent" << endl;
00154   KParts::ReadOnlyPart::guiActivateEvent( e );
00155 
00156   if ( e->activated() )
00157     mCore->reinitXMLGUI();
00158 
00159   if ( !e->activated() ) {
00160     mCore->statusBar()->removeItem( 1 );
00161     mCore->statusBar()->removeItem( 2 );
00162   }
00163 }
00164 
00165 #include "kaddressbook_part.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys