undocmds.cpp
00001 #include <qtextstream.h>
00002 #include <qapplication.h>
00003 #include <qclipboard.h>
00004
00005 #include <klocale.h>
00006 #include <kdebug.h>
00007 #include <kapplication.h>
00008 #include <kabc/addressbook.h>
00009
00010 #include "undocmds.h"
00011 #include "addresseeutil.h"
00012 #include "addresseeconfig.h"
00013
00015
00016
00017 PwDeleteCommand::PwDeleteCommand(KABC::AddressBook *doc,
00018 const QStringList &uidList)
00019 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList)
00020 {
00021 redo();
00022 }
00023
00024 PwDeleteCommand::~PwDeleteCommand()
00025 {
00026 }
00027
00028 QString PwDeleteCommand::name()
00029 {
00030 return i18n( "Delete" );
00031 }
00032
00033 void PwDeleteCommand::undo()
00034 {
00035
00036 KABC::Addressee::List::Iterator iter;
00037 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
00038 {
00039 mDocument->insertAddressee(*iter);
00040 }
00041
00042 mAddresseeList.clear();
00043 }
00044
00045 void PwDeleteCommand::redo()
00046 {
00047
00048
00049 KABC::Addressee a;
00050 QStringList::Iterator iter;
00051 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
00052 {
00053 a = mDocument->findByUid(*iter);
00054 mDocument->removeAddressee(a);
00055 mAddresseeList.append(a);
00056 AddresseeConfig cfg(a);
00057 cfg.remove();
00058 }
00059 }
00060
00062
00063
00064 PwPasteCommand::PwPasteCommand( KABC::AddressBook *doc,
00065 const QString &clipboard )
00066 : Command(), mDocument(doc), mUidList(), mClipboard(clipboard)
00067 {
00068 redo();
00069 }
00070
00071 QString PwPasteCommand::name()
00072 {
00073 return i18n( "Paste" );
00074 }
00075
00076 void PwPasteCommand::undo()
00077 {
00078 KABC::Addressee a;
00079 QStringList::Iterator it;
00080 for( it = mUidList.begin(); it != mUidList.end(); ++it )
00081 {
00082 a = mDocument->findByUid(*it);
00083 if (!a.isEmpty())
00084 mDocument->removeAddressee( a );
00085 }
00086
00087 mUidList.clear();
00088 }
00089
00090 void PwPasteCommand::redo()
00091 {
00092 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees(mClipboard);
00093
00094 KABC::Addressee::List::Iterator iter;
00095 for (iter = list.begin(); iter != list.end(); ++iter)
00096 {
00097 mDocument->insertAddressee(*iter);
00098 mUidList.append((*iter).uid());
00099 }
00100 }
00101
00103
00104
00105 PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a )
00106 : Command(), mDocument( doc ), mA( a )
00107 {
00108 mDocument->insertAddressee(mA);
00109 }
00110
00111 PwNewCommand::~PwNewCommand()
00112 {
00113 }
00114
00115 QString PwNewCommand::name()
00116 {
00117 return i18n( "New Contact" );
00118 }
00119
00120 void PwNewCommand::undo()
00121 {
00122 mDocument->removeAddressee( mA );
00123 }
00124
00125 void PwNewCommand::redo()
00126 {
00127 mDocument->insertAddressee( mA );
00128 }
00129
00131
00132
00133 PwEditCommand::PwEditCommand(KABC::AddressBook *doc,
00134 const KABC::Addressee &oldA,
00135 const KABC::Addressee &newA )
00136 : Command(), mDocument(doc), mOldA(oldA), mNewA(newA)
00137 {
00138 redo();
00139 }
00140
00141 PwEditCommand::~PwEditCommand()
00142 {
00143 }
00144
00145 QString PwEditCommand::name()
00146 {
00147 return i18n( "Entry Edit" );
00148 }
00149
00150 void PwEditCommand::undo()
00151 {
00152 mDocument->insertAddressee(mOldA);
00153 }
00154
00155 void PwEditCommand::redo()
00156 {
00157 mDocument->insertAddressee(mNewA);
00158 }
00159
00161
00162
00163 PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList)
00164 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList),
00165 mClipText(), mOldText()
00166 {
00167 redo();
00168 }
00169
00170 QString PwCutCommand::name()
00171 {
00172 return i18n( "Cut" );
00173 }
00174
00175 void PwCutCommand::undo()
00176 {
00177 KABC::Addressee::List::Iterator iter;
00178 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
00179 {
00180 mDocument->insertAddressee(*iter);
00181 }
00182 mAddresseeList.clear();
00183
00184 QClipboard *cb = QApplication::clipboard();
00185 kapp->processEvents();
00186 cb->setText( mOldText );
00187 }
00188
00189 void PwCutCommand::redo()
00190 {
00191 KABC::Addressee a;
00192 QStringList::Iterator iter;
00193 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
00194 {
00195 a = mDocument->findByUid(*iter);
00196 mDocument->removeAddressee(a);
00197 mAddresseeList.append(a);
00198 }
00199
00200
00201 mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList);
00202
00203 QClipboard *cb = QApplication::clipboard();
00204 mOldText = cb->text();
00205 kapp->processEvents();
00206 cb->setText( mClipText );
00207 }
This file is part of the documentation for kdelibs Version 3.1.4.