kmail

snippetitem.cpp

00001 /***************************************************************************
00002  *   snippet feature from tdevelop/plugins/snippet/                        *
00003  *                                                                         *
00004  *   Copyright (C) 2007 by Robert Gruber                                   *
00005  *   rgruber@users.sourceforge.net                                         *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "snippetitem.h"
00015 
00016 #include <tdeaction.h>
00017 
00018 #include <tqstring.h>
00019 
00020 SnippetItem::SnippetItem(TQListView * parent, TQString name, TQString text )
00021             : TQListViewItem( parent, name ), action(0)
00022 {
00023   strName = name;
00024   strText = text;
00025   iParent = -1;
00026   setOpen( true );
00027 }
00028 
00029 SnippetItem::SnippetItem(TQListViewItem * parent, TQString name, TQString text)
00030             : TQListViewItem( parent, name ), action(0)
00031 {
00032   strName = name;
00033   strText = text;
00034   iParent = ((SnippetGroup *)parent)->getId();
00035   setOpen( true );
00036 }
00037 
00038 SnippetItem::~SnippetItem()
00039 {
00040     if ( action ) {
00041         action->unplugAll();
00042         delete action;
00043     }
00044 }
00045 
00046 
00050 TQString SnippetItem::getName()
00051 {
00052   return strName;
00053 }
00054 
00055 
00059 TQString SnippetItem::getText()
00060 {
00061   return strText;
00062 }
00063 
00064 
00068 void SnippetItem::setText(TQString text)
00069 {
00070   strText = text;
00071 }
00072 
00073 
00077 void SnippetItem::setName(TQString name)
00078 {
00079   strName = name;
00080 }
00081 
00082 void SnippetItem::resetParent()
00083 {
00084   SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
00085   if (group)
00086     iParent = group->getId();
00087 }
00088 
00089 
00090 TDEAction* SnippetItem::getAction()
00091 {
00092     return action;
00093 }
00094 
00095 void SnippetItem::setAction(TDEAction * anAction)
00096 {
00097     action = anAction;
00098 }
00099 
00100 void SnippetItem::slotExecute()
00101 {
00102     emit execute( this );
00103 }
00104 
00105 
00106 SnippetItem * SnippetItem::findItemByName(TQString name, TQPtrList<SnippetItem> &list)
00107 {
00108   for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
00109     if (item->getName() == name)
00110         return item;
00111   }
00112   return NULL;
00113 }
00114 
00115 SnippetGroup * SnippetItem::findGroupById(int id, TQPtrList<SnippetItem> &list)
00116 {
00117   for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
00118     SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
00119     if (group && group->getId() == id)
00120         return group;
00121   }
00122   return NULL;
00123 }
00124 
00125 
00126 /* * * * * * * * * * * * * * * * * * * *
00127 Deklaration for class SnippetGroup
00128 * * * * * * * * * * * * * * * * * * * */
00129 
00130 int SnippetGroup::iMaxId = 1;
00131 
00132 SnippetGroup::SnippetGroup(TQListView * parent, TQString name, int id)
00133  : SnippetItem(parent, name, i18n("GROUP"))
00134 {
00135     if (id > 0) {
00136       iId = id;
00137       if (id >= iMaxId)
00138         iMaxId = id+1;
00139     } else {
00140       iId = iMaxId;
00141       iMaxId++;
00142     }
00143 }
00144 
00145 SnippetGroup::~SnippetGroup()
00146 {
00147 }
00148 
00149 void SnippetGroup::setId(int id)
00150 {
00151     iId = id;
00152     if (iId >= iMaxId)
00153         iMaxId = iId+1;
00154 }
00155 
00156 #include "snippetitem.moc"