mirror of
https://github.com/gqrx-sdr/gqrx.git
synced 2024-09-21 10:47:10 +00:00
Sanitize bookmark and tag names by preventing use of forbidden characters
This commit is contained in:
parent
691ba1d563
commit
8be3dc3856
@ -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
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
#include "bookmarkstaglist.h"
|
||||
#include "bookmarks.h"
|
||||
#include "dlg_saveablestring.h"
|
||||
#include <QColorDialog>
|
||||
#include <stdio.h>
|
||||
#include <QMenu>
|
||||
@ -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)
|
||||
|
64
src/qtgui/dlg_saveablestring.cpp
Normal file
64
src/qtgui/dlg_saveablestring.cpp
Normal file
@ -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
src/qtgui/dlg_saveablestring.h
Normal file
47
src/qtgui/dlg_saveablestring.h
Normal file
@ -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
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "bookmarks.h"
|
||||
#include "bookmarkstaglist.h"
|
||||
#include "dlg_saveablestring.h"
|
||||
#include "dockbookmarks.h"
|
||||
#include "dockrxopt.h"
|
||||
#include "qtcolorpicker.h"
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user