kaddressbook

xxport.cpp
1 /*
2  This file is part of KAddressbook.
3  Copyright (c) 2003 Tobias Koenig <tokoe@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 <tqmap.h>
25 #include <tqsignalmapper.h>
26 
27 #include <tdeaction.h>
28 #include <kinstance.h>
29 #include <tdemessagebox.h>
30 #include <tdeapplication.h>
31 #include "xxport.h"
32 
33 using namespace KAB;
34 
35 class XXPort::XXPortPrivate
36 {
37  public:
38  TQSignalMapper *mExportMapper;
39  TQSignalMapper *mImportMapper;
40  TDEApplication *mKApp;
41 };
42 
43 XXPort::XXPort( TDEABC::AddressBook *ab, TQWidget *parent,
44  const char *name )
45  : TQObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
46  d( new XXPortPrivate )
47 {
48  setInstance( new TDEInstance( "kaddressbook" ) );
49 
50  d->mExportMapper = new TQSignalMapper( this );
51  d->mImportMapper = new TQSignalMapper( this );
52 
53  connect( d->mExportMapper, TQ_SIGNAL( mapped( const TQString& ) ),
54  TQ_SLOT( slotExportActivated( const TQString& ) ) );
55  connect( d->mImportMapper, TQ_SIGNAL( mapped( const TQString& ) ),
56  TQ_SLOT( slotImportActivated( const TQString& ) ) );
57 }
58 
59 XXPort::~XXPort()
60 {
61  delete d;
62  d = 0;
63 }
64 
65 bool XXPort::exportContacts( const TDEABC::AddresseeList&, const TQString& )
66 {
67  // do nothing
68  return false;
69 }
70 
71 TDEABC::AddresseeList XXPort::importContacts( const TQString& ) const
72 {
73  // do nothing
74  return TDEABC::AddresseeList();
75 }
76 
77 void XXPort::createImportAction( const TQString &label, const TQString &data )
78 {
79  TQString id = "file_import_" + identifier() + ( data.isEmpty() ? TQString( "" ) : "_" + data );
80  TDEAction *action = new TDEAction( label, 0, d->mImportMapper, TQ_SLOT( map() ), actionCollection(), id.latin1() );
81 
82  d->mImportMapper->setMapping( action, ( data.isEmpty() ? TQString( "<empty>" ) : data ) );
83 
84  setXMLFile( identifier() + "_xxportui.rc" );
85 }
86 
87 void XXPort::createExportAction( const TQString &label, const TQString &data )
88 {
89  TQString id = "file_export_" + identifier() + ( data.isEmpty() ? TQString( "" ) : "_" + data );
90  TDEAction *action = new TDEAction( label, 0, d->mExportMapper, TQ_SLOT( map() ), actionCollection(), id.latin1() );
91 
92  d->mExportMapper->setMapping( action, ( data.isEmpty() ? TQString( "<empty>" ) : data ) );
93 
94  setXMLFile( identifier() + "_xxportui.rc" );
95 }
96 
97 TDEABC::AddressBook *XXPort::addressBook() const
98 {
99  return mAddressBook;
100 }
101 
102 TQWidget *XXPort::parentWidget() const
103 {
104  return mParentWidget;
105 }
106 
107 void XXPort::setTDEApplication( TDEApplication *app )
108 {
109  d->mKApp = app;
110 }
111 
112 void XXPort::processEvents() const
113 {
114  if ( d->mKApp )
115  d->mKApp->processEvents();
116 }
117 
118 void XXPort::slotExportActivated( const TQString &data )
119 {
120  emit exportActivated( identifier(), ( data == "<empty>" ? TQString() : data ) );
121 }
122 
123 void XXPort::slotImportActivated( const TQString &data )
124 {
125  emit importActivated( identifier(), ( data == "<empty>" ? TQString() : data ) );
126 }
127 
128 #include "xxport.moc"