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 <kkeydialog.h> //for KKeyDialog
00030 #include <kedittoolbar.h> //for saveMainWindowSettings() applyMainWindowSettings()
00031 #include <kmainwindow.h>
00032 #include <kcharsets.h>
00033 #include "globalsettings.h"
00034 
00035 #include "kmreadermainwin.h"
00036 #include "kmreadermainwin.moc"
00037 
00038 KMReaderMainWin::KMReaderMainWin( bool htmlOverride, char *name )
00039   : KMail::SecondaryWindow( name ), mMsg( 0 )
00040 {
00041   KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00042   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00043   //mReaderWin->setShowCompleteMessage( true );
00044   mReaderWin->setAutoDelete( true );
00045   mReaderWin->setHtmlOverride( htmlOverride );
00046   setCentralWidget( mReaderWin );
00047   setupAccel();
00048 
00049   connect( kmkernel, SIGNAL( configChanged() ),
00050            this, SLOT( slotConfigChanged() ) );
00051 }
00052 
00053 
00054 KMReaderMainWin::KMReaderMainWin( char *name )
00055   : KMail::SecondaryWindow( name ), mMsg( 0 )
00056 {
00057   mReaderWin = new KMReaderWin( this, this, actionCollection() );
00058   mReaderWin->setAutoDelete( true );
00059   setCentralWidget( mReaderWin );
00060   setupAccel();
00061 
00062   connect( kmkernel, SIGNAL( configChanged() ),
00063            this, SLOT( slotConfigChanged() ) );
00064 }
00065 
00066 
00067 KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
00068     bool aHTML, const QString& aFileName, const QString& pname,
00069     const QString & encoding, char *name )
00070   : KMail::SecondaryWindow( name ), mMsg( 0 )
00071 {
00072   mReaderWin = new KMReaderWin( this, this, actionCollection() ); //new reader
00073   mReaderWin->setOverrideEncoding( encoding );
00074   mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00075   setCentralWidget( mReaderWin );
00076   setupAccel();
00077 
00078   connect( kmkernel, SIGNAL( configChanged() ),
00079            this, SLOT( slotConfigChanged() ) );
00080 }
00081 
00082 
00083 KMReaderMainWin::~KMReaderMainWin()
00084 {
00085   saveMainWindowSettings(KMKernel::config(), "Separate Reader Window");
00086 }
00087 
00088 
00089 //-----------------------------------------------------------------------------
00090 void KMReaderMainWin::showMsg( const QString & encoding, KMMessage *msg )
00091 {
00092   mReaderWin->setOverrideEncoding( encoding );
00093   mReaderWin->setMsg( msg, true );
00094   setCaption( msg->subject() );
00095   mMsg = msg;
00096   toolBar( "mainToolBar" )->show();
00097 
00098   connect ( msg->parent(), SIGNAL( destroyed( QObject* ) ), this, SLOT( slotFolderRemoved( QObject* ) ) );
00099 
00100 }
00101 
00102 void KMReaderMainWin::slotFolderRemoved( QObject* folderPtr )
00103 {
00104   assert(mMsg);
00105   assert(folderPtr == mMsg->parent());
00106   if( mMsg && folderPtr == mMsg->parent() )
00107     mMsg->setParent( 0 );
00108 }
00109 
00110 //-----------------------------------------------------------------------------
00111 void KMReaderMainWin::slotPrintMsg()
00112 {
00113   KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00114       mReaderWin->htmlOverride(), mReaderWin->overrideEncoding(),
00115       mReaderWin->headerStyle(), mReaderWin->headerStrategy() );
00116   command->start();
00117 }
00118 
00119 //-----------------------------------------------------------------------------
00120 void KMReaderMainWin::slotReplyToMsg()
00121 {
00122   KMCommand *command = new KMReplyToCommand( this, mReaderWin->message(),
00123       mReaderWin->copyText() );
00124   command->start();
00125 }
00126 
00127 
00128 //-----------------------------------------------------------------------------
00129 void KMReaderMainWin::slotReplyAuthorToMsg()
00130 {
00131   KMCommand *command = new KMReplyAuthorCommand( this, mReaderWin->message(),
00132       mReaderWin->copyText() );
00133   command->start();
00134 }
00135 
00136 //-----------------------------------------------------------------------------
00137 void KMReaderMainWin::slotReplyAllToMsg()
00138 {
00139   KMCommand *command = new KMReplyToAllCommand( this, mReaderWin->message(),
00140       mReaderWin->copyText() );
00141   command->start();
00142 }
00143 
00144 //-----------------------------------------------------------------------------
00145 void KMReaderMainWin::slotReplyListToMsg()
00146 {
00147   KMCommand *command = new KMReplyListCommand( this, mReaderWin->message(),
00148       mReaderWin->copyText() );
00149   command->start();
00150 }
00151 
00152 //-----------------------------------------------------------------------------
00153 void KMReaderMainWin::slotForwardMsg()
00154 {
00155    KMCommand *command = 0;
00156    if ( mReaderWin->message()->parent() ) {
00157     command = new KMForwardCommand( this, mReaderWin->message(),
00158         mReaderWin->message()->parent()->identity() );
00159    } else {
00160     command = new KMForwardCommand( this, mReaderWin->message() );
00161    }
00162    command->start();
00163 }
00164 
00165 //-----------------------------------------------------------------------------
00166 void KMReaderMainWin::slotForwardAttachedMsg()
00167 {
00168    KMCommand *command = 0;
00169    if ( mReaderWin->message()->parent() ) {
00170      command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00171         mReaderWin->message()->parent()->identity() );
00172    } else {
00173      command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00174    }
00175    command->start();
00176 }
00177 
00178 //-----------------------------------------------------------------------------
00179 void KMReaderMainWin::slotRedirectMsg()
00180 {
00181   KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00182   command->start();
00183 }
00184 
00185 
00186 //-----------------------------------------------------------------------------
00187 void KMReaderMainWin::slotBounceMsg()
00188 {
00189   KMCommand *command = new KMBounceCommand( this, mReaderWin->message() );
00190   command->start();
00191 }
00192 
00193 //-----------------------------------------------------------------------------
00194 void KMReaderMainWin::slotConfigChanged()
00195 {
00196   //readConfig();
00197 }
00198 
00199 void KMReaderMainWin::setupAccel()
00200 {
00201   if (kmkernel->xmlGuiInstance())
00202     setInstance( kmkernel->xmlGuiInstance() );
00203   KStdAction::close( this, SLOT( close() ), actionCollection() );
00204   applyMainWindowSettings(KMKernel::config(), "Separate Reader Window");
00205   QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00206   accel->connectItem(accel->insertItem(Key_Up),
00207                      mReaderWin, SLOT(slotScrollUp()));
00208   accel->connectItem(accel->insertItem(Key_Down),
00209                      mReaderWin, SLOT(slotScrollDown()));
00210   accel->connectItem(accel->insertItem(Key_Prior),
00211                      mReaderWin, SLOT(slotScrollPrior()));
00212   accel->connectItem(accel->insertItem(Key_Next),
00213                      mReaderWin, SLOT(slotScrollNext()));
00214   accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00215                      mReaderWin, SLOT(slotCopySelectedText()));
00216   connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00217       this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00218   connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00219       mReaderWin, SLOT(slotUrlClicked()));
00220 
00221   mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00222                     "mail_forward", actionCollection(),
00223                     "message_forward" );
00224 
00225   mForwardInlineAction = new KAction( i18n("&Inline..."),
00226                                       "mail_forward", SHIFT+Key_F, this,
00227                                       SLOT(slotForwardMsg()),
00228                                       actionCollection(),
00229                                       "message_forward_inline" );
00230 
00231   mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00232                                         "mail_forward", Key_F, this,
00233                                         SLOT(slotForwardAttachedMsg()),
00234                                         actionCollection(),
00235                                         "message_forward_as_attachment" );
00236 
00237   mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00238                                  Key_E, this, SLOT(slotRedirectMsg()),
00239                                  actionCollection(), "message_forward_redirect" );
00240 
00241   if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
00242       mForwardActionMenu->insert( mForwardInlineAction );
00243       mForwardActionMenu->insert( mForwardAttachedAction );
00244       mForwardInlineAction->setShortcut( Key_F );
00245       mForwardAttachedAction->setShortcut( SHIFT+Key_F );
00246       connect( mForwardActionMenu, SIGNAL(activated()), this,
00247               SLOT(slotForwardMsg()) );
00248   } else {
00249         mForwardActionMenu->insert( mForwardAttachedAction );
00250         mForwardActionMenu->insert( mForwardInlineAction );
00251         mForwardInlineAction->setShortcut( SHIFT+Key_F );
00252         mForwardAttachedAction->setShortcut( Key_F );
00253         connect( mForwardActionMenu, SIGNAL(activated()), this,
00254              SLOT(slotForwardAttachedMsg()) );
00255   }
00256 
00257   mForwardActionMenu->insert( mRedirectAction );
00258 
00259 
00260   mBounceAction = new KAction( i18n("&Bounce..."), 0, this,
00261                   SLOT(slotBounceMsg()), actionCollection(), "bounce" );
00262 
00263 
00264   mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00265                                       "mail_reply", actionCollection(),
00266                                       "message_reply_menu" );
00267   connect( mReplyActionMenu, SIGNAL(activated()), this,
00268        SLOT(slotReplyToMsg()) );
00269 
00270   mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00271                   SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00272   mReplyActionMenu->insert( mReplyAction );
00273 
00274   mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00275                                     SHIFT+Key_A, this,
00276                                     SLOT(slotReplyAuthorToMsg()),
00277                                     actionCollection(), "reply_author" );
00278   mReplyActionMenu->insert( mReplyAuthorAction );
00279 
00280   mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00281                  Key_A, this, SLOT(slotReplyAllToMsg()),
00282                  actionCollection(), "reply_all" );
00283   mReplyActionMenu->insert( mReplyAllAction );
00284 
00285   mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00286                   "mail_replylist", Key_L, this,
00287                   SLOT(slotReplyListToMsg()), actionCollection(),
00288                   "reply_list" );
00289   mReplyActionMenu->insert( mReplyListAction );
00290 
00291   mPrintAction = KStdAction::print (this, SLOT(slotPrintMsg()), actionCollection());
00292 
00293   KStdAction::keyBindings(this, SLOT(slotEditKeys()), actionCollection());
00294   KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
00295 
00296   mSelectAllTextAction = new KAction( i18n("Select Message &Text"),
00297                       CTRL+SHIFT+Key_A, mReaderWin,
00298                       SLOT(selectAll()), actionCollection(), "mark_all_text" );
00299   mCopyMsgTextAction = new KAction( i18n("Copy Text"),
00300                                   "editcopy", CTRL + Key_C, mReaderWin,
00301                                   SLOT(slotCopySelectedText()), actionCollection(),
00302                                   "kmail_copy" );
00303 
00304   createGUI( "kmreadermainwin.rc" );
00305   //menuBar()->hide();
00306   //toolBar( "mainToolBar" )->hide();
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 
00315   if (!aUrl.isEmpty()) {
00316     if (aUrl.protocol() == "mailto") {
00317       // popup on a mailto URL
00318       mReaderWin->mailToComposeAction()->plug( menu );
00319       if ( mMsg ) {
00320     mReaderWin->mailToReplyAction()->plug( menu );
00321     mReaderWin->mailToForwardAction()->plug( menu );
00322         menu->insertSeparator();
00323       }
00324       mReaderWin->addAddrBookAction()->plug( menu );
00325       mReaderWin->openAddrBookAction()->plug( menu );
00326       mReaderWin->copyAction()->plug( menu );
00327     } else {
00328       // popup on a not-mailto URL
00329       mReaderWin->urlOpenAction()->plug( menu );
00330       mReaderWin->urlSaveAsAction()->plug( menu );
00331       mReaderWin->copyURLAction()->plug( menu );
00332       mReaderWin->addBookmarksAction()->plug( menu );
00333     }
00334   } else {
00335     // popup somewhere else (i.e., not a URL) on the message
00336 
00337     if (!mMsg) // no message
00338     {
00339       delete menu;
00340       return;
00341     }
00342 
00343     mReplyAction->plug( menu );
00344     mReplyAllAction->plug( menu );
00345     mReplyAuthorAction->plug( menu );
00346     mReplyListAction->plug( menu );
00347     mForwardActionMenu->plug( menu );
00348     mBounceAction->plug( menu );
00349 
00350     menu->insertSeparator();
00351 
00352     QPopupMenu* copyMenu = new QPopupMenu(menu);
00353     KMMenuCommand::folderToPopupMenu( false, this, &mMenuToFolder, copyMenu );
00354     menu->insertItem( i18n("&Copy To" ), copyMenu );
00355     menu->insertSeparator();
00356     mReaderWin->toggleFixFontAction()->plug( menu );
00357     mReaderWin->viewSourceAction()->plug( menu );
00358 
00359     menu->insertSeparator();
00360     mSelectAllTextAction->plug( menu );
00361     mCopyMsgTextAction->plug( menu );
00362     menu->insertSeparator();
00363 
00364     mPrintAction->plug( menu );
00365     menu->insertItem(  SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00366     menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00367   }
00368   menu->exec(aPoint, 0);
00369   delete menu;
00370 }
00371 
00372 void KMReaderMainWin::copySelectedToFolder( int menuId )
00373 {
00374   if (!mMenuToFolder[menuId])
00375     return;
00376 
00377   KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00378   command->start();
00379 }
00380 
00381 //----------------------------------------------------------------------------
00382 void KMReaderMainWin::slotEditToolbars()
00383 {
00384   saveMainWindowSettings(KMKernel::config(), "Reader");
00385   KEditToolbar dlg(guiFactory(), this);
00386 
00387   connect( &dlg, SIGNAL(newToolbarConfig()),
00388            SLOT(slotUpdateToolbars()) );
00389 
00390   dlg.exec();
00391 }
00392 
00393 void KMReaderMainWin::slotUpdateToolbars()
00394 {
00395   createGUI("kmreadermainwin.rc");
00396   applyMainWindowSettings(KMKernel::config(), "Reader");
00397 }
00398 
00399 void KMReaderMainWin::slotEditKeys()
00400 {
00401    KKeyDialog::configure( actionCollection(),
00402                          false /*don't allow one-letter shortcuts*/
00403                          );
00404 }
00405 
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 Fri Dec 21 14:25:01 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003