Skip to content

Commit

Permalink
Sanitize bookmark and tag names by preventing use of forbidden charac…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
0penBrain committed Oct 27, 2023
1 parent 691ba1d commit 8be3dc3
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/qtgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ add_source_files(SRCS_LIST
ctk/ctkRangeSlider.h
demod_options.cpp
demod_options.h
dlg_saveablestring.cpp
dlg_saveablestring.h
dockaudio.cpp
dockaudio.h
dockbookmarks.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
#include "bookmarkstaglist.h"
#include "bookmarks.h"
#include "dlg_saveablestring.h"
#include <QColorDialog>
#include <stdio.h>
#include <QMenu>
Expand All @@ -48,6 +49,9 @@ BookmarksTagList::BookmarksTagList(QWidget *parent, bool bShowUntagged )
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSortingEnabled(true);

LineEditDelegateSaveableString* DelegateTagName = new LineEditDelegateSaveableString(this);
this->setItemDelegateForColumn(1, DelegateTagName);
}

void BookmarksTagList::on_cellClicked(int row, int column)
Expand Down
64 changes: 64 additions & 0 deletions src/qtgui/dlg_saveablestring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* -*- c++ -*- */
/*
* Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
* https://gqrx.dk/
*
* Copyright 2023 0penBrain
*
* Gqrx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* Gqrx 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 Gqrx; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#include "dlg_saveablestring.h"

#include <QDebug>
#include <QLineEdit>

LineEditDelegateSaveableString::LineEditDelegateSaveableString(QObject *parent)
:QStyledItemDelegate(parent)
{

}

#include <QDebug>
QWidget *LineEditDelegateSaveableString::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
auto* editor = QStyledItemDelegate::createEditor(parent, option, index);
auto* lineedit = qobject_cast<QLineEdit*>(editor);
if (!lineedit)
{
qWarning() << __FUNCTION__ << " : " << "Editor cannot be cast to LineEdit, entry will not be validated";
}
else
{
lineedit->setValidator(new SaveableStringValidator(lineedit));
}
return editor;
}

SaveableStringValidator::SaveableStringValidator(QObject *parent)
:QValidator(parent)
{

}

QValidator::State SaveableStringValidator::validate(QString &input, int &pos) const
{
if (input.contains(';') || input.contains(','))
{
return QValidator::Invalid;
}
return QValidator::Acceptable;
}
47 changes: 47 additions & 0 deletions src/qtgui/dlg_saveablestring.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* -*- c++ -*- */
/*
* Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
* https://gqrx.dk/
*
* Copyright 2023 0penBrain
*
* Gqrx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* Gqrx 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 Gqrx; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef DLG_SAVEABLESTRING_H
#define DLG_SAVEABLESTRING_H

#include <QStyledItemDelegate>
#include <QValidator>

class LineEditDelegateSaveableString : public QStyledItemDelegate
{
Q_OBJECT
public:
LineEditDelegateSaveableString(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
//void setEditorData(QWidget *editor, const QModelIndex &index) const;
//void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
};

class SaveableStringValidator : public QValidator
{
Q_OBJECT
public:
SaveableStringValidator(QObject *parent = 0);
QValidator::State validate(QString &input, int &pos) const;
};

#endif // DLG_SAVEABLESTRING_H
4 changes: 4 additions & 0 deletions src/qtgui/dockbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "bookmarks.h"
#include "bookmarkstaglist.h"
#include "dlg_saveablestring.h"
#include "dockbookmarks.h"
#include "dockrxopt.h"
#include "qtcolorpicker.h"
Expand All @@ -56,6 +57,9 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
ComboBoxDelegateModulation* delegateModulation = new ComboBoxDelegateModulation(this);
ui->tableViewFrequencyList->setItemDelegateForColumn(2, delegateModulation);

LineEditDelegateSaveableString* delegateBookmarkName = new LineEditDelegateSaveableString(this);
ui->tableViewFrequencyList->setItemDelegateForColumn(1, delegateBookmarkName);

// Bookmarks Context menu
contextmenu = new QMenu(this);
// MenuItem Delete
Expand Down

0 comments on commit 8be3dc3

Please sign in to comment.