kaddressbook

imeditorwidget.h
1 /*
2  IM addresses editor widget for KAddressbook
3 
4  Copyright (c) 2004 Will Stephenson <lists@stevello.free-online.co.uk>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #ifndef IMEDITORWIDGET_H
26 #define IMEDITORWIDGET_H
27 
28 #include <tqvaluelist.h>
29 #include <tdelistview.h>
30 #include <kdialogbase.h>
31 
32 #include "contacteditorwidget.h"
33 
34 
35 class AddressWidget;
36 class KPluginInfo;
37 class IMEditorBase;
38 
39 enum IMContext { Any, Home, Work };
40 
41 /* Note regarding Context:
42  * It wasn not possible to get an idea of Context into Kopete in time for KDE 3.3,
43  * so it has been removed from the UI and functionally disabled in the code.
44  */
45 
49 class IMEditorWidget : public KDialogBase
50 {
51  TQ_OBJECT
52 
53 
54  public:
55  IMEditorWidget( TQWidget *parent, const TQString &preferredIM, const char *name = 0 );
56  ~IMEditorWidget() {};
57 
58  void loadContact( TDEABC::Addressee *addr );
59  void storeContact( TDEABC::Addressee *addr );
60  void setReadOnly( bool readOnly );
61  TQValueList<KPluginInfo *> availableProtocols() const;
62  bool isModified() const;
63  TQString preferred() const;
64 
65  protected slots:
66  void slotUpdateButtons();
67  void slotAdd();
68  void slotEdit();
69  void slotDelete();
70  void slotSetStandard();
71 
72  protected:
76  static void splitField( const TQString &str, TQString &app, TQString &name, TQString &value );
77 
81  KPluginInfo * protocolFromString( const TQString &fieldValue ) const;
82 
83  private:
84  bool mReadOnly;
85  bool mModified;
86  TQString mPreferred;
87  IMEditorBase *mWidget;
88  void setModified( bool modified );
89 
90  // Used to track changed protocols to reduce KABC writes
91  TQValueList<KPluginInfo *> mChangedProtocols;
92  TQValueList<KPluginInfo *> mProtocols;
93 };
94 
99 // VCard has been disabled as there is no standard VCard location to store IM addresses yet.
100 class IMAddressLVI : public TDEListViewItem
101 {
102  public:
103  IMAddressLVI( TDEListView *parent, KPluginInfo * protocol,
104  const TQString &address, const IMContext &context = Any );
105 
106  void setAddress( const TQString &address );
107  void setProtocol( KPluginInfo * protocol );
108  void setContext( const IMContext &context );
109  void activate();
110 
111  KPluginInfo * protocol() const;
112  TQString address() const;
113  IMContext context() const;
114 
115  void setPreferred( bool preferred );
116  bool preferred() const;
117 
118  protected:
119  virtual void paintCell( TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment );
120 
121  private:
122  KPluginInfo * mProtocol;
123  bool mPreferred;
124  IMContext mContext;
125  TQString mAddress;
126 };
127 
128 #endif
129 
List view item representing a single IM address.
The widget we add to KAddressbook's contact editor dialog.
static void splitField(const TQString &str, TQString &app, TQString &name, TQString &value)
Helper method to split the contents of an addressbook field up.
KPluginInfo * protocolFromString(const TQString &fieldValue) const
Find a protocol that matches the KABC key, or 0 if none found.