summaryrefslogtreecommitdiffstats
path: root/khelpcenter/navigatorappitem.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /khelpcenter/navigatorappitem.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
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/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khelpcenter/navigatorappitem.cpp')
-rw-r--r--khelpcenter/navigatorappitem.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/khelpcenter/navigatorappitem.cpp b/khelpcenter/navigatorappitem.cpp
new file mode 100644
index 000000000..ca1dabe1f
--- /dev/null
+++ b/khelpcenter/navigatorappitem.cpp
@@ -0,0 +1,147 @@
+/*
+ * This file is part of the KDE Help Center
+ *
+ * Copyright (C) 2001 Waldo Bastian <bastian@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "navigatorappitem.h"
+
+#include "docentry.h"
+
+#include <kdebug.h>
+#include <kservicegroup.h>
+
+using namespace KHC;
+
+NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QListView *parent,
+ const QString &relPath )
+ : NavigatorItem( entry, parent ),
+ mRelpath( relPath ),
+ mPopulated( false )
+{
+ setExpandable( true );
+}
+
+NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QListViewItem *parent,
+ const QString &relPath )
+ : NavigatorItem( entry, parent ),
+ mRelpath( relPath ),
+ mPopulated( false )
+{
+ setExpandable( true );
+}
+
+NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QListView *parent,
+ QListViewItem *after )
+ : NavigatorItem( entry, parent, after ),
+ mPopulated( false )
+{
+ setExpandable( true );
+}
+
+NavigatorAppItem::NavigatorAppItem( DocEntry *entry, QListViewItem *parent,
+ QListViewItem *after )
+ : NavigatorItem( entry, parent, after ),
+ mPopulated( false )
+{
+ setExpandable( true );
+}
+
+void NavigatorAppItem::setRelpath( const QString &relpath )
+{
+ mRelpath = relpath;
+}
+
+void NavigatorAppItem::setOpen(bool open)
+{
+ kdDebug() << "NavigatorAppItem::setOpen()" << endl;
+
+ if ( open && (childCount() == 0) && !mPopulated )
+ {
+ kdDebug() << "NavigatorAppItem::setOpen(" << this << ", "
+ << mRelpath << ")" << endl;
+ populate();
+ }
+ QListViewItem::setOpen(open);
+}
+
+void NavigatorAppItem::populate( bool recursive )
+{
+ if ( mPopulated ) return;
+
+ KServiceGroup::Ptr root = KServiceGroup::group(mRelpath);
+ if ( !root ) {
+ kdWarning() << "No Service groups\n";
+ return;
+ }
+ KServiceGroup::List list = root->entries();
+
+
+ for ( KServiceGroup::List::ConstIterator it = list.begin();
+ it != list.end(); ++it )
+ {
+ KSycocaEntry * e = *it;
+ KService::Ptr s;
+ NavigatorItem *item;
+ KServiceGroup::Ptr g;
+ QString url;
+
+ switch ( e->sycocaType() ) {
+ case KST_KService:
+ {
+ s = static_cast<KService*>(e);
+ url = documentationURL( s );
+ if ( !url.isEmpty() ) {
+ DocEntry *entry = new DocEntry( s->name(), url, s->icon() );
+ item = new NavigatorItem( entry, this );
+ item->setAutoDeleteDocEntry( true );
+ item->setExpandable( true );
+ }
+ break;
+ }
+ case KST_KServiceGroup:
+ {
+ g = static_cast<KServiceGroup*>(e);
+ if ( ( g->childCount() == 0 ) || g->name().startsWith( "." ) )
+ continue;
+ DocEntry *entry = new DocEntry( g->caption(), "", g->icon() );
+ NavigatorAppItem *appItem;
+ appItem = new NavigatorAppItem( entry, this, g->relPath() );
+ appItem->setAutoDeleteDocEntry( true );
+ if ( recursive ) appItem->populate( recursive );
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ sortChildItems( 0, true /* ascending */ );
+ mPopulated = true;
+}
+
+QString NavigatorAppItem::documentationURL( KService *s )
+{
+ QString docPath = s->property( "DocPath" ).toString();
+ if ( docPath.isEmpty() )
+ return QString::null;
+
+ if ( docPath.startsWith( "file:") || docPath.startsWith( "http:" ) )
+ return docPath;
+
+ return QString( "help:/" ) + docPath;
+}
+
+// vim:ts=2:sw=2:et