Commit d72381e7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve++

parent f8501f7d
......@@ -20,5 +20,5 @@ add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternalscri
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternalscriptparseargumenttest.cpp "../viewerpluginexternalscriptparseargument.cpp" "")
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternalconfigurewidgettest.cpp "../configuredialog/viewerpluginexternaleditwidget.cpp;../configuredialog/viewerpluginexternaleditdialog.cpp;../configuredialog/viewerpluginexternalconfigurewidget.cpp;../viewerpluginexternalscriptsloadjob.cpp;../viewerpluginexternalscriptinfo.cpp" "")
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternalconfiguredialogtest.cpp "../configuredialog/viewerpluginexternaleditwidget.cpp;../configuredialog/viewerpluginexternaleditdialog.cpp;../configuredialog/viewerpluginexternalconfiguredialog.cpp;../configuredialog/viewerpluginexternalconfigurewidget.cpp;../viewerpluginexternalscriptsloadjob.cpp;../viewerpluginexternalscriptinfo.cpp" "")
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternaleditwidgettest.cpp "../configuredialog/viewerpluginexternaleditwidget.cpp" "")
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternaleditdialogtest.cpp "../configuredialog/viewerpluginexternaleditdialog.cpp;../configuredialog/viewerpluginexternaleditwidget.cpp" "")
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternaleditwidgettest.cpp "../viewerpluginexternalscriptinfo.cpp;../configuredialog/viewerpluginexternaleditwidget.cpp" "")
add_messageviewer_viewerplugin_external_plugin_unittest(viewerpluginexternaleditdialogtest.cpp "../viewerpluginexternalscriptinfo.cpp;../configuredialog/viewerpluginexternaleditdialog.cpp;../configuredialog/viewerpluginexternaleditwidget.cpp" "")
......@@ -17,7 +17,6 @@
Boston, MA 02110-1301, USA.
*/
#include "viewerpluginexternalconfigurewidgettest.h"
#include "../configuredialog/viewerpluginexternalconfigurewidget.h"
#include <QTest>
......@@ -46,7 +45,6 @@ void ViewerPluginExternalConfigureWidgetTest::shouldHaveDefaultValue()
QVERIFY(mainLayout);
QCOMPARE(mainLayout->margin(), 0);
QListWidget *mListExternal = w.findChild<QListWidget *>(QStringLiteral("listexternal"));
QVERIFY(mListExternal);
QCOMPARE(mListExternal->selectionMode(), QAbstractItemView::SingleSelection);
......
......@@ -17,9 +17,11 @@
Boston, MA 02110-1301, USA.
*/
#include "viewerpluginexternaleditwidgettest.h"
#include "../configuredialog/viewerpluginexternaleditwidget.h"
#include <QFormLayout>
#include <QLineEdit>
#include <QTest>
ViewerPluginExternalEditWidgetTest::ViewerPluginExternalEditWidgetTest(QObject *parent)
......@@ -33,4 +35,24 @@ ViewerPluginExternalEditWidgetTest::~ViewerPluginExternalEditWidgetTest()
}
void ViewerPluginExternalEditWidgetTest::shouldHaveDefaultValue()
{
ViewerPluginExternalEditWidget w;
QFormLayout *mainLayout = w.findChild<QFormLayout *>(QStringLiteral("mainlayout"));
QVERIFY(mainLayout);
QCOMPARE(mainLayout->margin(), 0);
QLineEdit *mName = w.findChild<QLineEdit *>(QStringLiteral("name"));
QVERIFY(mName);
QLineEdit *mDescription = w.findChild<QLineEdit *>(QStringLiteral("description"));
QVERIFY(mDescription);
QLineEdit *mCommandLine = w.findChild<QLineEdit *>(QStringLiteral("commandline"));
QVERIFY(mCommandLine);
QLineEdit *mExecutable = w.findChild<QLineEdit *>(QStringLiteral("executable"));
QVERIFY(mExecutable);
}
QTEST_MAIN(ViewerPluginExternalEditWidgetTest)
......@@ -17,7 +17,6 @@
Boston, MA 02110-1301, USA.
*/
#ifndef VIEWERPLUGINEXTERNALEDITWIDGETTEST_H
#define VIEWERPLUGINEXTERNALEDITWIDGETTEST_H
......@@ -29,6 +28,8 @@ class ViewerPluginExternalEditWidgetTest : public QObject
public:
explicit ViewerPluginExternalEditWidgetTest(QObject *parent = Q_NULLPTR);
~ViewerPluginExternalEditWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // VIEWERPLUGINEXTERNALEDITWIDGETTEST_H
......@@ -33,7 +33,6 @@ ViewerPluginExternalConfigureDialog::~ViewerPluginExternalConfigureDialog()
}
QWidget *ViewerPluginExternalConfigureDialog::createLayout()
{
mConfigWidget = new ViewerPluginExternalConfigureWidget(this);
......
......@@ -48,6 +48,8 @@ ViewerPluginExternalScriptItem::ViewerPluginExternalScriptItem(QListWidget *pare
void ViewerPluginExternalScriptItem::setScriptInfo(const ViewerPluginExternalScriptInfo &scriptInfo)
{
mScriptInfo = scriptInfo;
setText(mScriptInfo.name());
setToolTip(mScriptInfo.description());
}
ViewerPluginExternalScriptInfo ViewerPluginExternalScriptItem::scriptInfo() const
......@@ -103,6 +105,9 @@ void ViewerPluginExternalConfigureWidget::slotRemoveScript()
QListWidgetItem *item = mListExternal->currentItem();
if (item) {
ViewerPluginExternalScriptItem *scriptItem = static_cast<ViewerPluginExternalScriptItem *>(item);
if (KMessageBox::Yes == KMessageBox::warningYesNo(this, i18n("Do you want to remove this script?"), i18n("Remove External Script"))) {
mFilesToRemove.append(scriptItem->scriptInfo().fileName());
}
}
}
......@@ -111,15 +116,23 @@ void ViewerPluginExternalConfigureWidget::slotModifyScript()
QListWidgetItem *item = mListExternal->currentItem();
if (item) {
ViewerPluginExternalScriptItem *scriptItem = static_cast<ViewerPluginExternalScriptItem *>(item);
QPointer<ViewerPluginExternalEditDialog> dlg = new ViewerPluginExternalEditDialog(this);
dlg->setScriptInfo(scriptItem->scriptInfo());
if (dlg->exec()) {
scriptItem->setScriptInfo(dlg->scriptInfo());
}
delete dlg;
}
}
void ViewerPluginExternalConfigureWidget::slotAddScript()
{
QListWidgetItem *item = mListExternal->currentItem();
if (item) {
ViewerPluginExternalScriptItem *scriptItem = static_cast<ViewerPluginExternalScriptItem *>(item);
QPointer<ViewerPluginExternalEditDialog> dlg = new ViewerPluginExternalEditDialog(this);
if (dlg->exec()) {
ViewerPluginExternalScriptItem *item = new ViewerPluginExternalScriptItem(mListExternal);
item->setScriptInfo(dlg->scriptInfo());
}
delete dlg;
}
void ViewerPluginExternalConfigureWidget::load()
......
......@@ -39,6 +39,8 @@ private:
void slotModifyScript();
void updateButtons();
void slotRemoveScript();
QStringList mFilesToRemove;
QListWidget *mListExternal;
QPushButton *mAddScript;
QPushButton *mRemoveScript;
......
......@@ -17,7 +17,6 @@
Boston, MA 02110-1301, USA.
*/
#include "viewerpluginexternaleditdialog.h"
#include "viewerpluginexternaleditwidget.h"
#include <KLocalizedString>
......@@ -53,3 +52,8 @@ void ViewerPluginExternalEditDialog::setScriptInfo(const ViewerPluginExternalScr
{
mEditWidget->setScriptInfo(info);
}
ViewerPluginExternalScriptInfo ViewerPluginExternalEditDialog::scriptInfo() const
{
return mEditWidget->scriptInfo();
}
......@@ -17,7 +17,6 @@
Boston, MA 02110-1301, USA.
*/
#ifndef VIEWERPLUGINEXTERNALEDITDIALOG_H
#define VIEWERPLUGINEXTERNALEDITDIALOG_H
......@@ -34,6 +33,7 @@ public:
~ViewerPluginExternalEditDialog();
void setScriptInfo(const ViewerPluginExternalScriptInfo &info);
ViewerPluginExternalScriptInfo scriptInfo() const;
private:
void slotAccepted();
......
......@@ -17,18 +17,36 @@
Boston, MA 02110-1301, USA.
*/
#include "viewerpluginexternaleditwidget.h"
#include <QVBoxLayout>
#include <KLocalizedString>
#include <QLabel>
#include <QLineEdit>
#include <QFormLayout>
ViewerPluginExternalEditWidget::ViewerPluginExternalEditWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QFormLayout *mainLayout = new QFormLayout(this);
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mainLayout->setMargin(0);
mName = new QLineEdit(this);
mName->setObjectName(QStringLiteral("name"));
mainLayout->addRow(i18n("Name:"), mName);
mDescription = new QLineEdit(this);
mDescription->setObjectName(QStringLiteral("description"));
mainLayout->addRow(i18n("Description:"), mDescription);
mCommandLine = new QLineEdit(this);
mCommandLine->setObjectName(QStringLiteral("commandline"));
mainLayout->addRow(i18n("CommandLine:"), mCommandLine);
mExecutable = new QLineEdit(this);
mExecutable->setObjectName(QStringLiteral("executable"));
mainLayout->addRow(i18n("Executable:"), mExecutable);
}
ViewerPluginExternalEditWidget::~ViewerPluginExternalEditWidget()
......@@ -38,10 +56,22 @@ ViewerPluginExternalEditWidget::~ViewerPluginExternalEditWidget()
void ViewerPluginExternalEditWidget::setScriptInfo(const ViewerPluginExternalScriptInfo &info)
{
//TODO
mScriptInfo = info;
mName->setText(mScriptInfo.name());
mDescription->setText(mScriptInfo.description());
mCommandLine->setText(mScriptInfo.commandLine());
mExecutable->setText(mScriptInfo.executable());
}
void ViewerPluginExternalEditWidget::save()
{
//TODO
mScriptInfo.setName(mName->text());
mScriptInfo.setDescription(mDescription->text());
mScriptInfo.setCommandLine(mCommandLine->text());
mScriptInfo.setExecutable(mExecutable->text());
}
ViewerPluginExternalScriptInfo ViewerPluginExternalEditWidget::scriptInfo() const
{
return mScriptInfo;
}
......@@ -17,21 +17,30 @@
Boston, MA 02110-1301, USA.
*/
#ifndef VIEWERPLUGINEXTERNALEDITWIDGET_H
#define VIEWERPLUGINEXTERNALEDITWIDGET_H
#include <QWidget>
#include "../viewerpluginexternalscriptinfo.h"
class QLineEdit;
class ViewerPluginExternalEditWidget : public QWidget
{
Q_OBJECT
public:
explicit ViewerPluginExternalEditWidget(QWidget *parent = Q_NULLPTR);
~ViewerPluginExternalEditWidget();
void setScriptInfo(const ViewerPluginExternalScriptInfo &info);
ViewerPluginExternalScriptInfo scriptInfo() const;
void save();
private:
ViewerPluginExternalScriptInfo mScriptInfo;
QLineEdit *mName;
QLineEdit *mDescription;
QLineEdit *mCommandLine;
QLineEdit *mExecutable;
//TODO add icon ?
};
#endif // VIEWERPLUGINEXTERNALEDITWIDGET_H
Supports Markdown
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