summaryrefslogtreecommitdiffstats
path: root/kmail/messageactions.cpp
blob: c1f569925add09b527344cc5003aefc95479653e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
    Copyright (c) 2007 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "messageactions.h"

#include "globalsettings.h"
#include "kmfolder.h"
#include "kmmessage.h"
#include "kmreaderwin.h"

#include <kaction.h>
#include <kactioncollection.h>
#include <kdebug.h>
#include <klocale.h>

#include <tqwidget.h>

using namespace KMail;

MessageActions::MessageActions( KActionCollection *ac, TQWidget * parent ) :
    TQObject( parent ),
    mParent( parent ),
    mActionCollection( ac ),
    mCurrentMessage( 0 ),
    mMessageView( 0 )
{
    mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
                                      "mail_reply", mActionCollection,
                                      "message_reply_menu" );
  connect( mReplyActionMenu, TQT_SIGNAL(activated()), this,
           TQT_SLOT(slotReplyToMsg()) );

  mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
                              TQT_SLOT(slotReplyToMsg()), mActionCollection, "reply" );
  mReplyActionMenu->insert( mReplyAction );

  mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
                                    SHIFT+Key_A, this,
                                    TQT_SLOT(slotReplyAuthorToMsg()),
                                    mActionCollection, "reply_author" );
  mReplyActionMenu->insert( mReplyAuthorAction );

  mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
                                 Key_A, this, TQT_SLOT(slotReplyAllToMsg()),
                                 mActionCollection, "reply_all" );
  mReplyActionMenu->insert( mReplyAllAction );

  mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
                                  "mail_replylist", Key_L, this,
                                  TQT_SLOT(slotReplyListToMsg()), mActionCollection,
                                  "reply_list" );
  mReplyActionMenu->insert( mReplyListAction );

  mNoQuoteReplyAction = new KAction( i18n("Reply Without &Quote..."), SHIFT+Key_R,
    this, TQT_SLOT(slotNoQuoteReplyToMsg()), mActionCollection, "noquotereply" );


  mCreateTodoAction = new KAction( i18n("Create Task/Reminder..."), "mail_todo",
                                   0, this, TQT_SLOT(slotCreateTodo()), mActionCollection,
                                   "create_todo" );


  mStatusMenu = new KActionMenu ( i18n( "Mar&k Message" ),
                                  mActionCollection, "set_status" );

  mStatusMenu->insert(new KAction(KGuiItem(i18n("Mark Message as &Read"), "kmmsgread",
                                          i18n("Mark selected messages as read")),
                                 0, this, TQT_SLOT(slotSetMsgStatusRead()),
                                 mActionCollection, "status_read"));

  mStatusMenu->insert(new KAction(KGuiItem(i18n("Mark Message as &New"), "kmmsgnew",
                                          i18n("Mark selected messages as new")),
                                 0, this, TQT_SLOT(slotSetMsgStatusNew()),
                                 mActionCollection, "status_new" ));

  mStatusMenu->insert(new KAction(KGuiItem(i18n("Mark Message as &Unread"), "kmmsgunseen",
                                          i18n("Mark selected messages as unread")),
                                 0, this, TQT_SLOT(slotSetMsgStatusUnread()),
                                 mActionCollection, "status_unread"));

  mStatusMenu->insert( new KActionSeparator( this ) );

  mToggleFlagAction = new KToggleAction(i18n("Mark Message as &Important"), "mail_flag",
                                 0, this, TQT_SLOT(slotSetMsgStatusFlag()),
                                 mActionCollection, "status_flag");
  mToggleFlagAction->setCheckedState( i18n("Remove &Important Message Mark") );
  mStatusMenu->insert( mToggleFlagAction );

  mToggleTodoAction = new KToggleAction(i18n("Mark Message as &Action Item"), "mail_todo",
                                 0, this, TQT_SLOT(slotSetMsgStatusTodo()),
                                 mActionCollection, "status_todo");
  mToggleTodoAction->setCheckedState( i18n("Remove &Action Item Message Mark") );
  mStatusMenu->insert( mToggleTodoAction );

  mEditAction = new KAction( i18n("&Edit Message"), "edit", Key_T, this,
                            TQT_SLOT(editCurrentMessage()), mActionCollection, "edit" );
  mEditAction->plugAccel( mActionCollection->kaccel() );

  updateActions();
}

void MessageActions::setCurrentMessage(KMMessage * msg)
{
  mCurrentMessage = msg;
  if ( !msg ) {
    mSelectedSernums.clear();
    mVisibleSernums.clear();
  }
  updateActions();
}

void MessageActions::setSelectedSernums(const TQValueList< TQ_UINT32 > & sernums)
{
  mSelectedSernums = sernums;
  updateActions();
}

