summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-29 20:37:51 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-29 20:38:28 (GMT)
commit36da994414c281cd4814d76ef50bb93e6cccac35 (patch)
treed7078b343d03fd3773ae9d83c0c2284c4104bfbd
parentb14ebb88bf21263be9324c52474bef22d8049842 (diff)
Avoid to create several script with same name
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/autotests/viewerpluginexternalscriptsloadjobtest.cpp2
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternalconfigurewidget.cpp19
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.cpp5
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.h2
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.cpp7
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.h4
-rw-r--r--plugins/messageviewerplugins/externalscriptplugin/viewerpluginexternalscriptsloadjob.cpp6
7 files changed, 38 insertions, 7 deletions
diff --git a/plugins/messageviewerplugins/externalscriptplugin/autotests/viewerpluginexternalscriptsloadjobtest.cpp b/plugins/messageviewerplugins/externalscriptplugin/autotests/viewerpluginexternalscriptsloadjobtest.cpp
index 87e8377..ecbad71 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/autotests/viewerpluginexternalscriptsloadjobtest.cpp
+++ b/plugins/messageviewerplugins/externalscriptplugin/autotests/viewerpluginexternalscriptsloadjobtest.cpp
@@ -112,7 +112,7 @@ void ViewerPluginExternalScriptsLoadJobTest::shouldNotLoadTwoSameNameDesktopFile
job.setExternalScriptsDirectories(dirs);
QCOMPARE(job.externalScriptsDirectories(), dirs);
job.start();
- QCOMPARE(job.scriptInfos().count(), 1);
+ QCOMPARE(job.scriptInfos().count(), 2);
}
QTEST_MAIN(ViewerPluginExternalScriptsLoadJobTest)
diff --git a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternalconfigurewidget.cpp b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternalconfigurewidget.cpp
index debb4c0..1affd89 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternalconfigurewidget.cpp
+++ b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternalconfigurewidget.cpp
@@ -29,6 +29,7 @@
#include <KMessageBox>
#include <QPointer>
#include <QFile>
+#include <QFileInfo>
#include <QDebug>
#include <KDesktopFile>
#include <KConfigGroup>
@@ -131,7 +132,14 @@ void ViewerPluginExternalConfigureWidget::slotModifyScript()
void ViewerPluginExternalConfigureWidget::slotAddScript()
{
+ QStringList existingNames;
+ const int numberOfElement(mListExternal->count());
+ for (int i = 0; i < numberOfElement; ++i) {
+ ViewerPluginExternalScriptItem *item = static_cast<ViewerPluginExternalScriptItem *>(mListExternal->item(i));
+ existingNames << item->text();
+ }
QPointer<ViewerPluginExternalEditDialog> dlg = new ViewerPluginExternalEditDialog(this);
+ dlg->setExistingsNames(existingNames);
if (dlg->exec()) {
ViewerPluginExternalScriptItem *item = new ViewerPluginExternalScriptItem(mListExternal);
item->setScriptInfo(dlg->scriptInfo());
@@ -165,12 +173,19 @@ void ViewerPluginExternalConfigureWidget::save()
qCWarning(EXTERNALSCRIPTPLUGIN_LOG) << " Impossible to delete " << path;
}
}
- for (int i = 0; i < mListExternal->count(); ++i) {
+ const QString writablePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/messageviewerplugins/");
+ const int numberOfElement(mListExternal->count());
+ for (int i = 0; i < numberOfElement; ++i) {
ViewerPluginExternalScriptItem *item = static_cast<ViewerPluginExternalScriptItem *>(mListExternal->item(i));
const ViewerPluginExternalScriptInfo &scriptInfo = item->scriptInfo();
QString filenamepath = scriptInfo.fileName();
if (filenamepath.isEmpty()) {
- filenamepath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/messageviewerplugins/%1.desktop").arg(scriptInfo.name());
+ filenamepath = writablePath + QStringLiteral("%1.desktop").arg(scriptInfo.name());
+ int fileIndex = 1;
+ while(QFileInfo(filenamepath).exists()) {
+ filenamepath = writablePath + QStringLiteral("%1-%2.desktop").arg(scriptInfo.name()).arg(fileIndex);
+ fileIndex++;
+ }
}
KDesktopFile desktopFile(filenamepath);
desktopFile.desktopGroup().writeEntry(QStringLiteral("Name"), scriptInfo.name());
diff --git a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.cpp b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.cpp
index e473dc7..4f9405c 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.cpp
+++ b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.cpp
@@ -61,6 +61,11 @@ void ViewerPluginExternalEditDialog::slotAccepted()
accept();
}
+void ViewerPluginExternalEditDialog::setExistingsNames(const QStringList &existingsNames)
+{
+ mEditWidget->setExistingsNames(existingsNames);
+}
+
void ViewerPluginExternalEditDialog::setScriptInfo(const ViewerPluginExternalScriptInfo &info)
{
mEditWidget->setScriptInfo(info);
diff --git a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.h b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.h
index c390b85..8ec8b8c 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.h
+++ b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditdialog.h
@@ -36,6 +36,8 @@ public:
void setScriptInfo(const ViewerPluginExternalScriptInfo &info);
ViewerPluginExternalScriptInfo scriptInfo() const;
+ void setExistingsNames(const QStringList &existingsNames);
+
private:
void slotScriptIsValid(bool valid);
void slotAccepted();
diff --git a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.cpp b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.cpp
index 27ce369..7bcfbe2 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.cpp
+++ b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.cpp
@@ -57,7 +57,12 @@ ViewerPluginExternalEditWidget::~ViewerPluginExternalEditWidget()
void ViewerPluginExternalEditWidget::slotInfoChanged()
{
- Q_EMIT scriptIsValid(!mExecutable->text().trimmed().isEmpty() && !mName->text().trimmed().isEmpty());
+ Q_EMIT scriptIsValid(!mExecutable->text().trimmed().isEmpty() && !mName->text().trimmed().isEmpty() && !mExistingsNames.contains(mName->text()));
+}
+
+void ViewerPluginExternalEditWidget::setExistingsNames(const QStringList &existingsNames)
+{
+ mExistingsNames = existingsNames;
}
void ViewerPluginExternalEditWidget::setScriptInfo(const ViewerPluginExternalScriptInfo &info)
diff --git a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.h b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.h
index 4edaf0b..81da504 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.h
+++ b/plugins/messageviewerplugins/externalscriptplugin/configuredialog/viewerpluginexternaleditwidget.h
@@ -34,17 +34,19 @@ public:
ViewerPluginExternalScriptInfo scriptInfo() const;
void save();
+ void setExistingsNames(const QStringList &existingsNames);
+
Q_SIGNALS:
void scriptIsValid(bool valid);
private:
void slotInfoChanged();
ViewerPluginExternalScriptInfo mScriptInfo;
+ QStringList mExistingsNames;
QLineEdit *mName;
QLineEdit *mDescription;
QLineEdit *mCommandLine;
QLineEdit *mExecutable;
- //TODO add icon ?
};
#endif // VIEWERPLUGINEXTERNALEDITWIDGET_H
diff --git a/plugins/messageviewerplugins/externalscriptplugin/viewerpluginexternalscriptsloadjob.cpp b/plugins/messageviewerplugins/externalscriptplugin/viewerpluginexternalscriptsloadjob.cpp
index a9a7745..e6a201d 100644
--- a/plugins/messageviewerplugins/externalscriptplugin/viewerpluginexternalscriptsloadjob.cpp
+++ b/plugins/messageviewerplugins/externalscriptplugin/viewerpluginexternalscriptsloadjob.cpp
@@ -63,9 +63,11 @@ void ViewerPluginExternalScriptsLoadJob::start()
info.setIcon(group.readEntry("Icon", QString()));
info.setIsReadOnly(!list.at(i).isWritable());
info.setFileName(filePath);
- if (info.isValid() && !scriptNames.contains(name)) {
+ if (info.isValid()) {
mScriptInfos.append(info);
- scriptNames.append(name);
+ if (!scriptNames.contains(name)) {
+ scriptNames.append(name);
+ }
}
}
}