Skip to content

Commit 5340785

Browse files
committed
Split the OptionsMenuButton declarations and data into librpbase header files.
This reduces source code duplication, though the data is not exported from libromdata, so copies are still included in each UI frontend. I might change it to export symbols from libromdata later.
1 parent 0f979f8 commit 5340785

File tree

9 files changed

+79
-69
lines changed

9 files changed

+79
-69
lines changed

src/gtk/OptionsMenuButton.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ROM Properties Page shell extension. (GTK+ common) *
33
* OptionsMenuButton.cpp: Options menu GtkMenuButton container. *
44
* *
5-
* Copyright (c) 2017-2025 by David Korth. *
5+
* Copyright (c) 2017-202 by David Korth. *
66
* SPDX-License-Identifier: GPL-2.0-or-later *
77
***************************************************************************/
88

@@ -13,6 +13,7 @@
1313
#include "RpGtkCpp.hpp"
1414

1515
// librpbase
16+
#include "librpbase/OptionsMenuButton_data.inc.h"
1617
using LibRpBase::RomData;
1718

1819
// C++ STL classes
@@ -137,18 +138,6 @@ struct _RpOptionsMenuButton {
137138
G_DEFINE_TYPE_EXTENDED(RpOptionsMenuButton, rp_options_menu_button,
138139
GTK_TYPE_SUPER, static_cast<GTypeFlags>(0), {});
139140

140-
/** Standard actions. **/
141-
struct option_menu_action_t {
142-
const char *desc;
143-
int id;
144-
};
145-
static const array<option_menu_action_t, 4> stdacts = {{
146-
{NOP_C_("OptionsMenuButton|StdActs", "Export to Text..."), OPTION_EXPORT_TEXT},
147-
{NOP_C_("OptionsMenuButton|StdActs", "Export to JSON..."), OPTION_EXPORT_JSON},
148-
{NOP_C_("OptionsMenuButton|StdActs", "Copy as Text"), OPTION_COPY_TEXT},
149-
{NOP_C_("OptionsMenuButton|StdActs", "Copy as JSON"), OPTION_COPY_JSON},
150-
}};
151-
152141
static void
153142
rp_options_menu_button_class_init(RpOptionsMenuButtonClass *klass)
154143
{
@@ -556,7 +545,7 @@ rp_options_menu_button_reinit_menu(RpOptionsMenuButton *widget,
556545

557546
GMenu *const menuStdActs = g_menu_new();
558547
g_menu_append_section(menuModel, nullptr, G_MENU_MODEL(menuStdActs));
559-
for (const option_menu_action_t &p : stdacts) {
548+
for (const option_menu_action_t &p : OptionsMenuButton_stdacts) {
560549
// Create the action.
561550
GSimpleAction *const action = g_simple_action_new(
562551
fmt::to_string(p.id).c_str(), nullptr);
@@ -602,7 +591,7 @@ rp_options_menu_button_reinit_menu(RpOptionsMenuButton *widget,
602591
GtkWidget *const menuOptions = gtk_menu_new();
603592
gtk_widget_set_name(menuOptions, "menuOptions");
604593

605-
for (const option_menu_action_t &p : stdacts) {
594+
for (const option_menu_action_t &p : OptionsMenuButton_stdacts) {
606595
GtkWidget *const menuItem = gtk_menu_item_new_with_label(
607596
pgettext_expr("RomDataView|Options", p.desc));
608597
// NOTE: No name for this GtkWidget.
@@ -706,7 +695,7 @@ rp_options_menu_button_update_op(RpOptionsMenuButton *widget,
706695
GList *l = gtk_container_get_children(GTK_CONTAINER(widget->menuOptions));
707696

708697
// Skip the standard actions and separator.
709-
for (size_t i = 0; i < (stdacts.size()+1) && l != nullptr; i++) {
698+
for (size_t i = 0; i < (ARRAY_SIZE(OptionsMenuButton_stdacts)+1) && l != nullptr; i++) {
710699
l = l->next;
711700
}
712701

src/gtk/OptionsMenuButton.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
* ROM Properties Page shell extension. (GTK+ common) *
33
* OptionsMenuButton.cpp: Options menu GtkMenuButton container. *
44
* *
5-
* Copyright (c) 2017-2025 by David Korth. *
5+
* Copyright (c) 2017-2026 by David Korth. *
66
* SPDX-License-Identifier: GPL-2.0-or-later *
77
***************************************************************************/
88

99
#pragma once
1010

1111
#include "gtk-compat.h"
12+
#include "librpbase/OptionsMenuButton_decl.h"
1213

1314
G_BEGIN_DECLS
1415

@@ -24,13 +25,6 @@ G_BEGIN_DECLS
2425

2526
G_DECLARE_FINAL_TYPE(RpOptionsMenuButton, rp_options_menu_button, RP, OPTIONS_MENU_BUTTON, _RpOptionsMenuButton_super)
2627

27-
enum StandardOptionID {
28-
OPTION_EXPORT_TEXT = -1,
29-
OPTION_EXPORT_JSON = -2,
30-
OPTION_COPY_TEXT = -3,
31-
OPTION_COPY_JSON = -4,
32-
};
33-
3428
GtkWidget *rp_options_menu_button_new (void) G_GNUC_MALLOC;
3529

3630
GtkArrowType rp_options_menu_button_get_direction (RpOptionsMenuButton *widget);

src/kde/OptionsMenuButton.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,21 @@
22
* ROM Properties Page shell extension. (KDE4/KF5) *
33
* OptionsMenuButton.cpp: Options menu button QPushButton subclass. *
44
* *
5-
* Copyright (c) 2016-2024 by David Korth. *
5+
* Copyright (c) 2016-2026 by David Korth. *
66
* SPDX-License-Identifier: GPL-2.0-or-later *
77
***************************************************************************/
88

99
#include "stdafx.h"
1010
#include "OptionsMenuButton.hpp"
1111

12-
// libromdata
12+
// librpbase
13+
#include "librpbase/OptionsMenuButton_data.inc.h"
1314
using LibRpBase::RomData;
1415

1516
// C++ STL classes
1617
using std::array;
1718
using std::vector;
1819

19-
/** Standard actions. **/
20-
struct option_menu_action_t {
21-
const char *desc;
22-
int id;
23-
};
24-
static const array<option_menu_action_t, 4> stdacts = {{
25-
{NOP_C_("OptionsMenuButton|StdActs", "Export to Text..."), OPTION_EXPORT_TEXT},
26-
{NOP_C_("OptionsMenuButton|StdActs", "Export to JSON..."), OPTION_EXPORT_JSON},
27-
{NOP_C_("OptionsMenuButton|StdActs", "Copy as Text"), OPTION_COPY_TEXT},
28-
{NOP_C_("OptionsMenuButton|StdActs", "Copy as JSON"), OPTION_COPY_JSON},
29-
}};
30-
3120
OptionsMenuButton::OptionsMenuButton(QWidget *parent)
3221
: super(parent)
3322
, menuOptions(nullptr)
@@ -65,7 +54,7 @@ void OptionsMenuButton::reinitMenu(const LibRpBase::RomData *romData)
6554
menuOptions->clear();
6655

6756
// Add the standard actions.
68-
for (const option_menu_action_t &p : stdacts) {
57+
for (const option_menu_action_t &p : OptionsMenuButton_stdacts) {
6958
QAction *const action = menuOptions->addAction(
7059
qpgettext_expr("OptionsMenuButton", p.desc));
7160
#ifdef RP_OMB_USE_LAMBDA_FUNCTIONS

src/kde/OptionsMenuButton.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* ROM Properties Page shell extension. (KDE4/KF5) *
33
* OptionsMenuButton.hpp: Options menu button QPushButton subclass. *
44
* *
5-
* Copyright (c) 2016-2025 by David Korth. *
5+
* Copyright (c) 2016-2026 by David Korth. *
66
* SPDX-License-Identifier: GPL-2.0-or-later *
77
***************************************************************************/
88

99
#pragma once
1010

1111
// librpbase
1212
#include "librpbase/RomData.hpp"
13+
#include "librpbase/OptionsMenuButton_decl.h"
1314

1415
// NOTE: Using QT_VERSION_CHECK causes errors on moc-qt4 due to CMAKE_AUTOMOC.
1516
// Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1396755
@@ -30,13 +31,6 @@ class QMenu;
3031
class QSignalMapper;
3132
#endif /* !RP_OMB_USE_LAMBDA_FUNCTIONS */
3233

33-
enum StandardOptionID {
34-
OPTION_EXPORT_TEXT = -1,
35-
OPTION_EXPORT_JSON = -2,
36-
OPTION_COPY_TEXT = -3,
37-
OPTION_COPY_JSON = -4,
38-
};
39-
4034
class OptionsMenuButton : public QPushButton
4135
{
4236
Q_OBJECT

src/librpbase/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ SET(${PROJECT_NAME}_H
6969
TextOut.hpp
7070
Achievements.hpp
7171
timeconv.h
72+
OptionsMenuButton_data.inc.h
73+
OptionsMenuButton_decl.h
7274
img/RpPng.hpp
7375
img/RpPngWriter.hpp
7476
img/APNG_dlopen.hpp
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/********************************************************************************
2+
* ROM Properties Page shell extension. (Win32) *
3+
* OptionsMenuButton_data.h: Common data for OptionsMenuButton implementations. *
4+
* NOTE: Should only be included by the OptionsMenuButton implementation. *
5+
* *
6+
* Copyright (c) 2017-2026 by David Korth. *
7+
* SPDX-License-Identifier: GPL-2.0-or-later *
8+
********************************************************************************/
9+
10+
#pragma once
11+
#include "OptionsMenuButton_decl.h"
12+
13+
// libi18n
14+
#include "libi18n/i18n.hpp"
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
/** Standard actions **/
21+
struct option_menu_action_t {
22+
const char *desc;
23+
int id;
24+
};
25+
static const option_menu_action_t OptionsMenuButton_stdacts[] = {
26+
{NOP_C_("OptionsMenuButton|StdActs", "Export to Text..."), OPTION_EXPORT_TEXT},
27+
{NOP_C_("OptionsMenuButton|StdActs", "Export to JSON..."), OPTION_EXPORT_JSON},
28+
{NOP_C_("OptionsMenuButton|StdActs", "Copy as Text"), OPTION_COPY_TEXT},
29+
{NOP_C_("OptionsMenuButton|StdActs", "Copy as JSON"), OPTION_COPY_JSON},
30+
};
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/***************************************************************************
2+
* ROM Properties Page shell extension. (Win32) *
3+
* OptionsMenuButton_decl.h: Common declarationss for OptionsMenuButton. *
4+
* NOTE: Should only be included by the OptionsMenuButton header file. *
5+
* *
6+
* Copyright (c) 2017-2026 by David Korth. *
7+
* SPDX-License-Identifier: GPL-2.0-or-later *
8+
***************************************************************************/
9+
10+
#pragma once
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
enum StandardOptionID {
17+
OPTION_EXPORT_TEXT = -1,
18+
OPTION_EXPORT_JSON = -2,
19+
OPTION_COPY_TEXT = -3,
20+
OPTION_COPY_JSON = -4,
21+
};
22+
23+
#ifdef __cplusplus
24+
}
25+
#endif

src/win32/OptionsMenuButton.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ROM Properties Page shell extension. (Win32) *
33
* OptionsMenuButton.cpp: Options menu button WC_BUTTON superclass. *
44
* *
5-
* Copyright (c) 2017-2025 by David Korth. *
5+
* Copyright (c) 2017-2026 by David Korth. *
66
* SPDX-License-Identifier: GPL-2.0-or-later *
77
***************************************************************************/
88

@@ -13,6 +13,7 @@
1313
// Other rom-properties libraries
1414
#include "librpbase/RomData.hpp"
1515
#include "librptext/wchar.hpp"
16+
#include "librpbase/OptionsMenuButton_data.inc.h"
1617
using LibRpBase::RomData;
1718

1819
// libwin32ui
@@ -25,18 +26,6 @@ using std::vector;
2526
static ATOM atom_optionsMenuButton;
2627
static WNDPROC pfnButtonWndProc;
2728

28-
/** Standard actions. **/
29-
struct option_menu_action_t {
30-
const char *desc;
31-
int id;
32-
};
33-
static const array<option_menu_action_t, 4> stdacts = {{
34-
{NOP_C_("OptionsMenuButton|StdActs", "Export to Text..."), OPTION_EXPORT_TEXT},
35-
{NOP_C_("OptionsMenuButton|StdActs", "Export to JSON..."), OPTION_EXPORT_JSON},
36-
{NOP_C_("OptionsMenuButton|StdActs", "Copy as Text"), OPTION_COPY_TEXT},
37-
{NOP_C_("OptionsMenuButton|StdActs", "Copy as JSON"), OPTION_COPY_JSON},
38-
}};
39-
4029
class OptionsMenuButtonPrivate
4130
{
4231
public:
@@ -131,7 +120,7 @@ void OptionsMenuButtonPrivate::reinitMenu(const RomData *romData)
131120
hMenuOptions = CreatePopupMenu();
132121

133122
// Add the standard actions.
134-
for (const option_menu_action_t &p : stdacts) {
123+
for (const option_menu_action_t &p : OptionsMenuButton_stdacts) {
135124
AppendMenu(hMenuOptions, MF_STRING, IDM_OPTIONS_MENU_BASE + p.id,
136125
tpgettext_expr("RomDataView|Options", p.desc));
137126
}

src/win32/OptionsMenuButton.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ROM Properties Page shell extension. (Win32) *
33
* OptionsMenuButton.hpp: Options menu button WC_BUTTON superclass. *
44
* *
5-
* Copyright (c) 2017-2023 by David Korth. *
5+
* Copyright (c) 2017-2026 by David Korth. *
66
* SPDX-License-Identifier: GPL-2.0-or-later *
77
***************************************************************************/
88

@@ -12,6 +12,7 @@
1212

1313
// librpbase
1414
#include "librpbase/RomData.hpp"
15+
#include "librpbase/OptionsMenuButton_decl.h"
1516

1617
#ifdef __cplusplus
1718
extern "C" {
@@ -27,13 +28,6 @@ void OptionsMenuButtonUnregister(void);
2728
#define WM_OMB_UPDATE_OP (WM_USER + 2) // wParam == id; lParam == RomData::RomOp*
2829
#define WM_OMB_POPUP_MENU (WM_USER + 3) // returns: id+IDM_OPTIONS_MENU_BASE, or 0 if none.
2930

30-
enum StandardOptionID {
31-
OPTION_EXPORT_TEXT = -1,
32-
OPTION_EXPORT_JSON = -2,
33-
OPTION_COPY_TEXT = -3,
34-
OPTION_COPY_JSON = -4,
35-
};
36-
3731
// "Options" menu item.
3832
#define IDM_OPTIONS_MENU_BASE 0x8000
3933
#define IDM_OPTIONS_MENU_EXPORT_TEXT (IDM_OPTIONS_MENU_BASE + OPTION_EXPORT_TEXT)

0 commit comments

Comments
 (0)