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