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

@@ -22494,3 +22494,10 @@
2021-10-02 Fred Gleason <fredg@paravelsystems.com> 2021-10-02 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in rdlogmanager(1) that broke the '--show-styles' and * Fixed a bug in rdlogmanager(1) that broke the '--show-styles' and
'-style <name>' command-line switches. '-style <name>' command-line switches.
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.

View File

@@ -159,6 +159,17 @@ QVariant RDGroupListModel::data(const QModelIndex &index,int role) const
} }
QModelIndex RDGroupListModel::indexOf(const QString &grpname) const
{
int row=d_visible_groups.indexOf(grpname);
if(row<0) {
return QModelIndex();
}
return index(row,0);
}
QString RDGroupListModel::groupName(const QModelIndex &row) const QString RDGroupListModel::groupName(const QModelIndex &row) const
{ {
return d_texts.at(row.row()).at(0).toString(); return d_texts.at(row.row()).at(0).toString();

View File

@@ -43,6 +43,7 @@ class RDGroupListModel : public QAbstractTableModel
QVariant headerData(int section,Qt::Orientation orient, QVariant headerData(int section,Qt::Orientation orient,
int role=Qt::DisplayRole) const; int role=Qt::DisplayRole) const;
QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const; QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const;
QModelIndex indexOf(const QString &grpname) const;
QString groupName(const QModelIndex &row) const; QString groupName(const QModelIndex &row) const;
QStringList allGroupNames() const; QStringList allGroupNames() const;
QModelIndex addGroup(const QString &name); QModelIndex addGroup(const QString &name);

View File

@@ -23,6 +23,9 @@
RDTextValidator::RDTextValidator(QObject *parent,bool allow_quote) RDTextValidator::RDTextValidator(QObject *parent,bool allow_quote)
: QValidator(parent) : QValidator(parent)
{ {
d_upper_case_only=false;
d_lower_case_only=false;
if(!allow_quote) { if(!allow_quote) {
banned_chars.push_back(34); // Double Quote banned_chars.push_back(34); // Double Quote
} }
@@ -34,14 +37,17 @@ RDTextValidator::RDTextValidator(QObject *parent,bool allow_quote)
QValidator::State RDTextValidator::validate(QString &input,int &pos) const QValidator::State RDTextValidator::validate(QString &input,int &pos) const
{ {
if(input.length()==0) {
return QValidator::Acceptable;
}
for(int i=0;i<banned_chars.size();i++) { for(int i=0;i<banned_chars.size();i++) {
if(input.contains(banned_chars.at(i))) { if(input.contains(banned_chars.at(i))) {
return QValidator::Invalid; return QValidator::Invalid;
} }
} }
if(d_upper_case_only&&(input.toUpper()!=input)) {
return QValidator::Invalid;
}
if(d_lower_case_only&&(input.toLower()!=input)) {
return QValidator::Invalid;
}
return QValidator::Acceptable; return QValidator::Acceptable;
} }
@@ -58,6 +64,18 @@ void RDTextValidator::addBannedChar(const QChar &c)
} }
void RDTextValidator::setUpperCaseOnly(bool state)
{
d_upper_case_only=state;
}
void RDTextValidator::setLowerCaseOnly(bool state)
{
d_lower_case_only=state;
}
QString RDTextValidator::stripString(QString str) QString RDTextValidator::stripString(QString str)
{ {
str.replace(34,""); // Double Quote str.replace(34,""); // Double Quote

View File

@@ -32,11 +32,14 @@ class RDTextValidator : public QValidator
QValidator::State validate(QString &input,int &pos) const; QValidator::State validate(QString &input,int &pos) const;
void addBannedChar(char c); void addBannedChar(char c);
void addBannedChar(const QChar &c); void addBannedChar(const QChar &c);
void setUpperCaseOnly(bool state);
void setLowerCaseOnly(bool state);
static QString stripString(QString str); static QString stripString(QString str);
private: private:
QList<QChar> banned_chars; QList<QChar> banned_chars;
// std::vector<char> banned_chars; bool d_upper_case_only;
bool d_lower_case_only;
}; };

View File

@@ -23,25 +23,21 @@
#include <rddb.h> #include <rddb.h>
#include <rdescape_string.h> #include <rdescape_string.h>
#include <edit_group.h> #include "add_group.h"
#include <add_group.h> #include "edit_group.h"
#include <rdpasswd.h> #include "rdpasswd.h"
#include <rdtextvalidator.h> #include "rdtextvalidator.h"
AddGroup::AddGroup(QString *group,QWidget *parent) AddGroup::AddGroup(QString *group,QWidget *parent)
: RDDialog(parent) : RDDialog(parent)
{ {
setModal(true);
group_group=group; group_group=group;
// //
// Fix the Window Size // Fix the Window Size
// //
setMinimumWidth(sizeHint().width()); setMinimumSize(sizeHint());
setMaximumWidth(sizeHint().width()); setMaximumSize(sizeHint());
setMinimumHeight(sizeHint().height());
setMaximumHeight(sizeHint().height());
setWindowTitle("RDAdmin - "+tr("Add Group")); setWindowTitle("RDAdmin - "+tr("Add Group"));
@@ -49,61 +45,58 @@ AddGroup::AddGroup(QString *group,QWidget *parent)
// Text Validator // Text Validator
// //
RDTextValidator *validator=new RDTextValidator(this); RDTextValidator *validator=new RDTextValidator(this);
validator->addBannedChar(',');
// //
// Group Name // Group Name
// //
group_name_edit=new QLineEdit(this); group_name_edit=new QLineEdit(this);
group_name_edit->setGeometry(145,11,sizeHint().width()-150,19);
group_name_edit->setMaxLength(10); group_name_edit->setMaxLength(10);
group_name_edit->setValidator(validator); group_name_edit->setValidator(validator);
QLabel *label=new QLabel(tr("New Group Name:"),this); connect(group_name_edit,SIGNAL(textChanged(const QString &)),
label->setFont(labelFont()); this,SLOT(groupNameChangedData(const QString &)));
label->setGeometry(10,11,130,19); group_name_label=new QLabel(tr("New Group Name:"),this);
label->setFont(labelFont()); group_name_label->setFont(labelFont());
label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); group_name_label->setFont(labelFont());
group_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
// //
// Enable Users Checkbox // Enable Users Checkbox
// //
group_users_box=new QCheckBox(this); group_users_box=new QCheckBox(this);
group_users_box->setGeometry(40,40,15,15);
group_users_box->setChecked(true); group_users_box->setChecked(true);
label=new QLabel(tr("Enable Group for All Users"),this); group_users_label=new QLabel(tr("Enable Group for All Users"),this);
label->setFont(subLabelFont()); group_users_label->setFont(subLabelFont());
label->setGeometry(60,38,sizeHint().width()-60,19); group_users_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
// //
// Enable Services Checkbox // Enable Services Checkbox
// //
group_svcs_box=new QCheckBox(this); group_svcs_box=new QCheckBox(this);
group_svcs_box->setGeometry(40,61,15,15);
group_svcs_box->setChecked(true); group_svcs_box->setChecked(true);
label=new QLabel(tr("Enable Group for All Services"),this); group_svcs_label=new QLabel(tr("Enable Group for All Services"),this);
label->setFont(subLabelFont()); group_svcs_label->setFont(subLabelFont());
label->setGeometry(60,58,sizeHint().width()-60,19); group_svcs_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
// //
// Ok Button // Ok Button
// //
QPushButton *ok_button=new QPushButton(this); group_ok_button=new QPushButton(this);
ok_button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50); group_ok_button->setDefault(true);
ok_button->setDefault(true); group_ok_button->setFont(buttonFont());
ok_button->setFont(buttonFont()); group_ok_button->setText(tr("OK"));
ok_button->setText(tr("OK")); connect(group_ok_button,SIGNAL(clicked()),this,SLOT(okData()));
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
// //
// Cancel Button // Cancel Button
// //
QPushButton *cancel_button=new QPushButton(this); group_cancel_button=new QPushButton(this);
cancel_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60, group_cancel_button->setFont(buttonFont());
80,50); group_cancel_button->setText(tr("Cancel"));
cancel_button->setFont(buttonFont()); connect(group_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
cancel_button->setText(tr("Cancel"));
connect(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() void AddGroup::okData()
{ {
QString err_msg; QString err_msg;
@@ -162,3 +169,19 @@ void AddGroup::cancelData()
{ {
done(false); 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 // 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 // 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 // it under the terms of the GNU General Public License version 2 as
@@ -21,8 +21,10 @@
#ifndef ADD_GROUP_H #ifndef ADD_GROUP_H
#define ADD_GROUP_H #define ADD_GROUP_H
#include <qcheckbox.h> #include <QCheckBox>
#include <qlineedit.h> #include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <rddialog.h> #include <rddialog.h>
@@ -36,16 +38,25 @@ class AddGroup : public RDDialog
QSizePolicy sizePolicy() const; QSizePolicy sizePolicy() const;
private slots: private slots:
void groupNameChangedData(const QString &str);
void okData(); void okData();
void cancelData(); void cancelData();
protected:
void resizeEvent(QResizeEvent *e);
private: private:
QLabel *group_name_label;
QLineEdit *group_name_edit; QLineEdit *group_name_edit;
QCheckBox *group_users_box; QCheckBox *group_users_box;
QLabel *group_users_label;
QCheckBox *group_svcs_box; QCheckBox *group_svcs_box;
QLabel *group_svcs_label;
QString *group_group; 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() void ListGroups::renameData()
{ {
QModelIndexList rows=list_groups_view->selectionModel()->selectedRows(); QModelIndexList rows=list_groups_view->selectionModel()->selectedRows();
QModelIndex index;
if(rows.size()!=1) { if(rows.size()!=1) {
return; return;
@@ -169,11 +170,24 @@ void ListGroups::renameData()
QString grpname=list_groups_model->groupName(rows.first()); QString grpname=list_groups_model->groupName(rows.first());
QString newgrpname; QString newgrpname;
RenameGroup *rename_group=new RenameGroup(grpname,this); RenameGroup *rename_group=new RenameGroup(grpname,this);
if(rename_group->exec(&newgrpname)) { switch((RenameGroup::Result)rename_group->exec(&newgrpname)) {
QModelIndex index=list_groups_model->renameGroup(grpname,newgrpname); case RenameGroup::Renamed:
index=list_groups_model->renameGroup(grpname,newgrpname);
if(index.isValid()) { if(index.isValid()) {
list_groups_view->selectRow(index.row()); 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; delete rename_group;
rename_group=NULL; rename_group=NULL;

View File

@@ -45,16 +45,15 @@ RenameGroup::RenameGroup(QString group,QWidget *parent)
// Text Validator // Text Validator
// //
RDTextValidator *validator=new RDTextValidator(this); RDTextValidator *validator=new RDTextValidator(this);
validator->addBannedChar(',');
// //
// Current Group Name // Current Group Name
// //
group_name_edit=new QLineEdit(this); group_name_edit=new QLineEdit(this);
group_name_edit->setGeometry(165,11,sizeHint().width()-175,19);
group_name_edit->setMaxLength(10); group_name_edit->setMaxLength(10);
group_name_edit->setReadOnly(true); group_name_edit->setReadOnly(true);
QLabel *group_name_label=new QLabel(tr("Current Group Name:"),this); group_name_label=new QLabel(tr("Current Group Name:"),this);
group_name_label->setGeometry(10,11,150,19);
group_name_label->setFont(labelFont()); group_name_label->setFont(labelFont());
group_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); group_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@@ -62,33 +61,30 @@ RenameGroup::RenameGroup(QString group,QWidget *parent)
// New Group Name // New Group Name
// //
group_newname_edit=new QLineEdit(this); group_newname_edit=new QLineEdit(this);
group_newname_edit->setGeometry(165,33,sizeHint().width()-175,19);
group_newname_edit->setMaxLength(10); group_newname_edit->setMaxLength(10);
group_newname_edit->setValidator(validator); group_newname_edit->setValidator(validator);
QLabel *group_newname_label=new QLabel(tr("New Group Name:"),this); connect(group_newname_edit,SIGNAL(textChanged(const QString &)),
group_newname_label->setGeometry(10,33,150,19); this,SLOT(newNameChangedData(const QString &)));
group_newname_label=new QLabel(tr("New Group Name:"),this);
group_newname_label->setFont(labelFont()); group_newname_label->setFont(labelFont());
group_newname_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); group_newname_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
// //
// Ok Button // Ok Button
// //
QPushButton *ok_button=new QPushButton(this); group_ok_button=new QPushButton(this);
ok_button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50); group_ok_button->setDefault(true);
ok_button->setDefault(true); group_ok_button->setFont(buttonFont());
ok_button->setFont(buttonFont()); group_ok_button->setText(tr("OK"));
ok_button->setText(tr("OK")); connect(group_ok_button,SIGNAL(clicked()),this,SLOT(okData()));
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
// //
// Cancel Button // Cancel Button
// //
QPushButton *cancel_button=new QPushButton(this); group_cancel_button=new QPushButton(this);
cancel_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60, group_cancel_button->setFont(buttonFont());
80,50); group_cancel_button->setText(tr("Cancel"));
cancel_button->setFont(buttonFont()); connect(group_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
cancel_button->setText(tr("Cancel"));
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
// //
// Populate Fields // Populate Fields
@@ -117,24 +113,34 @@ QSizePolicy RenameGroup::sizePolicy() const
int RenameGroup::exec(QString *newname) int RenameGroup::exec(QString *newname)
{ {
group_new_name=newname; group_new_name=newname;
group_newname_edit->setText(*newname);
newNameChangedData(*newname);
return RDDialog::exec(); return RDDialog::exec();
} }
void RenameGroup::newNameChangedData(const QString &str)
{
group_ok_button->
setDisabled(str.isEmpty()||(str==group_name_edit->text()));
}
void RenameGroup::okData() void RenameGroup::okData()
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q=NULL;
RDSqlQuery *q1=NULL;
bool merging=false; bool merging=false;
QString newname=group_newname_edit->text();
if(group_newname_edit->text().isEmpty()) {
QMessageBox::warning(this,tr("Invalid Group"), sql=QString("select ")+
tr("The group name is invalid!")); "`NAME`,"+ // 00
return; "`DEFAULT_LOW_CART`,"+ // 01
} "`DEFAULT_HIGH_CART`,"+ // 02
"`ENFORCE_CART_RANGE` "+ // 03
sql=QString("select `NAME` from `GROUPS` where ")+ "from `GROUPS` where "+
"`NAME`='"+RDEscapeString(group_newname_edit->text())+"'"; "`NAME`='"+RDEscapeString(group_newname_edit->text())+"'";
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
if(q->first()) { if(q->first()) {
@@ -142,100 +148,48 @@ void RenameGroup::okData()
tr("A")+" \""+group_newname_edit->text()+"\" "+ tr("A")+" \""+group_newname_edit->text()+"\" "+
tr("group already exists.")+"\n"+ tr("group already exists.")+"\n"+
tr("Do you want to combine the two?"), tr("Do you want to combine the two?"),
QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes) { QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes) {
delete q; delete q;
return; 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; merging=true;
} }
delete q; delete q;
// Rename(group_name_edit->text(),newname,merging);
// 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);
}
*group_new_name=group_newname_edit->text(); *group_new_name=group_newname_edit->text();
done(true); if(merging) {
done(RenameGroup::Merged);
}
else {
done(RenameGroup::Renamed);
}
} }
void RenameGroup::cancelData() void RenameGroup::cancelData()
{ {
done(false); done(RenameGroup::Cancelled);
} }
@@ -243,3 +197,74 @@ void RenameGroup::closeEvent(QCloseEvent *e)
{ {
cancelData(); 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 #ifndef RENAME_GROUP_H
#define RENAME_GROUP_H #define RENAME_GROUP_H
#include <qlineedit.h> #include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <rddialog.h> #include <rddialog.h>
#include <rdgroup.h> #include <rdgroup.h>
@@ -30,6 +32,7 @@ class RenameGroup : public RDDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Result {Renamed=0,Merged=1,Cancelled=2};
RenameGroup(QString group,QWidget *parent=0); RenameGroup(QString group,QWidget *parent=0);
~RenameGroup(); ~RenameGroup();
QSize sizeHint() const; QSize sizeHint() const;
@@ -39,15 +42,25 @@ class RenameGroup : public RDDialog
int exec(QString *newname); int exec(QString *newname);
private slots: private slots:
void newNameChangedData(const QString &str);
void okData(); void okData();
void cancelData(); void cancelData();
protected: protected:
void closeEvent(QCloseEvent *e); void closeEvent(QCloseEvent *e);
void resizeEvent(QResizeEvent *e);
private: 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; QLineEdit *group_name_edit;
QLabel *group_newname_label;
QLineEdit *group_newname_edit; QLineEdit *group_newname_edit;
QPushButton *group_ok_button;
QPushButton *group_cancel_button;
QString group_name; QString group_name;
QString *group_new_name; QString *group_new_name;
}; };