kmail

snippetitem.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   snippet feature from kdevelop/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 <kaction.h>
00017 
00018 #include <qstring.h>
00019 
00020 SnippetItem::SnippetItem(QListView * parent, QString name, QString text )
00021             : QListViewItem( parent, name ), action(0)
00022 {
00023   strName = name;
00024   strText = text;
00025   iParent = -1;
00026 }
00027 
00028 SnippetItem::SnippetItem(QListViewItem * parent, QString name, QString text)
00029             : QListViewItem( parent, name ), action(0)
00030 {
00031   strName = name;
00032   strText = text;
00033   iParent = ((SnippetGroup *)parent)->getId();
00034 }
00035 
00036 SnippetItem::~SnippetItem()
00037 {
00038     if ( action ) {
00039         action->unplugAll();
00040         delete action;
00041     }
00042 }
00043 
00044 
00048 QString SnippetItem::getName()
00049 {
00050   return strName;
00051 }
00052 
00053 
00057 QString SnippetItem::getText()
00058 {
00059   return strText;
00060 }
00061 
00062 
00066 void SnippetItem::setText(QString text)
00067 {
00068   strText = text;
00069 }
00070 
00071 
00075 void SnippetItem::setName(QString name)
00076 {
00077   strName = name;
00078 }
00079 
00080 void SnippetItem::resetParent()
00081 {
00082   SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
00083   if (group)
00084     iParent = group->getId();
00085 }
00086 
00087 
00088 KAction* SnippetItem::getAction()
00089 {   
00090     return action;
00091 }
00092 
00093 void SnippetItem::setAction(KAction * anAction)
00094 {
00095     action = anAction;
00096 }
00097 
00098 void SnippetItem::slotExecute()
00099 {
00100     emit execute( this );
00101 }
00102 
00103 
00104 SnippetItem * SnippetItem::findItemByName(QString name, QPtrList<SnippetItem> &list)
00105 {
00106   for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
00107     if (item->getName() == name)
00108         return item;
00109   }
00110   return NULL;
00111 }
00112 
00113 SnippetGroup * SnippetItem::findGroupById(int id, QPtrList<SnippetItem> &list)
00114 {
00115   for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
00116     SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
00117     if (group && group->getId() == id)
00118         return group;
00119   }
00120   return NULL;
00121 }
00122 
00123 
00124 /* * * * * * * * * * * * * * * * * * * *
00125 Deklaration for class SnippetGroup
00126 * * * * * * * * * * * * * * * * * * * */
00127 
00128 int SnippetGroup::iMaxId = 1;
00129 
00130 SnippetGroup::SnippetGroup(QListView * parent, QString name, int id)
00131  : SnippetItem(parent, name, "GROUP")
00132 {
00133     if (id > 0) {
00134       iId = id;
00135       if (id >= iMaxId)
00136         iMaxId = id+1;
00137     } else {
00138       iId = iMaxId;
00139       iMaxId++;
00140     }
00141 }
00142 
00143 SnippetGroup::~SnippetGroup()
00144 {
00145 }
00146 
00147 void SnippetGroup::setId(int id)
00148 {
00149     iId = id; 
00150     if (iId >= iMaxId)
00151         iMaxId = iId+1;
00152 }
00153 
00154 #include "snippetitem.moc"