kmail

snippetitem.cpp
1 /***************************************************************************
2  * snippet feature from tdevelop/plugins/snippet/ *
3  * *
4  * Copyright (C) 2007 by Robert Gruber *
5  * rgruber@users.sourceforge.net *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "snippetitem.h"
15 
16 #include <tdeaction.h>
17 
18 #include <tqstring.h>
19 
20 SnippetItem::SnippetItem(TQListView * parent, TQString name, TQString text )
21  : TQListViewItem( parent, name ), action(0)
22 {
23  strName = name;
24  strText = text;
25  iParent = -1;
26  setOpen( true );
27 }
28 
29 SnippetItem::SnippetItem(TQListViewItem * parent, TQString name, TQString text)
30  : TQListViewItem( parent, name ), action(0)
31 {
32  strName = name;
33  strText = text;
34  iParent = ((SnippetGroup *)parent)->getId();
35  setOpen( true );
36 }
37 
38 SnippetItem::~SnippetItem()
39 {
40  if ( action ) {
41  action->unplugAll();
42  delete action;
43  }
44 }
45 
46 
50 TQString SnippetItem::getName()
51 {
52  return strName;
53 }
54 
55 
59 TQString SnippetItem::getText()
60 {
61  return strText;
62 }
63 
64 
68 void SnippetItem::setText(TQString text)
69 {
70  strText = text;
71 }
72 
73 
77 void SnippetItem::setName(TQString name)
78 {
79  strName = name;
80 }
81 
82 void SnippetItem::resetParent()
83 {
84  SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
85  if (group)
86  iParent = group->getId();
87 }
88 
89 
90 TDEAction* SnippetItem::getAction()
91 {
92  return action;
93 }
94 
95 void SnippetItem::setAction(TDEAction * anAction)
96 {
97  action = anAction;
98 }
99 
100 void SnippetItem::slotExecute()
101 {
102  emit execute( this );
103 }
104 
105 
106 SnippetItem * SnippetItem::findItemByName(TQString name, TQPtrList<SnippetItem> &list)
107 {
108  for ( SnippetItem * item = list.first(); item; item = list.next() ) { //write the snippet-list
109  if (item->getName() == name)
110  return item;
111  }
112  return NULL;
113 }
114 
115 SnippetGroup * SnippetItem::findGroupById(int id, TQPtrList<SnippetItem> &list)
116 {
117  for ( SnippetItem * item = list.first(); item; item = list.next() ) { //write the snippet-list
118  SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
119  if (group && group->getId() == id)
120  return group;
121  }
122  return NULL;
123 }
124 
125 
126 /* * * * * * * * * * * * * * * * * * * *
127 Deklaration for class SnippetGroup
128 * * * * * * * * * * * * * * * * * * * */
129 
130 int SnippetGroup::iMaxId = 1;
131 
132 SnippetGroup::SnippetGroup(TQListView * parent, TQString name, int id)
133  : SnippetItem(parent, name, i18n("GROUP"))
134 {
135  if (id > 0) {
136  iId = id;
137  if (id >= iMaxId)
138  iMaxId = id+1;
139  } else {
140  iId = iMaxId;
141  iMaxId++;
142  }
143 }
144 
145 SnippetGroup::~SnippetGroup()
146 {
147 }
148 
149 void SnippetGroup::setId(int id)
150 {
151  iId = id;
152  if (iId >= iMaxId)
153  iMaxId = iId+1;
154 }
155 
156 #include "snippetitem.moc"
This class represents one group in the listview.
Definition: snippetitem.h:71
This class represents one CodeSnippet-Item in the listview.
Definition: snippetitem.h:32