Skip to content

Commit 4078e85

Browse files
authored
Merge pull request #71 from NickvisionApps/next
2 parents fcec21b + fd4b158 commit 4078e85

File tree

15 files changed

+318
-153
lines changed

15 files changed

+318
-153
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 2025.5.1
4+
### Breaking Changes
5+
#### System
6+
- A Process' status can now be queued with `Process::getState()` which returns a `ProcessState` value
7+
### New APIs
8+
#### Localizationm
9+
- Added `_f()` macro for creating strings with translated format strings
10+
- Added `Gettext::getAvailableLanguages()` function
11+
#### System
12+
- Added `ProcessState` enum
13+
- Added `Process::pause()` method
14+
- Added `Process::resume()` method
15+
### Fixes
16+
None
17+
318
## 2025.5.0
419
### Breaking Changes
520
#### Notifications

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
2121

2222
#libnick Definition
23-
project ("libnick" LANGUAGES C CXX VERSION 2025.5.0 DESCRIPTION "A cross-platform base for native Nickvision applications.")
23+
project ("libnick" LANGUAGES C CXX VERSION 2025.5.1 DESCRIPTION "A cross-platform base for native Nickvision applications.")
2424
include(CMakePackageConfigHelpers)
2525
include(GNUInstallDirs)
2626
include(CTest)
@@ -157,6 +157,7 @@ if (BUILD_TESTING)
157157
"tests/hardwaretests.cpp"
158158
"tests/ipctests.cpp"
159159
"tests/keyringtests.cpp"
160+
"tests/localizationtests.cpp"
160161
"tests/loggingtests.cpp"
161162
"tests/main.cpp"
162163
"tests/networktests.cpp"

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "libnick"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = "2025.3.6"
51+
PROJECT_NUMBER = "2025.5.1"
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

include/localization/gettext.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@
2323
#ifndef GETTEXT_H
2424
#define GETTEXT_H
2525

26+
#include <format>
2627
#include <string>
28+
#include <vector>
2729
#include <libintl.h>
2830

2931
#define GETTEXT_CONTEXT_SEPARATOR "\004"
3032
#define _(String) dgettext(::Nickvision::Localization::Gettext::getDomainName().c_str(), String)
3133
#define _n(String, StringPlural, N) dngettext(::Nickvision::Localization::Gettext::getDomainName().c_str(), String, StringPlural, static_cast<unsigned long>(N))
34+
#define _f(String, ...) ::Nickvision::Localization::Gettext::fgettext(String, __VA_ARGS__)
3235
#define _p(Context, String) ::Nickvision::Localization::Gettext::pgettext(Context GETTEXT_CONTEXT_SEPARATOR String, String)
3336
#define _pn(Context, String, StringPlural, N) ::Nickvision::Localization::Gettext::pngettext(Context GETTEXT_CONTEXT_SEPARATOR String, String, StringPlural, static_cast<unsigned long>(N))
3437

3538
namespace Nickvision::Localization::Gettext
3639
{
3740
/**
3841
* @brief Initializes the gettext system. This function should only be called once, regardless of with different domain names.
39-
* @param domainName The domain name to use for gettext translations. Must be lowercase and contain no spaces.
42+
* @param domainName The domain name to use for gettext translations. Must be lowercase and contain no spaces
4043
* @return True if initialized, else false
4144
*/
4245
bool init(const std::string& domainName);
@@ -45,6 +48,23 @@ namespace Nickvision::Localization::Gettext
4548
* @return The gettext domain name
4649
*/
4750
const std::string& getDomainName();
51+
/**
52+
* @brief Gets the list of available translated languages.
53+
* @return The list of available translated languages.
54+
*/
55+
const std::vector<std::string>& getAvailableLanguages();
56+
/**
57+
* @brief Translates a message and formats it with the given arguments.
58+
* @param msg The message to translate
59+
* @param args The arguments to format the translated message with
60+
*/
61+
template<typename... Args>
62+
const char* fgettext(const char* msg, Args&&... args)
63+
{
64+
static std::string res;
65+
res = std::vformat(_(msg), std::make_format_args(args...));
66+
return res.c_str();
67+
}
4868
/**
4969
* @brief Translates a message for a given context.
5070
* @param context The context of the message
@@ -63,4 +83,4 @@ namespace Nickvision::Localization::Gettext
6383
const char* pngettext(const char* context, const char* msg, const char* msgPlural, unsigned long n);
6484
}
6585

66-
#endif //GETTEXT_H
86+
#endif //GETTEXT_H

include/system/process.h

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <vector>
3333
#include "events/event.h"
3434
#include "processexitedeventargs.h"
35+
#include "processstate.h"
3536
#ifdef _WIN32
3637
#include <windows.h>
3738
#else
@@ -59,26 +60,21 @@ namespace Nickvision::System
5960
* @brief This method will wait for the process to exit if it is still running.
6061
*/
6162
~Process();
62-
/**
63-
* @brief Gets the path of the process.
64-
* @return The path of the process
65-
*/
66-
const std::filesystem::path& getPath() const;
6763
/**
6864
* @brief Gets the event for when the process has exited.
6965
* @return The process exited event
7066
*/
7167
Events::Event<ProcessExitedEventArgs>& exited();
7268
/**
73-
* @brief Gets whether or not the process is running.
74-
* @return True if running, else false
69+
* @brief Gets the path of the process.
70+
* @return The path of the process
7571
*/
76-
bool isRunning() const;
72+
const std::filesystem::path& getPath() const;
7773
/**
78-
* @brief Gets whether or not the process has completed.
79-
* @return True if completed, else false
74+
* @brief Gets the state of the proicess.
75+
* @return The state of the process.
8076
*/
81-
bool hasCompleted() const;
77+
ProcessState getState() const;
8278
/**
8379
* @brief Gets the exit code of the process.
8480
* @return The exit code of the process. -1 if the process has not completed
@@ -89,18 +85,19 @@ namespace Nickvision::System
8985
* @return The console output of the process. Empty if the process has not completed
9086
*/
9187
const std::string& getOutput() const;
92-
/**
93-
* @brief Gets the amount of RAM being used by the process in bytes.
94-
* @return The amount of RAM used by the process
95-
*/
96-
unsigned long long getRAMUsage() const;
9788
/**
9889
* @brief Gets the percent of the CPU being used by the process.
9990
* @return The CPU usage of the process
10091
*/
10192
double getCPUUsage() const;
93+
/**
94+
* @brief Gets the amount of RAM being used by the process in bytes.
95+
* @return The amount of RAM used by the process
96+
*/
97+
unsigned long long getRAMUsage() const;
10298
/**
10399
* @brief Starts the process.
100+
* @brief Use Process::resume() to start again a paused process.
104101
* @return True if the process was started, else false
105102
*/
106103
bool start();
@@ -109,21 +106,31 @@ namespace Nickvision::System
109106
* @return True if the process was killed, else false
110107
*/
111108
bool kill();
109+
/**
110+
* @brief Resumes the process.
111+
* @return True if the process was resumed, else false
112+
*/
113+
bool resume();
114+
/**
115+
* @brief Pauses the process.
116+
* @return True if the process was paused, else false
117+
*/
118+
bool pause();
112119
/**
113120
* @brief Waits for the process to exit.
114121
* @brief This function will block until the process has exited.
115-
* @brief Make sure to call start() before calling this function.
122+
* @brief Make sure to call start() / resume() before calling this function.
116123
* @return The exit code of the process
117124
*/
118125
int waitForExit();
119126
/**
120-
* @brief Send text to the process's console.
127+
* @brief Sends text to the process' console.
121128
* @param s The text to send
122129
* @return True if the text is sent, else false
123130
*/
124131
bool send(const std::string& s);
125132
/**
126-
* @brief Send text to the process's console and adds the return characters.
133+
* @brief Sends text to the process' console and adds the return characters.
127134
* @param s The command to send
128135
* @return True if the command is sent, else false
129136
*/
@@ -139,8 +146,7 @@ namespace Nickvision::System
139146
std::vector<std::string> m_args;
140147
std::filesystem::path m_workingDirectory;
141148
Events::Event<ProcessExitedEventArgs> m_exited;
142-
bool m_running;
143-
bool m_completed;
149+
ProcessState m_state;
144150
int m_exitCode;
145151
std::string m_output;
146152
std::thread m_watchThread;

include/system/processstate.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef PROCESSSTATE_H
2+
#define PROCESSSTATE_H
3+
4+
namespace Nickvision::System
5+
{
6+
/**
7+
* @brief States of a process.
8+
*/
9+
enum class ProcessState
10+
{
11+
Created, //The process was just created (start() not yet called)
12+
Running, //The process is running
13+
Killed, //The process was killed and is no longer running
14+
Paused, //The process was paused and is no longer running (continue using resume())
15+
Completed //The process was completed and is no longer running
16+
};
17+
}
18+
19+
#endif //PROCESSSTATE_H

manual/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66

77
libnick provides Nickvision apps with a common set of cross-platform APIs for managing system and desktop app functionality such as network management, taskbar icons, translations, app updates, and more.
88

9-
## 2025.3.6
9+
## 2025.5.1
1010
### Breaking Changes
11-
None
11+
#### System
12+
- A Process' status can now be queued with `Process::getState()` which returns a `ProcessState` value
1213
### New APIs
13-
None
14+
#### Localizationm
15+
- Added `_f()` macro for creating strings with translated format strings
16+
- Added `Gettext::getAvailableLanguages()` function
17+
#### System
18+
- Added `ProcessState` enum
19+
- Added `Process::pause()` method
20+
- Added `Process::resume()` method
1421
### Fixes
15-
- Library linking on Windows
22+
None
1623

1724
## Dependencies
1825
The following are a list of dependencies used by libnick.

src/filesystem/filesystemwatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace Nickvision::Filesystem
140140
{
141141
return;
142142
}
143-
OVERLAPPED overlapped{ 0 };
143+
OVERLAPPED overlapped{};
144144
overlapped.hEvent = CreateEvent(nullptr, 1, 0, nullptr);
145145
if (!overlapped.hEvent)
146146
{
@@ -312,4 +312,4 @@ namespace Nickvision::Filesystem
312312
}
313313
}
314314
#endif
315-
}
315+
}

src/localization/documentation.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,16 @@ namespace Nickvision::Localization
2525
#endif
2626
if (!sysLocale.empty() && sysLocale != "C" && sysLocale != "en_US" && sysLocale != "*")
2727
{
28-
/*
29-
* Because the translations of a Nickvision application are stored in the application's running
30-
* directory, we can look at the list of directory names and see if they contain a translation
31-
* file (.mo) for the sysLocale string. If a directory contains an mo file, we can set the
32-
* documentation lang to the sysLocale. If no directory contains an mo file for the sysLocale,
33-
* we can try to match using the two-letter language code. If that doesn't work, the default
34-
* English docs will be used.
35-
*/
3628
std::string twoLetter{ StringHelpers::split(sysLocale, "_")[0] };
37-
for (const std::filesystem::directory_entry& e : std::filesystem::directory_iterator(Environment::getExecutableDirectory()))
29+
for(const std::string& l : Gettext::getAvailableLanguages())
3830
{
39-
if (e.is_directory() && std::filesystem::exists(e.path() / (Gettext::getDomainName() + ".mo")))
31+
if(l == sysLocale || l == twoLetter)
4032
{
41-
std::string l{ e.path().filename().string() };
42-
if(l == sysLocale || l == twoLetter)
43-
{
44-
lang = l;
45-
break;
46-
}
33+
lang = l;
34+
break;
4735
}
4836
}
4937
}
5038
return "https://htmlpreview.github.io/?" + htmlDocStore + "/" + lang + "/" + pageName + ".html";
5139
}
52-
}
40+
}

src/localization/gettext.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "localization/gettext.h"
2-
#include <filesystem>
32
#include <cstdlib>
3+
#include <filesystem>
44
#include "helpers/stringhelpers.h"
55
#include "system/environment.h"
66

@@ -37,6 +37,22 @@ namespace Nickvision::Localization
3737
return s_domainName;
3838
}
3939

40+
const std::vector<std::string>& Gettext::getAvailableLanguages()
41+
{
42+
static std::vector<std::string> langs;
43+
if(langs.empty())
44+
{
45+
for (const std::filesystem::directory_entry& e : std::filesystem::directory_iterator(Environment::getExecutableDirectory()))
46+
{
47+
if (e.is_directory() && std::filesystem::exists(e.path() / (getDomainName() + ".mo")))
48+
{
49+
langs.push_back(e.path().filename().string());
50+
}
51+
}
52+
}
53+
return langs;
54+
}
55+
4056
const char* Gettext::pgettext(const char* context, const char* msg)
4157
{
4258
const char* translation{ dcgettext(s_domainName.c_str(), context, LC_MESSAGES) };
@@ -56,4 +72,4 @@ namespace Nickvision::Localization
5672
}
5773
return translation;
5874
}
59-
}
75+
}

0 commit comments

Comments
 (0)