Commit 0daea82c authored by Laurent Montel's avatar Laurent Montel 😁

Create a new action menu for show transport name. Fix bug, remove duplicate code

parent 5b2ec36c
......@@ -180,6 +180,7 @@ if (KDEPIM_BUILD_DESKTOP)
widgets/vacationscriptindicatorwidget.cpp
widgets/displaymessageformatactionmenu.cpp
widgets/statusbarlabeltoggledstate.cpp
widgets/kactionmenutransport.cpp
)
set(kmailprivate_tag_LIB_SRCS
tag/tagactionmanager.cpp
......
......@@ -65,6 +65,7 @@
#include "pimcommon/util/vcardutil.h"
#include "editor/potentialphishingemail/potentialphishingemailwarning.h"
#include "kmcomposerglobalaction.h"
#include "widgets/kactionmenutransport.h"
#include "libkdepim/progresswidget/statusbarprogresswidget.h"
#include "libkdepim/progresswidget/progressstatusbarwidget.h"
......@@ -1100,26 +1101,9 @@ void KMComposeWin::setQuotePrefix( uint uoid )
}
void KMComposeWin::getTransportMenu()
{
mActNowMenu->clear();
mActLaterMenu->clear();
const QList<Transport*> transports = TransportManager::self()->transports();
foreach ( Transport *transport, transports ) {
const QString name = transport->name().replace( QLatin1Char('&'), QLatin1String("&&") );
QAction *action1 = new QAction( name, mActNowMenu );
QAction *action2 = new QAction( name, mActLaterMenu );
action1->setData( transport->id() );
action2->setData( transport->id() );
mActNowMenu->addAction( action1 );
mActLaterMenu->addAction( action2 );
}
}
void KMComposeWin::setupActions( void )
{
KActionMenu *actActionNowMenu, *actActionLaterMenu;
KActionMenuTransport *actActionNowMenu, *actActionLaterMenu;
if ( MessageComposer::MessageComposerSettings::self()->sendImmediate() ) {
//default = send now, alternative = queue
......@@ -1134,14 +1118,18 @@ void KMComposeWin::setupActions( void )
// FIXME: change to mail_send_via icon when this exist.
actActionNowMenu = new KActionMenu( KIcon( QLatin1String("mail-send") ), i18n("&Send Mail Via"), this );
actActionNowMenu = new KActionMenuTransport( this);
actActionNowMenu->setIcon(KIcon( QLatin1String("mail-send") ));
actActionNowMenu->setText( i18n("&Send Mail Via") );
actActionNowMenu->setIconText( i18n( "Send" ) );
actionCollection()->addAction( QLatin1String("send_default_via"), actActionNowMenu );
action = new KAction( KIcon( QLatin1String("mail-queue") ), i18n("Send &Later"), this );
actionCollection()->addAction( QLatin1String("send_alternative"), action );
connect( action, SIGNAL(triggered(bool)), SLOT(slotSendLater()) );
actActionLaterMenu = new KActionMenu( KIcon( QLatin1String("mail-queue") ), i18n("Send &Later Via"), this );
actActionLaterMenu = new KActionMenuTransport( this );
actActionLaterMenu->setIcon(KIcon( QLatin1String("mail-queue") ));
actActionLaterMenu->setText(i18n("Send &Later Via"));
actActionLaterMenu->setIconText( i18nc( "Queue the message for sending at a later date", "Queue" ) );
actionCollection()->addAction( QLatin1String("send_alternative_via"), actActionLaterMenu );
......@@ -1151,7 +1139,9 @@ void KMComposeWin::setupActions( void )
actionCollection()->addAction( QLatin1String("send_mail"), action );
connect( action, SIGNAL(triggered(bool)), SLOT(slotSendLater()) );
action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_Return ) );
actActionLaterMenu = new KActionMenu( KIcon( QLatin1String("mail-queue") ), i18n("Send &Later Via"), this );
actActionLaterMenu = new KActionMenuTransport( this );
actActionLaterMenu->setIcon(KIcon( QLatin1String("mail-queue") ));
actActionLaterMenu->setText( i18n("Send &Later Via") );
actionCollection()->addAction( QLatin1String("send_default_via"), actActionLaterMenu );
action = new KAction( KIcon( QLatin1String("mail-send") ), i18n("&Send Mail"), this );
......@@ -1159,7 +1149,9 @@ void KMComposeWin::setupActions( void )
connect( action, SIGNAL(triggered(bool)), SLOT(slotSendNow()) );
// FIXME: change to mail_send_via icon when this exits.
actActionNowMenu = new KActionMenu( KIcon( QLatin1String("mail-send") ), i18n("&Send Mail Via"), this );
actActionNowMenu = new KActionMenuTransport(this);
actActionNowMenu->setIcon(KIcon( QLatin1String("mail-send") ));
actActionNowMenu->setText(i18n("&Send Mail Via"));
actionCollection()->addAction( QLatin1String("send_alternative_via"), actActionNowMenu );
}
......@@ -1172,16 +1164,11 @@ void KMComposeWin::setupActions( void )
SLOT(slotSendNow()) );
connect( actActionLaterMenu, SIGNAL(triggered(bool)), this,
SLOT(slotSendLater()) );
connect( actActionNowMenu, SIGNAL(transportSelected(MailTransport::Transport*)), this,
SLOT(slotSendNowVia(MailTransport::Transport*)));
connect( actActionLaterMenu, SIGNAL(transportSelected(MailTransport::Transport*)), this,
SLOT(slotSendLaterVia(MailTransport::Transport*)));
mActNowMenu = actActionNowMenu->menu();
mActLaterMenu = actActionLaterMenu->menu();
connect( TransportManager::self(), SIGNAL(transportsChanged()), this, SLOT(getTransportMenu()));
connect( mActNowMenu, SIGNAL(triggered(QAction*)), this,
SLOT(slotSendNowVia(QAction*)) );
connect( mActLaterMenu, SIGNAL(triggered(QAction*)), this,
SLOT(slotSendLaterVia(QAction*)) );
KAction *action = new KAction( KIcon( QLatin1String("document-save") ), i18n("Save as &Draft"), this );
actionCollection()->addAction(QLatin1String("save_in_drafts"), action );
......@@ -1454,7 +1441,6 @@ void KMComposeWin::setupActions( void )
if ( configureAction ) {
configureAction->setText( i18n("Configure KMail..." ) );
}
getTransportMenu();
}
void KMComposeWin::changeCryptoAction()
......@@ -2848,23 +2834,19 @@ void KMComposeWin::slotSaveTemplate()
}
void KMComposeWin::slotSendNowVia( QAction *item )
void KMComposeWin::slotSendNowVia( MailTransport::Transport *transport )
{
const QList<int> availTransports= TransportManager::self()->transportIds();
const int transport = item->data().toInt();
if ( availTransports.contains( transport ) ) {
mComposerBase->transportComboBox()->setCurrentTransport( transport );
if ( transport ) {
mComposerBase->transportComboBox()->setCurrentTransport( transport->id() );
slotSendNow();
}
}
void KMComposeWin::slotSendLaterVia( QAction *item )
void KMComposeWin::slotSendLaterVia( MailTransport::Transport *transport )
{
const QList<int> availTransports= TransportManager::self()->transportIds();
const int transport = item->data().toInt();
if ( availTransports.contains( transport ) ) {
mComposerBase->transportComboBox()->setCurrentTransport( transport );
if ( transport ) {
mComposerBase->transportComboBox()->setCurrentTransport( transport->id() );
slotSendLater();
}
}
......
......@@ -75,7 +75,9 @@ class KMComposerGlobalAction;
namespace boost {
template <typename T> class shared_ptr;
}
namespace MailTransport {
class Transport;
}
namespace KPIMIdentities {
class Identity;
}
......@@ -300,10 +302,9 @@ private slots:
void slotInsertRecentFile( const KUrl & );
void slotRecentListFileClear();
void slotSendNowVia( QAction * );
void slotSendNowVia(MailTransport::Transport *transport );
void slotSendLater();
void slotSendLaterVia( QAction * );
void getTransportMenu();
void slotSendLaterVia(MailTransport::Transport *transport );
/**
* Returns true when saving was successful.
......@@ -656,8 +657,6 @@ private:
int mLabelWidth;
QMenu *mActNowMenu;
QMenu *mActLaterMenu;
KActionMenu *mChangeCaseMenu;
QString mdbusObjectPath;
......
......@@ -42,6 +42,7 @@
#include "foldershortcutactionmanager.h"
#include "widgets/collectionpane.h"
#include "manageshowcollectionproperties.h"
#include "widgets/kactionmenutransport.h"
#if !defined(NDEBUG)
#include <ksieveui/debug/sievedebugdialog.h>
using KSieveUi::SieveDebugDialog;
......@@ -2309,12 +2310,11 @@ void KMMainWidget::slotSendQueued()
}
//-----------------------------------------------------------------------------
void KMMainWidget::slotSendQueuedVia( QAction *item )
void KMMainWidget::slotSendQueuedVia(MailTransport::Transport *transport)
{
const QStringList availTransports = MailTransport::TransportManager::self()->transportNames();
if ( !availTransports.isEmpty() && availTransports.contains( item->text() ) ) {
if (transport) {
if ( kmkernel->msgSender() ) {
kmkernel->msgSender()->sendQueued( item->text() );
kmkernel->msgSender()->sendQueued( transport->name() );
}
}
}
......@@ -2806,20 +2806,6 @@ void KMMainWidget::getAccountMenu()
}
}
//-----------------------------------------------------------------------------
void KMMainWidget::getTransportMenu()
{
mSendMenu->clear();
QStringList availTransports = MailTransport::TransportManager::self()->transportNames();
QStringList::Iterator it;
QStringList::Iterator end( availTransports.end() );
for (it = availTransports.begin(); it != end ; ++it)
mSendMenu->addAction((*it).replace(QLatin1Char('&'), QLatin1String("&&")));
}
//-----------------------------------------------------------------------------
void KMMainWidget::setupActions()
{
......@@ -2875,13 +2861,13 @@ void KMMainWidget::setupActions()
action->setText( i18n("Online status (unknown)") );
}
mSendActionMenu = new KActionMenu(KIcon(QLatin1String("mail-send-via")), i18n("Send Queued Messages Via"), this);
mSendActionMenu = new KActionMenuTransport(this);
mSendActionMenu->setIcon(KIcon(QLatin1String("mail-send-via")));
mSendActionMenu->setText(i18n("Send Queued Messages Via"));
actionCollection()->addAction(QLatin1String("send_queued_via"), mSendActionMenu );
mSendActionMenu->setDelayed(true);
mSendMenu = mSendActionMenu->menu();
connect(mSendMenu,SIGNAL(triggered(QAction*)), SLOT(slotSendQueuedVia(QAction*)));
connect(mSendMenu,SIGNAL(aboutToShow()),SLOT(getTransportMenu()));
connect(mSendActionMenu, SIGNAL(transportSelected(MailTransport::Transport*)), SLOT(slotSendQueuedVia(MailTransport::Transport*)));
//----- Tools menu
if (parent()->inherits("KMMainWin")) {
......
......@@ -38,6 +38,9 @@
#include <akonadi/tag.h>
#include <messagelist/core/view.h>
namespace MailTransport {
class Transport;
}
namespace Akonadi {
class Tag;
}
......@@ -60,6 +63,7 @@ class KMCommand;
class KMMoveCommand;
class KRecentFilesAction;
class ManageShowCollectionProperties;
class KActionMenuTransport;
template <typename T, typename S> class QMap;
namespace KIO {
......@@ -129,7 +133,7 @@ public:
KAction *editAction() const { return mMsgActions->editAction(); }
KAction *sendAgainAction() const { return mSendAgainAction; }
KAction *sendQueuedAction() const { return mSendQueued; }
KActionMenu *sendQueueViaMenu() const { return mSendActionMenu; }
KActionMenuTransport *sendQueueViaMenu() const { return mSendActionMenu; }
KMail::MessageActions *messageActions() const { return mMsgActions; }
......@@ -290,7 +294,6 @@ protected slots:
void updateFileMenu();
void slotCheckOneAccount( QAction* );
void getAccountMenu();
void getTransportMenu();
void slotHelp();
void slotFilter();
void slotManageSieveScripts();
......@@ -332,7 +335,7 @@ protected slots:
void slotSetThreadStatusWatched();
void slotSetThreadStatusIgnored();
void slotSendQueued();
void slotSendQueuedVia( QAction* item );
void slotSendQueuedVia(MailTransport::Transport*transport);
void slotOnlineStatus();
void slotUpdateOnlineStatus( GlobalSettings::EnumNetworkState::type );
void slotMessagePopup(const Akonadi::Item& ,const KUrl&,const KUrl &imageUrl,const QPoint& );
......@@ -523,7 +526,7 @@ private:
*mSaveAttachmentsAction, *mOpenAction,
*mMoveMsgToFolderAction, *mCollectionProperties, *mSendQueued;
KAction *mArchiveAction;
KActionMenu *mSendActionMenu;
KActionMenuTransport *mSendActionMenu;
// Filter actions
KActionMenu *mFilterMenu;
KAction *mExpireConfigAction;
......@@ -548,7 +551,6 @@ private:
QSplitter *mSplitter1, *mSplitter2, *mFolderViewSplitter;
Akonadi::Collection mTemplateFolder;
QMenu *mActMenu;
QMenu *mSendMenu;
bool mLongFolderList;
bool mStartupDone;
bool mWasEverShown;
......
......@@ -35,6 +35,7 @@
#include <KLocalizedString>
#include <KAction>
#include <KActionMenu>
#include "widgets/kactionmenutransport.h"
#include <KActionCollection>
#include <QPainter>
......
......@@ -37,6 +37,9 @@ set( kmail_cryptostateindicatorwidgettest_source cryptostateindicatorwidgettest.
kde4_add_unit_test( cryptostateindicatorwidgettest ${kmail_cryptostateindicatorwidgettest_source})
target_link_libraries( cryptostateindicatorwidgettest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} messagecore)
set( kmail_kactionmenutransporttest_source kactionmenutransporttest.cpp ../widgets/kactionmenutransport.cpp)
kde4_add_unit_test( kactionmenutransporttest ${kmail_kactionmenutransporttest_source})
target_link_libraries( kactionmenutransporttest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_MAILTRANSPORT_LIBS})
include(AkonadiMacros)
set(KDEPIMLIBS_RUN_ISOLATED_TESTS TRUE)
......
/*
Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 "kactionmenutransporttest.h"
#include "../widgets/kactionmenutransport.h"
#include <qtest_kde.h>
#include <KMenu>
KActionMenuTransportTest::KActionMenuTransportTest(QObject *parent)
: QObject(parent)
{
}
KActionMenuTransportTest::~KActionMenuTransportTest()
{
}
void KActionMenuTransportTest::shouldHaveDefaultValue()
{
KActionMenuTransport w;
QVERIFY(w.menu());
QCOMPARE(w.menu()->actions().count(), 0);
}
QTEST_KDEMAIN(KActionMenuTransportTest, GUI)
/*
Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
*/
#ifndef KACTIONMENUTRANSPORTTEST_H
#define KACTIONMENUTRANSPORTTEST_H
#include <QObject>
class KActionMenuTransportTest : public QObject
{
Q_OBJECT
public:
explicit KActionMenuTransportTest(QObject *parent = 0);
~KActionMenuTransportTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // KACTIONMENUTRANSPORTTEST_H
/*
Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 "kactionmenutransport.h"
#include <KMenu>
#include <mailtransport/transportmanager.h>
KActionMenuTransport::KActionMenuTransport(QObject *parent)
: KActionMenu(parent),
mInitialized(false)
{
connect( MailTransport::TransportManager::self(), SIGNAL(transportsChanged()), this, SLOT(updateTransportMenu()));
connect( menu(),SIGNAL(aboutToShow()),SLOT(slotCheckTransportMenu()));
connect( menu(), SIGNAL(triggered(QAction*)), this, SLOT(slotSelectTransport(QAction*)) );
}
KActionMenuTransport::~KActionMenuTransport()
{
}
void KActionMenuTransport::slotCheckTransportMenu()
{
if (!mInitialized) {
updateTransportMenu();
mInitialized = true;
}
}
void KActionMenuTransport::updateTransportMenu()
{
menu()->clear();
const QList<MailTransport::Transport*> transports = MailTransport::TransportManager::self()->transports();
Q_FOREACH (MailTransport::Transport *transport, transports ) {
const QString name = transport->name().replace( QLatin1Char('&'), QLatin1String("&&") );
QAction *action = new QAction( name, this );
action->setData( transport->id() );
menu()->addAction( action );
}
}
void KActionMenuTransport::slotSelectTransport(QAction *act)
{
const QList<int> availTransports = MailTransport::TransportManager::self()->transportIds();
const int transportId = act->data().toInt();
if ( availTransports.contains( transportId ) ) {
MailTransport::Transport *transport = MailTransport::TransportManager::self()->transportById(transportId);
Q_EMIT transportSelected(transport);
}
}
/*
Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
*/
#ifndef KACTIONMENUTRANSPORT_H
#define KACTIONMENUTRANSPORT_H
#include <KActionMenu>
namespace MailTransport {
class Transport;
}
class KActionMenuTransport : public KActionMenu
{
Q_OBJECT
public:
explicit KActionMenuTransport(QObject *parent=0);
~KActionMenuTransport();
Q_SIGNALS:
void transportSelected(MailTransport::Transport *transport);
private Q_SLOTS:
void updateTransportMenu();
void slotCheckTransportMenu();
void slotSelectTransport(QAction *act);
private:
bool mInitialized;
};
#endif // KACTIONMENUTRANSPORT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment