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 
00045 #include "kmreadermainwin.h"
00046 
00047 KMReaderMainWin::KMReaderMainWin( bool htmlOverride, bool htmlLoadExtOverride,
00048                                   char *name )
00049   : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00050     mMsg( 0 )
00051 {
00052   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00053   //mReaderWin->setShowCompleteMessage( true );
00054   mReaderWin->setAutoDelete( true );
00055   mReaderWin->setHtmlOverride( htmlOverride );
00056   mReaderWin->setHtmlLoadExtOverride( htmlLoadExtOverride );
00057   initKMReaderMainWin();
00058 }
00059 
00060 
00061 //-----------------------------------------------------------------------------
00062 KMReaderMainWin::KMReaderMainWin( char *name )
00063   : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00064     mMsg( 0 )
00065 {
00066   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00067   mReaderWin->setAutoDelete( true );
00068   initKMReaderMainWin();
00069 }
00070 
00071 
00072 //-----------------------------------------------------------------------------
00073 KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
00074     bool aHTML, const QString& aFileName, const QString& pname,
00075     const QString & encoding, char *name )
00076   : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00077     mMsg( 0 )
00078 {
00079   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00080   mReaderWin->setOverrideEncoding( encoding );
00081   mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00082   initKMReaderMainWin();
00083 }
00084 
00085 
00086 //-----------------------------------------------------------------------------
00087 void KMReaderMainWin::initKMReaderMainWin() {
00088   setCentralWidget( mReaderWin );
00089   setupAccel();
00090   setupGUI( ToolBar | Keys | StatusBar | Create, "kmreadermainwin.rc" );
00091   applyMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00092 
00093   connect( kmkernel, SIGNAL( configChanged() ),
00094            this, SLOT( slotConfigChanged() ) );
00095 }
00096 
00097 //-----------------------------------------------------------------------------
00098 KMReaderMainWin::~KMReaderMainWin()
00099 {
00100   saveMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00101 }
00102 
00103 //-----------------------------------------------------------------------------
00104 void KMReaderMainWin::setUseFixedFont( bool useFixedFont )
00105 {
00106   mReaderWin->setUseFixedFont( useFixedFont );
00107 }
00108 
00109 //-----------------------------------------------------------------------------
00110 void KMReaderMainWin::showMsg( const QString & encoding, KMMessage *msg )
00111 {
00112   mReaderWin->setOverrideEncoding( encoding );
00113   mReaderWin->setMsg( msg, true );
00114   setCaption( msg->subject() );
00115   mMsg = msg;
00116   toolBar( "mainToolBar" )->show();
00117 }
00118 
00119 //-----------------------------------------------------------------------------
00120 void KMReaderMainWin::slotPrintMsg()
00121 {
00122   KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00123       mReaderWin->htmlOverride(), mReaderWin->htmlLoadExtOverride(),
00124       mReaderWin->isFixedFont(), mReaderWin->overrideEncoding() );
00125   command->start();
00126 }
00127 
00128 //-----------------------------------------------------------------------------
00129 void KMReaderMainWin::slotReplyToMsg()
00130 {
00131   KMCommand *command = new KMReplyToCommand( this, mReaderWin->message(),
00132       mReaderWin->copyText() );
00133   command->start();
00134 }
00135 
00136 
00137 //-----------------------------------------------------------------------------
00138 void KMReaderMainWin::slotReplyAuthorToMsg()
00139 {
00140   KMCommand *command = new KMReplyAuthorCommand( this, mReaderWin->message(),
00141       mReaderWin->copyText() );
00142   command->start();
00143 }
00144 
00145 //-----------------------------------------------------------------------------
00146 void KMReaderMainWin::slotReplyAllToMsg()
00147 {
00148   KMCommand *command = new KMReplyToAllCommand( this, mReaderWin->message(),
00149       mReaderWin->copyText() );
00150   command->start();
00151 }
00152 
00153 //-----------------------------------------------------------------------------
00154 void KMReaderMainWin::slotReplyListToMsg()
00155 {
00156   KMCommand *command = new KMReplyListCommand( this, mReaderWin->message(),
00157       mReaderWin->copyText() );
00158   command->start();
00159 }
00160 
00161 //-----------------------------------------------------------------------------
00162 void KMReaderMainWin::slotForwardMsg()
00163 {
00164    KMCommand *command = 0;
00165    if ( mReaderWin->message()->parent() ) {
00166     command = new KMForwardCommand( this, mReaderWin->message(),
00167         mReaderWin->message()->parent()->identity() );
00168    } else {
00169     command = new KMForwardCommand( this, mReaderWin->message() );
00170    }
00171    command->start();
00172 }
00173 
00174 //-----------------------------------------------------------------------------
00175 void KMReaderMainWin::slotForwardAttachedMsg()
00176 {
00177    KMCommand *command = 0;
00178    if ( mReaderWin->message()->parent() ) {
00179      command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00180         mReaderWin->message()->parent()->identity() );
00181    } else {
00182      command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00183    }
00184    command->start();
00185 }
00186 
00187 //-----------------------------------------------------------------------------
00188 void KMReaderMainWin::slotRedirectMsg()
00189 {
00190   KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00191   command->start();
00192 }
00193 
00194 //-----------------------------------------------------------------------------
00195 void KMReaderMainWin::slotShowMsgSrc()
00196 {
00197   KMMessage *msg = mReaderWin->message();
00198   if ( !msg )
00199     return;
00200   KMCommand *command = new KMShowMsgSrcCommand( this, msg,
00201                                                 mReaderWin->isFixedFont() );
00202   command->start();
00203 }
00204 
00205 //-----------------------------------------------------------------------------
00206 void KMReaderMainWin::slotConfigChanged()
00207 {
00208   //readConfig();
00209 }
00210 
00211 void KMReaderMainWin::setupAccel()
00212 {
00213   if ( kmkernel->xmlGuiInstance() )
00214     setInstance( kmkernel->xmlGuiInstance() );
00215 
00216   //----- File Menu
00217   //mOpenAction = KStdAction::open( this, SLOT( slotOpenMsg() ),
00218   //                                actionCollection() );
00219 
00220   //mSaveAsAction = new KAction( i18n("Save &As..."), "filesave",
00221   //                             KStdAccel::shortcut( KStdAccel::Save ),
00222   //                             this, SLOT( slotSaveMsg() ),
00223   //                             actionCollection(), "file_save_as" );
00224 
00225   mPrintAction = KStdAction::print( this, SLOT( slotPrintMsg() ),
00226                                     actionCollection() );
00227 
00228   KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() );
00229   KShortcut closeShortcut = closeAction->shortcut();
00230   closeShortcut.append( KKey(Key_Escape));
00231   closeAction->setShortcut(closeShortcut);
00232 
00233   //----- View Menu
00234   mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
00235                                    SLOT(slotShowMsgSrc()), actionCollection(),
00236                                    "view_source" );
00237 
00238 
00239   mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00240                     "mail_forward", actionCollection(),
00241                     "message_forward" );
00242   connect( mForwardActionMenu, SIGNAL( activated() ), this,
00243            SLOT( slotForwardMsg() ) );
00244 
00245   mForwardAction = new KAction( i18n("&Inline..."), "mail_forward",
00246                 SHIFT+Key_F, this, SLOT(slotForwardMsg()),
00247                 actionCollection(), "message_forward_inline" );
00248   mForwardActionMenu->insert( mForwardAction );
00249 
00250   mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00251                        "mail_forward", Key_F, this,
00252                     SLOT(slotForwardAttachedMsg()), actionCollection(),
00253                     "message_forward_as_attachment" );
00254   mForwardActionMenu->insert( mForwardAttachedAction );
00255 
00256   mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00257                  Key_E, this, SLOT(slotRedirectMsg()),
00258                  actionCollection(), "message_forward_redirect" );
00259   mForwardActionMenu->insert( mRedirectAction );
00260 
00261   mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00262                                       "mail_reply", actionCollection(),
00263                                       "message_reply_menu" );
00264   connect( mReplyActionMenu, SIGNAL(activated()), this,
00265        SLOT(slotReplyToMsg()) );
00266 
00267   mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00268                   SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00269   mReplyActionMenu->insert( mReplyAction );
00270 
00271   mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00272                                     SHIFT+Key_A, this,
00273                                     SLOT(slotReplyAuthorToMsg()),
00274                                     actionCollection(), "reply_author" );
00275   mReplyActionMenu->insert( mReplyAuthorAction );
00276 
00277   mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00278                  Key_A, this, SLOT(slotReplyAllToMsg()),
00279                  actionCollection(), "reply_all" );
00280   mReplyActionMenu->insert( mReplyAllAction );
00281 
00282   mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00283                   "mail_replylist", Key_L, this,
00284                   SLOT(slotReplyListToMsg()), actionCollection(),
00285                   "reply_list" );
00286   mReplyActionMenu->insert( mReplyListAction );
00287 
00288 
00289 
00290   QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00291   accel->connectItem(accel->insertItem(Key_Up),
00292                      mReaderWin, SLOT(slotScrollUp()));
00293   accel->connectItem(accel->insertItem(Key_Down),
00294                      mReaderWin, SLOT(slotScrollDown()));
00295   accel->connectItem(accel->insertItem(Key_Prior),
00296                      mReaderWin, SLOT(slotScrollPrior()));
00297   accel->connectItem(accel->insertItem(Key_Next),
00298                      mReaderWin, SLOT(slotScrollNext()));
00299   accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00300                      mReaderWin, SLOT(slotCopySelectedText()));
00301   connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00302       this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00303   connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00304       mReaderWin, SLOT(slotUrlClicked()));
00305 
00306 }
00307 
00308 
00309 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00310 {
00311   KPopupMenu * menu = new KPopupMenu;
00312   mUrl = aUrl;
00313   mMsg = &aMsg;
00314   bool urlMenuAdded=false;
00315 
00316   if (!aUrl.isEmpty())
00317   {
00318     if (aUrl.protocol() == "mailto") {
00319       // popup on a mailto URL
00320       mReaderWin->mailToComposeAction()->plug( menu );
00321       if ( mMsg ) {
00322         mReaderWin->mailToReplyAction()->plug( menu );
00323         mReaderWin->mailToForwardAction()->plug( menu );
00324         menu->insertSeparator();
00325       }
00326       mReaderWin->addAddrBookAction()->plug( menu );
00327       mReaderWin->openAddrBookAction()->plug( menu );
00328       mReaderWin->copyAction()->plug( menu );
00329     } else {
00330       // popup on a not-mailto URL
00331       mReaderWin->urlOpenAction()->plug( menu );
00332       mReaderWin->addBookmarksAction()->plug( menu );
00333       mReaderWin->urlSaveAsAction()->plug( menu );
00334       mReaderWin->copyURLAction()->plug( menu );
00335     }
00336     urlMenuAdded=true;
00337   }
00338   if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
00339     if ( urlMenuAdded )
00340       menu->insertSeparator();
00341     mReaderWin->copyAction()->plug( menu );
00342     mReaderWin->selectAllAction()->plug( menu );
00343   } else if ( !urlMenuAdded )
00344   {
00345     // popup somewhere else (i.e., not a URL) on the message
00346 
00347     if (!mMsg) // no message
00348     {
00349       delete menu;
00350       return;
00351     }
00352 
00353     if( !aMsg.parent()->isSent() && !aMsg.parent()->isDrafts() ) {
00354       mReplyActionMenu->plug( menu );
00355       mForwardActionMenu->plug( menu );
00356       menu->insertSeparator();
00357     }
00358 
00359     QPopupMenu* copyMenu = new QPopupMenu(menu);
00360     KMMainWidget* mainwin = kmkernel->getKMMainWidget();
00361     if ( mainwin )
00362       mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
00363           &mMenuToFolder, copyMenu );
00364     menu->insertItem( i18n("&Copy To" ), copyMenu );
00365     menu->insertSeparator();
00366     mViewSourceAction->plug( menu );
00367     mReaderWin->toggleFixFontAction()->plug( menu );
00368     menu->insertSeparator();
00369     mPrintAction->plug( menu );
00370     menu->insertItem(  SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00371     menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00372   }
00373   menu->exec(aPoint, 0);
00374   delete menu;
00375 }
00376 
00377 void KMReaderMainWin::copySelectedToFolder( int menuId )
00378 {
00379   if (!mMenuToFolder[menuId])
00380     return;
00381 
00382   KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00383   command->start();
00384 }
00385 
00386 #include "kmreadermainwin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys