Qt: Various Profile UI Updates

Correct the text for delete and copy profiles, which better
display if they have been copied from a system-profile or
if the original entry has been deleted

Move Import button into the button box, as this seems
to be the consensus with applications and gives the info
label more room

Tooltips now behave the same way as they did before the
refactoring and copying from a new element creates the
correct names

Only one element could be deleted any given time, if the
default element was to be resetted

Change-Id: Ieb902b68627cb9bda5d2483b39de6479ff8d4533
Reviewed-on: https://code.wireshark.org/review/34070
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2019-07-22 21:27:39 +02:00
parent 7122a8a53e
commit faf520681a
4 changed files with 60 additions and 73 deletions

View File

@ -290,52 +290,10 @@ QVariant ProfileModel::dataToolTipRole(const QModelIndex &idx) const
QString msg;
switch (prof->status)
{
case PROF_STAT_DEFAULT:
if (reset_default_)
return tr("Will be reset to default values");
break;
case PROF_STAT_COPY:
if (prof->reference) {
QString reference = prof->reference;
GList *fl_entry = entry(prof);
if (fl_entry)
{
profile_def *profile = reinterpret_cast<profile_def *>(fl_entry->data);
if (strcmp(prof->reference, profile->reference) == 0) {
if (profile->status == PROF_STAT_CHANGED) {
// Reference profile was renamed, use the new name
reference = profile->name;
break;
}
}
}
QString profile_info = tr("Created from %1").arg(reference);
if (prof->from_global) {
profile_info.append(QString(" %1").arg(tr("(system provided)")));
} else if (!reference.isEmpty()) {
profile_info.append(QString(" %1").arg(tr("(deleted)")));
}
return profile_info;
}
break;
case PROF_STAT_NEW:
return tr("Created from default settings");
default:
break;
}
if ( ! ProfileModel::checkNameValidity(QString(prof->name), &msg) )
return msg;
if (prof->is_global)
return tr("This is a system provided profile.");
if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
return tr("The profile will be reset to default values.");
return QVariant();
else
return dataPath(idx);
}
QVariant ProfileModel::dataPath(const QModelIndex &index) const
@ -361,14 +319,38 @@ QVariant ProfileModel::dataPath(const QModelIndex &index) const
return profile_path;
}
case PROF_STAT_NEW:
return tr("Created from default settings");
{
QList<int> entries = const_cast<ProfileModel *>(this)->findAllByNameAndVisibility(prof->name);
QString errMsg;
if ( entries.count() > 1 )
return tr("A profile already exists with this name.");
else if ( ! checkNameValidity(prof->name, &errMsg) )
return errMsg;
else
return tr("Created from default settings");
}
case PROF_STAT_CHANGED:
if (prof->reference)
return QString("%1 %2").arg(tr("Renamed from: ")).arg(prof->reference);
break;
case PROF_STAT_COPY:
if (prof->reference)
return QString("%1 %2").arg(tr("Copied from: ")).arg(prof->reference);
{
QString msg = QString("%1 %2").arg(tr("Copied from: ")).arg(prof->reference);
if ( profile_exists(prof->reference, TRUE) )
msg.append(QString(" (%1)").arg(tr("system provided")));
else
{
ProfileModel * nthis = const_cast<ProfileModel *>(this);
int row = nthis->findByNameAndVisibility(prof->reference);
if ( row < 0 )
msg.append(QString(" (%1)").arg(tr("deleted")));
}
return msg;
}
break;
}
@ -523,7 +505,7 @@ QModelIndex ProfileModel::addNewProfile(QString name)
QModelIndex ProfileModel::duplicateEntry(QModelIndex idx)
{
if ( ! idx.isValid() || profiles_.count() <= idx.row() )
if ( ! idx.isValid() )
return QModelIndex();
profile_def * prof = guard(idx.row());
@ -531,14 +513,14 @@ QModelIndex ProfileModel::duplicateEntry(QModelIndex idx)
return QModelIndex();
QString parent = prof->name;
if ( ! prof->is_global && prof->status != PROF_STAT_CHANGED )
if ( ! prof->is_global && prof->status != PROF_STAT_CHANGED && prof->status != PROF_STAT_NEW )
parent = get_profile_parent (prof->name);
QString new_name;
if (prof->is_global && ! profile_exists (parent.toUtf8().constData(), FALSE))
new_name = QString(prof->name);
else
new_name = QString("%1 (%2)").arg(parent).arg(tr("copy"));
new_name = QString("%1 (%2)").arg(parent).arg(tr("copy", "noun"));
if ( findByNameAndVisibility(new_name) >= 0 )
{
@ -547,7 +529,7 @@ QModelIndex ProfileModel::duplicateEntry(QModelIndex idx)
while(findByNameAndVisibility(copyName) >= 0)
{
copyName = new_name;
copyName = copyName.replace(tr("copy"), tr("copy").append(" %1").arg(QString::number(cnt)));
copyName = copyName.replace(tr("copy", "noun"), tr("copy", "noun").append(" %1").arg(QString::number(cnt)));
cnt++;
}
new_name = copyName;
@ -811,10 +793,16 @@ bool ProfileModel::checkNameValidity(QString name, QString *msg)
invalid = true;
}
if ( invalid )
message = tr("A profile must not contain any of the following characters: %1").arg(msgChars);
{
#ifdef _WIN32
message = tr("A profile name cannot contain the following characters: %1").arg(msgChars);
#else
message = tr("A profile name cannot contain the '/' character.");
#endif
}
if ( message.isEmpty() && ( name.startsWith('.') || name.endsWith('.') ) )
message = tr("A profile must not start or end with a period (.)");
message = tr("A profile cannot start or end with a period (.)");
if (! message.isEmpty()) {
if (msg)

View File

@ -46,6 +46,7 @@ ProfileDialog::ProfileDialog(QWidget *parent) :
GeometryStateDialog(parent),
pd_ui_(new Ui::ProfileDialog),
ok_button_(Q_NULLPTR),
import_button_(Q_NULLPTR),
model_(Q_NULLPTR),
sort_model_(Q_NULLPTR)
{
@ -68,15 +69,17 @@ ProfileDialog::ProfileDialog(QWidget *parent) :
pd_ui_->lblInfo->setAttribute(Qt::WA_MacSmallSize, true);
#endif
import_button_ = pd_ui_->buttonBox->addButton(tr("Import"), QDialogButtonBox::ActionRole);
#ifdef HAVE_MINIZIP
QMenu * importMenu = new QMenu(pd_ui_->btnImport);
QMenu * importMenu = new QMenu(import_button_);
QAction * entry = importMenu->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS " from Zip"));
connect( entry, &QAction::triggered, this, &ProfileDialog::importFromZip);
entry = importMenu->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS " from Directory"));
connect( entry, &QAction::triggered, this, &ProfileDialog::importFromDirectory);
pd_ui_->btnImport->setMenu(importMenu);
import_button_->setMenu(importMenu);
#else
connect( pd_ui_->btnImport, &QPushButton::clicked, this, &ProfileDialog::importFromDirectory);
connect( import_button_, &QPushButton::clicked, this, &ProfileDialog::importFromDirectory);
#endif
resetTreeView();
@ -173,15 +176,15 @@ void ProfileDialog::updateWidgets()
QString msg = "";
if ( model_->changesPending() )
msg = tr("An import of profiles is not allowed, while changes are pending.");
pd_ui_->btnImport->setToolTip(msg);
pd_ui_->btnImport->setEnabled( ! model_->changesPending() );
import_button_->setToolTip(msg);
import_button_->setEnabled( ! model_->changesPending() );
QModelIndex index = sort_model_->mapToSource(pd_ui_->profileTreeView->currentIndex());
if ( index.column() != ProfileModel::COL_NAME )
index = index.sibling(index.row(), ProfileModel::COL_NAME);
if (index.isValid()) {
if ( !index.data(ProfileModel::DATA_IS_GLOBAL).toBool() && ! model_->resetDefault())
if ( !index.data(ProfileModel::DATA_IS_GLOBAL).toBool() || ! model_->resetDefault())
enable_del = true;
}
@ -234,7 +237,8 @@ void ProfileDialog::currentItemChanged()
void ProfileDialog::on_newToolButton_clicked()
{
pd_ui_->cmbProfileTypes->setCurrentIndex(ProfileSortModel::UserProfiles);
pd_ui_->lineProfileFilter->setText("");
pd_ui_->cmbProfileTypes->setCurrentIndex(ProfileSortModel::AllProfiles);
sort_model_->setFilterString();
QModelIndex ridx = sort_model_->mapFromSource(model_->addNewProfile(tr("New profile")));
@ -263,6 +267,7 @@ void ProfileDialog::on_deleteToolButton_clicked()
void ProfileDialog::on_copyToolButton_clicked()
{
pd_ui_->lineProfileFilter->setText("");
pd_ui_->cmbProfileTypes->setCurrentIndex(ProfileSortModel::AllProfiles);
sort_model_->setFilterString();
@ -350,6 +355,8 @@ void ProfileDialog::on_buttonBox_helpRequested()
void ProfileDialog::editingFinished()
{
pd_ui_->lineProfileFilter->setText("");
pd_ui_->cmbProfileTypes->setCurrentIndex(ProfileSortModel::AllProfiles);
currentItemChanged();
}

View File

@ -50,6 +50,7 @@ protected:
private:
Ui::ProfileDialog *pd_ui_;
QPushButton *ok_button_;
QPushButton *import_button_;
ProfileModel *model_;
ProfileSortModel *sort_model_;

View File

@ -51,7 +51,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0,0">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0">
<item>
<widget class="StockIconToolButton" name="newToolButton">
<property name="toolTip">
@ -61,7 +61,7 @@
<string/>
</property>
<property name="icon">
<iconset resource="../../image/stock_icons.qrc">
<iconset>
<normaloff>:/stock/plus-8.png</normaloff>:/stock/plus-8.png</iconset>
</property>
</widget>
@ -72,7 +72,7 @@
<string>Remove this profile. System provided profiles cannot be removed.</string>
</property>
<property name="icon">
<iconset resource="../../image/stock_icons.qrc">
<iconset>
<normaloff>:/stock/minus-8.png</normaloff>:/stock/minus-8.png</iconset>
</property>
</widget>
@ -86,18 +86,11 @@
<string/>
</property>
<property name="icon">
<iconset resource="../../image/stock_icons.qrc">
<iconset>
<normaloff>:/stock/copy-8.png</normaloff>:/stock/copy-8.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnImport">
<property name="text">
<string>Import</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -161,9 +154,7 @@
<header>widgets/elided_label.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../image/stock_icons.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>