kaddressbook

kaddressbook_part.cpp
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of TQt, and distribute the resulting executable,
21 without including the source code for TQt in the source distribution.
22*/
23
24#include <tqlayout.h>
25
26#include <tdeaction.h>
27#include <tdeapplication.h>
28#include <kdebug.h>
29#include <kiconloader.h>
30#include <kinstance.h>
31#include <tdelocale.h>
32#include <tdeparts/genericfactory.h>
33#include <tdeparts/statusbarextension.h>
34#include <kstatusbar.h>
35
36#include "kabcore.h"
37#include "kabprefs.h"
38#include "kaddressbookiface.h"
39
40#include "kaddressbook_part.h"
41
42typedef KParts::GenericFactory< KAddressbookPart > KAddressbookFactory;
43K_EXPORT_COMPONENT_FACTORY( libkaddressbookpart, KAddressbookFactory )
44
45KAddressbookPart::KAddressbookPart( TQWidget *parentWidget, const char *widgetName,
46 TQObject *parent, const char *name,
47 const TQStringList & )
48 : DCOPObject( "KAddressBookIface" ), KParts::ReadOnlyPart( parent, name )
49{
50 setInstance( KAddressbookFactory::instance() );
51
52 // create a canvas to insert our widget
53 TQWidget *canvas = new TQWidget( parentWidget, widgetName );
54 canvas->setFocusPolicy( TQWidget::ClickFocus );
55 setWidget( canvas );
56
57 TQVBoxLayout *topLayout = new TQVBoxLayout( canvas );
58
59 TDEGlobal::iconLoader()->addAppDir( "kaddressbook" );
60
61 mCore = new KABCore( this, true, canvas );
62 mCore->restoreSettings();
63 topLayout->addWidget( mCore->widget() );
64
65 KParts::StatusBarExtension *statusBar = new KParts::StatusBarExtension( this );
66 mCore->setStatusBar( statusBar->statusBar() );
67
68 setXMLFile( "kaddressbook_part.rc" );
69}
70
71KAddressbookPart::~KAddressbookPart()
72{
73 mCore->save();
74 mCore->saveSettings();
75
76 KABPrefs::instance()->writeConfig();
77 closeURL();
78}
79
80TDEAboutData *KAddressbookPart::createAboutData()
81{
82 return KABCore::createAboutData();
83}
84
85void KAddressbookPart::addEmail( TQString addr )
86{
87 mCore->addEmail( addr );
88}
89
90void KAddressbookPart::importVCard( const KURL& url )
91{
92 mCore->importVCard( url );
93}
94
95void KAddressbookPart::importVCardFromData( const TQString& vCard )
96{
97 mCore->importVCardFromData( vCard );
98}
99
100ASYNC KAddressbookPart::showContactEditor( TQString uid )
101{
102 mCore->editContact( uid );
103}
104
105void KAddressbookPart::newContact()
106{
107 mCore->newContact();
108}
109
110
111void KAddressbookPart::newDistributionList()
112{
113 mCore->newDistributionList();
114}
115
116TQString KAddressbookPart::getNameByPhone( TQString phone )
117{
118 return mCore->getNameByPhone( phone );
119}
120
121void KAddressbookPart::save()
122{
123 mCore->save();
124}
125
126void KAddressbookPart::exit()
127{
128 mCore->queryClose();
129
130 delete this;
131}
132
133bool KAddressbookPart::openURL( const KURL &url )
134{
135 kdDebug(5720) << "KAddressbookPart:openFile()" << endl;
136
137 mCore->widget()->show();
138
139 if ( !url.isEmpty() )
140 mCore->importVCard( url );
141
142 emit setWindowCaption( url.prettyURL() );
143
144 return true;
145}
146
147bool KAddressbookPart::openFile()
148{
149 return false;
150}
151
152bool KAddressbookPart::handleCommandLine()
153{
154 return mCore->handleCommandLine( this );
155}
156
157void KAddressbookPart::syncAllResources()
158{
159 mCore->save();
160 mCore->load();
161}
162
163void KAddressbookPart::guiActivateEvent( KParts::GUIActivateEvent *e )
164{
165 kdDebug(5720) << "KAddressbookPart::guiActivateEvent" << endl;
166 KParts::ReadOnlyPart::guiActivateEvent( e );
167
168 if ( e->activated() )
169 mCore->reinitXMLGUI();
170
171 if ( !e->activated() ) {
172 mCore->statusBar()->removeItem( 1 );
173 mCore->statusBar()->removeItem( 2 );
174 }
175}
176
177void KAddressbookPart::loadProfile( const TQString& )
178{
179}
180
181void KAddressbookPart::saveToProfile( const TQString& ) const
182{
183}
184
185#include "kaddressbook_part.moc"