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

Commit d776ea6

Browse files
authored
Merge pull request #221 from matejak/sort_content
Sort content labels lexicographically and allow setting of default product
2 parents f9a3d7e + b645f68 commit d776ea6

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ if (CPPCHECK_EXECUTABLE)
332332
)
333333
endif()
334334

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.")
336+
335337
# only CPack should follow
336338
set(CPACK_CMAKE_GENERATOR "Unix Makefiles")
337339
set(CPACK_SOURCE_GENERATOR "TBZ2")

include/Config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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_BASENAMES "@SCAP_WORKBENCH_PREFERRED_DATASTREAM_BASENAMES@"
3839
#define SCAP_WORKBENCH_LOCAL_OSCAP_PATH "oscap"
3940
#define SCAP_WORKBENCH_LOCAL_PKEXEC_OSCAP_PATH "@CMAKE_INSTALL_FULL_LIBEXECDIR@/scap-workbench-pkexec-oscap.sh"
4041
#define SCAP_WORKBENCH_LOCAL_RPM_EXTRACT_PATH "@CMAKE_INSTALL_FULL_LIBEXECDIR@/scap-workbench-rpm-extract.sh"

src/SSGIntegrationDialog.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,48 @@ void SSGIntegrationDialog::loadContent()
8989
accept();
9090
}
9191

92+
/*
93+
* Given the string list passed as the first argument,
94+
* either make sure that the passed value is the first item,
95+
* 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.
98+
*/
99+
static bool put_value_as_first_item(QStringList& list, const QString& value)
100+
{
101+
const int value_index = list.indexOf(value);
102+
if (value_index == -1)
103+
{
104+
return false;
105+
}
106+
list.removeAt(value_index);
107+
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+
}
122+
}
123+
92124
void SSGIntegrationDialog::scrapeSSGVariants()
93125
{
94126
const QDir& dir = getSSGDirectory();
95-
const QStringList variants = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
127+
QStringList variants = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
96128
QComboBox* cBox = mUI.contentComboBox;
97129

98-
int lastFavoriteIndex = 0;
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);
99134
for (QStringList::const_iterator it = variants.constBegin();
100135
it != variants.constEnd(); ++it)
101136
{
@@ -109,13 +144,11 @@ void SSGIntegrationDialog::scrapeSSGVariants()
109144

110145
QString label = name;
111146

112-
bool favorite = false;
113147
// Make the label nicer for known variants
114148
if (label.startsWith("rhel") || label.startsWith("ol"))
115149
{
116150
// use RHEL instead of rhel and OL instead of ol
117151
label = name.toUpper();
118-
favorite = true;
119152
}
120153
else if (label.startsWith("centos")) // use CentOS instead of centos
121154
label.replace(0, 6, "CentOS");
@@ -129,19 +162,15 @@ void SSGIntegrationDialog::scrapeSSGVariants()
129162
else
130163
label[0] = label[0].toUpper(); // Capitalize first letter
131164

132-
if (label.startsWith("Fedora"))
133-
favorite = true;
134-
135-
if (favorite)
136-
cBox->insertItem(lastFavoriteIndex++, label, QVariant(name));
137-
138-
else
139-
cBox->addItem(label, QVariant(name));
165+
cBox->addItem(label, QVariant(name));
140166

141167
}
168+
if (matched_priority_items)
169+
{
170+
cBox->insertSeparator(matched_priority_items);
171+
}
142172
cBox->insertSeparator(cBox->count());
143173
cBox->addItem(QString("Other SCAP Content"), QVariant(QString("other-scap-content")));
144174

145-
cBox->insertSeparator(lastFavoriteIndex);
146175
cBox->setCurrentIndex(0);
147176
}

0 commit comments

Comments
 (0)