Audacity 3.2.0
URLSchemesRegistry.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 URLSchemesRegistry.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11
12#include "URLSchemesRegistry.h"
13
14#include <cassert>
15#include <string>
16#include <vector>
17#include <memory>
18
19namespace
20{
21std::function<bool(std::string_view)> SchemeRegistrar;
22}
23
24void SetSchemaRegistrar(std::function<bool(std::string_view)> registrar);
25void SetSchemaRegistrar(std::function<bool(std::string_view)> registrar)
26{
27 // Only a single registrar is allowed.
28 assert(!SchemeRegistrar);
29
30 SchemeRegistrar = std::move(registrar);
31}
32
33
35{
36 return !!SchemeRegistrar;
37}
38
40{
41 static URLSchemesRegistry registry;
42 return registry;
43}
44
45bool URLSchemesRegistry::RegisterScheme(std::string_view schema)
46{
47 if (!SchemeRegistrar)
48 return false;
49
50 return SchemeRegistrar(schema);
51}
52
53void URLSchemesRegistry::HandleURL(std::string_view url)
54{
55 Publish({ url });
56}
57
auto registrar
void SetSchemaRegistrar(std::function< bool(std::string_view)> registrar)
CallbackReturn Publish(const URLschemeHandlerMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
bool RegisterScheme(std::string_view scheme)
Associates a new scheme with Audacity.
bool IsURLHandlingSupported() const noexcept
Returns true, if Audacity can handle custom URLs.
static URLSchemesRegistry & Get()
Retrieves the registry instance.
void HandleURL(std::string_view url)
std::function< bool(std::string_view)> SchemeRegistrar