mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Switched to qmlformat.
This commit is contained in:
@@ -11,95 +11,101 @@ ColumnLayout {
|
||||
spacing: Style.marginL
|
||||
|
||||
property list<var> cardsModel: []
|
||||
property list<var> cardsDefault: [{
|
||||
property list<var> cardsDefault: [
|
||||
{
|
||||
"id": "profile-card",
|
||||
"text": "Profile",
|
||||
"enabled": true,
|
||||
"required": true
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"id": "shortcuts-card",
|
||||
"text": "Shortcuts",
|
||||
"enabled": true,
|
||||
"required": false
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"id": "audio-card",
|
||||
"text": "Audio Sliders",
|
||||
"enabled": true,
|
||||
"required": false
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"id": "weather-card",
|
||||
"text": "Weather",
|
||||
"enabled": true,
|
||||
"required": false
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"id": "media-sysmon-card",
|
||||
"text": "Media and System Monitor",
|
||||
"enabled": true,
|
||||
"required": false
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
function saveCards() {
|
||||
var toSave = []
|
||||
var toSave = [];
|
||||
for (var i = 0; i < cardsModel.length; i++) {
|
||||
toSave.push({
|
||||
"id": cardsModel[i].id,
|
||||
"enabled": cardsModel[i].enabled
|
||||
})
|
||||
});
|
||||
}
|
||||
Settings.data.controlCenter.cards = toSave
|
||||
Settings.data.controlCenter.cards = toSave;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
// Fill out availableWidgets ListModel
|
||||
availableWidgets.clear()
|
||||
var sortedEntries = ControlCenterWidgetRegistry.getAvailableWidgets().slice().sort()
|
||||
availableWidgets.clear();
|
||||
var sortedEntries = ControlCenterWidgetRegistry.getAvailableWidgets().slice().sort();
|
||||
sortedEntries.forEach(entry => {
|
||||
availableWidgets.append({
|
||||
"key": entry,
|
||||
"name": entry
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
// Starts empty
|
||||
cardsModel = []
|
||||
cardsModel = [];
|
||||
|
||||
// Add the cards available in settings
|
||||
for (var i = 0; i < Settings.data.controlCenter.cards.length; i++) {
|
||||
const settingCard = Settings.data.controlCenter.cards[i]
|
||||
const settingCard = Settings.data.controlCenter.cards[i];
|
||||
|
||||
for (var j = 0; j < cardsDefault.length; j++) {
|
||||
if (settingCard.id === cardsDefault[j].id) {
|
||||
var card = cardsDefault[j]
|
||||
card.enabled = settingCard.enabled
|
||||
var card = cardsDefault[j];
|
||||
card.enabled = settingCard.enabled;
|
||||
// Auto-disable weather card if weather is disabled
|
||||
if (card.id === "weather-card" && !Settings.data.location.weatherEnabled) {
|
||||
card.enabled = false
|
||||
card.enabled = false;
|
||||
}
|
||||
cardsModel.push(card)
|
||||
cardsModel.push(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add any missing cards from default
|
||||
for (var i = 0; i < cardsDefault.length; i++) {
|
||||
var found = false
|
||||
var found = false;
|
||||
for (var j = 0; j < cardsModel.length; j++) {
|
||||
if (cardsModel[j].id === cardsDefault[i].id) {
|
||||
found = true
|
||||
break
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
var card = cardsDefault[i]
|
||||
var card = cardsDefault[i];
|
||||
// Auto-disable weather card if weather is disabled
|
||||
if (card.id === "weather-card" && !Settings.data.location.weatherEnabled) {
|
||||
card.enabled = false
|
||||
card.enabled = false;
|
||||
}
|
||||
cardsModel.push(card)
|
||||
cardsModel.push(card);
|
||||
}
|
||||
}
|
||||
|
||||
saveCards()
|
||||
saveCards();
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
@@ -116,34 +122,43 @@ ColumnLayout {
|
||||
label: I18n.tr("settings.control-center.position.label")
|
||||
description: I18n.tr("settings.control-center.position.description")
|
||||
Layout.fillWidth: true
|
||||
model: [{
|
||||
model: [
|
||||
{
|
||||
"key": "close_to_bar_button",
|
||||
"name": I18n.tr("options.control-center.position.close_to_bar_button")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "center",
|
||||
"name": I18n.tr("options.control-center.position.center")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "top_center",
|
||||
"name": I18n.tr("options.control-center.position.top_center")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "top_left",
|
||||
"name": I18n.tr("options.control-center.position.top_left")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "top_right",
|
||||
"name": I18n.tr("options.control-center.position.top_right")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "bottom_center",
|
||||
"name": I18n.tr("options.control-center.position.bottom_center")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "bottom_left",
|
||||
"name": I18n.tr("options.control-center.position.bottom_left")
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"key": "bottom_right",
|
||||
"name": I18n.tr("options.control-center.position.bottom_right")
|
||||
}]
|
||||
}
|
||||
]
|
||||
currentKey: Settings.data.controlCenter.position
|
||||
onSelected: function (key) {
|
||||
Settings.data.controlCenter.position = key
|
||||
Settings.data.controlCenter.position = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,15 +183,15 @@ ColumnLayout {
|
||||
target: Settings.data.location
|
||||
function onWeatherEnabledChanged() {
|
||||
// Auto-disable weather card when weather is disabled
|
||||
var newModel = cardsModel.slice()
|
||||
var newModel = cardsModel.slice();
|
||||
for (var i = 0; i < newModel.length; i++) {
|
||||
if (newModel[i].id === "weather-card") {
|
||||
newModel[i] = Object.assign({}, newModel[i], {
|
||||
"enabled": Settings.data.location.weatherEnabled
|
||||
})
|
||||
cardsModel = newModel
|
||||
saveCards()
|
||||
break
|
||||
});
|
||||
cardsModel = newModel;
|
||||
saveCards();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,20 +203,20 @@ ColumnLayout {
|
||||
disabledIds: Settings.data.location.weatherEnabled ? [] : ["weather-card"]
|
||||
onItemToggled: function (index, enabled) {
|
||||
//Logger.i("ControlCenterTab", "Item", index, "toggled to", enabled)
|
||||
var newModel = cardsModel.slice()
|
||||
var newModel = cardsModel.slice();
|
||||
newModel[index] = Object.assign({}, newModel[index], {
|
||||
"enabled": enabled
|
||||
})
|
||||
cardsModel = newModel
|
||||
saveCards()
|
||||
});
|
||||
cardsModel = newModel;
|
||||
saveCards();
|
||||
}
|
||||
onItemsReordered: function (fromIndex, toIndex) {
|
||||
//Logger.i("ControlCenterTab", "Item moved from", fromIndex, "to", toIndex)
|
||||
var newModel = cardsModel.slice()
|
||||
var item = newModel.splice(fromIndex, 1)[0]
|
||||
newModel.splice(toIndex, 0, item)
|
||||
cardsModel = newModel
|
||||
saveCards()
|
||||
var newModel = cardsModel.slice();
|
||||
var item = newModel.splice(fromIndex, 1)[0];
|
||||
newModel.splice(toIndex, 0, item);
|
||||
cardsModel = newModel;
|
||||
saveCards();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,25 +292,25 @@ ColumnLayout {
|
||||
function _addWidgetToSection(widgetId, section) {
|
||||
var newWidget = {
|
||||
"id": widgetId
|
||||
}
|
||||
};
|
||||
if (ControlCenterWidgetRegistry.widgetHasUserSettings(widgetId)) {
|
||||
var metadata = ControlCenterWidgetRegistry.widgetMetadata[widgetId]
|
||||
var metadata = ControlCenterWidgetRegistry.widgetMetadata[widgetId];
|
||||
if (metadata) {
|
||||
Object.keys(metadata).forEach(function (key) {
|
||||
if (key !== "allowUserSettings") {
|
||||
newWidget[key] = metadata[key]
|
||||
newWidget[key] = metadata[key];
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
Settings.data.controlCenter.shortcuts[section].push(newWidget)
|
||||
Settings.data.controlCenter.shortcuts[section].push(newWidget);
|
||||
}
|
||||
|
||||
function _removeWidgetFromSection(section, index) {
|
||||
if (index >= 0 && index < Settings.data.controlCenter.shortcuts[section].length) {
|
||||
var newArray = Settings.data.controlCenter.shortcuts[section].slice()
|
||||
var removedWidgets = newArray.splice(index, 1)
|
||||
Settings.data.controlCenter.shortcuts[section] = newArray
|
||||
var newArray = Settings.data.controlCenter.shortcuts[section].slice();
|
||||
var removedWidgets = newArray.splice(index, 1);
|
||||
Settings.data.controlCenter.shortcuts[section] = newArray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,29 +318,29 @@ ColumnLayout {
|
||||
if (fromIndex >= 0 && fromIndex < Settings.data.controlCenter.shortcuts[section].length && toIndex >= 0 && toIndex < Settings.data.controlCenter.shortcuts[section].length) {
|
||||
|
||||
// Create a new array to avoid modifying the original
|
||||
var newArray = Settings.data.controlCenter.shortcuts[section].slice()
|
||||
var item = newArray[fromIndex]
|
||||
newArray.splice(fromIndex, 1)
|
||||
newArray.splice(toIndex, 0, item)
|
||||
var newArray = Settings.data.controlCenter.shortcuts[section].slice();
|
||||
var item = newArray[fromIndex];
|
||||
newArray.splice(fromIndex, 1);
|
||||
newArray.splice(toIndex, 0, item);
|
||||
|
||||
Settings.data.controlCenter.shortcuts[section] = newArray
|
||||
Settings.data.controlCenter.shortcuts[section] = newArray;
|
||||
}
|
||||
}
|
||||
|
||||
function _moveWidgetBetweenSections(fromSection, index, toSection) {
|
||||
// Get the widget from the source section
|
||||
if (index >= 0 && index < Settings.data.controlCenter.shortcuts[fromSection].length) {
|
||||
var widget = Settings.data.controlCenter.shortcuts[fromSection][index]
|
||||
var widget = Settings.data.controlCenter.shortcuts[fromSection][index];
|
||||
|
||||
// Remove from source section
|
||||
var sourceArray = Settings.data.controlCenter.shortcuts[fromSection].slice()
|
||||
sourceArray.splice(index, 1)
|
||||
Settings.data.controlCenter.shortcuts[fromSection] = sourceArray
|
||||
var sourceArray = Settings.data.controlCenter.shortcuts[fromSection].slice();
|
||||
sourceArray.splice(index, 1);
|
||||
Settings.data.controlCenter.shortcuts[fromSection] = sourceArray;
|
||||
|
||||
// Add to target section
|
||||
var targetArray = Settings.data.controlCenter.shortcuts[toSection].slice()
|
||||
targetArray.push(widget)
|
||||
Settings.data.controlCenter.shortcuts[toSection] = targetArray
|
||||
var targetArray = Settings.data.controlCenter.shortcuts[toSection].slice();
|
||||
targetArray.push(widget);
|
||||
Settings.data.controlCenter.shortcuts[toSection] = targetArray;
|
||||
|
||||
//Logger.i("BarTab", `Moved widget ${widget.id} from ${fromSection} to ${toSection}`)
|
||||
}
|
||||
@@ -334,10 +349,10 @@ ColumnLayout {
|
||||
function _updateWidgetSettingsInSection(section, index, settings) {
|
||||
// Create a new array to trigger QML's change detection for persistence.
|
||||
// This is crucial for Settings.data to detect the change and persist it.
|
||||
var newSectionArray = Settings.data.controlCenter.shortcuts[section].slice()
|
||||
newSectionArray[index] = settings
|
||||
Settings.data.controlCenter.shortcuts[section] = newSectionArray
|
||||
Settings.saveImmediate()
|
||||
var newSectionArray = Settings.data.controlCenter.shortcuts[section].slice();
|
||||
newSectionArray[index] = settings;
|
||||
Settings.data.controlCenter.shortcuts[section] = newSectionArray;
|
||||
Settings.saveImmediate();
|
||||
}
|
||||
|
||||
// Base list model for all combo boxes
|
||||
|
||||
Reference in New Issue
Block a user