restructure
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
This commit is contained in:
285
linux/src/notification-preferences-store.vala
Normal file
285
linux/src/notification-preferences-store.vala
Normal file
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* notification-preferences-store.vala
|
||||
*
|
||||
* Store for notification preferences.
|
||||
* Provides persistent storage for user notification settings.
|
||||
*/
|
||||
|
||||
using GLib;
|
||||
|
||||
namespace RSSuper {
|
||||
|
||||
/**
|
||||
* NotificationPreferencesStore - Persistent storage for notification preferences
|
||||
*
|
||||
* Uses GSettings for persistent storage following freedesktop.org conventions.
|
||||
*/
|
||||
public class NotificationPreferencesStore : Object {
|
||||
|
||||
// Singleton instance
|
||||
private static NotificationPreferencesStore? _instance;
|
||||
|
||||
// GSettings schema key
|
||||
private const string SCHEMA_KEY = "org.rssuper.notification.preferences";
|
||||
|
||||
// GSettings schema description
|
||||
private const string SCHEMA_DESCRIPTION = "RSSuper notification preferences";
|
||||
|
||||
// GSettings schema source URI
|
||||
private const string SCHEMA_SOURCE = "file:///app/gsettings/org.rssuper.notification.preferences.gschema.xml";
|
||||
|
||||
// Preferences schema
|
||||
private GSettings? _settings;
|
||||
|
||||
// Preferences object
|
||||
private NotificationPreferences? _preferences;
|
||||
|
||||
/**
|
||||
* Get singleton instance
|
||||
*/
|
||||
public static NotificationPreferencesStore? get_instance() {
|
||||
if (_instance == null) {
|
||||
_instance = new NotificationPreferencesStore();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance
|
||||
*/
|
||||
private NotificationPreferencesStore() {
|
||||
_settings = GSettings.new(SCHEMA_KEY, SCHEMA_DESCRIPTION);
|
||||
|
||||
// Load initial preferences
|
||||
_preferences = NotificationPreferences.from_json_string(_settings.get_string("preferences"));
|
||||
|
||||
if (_preferences == null) {
|
||||
// Set default preferences if none exist
|
||||
_preferences = new NotificationPreferences();
|
||||
_settings.set_string("preferences", _preferences.to_json_string());
|
||||
}
|
||||
|
||||
// Listen for settings changes
|
||||
_settings.changed.connect(_on_settings_changed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification preferences
|
||||
*/
|
||||
public NotificationPreferences? get_preferences() {
|
||||
return _preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set notification preferences
|
||||
*/
|
||||
public void set_preferences(NotificationPreferences prefs) {
|
||||
_preferences = prefs;
|
||||
|
||||
// Save to GSettings
|
||||
_settings.set_string("preferences", prefs.to_json_string());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new articles preference
|
||||
*/
|
||||
public bool get_new_articles() {
|
||||
return _preferences != null ? _preferences.new_articles : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new articles preference
|
||||
*/
|
||||
public void set_new_articles(bool enabled) {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.new_articles = enabled;
|
||||
_settings.set_boolean("newArticles", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get episode releases preference
|
||||
*/
|
||||
public bool get_episode_releases() {
|
||||
return _preferences != null ? _preferences.episode_releases : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set episode releases preference
|
||||
*/
|
||||
public void set_episode_releases(bool enabled) {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.episode_releases = enabled;
|
||||
_settings.set_boolean("episodeReleases", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom alerts preference
|
||||
*/
|
||||
public bool get_custom_alerts() {
|
||||
return _preferences != null ? _preferences.custom_alerts : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom alerts preference
|
||||
*/
|
||||
public void set_custom_alerts(bool enabled) {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.custom_alerts = enabled;
|
||||
_settings.set_boolean("customAlerts", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get badge count preference
|
||||
*/
|
||||
public bool get_badge_count() {
|
||||
return _preferences != null ? _preferences.badge_count : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set badge count preference
|
||||
*/
|
||||
public void set_badge_count(bool enabled) {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.badge_count = enabled;
|
||||
_settings.set_boolean("badgeCount", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sound preference
|
||||
*/
|
||||
public bool get_sound() {
|
||||
return _preferences != null ? _preferences.sound : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sound preference
|
||||
*/
|
||||
public void set_sound(bool enabled) {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.sound = enabled;
|
||||
_settings.set_boolean("sound", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get vibration preference
|
||||
*/
|
||||
public bool get_vibration() {
|
||||
return _preferences != null ? _preferences.vibration : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set vibration preference
|
||||
*/
|
||||
public void set_vibration(bool enabled) {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.vibration = enabled;
|
||||
_settings.set_boolean("vibration", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable all notifications
|
||||
*/
|
||||
public void enable_all() {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.enable_all();
|
||||
|
||||
// Save to GSettings
|
||||
_settings.set_string("preferences", _preferences.to_json_string());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable all notifications
|
||||
*/
|
||||
public void disable_all() {
|
||||
_preferences = _preferences ?? new NotificationPreferences();
|
||||
_preferences.disable_all();
|
||||
|
||||
// Save to GSettings
|
||||
_settings.set_string("preferences", _preferences.to_json_string());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all preferences as dictionary
|
||||
*/
|
||||
public Dictionary<string, object> get_all_preferences() {
|
||||
if (_preferences == null) {
|
||||
return new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
var prefs = new Dictionary<string, object>();
|
||||
prefs["new_articles"] = _preferences.new_articles;
|
||||
prefs["episode_releases"] = _preferences.episode_releases;
|
||||
prefs["custom_alerts"] = _preferences.custom_alerts;
|
||||
prefs["badge_count"] = _preferences.badge_count;
|
||||
prefs["sound"] = _preferences.sound;
|
||||
prefs["vibration"] = _preferences.vibration;
|
||||
|
||||
return prefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all preferences from dictionary
|
||||
*/
|
||||
public void set_all_preferences(Dictionary<string, object> prefs) {
|
||||
_preferences = new NotificationPreferences();
|
||||
|
||||
if (prefs.containsKey("new_articles")) {
|
||||
_preferences.new_articles = prefs["new_articles"] as bool;
|
||||
}
|
||||
if (prefs.containsKey("episode_releases")) {
|
||||
_preferences.episode_releases = prefs["episode_releases"] as bool;
|
||||
}
|
||||
if (prefs.containsKey("custom_alerts")) {
|
||||
_preferences.custom_alerts = prefs["custom_alerts"] as bool;
|
||||
}
|
||||
if (prefs.containsKey("badge_count")) {
|
||||
_preferences.badge_count = prefs["badge_count"] as bool;
|
||||
}
|
||||
if (prefs.containsKey("sound")) {
|
||||
_preferences.sound = prefs["sound"] as bool;
|
||||
}
|
||||
if (prefs.containsKey("vibration")) {
|
||||
_preferences.vibration = prefs["vibration"] as bool;
|
||||
}
|
||||
|
||||
// Save to GSettings
|
||||
_settings.set_string("preferences", _preferences.to_json_string());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get schema key
|
||||
*/
|
||||
public string get_schema_key() {
|
||||
return SCHEMA_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get schema description
|
||||
*/
|
||||
public string get_schema_description() {
|
||||
return SCHEMA_DESCRIPTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get schema source
|
||||
*/
|
||||
public string get_schema_source() {
|
||||
return SCHEMA_SOURCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle settings changed signal
|
||||
*/
|
||||
private void _on_settings_changed(GSettings settings) {
|
||||
// Settings changed, reload preferences
|
||||
_preferences = NotificationPreferences.from_json_string(settings.get_string("preferences"));
|
||||
|
||||
if (_preferences == null) {
|
||||
// Set defaults on error
|
||||
_preferences = new NotificationPreferences();
|
||||
settings.set_string("preferences", _preferences.to_json_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user