kmail

kmreadermainwin.cpp

00001 /*
00002     This file is part of KMail, the KDE mail client.
00003     Copyright (c) 2002 Don Sanders <sanders@kde.org>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     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 // A toplevel KMainWindow derived class for displaying
00020 // single messages or single message parts.
00021 //
00022 // Could be extended to include support for normal main window
00023 // widgets like a toolbar.
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028 
00029 #include <qaccel.h>
00030 #include <kapplication.h>
00031 #include <klocale.h>
00032 #include <kstdaccel.h>
00033 #include <kwin.h>
00034 #include <kaction.h>
00035 #include <kiconloader.h>
00036 #include <kdebug.h>
00037 #include "kmcommands.h"
00038 #include "kmenubar.h"
00039 #include "kpopupmenu.h"
00040 #include "kmreaderwin.h"
00041 #include "kmfolder.h"
00042 #include "kmmainwidget.h"
00043 #include "kmfoldertree.h"
00044 #include "kmmsgdict.h"
00045 
00046 #include "kmreadermainwin.h"
00047 
00048 KMReaderMainWin::KMReaderMainWin( bool htmlOverride, bool htmlLoadExtOverride,
00049                                   char *name )
00050   : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00051     mMsg( 0 )
00052 {
00053   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00054   //mReaderWin->setShowCompleteMessage( true );
00055   mReaderWin->setAutoDelete( true );
00056   mReaderWin->setHtmlOverride( htmlOverride );
00057   mReaderWin->setHtmlLoadExtOverride( htmlLoadExtOverride );
00058   initKMReaderMainWin();
00059 }
00060 
00061 
00062 //-----------------------------------------------------------------------------
00063 KMReaderMainWin::KMReaderMainWin( char *name )
00064   : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00065     mMsg( 0 )
00066 {
00067   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00068   mReaderWin->setAutoDelete( true );
00069   initKMReaderMainWin();
00070 }
00071 
00072 
00073 //-----------------------------------------------------------------------------
00074 KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
00075     bool aHTML, const QString& aFileName, const QString& pname,
00076     const QString & encoding, char *name )
00077   : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00078     mMsg( 0 )
00079 {
00080   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00081   mReaderWin->setOverrideEncoding( encoding );
00082   mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00083   initKMReaderMainWin();
00084 }
00085 
00086 
00087 //-----------------------------------------------------------------------------
00088 void KMReaderMainWin::initKMReaderMainWin() {
00089   setCentralWidget( mReaderWin );
00090   setupAccel();
00091   setupGUI( ToolBar | Keys | StatusBar | Create, "kmreadermainwin.rc" );
00092   applyMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00093   if ( ! mReaderWin->message() ) {
00094     menuBar()->hide();
00095     toolBar( "mainToolBar" )->hide();
00096   }
00097 
00098   connect( kmkernel, SIGNAL( configChanged() ),
00099            this, SLOT( slotConfigChanged() ) );
00100 }
00101 
00102 //-----------------------------------------------------------------------------
00103 KMReaderMainWin::~KMReaderMainWin()
00104 {
00105   saveMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00106 }
00107 
00108 //-----------------------------------------------------------------------------
00109 void KMReaderMainWin::setUseFixedFont( bool useFixedFont )
00110 {
00111   mReaderWin->setUseFixedFont( useFixedFont );
00112 }
00113 
00114 //-----------------------------------------------------------------------------
00115 void KMReaderMainWin::showMsg( const QString & encoding, KMMessage *msg )
00116 {
00117   mReaderWin->setOverrideEncoding( encoding );
00118   mReaderWin->setMsg( msg, true );
00119   mReaderWin->slotTouchMessage();
00120   setCaption( msg->subject() );
00121   mMsg = msg;
00122   menuBar()->show();
00123   toolBar( "mainToolBar" )->show();
00124 }
00125 
00126 //-----------------------------------------------------------------------------
00127 void KMReaderMainWin::slotTrashMsg()
00128 {
00129   // find the real msg by its sernum
00130   KMFolder* parent;
00131   int index;
00132   KMMsgDict::instance()->getLocation( mMsg->getMsgSerNum(), &parent, &index );
00133   if ( parent && !parent->isTrash() ) {
00134     // open the folder (ref counted)
00135     parent->open();
00136     KMMessage *msg = parent->getMsg( index );
00137     if (msg) {
00138       KMDeleteMsgCommand *command = new KMDeleteMsgCommand( parent, msg );
00139       command->start();
00140     }
00141     parent->close();
00142   }
00143   close();
00144 }
00145 
00146 //-----------------------------------------------------------------------------
00147 void KMReaderMainWin::slotFind()
00148 {
00149   mReaderWin->slotFind();
00150 }
00151 
00152 void KMReaderMainWin::slotFindNext()
00153 {
00154   mReaderWin->slotFindNext();
00155 }
00156 
00157 //-----------------------------------------------------------------------------
00158 void KMReaderMainWin::slotCopy()
00159 {
00160   mReaderWin->slotCopySelectedText();
00161 }
00162 
00163 //-----------------------------------------------------------------------------
00164 void KMReaderMainWin::slotMarkAll()
00165 {
00166   mReaderWin->selectAll();
00167 }
00168 
00169 //-----------------------------------------------------------------------------
00170 void KMReaderMainWin::slotPrintMsg()
00171 {
00172   KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00173       mReaderWin->htmlOverride(), mReaderWin->htmlLoadExtOverride(),
00174       mReaderWin->isFixedFont(), mReaderWin->overrideEncoding() );
00175   command->start();
00176 }
00177 
00178 //-----------------------------------------------------------------------------
00179 void KMReaderMainWin::slotReplyToMsg()
00180 {
00181   KMCommand *command = new KMReplyToCommand( this, mReaderWin->message(),
00182       mReaderWin->copyText() );
00183   command->start();
00184 }
00185 
00186 
00187 //-----------------------------------------------------------------------------
00188 void KMReaderMainWin::slotReplyAuthorToMsg()
00189 {
00190   KMCommand *command = new KMReplyAuthorCommand( this, mReaderWin->message(),
00191       mReaderWin->copyText() );
00192   command->start();
00193 }
00194 
00195 //-----------------------------------------------------------------------------
00196 void KMReaderMainWin::slotReplyAllToMsg()
00197 {
00198   KMCommand *command = new KMReplyToAllCommand( this, mReaderWin->message(),
00199       mReaderWin->copyText() );
00200   command->start();
00201 }
00202 
00203 //-----------------------------------------------------------------------------
00204 void KMReaderMainWin::slotReplyListToMsg()
00205 {
00206   KMCommand *command = new KMReplyListCommand( this, mReaderWin->message(),
00207       mReaderWin->copyText() );
00208   command->start();
00209 }
00210 
00211 //-----------------------------------------------------------------------------
00212 void KMReaderMainWin::slotForwardInlineMsg()
00213 {
00214    KMCommand *command = 0;
00215    if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00216     command = new KMForwardInlineCommand( this, mReaderWin->message(),
00217         mReaderWin->message()->parent()->identity() );
00218    } else {
00219     command = new KMForwardInlineCommand( this, mReaderWin->message() );
00220    }
00221    command->start();
00222 }
00223 
00224 //-----------------------------------------------------------------------------
00225 void KMReaderMainWin::slotForwardAttachedMsg()
00226 {
00227    KMCommand *command = 0;
00228    if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00229      command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00230         mReaderWin->message()->parent()->identity() );
00231    } else {
00232      command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00233    }
00234    command->start();
00235 }
00236 
00237 //-----------------------------------------------------------------------------
00238 void KMReaderMainWin::slotForwardDigestMsg()
00239 {
00240    KMCommand *command = 0;
00241    if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00242      command = new KMForwardDigestCommand( this, mReaderWin->message(),
00243         mReaderWin->message()->parent()->identity() );
00244    } else {
00245      command = new KMForwardDigestCommand( this, mReaderWin->message() );
00246    }
00247    command->start();
00248 }
00249 
00250 //-----------------------------------------------------------------------------
00251 void KMReaderMainWin::slotRedirectMsg()
00252 {
00253   KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00254   command->start();
00255 }
00256 
00257 //-----------------------------------------------------------------------------
00258 void KMReaderMainWin::slotShowMsgSrc()
00259 {
00260   KMMessage *msg = mReaderWin->message();
00261   if ( !msg )
00262     return;
00263   KMCommand *command = new KMShowMsgSrcCommand( this, msg,
00264                                                 mReaderWin->isFixedFont() );
00265   command->start();
00266 }
00267 
00268 //-----------------------------------------------------------------------------
00269 void KMReaderMainWin::slotConfigChanged()
00270 {
00271   //readConfig();
00272 }
00273 
00274 void KMReaderMainWin::setupAccel()
00275 {
00276   if ( kmkernel->xmlGuiInstance() )
00277     setInstance( kmkernel->xmlGuiInstance() );
00278 
00279   //----- File Menu
00280   //mOpenAction = KStdAction::open( this, SLOT( slotOpenMsg() ),
00281   //                                actionCollection() );
00282 
00283   //mSaveAsAction = new KAction( i18n("Save &As..."), "filesave",
00284   //                             KStdAccel::shortcut( KStdAccel::Save ),
00285   //                             this, SLOT( slotSaveMsg() ),
00286   //                             actionCollection(), "file_save_as" );
00287 
00288   mPrintAction = KStdAction::print( this, SLOT( slotPrintMsg() ),
00289                                     actionCollection() );
00290 
00291   KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() );
00292   KShortcut closeShortcut = closeAction->shortcut();
00293   closeShortcut.append( KKey(Key_Escape));
00294   closeAction->setShortcut(closeShortcut);
00295 
00296   //----- Edit Menu
00297   KStdAction::copy( this, SLOT( slotCopy() ), actionCollection() );
00298   KStdAction::selectAll( this, SLOT( slotMarkAll() ), actionCollection() );
00299   KStdAction::find( this, SLOT(slotFind()), actionCollection() );
00300   KStdAction::findNext( this, SLOT( slotFindNext() ), actionCollection() );
00301   mTrashAction = new KAction( KGuiItem( i18n( "&Move to Trash" ), "edittrash",
00302                               i18n( "Move message to trashcan" ) ),
00303                               Key_Delete, this, SLOT( slotTrashMsg() ),
00304                               actionCollection(), "move_to_trash" );
00305 
00306   //----- View Menu
00307   mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
00308                                    SLOT(slotShowMsgSrc()), actionCollection(),
00309                                    "view_source" );
00310 
00311 
00312   mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00313                     "mail_forward", actionCollection(),
00314                     "message_forward" );
00315   connect( mForwardActionMenu, SIGNAL( activated() ), this,
00316            SLOT( slotForwardInlineMsg() ) );
00317 
00318   mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00319                                         "mail_forward", Key_F, this,
00320                     SLOT(slotForwardAttachedMsg()),
00321                                         actionCollection(),
00322                     "message_forward_as_attachment" );
00323   mForwardActionMenu->insert( mForwardAttachedAction );
00324 
00325   mForwardInlineAction = new KAction( i18n("&Inline..."),
00326                                       "mail_forward", SHIFT+Key_F, this,
00327                                       SLOT(slotForwardInlineMsg()),
00328                                       actionCollection(),
00329                                       "message_forward_inline" );
00330   mForwardActionMenu->insert( mForwardInlineAction );
00331 
00332   mForwardDigestAction = new KAction( i18n("Message->Forward->","As Di&gest..."),
00333                                       "mail_forward", 0, this,
00334                                       SLOT(slotForwardDigestMsg()),
00335                                       actionCollection(),
00336                                       "message_forward_as_digest" );
00337   mForwardActionMenu->insert( mForwardDigestAction );
00338 
00339   mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00340                  "mail_forward", Key_E, this,
00341                                  SLOT(slotRedirectMsg()),
00342                  actionCollection(),
00343                                  "message_forward_redirect" );
00344   mForwardActionMenu->insert( mRedirectAction );
00345 
00346   mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00347                                       "mail_reply", actionCollection(),
00348                                       "message_reply_menu" );
00349   connect( mReplyActionMenu, SIGNAL(activated()), this,
00350        SLOT(slotReplyToMsg()) );
00351 
00352   mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00353                   SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00354   mReplyActionMenu->insert( mReplyAction );
00355 
00356   mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00357                                     SHIFT+Key_A, this,
00358                                     SLOT(slotReplyAuthorToMsg()),
00359                                     actionCollection(), "reply_author" );
00360   mReplyActionMenu->insert( mReplyAuthorAction );
00361 
00362   mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00363                  Key_A, this, SLOT(slotReplyAllToMsg()),
00364                  actionCollection(), "reply_all" );
00365   mReplyActionMenu->insert( mReplyAllAction );
00366 
00367   mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00368                   "mail_replylist", Key_L, this,
00369                   SLOT(slotReplyListToMsg()), actionCollection(),
00370                   "reply_list" );
00371   mReplyActionMenu->insert( mReplyListAction );
00372 
00373 
00374 
00375   QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00376   accel->connectItem(accel->insertItem(Key_Up),
00377                      mReaderWin, SLOT(slotScrollUp()));
00378   accel->connectItem(accel->insertItem(Key_Down),
00379                      mReaderWin, SLOT(slotScrollDown()));
00380   accel->connectItem(accel->insertItem(Key_Prior),
00381                      mReaderWin, SLOT(slotScrollPrior()));
00382   accel->connectItem(accel->insertItem(Key_Next),
00383                      mReaderWin, SLOT(slotScrollNext()));
00384   accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00385                      mReaderWin, SLOT(slotCopySelectedText()));
00386   connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00387       this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00388   connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00389       mReaderWin, SLOT(slotUrlClicked()));
00390 
00391 }
00392 
00393 
00394 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00395 {
00396   KPopupMenu * menu = new KPopupMenu;
00397   mUrl = aUrl;
00398   mMsg = &aMsg;
00399   bool urlMenuAdded=false;
00400 
00401   if (!aUrl.isEmpty())
00402   {
00403     if (aUrl.protocol() == "mailto") {
00404       // popup on a mailto URL
00405       mReaderWin->mailToComposeAction()->plug( menu );
00406       if ( mMsg ) {
00407         mReaderWin->mailToReplyAction()->plug( menu );
00408         mReaderWin->mailToForwardAction()->plug( menu );
00409         menu->insertSeparator();
00410       }
00411       mReaderWin->addAddrBookAction()->plug( menu );
00412       mReaderWin->openAddrBookAction()->plug( menu );
00413       mReaderWin->copyAction()->plug( menu );
00414     } else {
00415       // popup on a not-mailto URL
00416       mReaderWin->urlOpenAction()->plug( menu );
00417       mReaderWin->addBookmarksAction()->plug( menu );
00418       mReaderWin->urlSaveAsAction()->plug( menu );
00419       mReaderWin->copyURLAction()->plug( menu );
00420     }
00421     urlMenuAdded=true;
00422   }
00423   if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
00424     if ( urlMenuAdded )
00425       menu->insertSeparator();
00426     mReaderWin->copyAction()->plug( menu );
00427     mReaderWin->selectAllAction()->plug( menu );
00428   } else if ( !urlMenuAdded )
00429   {
00430     // popup somewhere else (i.e., not a URL) on the message
00431 
00432     if (!mMsg) // no message
00433     {
00434       delete menu;
00435       return;
00436     }
00437 
00438     if ( ! ( aMsg.parent() && ( aMsg.parent()->isSent() || aMsg.parent()->isDrafts() ) ) ) {
00439       // add the reply and forward actions only if we are not in a sent-mail or drafts
00440       // folder
00441       mReplyActionMenu->plug( menu );
00442       mForwardActionMenu->plug( menu );
00443       menu->insertSeparator();
00444     }
00445 
00446     QPopupMenu* copyMenu = new QPopupMenu(menu);
00447     KMMainWidget* mainwin = kmkernel->getKMMainWidget();
00448     if ( mainwin )
00449       mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
00450           &mMenuToFolder, copyMenu );
00451     menu->insertItem( i18n("&Copy To" ), copyMenu );
00452     menu->insertSeparator();
00453     mViewSourceAction->plug( menu );
00454     mReaderWin->toggleFixFontAction()->plug( menu );
00455     menu->insertSeparator();
00456     mPrintAction->plug( menu );
00457     menu->insertItem(  SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00458     menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00459   }
00460   menu->exec(aPoint, 0);
00461   delete menu;
00462 }
00463 
00464 void KMReaderMainWin::copySelectedToFolder( int menuId )
00465 {
00466   if (!mMenuToFolder[menuId])
00467     return;
00468 
00469   KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00470   command->start();
00471 }
00472 
00473 #include "kmreadermainwin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys