Added specified widget for file extensions.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Mon, 15 Nov 2010 21:49:04 +0000 (23:49 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Mon, 15 Nov 2010 21:49:04 +0000 (23:49 +0200)
src/dialogs/setupeditdialog.cpp
src/dialogs/setupeditdialog.h
src/emufront.pro
src/widgets/fileextensionwidget.cpp [new file with mode: 0644]
src/widgets/fileextensionwidget.h [new file with mode: 0644]
src/widgets/stringlistwidget.cpp
src/widgets/stringlistwidget.h

index 049512f..77154b6 100644 (file)
@@ -21,7 +21,7 @@
 #include <QSqlTableModel>
 #include <QSqlRecord>
 #include "setupeditdialog.h"
-#include "../widgets/stringlistwidget.h"
+#include "../widgets/fileextensionwidget.h"
 #include "../widgets/effileobjectcombobox.h"
 #include "../db/dbmediatype.h"
 #include "../db/dbplatform.h"
@@ -43,21 +43,24 @@ void SetupEditDialog::initWidgets()
 {
     mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this);
     platformComBox = new EFFileObjectComboBox(dbPlatform, this);
-    supportedFileTypesList = new StringListWidget;
+    supportedFileTypesList = new FileExtensionWidget;
+    supportedFileTypesList->setToolTip(tr("Set the supported file types by entering the file extension(s) (no wildcards or dots!)."));
 }
 
 void SetupEditDialog::layout()
 {
-   QLabel *platformLabel = new QLabel(tr("&Platform"));
+   QLabel *platformLabel = new QLabel(tr("&Platform:"));
    platformLabel->setBuddy(platformComBox);
-   QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
+   QLabel *mediaTypeLabel = new QLabel(tr("Media&Type:"));
    mediaTypeLabel->setBuddy(mediaTypeComBox);
+   QLabel *fileTypesLabel = new QLabel(tr("Supported file types:"));
    QGridLayout *gridLayout = new QGridLayout;
    gridLayout->addWidget(platformLabel, 0, 0);
    gridLayout->addWidget(platformComBox, 0, 1);
    gridLayout->addWidget(mediaTypeLabel, 1, 0);
    gridLayout->addWidget(mediaTypeComBox, 1, 1);
-   gridLayout->addWidget(supportedFileTypesList, 2, 0, 2, 2);
+   gridLayout->addWidget(fileTypesLabel, 2, 0, 1, 2);
+   gridLayout->addWidget(supportedFileTypesList, 3, 0, 2, 2);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(gridLayout);
    mainLayout->addWidget(buttonBox);
index 31de441..d116ce0 100644 (file)
@@ -26,7 +26,7 @@ class EFFileObjectComboBox;
 class DbSetup;
 class DbMediaType;
 class DbPlatform;
-class StringListWidget;
+class FileExtensionWidget;
 class MediaType;
 class Platform;
 
@@ -49,7 +49,7 @@ private:
     DbSetup *dbSetup;
     DbPlatform *dbPlatform;
     DbMediaType *dbMediaType;
-    StringListWidget *supportedFileTypesList;
+    FileExtensionWidget *supportedFileTypesList;
 
     void initWidgets();
     void layout();
index 878777a..25b0c13 100644 (file)
@@ -69,7 +69,8 @@ HEADERS += mainwindow.h \
     dialogs/emufrontfileobjectdialog.h \
     dialogs/browsefilepathdialog.h \
     db/dbconfig.h \
-    utils/datfileutil.h
+    utils/datfileutil.h \
+    widgets/fileextensionwidget.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -126,7 +127,8 @@ SOURCES += main.cpp \
     dialogs/emufrontfileobjectdialog.cpp \
     dialogs/browsefilepathdialog.cpp \
     db/dbconfig.cpp \
-    utils/datfileutil.cpp
+    utils/datfileutil.cpp \
+    widgets/fileextensionwidget.cpp
 OTHER_FILES +=  
 
 CONFIG += mobility
diff --git a/src/widgets/fileextensionwidget.cpp b/src/widgets/fileextensionwidget.cpp
new file mode 100644 (file)
index 0000000..5dbf777
--- /dev/null
@@ -0,0 +1,31 @@
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront 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 and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront 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 EmuFront.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "fileextensionwidget.h"
+
+FileExtensionWidget::FileExtensionWidget(QWidget *parent) :
+    StringListWidget(parent)
+{
+}
+
+bool FileExtensionWidget::confirmInput(const QString &input) const
+{
+    QRegExp rx("^[A-Za-z0-9]*$");
+    return rx.exactMatch(input);
+}
diff --git a/src/widgets/fileextensionwidget.h b/src/widgets/fileextensionwidget.h
new file mode 100644 (file)
index 0000000..82fcba4
--- /dev/null
@@ -0,0 +1,40 @@
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront 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 and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront 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 EmuFront.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef FILEEXTENSIONWIDGET_H
+#define FILEEXTENSIONWIDGET_H
+
+#include "stringlistwidget.h"
+
+class FileExtensionWidget : public StringListWidget
+{
+    Q_OBJECT
+public:
+    FileExtensionWidget(QWidget *parent = 0);
+
+protected:
+    virtual bool confirmInput(const QString &) const;
+
+signals:
+
+public slots:
+
+};
+
+#endif // FILEEXTENSIONWIDGET_H
index 476d12c..cb54203 100644 (file)
@@ -54,12 +54,22 @@ void StringListWidget::connectSignals()
 void StringListWidget::addClicked()
 {
     QString input = QInputDialog::getText(this, tr("Add"), tr("Add new item"));
+    input = input.trimmed();
     if (input.isEmpty()) return;
+    if (!confirmInput(input)) {
+       QMessageBox::information(this, tr("Input failed!"), ("Input was not accepted."));
+       return;
+    }
     stringList->addItem(input);
     stringList->sortItems();
     emit stringListUpdated();
 }
 
+bool StringListWidget::confirmInput(const QString &) const
+{
+    return true;
+}
+
 void StringListWidget::removeClicked()
 {
     qDebug() << "StringListWidget::removeClicked";
index 3d5e6dc..124a10d 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <QWidget>
 
-//class QStringListModel;
 class QListWidget;
 class QPushButton;
 
@@ -37,6 +36,9 @@ public:
 signals:
     void stringListUpdated();
 
+protected:
+    virtual bool confirmInput(const QString &) const;
+
 private slots:
     void addClicked();
     void removeClicked();