summaryrefslogtreecommitdiffstats
path: root/kmail/snippetitem.cpp
blob: 7839511ae4d2a62c90456c9e4f6041fddab7e005 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/***************************************************************************
 *   snippet feature from tdevelop/plugins/snippet/                        *
 *                                                                         *
 *   Copyright (C) 2007 by Robert Gruber                                   *
 *   rgruber@users.sourceforge.net                                         *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "snippetitem.h"

#include <kaction.h>

#include <tqstring.h>

SnippetItem::SnippetItem(TQListView * parent, TQString name, TQString text )
			: TQListViewItem( parent, name ), action(0)
{
  strName = name;
  strText = text;
  iParent = -1;
  setOpen( true );
}

SnippetItem::SnippetItem(TQListViewItem * parent, TQString name, TQString text)
			: TQListViewItem( parent, name ), action(0)
{
  strName = name;
  strText = text;
  iParent = ((SnippetGroup *)parent)->getId();
  setOpen( true );
}

SnippetItem::~SnippetItem()
{
    if ( action ) {
        action->unplugAll();
        delete action;
    }
}


/*!
    \fn SnippetItem::getName()
 */
TQString SnippetItem::getName()
{
  return strName;
}


/*!
    \fn SnippetItem::getText
 */
TQString SnippetItem::getText()
{
  return strText;
}


/*!
    \fn SnippetItem::setText(TQString text)
 */
void SnippetItem::setText(TQString text)
{
  strText = text;
}


/*!
    \fn SnippetItem::setName(TQString name)
 */
void SnippetItem::setName(TQString name)
{
  strName = name;
}

void SnippetItem::resetParent()
{
  SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
  if (group)
    iParent = group->getId();
}


KAction* SnippetItem::getAction()
{
    return action;
}

void SnippetItem::setAction(KAction * anAction)
{
    action = anAction;
}

void SnippetItem::slotExecute()
{
    emit execute( this );
}


SnippetItem * SnippetItem::findItemByName(TQString name, TQPtrList<SnippetItem> &list)
{
  for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
    if (item->getName() == name)
        return item;
  }
  return NULL;
}

SnippetGroup * SnippetItem::findGroupById(int id, TQPtrList<SnippetItem> &list)
{
  for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
    SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
    if (group && group->getId() == id)
        return group;
  }
  return NULL;
}


/* * * * * * * * * * * * * * * * * * * *
Deklaration for class SnippetGroup
* * * * * * * * * * * * * * * * * * * */

int SnippetGroup::iMaxId = 1;

SnippetGroup::SnippetGroup(TQListView * parent, TQString name, int id)
 : SnippetItem(parent, name, i18n("GROUP"))
{
    if (id > 0) {
      iId = id;
      if (id >= iMaxId)
        iMaxId = id+1;
    } else {
      iId = iMaxId;
      iMaxId++;
    }
}

SnippetGroup::~SnippetGroup()
{
}

void SnippetGroup::setId(int id)
{
    iId = id;
    if (iId >= iMaxId)
        iMaxId = iId+1;
}

#include "snippetitem.moc"