@ -1,72 +1,68 @@
/* -*- mode: C++; c-file-style: "gnu" -*-
* kmail : KDE mail client
* This file : Copyright ( C ) 2006 Dmitry Morozhnikov
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
*/
* kmail : KDE mail client
* This file : Copyright ( C ) 2006 Dmitry Morozhnikov < dmiceman @ ubiz . ru >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
# include "customtemplatesmenu.h"
# include <QSignalMapper>
# include "customtemplates.h"
# include "customtemplates_kfg.h"
# include "globalsettings.h"
# include "kmkernel.h"
# include <klocale.h>
# include <kactionmenu.h>
# include <kmenu.h>
# include <kactioncollection.h>
# include "customtemplates.h"
# include "customtemplates_kfg.h"
# include "globalsettings.h"
# include "kmkernel.h"
# include <QSignalMapper>
CustomTemplatesMenu : : CustomTemplatesMenu ( QWidget * owner , KActionCollection * ac )
CustomTemplatesMenu : : CustomTemplatesMenu ( QWidget * owner , KActionCollection * ac )
{
mOwnerActionCollection = ac ;
mCustomForwardActionMenu = new KActionMenu ( KIcon ( " mail-forward-custom " ) ,
i18n ( " With Custom Template " ) , owner ) ;
i18n ( " With Custom Template " ) , owner ) ;
mOwnerActionCollection - > addAction ( " custom_forward " , mCustomForwardActionMenu ) ;
mCustomReplyActionMenu = new KActionMenu ( KIcon ( " mail-reply-custom " ) ,
i18n ( " Reply With Custom Template " ) , owner ) ;
i18n ( " Reply With Custom Template " ) , owner ) ;
mOwnerActionCollection - > addAction ( " custom_reply " , mCustomReplyActionMenu ) ;
mCustomReplyAllActionMenu = new KActionMenu ( KIcon ( " mail-reply-all-custom " ) ,
i18n ( " Reply to All With Custom Template " ) , owner ) ;
i18n ( " Reply to All With Custom Template " ) , owner ) ;
mOwnerActionCollection - > addAction ( " custom_reply_all " , mCustomReplyAllActionMenu ) ;
mCustomForwardMapper = new QSignalMapper ( this ) ;
connect ( mCustomForwardMapper , SIGNAL ( mapped ( int ) ) ,
this , SLOT ( slotForwardSelected ( int ) ) ) ;
connect ( mCustomForwardMapper , SIGNAL ( mapped ( int ) ) ,
this , SLOT ( slotForwardSelected ( int ) ) ) ;
mCustomReplyMapper = new QSignalMapper ( this ) ;
connect ( mCustomReplyMapper , SIGNAL ( mapped ( int ) ) ,
this , SLOT ( slotReplySelected ( int ) ) ) ;
connect ( mCustomReplyMapper , SIGNAL ( mapped ( int ) ) ,
this , SLOT ( slotReplySelected ( int ) ) ) ;
mCustomReplyAllMapper = new QSignalMapper ( this ) ;
connect ( mCustomReplyAllMapper , SIGNAL ( mapped ( int ) ) ,
this , SLOT ( slotReplyAllSelected ( int ) ) ) ;
connect ( mCustomReplyAllMapper , SIGNAL ( mapped ( int ) ) ,
this , SLOT ( slotReplyAllSelected ( int ) ) ) ;
connect ( kmkernel , SIGNAL ( customTemplatesChanged ( ) ) , this , SLOT ( update ( ) ) ) ;
update ( ) ;
}
CustomTemplatesMenu : : ~ CustomTemplatesMenu ( )
{
clear ( ) ;
@ -80,20 +76,17 @@ CustomTemplatesMenu::~CustomTemplatesMenu()
delete mCustomForwardMapper ;
}
void CustomTemplatesMenu : : clear ( )
{
if ( ! mCustomTemplateActions . isEmpty ( ) ) {
for ( QList < KAction * > : : iterator ait = mCustomTemplateActions . begin ( ) ;
ait ! = mCustomTemplateActions . end ( ) ; + + ait ) {
KAction * action = ( * ait ) ;
mCustomReplyMapper - > removeMappings ( action ) ;
mCustomReplyAllMapper - > removeMappings ( action ) ;
mCustomForwardMapper - > removeMappings ( action ) ;
delete action ;
}
mCustomTemplateActions . clear ( ) ;
QListIterator < KAction * > ait ( mCustomTemplateActions ) ;
while ( ait . hasNext ( ) ) {
KAction * action = ait . next ( ) ;
mCustomReplyMapper - > removeMappings ( action ) ;
mCustomReplyAllMapper - > removeMappings ( action ) ;
mCustomForwardMapper - > removeMappings ( action ) ;
}
qDeleteAll ( mCustomTemplateActions ) ;
mCustomTemplateActions . clear ( ) ;
mCustomReplyActionMenu - > menu ( ) - > clear ( ) ;
mCustomReplyAllActionMenu - > menu ( ) - > clear ( ) ;
@ -101,11 +94,8 @@ void CustomTemplatesMenu::clear()
mCustomTemplates . clear ( ) ;
}
void CustomTemplatesMenu : : update ( )
{
//kDebug(5006) << "updating";
clear ( ) ;
QStringList list = GlobalSettingsBase : : self ( ) - > customTemplates ( ) ;
@ -129,6 +119,7 @@ void CustomTemplatesMenu::update()
mCustomTemplateActions . append ( action ) ;
+ + replyc ;
break ;
case CustomTemplates : : TReplyAll :
action = new KAction ( ( * it ) . replace ( " & " , " && " ) , mOwnerActionCollection ) ;
action - > setShortcut ( t . shortcut ( ) ) ;
@ -138,6 +129,7 @@ void CustomTemplatesMenu::update()
mCustomTemplateActions . append ( action ) ;
+ + replyallc ;
break ;
case CustomTemplates : : TForward :
action = new KAction ( ( * it ) . replace ( " & " , " && " ) , mOwnerActionCollection ) ;
action - > setShortcut ( t . shortcut ( ) ) ;
@ -147,6 +139,7 @@ void CustomTemplatesMenu::update()
mCustomTemplateActions . append ( action ) ;
+ + forwardc ;
break ;
case CustomTemplates : : TUniversal :
action = new KAction ( ( * it ) . replace ( " & " , " && " ) , mOwnerActionCollection ) ;
connect ( action , SIGNAL ( triggered ( bool ) ) , mCustomReplyMapper , SLOT ( map ( ) ) ) ;
@ -171,44 +164,40 @@ void CustomTemplatesMenu::update()
+ + idx ;
}
if ( ! replyc ) {
QAction * noAction = mCustomReplyActionMenu - > menu ( ) - > addAction (
i18n ( " (no custom templates) " ) ) ;
QAction * noAction =
mCustomReplyActionMenu - > menu ( ) - > addAction ( i18n ( " (no custom templates) " ) ) ;
noAction - > setEnabled ( false ) ;
mCustomReplyActionMenu - > setEnabled ( false ) ;
}
if ( ! replyallc ) {
QAction * noAction = mCustomReplyAllActionMenu - > menu ( ) - > addAction (
i18n ( " (no custom templates) " ) ) ;
QAction * noAction =
mCustomReplyAllActionMenu - > menu ( ) - > addAction ( i18n ( " (no custom templates) " ) ) ;
noAction - > setEnabled ( false ) ;
mCustomReplyAllActionMenu - > setEnabled ( false ) ;
}
if ( ! forwardc ) {
QAction * noAction = mCustomForwardActionMenu - > menu ( ) - > addAction (
i18n ( " (no custom templates) " ) ) ;
QAction * noAction =
mCustomForwardActionMenu - > menu ( ) - > addAction ( i18n ( " (no custom templates) " ) ) ;
noAction - > setEnabled ( false ) ;
mCustomForwardActionMenu - > setEnabled ( false ) ;
}
}
void CustomTemplatesMenu : : slotReplySelected ( int idx )
{
//kDebug(5006) << "selected idx=" << idx;
emit replyTemplateSelected ( mCustomTemplates [ idx ] ) ;
}
void CustomTemplatesMenu : : slotReplyAllSelected ( int idx )
{
//kDebug(5006) << "selected idx=" << idx;
emit replyAllTemplateSelected ( mCustomTemplates [ idx ] ) ;
}
void CustomTemplatesMenu : : slotForwardSelected ( int idx )
{
//kDebug(5006) << "selected idx=" << idx;
emit forwardTemplateSelected ( mCustomTemplates [ idx ] ) ;
}
# include "customtemplatesmenu.moc"