1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-05 01:18:06 +03:00

User icon changes after disabling.

Disabled user icon is added to icon manager. Now user item
icon changes after user disabling in the object tree and in the
results widget.
This commit is contained in:
Semyon Knyazev 2023-08-14 21:24:28 +04:00
parent a836858a96
commit a4f677d763
5 changed files with 30 additions and 23 deletions

View File

@ -25,8 +25,6 @@
enum MyConsoleRole {
MyConsoleRole_SearchThreadId = ConsoleRole_LAST + 1,
MyConsoleRole_IconBeforeSearch,
MyConsoleRole_LAST,
};

View File

@ -1197,6 +1197,9 @@ void ObjectImpl::set_disabled(const bool disabled) {
for (const QModelIndex &index : index_list) {
QStandardItem *item = target_console->get_item(index);
item->setData(disabled, ObjectRole_AccountDisabled);
const QIcon icon = disabled ? g_icon_manager->get_icon_for_type(ItemIconType_Person_Blocked) :
g_icon_manager->get_icon_for_type(ItemIconType_Person_Clean);
item->setIcon(icon);
}
}
};
@ -1554,14 +1557,14 @@ void console_object_load(const QList<QStandardItem *> row, const AdObject &objec
}
void console_object_item_data_load(QStandardItem *item, const AdObject &object) {
const QIcon icon = g_icon_manager->get_object_icon(object);
item->setIcon(icon);
item->setData(object.get_dn(), ObjectRole_DN);
const QList<QString> object_classes = object.get_strings(ATTRIBUTE_OBJECT_CLASS);
item->setData(QVariant(object_classes), ObjectRole_ObjectClasses);
const QString object_category = object.get_string(ATTRIBUTE_OBJECT_CATEGORY);
item->setData(object_category, ObjectRole_ObjectCategory);
const bool cannot_move = object.get_system_flag(SystemFlagsBit_DomainCannotMove);
item->setData(cannot_move, ObjectRole_CannotMove);
@ -1573,6 +1576,8 @@ void console_object_item_data_load(QStandardItem *item, const AdObject &object)
const bool account_disabled = object.get_account_option(AccountOption_Disabled, g_adconfig);
item->setData(account_disabled, ObjectRole_AccountDisabled);
console_object_item_load_icon(item, account_disabled);
}
QList<QString> object_impl_column_labels() {
@ -1637,18 +1642,6 @@ void console_object_search(ConsoleWidget *console, const QModelIndex &index, con
QStandardItem *item = console->get_item(index);
// Save original icon
// NOTE: only save original icon if there isn't one
// saved already. If this search overlaps a previous
// one, then previous search would've already saved it.
const QString icon_before_search_current = item->data(MyConsoleRole_IconBeforeSearch).toString();
if (icon_before_search_current.isEmpty()) {
const QIcon original_icon = item->icon();
const QString original_icon_name = original_icon.name();
item->setData(original_icon_name, MyConsoleRole_IconBeforeSearch);
}
// Set icon to indicate that item is in "search" state
item->setIcon(QIcon::fromTheme("system-search"));
@ -1723,12 +1716,8 @@ void console_object_search(ConsoleWidget *console, const QModelIndex &index, con
return;
}
const QString original_icon_name = item_now->data(MyConsoleRole_IconBeforeSearch).toString();
item_now->setIcon(QIcon::fromTheme(original_icon_name));
// NOTE: empty IconBeforeSearch so next search
// can use this as clean state
item_now->setData(QString(), MyConsoleRole_IconBeforeSearch);
const bool is_disabled = item_now->data(ObjectRole_AccountDisabled).toBool();
console_object_item_load_icon(item_now, is_disabled);
item_now->setData(false, ObjectRole_Fetching);
item_now->setDragEnabled(true);
@ -1861,3 +1850,16 @@ bool can_create_class_at_parent(const QString &create_class, const QString &pare
return out;
}
void console_object_item_load_icon(QStandardItem *item, bool disabled) {
const QString category = dn_get_name(item->data(ObjectRole_ObjectCategory).toString());
QIcon icon;
if (category == OBJECT_CATEGORY_PERSON) {
icon = disabled ? g_icon_manager->get_icon_for_type(ItemIconType_Person_Blocked) :
g_icon_manager->get_icon_for_type(ItemIconType_Person_Clean);
item->setIcon(icon);
return;
}
icon = g_icon_manager->get_object_icon(category);
item->setIcon(icon);
}

View File

@ -47,6 +47,7 @@ class QStackedWidget;
enum ObjectRole {
ObjectRole_DN = MyConsoleRole_LAST + 1,
ObjectRole_ObjectClasses,
ObjectRole_ObjectCategory,
ObjectRole_CannotMove,
ObjectRole_CannotRename,
ObjectRole_CannotDelete,
@ -158,6 +159,7 @@ void object_impl_add_objects_to_console(ConsoleWidget *console, const QList<AdOb
void object_impl_add_objects_to_console_from_dns(ConsoleWidget *console, AdInterface &ad, const QList<QString> &dn_list, const QModelIndex &parent);
void console_object_load(const QList<QStandardItem *> row, const AdObject &object);
void console_object_item_data_load(QStandardItem *item, const AdObject &object);
void console_object_item_load_icon(QStandardItem *item, bool disabled);
QList<QString> object_impl_column_labels();
QList<int> object_impl_default_columns();
QList<QString> console_object_search_attributes();

View File

@ -51,6 +51,9 @@ void IconManager::init()
type_index_icons_array[ItemIconType_Domain_InheritanceBlocked] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Domain_Clean],
QIcon::fromTheme("changes-prevent"),
QSize(10, 10), QPoint(6, 6));
type_index_icons_array[ItemIconType_Person_Clean] = get_object_icon(OBJECT_CATEGORY_PERSON);
type_index_icons_array[ItemIconType_Person_Blocked] = overlay_scope_item_icon(type_index_icons_array[ItemIconType_Person_Clean],
QIcon::fromTheme("dialog-error"), QSize(8, 8), QPoint(8, 8));
}
QIcon IconManager::overlay_scope_item_icon(const QIcon &clean_icon, const QIcon &overlay_icon, IconOverlayPosition position) const

View File

@ -17,6 +17,8 @@ enum ItemIconType {
ItemIconType_Policy_Enforced_Disabled,
ItemIconType_Domain_Clean,
ItemIconType_Domain_InheritanceBlocked,
ItemIconType_Person_Clean,
ItemIconType_Person_Blocked,
ItemIconType_LAST
};