Skip to content

Commit

Permalink
UI: Add API to modify Custom Browser Docks
Browse files Browse the repository at this point in the history
  • Loading branch information
Elgato-AStory committed Dec 21, 2021
1 parent 00e6f6e commit 843b49d
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 1 deletion.
33 changes: 33 additions & 0 deletions UI/api-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,39 @@ struct OBSStudioAPI : obs_frontend_callbacks {
return (void *)main->AddDockWidget((QDockWidget *)dock);
}

void obs_frontend_add_extra_browser_dock(const char *title,
const char *url,
const char *uuid) override
{
QString qstrTitle = QT_UTF8(title);
QString qstrURL = QT_UTF8(url);
QString qstrUUID = QT_UTF8(uuid);

return main->AddExtraBrowserDock(qstrTitle, qstrURL, qstrUUID,
true);
}

void obs_frontend_get_extra_browser_docks(
std::vector<std::string> &strings) override
{
for (int i = 0; i < main->extraBrowserDocks.size(); i++) {
QAction *action =
main->extraBrowserDockActions[i].data();
QString url = main->extraBrowserDockTargets[i];
QString uuid = action->property("uuid").toString();
strings.emplace_back(action->text().toStdString());
strings.emplace_back(url.toStdString());
strings.emplace_back(uuid.toStdString());
}
}

void obs_frontend_remove_extra_browser_dock(const char *uuid) override
{
QString qstrUUID = QT_UTF8(uuid);

return main->RemoveExtraBrowserDock(qstrUUID);
}

void obs_frontend_add_event_callback(obs_frontend_event_cb callback,
void *private_data) override
{
Expand Down
23 changes: 23 additions & 0 deletions UI/obs-frontend-api/obs-frontend-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,29 @@ void *obs_frontend_add_dock(void *dock)
return !!callbacks_valid() ? c->obs_frontend_add_dock(dock) : nullptr;
}

void obs_frontend_add_extra_browser_dock(const char *title, const char *url,
const char *uuid)
{
if (callbacks_valid())
c->obs_frontend_add_extra_browser_dock(title, url, uuid);
}

char **obs_frontend_get_extra_browser_docks(void)
{
if (!callbacks_valid())
return nullptr;

std::vector<std::string> strings;
c->obs_frontend_get_extra_browser_docks(strings);
return convert_string_list(strings);
}

void obs_frontend_remove_extra_browser_dock(const char *uuid)
{
if (callbacks_valid())
c->obs_frontend_remove_extra_browser_dock(uuid);
}

void obs_frontend_add_event_callback(obs_frontend_event_cb callback,
void *private_data)
{
Expand Down
7 changes: 7 additions & 0 deletions UI/obs-frontend-api/obs-frontend-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ EXPORT void obs_frontend_add_tools_menu_item(const char *name,

/* takes QDockWidget and returns QAction */
EXPORT void *obs_frontend_add_dock(void *dock);
EXPORT void obs_frontend_add_extra_browser_dock(const char *title,
const char *url,
const char *uuid);
/* Returned in the order:
title[0], url[0], uuid[0], title[1], url[1], uuid[1], ... */
EXPORT char **obs_frontend_get_extra_browser_docks(void);
EXPORT void obs_frontend_remove_extra_browser_dock(const char *uuid);

typedef void (*obs_frontend_event_cb)(enum obs_frontend_event event,
void *private_data);
Expand Down
7 changes: 7 additions & 0 deletions UI/obs-frontend-api/obs-frontend-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ struct obs_frontend_callbacks {
void *private_data) = 0;

virtual void *obs_frontend_add_dock(void *dock) = 0;
virtual void obs_frontend_add_extra_browser_dock(const char *title,
const char *url,
const char *uuid) = 0;
virtual void obs_frontend_get_extra_browser_docks(
std::vector<std::string> &strings) = 0;
virtual void
obs_frontend_remove_extra_browser_dock(const char *uuid) = 0;

virtual void
obs_frontend_add_event_callback(obs_frontend_event_cb callback,
Expand Down
1 change: 1 addition & 0 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ class OBSBasic : public OBSMainWindow {
void ManageExtraBrowserDocks();
void AddExtraBrowserDock(const QString &title, const QString &url,
const QString &uuid, bool firstCreate);
void RemoveExtraBrowserDock(const QString &uuid);
#endif

QIcon imageIcon;
Expand Down
18 changes: 18 additions & 0 deletions UI/window-extra-browsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,21 @@ void OBSBasic::AddExtraBrowserDock(const QString &title, const QString &url,
extraBrowserDockActions.push_back(QSharedPointer<QAction>(action));
extraBrowserDockTargets.push_back(url);
}

void OBSBasic::RemoveExtraBrowserDock(const QString &uuid)
{
std::vector<int> deleted;
for (int i = 0; i < extraBrowserDocks.size(); i++) {
QAction *action = extraBrowserDockActions[i].data();
QString checkUUID = action->property("uuid").toString();
if (uuid == checkUUID) {
deleted.push_back(i);
}
}
for (int i = deleted.size() - 1; i >= 0; i--) {
auto deleteAt = deleted[i];
extraBrowserDocks.removeAt(deleteAt);
extraBrowserDockActions.removeAt(deleteAt);
extraBrowserDockTargets.removeAt(deleteAt);
}
}
33 changes: 32 additions & 1 deletion docs/sphinx/reference-frontend-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Structures/Enumerations
- **OBS_FRONTEND_EVENT_TRANSITION_DURATION_CHANGED**

Triggered when the transition duration has been changed by the
user.
user.

- **OBS_FRONTEND_EVENT_TBAR_VALUE_CHANGED**

Expand Down Expand Up @@ -423,6 +423,37 @@ Functions

---------------------------------------

.. function:: void obs_frontend_add_extra_browser_dock(const char *title, const char *url, const char *uuid)

Adds a Custom Browser Dock to the UI.

:param title: Name of the dock to create
:param url: URL of page to show in the new dock
:param uuid: Optional UUID string to identify the new dock, pass an empty string to have one generated automatically

---------------------------------------

.. function:: char **obs_frontend_get_extra_browser_docks(void)

Gets a list of all custom browser docks.

:return: A list of strings, ending with NULL. Each group of 3 strings
contains the data for one custom browser dock, in the order:
title[0], url[0], uuid[0], title[1], url[1], uuid[1], ...
The list is stored within one contiguous segment of memory,
so freeing the returned pointer with :c:func:`bfree()` will free
the entire list.

---------------------------------------

.. function:: void obs_frontend_remove_extra_browser_dock(const char *uuid)

Removes all custom browser docks with a given UUID.

:param uuid: UUID string to identify the dock(s) to remove

---------------------------------------

.. function:: void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data)

Adds a callback that will be called when a frontend event occurs.
Expand Down

0 comments on commit 843b49d

Please sign in to comment.