From 84da08d7b7fcda12c85caeb5a10b4903770a6f69 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksig/siglistview.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 ksig/siglistview.cpp (limited to 'ksig/siglistview.cpp') diff --git a/ksig/siglistview.cpp b/ksig/siglistview.cpp new file mode 100644 index 0000000..d212478 --- /dev/null +++ b/ksig/siglistview.cpp @@ -0,0 +1,124 @@ +/*************************************************************************** + siglistview.cpp - description + ------------------- + begin : Fri Jul 19 2002 + copyright : (C) 2002 by Scott Wheeler + email : wheeler@kde.org + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "siglistview.h" +#include "siglistview.moc" + +#include "siglistviewitem.h" + +#include +#include + +SigListView *SigListView::listView = 0; + +//////////////////////////////////////////////////////////////////////////////// +// public members +//////////////////////////////////////////////////////////////////////////////// + +SigListView *SigListView::instance(QWidget *parent, const char *name) +{ + if(!listView) + listView = new SigListView(parent, name); + return(listView); +} + +void SigListView::load() +{ + if(file.open(IO_ReadOnly) && doc.setContent(&file)) { + + // find the root element + QDomNodeList topLevelElements = doc.childNodes(); + uint i = 0; + while(topLevelElements.item(i).toElement().tagName() != "SigML" && i < topLevelElements.count()) + i++; + + if(i < topLevelElements.count()) + // if we didn't hit the end of the list + rootElement = topLevelElements.item(i).toElement(); + else { + // if we didn't find the root element, create one + rootElement = doc.createElement("SigML"); + doc.appendChild(rootElement); + } + + QDomNodeList signatures = doc.elementsByTagName("signature"); + for(i = 0; i < signatures.count(); i++) + (void) new SigListViewItem(this, doc, signatures.item(i).toElement()); + + file.close(); + } + // if the document could not be opened or setData failed, create the document framework + else { + rootElement = doc.createElement("SigML"); + doc.appendChild(rootElement); + } +} + +void SigListView::save() +{ + QListViewItemIterator it(this); + while(it.current()) { + SigListViewItem *item = dynamic_cast(it.current()); + if(item) + item->render(); + it++; + } + + if(file.open(IO_WriteOnly)) { + QTextStream stream(&file); + stream << doc; + file.close(); + } +} + +SigListViewItem *SigListView::createItem() +{ + QDomElement element = doc.createElement("signature"); + rootElement.appendChild(element); + + SigListViewItem *item = new SigListViewItem(this, doc, element); + return(item); +} + +SigListViewItem *SigListView::currentItem() +{ + return(dynamic_cast(KListView::currentItem())); +} + +const SigListViewItem *SigListView::currentItem() const +{ + return(dynamic_cast(KListView::currentItem())); +} + +//////////////////////////////////////////////////////////////////////////////// +// protected members +//////////////////////////////////////////////////////////////////////////////// + +SigListView::SigListView(QWidget *parent, const char *name) : KListView(parent, name) +{ + addColumn(i18n("Signatures")); + + QString dir = KGlobal::dirs()->saveLocation("appdata"); + if(!dir.isNull()) + file.setName(dir + "sigs.sigml"); + load(); +} + +SigListView::~SigListView() +{ + +} -- cgit v1.2.1