[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 21:50:42
Message-ID: 1226613042.853841.12458.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 883942 by dafre:
Preventing stale pointer crash
M +17 -12 AuthorizationsModel.cpp
M +8 -8 AuthorizationsModel.h
--- trunk/playground/base/PolicyKit-kde/authorization/AuthorizationsModel.cpp #883941:883942
@@ -9,13 +9,13 @@
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;*/}
-
+
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);
@@ -34,7 +34,7 @@
m_tree.insert(name, new TreeNode(child, this));
}
}
-
+
TreeNode* findName(const QString &path) {
QString root = path.section('.', 0, 0);
QString subpath = path.section('.', 1);
@@ -45,19 +45,19 @@
else
return 0;
}
-
+
TreeNode* parent() {
return m_parent;
}
-
+
QString id() {
return m_id;
}
-
+
QString name() {
return id().section('.', -1);
}
-
+
QDebug operator<<(QDebug dbg) {
if (m_entry==0) {
foreach(QString path, m_tree.keys()) {
@@ -68,7 +68,7 @@
}
return dbg.space();
}
-
+
QString m_id;
TreeNode* m_parent;
PolKitPolicyFileEntry* m_entry;
@@ -122,10 +122,15 @@
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 index(node->parent()->tree().keys().indexOf(node->name()), 0,
return createIndex(node->parent()->tree().keys().indexOf(node->name()), 0, node->parent());
} else {
return QModelIndex();
@@ -173,4 +178,4 @@
//kDebug() << "Added entry to tree:" << m_tree->tree()["org"]->tree();
}
-}
\ No newline at end of file
+}
--- trunk/playground/base/PolicyKit-kde/authorization/AuthorizationsModel.h #883941:883942
@@ -7,7 +7,7 @@
namespace PkKAuthorization
{
-
+
class TreeNode;
class AuthorizationsModel : public QAbstractItemModel {
@@ -16,21 +16,21 @@
enum {
IdRole = Qt::UserRole
};
-
+
AuthorizationsModel(QObject* parent = 0);
virtual ~AuthorizationsModel();
-
+
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
-
+
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;
@@ -38,4 +38,4 @@
}
-#endif
\ No newline at end of file
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic