Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/Tizen.Applications.Team/CultureInfoHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2026 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Tizen.Applications
{
/// <summary>
/// Resolves culture names from the platform-provided CultureInfo INI file.
/// </summary>
internal static class CultureInfoHelper
{
private const string _pathCultureInfoIni = "/usr/share/dotnet.tizen/framework/i18n/CultureInfo.ini";
private static bool _fileExists = File.Exists(_pathCultureInfoIni);

public static string GetCultureName(string locale)
{
if (!_fileExists)
{
return string.Empty;
}

IntPtr dictionary = Interop.LibIniParser.Load(_pathCultureInfoIni);
if (dictionary == IntPtr.Zero)
{
return string.Empty;
}

string cultureName = string.Empty;
#pragma warning disable CA1308
string key = "CultureInfo:" + locale.ToLowerInvariant();
#pragma warning restore CA1308
IntPtr value = Interop.LibIniParser.GetString(dictionary, key, IntPtr.Zero);
if (value != IntPtr.Zero)
{
cultureName = Marshal.PtrToStringAnsi(value);
}

Interop.LibIniParser.FreeDict(dictionary);
return cultureName;
}
}
}
92 changes: 92 additions & 0 deletions src/Tizen.Applications.Team/GSourceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2026 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Concurrent;

namespace Tizen.Applications
{
/// <summary>
/// Posts actions onto the GLib main loop used by the Team application.
/// </summary>
internal static class GSourceManager
{
private static readonly GSourceContext _tizenContext = new GSourceContext();
private static readonly GSourceContext _tizenUIContext = new GSourceContext();
private static readonly Interop.Glib.GSourceFunc _wrapperHandler = new Interop.Glib.GSourceFunc(Handler);

public static void Post(Action action)
{
IntPtr context = IntPtr.Zero;
var sourceContext = context == IntPtr.Zero ? _tizenContext : _tizenUIContext;
sourceContext.Post(action, context, _wrapperHandler);
}

private static bool Handler(IntPtr userData)
{
var sourceContext = userData == IntPtr.Zero ? _tizenContext : _tizenUIContext;
return sourceContext.ProcessQueue();
}
}

/// <summary>
/// Holds the GLib source state and action queue for a single main loop context.
/// </summary>
internal class GSourceContext
{
private readonly ConcurrentQueue<Action> _actionQueue = new ConcurrentQueue<Action>();
private readonly object _lock = new object();
private IntPtr _source = IntPtr.Zero;

public void Post(Action action, IntPtr context, Interop.Glib.GSourceFunc handler)
{
_actionQueue.Enqueue(action);

lock (_lock)
{
if (_source != IntPtr.Zero)
{
return;
}

_source = Interop.Glib.IdleSourceNew();
Interop.Glib.SourceSetCallback(_source, handler, context, IntPtr.Zero);
_ = Interop.Glib.SourceAttach(_source, context);
Interop.Glib.SourceUnref(_source);
}
}

public bool ProcessQueue()
{
if (_actionQueue.TryDequeue(out var action))
{
action?.Invoke();
}

lock (_lock)
{
if (!_actionQueue.IsEmpty)
{
return true;
}

_source = IntPtr.Zero;
}

return false;
}
}
}
Loading
Loading