void MessageActions::setSelectedVisibleSernums(const TQValueList< TQ_UINT32 > & sernums)
{
  mVisibleSernums = sernums;
  updateActions();
}

void MessageActions::updateActions()
{
  bool singleMsg = (mCurrentMessage != 0);
  if ( mCurrentMessage && mCurrentMessage->parent() ) {
    if ( mCurrentMessage->parent()->isTemplates() )
      singleMsg = false;
  }
  const bool multiVisible = mVisibleSernums.count() > 0 || mCurrentMessage;
  const bool flagsAvailable = GlobalSettings::self()->allowLocalFlags() ||
      !((mCurrentMessage && mCurrentMessage->parent()) ? mCurrentMessage->parent()->isReadOnly() : true);

  mCreateTodoAction->setEnabled( singleMsg );
  mReplyActionMenu->setEnabled( singleMsg );
  mReplyAction->setEnabled( singleMsg );
  mNoQuoteReplyAction->setEnabled( singleMsg );
  mReplyAuthorAction->setEnabled( singleMsg );
  mReplyAllAction->setEnabled( singleMsg );
  mReplyListAction->setEnabled( singleMsg );
  mNoQuoteReplyAction->setEnabled( singleMsg );

  mStatusMenu->setEnabled( multiVisible );
  mToggleFlagAction->setEnabled( flagsAvailable );
  mToggleTodoAction->setEnabled( flagsAvailable );

  if ( mCurrentMessage ) {
    mToggleTodoAction->setChecked( mCurrentMessage->isTodo() );
    mToggleFlagAction->setChecked( mCurrentMessage->isImportant() );
  }

  mEditAction->setEnabled( singleMsg );
}

template<typename T> void MessageActions::replyCommand()
{
  if ( !mCurrentMessage )
    return;
  const TQString text = mMessageView ? mMessageView->copyText() : "";
  KMCommand *command = new T( mParent, mCurrentMessage, text );
  connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
           this, TQT_SIGNAL( replyActionFinished() ) );
  command->start();
}


void MessageActions::slotCreateTodo()
{
  if ( !mCurrentMessage )
    return;
  KMCommand *command = new CreateTodoCommand( mParent, mCurrentMessage );
  command->start();
}

void MessageActions::setMessageView(KMReaderWin * msgView)
{
  mMessageView = msgView;
}

void MessageActions::slotReplyToMsg()
{
  replyCommand<KMReplyToCommand>();
}

void MessageActions::slotReplyAuthorToMsg()
{
  replyCommand<KMReplyAuthorCommand>();
}

void MessageActions::slotReplyListToMsg()
{
  replyCommand<KMReplyListCommand>();
}

void MessageActions::slotReplyAllToMsg()
{
  replyCommand<KMReplyToAllCommand>();
}

void MessageActions::slotNoQuoteReplyToMsg()
{
  if ( !mCurrentMessage )
    return;
  KMCommand *command = new KMNoQuoteReplyToCommand( mParent, mCurrentMessage );
  command->start();
}

void MessageActions::slotSetMsgStatusNew()
{
  setMessageStatus( KMMsgStatusNew );
}

void MessageActions::slotSetMsgStatusUnread()
{
  setMessageStatus( KMMsgStatusUnread );
}

void MessageActions::slotSetMsgStatusRead()
{
  setMessageStatus( KMMsgStatusRead );
}

void MessageActions::slotSetMsgStatusFlag()
{
  setMessageStatus( KMMsgStatusFlag, true );
}

void MessageActions::slotSetMsgStatusTodo()
{
  setMessageStatus( KMMsgStatusTodo, true );
}

void MessageActions::setMessageStatus( KMMsgStatus status, bool toggle )
{
  TQValueList<TQ_UINT32> serNums = mVisibleSernums;
  if ( serNums.isEmpty() && mCurrentMessage )
    serNums.append( mCurrentMessage->getMsgSerNum() );
  if ( serNums.empty() )
    return;
  KMCommand *command = new KMSeStatusCommand( status, serNums, toggle );
  command->start();
}

void MessageActions::editCurrentMessage()
{
  if ( !mCurrentMessage )
    return;
  KMCommand *command = 0;
  KMFolder *folder = mCurrentMessage->parent();
  // edit, unlike send again, removes the message from the folder
  // we only want that for templates and drafts folders
  if ( folder && ( kmkernel->folderIsDraftOrOutbox( folder ) ||
       kmkernel->folderIsTemplates( folder ) ) )
    command = new KMEditMsgCommand( mParent, mCurrentMessage );
  else
    command = new KMResendMessageCommand( mParent, mCurrentMessage );
  command->start();
}

#include "messageactions.moc"