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