27 #include "simplenodeselector.h"
29 #include "treenodevisitor.h"
31 #include <tdelistview.h>
32 #include <tdelocale.h>
41 class SelectNodeDialog::SelectNodeDialogPrivate
44 SimpleNodeSelector* widget;
47 SelectNodeDialog::SelectNodeDialog(FeedList* feedList, TQWidget* parent,
char* name) :
48 KDialogBase(parent, name, true, i18n(
"Select Feed or Folder"),
49 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true), d(new SelectNodeDialogPrivate)
51 d->widget =
new SimpleNodeSelector(feedList,
this);
53 connect(d->widget, TQ_SIGNAL(signalNodeSelected(TreeNode*)),
this, TQ_SLOT(slotNodeSelected(TreeNode*)));
55 setMainWidget(d->widget);
56 enableButtonOK(
false);
59 SelectNodeDialog::~SelectNodeDialog()
65 TreeNode* SelectNodeDialog::selectedNode()
const
67 return d->widget->selectedNode();
70 void SelectNodeDialog::slotSelectNode(TreeNode* node)
72 d->widget->slotSelectNode(node);
75 void SelectNodeDialog::slotNodeSelected(TreeNode* node)
77 enableButtonOK(node != 0);
81 class SimpleNodeSelector::SimpleNodeSelectorPrivate
87 TQMap<TreeNode*,TQListViewItem*> nodeToItem;
88 TQMap<TQListViewItem*, TreeNode*> itemToNode;
91 class SimpleNodeSelector::NodeVisitor :
public TreeNodeVisitor
95 NodeVisitor(SimpleNodeSelector* view) : TreeNodeVisitor(), m_view(view) {}
96 virtual ~NodeVisitor() {}
98 void createItems(TreeNode* node)
103 virtual bool visitFolder(Folder* node)
106 TQValueList<TreeNode*> children = node->children();
107 m_view->d->nodeToItem[node]->setExpandable(
true);
108 for (TQValueList<TreeNode*>::ConstIterator it = children.begin(); it != children.end(); ++it)
113 virtual bool visitTreeNode(TreeNode* node)
115 TQListViewItem* pi = node->parent() ? m_view->d->nodeToItem[node->parent()] : 0;
117 TDEListViewItem* item = 0;
119 item =
new TDEListViewItem(pi, node->title());
121 item =
new TDEListViewItem(m_view->d->view, node->title());
122 item->setExpandable(
false);
123 m_view->d->nodeToItem.insert(node, item);
124 m_view->d->itemToNode.insert(item, node);
125 connect(node, TQ_SIGNAL(signalDestroyed(TreeNode*)), m_view, TQ_SLOT(slotNodeDestroyed(TreeNode*)));
131 SimpleNodeSelector* m_view;
135 SimpleNodeSelector::SimpleNodeSelector(FeedList* feedList, TQWidget* parent,
const char* name) : TQWidget(parent, name), d(new SimpleNodeSelectorPrivate)
138 connect(feedList, TQ_SIGNAL(signalDestroyed(FeedList*)),
this, TQ_SLOT(slotFeedListDestroyed(FeedList*)));
140 d->view =
new TDEListView(
this);
141 d->view->setRootIsDecorated(
true);
142 d->view->addColumn(i18n(
"Feeds"));
144 connect(d->view, TQ_SIGNAL(selectionChanged(TQListViewItem*)),
this, TQ_SLOT(slotItemSelected(TQListViewItem*)));
146 TQGridLayout* layout =
new TQGridLayout(
this, 1, 1);
147 layout->addWidget(d->view, 0, 0);
149 d->visitor =
new NodeVisitor(
this);
151 d->visitor->createItems(d->list->rootNode());
152 d->nodeToItem[d->list->rootNode()]->setOpen(
true);
153 d->view->ensureItemVisible(d->nodeToItem[d->list->rootNode()]);
156 SimpleNodeSelector::~SimpleNodeSelector()
163 TreeNode* SimpleNodeSelector::selectedNode()
const
165 return d->itemToNode[d->view->selectedItem()];
168 void SimpleNodeSelector::slotSelectNode(TreeNode* node)
170 TQListViewItem* item = d->nodeToItem[node];
172 d->view->setSelected(item,
true);
175 void SimpleNodeSelector::slotFeedListDestroyed(FeedList* )
177 d->nodeToItem.clear();
178 d->itemToNode.clear();
182 void SimpleNodeSelector::slotItemSelected(TQListViewItem* item)
184 emit signalNodeSelected(d->itemToNode[item]);
187 void SimpleNodeSelector::slotNodeDestroyed(TreeNode* node)
189 if (d->nodeToItem.contains(node))
191 TQListViewItem* item = d->nodeToItem[node];
192 d->nodeToItem.remove(node);
193 d->itemToNode.remove(item);
200 #include "simplenodeselector.moc"