00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028
00029 #include <qaccel.h>
00030 #include <kapplication.h>
00031 #include <klocale.h>
00032 #include <kstdaccel.h>
00033 #include <kwin.h>
00034 #include <kaction.h>
00035 #include <kiconloader.h>
00036 #include <kdebug.h>
00037 #include "kmcommands.h"
00038 #include "kmenubar.h"
00039 #include "kpopupmenu.h"
00040 #include "kmreaderwin.h"
00041 #include "kmfolder.h"
00042 #include "kmmainwidget.h"
00043 #include "kmfoldertree.h"
00044
00045 #include "kmreadermainwin.h"
00046
00047 KMReaderMainWin::KMReaderMainWin( bool htmlOverride, bool htmlLoadExtOverride,
00048 char *name )
00049 : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00050 mMsg( 0 )
00051 {
00052 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00053
00054 mReaderWin->setAutoDelete( true );
00055 mReaderWin->setHtmlOverride( htmlOverride );
00056 mReaderWin->setHtmlLoadExtOverride( htmlLoadExtOverride );
00057 initKMReaderMainWin();
00058 }
00059
00060
00061
00062 KMReaderMainWin::KMReaderMainWin( char *name )
00063 : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00064 mMsg( 0 )
00065 {
00066 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00067 mReaderWin->setAutoDelete( true );
00068 initKMReaderMainWin();
00069 }
00070
00071
00072
00073 KMReaderMainWin::KMReaderMainWin(KMMessagePart* aMsgPart,
00074 bool aHTML, const QString& aFileName, const QString& pname,
00075 const QString & encoding, char *name )
00076 : KMail::SecondaryWindow( name ? name : "readerwindow#" ),
00077 mMsg( 0 )
00078 {
00079 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00080 mReaderWin->setOverrideEncoding( encoding );
00081 mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00082 initKMReaderMainWin();
00083 }
00084
00085
00086
00087 void KMReaderMainWin::initKMReaderMainWin() {
00088 setCentralWidget( mReaderWin );
00089 setupAccel();
00090 setupGUI( ToolBar | Keys | StatusBar | Create, "kmreadermainwin.rc" );
00091 applyMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00092 if ( ! mReaderWin->message() ) {
00093 menuBar()->hide();
00094 toolBar( "mainToolBar" )->hide();
00095 }
00096
00097 connect( kmkernel, SIGNAL( configChanged() ),
00098 this, SLOT( slotConfigChanged() ) );
00099 }
00100
00101
00102 KMReaderMainWin::~KMReaderMainWin()
00103 {
00104 saveMainWindowSettings( KMKernel::config(), "Separate Reader Window" );
00105 }
00106
00107
00108 void KMReaderMainWin::setUseFixedFont( bool useFixedFont )
00109 {
00110 mReaderWin->setUseFixedFont( useFixedFont );
00111 }
00112
00113
00114 void KMReaderMainWin::showMsg( const QString & encoding, KMMessage *msg )
00115 {
00116 mReaderWin->setOverrideEncoding( encoding );
00117 mReaderWin->setMsg( msg, true );
00118 setCaption( msg->subject() );
00119 mMsg = msg;
00120 menuBar()->show();
00121 toolBar( "mainToolBar" )->show();
00122 }
00123
00124
00125 void KMReaderMainWin::slotPrintMsg()
00126 {
00127 KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00128 mReaderWin->htmlOverride(), mReaderWin->htmlLoadExtOverride(),
00129 mReaderWin->isFixedFont(), mReaderWin->overrideEncoding() );
00130 command->start();
00131 }
00132
00133
00134 void KMReaderMainWin::slotReplyToMsg()
00135 {
00136 KMCommand *command = new KMReplyToCommand( this, mReaderWin->message(),
00137 mReaderWin->copyText() );
00138 command->start();
00139 }
00140
00141
00142
00143 void KMReaderMainWin::slotReplyAuthorToMsg()
00144 {
00145 KMCommand *command = new KMReplyAuthorCommand( this, mReaderWin->message(),
00146 mReaderWin->copyText() );
00147 command->start();
00148 }
00149
00150
00151 void KMReaderMainWin::slotReplyAllToMsg()
00152 {
00153 KMCommand *command = new KMReplyToAllCommand( this, mReaderWin->message(),
00154 mReaderWin->copyText() );
00155 command->start();
00156 }
00157
00158
00159 void KMReaderMainWin::slotReplyListToMsg()
00160 {
00161 KMCommand *command = new KMReplyListCommand( this, mReaderWin->message(),
00162 mReaderWin->copyText() );
00163 command->start();
00164 }
00165
00166
00167 void KMReaderMainWin::slotForwardMsg()
00168 {
00169 KMCommand *command = 0;
00170 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00171 command = new KMForwardCommand( this, mReaderWin->message(),
00172 mReaderWin->message()->parent()->identity() );
00173 } else {
00174 command = new KMForwardCommand( this, mReaderWin->message() );
00175 }
00176 command->start();
00177 }
00178
00179
00180 void KMReaderMainWin::slotForwardAttachedMsg()
00181 {
00182 KMCommand *command = 0;
00183 if ( mReaderWin->message() && mReaderWin->message()->parent() ) {
00184 command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00185 mReaderWin->message()->parent()->identity() );
00186 } else {
00187 command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00188 }
00189 command->start();
00190 }
00191
00192
00193 void KMReaderMainWin::slotRedirectMsg()
00194 {
00195 KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00196 command->start();
00197 }
00198
00199
00200 void KMReaderMainWin::slotShowMsgSrc()
00201 {
00202 KMMessage *msg = mReaderWin->message();
00203 if ( !msg )
00204 return;
00205 KMCommand *command = new KMShowMsgSrcCommand( this, msg,
00206 mReaderWin->isFixedFont() );
00207 command->start();
00208 }
00209
00210
00211 void KMReaderMainWin::slotConfigChanged()
00212 {
00213
00214 }
00215
00216 void KMReaderMainWin::setupAccel()
00217 {
00218 if ( kmkernel->xmlGuiInstance() )
00219 setInstance( kmkernel->xmlGuiInstance() );
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 mPrintAction = KStdAction::print( this, SLOT( slotPrintMsg() ),
00231 actionCollection() );
00232
00233 KAction *closeAction = KStdAction::close( this, SLOT( close() ), actionCollection() );
00234 KShortcut closeShortcut = closeAction->shortcut();
00235 closeShortcut.append( KKey(Key_Escape));
00236 closeAction->setShortcut(closeShortcut);
00237
00238
00239 mViewSourceAction = new KAction( i18n("&View Source"), Key_V, this,
00240 SLOT(slotShowMsgSrc()), actionCollection(),
00241 "view_source" );
00242
00243
00244 mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00245 "mail_forward", actionCollection(),
00246 "message_forward" );
00247 connect( mForwardActionMenu, SIGNAL( activated() ), this,
00248 SLOT( slotForwardMsg() ) );
00249
00250 mForwardAction = new KAction( i18n("&Inline..."), "mail_forward",
00251 SHIFT+Key_F, this, SLOT(slotForwardMsg()),
00252 actionCollection(), "message_forward_inline" );
00253 mForwardActionMenu->insert( mForwardAction );
00254
00255 mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00256 "mail_forward", Key_F, this,
00257 SLOT(slotForwardAttachedMsg()), actionCollection(),
00258 "message_forward_as_attachment" );
00259 mForwardActionMenu->insert( mForwardAttachedAction );
00260
00261 mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00262 Key_E, this, SLOT(slotRedirectMsg()),
00263 actionCollection(), "message_forward_redirect" );
00264 mForwardActionMenu->insert( mRedirectAction );
00265
00266 mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00267 "mail_reply", actionCollection(),
00268 "message_reply_menu" );
00269 connect( mReplyActionMenu, SIGNAL(activated()), this,
00270 SLOT(slotReplyToMsg()) );
00271
00272 mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00273 SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00274 mReplyActionMenu->insert( mReplyAction );
00275
00276 mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00277 SHIFT+Key_A, this,
00278 SLOT(slotReplyAuthorToMsg()),
00279 actionCollection(), "reply_author" );
00280 mReplyActionMenu->insert( mReplyAuthorAction );
00281
00282 mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00283 Key_A, this, SLOT(slotReplyAllToMsg()),
00284 actionCollection(), "reply_all" );
00285 mReplyActionMenu->insert( mReplyAllAction );
00286
00287 mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00288 "mail_replylist", Key_L, this,
00289 SLOT(slotReplyListToMsg()), actionCollection(),
00290 "reply_list" );
00291 mReplyActionMenu->insert( mReplyListAction );
00292
00293
00294
00295 QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00296 accel->connectItem(accel->insertItem(Key_Up),
00297 mReaderWin, SLOT(slotScrollUp()));
00298 accel->connectItem(accel->insertItem(Key_Down),
00299 mReaderWin, SLOT(slotScrollDown()));
00300 accel->connectItem(accel->insertItem(Key_Prior),
00301 mReaderWin, SLOT(slotScrollPrior()));
00302 accel->connectItem(accel->insertItem(Key_Next),
00303 mReaderWin, SLOT(slotScrollNext()));
00304 accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00305 mReaderWin, SLOT(slotCopySelectedText()));
00306 connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00307 this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00308 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00309 mReaderWin, SLOT(slotUrlClicked()));
00310
00311 }
00312
00313
00314 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00315 {
00316 KPopupMenu * menu = new KPopupMenu;
00317 mUrl = aUrl;
00318 mMsg = &aMsg;
00319 bool urlMenuAdded=false;
00320
00321 if (!aUrl.isEmpty())
00322 {
00323 if (aUrl.protocol() == "mailto") {
00324
00325 mReaderWin->mailToComposeAction()->plug( menu );
00326 if ( mMsg ) {
00327 mReaderWin->mailToReplyAction()->plug( menu );
00328 mReaderWin->mailToForwardAction()->plug( menu );
00329 menu->insertSeparator();
00330 }
00331 mReaderWin->addAddrBookAction()->plug( menu );
00332 mReaderWin->openAddrBookAction()->plug( menu );
00333 mReaderWin->copyAction()->plug( menu );
00334 } else {
00335
00336 mReaderWin->urlOpenAction()->plug( menu );
00337 mReaderWin->addBookmarksAction()->plug( menu );
00338 mReaderWin->urlSaveAsAction()->plug( menu );
00339 mReaderWin->copyURLAction()->plug( menu );
00340 }
00341 urlMenuAdded=true;
00342 }
00343 if(mReaderWin && !mReaderWin->copyText().isEmpty()) {
00344 if ( urlMenuAdded )
00345 menu->insertSeparator();
00346 mReaderWin->copyAction()->plug( menu );
00347 mReaderWin->selectAllAction()->plug( menu );
00348 } else if ( !urlMenuAdded )
00349 {
00350
00351
00352 if (!mMsg)
00353 {
00354 delete menu;
00355 return;
00356 }
00357
00358 if( !aMsg.parent()->isSent() && !aMsg.parent()->isDrafts() ) {
00359 mReplyActionMenu->plug( menu );
00360 mForwardActionMenu->plug( menu );
00361 menu->insertSeparator();
00362 }
00363
00364 QPopupMenu* copyMenu = new QPopupMenu(menu);
00365 KMMainWidget* mainwin = kmkernel->getKMMainWidget();
00366 if ( mainwin )
00367 mainwin->folderTree()->folderToPopupMenu( KMFolderTree::CopyMessage, this,
00368 &mMenuToFolder, copyMenu );
00369 menu->insertItem( i18n("&Copy To" ), copyMenu );
00370 menu->insertSeparator();
00371 mViewSourceAction->plug( menu );
00372 mReaderWin->toggleFixFontAction()->plug( menu );
00373 menu->insertSeparator();
00374 mPrintAction->plug( menu );
00375 menu->insertItem( SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00376 menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00377 }
00378 menu->exec(aPoint, 0);
00379 delete menu;
00380 }
00381
00382 void KMReaderMainWin::copySelectedToFolder( int menuId )
00383 {
00384 if (!mMenuToFolder[menuId])
00385 return;
00386
00387 KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00388 command->start();
00389 }
00390
00391 #include "kmreadermainwin.moc"