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 "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
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 mReaderWin = new KMReaderWin( this, this, actionCollection() );
00067 mReaderWin->setOverrideCodec( codec );
00068 mReaderWin->setMsgPart( aMsgPart, aHTML, aFileName, pname );
00069 setCentralWidget( mReaderWin );
00070 setupAccel();
00071
00072 connect( kmkernel, SIGNAL( configChanged() ),
00073 this, SLOT( slotConfigChanged() ) );
00074 }
00075
00076
00077 KMReaderMainWin::~KMReaderMainWin()
00078 {
00079 saveMainWindowSettings(KMKernel::config(), "Separate Reader Window");
00080 }
00081
00082
00083 void KMReaderMainWin::showMsg( const QTextCodec *codec, KMMessage *msg )
00084 {
00085 mReaderWin->setOverrideCodec( codec );
00086 mReaderWin->setMsg( msg, true );
00087 setCaption( msg->subject() );
00088 mMsg = msg;
00089 toolBar( "mainToolBar" )->show();
00090 }
00091
00092
00093 void KMReaderMainWin::slotPrintMsg()
00094 {
00095 KMCommand *command = new KMPrintCommand( this, mReaderWin->message(),
00096 mReaderWin->htmlOverride(), mReaderWin->overrideCodec() );
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
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 connect( mForwardActionMenu, SIGNAL( activated() ), this,
00206 SLOT( slotForwardMsg() ) );
00207
00208 mForwardAction = new KAction( i18n("&Inline..."), "mail_forward",
00209 SHIFT+Key_F, this, SLOT(slotForwardMsg()),
00210 actionCollection(), "message_forward_inline" );
00211 mForwardActionMenu->insert( mForwardAction );
00212
00213 mForwardAttachedAction = new KAction( i18n("Message->Forward->","As &Attachment..."),
00214 "mail_forward", Key_F, this,
00215 SLOT(slotForwardAttachedMsg()), actionCollection(),
00216 "message_forward_as_attachment" );
00217 mForwardActionMenu->insert( mForwardAttachedAction );
00218
00219 mRedirectAction = new KAction( i18n("Message->Forward->","&Redirect..."),
00220 Key_E, this, SLOT(slotRedirectMsg()),
00221 actionCollection(), "message_forward_redirect" );
00222 mForwardActionMenu->insert( mRedirectAction );
00223
00224 mBounceAction = new KAction( i18n("&Bounce..."), 0, this,
00225 SLOT(slotBounceMsg()), actionCollection(), "bounce" );
00226
00227
00228 mReplyActionMenu = new KActionMenu( i18n("Message->","&Reply"),
00229 "mail_reply", actionCollection(),
00230 "message_reply_menu" );
00231 connect( mReplyActionMenu, SIGNAL(activated()), this,
00232 SLOT(slotReplyToMsg()) );
00233
00234 mReplyAction = new KAction( i18n("&Reply..."), "mail_reply", Key_R, this,
00235 SLOT(slotReplyToMsg()), actionCollection(), "reply" );
00236 mReplyActionMenu->insert( mReplyAction );
00237
00238 mReplyAuthorAction = new KAction( i18n("Reply to A&uthor..."), "mail_reply",
00239 SHIFT+Key_A, this,
00240 SLOT(slotReplyAuthorToMsg()),
00241 actionCollection(), "reply_author" );
00242 mReplyActionMenu->insert( mReplyAuthorAction );
00243
00244 mReplyAllAction = new KAction( i18n("Reply to &All..."), "mail_replyall",
00245 Key_A, this, SLOT(slotReplyAllToMsg()),
00246 actionCollection(), "reply_all" );
00247 mReplyActionMenu->insert( mReplyAllAction );
00248
00249 mReplyListAction = new KAction( i18n("Reply to Mailing-&List..."),
00250 "mail_replylist", Key_L, this,
00251 SLOT(slotReplyListToMsg()), actionCollection(),
00252 "reply_list" );
00253 mReplyActionMenu->insert( mReplyListAction );
00254
00255 mPrintAction = KStdAction::print (this, SLOT(slotPrintMsg()), actionCollection());
00256 createGUI( "kmreadermainwin.rc" );
00257 menuBar()->hide();
00258 toolBar( "mainToolBar" )->hide();
00259 }
00260
00261
00262 void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KURL &aUrl, const QPoint& aPoint)
00263 {
00264 KPopupMenu * menu = new KPopupMenu;
00265 mUrl = aUrl;
00266 mMsg = &aMsg;
00267
00268 if (!aUrl.isEmpty()) {
00269 if (aUrl.protocol() == "mailto") {
00270
00271 mReaderWin->mailToComposeAction()->plug( menu );
00272 if ( mMsg ) {
00273 mReaderWin->mailToReplyAction()->plug( menu );
00274 mReaderWin->mailToForwardAction()->plug( menu );
00275 menu->insertSeparator();
00276 }
00277 mReaderWin->addAddrBookAction()->plug( menu );
00278 mReaderWin->openAddrBookAction()->plug( menu );
00279 mReaderWin->copyAction()->plug( menu );
00280 } else {
00281
00282 mReaderWin->urlOpenAction()->plug( menu );
00283 mReaderWin->urlSaveAsAction()->plug( menu );
00284 mReaderWin->copyURLAction()->plug( menu );
00285 mReaderWin->addBookmarksAction()->plug( menu );
00286 }
00287 } else {
00288
00289
00290 if (!mMsg)
00291 {
00292 delete menu;
00293 return;
00294 }
00295
00296 mReplyAction->plug( menu );
00297 mReplyAllAction->plug( menu );
00298 mReplyAuthorAction->plug( menu );
00299 mReplyListAction->plug( menu );
00300 mForwardActionMenu->plug( menu );
00301 mBounceAction->plug( menu );
00302
00303 menu->insertSeparator();
00304
00305 QPopupMenu* copyMenu = new QPopupMenu(menu);
00306 KMMenuCommand::folderToPopupMenu( false, this, &mMenuToFolder, copyMenu );
00307 menu->insertItem( i18n("&Copy To" ), copyMenu );
00308 menu->insertSeparator();
00309 mReaderWin->toggleFixFontAction()->plug( menu );
00310 mReaderWin->viewSourceAction()->plug( menu );
00311
00312 mPrintAction->plug( menu );
00313 menu->insertItem( SmallIcon("filesaveas"), i18n( "Save &As..." ), mReaderWin, SLOT( slotSaveMsg() ) );
00314 menu->insertItem( i18n("Save Attachments..."), mReaderWin, SLOT(slotSaveAttachments()) );
00315 }
00316 menu->exec(aPoint, 0);
00317 delete menu;
00318 }
00319
00320 void KMReaderMainWin::copySelectedToFolder( int menuId )
00321 {
00322 if (!mMenuToFolder[menuId])
00323 return;
00324
00325 KMCommand *command = new KMCopyCommand( mMenuToFolder[menuId], mMsg );
00326 command->start();
00327 }