19 #include "messageactions.h"
21 #include "globalsettings.h"
23 #include "kmmessage.h"
24 #include "kmreaderwin.h"
26 #include <tdeaction.h>
27 #include <tdeactioncollection.h>
29 #include <tdelocale.h>
33 using namespace KMail;
35 MessageActions::MessageActions( TDEActionCollection *ac, TQWidget * parent ) :
38 mActionCollection( ac ),
42 mReplyActionMenu =
new TDEActionMenu( i18n(
"Message->",
"&Reply"),
43 "mail-reply-sender", mActionCollection,
44 "message_reply_menu" );
45 connect( mReplyActionMenu, TQ_SIGNAL(activated()),
this,
46 TQ_SLOT(slotReplyToMsg()) );
48 mReplyAction =
new TDEAction( i18n(
"&Reply..."),
"mail-reply-sender", Key_R,
this,
49 TQ_SLOT(slotReplyToMsg()), mActionCollection,
"reply" );
50 mReplyActionMenu->insert( mReplyAction );
52 mReplyAuthorAction =
new TDEAction( i18n(
"Reply to A&uthor..."),
"mail-reply-sender",
54 TQ_SLOT(slotReplyAuthorToMsg()),
55 mActionCollection,
"reply_author" );
56 mReplyActionMenu->insert( mReplyAuthorAction );
58 mReplyAllAction =
new TDEAction( i18n(
"Reply to &All..."),
"mail-reply-all",
59 Key_A,
this, TQ_SLOT(slotReplyAllToMsg()),
60 mActionCollection,
"reply_all" );
61 mReplyActionMenu->insert( mReplyAllAction );
63 mReplyListAction =
new TDEAction( i18n(
"Reply to Mailing-&List..."),
64 "mail_replylist", Key_L,
this,
65 TQ_SLOT(slotReplyListToMsg()), mActionCollection,
67 mReplyActionMenu->insert( mReplyListAction );
69 mNoQuoteReplyAction =
new TDEAction( i18n(
"Reply Without &Quote..."), SHIFT+Key_R,
70 this, TQ_SLOT(slotNoQuoteReplyToMsg()), mActionCollection,
"noquotereply" );
73 mCreateTodoAction =
new TDEAction( i18n(
"Create Task/Reminder..."),
"mail_todo",
74 0,
this, TQ_SLOT(slotCreateTodo()), mActionCollection,
78 mStatusMenu =
new TDEActionMenu ( i18n(
"Mar&k Message" ),
79 mActionCollection,
"set_status" );
81 mStatusMenu->insert(
new TDEAction(KGuiItem(i18n(
"Mark Message as &Read"),
"kmmsgread",
82 i18n(
"Mark selected messages as read")),
83 0,
this, TQ_SLOT(slotSetMsgStatusRead()),
84 mActionCollection,
"status_read"));
86 mStatusMenu->insert(
new TDEAction(KGuiItem(i18n(
"Mark Message as &New"),
"kmmsgnew",
87 i18n(
"Mark selected messages as new")),
88 0,
this, TQ_SLOT(slotSetMsgStatusNew()),
89 mActionCollection,
"status_new" ));
91 mStatusMenu->insert(
new TDEAction(KGuiItem(i18n(
"Mark Message as &Unread"),
"kmmsgunseen",
92 i18n(
"Mark selected messages as unread")),
93 0,
this, TQ_SLOT(slotSetMsgStatusUnread()),
94 mActionCollection,
"status_unread"));
96 mStatusMenu->insert(
new TDEActionSeparator(
this ) );
98 mToggleFlagAction =
new TDEToggleAction(i18n(
"Mark Message as &Important"),
"mail_flag",
99 0,
this, TQ_SLOT(slotSetMsgStatusFlag()),
100 mActionCollection,
"status_flag");
101 mToggleFlagAction->setCheckedState( i18n(
"Remove &Important Message Mark") );
102 mStatusMenu->insert( mToggleFlagAction );
104 mToggleTodoAction =
new TDEToggleAction(i18n(
"Mark Message as &Action Item"),
"mail_todo",
105 0,
this, TQ_SLOT(slotSetMsgStatusTodo()),
106 mActionCollection,
"status_todo");
107 mToggleTodoAction->setCheckedState( i18n(
"Remove &Action Item Message Mark") );
108 mStatusMenu->insert( mToggleTodoAction );
110 mEditAction =
new TDEAction( i18n(
"&Edit Message"),
"edit", Key_T,
this,
111 TQ_SLOT(editCurrentMessage()), mActionCollection,
"edit" );
112 mEditAction->plugAccel( mActionCollection->tdeaccel() );
117 void MessageActions::setCurrentMessage(
KMMessage * msg)
119 mCurrentMessage = msg;
121 mSelectedSernums.clear();
122 mVisibleSernums.clear();
127 void MessageActions::setSelectedSernums(
const TQValueList< TQ_UINT32 > & sernums)
129 mSelectedSernums = sernums;
133 void MessageActions::setSelectedVisibleSernums(
const TQValueList< TQ_UINT32 > & sernums)
135 mVisibleSernums = sernums;
139 void MessageActions::updateActions()
141 bool singleMsg = (mCurrentMessage != 0);
142 if ( mCurrentMessage && mCurrentMessage->parent() ) {
143 if ( mCurrentMessage->parent()->isTemplates() )
146 const bool multiVisible = mVisibleSernums.count() > 0 || mCurrentMessage;
147 const bool flagsAvailable = GlobalSettings::self()->allowLocalFlags() ||
148 !((mCurrentMessage && mCurrentMessage->parent()) ? mCurrentMessage->parent()->isReadOnly() :
true);
150 mCreateTodoAction->setEnabled( singleMsg );
151 mReplyActionMenu->setEnabled( singleMsg );
152 mReplyAction->setEnabled( singleMsg );
153 mNoQuoteReplyAction->setEnabled( singleMsg );
154 mReplyAuthorAction->setEnabled( singleMsg );
155 mReplyAllAction->setEnabled( singleMsg );
156 mReplyListAction->setEnabled( singleMsg );
157 mNoQuoteReplyAction->setEnabled( singleMsg );
159 mStatusMenu->setEnabled( multiVisible );
160 mToggleFlagAction->setEnabled( flagsAvailable );
161 mToggleTodoAction->setEnabled( flagsAvailable );
163 if ( mCurrentMessage ) {
164 mToggleTodoAction->setChecked( mCurrentMessage->isTodo() );
165 mToggleFlagAction->setChecked( mCurrentMessage->isImportant() );
168 mEditAction->setEnabled( singleMsg );
171 template<
typename T>
void MessageActions::replyCommand()
173 if ( !mCurrentMessage )
175 const TQString text = mMessageView ? mMessageView->
copyText() :
"";
176 KMCommand *command =
new T( mParent, mCurrentMessage, text );
177 connect( command, TQ_SIGNAL( completed( KMCommand * ) ),
178 this, TQ_SIGNAL( replyActionFinished() ) );
183 void MessageActions::slotCreateTodo()
185 if ( !mCurrentMessage )
187 KMCommand *command =
new CreateTodoCommand( mParent, mCurrentMessage );
191 void MessageActions::setMessageView(
KMReaderWin * msgView)
193 mMessageView = msgView;
196 void MessageActions::slotReplyToMsg()
198 replyCommand<KMReplyToCommand>();
201 void MessageActions::slotReplyAuthorToMsg()
203 replyCommand<KMReplyAuthorCommand>();
206 void MessageActions::slotReplyListToMsg()
208 replyCommand<KMReplyListCommand>();
211 void MessageActions::slotReplyAllToMsg()
213 replyCommand<KMReplyToAllCommand>();
216 void MessageActions::slotNoQuoteReplyToMsg()
218 if ( !mCurrentMessage )
220 KMCommand *command =
new KMNoQuoteReplyToCommand( mParent, mCurrentMessage );
224 void MessageActions::slotSetMsgStatusNew()
226 setMessageStatus( KMMsgStatusNew );
229 void MessageActions::slotSetMsgStatusUnread()
231 setMessageStatus( KMMsgStatusUnread );
234 void MessageActions::slotSetMsgStatusRead()
236 setMessageStatus( KMMsgStatusRead );
239 void MessageActions::slotSetMsgStatusFlag()
241 setMessageStatus( KMMsgStatusFlag,
true );
244 void MessageActions::slotSetMsgStatusTodo()
246 setMessageStatus( KMMsgStatusTodo,
true );
249 void MessageActions::setMessageStatus( KMMsgStatus status,
bool toggle )
251 TQValueList<TQ_UINT32> serNums = mVisibleSernums;
252 if ( serNums.isEmpty() && mCurrentMessage )
253 serNums.append( mCurrentMessage->getMsgSerNum() );
254 if ( serNums.empty() )
256 KMCommand *command =
new KMSeStatusCommand( status, serNums, toggle );
260 void MessageActions::editCurrentMessage()
262 if ( !mCurrentMessage )
264 KMCommand *command = 0;
265 KMFolder *folder = mCurrentMessage->parent();
268 if ( folder && ( kmkernel->folderIsDraftOrOutbox( folder ) ||
269 kmkernel->folderIsTemplates( folder ) ) )
270 command =
new KMEditMsgCommand( mParent, mCurrentMessage );
272 command =
new KMResendMessageCommand( mParent, mCurrentMessage );
276 #include "messageactions.moc"
This class implements a "reader window", that is a window used for reading or viewing messages.
TQString copyText()
Return selected text.