kaddressbook
kaddressbook_part.cpp
Go to the documentation of this file.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 <QtGui/QVBoxLayout> 00025 00026 #include <kaction.h> 00027 #include <kcomponentdata.h> 00028 #include <kdebug.h> 00029 #include <kiconloader.h> 00030 #include <klocale.h> 00031 #include <kparts/genericfactory.h> 00032 #include <kparts/statusbarextension.h> 00033 #include <kstatusbar.h> 00034 00035 #include "kabcore.h" 00036 #include "kabprefs.h" 00037 #include "kaddressbookpartadaptor.h" 00038 00039 #include "kaddressbook_part.h" 00040 00041 static const KAboutData &createAboutData() 00042 { 00043 static KAboutData about = KABCore::createAboutData(); 00044 return about; 00045 } 00046 00047 K_PLUGIN_FACTORY( KAddressbookFactory, registerPlugin<KAddressbookPart>(); ) 00048 K_EXPORT_PLUGIN( KAddressbookFactory( createAboutData() ) ) 00049 00050 KAddressbookPart::KAddressbookPart( QWidget *parentWidget, QObject *parent, 00051 const QVariantList & ) 00052 : KParts::ReadOnlyPart( parent ) 00053 { 00054 setComponentData( KAddressbookFactory::componentData() ); 00055 00056 // create a canvas to insert our widget 00057 QWidget *canvas = new QWidget( parentWidget ); 00058 canvas->setFocusPolicy( Qt::ClickFocus ); 00059 setWidget( canvas ); 00060 00061 QVBoxLayout *topLayout = new QVBoxLayout( canvas ); 00062 00063 KIconLoader::global()->addAppDir( "kaddressbook" ); 00064 KIconLoader::global()->addAppDir( "kdepim" ); 00065 00066 mCore = new KABCore( this, true, canvas ); 00067 mCore->restoreSettings(); 00068 topLayout->addWidget( mCore->widget() ); 00069 topLayout->setMargin(0); 00070 00071 KParts::StatusBarExtension *statusBar = new KParts::StatusBarExtension( this ); 00072 mCore->setStatusBar( statusBar->statusBar() ); 00073 00074 setXMLFile( "kaddressbook_part.rc" ); 00075 00076 new CoreAdaptor( this ); 00077 QDBusConnection::sessionBus().registerObject( "/KAddressBook", this, QDBusConnection::ExportAdaptors ); 00078 } 00079 00080 KAddressbookPart::~KAddressbookPart() 00081 { 00082 mCore->save(); 00083 mCore->saveSettings(); 00084 00085 KABPrefs::instance()->writeConfig(); 00086 closeUrl(); 00087 } 00088 00089 void KAddressbookPart::addEmail( QString addr ) 00090 { 00091 mCore->addEmail( addr ); 00092 } 00093 00094 void KAddressbookPart::importVCard( const KUrl& url ) 00095 { 00096 mCore->importVCard( url ); 00097 } 00098 00099 void KAddressbookPart::importVCardFromData( const QString& vCard ) 00100 { 00101 mCore->importVCardFromData( vCard ); 00102 } 00103 00104 void KAddressbookPart::showContactEditor( QString uid ) 00105 { 00106 mCore->editContact( uid ); 00107 } 00108 00109 void KAddressbookPart::newContact() 00110 { 00111 mCore->newContact(); 00112 } 00113 00114 00115 void KAddressbookPart::newDistributionList() 00116 { 00117 mCore->newDistributionList(); 00118 } 00119 00120 QString KAddressbookPart::getNameByPhone( QString phone ) 00121 { 00122 return mCore->getNameByPhone( phone ); 00123 } 00124 00125 void KAddressbookPart::save() 00126 { 00127 mCore->save(); 00128 } 00129 00130 void KAddressbookPart::exit() 00131 { 00132 mCore->queryClose(); 00133 00134 delete this; 00135 } 00136 00137 bool KAddressbookPart::openURL( const KUrl &url ) 00138 { 00139 kDebug(5720) <<"KAddressbookPart:openFile()"; 00140 00141 mCore->widget()->show(); 00142 00143 if ( !url.isEmpty() ) 00144 mCore->importVCard( url ); 00145 00146 emit setWindowCaption( url.prettyUrl() ); 00147 00148 return true; 00149 } 00150 00151 bool KAddressbookPart::openFile() 00152 { 00153 return false; 00154 } 00155 00156 bool KAddressbookPart::handleCommandLine() 00157 { 00158 return mCore->handleCommandLine(); 00159 } 00160 00161 void KAddressbookPart::guiActivateEvent( KParts::GUIActivateEvent *e ) 00162 { 00163 kDebug(5720) <<"KAddressbookPart::guiActivateEvent"; 00164 KParts::ReadOnlyPart::guiActivateEvent( e ); 00165 00166 if ( e->activated() ) 00167 mCore->reinitXMLGUI(); 00168 00169 if ( !e->activated() ) { 00170 mCore->statusBar()->removeItem( 1 ); 00171 mCore->statusBar()->removeItem( 2 ); 00172 } 00173 } 00174 00175 #include "kaddressbook_part.moc"
KDE 4.2 API Reference