kmail

messageactions.cpp

Go to the documentation of this file.
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 <kaction.h>
00027 #include <kactioncollection.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 
00031 #include <qwidget.h>
00032 
00033 using namespace KMail;
00034 
00035 MessageActions::MessageActions( KActionCollection *ac, QWidget * parent ) :
00036     QObject( parent ),
00037     mParent( parent ),
00038     mActionCollection( ac ),
00039     mCurrentMessage( 0 ),
00040     mMessageView( 0 )
00041 {
00042     mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00043                                       "mail_reply", mActionCollection,
00044                                       "message_reply_menu" );
00045   connect( mReplyActionMenu, SIGNAL(activated()), this,
00046            SLOT(slotReplyToMsg()) );
00047 
00048   mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00049                               SLOT(slotReplyToMsg()), mActionCollection, "reply" );
00050   mReplyActionMenu->insert( mReplyAction );
00051 
00052   mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00053                                     SHIFT+Key_A, this,
00054                                     SLOT(slotReplyAuthorToMsg()),
00055                                     mActionCollection, "reply_author" );
00056   mReplyActionMenu->insert( mReplyAuthorAction );
00057 
00058   mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00059                                  Key_A, this, SLOT(slotReplyAllToMsg()),
00060                                  mActionCollection, "reply_all" );
00061   mReplyActionMenu->insert( mReplyAllAction );
00062 
00063   mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00064                                   "mail_replylist", Key_L, this,
00065                                   SLOT(slotReplyListToMsg()), mActionCollection,
00066                                   "reply_list" );
00067   mReplyActionMenu->insert( mReplyListAction );
00068 
00069   mNoQuoteReplyAction = new KAction( i18n("Reply Without &Quote..."), SHIFT+Key_R,
00070     this, SLOT(slotNoQuoteReplyToMsg()), mActionCollection, "noquotereply" );
00071 
00072 
00073   mCreateTodoAction = new KAction( i18n("Create Task/Reminder..."), "mail_todo",
00074                                    0, this, SLOT(slotCreateTodo()), mActionCollection,
00075                                    "create_todo" );
00076 
00077 
00078   mStatusMenu = new KActionMenu ( i18n( "Mar&k Message" ),
00079                                   mActionCollection, "set_status" );
00080 
00081   mStatusMenu->insert(new KAction(KGuiItem(i18n("Mark Message as &Read"), "kmmsgread",
00082                                           i18n("Mark selected messages as read")),
00083                                  0, this, SLOT(slotSetMsgStatusRead()),
00084                                  mActionCollection, "status_read"));
00085 
00086   mStatusMenu->insert(new KAction(KGuiItem(i18n("Mark Message as &New"), "kmmsgnew",
00087                                           i18n("Mark selected messages as new")),
00088                                  0, this, SLOT(slotSetMsgStatusNew()),
00089                                  mActionCollection, "status_new" ));
00090 
00091   mStatusMenu->insert(new KAction(KGuiItem(i18n("Mark Message as &Unread"), "kmmsgunseen",
00092                                           i18n("Mark selected messages as unread")),
00093                                  0, this, SLOT(slotSetMsgStatusUnread()),
00094                                  mActionCollection, "status_unread"));
00095 
00096   mStatusMenu->insert( new KActionSeparator( this ) );
00097 
00098   mToggleFlagAction = new KToggleAction(i18n("Mark Message as &Important"), "mail_flag",
00099                                  0, this, SLOT(slotSetMsgStatusFlag()),
00100                                  mActionCollection, "status_flag");
00101   mToggleFlagAction->setCheckedState( i18n("Remove &Important Message Mark") );
00102   mStatusMenu->insert( mToggleFlagAction );
00103 
00104   mToggleTodoAction = new KToggleAction(i18n("Mark Message as &Action Item"), "mail_todo",
00105                                  0, this, SLOT(slotSetMsgStatusTodo()),
00106                                  mActionCollection, "status_todo");
00107   mToggleTodoAction->setCheckedState( i18n("Remove &Action Item Message Mark") );
00108   mStatusMenu->insert( mToggleTodoAction );
00109 
00110   mEditAction = new KAction( i18n("&Edit Message"), "edit", Key_T, this,
00111                             SLOT(editCurrentMessage()), mActionCollection, "edit" );
00112   mEditAction->plugAccel( mActionCollection->kaccel() );
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 QValueList< Q_UINT32 > & sernums)
00128 {
00129   mSelectedSernums = sernums;
00130   updateActions();
00131 }
00132 
00133 void MessageActions::setSelectedVisibleSernums(const QValueList< Q_UINT32 > & sernums)
00134 {
00135   mVisibleSernums = sernums;
00136   updateActions();
00137 }
00138 
00139 void MessageActions::updateActions()
00140 {
00141   const bool singleMsg = (mCurrentMessage != 0);
00142   const bool multiVisible = mVisibleSernums.count() > 0 || mCurrentMessage;
00143   const bool flagsAvailable = GlobalSettings::self()->allowLocalFlags() ||
00144       !((mCurrentMessage && mCurrentMessage->parent()) ? mCurrentMessage->parent()->isReadOnly() : true);
00145 
00146   mCreateTodoAction->setEnabled( singleMsg );
00147   mReplyActionMenu->setEnabled( singleMsg );
00148   mReplyAction->setEnabled( singleMsg );
00149   mNoQuoteReplyAction->setEnabled( singleMsg );
00150   mReplyAuthorAction->setEnabled( singleMsg );
00151   mReplyAllAction->setEnabled( singleMsg );
00152   mReplyListAction->setEnabled( singleMsg );
00153   mNoQuoteReplyAction->setEnabled( singleMsg );
00154 
00155   mStatusMenu->setEnabled( multiVisible );
00156   mToggleFlagAction->setEnabled( flagsAvailable );
00157   mToggleTodoAction->setEnabled( flagsAvailable );
00158 
00159   if ( mCurrentMessage ) {
00160     mToggleTodoAction->setChecked( mCurrentMessage->isTodo() );
00161     mToggleFlagAction->setChecked( mCurrentMessage->isImportant() );
00162   }
00163 
00164   mEditAction->setEnabled( singleMsg );
00165 }
00166 
00167 void MessageActions::slotCreateTodo()
00168 {
00169   if ( !mCurrentMessage )
00170     return;
00171   KMCommand *command = new CreateTodoCommand( mParent, mCurrentMessage );
00172   command->start();
00173 }
00174 
00175 void MessageActions::setMessageView(KMReaderWin * msgView)
00176 {
00177   mMessageView = msgView;
00178 }
00179 
00180 void MessageActions::slotReplyToMsg()
00181 {
00182   replyCommand<KMReplyToCommand>();
00183 }
00184 
00185 void MessageActions::slotReplyAuthorToMsg()
00186 {
00187   replyCommand<KMReplyAuthorCommand>();
00188 }
00189 
00190 void MessageActions::slotReplyListToMsg()
00191 {
00192   replyCommand<KMReplyListCommand>();
00193 }
00194 
00195 void MessageActions::slotReplyAllToMsg()
00196 {
00197   replyCommand<KMReplyToAllCommand>();
00198 }
00199 
00200 void MessageActions::slotNoQuoteReplyToMsg()
00201 {
00202   if ( !mCurrentMessage )
00203     return;
00204   KMCommand *command = new KMNoQuoteReplyToCommand( mParent, mCurrentMessage );
00205   command->start();
00206 }
00207 
00208 void MessageActions::slotSetMsgStatusNew()
00209 {
00210   setMessageStatus( KMMsgStatusNew );
00211 }
00212 
00213 void MessageActions::slotSetMsgStatusUnread()
00214 {
00215   setMessageStatus( KMMsgStatusUnread );
00216 }
00217 
00218 void MessageActions::slotSetMsgStatusRead()
00219 {
00220   setMessageStatus( KMMsgStatusRead );
00221 }
00222 
00223 void MessageActions::slotSetMsgStatusFlag()
00224 {
00225   setMessageStatus( KMMsgStatusFlag, true );
00226 }
00227 
00228 void MessageActions::slotSetMsgStatusTodo()
00229 {
00230   setMessageStatus( KMMsgStatusTodo, true );
00231 }
00232 
00233 void MessageActions::setMessageStatus( KMMsgStatus status, bool toggle )
00234 {
00235   QValueList<Q_UINT32> serNums = mVisibleSernums;
00236   if ( serNums.isEmpty() && mCurrentMessage )
00237     serNums.append( mCurrentMessage->getMsgSerNum() );
00238   if ( serNums.empty() )
00239     return;
00240   KMCommand *command = new KMSetStatusCommand( status, serNums, toggle );
00241   command->start();
00242 }
00243 
00244 void MessageActions::editCurrentMessage()
00245 {
00246   if ( !mCurrentMessage )
00247     return;
00248   KMCommand *command = 0;
00249   KMFolder *folder = mCurrentMessage->parent();
00250   // edit, unlike send again, removes the message from the folder
00251   // we only want that for templates and drafts folders
00252   if ( folder && ( kmkernel->folderIsDraftOrOutbox( folder ) ||
00253        kmkernel->folderIsTemplates( folder ) ) )
00254     command = new KMEditMsgCommand( mParent, mCurrentMessage );
00255   else
00256     command = new KMResendMessageCommand( mParent, mCurrentMessage );
00257   command->start();
00258 }
00259 
00260 #include "messageactions.moc"