kaddressbook

kaddressbookview.cpp
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#include <tqpopupmenu.h>
26
27#include <tdeabc/addressbook.h>
28#include <tdeabc/distributionlistdialog.h>
29#include <tdeconfig.h>
30#include <kdebug.h>
31#include <tdelocale.h>
32#include <kxmlguifactory.h>
33#include <kxmlguiclient.h>
34
35#include "core.h"
36#include "searchmanager.h"
37
38#include "kaddressbookview.h"
39
40KAddressBookView::KAddressBookView( KAB::Core *core, TQWidget *parent,
41 const char *name )
42 : TQWidget( parent, name ), mCore( core ), mFieldList()
43{
44 initGUI();
45
46 connect( mCore->searchManager(), TQ_SIGNAL( contactsUpdated() ),
47 TQ_SLOT( updateView() ) );
48}
49
50KAddressBookView::~KAddressBookView()
51{
52 kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - "
53 << name() << endl;
54}
55
56void KAddressBookView::readConfig( TDEConfig *config )
57{
58 mFieldList = TDEABC::Field::restoreFields( config, "KABCFields" );
59
60 if ( mFieldList.isEmpty() )
61 mFieldList = TDEABC::Field::defaultFields();
62
63 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
64 mDefaultFilterName = config->readEntry( "DefaultFilterName" );
65}
66
68{
69 // Most of writing the config is handled by the ConfigureViewDialog
70}
71
73{
74 bool first = true;
75 TQString emailAddrs;
76 const TQStringList uidList = selectedUids();
77 TDEABC::Addressee addr;
78 TQString email;
79
80 TQStringList::ConstIterator it;
81 for ( it = uidList.begin(); it != uidList.end(); ++it ) {
82 addr = mCore->addressBook()->findByUid( *it );
83
84 if ( !addr.isEmpty() ) {
85 TQString m = TQString();
86
87 if ( addr.emails().count() > 1 )
88 m = TDEABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
89
90 email = addr.fullEmail( m );
91
92 if ( !first )
93 emailAddrs += ", ";
94 else
95 first = false;
96
97 emailAddrs += email;
98 }
99 }
100
101 return emailAddrs;
102}
103
104TDEABC::Addressee::List KAddressBookView::addressees()
105{
106 if ( mFilter.isEmpty() )
107 return mCore->searchManager()->contacts();
108
109 TDEABC::Addressee::List addresseeList;
110 const TDEABC::Addressee::List contacts = mCore->searchManager()->contacts();
111
112 TDEABC::Addressee::List::ConstIterator it;
113 TDEABC::Addressee::List::ConstIterator contactsEnd( contacts.end() );
114 for ( it = contacts.begin(); it != contactsEnd; ++it ) {
115 if ( mFilter.filterAddressee( *it ) )
116 addresseeList.append( *it );
117 }
118
119 return addresseeList;
120}
121
122void KAddressBookView::initGUI()
123{
124 // Create the layout
125 TQVBoxLayout *layout = new TQVBoxLayout( this );
126
127 // Add the view widget
128 mViewWidget = new TQWidget( this );
129 layout->addWidget( mViewWidget );
130}
131
132TDEABC::Field::List KAddressBookView::fields() const
133{
134 return mFieldList;
135}
136
138{
139 mFilter = filter;
140}
141
142KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
143{
144 return mDefaultFilterType;
145}
146
148{
149 return mDefaultFilterName;
150}
151
152KAB::Core *KAddressBookView::core() const
153{
154 return mCore;
155}
156
157void KAddressBookView::popup( const TQPoint &point )
158{
159 if ( !mCore->guiClient() ) {
160 kdWarning() << "No GUI client set!" << endl;
161 return;
162 }
163
164 TQPopupMenu *menu = static_cast<TQPopupMenu*>( mCore->guiClient()->factory()->container( "RMBPopup",
165 mCore->guiClient() ) );
166 if ( menu )
167 menu->popup( point );
168}
169
171{
172 return mViewWidget;
173}
174
175void KAddressBookView::updateView()
176{
177 const TQStringList uidList = selectedUids();
178
179 refresh(); // This relists and deselects everything, in all views
180
181 if ( !uidList.isEmpty() ) {
182 // Keep previous selection
183 TQStringList::ConstIterator it, uidListEnd( uidList.end() );
184 for ( it = uidList.begin(); it != uidListEnd; ++it )
185 setSelected( *it, true );
186
187 } else {
188 const TDEABC::Addressee::List contacts = mCore->searchManager()->contacts();
189 if ( !contacts.isEmpty() )
190 setFirstSelected( true );
191 else
192 emit selected( TQString() );
193 }
194}
195
196ViewConfigureWidget *ViewFactory::configureWidget( TDEABC::AddressBook *ab,
197 TQWidget *parent,
198 const char *name )
199{
200 return new ViewConfigureWidget( ab, parent, name );
201}
202
203#include "kaddressbookview.moc"
Filter for AddressBook related objects (Addressees)
Definition: filter.h:40
bool isEmpty() const
Definition: filter.cpp:216
bool filterAddressee(const TDEABC::Addressee &a) const
Apply the filter to the addressee.
Definition: filter.cpp:75
virtual TQStringList selectedUids()=0
Must be overloaded in subclasses.
const TQString & defaultFilterName() const
TQWidget * viewWidget()
This method returns the widget that should be used as the parent for all view components.
void setFilter(const Filter &)
Sets the active filter.
void popup(const TQPoint &point)
Call this slot to popup a rmb menu.
KAB::Core * core() const
DefaultFilterType defaultFilterType() const
virtual void refresh(const TQString &uid=TQString())=0
Must be overloaded in subclasses to refresh the view.
void selected(const TQString &uid)
This signal should be emitted by a subclass whenever an addressee is selected.
virtual TQString selectedEmails()
Returns a TQString with all the selected email addresses concatenated together with a ',...
virtual void setSelected(const TQString &uid=TQString(), bool selected=true)=0
This method must be overloaded in subclasses.
virtual void writeConfig(TDEConfig *)
Called whenever this view should write the config.
TDEABC::Addressee::List addressees()
Returns a list of the addressees that should be displayed.
virtual void setFirstSelected(bool selected=true)=0
Selects the first contact in the view.
virtual void readConfig(TDEConfig *config)
Called whenever this view should read the config.
TDEABC::Field::List fields() const
Returns a list of the fields that should be displayed.
This widget is the base class for all view configuration widgets.