kmail Library API Documentation

kmreadermainwin.cpp

00001 // kmreadermainwin
00002 // (c) 2002 Don Sanders <sanders@kde.org>
00003 // License: GPL
00004 //
00005 // A toplevel KMainWindow derived class for displaying
00006 // single messages or single message parts.
00007 //
00008 // Could be extended to include support for normal main window
00009 // widgets like a toolbar.
00010 
00011 #ifdef HAVE_CONFIG_H
00012 #include <config.h>
00013 #endif
00014 
00015 #include <qaccel.h>
00016 #include <kapplication.h>
00017 #include <klocale.h>
00018 #include <kstdaccel.h>
00019 #include <kwin.h>
00020 #include <kaction.h>
00021 #include <kiconloader.h>
00022 
00023 #include "kmcommands.h"
00024 #include "kmenubar.h"
00025 #include "kpopupmenu.h"
00026 #include "kmreaderwin.h"
00027 #include "kmfolder.h"
00028 
00029 #include "kmreadermainwin.h"
00030 #include "kmreadermainwin.moc"
00031 
00032 KMReaderMainWin::KMReaderMainWin( bool htmlOverride, char *name )
00033   : KMail::SecondaryWindow( name ), mMsg( 0 )
00034 {
00035   KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00036   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00037   //mReaderWin->setShowCompleteMessage( true );
00038   mReaderWin->setAutoDelete( true );
00039   mReaderWin->setHtmlOverride( htmlOverride );
00040   setCentralWidget( mReaderWin );
00041   setupAccel();
00042 
00043   connect( kmkernel, SIGNAL( configChanged() ),
00044            this, SLOT( slotConfigChanged() ) );
00045 }
00046 
00047 
00048 KMReaderMainWin::KMReaderMainWin( char *name )
00049   : KMail::SecondaryWindow( name ), mMsg( 0 )
00050 {
00051   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00052   mReaderWin->setAutoDelete( true );
00053   setCentralWidget( mReaderWin );
00054   setupAccel();
00055 
00056   connect( kmkernel, SIGNAL( configChanged() ),
00057            this, SLOT( slotConfigChanged() ) );
00058 }
00059 
00060 
00061 KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
00062     bool aHTML, const QString& aFileName, const QString& pname,
00063     const QTextCodec *codec, char *name )
00064   : KMail::SecondaryWindow( name ), mMsg( 0 )
00065 {
00066   mReaderWin = new KMReaderWin( this, this, actionCollection() ); //new reader
00067   mReaderWin->setOverrideCodec( codec );
00068   mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00069   setCentralWidget( mReaderWin );
00070   setupAccel();
00071 
00072   connect( kmkernel, SIGNAL( configChanged() ),
00073            this, SLOT( slotConfigChanged() ) );
00074 }
00075 
00076 
00077 KMReaderMainWin::~KMReaderMainWin()
00078 {
00079   saveMainWindowSettings(KMKernel::config(), "Separate Reader Window");
00080 }
00081 
00082 
00083 void KMReaderMainWin::setUseFixedFont( bool useFixedFont )
00084 {
00085   mReaderWin->setUseFixedFont( useFixedFont );
00086 }
00087 
00088 
00089 void KMReaderMainWin::showMsg( const QTextCodec *codec, KMMessage *msg )
00090 {
00091   mReaderWin->setOverrideCodec( codec );
00092   mReaderWin->setMsg( msg, true );
00093   setCaption( msg->subject() );
00094   mMsg = msg;
00095   toolBar( "mainToolBar" )->show();
00096 }
00097 
00098 //-----------------------------------------------------------------------------
00099 void KMReaderMainWin::slotPrintMsg()
00100 {
00101   KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00102       mReaderWin->htmlOverride(), mReaderWin->overrideCodec() );
00103   command->start();
00104 }
00105 
00106 //-----------------------------------------------------------------------------
00107 void KMReaderMainWin::slotReplyToMsg()
00108 {
00109   KMCommand *command = new KMReplyToCommand( this, mReaderWin->message(),
00110       mReaderWin->copyText() );
00111   command->start();
00112 }
00113 
00114 
00115 //-----------------------------------------------------------------------------
00116 void KMReaderMainWin::slotReplyAuthorToMsg()
00117 {
00118   KMCommand *command = new KMReplyAuthorCommand( this, mReaderWin->message(),
00119       mReaderWin->copyText() );
00120   command->start();
00121 }
00122 
00123 //-----------------------------------------------------------------------------
00124 void KMReaderMainWin::slotReplyAllToMsg()
00125 {
00126   KMCommand *command = new KMReplyToAllCommand( this, mReaderWin->message(),
00127       mReaderWin->copyText() );
00128   command->start();
00129 }
00130 
00131 //-----------------------------------------------------------------------------
00132 void KMReaderMainWin::slotReplyListToMsg()
00133 {
00134   KMCommand *command = new KMReplyListCommand( this, mReaderWin->message(),
00135       mReaderWin->copyText() );
00136   command->start();
00137 }
00138 
00139 //-----------------------------------------------------------------------------
00140 void KMReaderMainWin::slotForwardMsg()
00141 {
00142    KMCommand *command = 0;
00143    if ( mReaderWin->message()->parent() ) {
00144     command = new KMForwardCommand( this, mReaderWin->message(),
00145         mReaderWin->message()->parent()->identity() );
00146    } else {
00147     command = new KMForwardCommand( this, mReaderWin->message() );
00148    }
00149    command->start();
00150 }
00151 
00152 //-----------------------------------------------------------------------------
00153 void KMReaderMainWin::slotForwardAttachedMsg()
00154 {
00155    KMCommand *command = 0;
00156    if ( mReaderWin->message()->parent() ) {
00157      command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00158         mReaderWin->message()->parent()->identity() );
00159    } else {
00160      command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00161    }
00162    command->start();
00163 }
00164 
00165 //-----------------------------------------------------------------------------
00166 void KMReaderMainWin::slotRedirectMsg()
00167 {
00168   KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00169   command->start();
00170 }
00171 
00172 
00173 //-----------------------------------------------------------------------------
00174 void KMReaderMainWin::slotBounceMsg()
00175 {
00176   KMCommand *command = new KMBounceCommand( this, mReaderWin->message() );
00177   command->start();
00178 }
00179 
00180 //-----------------------------------------------------------------------------
00181 void KMReaderMainWin::slotConfigChanged()
00182 {
00183   //readConfig();
00184 }
00185 
00186 void KMReaderMainWin::setupAccel()
00187 {
00188   if (kmkernel->xmlGuiInstance())
00189     setInstance( kmkernel->xmlGuiInstance() );
00190   KStdAction::close( this, SLOT( close() ), actionCollection() );
00191   applyMainWindowSettings(KMKernel::config(), "Separate Reader Window");
00192   QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00193   accel->connectItem(accel->insertItem(Key_Up),
00194                      mReaderWin, SLOT(slotScrollUp()));
00195   accel->connectItem(accel->insertItem(Key_Down),
00196                      mReaderWin, SLOT(slotScrollDown()));
00197   accel->connectItem(accel->insertItem(Key_Prior),
00198                      mReaderWin, SLOT(slotScrollPrior()));
00199   accel->connectItem(accel->insertItem(Key_Next),
00200                      mReaderWin, SLOT(slotScrollNext()));
00201   accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00202                      mReaderWin, SLOT(slotCopySelectedText()));
00203   connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00204       this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00205   connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00206       mReaderWin, SLOT(slotUrlClicked()));
00207 
00208   mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00209                     "mail_forward", actionCollection(),
00210                     "message_forward" );
00211   connect( mForwardActionMenu, SIGNAL( activated() ), this,
00212            SLOT( slotForwardMsg() ) );
00213 
00214   mForwardAction = new KAction( i18n("&Inline..."), "mail_forward",
00215                 SHIFT+Key_F, this, SLOT(slotForwardMsg()),
00216                 actionCollection(), "message_forward_inline" );
00217   mForwardActionMenu->insert( mForwardAction );
00218 
00219   mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00220                        "mail_forward", Key_F, this,
00221                     SLOT(slotForwardAttachedMsg()), actionCollection(),
00222                     "message_forward_as_attachment" );
00223   mForwardActionMenu->insert( mForwardAttachedAction );
00224 
00225   mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00226                  Key_E, this, SLOT(slotRedirectMsg()),
00227                  actionCollection(), "message_forward_redirect" );
00228   mForwardActionMenu->insert( mRedirectAction );
00229 
00230   mBounceAction = new KAction( i18n("&Bounce..."), 0, this,
00231                   SLOT(slotBounceMsg()), actionCollection(), "bounce" );
00232 
00233 
00234   mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00235                                       "mail_reply", actionCollection(),
00236                                       "message_reply_menu" );
00237   connect( mReplyActionMenu, SIGNAL(activated()), this,
00238        SLOT(slotReplyToMsg()) );
00239 
00240   mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00241                   SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00242   mReplyActionMenu->insert( mReplyAction );
00243 
00244   mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00245                                     SHIFT+Key_A, this,
00246                                     SLOT(slotReplyAuthorToMsg()),
00247                                     actionCollection(), "reply_author" );
00248   mReplyActionMenu->insert( mReplyAuthorAction );
00249 
00250   mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00251                  Key_A, this, SLOT(slotReplyAllToMsg()),
00252                  actionCollection(), "reply_all" );
00253   mReplyActionMenu->insert( mReplyAllAction );
00254 
00255   mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00256                   "mail_replylist", Key_L, this,
00257                   SLOT(slotReplyListToMsg()), actionCollection(),
00258                   "reply_list" );
00259   mReplyActionMenu->insert( mReplyListAction );
00260 
00261   mPrintAction = KStdAction::print (this, SLOT(slotPrintMsg()), actionCollection());
00262   createGUI( "kmreadermainwin.rc" );
00263   menuBar()->hide();
00264   toolBar( "mainToolBar" )->hide();
00265 }
00266 
00267 
00268 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00269 {
00270   KPopupMenu * menu = new KPopupMenu;
00271   mUrl = aUrl;
00272   mMsg = &aMsg;
00273 
00274   if (!aUrl.isEmpty()) {
00275     if (aUrl.protocol() == "mailto") {
00276       // popup on a mailto URL
00277       mReaderWin->mailToComposeAction()->plug( menu );
00278       if ( mMsg ) {
00279     mReaderWin->mailToReplyAction()->plug( menu );
00280     mReaderWin->mailToForwardAction()->plug( menu );
00281         menu->insertSeparator();
00282       }
00283       mReaderWin->addAddrBookAction()->plug( menu );
00284       mReaderWin->openAddrBookAction()->plug( menu );
00285       mReaderWin->copyAction()->plug( menu );
00286     } else {
00287       // popup on a not-mailto URL
00288       mReaderWin->urlOpenAction()->plug( menu );
00289       mReaderWin->urlSaveAsAction()->plug( menu );
00290       mReaderWin->copyURLAction()->plug( menu );
00291       mReaderWin->addBookmarksAction()->plug( menu );
00292     }
00293   } else {
00294     // popup somewhere else (i.e., not a URL) on the message
00295 
00296     if (!mMsg) // no message
00297     {
00298       delete menu;
00299       return;
00300     }
00301 
00302     mReplyAction->plug( menu );
00303     mReplyAllAction->plug( menu );
00304     mReplyAuthorAction->plug( menu );
00305     mReplyListAction->plug( menu );
00306     mForwardActionMenu->plug( menu );
00307     mBounceAction->plug( menu );
00308 
00309     menu->insertSeparator();
00310 
00311     QPopupMenu* copyMenu = new QPopupMenu(menu);
00312     KMMenuCommand::folderToPopupMenu( false, this, &mMenuToFolder, copyMenu );
00313     menu->insertItem( i18n("&Copy To" ), copyMenu );
00314     menu->insertSeparator();
00315     mReaderWin->toggleFixFontAction()->plug( menu );
00316     mReaderWin->viewSourceAction()->plug( menu );
00317 
00318     mPrintAction->plug( menu );
00319     menu->insertItem(  SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00320     menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00321   }
00322   menu->exec(aPoint, 0);
00323   delete menu;
00324 }
00325 
00326 void KMReaderMainWin::copySelectedToFolder( int menuId )
00327 {
00328   if (!mMenuToFolder[menuId])
00329     return;
00330 
00331   KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00332   command->start();
00333 }
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 04:48:29 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003