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

make dragging check type of entry and container

put objectClass->icon mapping into a map
This commit is contained in:
Dmitry Degtyarev 2020-05-20 14:14:54 +04:00
parent 6df0b0bb9c
commit a3075abd44
3 changed files with 48 additions and 39 deletions

View File

@ -417,8 +417,6 @@ void move_user(const QString &user_dn, const QString &container_dn) {
QString user_name = extract_name_from_dn(user_dn);
QString new_dn = "CN=" + user_name + "," + container_dn;
printf("fake move %s %s\n", qPrintable(user_dn), qPrintable(container_dn));
if (FAKE_AD) {
fake_move_user(user_dn, container_dn);
@ -445,8 +443,6 @@ QString extract_name_from_dn(const QString &dn) {
QString name = dn.mid(equals_i, segment_length);
printf("extract_name_from_dn: %s %s\n", qPrintable(dn), qPrintable(name));
return name;
}
@ -458,7 +454,5 @@ QString extract_parent_dn_from_dn(const QString &dn) {
QString parent_dn = dn.mid(comma_i + 1);
printf("extract_parent_dn_from_dn: %s %s\n", qPrintable(dn), qPrintable(parent_dn));
return parent_dn;
}

View File

@ -73,29 +73,25 @@ void load_row(QList<QStandardItem*> row, const QString &dn) {
row[0]->setData(is_container, AdModel::Roles::IsContainer);
// Set icon
// NOTE: default to question mark for unhandled cases (to let you know to handle them)
// TODO: change to custom, good icons, add those icons to installation?
// TODO: are there cases where an entry can have multiple icons due to multiple objectClasses and one of them needs to be prioritized?
QMap<QString, QString> class_to_icon = {
{"groupPolicyContainer", "x-office-address-book"},
{"container", "folder"},
{"organizationalUnit", "network-workgroup"},
{"person", "avatar-default"},
{"group", "application-x-smb-workgroup"},
{"builtinDomain", "emblem-system"},
};
QList<QString> objectClasses = attributes["objectClass"];
QString icon_name = "dialog-question";
QList<QString> objectClass = attributes["objectClass"];
for (auto o : objectClass) {
printf("class=%s\n", qPrintable(o));
for (auto c : objectClasses) {
if (class_to_icon.contains(c)) {
icon_name = class_to_icon[c];
break;
}
}
if (objectClass.contains("groupPolicyContainer")) {
icon_name = "x-office-address-book";
} else if (objectClass.contains("container")) {
icon_name = "folder";
} else if (objectClass.contains("organizationalUnit")) {
icon_name = "network-workgroup";
} else if (objectClass.contains("person")) {
icon_name = "avatar-default";
} else if (objectClass.contains("group")) {
icon_name = "application-x-smb-workgroup";
} else if (objectClass.contains("builtinDomain")) {
icon_name = "emblem-system";
}
printf("icon_name=%s\n", qPrintable(icon_name));
QIcon icon = QIcon::fromTheme(icon_name);
row[0]->setIcon(icon);
}

View File

@ -82,16 +82,23 @@ void ContentsView::mouseMoveEvent(QMouseEvent *event) {
QDrag *drag = new QDrag(this);
// Set drag data to the DN of clicked entry
// Figure out if this entry can be dragged
// Entry has to be a person
QPoint pos = event->pos();
QModelIndex index = this->indexAt(pos);
QModelIndex dn_index = index.siblingAtColumn(AdModel::Column::DN);
QString dn = dn_index.data().toString();
QMimeData *mime_data = new QMimeData();
mime_data->setText(dn);
drag->setMimeData(mime_data);
QModelIndex category_index = index.siblingAtColumn(AdModel::Column::Category);
QString category_text = category_index.data().toString();
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
if (category_text == "Person") {
// Set drag data to the DN of clicked entry
QModelIndex dn_index = index.siblingAtColumn(AdModel::Column::DN);
QString dn = dn_index.data().toString();
QMimeData *mime_data = new QMimeData();
mime_data->setText(dn);
drag->setMimeData(mime_data);
drag->exec(Qt::MoveAction);
}
}
void ContentsView::dragEnterEvent(QDragEnterEvent *event) {
@ -135,14 +142,26 @@ void ContentsView::dropEvent(QDropEvent *event) {
// TODO: should accept? determining whether move succeeded is delayed until ad request is complete, so not sure how that works out
// event->acceptProposedAction();
printf("drop xd\n");
QString user_dn = event->mimeData()->text();
printf("drop\n");
QPoint pos = event->pos();
QModelIndex index = this->indexAt(pos);
QModelIndex dn_index = index.siblingAtColumn(AdModel::Column::DN);
QString container_dn = dn_index.data().toString();
QModelIndex target_index = this->indexAt(pos);
QModelIndex target_category_index = target_index.siblingAtColumn(AdModel::Column::Category);
QString target_category = target_category_index.data().toString();
move_user(user_dn, container_dn);
// TODO: figure out all possible move targets
QList<QString> valid_move_target_categories = {
"Container", "Organizational-Unit"
};
if (valid_move_target_categories.contains(target_category)) {
QString user_dn = event->mimeData()->text();
QModelIndex target_dn_index = target_index.siblingAtColumn(AdModel::Column::DN);
QString target_dn = target_dn_index.data().toString();
move_user(user_dn, target_dn);
printf("dropped with valid target\n");
} else {
printf("dropped, but invalid target\n");
}
}