2021-10-05 Fred Gleason <fredg@paravelsystems.com>

* Added 'RDTextValidator::setUpperCaseOnly()' and
	'RDTextValidator::setLowerCaseOnly()' methods.
	* Added the RDGroupListModel::indexOf()' method.
	* Fixed a bug in the 'Rename Group' dialog in rdadmin(1) that
	caused the group being renamed to be deleted when simply attempting
	to change the case of its name.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2021-10-05 13:08:49 -04:00
parent c4b1e2f2fc
commit 1d485f3ae3
10 changed files with 282 additions and 156 deletions

View File

@@ -23,25 +23,21 @@
#include <rddb.h>
#include <rdescape_string.h>
#include <edit_group.h>
#include <add_group.h>
#include <rdpasswd.h>
#include <rdtextvalidator.h>
#include "add_group.h"
#include "edit_group.h"
#include "rdpasswd.h"
#include "rdtextvalidator.h"
AddGroup::AddGroup(QString *group,QWidget *parent)
: RDDialog(parent)
{
setModal(true);
group_group=group;
//
// Fix the Window Size
//
setMinimumWidth(sizeHint().width());
setMaximumWidth(sizeHint().width());
setMinimumHeight(sizeHint().height());
setMaximumHeight(sizeHint().height());
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
setWindowTitle("RDAdmin - "+tr("Add Group"));
@@ -49,61 +45,58 @@ AddGroup::AddGroup(QString *group,QWidget *parent)
// Text Validator
//
RDTextValidator *validator=new RDTextValidator(this);
validator->addBannedChar(',');
//
// Group Name
//
group_name_edit=new QLineEdit(this);
group_name_edit->setGeometry(145,11,sizeHint().width()-150,19);
group_name_edit->setMaxLength(10);
group_name_edit->setValidator(validator);
QLabel *label=new QLabel(tr("New Group Name:"),this);
label->setFont(labelFont());
label->setGeometry(10,11,130,19);
label->setFont(labelFont());
label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
connect(group_name_edit,SIGNAL(textChanged(const QString &)),
this,SLOT(groupNameChangedData(const QString &)));
group_name_label=new QLabel(tr("New Group Name:"),this);
group_name_label->setFont(labelFont());
group_name_label->setFont(labelFont());
group_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
//
// Enable Users Checkbox
//
group_users_box=new QCheckBox(this);
group_users_box->setGeometry(40,40,15,15);
group_users_box->setChecked(true);
label=new QLabel(tr("Enable Group for All Users"),this);
label->setFont(subLabelFont());
label->setGeometry(60,38,sizeHint().width()-60,19);
label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
group_users_label=new QLabel(tr("Enable Group for All Users"),this);
group_users_label->setFont(subLabelFont());
group_users_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
//
// Enable Services Checkbox
//
group_svcs_box=new QCheckBox(this);
group_svcs_box->setGeometry(40,61,15,15);
group_svcs_box->setChecked(true);
label=new QLabel(tr("Enable Group for All Services"),this);
label->setFont(subLabelFont());
label->setGeometry(60,58,sizeHint().width()-60,19);
label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
group_svcs_label=new QLabel(tr("Enable Group for All Services"),this);
group_svcs_label->setFont(subLabelFont());
group_svcs_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
//
// Ok Button
//
QPushButton *ok_button=new QPushButton(this);
ok_button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50);
ok_button->setDefault(true);
ok_button->setFont(buttonFont());
ok_button->setText(tr("OK"));
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
group_ok_button=new QPushButton(this);
group_ok_button->setDefault(true);
group_ok_button->setFont(buttonFont());
group_ok_button->setText(tr("OK"));
connect(group_ok_button,SIGNAL(clicked()),this,SLOT(okData()));
//
// Cancel Button
//
QPushButton *cancel_button=new QPushButton(this);
cancel_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60,
80,50);
cancel_button->setFont(buttonFont());
cancel_button->setText(tr("Cancel"));
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
group_cancel_button=new QPushButton(this);
group_cancel_button->setFont(buttonFont());
group_cancel_button->setText(tr("Cancel"));
connect(group_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
group_name_edit->setText(*group);
groupNameChangedData(*group);
}
@@ -125,6 +118,20 @@ QSizePolicy AddGroup::sizePolicy() const
}
void AddGroup::groupNameChangedData(const QString &str)
{
QString sql;
RDSqlQuery *q=NULL;
sql=QString("select ")+
"`NAME` "+
"from `GROUPS` where `NAME`='"+RDEscapeString(str)+"'";
q=new RDSqlQuery(sql);
group_ok_button->setDisabled(str.isEmpty()||q->first());
delete q;
}
void AddGroup::okData()
{
QString err_msg;
@@ -162,3 +169,19 @@ void AddGroup::cancelData()
{
done(false);
}
void AddGroup::resizeEvent(QResizeEvent *e)
{
group_name_edit->setGeometry(145,11,size().width()-150,19);
group_name_label->setGeometry(10,11,130,19);
group_users_box->setGeometry(40,40,15,15);
group_users_label->setGeometry(60,38,size().width()-60,19);
group_svcs_box->setGeometry(40,61,15,15);
group_svcs_label->setGeometry(60,58,size().width()-60,19);
group_ok_button->setGeometry(size().width()-180,size().height()-60,80,50);
group_cancel_button->setGeometry(size().width()-90,size().height()-60,80,50);
}

View File

@@ -2,7 +2,7 @@
//
// Add a Rivendell Group
//
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
@@ -21,8 +21,10 @@
#ifndef ADD_GROUP_H
#define ADD_GROUP_H
#include <qcheckbox.h>
#include <qlineedit.h>
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <rddialog.h>
@@ -36,16 +38,25 @@ class AddGroup : public RDDialog
QSizePolicy sizePolicy() const;
private slots:
void groupNameChangedData(const QString &str);
void okData();
void cancelData();
protected:
void resizeEvent(QResizeEvent *e);
private:
QLabel *group_name_label;
QLineEdit *group_name_edit;
QCheckBox *group_users_box;
QLabel *group_users_label;
QCheckBox *group_svcs_box;
QLabel *group_svcs_label;
QString *group_group;
QPushButton *group_ok_button;
QPushButton *group_cancel_button;
};
#endif
#endif // ADD_GROUP_H

