Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon themes: Active-Directory (line, duotone, color) #425

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gear/admc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BuildRequires: libkrb5-devel

Requires: libsasl2
Requires: libsasl2-plugin-gssapi
Requires: icon-theme-ActiveDirectory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest dividing theme changing feature and new themes package addition (main icon too) into two pull requests, but I am not sure about it.


Source0: %name-%version.tar

Expand Down
6 changes: 6 additions & 0 deletions src/admc/admc_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,12 @@
<oldsource>View</oldsource>
<translation>&amp;Вид</translation>
</message>
<message>
<location filename="main_window.ui" line="47"/>
<source>&amp;Theme</source>
<oldsource>Theme</oldsource>
<translation>&amp;Тема</translation>
</message>
<message>
<location filename="main_window.ui" line="59"/>
<source>&amp;Preferences</source>
Expand Down
10 changes: 8 additions & 2 deletions src/admc/console_impls/query_folder_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "globals.h"
#include "settings.h"
#include "utils.h"
#include "icon_manager/icon_manager.h"

#include <QFileDialog>
#include <QJsonDocument>
Expand Down Expand Up @@ -341,7 +342,10 @@ void console_query_tree_init(ConsoleWidget *console) {
const QList<QStandardItem *> root_row = console->add_scope_item(ItemType_QueryFolder, console->domain_info_index());
auto root = root_row[0];
root->setText(QCoreApplication::translate("query", "Saved Queries"));
root->setIcon(QIcon::fromTheme("folder"));

const QIcon create_query_folder_icon = g_icon_manager->get_object_icon("folder-query");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not related to the commit topic. Better move to another commit or create refactor branch

root->setIcon(create_query_folder_icon);

root->setDragEnabled(false);
root->setData(true, QueryItemRole_IsRoot);

Expand Down Expand Up @@ -533,7 +537,9 @@ QModelIndex console_query_folder_create(ConsoleWidget *console, const QString &n
void console_query_folder_load(const QList<QStandardItem *> &row, const QString &name, const QString &description) {
QStandardItem *main_item = row[0];
main_item->setData(description, QueryItemRole_Description);
main_item->setIcon(QIcon::fromTheme("folder"));

const QIcon create_query_folder_icon = g_icon_manager->get_object_icon("folder-query");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not related to the commit topic. Better move to another commit or create refactor branch

main_item->setIcon(create_query_folder_icon);
main_item->setData(false, QueryItemRole_IsRoot);

row[QueryColumn_Name]->setText(name);
Expand Down
11 changes: 7 additions & 4 deletions src/admc/console_impls/query_item_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "globals.h"
#include "settings.h"
#include "utils.h"
#include "icon_manager/icon_manager.h"

#include <QCoreApplication>
#include <QFileDialog>
Expand All @@ -41,8 +42,6 @@

#define QUERY_ROOT "QUERY_ROOT"

const QString query_item_icon = "emblem-system";

QueryItemImpl::QueryItemImpl(ConsoleWidget *console_arg)
: ConsoleImpl(console_arg) {
query_folder_impl = nullptr;
Expand All @@ -68,7 +67,9 @@ void QueryItemImpl::fetch(const QModelIndex &index) {
// NOTE: reset icon and tooltip in case query is in the
// "out of date" state
QStandardItem *item = console->get_item(index);
item->setIcon(QIcon::fromTheme(query_item_icon));

const QIcon create_query_item = g_icon_manager->get_object_icon("query-item");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not related to the commit topic. Better move to another commit or create refactor branch

item->setIcon(create_query_item);
item->setToolTip("");

const QString filter = index.data(QueryItemRole_Filter).toString();
Expand Down Expand Up @@ -197,7 +198,9 @@ void console_query_item_load(const QList<QStandardItem *> row, const QString &na
main_item->setData(filter_state, QueryItemRole_FilterState);
main_item->setData(base, QueryItemRole_Base);
main_item->setData(scope_is_children, QueryItemRole_ScopeIsChildren);
main_item->setIcon(QIcon::fromTheme(query_item_icon));

const QIcon create_query_item = g_icon_manager->get_object_icon("query-item");
main_item->setIcon(create_query_item);

row[QueryColumn_Name]->setText(name);
row[QueryColumn_Description]->setText(description);
Expand Down
59 changes: 42 additions & 17 deletions src/admc/icon_manager/icon_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "utils.h"
#include "ad_utils.h"
#include "ad_object.h"
#include "settings.h"

#include <QPainter>
#include <QPixmap>
Expand All @@ -11,28 +12,44 @@ IconManager::IconManager()
{
}

void IconManager::icon_theme(QString icon_theme)
{
if (icon_theme != default_theme && icon_theme != "")
settings_set_variant(SETTING_icons_theme, icon_theme);
else
settings_set_variant(SETTING_icons_theme, "");

if (icon_theme != "")
QIcon::setThemeName(icon_theme);
else
QIcon::setThemeName(default_theme);

icon_theme_name = icon_theme;
}

void IconManager::init()
{
// NOTE: use a list of possible icons because
// default icon themes for different DE's don't
// fully intersect
category_to_icon_list = {
{"Domain-DNS", {"network-server"}},
{"Container", {"folder"}},
{OBJECT_CATEGORY_OU, {"folder-documents"}},
{OBJECT_CATEGORY_GROUP, {"system-users"}},
{OBJECT_CATEGORY_PERSON, {"avatar-default", "avatar-default-symbolic"}},
{"Computer", {"computer"}},
{"Group-Policy-Container", {"preferences-other"}},
{"Volume", {"folder-templates"}},

// Some custom icons for one-off objects
{"Builtin-Domain", {"emblem-system", "emblem-system-symbolic"}},
{"Configuration", {"emblem-system", "emblem-system-symbolic"}},
{"Lost-And-Found", {"emblem-system", "emblem-system-symbolic"}},
{"Infrastructure-Update", {"emblem-system", "emblem-system-symbolic"}},
{"ms-DS-Quota-Container", {"emblem-system", "emblem-system-symbolic"}},
};
bool default_theme = icon_theme_name == QIcon::fallbackThemeName();

category_to_icon_list["Domain-DNS"] = {"network-server"};
category_to_icon_list["Container"] = {"folder"};
category_to_icon_list[OBJECT_CATEGORY_OU] = {"folder-documents"};
category_to_icon_list[OBJECT_CATEGORY_GROUP] = {"system-users"};
category_to_icon_list[OBJECT_CATEGORY_PERSON] = {"avatar-default", "avatar-default-symbolic"};
category_to_icon_list["Computer"] = {"computer"};
category_to_icon_list["Group-Policy-Container"] = {"preferences-other"};
category_to_icon_list["Volume"] = {"folder-templates"};
// Some custom icons for one-off objects
category_to_icon_list ["Builtin-Domain"] = {default_theme ? QList<QString>({"emblem-system", "emblem-system-symbolic"}) : QList<QString>({"folder"})};
category_to_icon_list["Configuration"] = {"emblem-system", "emblem-system-symbolic"};
category_to_icon_list["Lost-And-Found"] = {default_theme ? QList<QString>({"emblem-system", "emblem-system-symbolic"}) : QList<QString>({"folder"})};
category_to_icon_list["Infrastructure-Update"] = {"emblem-system", "emblem-system-symbolic"};
category_to_icon_list["ms-DS-Quota-Container"] = {default_theme ? QList<QString>({"emblem-system", "emblem-system-symbolic"}) : QList<QString>({"folder"})};
category_to_icon_list["folder-query"] = {default_theme ? QList<QString>({"emblem-system", "emblem-system-symbolic"}) : QList<QString>({"folder-query"})};
category_to_icon_list["query-item"] = {default_theme ? QList<QString>({"emblem-system", "emblem-system-symbolic"}) : QList<QString>({"query-item"})};

// NOTE: This is the icon used when no icon is
// defined for some object category
Expand Down Expand Up @@ -152,3 +169,11 @@ void IconManager::set_icon_for_type(const QIcon &icon, ItemIconType icon_type)
{
type_index_icons_array[icon_type] = icon;
}

void IconManager::set_icons_for_actions(const QHash<QString, QAction *> actions)
{
for (const QString &category : actions.keys()){
const QIcon icon = get_object_icon(category);
actions[category]->setIcon(icon);
}
}
6 changes: 6 additions & 0 deletions src/admc/icon_manager/icon_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QObject>
#include <QIcon>
#include <QMap>
#include <QAction>

enum ItemIconType {
ItemIconType_Policy_Clean,
Expand Down Expand Up @@ -35,17 +36,22 @@ class IconManager final {
public:
explicit IconManager();

QString default_theme;
void icon_theme(QString);
void init();

const QIcon& get_icon_for_type(ItemIconType icon_type) const;
QIcon get_object_icon(const AdObject &object) const;
QIcon get_object_icon(const QString& object_category) const;
void set_icon_for_type(const QIcon &icon, ItemIconType icon_type);
void set_icons_for_actions(const QHash<QString, QAction *>);

private:
QIcon type_index_icons_array[ItemIconType_LAST];
QMap<QString, QList<QString>> category_to_icon_list;

QString error_icon;
QString icon_theme_name;

//Enums positions where scope item icon can be overlayed
//by another icon
Expand Down
2 changes: 2 additions & 0 deletions src/admc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ int main(int argc, char **argv) {
app.setOrganizationDomain(ADMC_ORGANIZATION_DOMAIN);
app.setWindowIcon(QIcon(":/admc/admc.ico"));

g_icon_manager->default_theme = QIcon::themeName();
g_icon_manager->icon_theme(settings_get_variant(SETTING_icons_theme).toString());
g_icon_manager->init();

const QLocale saved_locale = settings_get_variant(SETTING_locale).toLocale();
Expand Down
42 changes: 42 additions & 0 deletions src/admc/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,48 @@ MainWindow::MainWindow(AdInterface &ad, QWidget *parent)
open_changelog();
}

//
// Setup theme action
//
QList<QPair<QString, QString>> pair = settings_get_themes();
auto theme_group = new QActionGroup(this);
for (const QPair<QString, QString> &theme : pair){
QString name_theme = theme.first;
QString display_name = theme.second;
const auto action = new QAction(display_name, theme_group);

action->setCheckable(true);
theme_group->addAction(action);

bool is_checked;
const QString current_theme = settings_get_variant(SETTING_icons_theme).toString();
current_theme == name_theme ? is_checked = true : is_checked = false;

action->setChecked(is_checked);
ui->menu_theme->addAction(action);

connect(
action, &QAction::triggered,
this,
[this, name_theme](bool checked) {
if (checked == false)
return;

g_icon_manager->icon_theme(name_theme);
g_icon_manager->init();

QHash <QString, QAction*> icons_tool_bar = {
{OBJECT_CATEGORY_PERSON, ui->action_create_user},
{OBJECT_CATEGORY_GROUP, ui->action_create_group},
{OBJECT_CATEGORY_OU, ui->action_create_ou}
};
g_icon_manager->set_icons_for_actions(icons_tool_bar);

update();
reload_console_tree();
});
}

//
// Setup language actions
//
Expand Down
8 changes: 7 additions & 1 deletion src/admc/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>27</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menu_file">
Expand All @@ -42,6 +42,11 @@
<property name="title">
<string>&amp;View</string>
</property>
<widget class="QMenu" name="menu_theme">
<property name="title">
<string>&amp;Theme</string>
</property>
</widget>
<addaction name="action_view_icons"/>
<addaction name="action_view_list"/>
<addaction name="action_view_detail"/>
Expand All @@ -53,6 +58,7 @@
<addaction name="separator"/>
<addaction name="action_customize_columns"/>
<addaction name="action_filter_objects"/>
<addaction name="menu_theme"/>
</widget>
<widget class="QMenu" name="menu_preferences">
<property name="title">
Expand Down
31 changes: 31 additions & 0 deletions src/admc/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "config.h"
#include "connection_options_dialog.h"
#include "globals.h"
#include "icon_manager/icon_manager.h"

#include <QAction>
#include <QDialog>
Expand Down Expand Up @@ -112,3 +114,32 @@ void settings_set_variant(const QString setting, const QVariant &value) {

settings.setValue(setting, value);
}

QList<QPair<QString, QString>> settings_get_themes(){
QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, "/usr/share/alt-management-console");
QSettings set("icon-theme");
set.setIniCodec("UTF-8");

QList<QPair<QString, QString>> list;
QString display_name;
if (settings_get_variant(SETTING_locale).toLocale() == QLocale::Russian){
display_name = "DISPLAY_NAME[ru]";
list.push_back({g_icon_manager->default_theme, "Системная"});
}
else{
display_name = "DISPLAY_NAME";
list.push_back({g_icon_manager->default_theme, "System"});
}

QStringList all_themes = set.childGroups();
for (QString &theme : all_themes)
{
QPair<QString, QString> pair;
set.beginGroup(theme);
pair.first = set.value("NAME").toString();
pair.second = set.value(display_name).toString();
set.endGroup();
list.push_back(pair);
}
return list;
}
5 changes: 4 additions & 1 deletion src/admc/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ DEFINE_SETTING(SETTING_last_opened_version);
DEFINE_SETTING(SETTING_object_filter);
DEFINE_SETTING(SETTING_object_filter_enabled);
DEFINE_SETTING(SETTING_object_display_limit);
DEFINE_SETTING(SETTING_custom_domain)
DEFINE_SETTING(SETTING_custom_domain);
DEFINE_SETTING(SETTING_icons_theme);

// Feature flags
//
Expand Down Expand Up @@ -166,4 +167,6 @@ bool settings_restore_geometry(const QString setting, QWidget *widget);
void settings_save_header_state(const QString setting, QHeaderView *header);
bool settings_restore_header_state(const QString setting, QHeaderView *header);

QList<QPair<QString, QString>> settings_get_themes();

#endif /* SETTINGS_H */