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