View File

@@ -161,6 +161,7 @@ void ListGroups::editData()
void ListGroups::renameData()
{
QModelIndexList rows=list_groups_view->selectionModel()->selectedRows();
QModelIndex index;
if(rows.size()!=1) {
return;
@@ -169,11 +170,24 @@ void ListGroups::renameData()
QString grpname=list_groups_model->groupName(rows.first());
QString newgrpname;
RenameGroup *rename_group=new RenameGroup(grpname,this);
if(rename_group->exec(&newgrpname)) {
QModelIndex index=list_groups_model->renameGroup(grpname,newgrpname);
switch((RenameGroup::Result)rename_group->exec(&newgrpname)) {
case RenameGroup::Renamed:
index=list_groups_model->renameGroup(grpname,newgrpname);
if(index.isValid()) {
list_groups_view->selectRow(index.row());
}
break;
case RenameGroup::Merged:
list_groups_model->removeGroup(grpname);
index=list_groups_model->indexOf(newgrpname);
if(index.isValid()) {
list_groups_view->selectRow(index.row());
}
break;
case RenameGroup::Cancelled:
break;
}
delete rename_group;
rename_group=NULL;

View File

@@ -45,16 +45,15 @@ RenameGroup::RenameGroup(QString group,QWidget *parent)
// Text Validator
//
RDTextValidator *validator=new RDTextValidator(this);
validator->addBannedChar(',');
//
// Current Group Name
//
group_name_edit=new QLineEdit(this);
group_name_edit->setGeometry(165,11,sizeHint().width()-175,19);
group_name_edit->setMaxLength(10);
group_name_edit->setReadOnly(true);
QLabel *group_name_label=new QLabel(tr("Current Group Name:"),this);
group_name_label->setGeometry(10,11,150,19);
group_name_label=new QLabel(tr("Current Group Name:"),this);
group_name_label->setFont(labelFont());
group_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@@ -62,33 +61,30 @@ RenameGroup::RenameGroup(QString group,QWidget *parent)
// New Group Name
//
group_newname_edit=new QLineEdit(this);
group_newname_edit->setGeometry(165,33,sizeHint().width()-175,19);
group_newname_edit->setMaxLength(10);
group_newname_edit->setValidator(validator);
QLabel *group_newname_label=new QLabel(tr("New Group Name:"),this);
group_newname_label->setGeometry(10,33,150,19);
connect(group_newname_edit,SIGNAL(textChanged(const QString &)),
this,SLOT(newNameChangedData(const QString &)));
group_newname_label=new QLabel(tr("New Group Name:"),this);
group_newname_label->setFont(labelFont());
group_newname_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
//
// Ok Button
//
QPushButton *ok_button=new QPushButton(this);
ok_button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50);
ok_button->setDefault(true);
ok_button->setFont(buttonFont());
ok_button->setText(tr("OK"));
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
group_ok_button=new QPushButton(this);
group_ok_button->setDefault(true);
group_ok_button->setFont(buttonFont());
group_ok_button->setText(tr("OK"));
connect(group_ok_button,SIGNAL(clicked()),this,SLOT(okData()));
//
// Cancel Button
//
QPushButton *cancel_button=new QPushButton(this);
cancel_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60,
80,50);
cancel_button->setFont(buttonFont());
cancel_button->setText(tr("Cancel"));
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
group_cancel_button=new QPushButton(this);
group_cancel_button->setFont(buttonFont());
group_cancel_button->setText(tr("Cancel"));
connect(group_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
//
// Populate Fields
@@ -117,24 +113,34 @@ QSizePolicy RenameGroup::sizePolicy() const
int RenameGroup::exec(QString *newname)
{
group_new_name=newname;
group_newname_edit->setText(*newname);
newNameChangedData(*newname);
return RDDialog::exec();
}
void RenameGroup::newNameChangedData(const QString &str)
{
group_ok_button->
setDisabled(str.isEmpty()||(str==group_name_edit->text()));
}
void RenameGroup::okData()
{
QString sql;
RDSqlQuery *q;
RDSqlQuery *q=NULL;
RDSqlQuery *q1=NULL;
bool merging=false;
if(group_newname_edit->text().isEmpty()) {
QMessageBox::warning(this,tr("Invalid Group"),
tr("The group name is invalid!"));
return;
}
sql=QString("select `NAME` from `GROUPS` where ")+
QString newname=group_newname_edit->text();
sql=QString("select ")+
"`NAME`,"+ // 00
"`DEFAULT_LOW_CART`,"+ // 01
"`DEFAULT_HIGH_CART`,"+ // 02
"`ENFORCE_CART_RANGE` "+ // 03
"from `GROUPS` where "+
"`NAME`='"+RDEscapeString(group_newname_edit->text())+"'";
q=new RDSqlQuery(sql);
if(q->first()) {
@@ -142,100 +148,48 @@ void RenameGroup::okData()
tr("A")+" \""+group_newname_edit->text()+"\" "+
tr("group already exists.")+"\n"+
tr("Do you want to combine the two?"),
QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes) {
QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes) {
delete q;
return;
}
if(q->value(3).toString()=="Y") {
sql=QString("select ")+
"`NUMBER` "+ // 00
"from `CART` where "+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"' && "+
QString::asprintf(" (`NUMBER`<%u || ",q->value(1).toUInt())+
QString::asprintf("`NUMBER`>%u)",q->value(2).toUInt());
q1=new RDSqlQuery(sql);
if(q1->first()) {
QMessageBox::information(this,"RDAdmin - "+tr("Conflicting Cart Numbers"),
tr("One or more carts in this group has an out-of-range number.")+
"\n"+tr("Unable to merge!"));
delete q1;
delete q;
return;
}
delete q1;
}
newname=q->value(0).toString(); // To ensure consistent case
merging=true;
}
delete q;
//
// Update Cart List
//
sql=QString("update `CART` set ")+
"`GROUP_NAME`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update LogManager Events
//
sql=QString("update `EVENTS` set ")+
"`SCHED_GROUP`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`SCHED_GROUP`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update Replicators
//
sql=QString("update `REPLICATOR_MAP` set ")+
"`GROUP_NAME`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update Dropboxes
//
sql=QString("update `DROPBOXES` set ")+
"`GROUP_NAME`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update Group List
//
if(!merging) {
sql=QString("update `GROUPS` set ")+
"`NAME`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update AUDIO_PERMS
//
sql=QString("update `AUDIO_PERMS` set ")+
"`GROUP_NAME`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update USER_PERMS
//
sql=QString("update `USER_PERMS` set ")+
"`GROUP_NAME`='"+RDEscapeString(group_newname_edit->text())+"' where "+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
}
else {
sql=QString("delete from `GROUPS` where ")+
"`NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update AUDIO_PERMS
//
sql=QString("delete from `AUDIO_PERMS` where ")+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
//
// Update USER_PERMS
//
sql=QString("delete from `USER_PERMS` where ")+
"`GROUP_NAME`='"+RDEscapeString(group_name_edit->text())+"'";
RDSqlQuery::apply(sql);
}
Rename(group_name_edit->text(),newname,merging);
*group_new_name=group_newname_edit->text();
done(true);
if(merging) {
done(RenameGroup::Merged);
}
else {
done(RenameGroup::Renamed);
}
}
void RenameGroup::cancelData()
{
done(false);
done(RenameGroup::Cancelled);
}
@@ -243,3 +197,74 @@ void RenameGroup::closeEvent(QCloseEvent *e)
{
cancelData();
}
void RenameGroup::resizeEvent(QResizeEvent *e)
{
group_name_edit->setGeometry(165,11,size().width()-175,19);
group_name_label->setGeometry(10,11,150,19);
group_newname_edit->setGeometry(165,33,size().width()-175,19);
group_newname_label->setGeometry(10,33,150,19);
group_ok_button->setGeometry(size().width()-180,size().height()-60,80,50);
group_cancel_button->setGeometry(size().width()-90,size().height()-60,80,50);
}
void RenameGroup::Rename(const QString &old_name,const QString &new_name,
bool merge) const
{
QString sql;
RenameField("CART","GROUP_NAME",old_name,new_name);
RenameField("EVENTS","SCHED_GROUP",old_name,new_name);
RenameField("REPLICATOR_MAP","GROUP_NAME",old_name,new_name);
RenameField("DROPBOXES","GROUP_NAME",old_name,new_name);
RenameField("SERVICES","TRACK_GROUP",old_name,new_name);
RenameField("SERVICES","AUTOSPOT_GROUP",old_name,new_name);
RenameField("NEXUS_STATIONS","RD_GROUP_NAME",old_name,new_name);
RenameField("REPORT_GROUPS","GROUP_NAME",old_name,new_name);
//
// Update Group List
//
if(merge) {
sql=QString("delete from `GROUPS` where ")+
"`NAME`='"+RDEscapeString(old_name)+"'";
RDSqlQuery::apply(sql);
//
// Update AUDIO_PERMS
//
sql=QString("delete from `AUDIO_PERMS` where ")+
"`GROUP_NAME`='"+RDEscapeString(old_name)+"'";
RDSqlQuery::apply(sql);
//
// Update USER_PERMS
//
sql=QString("delete from `USER_PERMS` where ")+
"`GROUP_NAME`='"+RDEscapeString(old_name)+"'";
RDSqlQuery::apply(sql);
}
else {
RenameField("GROUPS","NAME",old_name,new_name);
RenameField("AUDIO_PERMS","GROUP_NAME",old_name,new_name);
RenameField("USER_PERMS","GROUP_NAME",old_name,new_name);
}
}
void RenameGroup::RenameField(const QString &table,const QString &field,
const QString &old_name,
const QString &new_name) const
{
QString sql;
sql=QString("update ")+
"`"+table+"` set "+
"`"+field+"`='"+RDEscapeString(new_name)+"' "+
"where `"+field+"`='"+RDEscapeString(old_name)+"'";
RDSqlQuery::apply(sql);
}

View File

@@ -21,7 +21,9 @@
#ifndef RENAME_GROUP_H
#define RENAME_GROUP_H
#include <qlineedit.h>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <rddialog.h>
#include <rdgroup.h>
@@ -30,6 +32,7 @@ class RenameGroup : public RDDialog
{
Q_OBJECT
public:
enum Result {Renamed=0,Merged=1,Cancelled=2};
RenameGroup(QString group,QWidget *parent=0);
~RenameGroup();
QSize sizeHint() const;
@@ -39,15 +42,25 @@ class RenameGroup : public RDDialog
int exec(QString *newname);
private slots:
void newNameChangedData(const QString &str);
void okData();
void cancelData();
protected:
void closeEvent(QCloseEvent *e);
void resizeEvent(QResizeEvent *e);
private:
void Rename(const QString &old_name,const QString &new_name,
bool merge) const;
void RenameField(const QString &table,const QString &field,
const QString &old_name,const QString &new_name) const;
QLabel *group_name_label;
QLineEdit *group_name_edit;
QLabel *group_newname_label;
QLineEdit *group_newname_edit;
QPushButton *group_ok_button;
QPushButton *group_cancel_button;
QString group_name;
QString *group_new_name;
};