Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit b645f68

Browse files
committed
Tuned up the SSG integration dialog.
Removed the Favorites concept, and allowed to specify more items in the list that should be promoted forward.
1 parent 4f78f24 commit b645f68

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ if (CPPCHECK_EXECUTABLE)
332332
)
333333
endif()
334334

335-
set(SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAME "ssg-<productname>-ds.xml" CACHE STRING "Name of the datastream that should be the first one on the selection list in the initial dialogue.")
335+
set(SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAMES "ssg-<productname1>-ds.xml" CACHE STRING "Comma-separated list of datastream that should be the first ones on the selection list in the initial dialogue.")
336336

337337
# only CPack should follow
338338
set(CPACK_CMAKE_GENERATOR "Unix Makefiles")

include/Config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define SCAP_WORKBENCH_SCAP_CONTENT_DIRECTORY "@SCAP_WORKBENCH_SCAP_CONTENT_DIRECTORY@"
3636

3737
#cmakedefine SCAP_WORKBENCH_LOCAL_SCAN_ENABLED
38-
#define SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAME "@SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAME@"
38+
#define SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAMES "@SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAMES@"
3939
#define SCAP_WORKBENCH_LOCAL_OSCAP_PATH "oscap"
4040
#define SCAP_WORKBENCH_LOCAL_PKEXEC_OSCAP_PATH "@CMAKE_INSTALL_FULL_LIBEXECDIR@/scap-workbench-pkexec-oscap.sh"
4141
#define SCAP_WORKBENCH_LOCAL_RPM_EXTRACT_PATH "@CMAKE_INSTALL_FULL_LIBEXECDIR@/scap-workbench-rpm-extract.sh"

src/SSGIntegrationDialog.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,32 @@ void SSGIntegrationDialog::loadContent()
9393
* Given the string list passed as the first argument,
9494
* either make sure that the passed value is the first item,
9595
* or don't do anything (if the value is not present in the string).
96+
*
97+
* Returns true if the priority item matched a list item, returns false otherwise.
9698
*/
97-
static void put_value_as_first_item(QStringList& list, const QString& value)
99+
static bool put_value_as_first_item(QStringList& list, const QString& value)
98100
{
99101
const int value_index = list.indexOf(value);
100102
if (value_index == -1)
101103
{
102-
return;
104+
return false;
103105
}
104106
list.removeAt(value_index);
105107
list.push_front(value);
108+
return true;
109+
}
110+
111+
static void ensure_good_string_list_ordering(QStringList& list, const QStringList& priority_items, int& matched_priority_items)
112+
{
113+
list.sort();
114+
for (QStringList::const_reverse_iterator it = priority_items.rbegin();
115+
it != priority_items.rend(); ++it)
116+
{
117+
if (put_value_as_first_item(list, * it))
118+
{
119+
matched_priority_items++;
120+
}
121+
}
106122
}
107123

108124
void SSGIntegrationDialog::scrapeSSGVariants()
@@ -111,9 +127,10 @@ void SSGIntegrationDialog::scrapeSSGVariants()
111127
QStringList variants = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
112128
QComboBox* cBox = mUI.contentComboBox;
113129

114-
int lastFavoriteIndex = 0;
115-
variants.sort();
116-
put_value_as_first_item(variants, QString(SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAME));
130+
const QString first_items = QString(SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAMES);
131+
const QStringList priority_products = first_items.split(",");
132+
int matched_priority_items = 0;
133+
ensure_good_string_list_ordering(variants, priority_products, matched_priority_items);
117134
for (QStringList::const_iterator it = variants.constBegin();
118135
it != variants.constEnd(); ++it)
119136
{
@@ -127,13 +144,11 @@ void SSGIntegrationDialog::scrapeSSGVariants()
127144

128145
QString label = name;
129146

130-
bool favorite = false;
131147
// Make the label nicer for known variants
132148
if (label.startsWith("rhel") || label.startsWith("ol"))
133149
{
134150
// use RHEL instead of rhel and OL instead of ol
135151
label = name.toUpper();
136-
favorite = true;
137152
}
138153
else if (label.startsWith("centos")) // use CentOS instead of centos
139154
label.replace(0, 6, "CentOS");
@@ -147,19 +162,15 @@ void SSGIntegrationDialog::scrapeSSGVariants()
147162
else
148163
label[0] = label[0].toUpper(); // Capitalize first letter
149164

150-
if (label.startsWith("Fedora"))
151-
favorite = true;
152-
153-
if (favorite)
154-
cBox->insertItem(lastFavoriteIndex++, label, QVariant(name));
155-
156-
else
157-
cBox->addItem(label, QVariant(name));
165+
cBox->addItem(label, QVariant(name));
158166

159167
}
168+
if (matched_priority_items)
169+
{
170+
cBox->insertSeparator(matched_priority_items);
171+
}
160172
cBox->insertSeparator(cBox->count());
161173
cBox->addItem(QString("Other SCAP Content"), QVariant(QString("other-scap-content")));
162174

163-
cBox->insertSeparator(lastFavoriteIndex);
164175
cBox->setCurrentIndex(0);
165176
}

0 commit comments

Comments
 (0)