00001
00002
00003
00004
00005
00006
00007
00008
00009
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>
00030 #include <kedittoolbar.h>
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
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() );
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
00099
00100 void KMReaderMainWin::slotPrintMsg()
00101 {
00102 KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00103 mReaderWin->htmlOverride(), mReaderWin->overrideEncoding(),
00104 mReaderWin->headerStyle(), mReaderWin->headerStrategy() );
00105 command->start();
00106 }
00107
00108
00109 void KMReaderMainWin::slotReplyToMsg()
00110 {
00111 KMCommand *command = new KMReplyToCommand( this, mReaderWin->message(),
00112 mReaderWin->copyText() );
00113 command->start();
00114 }
00115
00116
00117
00118 void KMReaderMainWin::slotReplyAuthorToMsg()
00119 {
00120 KMCommand *command = new KMReplyAuthorCommand( this, mReaderWin->message(),
00121 mReaderWin->copyText() );
00122 command->start();
00123 }
00124
00125
00126 void KMReaderMainWin::slotReplyAllToMsg()
00127 {
00128 KMCommand *command = new KMReplyToAllCommand( this, mReaderWin->message(),
00129 mReaderWin->copyText() );
00130 command->start();
00131 }
00132
00133
00134 void KMReaderMainWin::slotReplyListToMsg()
00135 {
00136 KMCommand *command = new KMReplyListCommand( this, mReaderWin->message(),
00137 mReaderWin->copyText() );
00138 command->start();
00139 }
00140
00141
00142 void KMReaderMainWin::slotForwardMsg()
00143 {
00144 KMCommand *command = 0;
00145 if ( mReaderWin->message()->parent() ) {
00146 command = new KMForwardCommand( this, mReaderWin->message(),
00147 mReaderWin->message()->parent()->identity() );
00148 } else {
00149 command = new KMForwardCommand( this, mReaderWin->message() );
00150 }
00151 command->start();
00152 }
00153
00154
00155 void KMReaderMainWin::slotForwardAttachedMsg()
00156 {
00157 KMCommand *command = 0;
00158 if ( mReaderWin->message()->parent() ) {
00159 command = new KMForwardAttachedCommand( this, mReaderWin->message(),
00160 mReaderWin->message()->parent()->identity() );
00161 } else {
00162 command = new KMForwardAttachedCommand( this, mReaderWin->message() );
00163 }
00164 command->start();
00165 }
00166
00167
00168 void KMReaderMainWin::slotRedirectMsg()
00169 {
00170 KMCommand *command = new KMRedirectCommand( this, mReaderWin->message() );
00171 command->start();
00172 }
00173
00174
00175
00176 void KMReaderMainWin::slotBounceMsg()
00177 {
00178 KMCommand *command = new KMBounceCommand( this, mReaderWin->message() );
00179 command->start();
00180 }
00181
00182
00183 void KMReaderMainWin::slotConfigChanged()
00184 {
00185
00186 }
00187
00188 void KMReaderMainWin::setupAccel()
00189 {
00190 if (kmkernel->xmlGuiInstance())
00191 setInstance( kmkernel->xmlGuiInstance() );
00192 KStdAction::close( this, SLOT( close() ), actionCollection() );
00193 applyMainWindowSettings(KMKernel::config(), "Separate Reader Window");
00194 QAccel *accel = new QAccel(mReaderWin, "showMsg()");
00195 accel->connectItem(accel->insertItem(Key_Up),
00196 mReaderWin, SLOT(slotScrollUp()));
00197 accel->connectItem(accel->insertItem(Key_Down),
00198 mReaderWin, SLOT(slotScrollDown()));
00199 accel->connectItem(accel->insertItem(Key_Prior),
00200 mReaderWin, SLOT(slotScrollPrior()));
00201 accel->connectItem(accel->insertItem(Key_Next),
00202 mReaderWin, SLOT(slotScrollNext()));
00203 accel->connectItem(accel->insertItem(KStdAccel::shortcut(KStdAccel::Copy)),
00204 mReaderWin, SLOT(slotCopySelectedText()));
00205 connect( mReaderWin, SIGNAL(popupMenu(KMMessage&,const KURL&,const QPoint&)),
00206 this, SLOT(slotMsgPopup(KMMessage&,const KURL&,const QPoint&)));
00207 connect(mReaderWin, SIGNAL(urlClicked(const KURL&,int)),
00208 mReaderWin, SLOT(slotUrlClicked()));
00209
00210 mForwardActionMenu = new KActionMenu( i18n("Message->","&Forward"),
00211 "mail_forward", actionCollection(),
00212 "message_forward" );
00213
00214 mForwardInlineAction = new KAction( i18n("&Inline..."),
00215 "mail_forward", SHIFT+Key_F, this,
00216 SLOT(slotForwardMsg()),
00217 actionCollection(),
00218 "message_forward_inline" );
00219
00220 mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00221 "mail_forward", Key_F, this,
00222 SLOT(slotForwardAttachedMsg()),
00223 actionCollection(),
00224 "message_forward_as_attachment" );
00225
00226 mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00227 Key_E, this, SLOT(slotRedirectMsg()),
00228 actionCollection(), "message_forward_redirect" );
00229
00230 if ( GlobalSettings::self()->forwardingInlineByDefault() ) {
00231 mForwardActionMenu->insert( mForwardInlineAction );
00232 mForwardActionMenu->insert( mForwardAttachedAction );
00233 mForwardInlineAction->setShortcut( Key_F );
00234 mForwardAttachedAction->setShortcut( SHIFT+Key_F );
00235 connect( mForwardActionMenu, SIGNAL(activated()), this,
00236 SLOT(slotForwardMsg()) );
00237 } else {
00238 mForwardActionMenu->insert( mForwardAttachedAction );
00239 mForwardActionMenu->insert( mForwardInlineAction );
00240 mForwardInlineAction->setShortcut( SHIFT+Key_F );
00241 mForwardAttachedAction->setShortcut( Key_F );
00242 connect( mForwardActionMenu, SIGNAL(activated()), this,
00243 SLOT(slotForwardAttachedMsg()) );
00244 }
00245
00246 mForwardActionMenu->insert( mRedirectAction );
00247
00248
00249 mBounceAction = new KAction( i18n("&Bounce..."), 0, this,
00250 SLOT(slotBounceMsg()), actionCollection(), "bounce" );
00251
00252
00253 mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00254 "mail_reply", actionCollection(),
00255 "message_reply_menu" );
00256 connect( mReplyActionMenu, SIGNAL(activated()), this,
00257 SLOT(slotReplyToMsg()) );
00258
00259 mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00260 SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00261 mReplyActionMenu->insert( mReplyAction );
00262
00263 mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00264 SHIFT+Key_A, this,
00265 SLOT(slotReplyAuthorToMsg()),
00266 actionCollection(), "reply_author" );
00267 mReplyActionMenu->insert( mReplyAuthorAction );
00268
00269 mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00270 Key_A, this, SLOT(slotReplyAllToMsg()),
00271 actionCollection(), "reply_all" );
00272 mReplyActionMenu->insert( mReplyAllAction );
00273
00274 mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00275 "mail_replylist", Key_L, this,
00276 SLOT(slotReplyListToMsg()), actionCollection(),
00277 "reply_list" );
00278 mReplyActionMenu->insert( mReplyListAction );
00279
00280 mPrintAction = KStdAction::print (this, SLOT(slotPrintMsg()), actionCollection());
00281
00282 KStdAction::keyBindings(this, SLOT(slotEditKeys()), actionCollection());
00283 KStdAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
00284
00285 mSelectAllTextAction = new KAction( i18n("Select Message &Text"),
00286 CTRL+SHIFT+Key_A, mReaderWin,
00287 SLOT(selectAll()), actionCollection(), "mark_all_text" );
00288 mCopyMsgTextAction = new KAction( i18n("Copy Text"),
00289 "editcopy", CTRL + Key_C, mReaderWin,
00290 SLOT(slotCopySelectedText()), actionCollection(),
00291 "kmail_copy" );
00292
00293 createGUI( "kmreadermainwin.rc" );
00294
00295
00296 }
00297
00298 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00299 {
00300 KPopupMenu * menu = new KPopupMenu;
00301 mUrl = aUrl;
00302 mMsg = &aMsg;
00303
00304 if (!aUrl.isEmpty()) {
00305 if (aUrl.protocol() == "mailto") {
00306
00307 mReaderWin->mailToComposeAction()->plug( menu );
00308 if ( mMsg ) {
00309 mReaderWin->mailToReplyAction()->plug( menu );
00310 mReaderWin->mailToForwardAction()->plug( menu );
00311 menu->insertSeparator();
00312 }
00313 mReaderWin->addAddrBookAction()->plug( menu );
00314 mReaderWin->openAddrBookAction()->plug( menu );
00315 mReaderWin->copyAction()->plug( menu );
00316 } else {
00317
00318 mReaderWin->urlOpenAction()->plug( menu );
00319 mReaderWin->urlSaveAsAction()->plug( menu );
00320 mReaderWin->copyURLAction()->plug( menu );
00321 mReaderWin->addBookmarksAction()->plug( menu );
00322 }
00323 } else {
00324
00325
00326 if (!mMsg)
00327 {
00328 delete menu;
00329 return;
00330 }
00331
00332 mReplyAction->plug( menu );
00333 mReplyAllAction->plug( menu );
00334 mReplyAuthorAction->plug( menu );
00335 mReplyListAction->plug( menu );
00336 mForwardActionMenu->plug( menu );
00337 mBounceAction->plug( menu );
00338
00339 menu->insertSeparator();
00340
00341 QPopupMenu* copyMenu = new QPopupMenu(menu);
00342 KMMenuCommand::folderToPopupMenu( false, this, &mMenuToFolder, copyMenu );
00343 menu->insertItem( i18n("&Copy To" ), copyMenu );
00344 menu->insertSeparator();
00345 mReaderWin->toggleFixFontAction()->plug( menu );
00346 mReaderWin->viewSourceAction()->plug( menu );
00347
00348 menu->insertSeparator();
00349 mSelectAllTextAction->plug( menu );
00350 mCopyMsgTextAction->plug( menu );
00351 menu->insertSeparator();
00352
00353 mPrintAction->plug( menu );
00354 menu->insertItem( SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00355 menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00356 }
00357 menu->exec(aPoint, 0);
00358 delete menu;
00359 }
00360
00361 void KMReaderMainWin::copySelectedToFolder( int menuId )
00362 {
00363 if (!mMenuToFolder[menuId])
00364 return;
00365
00366 KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00367 command->start();
00368 }
00369
00370
00371 void KMReaderMainWin::slotEditToolbars()
00372 {
00373 saveMainWindowSettings(KMKernel::config(), "Reader");
00374 KEditToolbar dlg(guiFactory(), this);
00375
00376 connect( &dlg, SIGNAL(newToolbarConfig()),
00377 SLOT(slotUpdateToolbars()) );
00378
00379 dlg.exec();
00380 }
00381
00382 void KMReaderMainWin::slotUpdateToolbars()
00383 {
00384 createGUI("kmreadermainwin.rc");
00385 applyMainWindowSettings(KMKernel::config(), "Reader");
00386 }
00387
00388 void KMReaderMainWin::slotEditKeys()
00389 {
00390 KKeyDialog::configure( actionCollection(),
00391 false
00392 );
00393 }
00394