Commit fda8ae04 authored by Laurent Montel's avatar Laurent Montel 😁

Reduce duplicate code

parent 8e94f652
......@@ -182,6 +182,7 @@ if (KDEPIM_BUILD_DESKTOP)
widgets/statusbarlabeltoggledstate.cpp
widgets/kactionmenutransport.cpp
widgets/kactionmenuaccount.cpp
widgets/kactionmenuchangecase.cpp
)
set(kmailprivate_tag_LIB_SRCS
tag/tagactionmanager.cpp
......
......@@ -23,7 +23,7 @@
#include "editor/kmcomposewin.h"
#include "kmcommands.h"
#include "util.h"
#include "widgets/kactionmenuchangecase.h"
#include <kabc/addressee.h>
#include <kmime/kmime_codecs.h>
#include <akonadi/itemfetchjob.h>
......
......@@ -66,6 +66,7 @@
#include "editor/potentialphishingemail/potentialphishingemailwarning.h"
#include "kmcomposerglobalaction.h"
#include "widgets/kactionmenutransport.h"
#include "widgets/kactionmenuchangecase.h"
#include "libkdepim/progresswidget/statusbarprogresswidget.h"
#include "libkdepim/progresswidget/progressstatusbarwidget.h"
......@@ -1345,24 +1346,12 @@ void KMComposeWin::setupActions( void )
actionCollection()->addAction( QLatin1String("insert_special_character"), action );
connect( action, SIGNAL(triggered(bool)), this, SLOT(insertSpecialCharacter()) );
KAction *upperCase = new KAction( i18n("Uppercase"), this );
actionCollection()->addAction( QLatin1String("change_to_uppercase"), upperCase );
connect( upperCase, SIGNAL(triggered(bool)), this, SLOT(slotUpperCase()) );
KAction *sentenceCase = new KAction( i18n("Sentence case"), this );
actionCollection()->addAction( QLatin1String("change_to_sentencecase"), sentenceCase );
connect( sentenceCase, SIGNAL(triggered(bool)), this, SLOT(slotSentenceCase()) );
KAction *lowerCase = new KAction( i18n("Lowercase"), this );
actionCollection()->addAction( QLatin1String("change_to_lowercase"), lowerCase );
connect( lowerCase, SIGNAL(triggered(bool)), this, SLOT(slotLowerCase()) );
mChangeCaseMenu = new KActionMenu(i18n("Change Case"), this);
mChangeCaseMenu = new KActionMenuChangeCase(this);
mChangeCaseMenu->appendInActionCollection(actionCollection());
actionCollection()->addAction(QLatin1String("change_case_menu"), mChangeCaseMenu );
mChangeCaseMenu->addAction(sentenceCase);
mChangeCaseMenu->addAction(upperCase);
mChangeCaseMenu->addAction(lowerCase);
connect(mChangeCaseMenu, SIGNAL(upperCase()), this, SLOT(slotUpperCase()));
connect(mChangeCaseMenu, SIGNAL(lowerCase()), this, SLOT(slotLowerCase()));
connect(mChangeCaseMenu, SIGNAL(sentenceCase()), this, SLOT(slotSentenceCase()));
mComposerBase->attachmentController()->createActions();
......
......@@ -55,6 +55,7 @@ class QPushButton;
class QSplitter;
class CodecAction;
class KActionMenuChangeCase;
class KMComposeWin;
class KMComposerEditor;
class KSelectAction;
......@@ -231,7 +232,7 @@ public: // kmkernel, kmcommands, callback
void addExtraCustomHeaders( const QMap<QByteArray, QString> &header);
KToggleAction *translateAction() const { return mTranslateAction; }
KActionMenu *changeCaseMenu() const { return mChangeCaseMenu; }
KActionMenuChangeCase *changeCaseMenu() const { return mChangeCaseMenu; }
KToggleAction *generateShortenUrlAction() const { return mGenerateShortenUrl; }
private:
......@@ -656,7 +657,7 @@ private:
int mLabelWidth;
KActionMenu *mChangeCaseMenu;
KActionMenuChangeCase *mChangeCaseMenu;
QString mdbusObjectPath;
static int s_composerNumber;
......
......@@ -41,6 +41,11 @@ set( kmail_kactionmenutransporttest_source kactionmenutransporttest.cpp ../widge
kde4_add_unit_test( kactionmenutransporttest ${kmail_kactionmenutransporttest_source})
target_link_libraries( kactionmenutransporttest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_MAILTRANSPORT_LIBS})
set( kmail_kactionmenuchangecasetest_source kactionmenuchangecasetest.cpp ../widgets/kactionmenuchangecase.cpp)
kde4_add_unit_test( kactionmenuchangecasetest ${kmail_kactionmenuchangecasetest_source})
target_link_libraries( kactionmenuchangecasetest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS})
include(AkonadiMacros)
set(KDEPIMLIBS_RUN_ISOLATED_TESTS TRUE)
set(KDEPIMLIBS_RUN_SQLITE_ISOLATED_TESTS TRUE)
......
/*
Copyright (c) 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 "kactionmenuchangecasetest.h"
#include "../widgets/kactionmenuchangecase.h"
#include <qtest_kde.h>
#include <QSignalSpy>
#include <KMenu>
KActionMenuChangeCaseTest::KActionMenuChangeCaseTest(QObject *parent)
: QObject(parent)
{
}
KActionMenuChangeCaseTest::~KActionMenuChangeCaseTest()
{
}
void KActionMenuChangeCaseTest::shouldHaveDefaultValue()
{
KActionMenuChangeCase menu;
QVERIFY(menu.upperCaseAction());
QVERIFY(menu.sentenceCaseAction());
QVERIFY(menu.lowerCaseAction());
QCOMPARE(menu.menu()->actions().count(), 3);
}
void KActionMenuChangeCaseTest::shouldEmitSignals()
{
KActionMenuChangeCase menu;
QSignalSpy spyUpper(&menu, SIGNAL(upperCase()));
QSignalSpy spyLower(&menu, SIGNAL(lowerCase()));
QSignalSpy spySentence(&menu, SIGNAL(sentenceCase()));
menu.upperCaseAction()->trigger();
menu.lowerCaseAction()->trigger();
menu.sentenceCaseAction()->trigger();
QCOMPARE(spyUpper.count(), 1);
QCOMPARE(spyLower.count(), 1);
QCOMPARE(spySentence.count(), 1);
}
QTEST_KDEMAIN(KActionMenuChangeCaseTest, GUI)
/*
Copyright (c) 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 KACTIONMENUCHANGECASETEST_H
#define KACTIONMENUCHANGECASETEST_H
#include <QObject>
class KActionMenuChangeCaseTest : public QObject
{
Q_OBJECT
public:
explicit KActionMenuChangeCaseTest(QObject *parent = 0);
~KActionMenuChangeCaseTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldEmitSignals();
};
#endif // KACTIONMENUCHANGECASETEST_H
/*
Copyright (c) 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 "kactionmenuchangecase.h"
#include <KLocalizedString>
#include <KActionCollection>
#include <KAction>
KActionMenuChangeCase::KActionMenuChangeCase(QObject *parent)
: KActionMenu(parent)
{
setText(i18n("Change Case"));
mUpperCase = new KAction( i18n("Uppercase"), this );
connect( mUpperCase, SIGNAL(triggered(bool)), this, SIGNAL(upperCase()) );
mSentenceCase = new KAction( i18n("Sentence case"), this );
connect( mSentenceCase, SIGNAL(triggered(bool)), this, SIGNAL(sentenceCase()) );
mLowerCase = new KAction( i18n("Lowercase"), this );
connect( mLowerCase, SIGNAL(triggered(bool)), this, SIGNAL(lowerCase()) );
addAction(mUpperCase);
addAction(mLowerCase);
addAction(mSentenceCase);
}
KActionMenuChangeCase::~KActionMenuChangeCase()
{
}
KAction *KActionMenuChangeCase::upperCaseAction() const
{
return mUpperCase;
}
KAction *KActionMenuChangeCase::sentenceCaseAction() const
{
return mSentenceCase;
}
KAction *KActionMenuChangeCase::lowerCaseAction() const
{
return mLowerCase;
}
void KActionMenuChangeCase::appendInActionCollection(KActionCollection *ac)
{
if (ac) {
ac->addAction( QLatin1String("change_to_uppercase"), mUpperCase );
ac->addAction( QLatin1String("change_to_sentencecase"), mSentenceCase );
ac->addAction( QLatin1String("change_to_lowercase"), mLowerCase );
}
}
/*
Copyright (c) 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 KACTIONMENUCHANGECASE_H
#define KACTIONMENUCHANGECASE_H
#include <KActionMenu>
class KAction;
class KActionCollection;
class KActionMenuChangeCase : public KActionMenu
{
Q_OBJECT
public:
explicit KActionMenuChangeCase(QObject *parent = 0);
~KActionMenuChangeCase();
KAction *upperCaseAction() const;
KAction *sentenceCaseAction() const;
KAction *lowerCaseAction() const;
void appendInActionCollection(KActionCollection *ac);
Q_SIGNALS:
void upperCase();
void sentenceCase();
void lowerCase();
private:
KAction *mUpperCase;
KAction *mSentenceCase;
KAction *mLowerCase;
};
#endif // KACTIONMENUCHANGECASE_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