kmail

messageactions.cpp
1 /*
2  Copyright (c) 2007 Volker Krause <vkrause@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include "messageactions.h"
20 
21 #include "globalsettings.h"
22 #include "kmfolder.h"
23 #include "kmmessage.h"
24 #include "kmreaderwin.h"
25 
26 #include <tdeaction.h>
27 #include <tdeactioncollection.h>
28 #include <kdebug.h>
29 #include <tdelocale.h>
30 
31 #include <tqwidget.h>
32 
33 using namespace KMail;
34 
35 MessageActions::MessageActions( TDEActionCollection *ac, TQWidget * parent ) :
36  TQObject( parent ),
37  mParent( parent ),
38  mActionCollection( ac ),
39  mCurrentMessage( 0 ),
40  mMessageView( 0 )
41 {
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()) );
47 
48  mReplyAction = new TDEAction( i18n("&Reply..."), "mail-reply-sender", Key_R, this,
49  TQ_SLOT(slotReplyToMsg()), mActionCollection, "reply" );
50  mReplyActionMenu->insert( mReplyAction );
51 
52  mReplyAuthorAction = new TDEAction( i18n("Reply to A&uthor..."), "mail-reply-sender",
53  SHIFT+Key_A, this,
54  TQ_SLOT(slotReplyAuthorToMsg()),
55  mActionCollection, "reply_author" );
56  mReplyActionMenu->insert( mReplyAuthorAction );
57 
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 );
62 
63  mReplyListAction = new TDEAction( i18n("Reply to Mailing-&List..."),
64  "mail_replylist", Key_L, this,
65  TQ_SLOT(slotReplyListToMsg()), mActionCollection,
66  "reply_list" );
67  mReplyActionMenu->insert( mReplyListAction );
68 
69  mNoQuoteReplyAction = new TDEAction( i18n("Reply Without &Quote..."), SHIFT+Key_R,
70  this, TQ_SLOT(slotNoQuoteReplyToMsg()), mActionCollection, "noquotereply" );
71 
72 
73  mCreateTodoAction = new TDEAction( i18n("Create Task/Reminder..."), "mail_todo",
74  0, this, TQ_SLOT(slotCreateTodo()), mActionCollection,
75  "create_todo" );
76 
77 
78  mStatusMenu = new TDEActionMenu ( i18n( "Mar&k Message" ),
79  mActionCollection, "set_status" );
80 
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"));
85 
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" ));
90 
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"));
95 
96  mStatusMenu->insert( new TDEActionSeparator( this ) );
97 
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 );
103 
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 );
109 
110  mEditAction = new TDEAction( i18n("&Edit Message"), "edit", Key_T, this,
111  TQ_SLOT(editCurrentMessage()), mActionCollection, "edit" );
112  mEditAction->plugAccel( mActionCollection->tdeaccel() );
113 
114  updateActions();
115 }
116 
117 void MessageActions::setCurrentMessage(KMMessage * msg)
118 {
119  mCurrentMessage = msg;
120  if ( !msg ) {
121  mSelectedSernums.clear();
122  mVisibleSernums.clear();
123  }
124  updateActions();
125 }
126 
127 void MessageActions::setSelectedSernums(const TQValueList< TQ_UINT32 > & sernums)
128 {
129  mSelectedSernums = sernums;
130  updateActions();
131 }
132 
133 void MessageActions::setSelectedVisibleSernums(const TQValueList< TQ_UINT32 > & sernums)
134 {
135  mVisibleSernums = sernums;
136  updateActions();
137 }
138 
139 void MessageActions::updateActions()
140 {
141  bool singleMsg = (mCurrentMessage != 0);
142  if ( mCurrentMessage && mCurrentMessage->parent() ) {
143  if ( mCurrentMessage->parent()->isTemplates() )
144  singleMsg = false;
145  }
146  const bool multiVisible = mVisibleSernums.count() > 0 || mCurrentMessage;
147  const bool flagsAvailable = GlobalSettings::self()->allowLocalFlags() ||
148  !((mCurrentMessage && mCurrentMessage->parent()) ? mCurrentMessage->parent()->isReadOnly() : true);
149 
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 );
158 
159  mStatusMenu->setEnabled( multiVisible );
160  mToggleFlagAction->setEnabled( flagsAvailable );
161  mToggleTodoAction->setEnabled( flagsAvailable );
162 
163  if ( mCurrentMessage ) {
164  mToggleTodoAction->setChecked( mCurrentMessage->isTodo() );
165  mToggleFlagAction->setChecked( mCurrentMessage->isImportant() );
166  }
167 
168  mEditAction->setEnabled( singleMsg );
169 }
170 
171 template<typename T> void MessageActions::replyCommand()
172 {
173  if ( !mCurrentMessage )
174  return;
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() ) );
179  command->start();
180 }
181 
182 
183 void MessageActions::slotCreateTodo()
184 {
185  if ( !mCurrentMessage )
186  return;
187  KMCommand *command = new CreateTodoCommand( mParent, mCurrentMessage );
188  command->start();
189 }
190 
191 void MessageActions::setMessageView(KMReaderWin * msgView)
192 {
193  mMessageView = msgView;
194 }
195 
196 void MessageActions::slotReplyToMsg()
197 {
198  replyCommand<KMReplyToCommand>();
199 }
200 
201 void MessageActions::slotReplyAuthorToMsg()
202 {
203  replyCommand<KMReplyAuthorCommand>();
204 }
205 
206 void MessageActions::slotReplyListToMsg()
207 {
208  replyCommand<KMReplyListCommand>();
209 }
210 
211 void MessageActions::slotReplyAllToMsg()
212 {
213  replyCommand<KMReplyToAllCommand>();
214 }
215 
216 void MessageActions::slotNoQuoteReplyToMsg()
217 {
218  if ( !mCurrentMessage )
219  return;
220  KMCommand *command = new KMNoQuoteReplyToCommand( mParent, mCurrentMessage );
221  command->start();
222 }
223 
224 void MessageActions::slotSetMsgStatusNew()
225 {
226  setMessageStatus( KMMsgStatusNew );
227 }
228 
229 void MessageActions::slotSetMsgStatusUnread()
230 {
231  setMessageStatus( KMMsgStatusUnread );
232 }
233 
234 void MessageActions::slotSetMsgStatusRead()
235 {
236  setMessageStatus( KMMsgStatusRead );
237 }
238 
239 void MessageActions::slotSetMsgStatusFlag()
240 {
241  setMessageStatus( KMMsgStatusFlag, true );
242 }
243 
244 void MessageActions::slotSetMsgStatusTodo()
245 {
246  setMessageStatus( KMMsgStatusTodo, true );
247 }
248 
249 void MessageActions::setMessageStatus( KMMsgStatus status, bool toggle )
250 {
251  TQValueList<TQ_UINT32> serNums = mVisibleSernums;
252  if ( serNums.isEmpty() && mCurrentMessage )
253  serNums.append( mCurrentMessage->getMsgSerNum() );
254  if ( serNums.empty() )
255  return;
256  KMCommand *command = new KMSeStatusCommand( status, serNums, toggle );
257  command->start();
258 }
259 
260 void MessageActions::editCurrentMessage()
261 {
262  if ( !mCurrentMessage )
263  return;
264  KMCommand *command = 0;
265  KMFolder *folder = mCurrentMessage->parent();
266  // edit, unlike send again, removes the message from the folder
267  // we only want that for templates and drafts folders
268  if ( folder && ( kmkernel->folderIsDraftOrOutbox( folder ) ||
269  kmkernel->folderIsTemplates( folder ) ) )
270  command = new KMEditMsgCommand( mParent, mCurrentMessage );
271  else
272  command = new KMResendMessageCommand( mParent, mCurrentMessage );
273  command->start();
274 }
275 
276 #include "messageactions.moc"
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
This class implements a "reader window", that is a window used for reading or viewing messages.
Definition: kmreaderwin.h:75
TQString copyText()
Return selected text.
folderdiaquotatab.h
Definition: aboutdata.cpp:40