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 QString& vCardURL )
00091 {
00092   mCore->importVCard( vCardURL );
00093 }
00094 
00095 ASYNC KAddressbookPart::showContactEditor( QString uid )
00096 {
00097   mCore->editContact( uid );
00098 }
00099 
00100 void KAddressbookPart::newContact()
00101 {
00102   mCore->newContact();
00103 }
00104 
00105 QString KAddressbookPart::getNameByPhone( QString phone )
00106 {
00107   return mCore->getNameByPhone( phone );
00108 }
00109 
00110 void KAddressbookPart::save()
00111 {
00112   mCore->save();
00113 }
00114 
00115 void KAddressbookPart::exit()
00116 {
00117   mCore->queryClose();
00118 
00119   delete this;
00120 }
00121 
00122 bool KAddressbookPart::openURL( const KURL &url )
00123 {
00124   kdDebug(5720) << "KAddressbookPart:openFile()" << endl;
00125 
00126   mCore->widget()->show();
00127 
00128   if ( !url.isEmpty() )
00129     mCore->importVCard( url );
00130 
00131   emit setWindowCaption( url.prettyURL() );
00132 
00133   return true;
00134 }
00135 
00136 bool KAddressbookPart::openFile()
00137 {
00138   return false;
00139 }
00140 
00141 bool KAddressbookPart::handleCommandLine()
00142 {
00143   return mCore->handleCommandLine( this );
00144 }
00145 
00146 void KAddressbookPart::guiActivateEvent( KParts::GUIActivateEvent *e )
00147 {
00148   kdDebug(5720) << "KAddressbookPart::guiActivateEvent" << endl;
00149   KParts::ReadOnlyPart::guiActivateEvent( e );
00150 
00151   if ( e->activated() )
00152     mCore->reinitXMLGUI();
00153 
00154   if ( !e->activated() ) {
00155     mCore->statusBar()->removeItem( 1 );
00156     mCore->statusBar()->removeItem( 2 );
00157   }
00158 }
00159 
00160 #include "kaddressbook_part.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys