+#endif
+
+ QString groupName;
+ QMenu* groupMenu = 0;
+
+ // Add all roles to the menu that can be shown or hidden by the user
+ const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+ foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+ if (info.role == "text") {
+ // It should not be possible to hide the "text" role
+ continue;
+ }
+
+ const QString text = m_model->roleDescription(info.role);
+ QAction* action = 0;
+ if (info.group.isEmpty()) {
+ action = menu->addAction(text);
+ } else {
+ if (!groupMenu || info.group != groupName) {
+ groupName = info.group;
+ groupMenu = menu->addMenu(groupName);
+ }
+
+ action = groupMenu->addAction(text);
+ }
+
+ action->setCheckable(true);
+ action->setChecked(visibleRolesSet.contains(info.role));
+ action->setData(info.role);
+
+ const bool enable = (!info.requiresNepomuk && !info.requiresIndexer) ||
+ (info.requiresNepomuk && nepomukRunning) ||
+ (info.requiresIndexer && indexingEnabled);
+ action->setEnabled(enable);
+ }
+
+ menu->addSeparator();
+
+ QActionGroup* widthsGroup = new QActionGroup(menu);
+ const bool autoColumnWidths = props.headerColumnWidths().isEmpty();
+
+ QAction* autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
+ autoAdjustWidthsAction->setCheckable(true);
+ autoAdjustWidthsAction->setChecked(autoColumnWidths);
+ autoAdjustWidthsAction->setActionGroup(widthsGroup);
+
+ QAction* customWidthsAction = menu->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
+ customWidthsAction->setCheckable(true);
+ customWidthsAction->setChecked(!autoColumnWidths);
+ customWidthsAction->setActionGroup(widthsGroup);
+
+ QAction* action = menu->exec(pos.toPoint());
+ if (menu && action) {
+ KItemListHeader* header = view->header();
+
+ if (action == autoAdjustWidthsAction) {
+ // Clear the column-widths from the viewproperties and turn on
+ // the automatic resizing of the columns
+ props.setHeaderColumnWidths(QList<int>());
+ header->setAutomaticColumnResizing(true);
+ } else if (action == customWidthsAction) {
+ // Apply the current column-widths as custom column-widths and turn
+ // off the automatic resizing of the columns
+ QList<int> columnWidths;
+ foreach (const QByteArray& role, view->visibleRoles()) {
+ columnWidths.append(header->columnWidth(role));
+ }
+ props.setHeaderColumnWidths(columnWidths);
+ header->setAutomaticColumnResizing(false);
+ } else {
+ // Show or hide the selected role
+ const QByteArray selectedRole = action->data().toByteArray();
+
+ QList<QByteArray> visibleRoles = view->visibleRoles();
+ if (action->isChecked()) {
+ visibleRoles.append(selectedRole);
+ } else {
+ visibleRoles.removeOne(selectedRole);
+ }
+
+ view->setVisibleRoles(visibleRoles);
+ props.setVisibleRoles(visibleRoles);
+
+ QList<int> columnWidths;
+ if (!header->automaticColumnResizing()) {
+ foreach (const QByteArray& role, view->visibleRoles()) {
+ columnWidths.append(header->columnWidth(role));
+ }
+ }
+ props.setHeaderColumnWidths(columnWidths);
+ }
+ }
+
+ delete menu;