kaddressbook

imeditorwidget.h

00001 /*
00002   IM addresses editor widget for KAddressbook
00003 
00004   Copyright (c) 2004 Will Stephenson   <lists@stevello.free-online.co.uk>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #ifndef IMEDITORWIDGET_H
00026 #define IMEDITORWIDGET_H
00027 
00028 #include <qvaluelist.h>
00029 #include <klistview.h>
00030 #include <kdialogbase.h>
00031 
00032 #include "contacteditorwidget.h"
00033 
00034 
00035 class AddressWidget;
00036 class KPluginInfo;
00037 class IMEditorBase;
00038 
00039 enum IMContext { Any, Home, Work };
00040 
00041 /* Note regarding Context:
00042  * It wasn not possible to get an idea of Context into Kopete in time for KDE 3.3,
00043  * so it has been removed from the UI and functionally disabled in the code.
00044  */
00045 
00049 class IMEditorWidget : public KDialogBase
00050 {
00051   Q_OBJECT
00052 
00053   public:
00054     IMEditorWidget( QWidget *parent, const QString &preferredIM, const char *name = 0 );
00055     ~IMEditorWidget() {};
00056 
00057     void loadContact( KABC::Addressee *addr );
00058     void storeContact( KABC::Addressee *addr );
00059     void setReadOnly( bool readOnly );
00060     QValueList<KPluginInfo *> availableProtocols() const;
00061     bool isModified() const;
00062     QString preferred() const;
00063 
00064   protected slots:
00065     void slotUpdateButtons();
00066     void slotAdd();
00067     void slotEdit();
00068     void slotDelete();
00069     void slotSetStandard();
00070 
00071   protected:
00075     static void splitField( const QString &str, QString &app, QString &name, QString &value );
00076 
00080     KPluginInfo * protocolFromString( const QString &fieldValue ) const;
00081 
00082   private:
00083     bool mReadOnly;
00084     bool mModified;
00085     QString mPreferred;
00086     IMEditorBase *mWidget;
00087     void setModified( bool modified );
00088 
00089     // Used to track changed protocols to reduce KABC writes
00090     QValueList<KPluginInfo *> mChangedProtocols;
00091     QValueList<KPluginInfo *> mProtocols;
00092 };
00093 
00098 // VCard has been disabled as there is no standard VCard location to store IM addresses yet.
00099 class IMAddressLVI : public KListViewItem
00100 {
00101   public:
00102     IMAddressLVI( KListView *parent, KPluginInfo * protocol,
00103                   const QString &address, const IMContext &context = Any );
00104 
00105     void setAddress( const QString &address );
00106     void setProtocol( KPluginInfo * protocol );
00107     void setContext( const IMContext &context );
00108     void activate();
00109 
00110     KPluginInfo * protocol() const;
00111     QString address() const;
00112     IMContext context() const;
00113 
00114     void setPreferred( bool preferred );
00115     bool preferred() const;
00116 
00117   protected:
00118     virtual void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
00119 
00120   private:
00121     KPluginInfo * mProtocol;
00122     bool mPreferred;
00123     IMContext mContext;
00124     QString mAddress;
00125 };
00126 
00127 #endif
00128 
KDE Home | KDE Accessibility Home | Description of Access Keys