Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/server/src/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ProviderItemData {

struct ProviderData {
std::optional<bool> enabled;
std::optional<bool> favorite;
std::optional<glz::generic::object_t> preferences;
std::map<std::string, ProviderItemData> entrypoints;
};
Expand Down Expand Up @@ -53,6 +54,7 @@ template <> struct Partial<ThemeConfig> {

template <> struct Partial<ProviderData> {
std::optional<bool> enabled;
std::optional<bool> favorite;
std::optional<glz::generic::object_t> preferences;
std::optional<std::map<std::string, ProviderItemData>> entrypoints;
};
Expand Down
37 changes: 35 additions & 2 deletions src/server/src/qml/extension-settings-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ QVariant ExtensionSettingsModel::data(const QModelIndex &index, int role) const
return e.indent;
case EnabledRole:
return e.enabled;
case FavoriteRole:
return e.favorite;
case AliasRole:
return e.alias;
case EntrypointIdRole:
Expand All @@ -64,6 +66,7 @@ QHash<int, QByteArray> ExtensionSettingsModel::roleNames() const {
{IsProviderRole, "isProvider"},
{IndentRole, "indent"},
{EnabledRole, "enabled"},
{FavoriteRole, "favorite"},
{AliasRole, "alias"},
{EntrypointIdRole, "entrypointId"},
{ExpandedRole, "expanded"},
Expand Down Expand Up @@ -168,6 +171,26 @@ void ExtensionSettingsModel::setEnabled(int row, bool value) {
if (row == m_selectedRow) emit selectedChanged();
}

void ExtensionSettingsModel::setFavorite(int row, bool value) {
if (row < 0 || std::cmp_greater_equal(row, m_visibleIndices.size())) return;
auto &e = m_allEntries[m_visibleIndices[row]];
auto *manager = ServiceRegistry::instance()->rootItemManager();

if (e.isProvider) {
manager->setProviderFavorite(e.providerId, value);
e.favorite = value;
auto idx = index(row);
emit dataChanged(idx, idx, {FavoriteRole});
} else {
manager->setItemAsFavorite(e.entrypointId, value);
e.favorite = value;
auto idx = index(row);
emit dataChanged(idx, idx, {FavoriteRole});
}

if (row == m_selectedRow) emit selectedChanged();
}

void ExtensionSettingsModel::setAlias(int row, const QString &alias) {
if (row < 0 || std::cmp_greater_equal(row, m_visibleIndices.size())) return;
auto &e = m_allEntries[m_visibleIndices[row]];
Expand Down Expand Up @@ -309,6 +332,7 @@ void ExtensionSettingsModel::rebuild(const QString &filter) {
ie.isProvider = false;
ie.indent = 1;
ie.enabled = metadata.enabled;
ie.favorite = metadata.favorite;
ie.alias = QString::fromStdString(metadata.alias.value_or(""));
ie.shortcut = QString::fromStdString(metadata.shortcut.value_or(""));
ie.entrypointId = item->uniqueId();
Expand Down Expand Up @@ -395,8 +419,8 @@ void ExtensionSettingsModel::loadCommandsForProvider(const QString &providerId)
const auto &e = m_allEntries[j];
auto *item = manager->findItemById(e.entrypointId);
bool const hasPrefs = item && !item->preferences().empty();
commands.push_back({e.name, e.type, e.iconSource, e.description, e.enabled, hasPrefs, e.alias,
QString::fromStdString(e.entrypointId), e.shortcut});
commands.push_back({e.name, e.type, e.iconSource, e.description, e.enabled, e.favorite, hasPrefs,
e.alias, QString::fromStdString(e.entrypointId), e.shortcut});
}
break;
}
Expand Down Expand Up @@ -437,6 +461,14 @@ void ExtensionSettingsModel::setEnabledByEntrypointId(const QString &id, bool va
}
}

void ExtensionSettingsModel::setFavoriteByEntrypointId(const QString &id, bool value) {
int const row = findVisibleEntryByEntrypointId(id);
if (row >= 0) {
setFavorite(row, value);
m_commandModel->setFavorite(id, value);
}
}

void ExtensionSettingsModel::setAliasByEntrypointId(const QString &id, const QString &alias) {
int const row = findVisibleEntryByEntrypointId(id);
if (row >= 0) {
Expand Down Expand Up @@ -473,6 +505,7 @@ void ExtensionSettingsModel::loadCommandPreferences(const QString &entrypointId)
for (auto &e : m_allEntries) {
if (!e.isProvider && QString::fromStdString(e.entrypointId) == entrypointId) {
auto *item = manager->findItemById(e.entrypointId);

m_cmdPrefModel->load(e.entrypointId, item ? item->preferences() : std::vector<Preference>{});
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/server/src/qml/extension-settings-model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ExtensionSettingsModel : public QAbstractListModel {
IsProviderRole,
IndentRole,
EnabledRole,
FavoriteRole,
AliasRole,
EntrypointIdRole,
ExpandedRole,
Expand Down Expand Up @@ -72,13 +73,15 @@ class ExtensionSettingsModel : public QAbstractListModel {
Q_INVOKABLE void setFilter(const QString &text);
Q_INVOKABLE void select(int row);
Q_INVOKABLE void setEnabled(int row, bool value);
Q_INVOKABLE void setFavorite(int row, bool value);
Q_INVOKABLE void setAlias(int row, const QString &alias);
Q_INVOKABLE void toggleExpanded(int row);
Q_INVOKABLE void moveUp();
Q_INVOKABLE void moveDown();
Q_INVOKABLE void activate();
Q_INVOKABLE void selectProviderById(const QString &providerId);
Q_INVOKABLE void setEnabledByEntrypointId(const QString &id, bool value);
Q_INVOKABLE void setFavoriteByEntrypointId(const QString &id, bool value);
Q_INVOKABLE void setAliasByEntrypointId(const QString &id, const QString &alias);
Q_INVOKABLE void setShortcutByEntrypointId(const QString &id, const QString &shortcut);
Q_INVOKABLE void clearShortcutByEntrypointId(const QString &id);
Expand All @@ -92,6 +95,7 @@ class ExtensionSettingsModel : public QAbstractListModel {
QString description;
bool isProvider;
bool enabled;
bool favorite;
QString alias;
QString shortcut;
EntrypointId entrypointId;
Expand Down
17 changes: 17 additions & 0 deletions src/server/src/qml/provider-command-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ QVariant ProviderCommandModel::data(const QModelIndex &index, int role) const {
return cmd.iconSource;
case EnabledRole:
return cmd.enabled;
case FavoriteRole:
return cmd.favorite;
case AliasRole:
return cmd.alias;
case EntrypointIdRole:
Expand All @@ -40,6 +42,7 @@ QHash<int, QByteArray> ProviderCommandModel::roleNames() const {
{TypeRole, "type"},
{IconSourceRole, "iconSource"},
{EnabledRole, "enabled"},
{FavoriteRole, "favorite"},
{AliasRole, "alias"},
{EntrypointIdRole, "entrypointId"},
{DescriptionRole, "description"},
Expand Down Expand Up @@ -106,6 +109,20 @@ bool ProviderCommandModel::setEnabled(const QString &entrypointId, bool value) {
return false;
}

bool ProviderCommandModel::setFavorite(const QString &entrypointId, bool value) {
for (int i = 0; std::cmp_less(i, m_allCommands.size()); ++i) {
if (m_allCommands[i].entrypointId != entrypointId) continue;
m_allCommands[i].favorite = value;
int const row = visibleRowFor(i);
if (row >= 0) {
auto idx = index(row);
emit dataChanged(idx, idx, {FavoriteRole});
}
return true;
}
return false;
}

void ProviderCommandModel::setAllEnabled(bool value) {
for (auto &cmd : m_allCommands) {
cmd.enabled = value;
Expand Down
3 changes: 3 additions & 0 deletions src/server/src/qml/provider-command-model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ProviderCommandModel : public QAbstractListModel {
TypeRole,
IconSourceRole,
EnabledRole,
FavoriteRole,
AliasRole,
EntrypointIdRole,
DescriptionRole,
Expand All @@ -32,6 +33,7 @@ class ProviderCommandModel : public QAbstractListModel {
QString iconSource;
QString description;
bool enabled;
bool favorite;
bool hasPreferences;
QString alias;
QString entrypointId;
Expand All @@ -51,6 +53,7 @@ class ProviderCommandModel : public QAbstractListModel {
void clear();

bool setEnabled(const QString &entrypointId, bool value);
bool setFavorite(const QString &entrypointId, bool value);
void setAllEnabled(bool value);
bool setAlias(const QString &entrypointId, const QString &alias);
bool setShortcut(const QString &entrypointId, const QString &shortcut);
Expand Down
15 changes: 15 additions & 0 deletions src/server/src/qml/qml/ExtensionSettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Item {
required property string iconSource
required property string description
required property bool enabled
required property bool favorite
required property string alias
required property string entrypointId
required property bool hasPreferences
Expand Down Expand Up @@ -271,6 +272,20 @@ Item {
onClicked: root.extModel.setEnabledByEntrypointId(cmdDelegate.entrypointId, !cmdDelegate.enabled)
}
}

// Favorite toggle
ViciImage {
source: cmdDelegate.favorite ? Img.builtin("star").withFillColor(Theme.accent) : Img.builtin("star-disabled").withFillColor(Theme.textMuted)
// source: Img.builtin(cmdDelegate.favorite ? "star" : "star-disabled").withFillColor(Theme.textMuted)
Layout.preferredWidth: 16
Layout.preferredHeight: 16

MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.extModel.setFavoriteByEntrypointId(cmdDelegate.entrypointId, !cmdDelegate.favorite)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ bool RootItemManager::disableItem(const EntrypointId &id) { return setItemEnable

bool RootItemManager::enableItem(const EntrypointId &id) { return setItemEnabled(id, true); }

bool RootItemManager::setProviderFavorite(const QString &providerId, bool value) {
m_cfg.mergeProviderWithUser(providerId.toStdString(), {.favorite = value});
return true;
}

std::vector<RootProvider *> RootItemManager::providers() const {
std::vector<RootProvider *> providers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ class RootItemManager : public QObject {

bool enableItem(const EntrypointId &id);

bool setProviderFavorite(const QString &providerId, bool value);

std::vector<RootProvider *> providers() const;
std::vector<ExtensionRootProvider *> extensions() const;

Expand Down