messageactions.cpp
00001 /* 00002 Copyright (c) 2007 Volker Krause <vkrause@kde.org> 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "messageactions.h" 00020 00021 #include "globalsettings.h" 00022 #include "kmfolder.h" 00023 #include "kmmessage.h" 00024 #include "kmreaderwin.h" 00025 00026 #include <tdeaction.h> 00027 #include <tdeactioncollection.h> 00028 #include <kdebug.h> 00029 #include <tdelocale.h> 00030 00031 #include <tqwidget.h> 00032 00033 using namespace KMail; 00034 00035 MessageActions::MessageActions( TDEActionCollection *ac, TQWidget * parent ) : 00036 TQObject( parent ), 00037 mParent( parent ), 00038 mActionCollection( ac ), 00039 mCurrentMessage( 0 ), 00040 mMessageView( 0 ) 00041 { 00042 mReplyActionMenu = new TDEActionMenu( i18n("Message->","&Reply"), 00043 "mail-reply-sender", mActionCollection, 00044 "message_reply_menu" ); 00045 connect( mReplyActionMenu, TQT_SIGNAL(activated()), this, 00046 TQT_SLOT(slotReplyToMsg()) ); 00047 00048 mReplyAction = new TDEAction( i18n("&Reply..."), "mail-reply-sender", Key_R, this, 00049 TQT_SLOT(slotReplyToMsg()), mActionCollection, "reply" ); 00050 mReplyActionMenu->insert( mReplyAction ); 00051 00052 mReplyAuthorAction = new TDEAction( i18n("Reply to A&uthor..."), "mail-reply-sender", 00053 SHIFT+Key_A, this, 00054 TQT_SLOT(slotReplyAuthorToMsg()), 00055 mActionCollection, "reply_author" ); 00056 mReplyActionMenu->insert( mReplyAuthorAction ); 00057 00058 mReplyAllAction = new TDEAction( i18n("Reply to &All..."), "mail-reply-all", 00059 Key_A, this, TQT_SLOT(slotReplyAllToMsg()), 00060 mActionCollection, "reply_all" ); 00061 mReplyActionMenu->insert( mReplyAllAction ); 00062 00063 mReplyListAction = new TDEAction( i18n("Reply to Mailing-&List..."), 00064 "mail_replylist", Key_L, this, 00065 TQT_SLOT(slotReplyListToMsg()), mActionCollection, 00066 "reply_list" ); 00067 mReplyActionMenu->insert( mReplyListAction ); 00068 00069 mNoQuoteReplyAction = new TDEAction( i18n("Reply Without &Quote..."), SHIFT+Key_R, 00070 this, TQT_SLOT(slotNoQuoteReplyToMsg()), mActionCollection, "noquotereply" ); 00071 00072 00073 mCreateTodoAction = new TDEAction( i18n("Create Task/Reminder..."), "mail_todo", 00074 0, this, TQT_SLOT(slotCreateTodo()), mActionCollection, 00075 "create_todo" ); 00076 00077 00078 mStatusMenu = new TDEActionMenu ( i18n( "Mar&k Message" ), 00079 mActionCollection, "set_status" ); 00080 00081 mStatusMenu->insert(new TDEAction(KGuiItem(i18n("Mark Message as &Read"), "kmmsgread", 00082 i18n("Mark selected messages as read")), 00083 0, this, TQT_SLOT(slotSetMsgStatusRead()), 00084 mActionCollection, "status_read")); 00085 00086 mStatusMenu->insert(new TDEAction(KGuiItem(i18n("Mark Message as &New"), "kmmsgnew", 00087 i18n("Mark selected messages as new")), 00088 0, this, TQT_SLOT(slotSetMsgStatusNew()), 00089 mActionCollection, "status_new" )); 00090 00091 mStatusMenu->insert(new TDEAction(KGuiItem(i18n("Mark Message as &Unread"), "kmmsgunseen", 00092 i18n("Mark selected messages as unread")), 00093 0, this, TQT_SLOT(slotSetMsgStatusUnread()), 00094 mActionCollection, "status_unread")); 00095 00096 mStatusMenu->insert( new TDEActionSeparator( this ) ); 00097 00098 mToggleFlagAction = new TDEToggleAction(i18n("Mark Message as &Important"), "mail_flag", 00099 0, this, TQT_SLOT(slotSetMsgStatusFlag()), 00100 mActionCollection, "status_flag"); 00101 mToggleFlagAction->setCheckedState( i18n("Remove &Important Message Mark") ); 00102 mStatusMenu->insert( mToggleFlagAction ); 00103 00104 mToggleTodoAction = new TDEToggleAction(i18n("Mark Message as &Action Item"), "mail_todo", 00105 0, this, TQT_SLOT(slotSetMsgStatusTodo()), 00106 mActionCollection, "status_todo"); 00107 mToggleTodoAction->setCheckedState( i18n("Remove &Action Item Message Mark") ); 00108 mStatusMenu->insert( mToggleTodoAction ); 00109 00110 mEditAction = new TDEAction( i18n("&Edit Message"), "edit", Key_T, this, 00111 TQT_SLOT(editCurrentMessage()), mActionCollection, "edit" ); 00112 mEditAction->plugAccel( mActionCollection->tdeaccel() ); 00113 00114 updateActions(); 00115 } 00116 00117 void MessageActions::setCurrentMessage(KMMessage * msg) 00118 { 00119 mCurrentMessage = msg; 00120 if ( !msg ) { 00121 mSelectedSernums.clear(); 00122 mVisibleSernums.clear(); 00123 } 00124 updateActions(); 00125 } 00126 00127 void MessageActions::setSelectedSernums(const TQValueList< TQ_UINT32 > & sernums) 00128 { 00129 mSelectedSernums = sernums; 00130 updateActions(); 00131 } 00132 00133 void MessageActions::setSelectedVisibleSernums(const TQValueList< TQ_UINT32 > & sernums) 00134 { 00135 mVisibleSernums = sernums; 00136 updateActions(); 00137 } 00138 00139 void MessageActions::updateActions() 00140 { 00141 bool singleMsg = (mCurrentMessage != 0); 00142 if ( mCurrentMessage && mCurrentMessage->parent() ) { 00143 if ( mCurrentMessage->parent()->isTemplates() ) 00144 singleMsg = false; 00145 } 00146 const bool multiVisible = mVisibleSernums.count() > 0 || mCurrentMessage; 00147 const bool flagsAvailable = GlobalSettings::self()->allowLocalFlags() || 00148 !((mCurrentMessage && mCurrentMessage->parent()) ? mCurrentMessage->parent()->isReadOnly() : true); 00149 00150 mCreateTodoAction->setEnabled( singleMsg ); 00151 mReplyActionMenu->setEnabled( singleMsg ); 00152 mReplyAction->setEnabled( singleMsg ); 00153 mNoQuoteReplyAction->setEnabled( singleMsg ); 00154 mReplyAuthorAction->setEnabled( singleMsg ); 00155 mReplyAllAction->setEnabled( singleMsg ); 00156 mReplyListAction->setEnabled( singleMsg ); 00157 mNoQuoteReplyAction->setEnabled( singleMsg ); 00158 00159 mStatusMenu->setEnabled( multiVisible ); 00160 mToggleFlagAction->setEnabled( flagsAvailable ); 00161 mToggleTodoAction->setEnabled( flagsAvailable ); 00162 00163 if ( mCurrentMessage ) { 00164 mToggleTodoAction->setChecked( mCurrentMessage->isTodo() ); 00165 mToggleFlagAction->setChecked( mCurrentMessage->isImportant() ); 00166 } 00167 00168 mEditAction->setEnabled( singleMsg ); 00169 } 00170 00171 template<typename T> void MessageActions::replyCommand() 00172 { 00173 if ( !mCurrentMessage ) 00174 return; 00175 const TQString text = mMessageView ? mMessageView->copyText() : ""; 00176 KMCommand *command = new T( mParent, mCurrentMessage, text ); 00177 connect( command, TQT_SIGNAL( completed( KMCommand * ) ), 00178 this, TQT_SIGNAL( replyActionFinished() ) ); 00179 command->start(); 00180 } 00181 00182 00183 void MessageActions::slotCreateTodo() 00184 { 00185 if ( !mCurrentMessage ) 00186 return; 00187 KMCommand *command = new CreateTodoCommand( mParent, mCurrentMessage ); 00188 command->start(); 00189 } 00190 00191 void MessageActions::setMessageView(KMReaderWin * msgView) 00192 { 00193 mMessageView = msgView; 00194 } 00195 00196 void MessageActions::slotReplyToMsg() 00197 { 00198 replyCommand<KMReplyToCommand>(); 00199 } 00200 00201 void MessageActions::slotReplyAuthorToMsg() 00202 { 00203 replyCommand<KMReplyAuthorCommand>(); 00204 } 00205 00206 void MessageActions::slotReplyListToMsg() 00207 { 00208 replyCommand<KMReplyListCommand>(); 00209 } 00210 00211 void MessageActions::slotReplyAllToMsg() 00212 { 00213 replyCommand<KMReplyToAllCommand>(); 00214 } 00215 00216 void MessageActions::slotNoQuoteReplyToMsg() 00217 { 00218 if ( !mCurrentMessage ) 00219 return; 00220 KMCommand *command = new KMNoQuoteReplyToCommand( mParent, mCurrentMessage ); 00221 command->start(); 00222 } 00223 00224 void MessageActions::slotSetMsgStatusNew() 00225 { 00226 setMessageStatus( KMMsgStatusNew ); 00227 } 00228 00229 void MessageActions::slotSetMsgStatusUnread() 00230 { 00231 setMessageStatus( KMMsgStatusUnread ); 00232 } 00233 00234 void MessageActions::slotSetMsgStatusRead() 00235 { 00236 setMessageStatus( KMMsgStatusRead ); 00237 } 00238 00239 void MessageActions::slotSetMsgStatusFlag() 00240 { 00241 setMessageStatus( KMMsgStatusFlag, true ); 00242 } 00243 00244 void MessageActions::slotSetMsgStatusTodo() 00245 { 00246 setMessageStatus( KMMsgStatusTodo, true ); 00247 } 00248 00249 void MessageActions::setMessageStatus( KMMsgStatus status, bool toggle ) 00250 { 00251 TQValueList<TQ_UINT32> serNums = mVisibleSernums; 00252 if ( serNums.isEmpty() && mCurrentMessage ) 00253 serNums.append( mCurrentMessage->getMsgSerNum() ); 00254 if ( serNums.empty() ) 00255 return; 00256 KMCommand *command = new KMSeStatusCommand( status, serNums, toggle ); 00257 command->start(); 00258 } 00259 00260 void MessageActions::editCurrentMessage() 00261 { 00262 if ( !mCurrentMessage ) 00263 return; 00264 KMCommand *command = 0; 00265 KMFolder *folder = mCurrentMessage->parent(); 00266 // edit, unlike send again, removes the message from the folder 00267 // we only want that for templates and drafts folders 00268 if ( folder && ( kmkernel->folderIsDraftOrOutbox( folder ) || 00269 kmkernel->folderIsTemplates( folder ) ) ) 00270 command = new KMEditMsgCommand( mParent, mCurrentMessage ); 00271 else 00272 command = new KMResendMessageCommand( mParent, mCurrentMessage ); 00273 command->start(); 00274 } 00275 00276 #include "messageactions.moc"