Fix porting bug where clearing Custom Templates would crash.

I think there was a bug report for this but I can't find it.

Also clean the coding style and add Dmitry's email address to the copyright.

svn path=/trunk/KDE/kdepim/; revision=772005
wilder-work
Allen Winter 18 years ago
parent a21eeddac2
commit af209dd5d9
  1. 111
      customtemplatesmenu.cpp
  2. 60
      customtemplatesmenu.h

@ -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"

@ -1,6 +1,6 @@
/* -*- mode: C++; c-file-style: "gnu" -*-
* kmail: KDE mail client
* This file: Copyright (C) 2006 Dmitry Morozhnikov
* 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
@ -12,13 +12,11 @@
* 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.
*
* 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.
*/
#ifndef CUSTOMTEMPLATESMENU_H
#define CUSTOMTEMPLATESMENU_H
@ -36,40 +34,40 @@ class CustomTemplatesMenu : public QObject
{
Q_OBJECT
public:
CustomTemplatesMenu(QWidget *parent,KActionCollection *ac);
~CustomTemplatesMenu();
public:
CustomTemplatesMenu( QWidget *parent, KActionCollection *ac );
~CustomTemplatesMenu();
KActionMenu *replyActionMenu() const { return (mCustomReplyActionMenu); }
KActionMenu *replyAllActionMenu() const { return (mCustomReplyAllActionMenu); }
KActionMenu *forwardActionMenu() const { return (mCustomForwardActionMenu); }
KActionMenu *replyActionMenu() const { return (mCustomReplyActionMenu); }
KActionMenu *replyAllActionMenu() const { return (mCustomReplyAllActionMenu); }
KActionMenu *forwardActionMenu() const { return (mCustomForwardActionMenu); }
public slots:
void update();
public slots:
void update();
signals:
void replyTemplateSelected( const QString &tmpl );
void replyAllTemplateSelected( const QString &tmpl );
void forwardTemplateSelected( const QString &tmpl );
signals:
void replyTemplateSelected( const QString &tmpl );
void replyAllTemplateSelected( const QString &tmpl );
void forwardTemplateSelected( const QString &tmpl );
private slots:
void slotReplySelected( int idx );
void slotReplyAllSelected( int idx );
void slotForwardSelected( int idx );
private slots:
void slotReplySelected( int idx );
void slotReplyAllSelected( int idx );
void slotForwardSelected( int idx );
private:
void clear();
private:
void clear();
KActionCollection *mOwnerActionCollection;
KActionCollection *mOwnerActionCollection;
QVector<QString> mCustomTemplates;
QList<KAction*> mCustomTemplateActions;
QVector<QString> mCustomTemplates;
QList<KAction*> mCustomTemplateActions;
// Custom template actions menu
KActionMenu *mCustomReplyActionMenu, *mCustomReplyAllActionMenu, *mCustomForwardActionMenu;
// Custom template actions menu
KActionMenu *mCustomReplyActionMenu, *mCustomReplyAllActionMenu, *mCustomForwardActionMenu;
// Signal mappers for custom template actions
QSignalMapper *mCustomReplyMapper, *mCustomReplyAllMapper, *mCustomForwardMapper;
// Signal mappers for custom template actions
QSignalMapper *mCustomReplyMapper, *mCustomReplyAllMapper, *mCustomForwardMapper;
};
#endif // CUSTOMTEMPLATESMENU_H

Loading…
Cancel
Save