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