Skip to content

Commit

Permalink
Merge pull request #125 from oblivioncth/dev
Browse files Browse the repository at this point in the history
Merge to master for v0.5.4
  • Loading branch information
oblivioncth authored Oct 26, 2023
2 parents fe5d641 + 1c27fd1 commit 19fd9ef
Show file tree
Hide file tree
Showing 9 changed files with 723 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ cmake_minimum_required(VERSION 3.23.0...3.26.0)
# avoided and only used for hotfixes. DON'T USE TRAILING
# ZEROS IN VERSIONS
project(Qx
VERSION 0.5.3.1
VERSION 0.5.4
LANGUAGES CXX
DESCRIPTION "Qt Extensions Library"
)

# Get helper scripts
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetchOBCMake.cmake)
fetch_ob_cmake("v0.3.2")
fetch_ob_cmake("v0.3.2.1")

# Initialize project according to standard rules
include(OB/Project)
Expand Down
3 changes: 3 additions & 0 deletions lib/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
qx_add_component("Core"
HEADERS_PRIVATE
qx-json_p.h
qx-system_p.h
HEADERS_API
qx-abstracterror.h
qx-algorithm.h
Expand Down Expand Up @@ -57,6 +58,8 @@ qx_add_component("Core"
qx-system.cpp
qx-system_linux.cpp
qx-system_win.cpp
qx-system_p_win.cpp
qx-system_p_linux.cpp
qx-systemerror.cpp
qx-systemerror_linux.cpp
qx-systemerror_win.cpp
Expand Down
13 changes: 13 additions & 0 deletions lib/core/include/qx/core/qx-system.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

// Qt Includes
#include <QString>
#ifdef __linux
#include <QSettings>
#endif

// Inner-component Includes
#include "qx/core/qx-systemerror.h"
Expand All @@ -25,6 +28,16 @@ QX_CORE_EXPORT SystemError cleanKillProcess(quint32 processId);
QX_CORE_EXPORT SystemError forceKillProcess(quint32 processId);

QX_CORE_EXPORT bool enforceSingleInstance(QString uniqueAppId);

QX_CORE_EXPORT bool setDefaultProtocolHandler(const QString& scheme, const QString& name, const QString& path = {}, const QStringList& args = {});
QX_CORE_EXPORT bool isDefaultProtocolHandler(const QString& scheme, const QString& path = {});
QX_CORE_EXPORT bool removeDefaultProtocolHandler(const QString& scheme, const QString& path = {});

#ifdef __linux__
// Temporary means to and end, will replace with full parser eventually
QX_CORE_EXPORT QSettings::Format xdgSettingsFormat();
QX_CORE_EXPORT QSettings::Format xdgDesktopSettingsFormat();
#endif
}

#endif // QX_SYSTEM_H
102 changes: 102 additions & 0 deletions lib/core/src/qx-system.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Unit Includes
#include "qx/core/qx-system.h"
#include "qx-system_p.h"

// Qt Includes
#include <QDir>
#include <QCoreApplication>

/*!
* @file qx-system.h
Expand All @@ -11,6 +16,13 @@
namespace Qx
{

namespace // Anonymous namespace for effectively private (to this cpp) functions
{

bool isValidScheme(QStringView scheme) { return !scheme.isEmpty() && !scheme.contains(QChar::Space); };

}

//-Namespace Functions-------------------------------------------------------------------------------------------------------------
/*!
* @fn quint32 processId(QString processName)
Expand Down Expand Up @@ -123,4 +135,94 @@ bool processIsRunning(quint32 processId) { return processName(processId).isNull(
* changed in future revisions once set.
*/

/*!
* Sets the application at @a path as the default handler for URI requests of @a scheme for the
* current user. The registration is configured so that when a URL that uses the protocol is followed,
* the program at the given path will be executed with the scheme URL as the last argument. Generally,
* the user is shown a prompt with the friendly name of the application @a name
* when the protocol is used.
*
* @a scheme cannot contain whitespace. If @a path is left empty, it defaults to
* QCoreApplication::applicationFilePath().
*
* Returns @c true if the operation was successful; otherwise, returns @c false.
*
* Commonly, applications are designed to handle scheme URLs as a singular argument:
*
* @code
* myapp myscheme://some-data-here
* @endcode
*
* as most operating system facilities that allow a user to select a default protocol handler do not
* for adding additional arguments; however, additional arguments can be provided via @a args, which
* are placed before the scheme URL.
*
* @note On Linux this function relies on FreeDesktop conformance.
*
* @warning The provided arguments are automatically quoted, but not escaped. If the provided arguments
* contain reserved characters, they will need to be escaped manually.
*
* @sa isDefaultProtocolHandler() and removeDefaultProtocolHandler().
*/
bool setDefaultProtocolHandler(const QString& scheme, const QString& name, const QString& path, const QStringList& args)
{
if(!isValidScheme(scheme))
return false;

QString command = '"' + QDir::toNativeSeparators(!path.isEmpty() ? path : QCoreApplication::applicationFilePath()) + '"';
if(!args.isEmpty())
command += uR"( ")"_s + args.join(uR"(" ")"_s) + '"';

return registerUriSchemeHandler(scheme, name, command);
}

/*!
* Returns @c true if the application at @a path is set as the default handler for URI requests of
* @a scheme for the current user; otherwise, returns @c false.
*
* If @a path is left empty, it defaults to
* QCoreApplication::applicationFilePath().
*
* @note On Linux this function relies on FreeDesktop conformance.
*
* @sa setDefaultProtocolHandler() and removeDefaultProtocolHandler().
*/
bool isDefaultProtocolHandler(const QString& scheme, const QString& path)
{
if(!isValidScheme(scheme))
return false;

QString p = QDir::toNativeSeparators(!path.isEmpty() ? path : QCoreApplication::applicationFilePath());
return checkUriSchemeHandler(scheme, p);
}

/*!
* Removes the application at @a path as the default handler for UR requests of @a scheme if it is
* currently set as such for the current user. This function can only remove the default on a per-user
* basis, so it can fail if the default is set system-wide on platforms where users cannot
* override defaults with an unset value.
*
* If @a path is left empty, it defaults to
* QCoreApplication::applicationFilePath().
*
* Returns @c true if the operation was successful, or the application is not the default;
* otherwise, returns @c false.
*
* @note On Linux this function relies on FreeDesktop conformance and may require a restart
* of the user's desktop session to take effect.
*
* @warning On Linux this function causes mimeapps.list to be reordered, which can affect
* MIME handler priorities! It is recommended to avoid this function in its current state.
*
* @sa isDefaultProtocolHandler() and setDefaultProtocolHandler().
*/
bool removeDefaultProtocolHandler(const QString& scheme, const QString& path)
{
if(!isValidScheme(scheme))
return false;

QString p = QDir::toNativeSeparators(!path.isEmpty() ? path : QCoreApplication::applicationFilePath());
return removeUriSchemeHandler(scheme, p);
}

}
Loading

0 comments on commit 19fd9ef

Please sign in to comment.