[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/PolicyKit-kde/authorization
From: Dario Freddi <drf54321 () gmail ! com>
Date: 2008-11-13 22:25:39
Message-ID: 1226615139.051794.15652.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 883963 by dafre:
Simplyfying somehow the model
M +32 -107 AuthorizationsModel.cpp
M +23 -13 AuthorizationsModel.h
--- trunk/playground/base/PolicyKit-kde/authorization/AuthorizationsModel.cpp #883962:883963
@@ -1,38 +1,26 @@
+
+
#include "AuthorizationsModel.h"
#include <QHash>
+#include <QStandardItem>
#include <KDebug>
namespace PkKAuthorization {
-class TreeNode {
+/*class TreeNode : public QStandardItem {
public:
TreeNode(TreeNode* parent = 0) {m_parent=parent;m_entry = 0;}
TreeNode(PolKitPolicyFileEntry* root, TreeNode* parent = 0) {m_parent=parent;m_entry = root;}
- ~TreeNode() {/*delete m_entry;*/}
+ ~TreeNode() {delete m_entry;}
PolKitPolicyFileEntry* data() { return m_entry; }
QHash<QString, TreeNode*> tree() { return m_tree; }
void addEntry(PolKitPolicyFileEntry* child, const QString &mypath) {
- kDebug() << "Adding entry to" << mypath;
- QString root = mypath.section('.', 0, -2).section('.', 0, 0);
- QString name = mypath.section('.', -1);
- QString path = mypath.section('.', 1);
- if (root!="") {
- if (!m_tree.contains(root)) {
- TreeNode* node = new TreeNode(this);
- node->m_id = id()+"."+root;
- m_tree.insert(root, node);
- }
- kDebug() << "Diving deeper for" << name;
- m_tree[root]->addEntry(child, path);
- } else {
- kDebug() << "Found home.";
- m_tree.insert(name, new TreeNode(child, this));
- }
+
}
TreeNode* findName(const QString &path) {
@@ -73,107 +61,44 @@
TreeNode* m_parent;
PolKitPolicyFileEntry* m_entry;
QHash<QString, TreeNode*> m_tree;
-};
+};*/
AuthorizationsModel::AuthorizationsModel(QObject* parent)
- : QAbstractItemModel(parent)
+ : QStandardItemModel(parent)
{
- m_tree = new TreeNode();
}
AuthorizationsModel::~AuthorizationsModel()
{
}
-QVariant
-AuthorizationsModel::data(const QModelIndex &index, int role) const
-{
- TreeNode* node = static_cast<TreeNode*>(index.internalPointer());
- switch(role) {
- case Qt::DisplayRole:
- return node->name();
- case IdRole:
- return node->id();
- }
- return QVariant();
-}
-
-QModelIndex
-AuthorizationsModel::index(int row, int column, const QModelIndex &parent) const
-{
- if (!parent.isValid() && m_tree->tree().keys().count() > row) {
- kDebug() << "Requesting root child";
- QList<QString> keys = m_tree->tree().keys();
- return createIndex(row, column, m_tree->tree().value(keys[row]));
- } else if (static_cast<TreeNode*>(parent.internalPointer())) {
- TreeNode* node = static_cast<TreeNode*>(parent.internalPointer());
- kDebug() << "Requesting subchild of" << node->id();
- QList<QString> keys = node->tree().keys();
- if (keys.count() <= row)
- return QModelIndex();
- kDebug() << "Found" << keys.size() << "children:" << node->tree();
- kDebug() << "Returning" << node->tree().value(keys[row]);
- return createIndex(row, column, node->tree().value(keys[row]));
- }
- return QModelIndex();
-}
-
-QModelIndex
-AuthorizationsModel::parent(const QModelIndex &index) const
-{
- TreeNode* node = static_cast<TreeNode*>(index.internalPointer());
-
- if (!node) {
- return QModelIndex();
- }
-
- if (index.isValid() && node->parent()) {
- kDebug() << "Parent:" << node->parent()->id() << "Node:" << node->id();
- kDebug() << "Children within:" << node->tree().keys();
- //return index(node->parent()->tree().keys().indexOf(node->name()), 0,
- return createIndex(node->parent()->tree().keys().indexOf(node->name()), 0, node->parent());
- } else {
- return QModelIndex();
- }
-}
-
-bool
-AuthorizationsModel::hasChildren(const QModelIndex &index) const
-{
- if (index.isValid()) {
- TreeNode* node = static_cast<TreeNode*>(index.internalPointer());
- return node->tree().size()>0;
- } else {
- return m_tree->tree().size()>0;
- }
-}
-
-int
-AuthorizationsModel::columnCount(const QModelIndex &index) const
-{
- Q_UNUSED(index)
- return 1;
-}
-
-int
-AuthorizationsModel::rowCount(const QModelIndex &index) const
-{
- TreeNode* node = static_cast<TreeNode*>(index.internalPointer());
- if (index.isValid()) {
- kDebug() << "Node" << node->name() << "Rows:" << node->tree().size();
- return node->tree().size();
- } else {
- kDebug() << "Root Rows:" << m_tree->tree().size();
- return m_tree->tree().size();
- }
- //return 0;
-}
-
void
-AuthorizationsModel::addEntry(PolKitPolicyFileEntry* entry)
+AuthorizationsModel::addEntry(PolKitPolicyFileEntry* entry, QStandardItem *parent)
{
+ if (!parent) {
+ parent = invisibleRootItem();
+ }
m_entries.append(entry);
- m_tree->addEntry(entry, polkit_policy_file_entry_get_id(entry));
+ QString mypath = polkit_policy_file_entry_get_id(entry);
+ /*kDebug() << "Adding entry to" << mypath;
+ QString root = mypath.section('.', 0, -2).section('.', 0, 0);
+ QString name = mypath.section('.', -1);
+ QString path = mypath.section('.', 1);
+ if (root != "") {
+ if (findItems(root).isEmpty()) {
+ QStandardItem *itm = new QStandardItem(root);
+ node->m_id = id()+"."+root;
+ m_tree.insert(root, node);
+ }
+ kDebug() << "Diving deeper for" << name;
+ m_tree[root]->addEntry(child, path);
+ } else {
+ kDebug() << "Found home.";
+ m_tree.insert(name, new TreeNode(child, this));
+ }*/
+ QStandardItem *itm = new QStandardItem(mypath);
+ itm->setData(mypath, IdRole);
+ parent->appendRow(itm);
emit reset();
//kDebug() << "Added entry to tree:" << m_tree->tree()["org"]->tree();
}
--- trunk/playground/base/PolicyKit-kde/authorization/AuthorizationsModel.h #883962:883963
@@ -1,7 +1,27 @@
+/* This file is part of the KDE project
+ Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+
+*/
+
#ifndef AUTHORIZATIONSMODEL_H
#define AUTHORIZATIONSMODEL_H
-#include <QAbstractItemModel>
+#include <QStandardItemModel>
#include <polkit-dbus/polkit-dbus.h>
@@ -10,7 +30,7 @@
class TreeNode;
-class AuthorizationsModel : public QAbstractItemModel {
+class AuthorizationsModel : public QStandardItemModel {
Q_OBJECT
public:
enum {
@@ -20,19 +40,9 @@
AuthorizationsModel(QObject* parent = 0);
virtual ~AuthorizationsModel();
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ void addEntry(PolKitPolicyFileEntry* entry, QStandardItem *parent = 0);
- QModelIndex index(int row, int column, const QModelIndex &parent) const;
- QModelIndex parent(const QModelIndex &index) const;
-
- int columnCount(const QModelIndex &index) const;
- int rowCount(const QModelIndex &index) const;
- bool hasChildren(const QModelIndex &index) const;
-
- void addEntry(PolKitPolicyFileEntry* entry);
-
private:
- TreeNode* m_tree;
QList<PolKitPolicyFileEntry* > m_entries;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic