Exemplo n.º 1
0
void Navigator::slotItemSelected( QTreeWidgetItem *currentItem )
{
  if ( !currentItem ) return;

  mSelected = true;

  NavigatorItem *item = static_cast<NavigatorItem *>( currentItem );

  kDebug(1400) << item->entry()->name() << endl;

  item->setExpanded( !item->isExpanded() );

  KUrl url ( item->entry()->url() );

  
  
  if ( url.protocol() == "khelpcenter" ) {
      mView->closeUrl();
      History::self().updateCurrentEntry( mView );
      History::self().createEntry();
      showOverview( item, url );
  } else {
   
    emit itemSelected( url.url() );
  }

  mLastUrl = url;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
void NavigatorAppItem::populate( bool recursive )
{
  if ( mPopulated ) return;

  KServiceGroup::Ptr root = KServiceGroup::group(mRelpath);
  if ( !root ) {
    kWarning() << "No Service groups\n";
    return;
  }
  KServiceGroup::List list = root->entries();


  for ( KServiceGroup::List::ConstIterator it = list.constBegin();
        it != list.constEnd(); ++it )
  {
    const KSycocaEntry::Ptr e = *it;
    NavigatorItem *item;
    QString url;

    switch ( e->sycocaType() ) {
      case KST_KService:
      {
        const KService::Ptr s = KService::Ptr::staticCast(e);
        url = documentationURL( s.data() );
        if ( !url.isEmpty() ) {
          DocEntry *entry = new DocEntry( s->name(), url, s->icon() );
          item = new NavigatorItem( entry, this );
          item->setAutoDeleteDocEntry( true );
        }
        break;
      }
      case KST_KServiceGroup:
      {
        KServiceGroup::Ptr g = KServiceGroup::Ptr::staticCast(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;
    }
  }
  sortChildren( 0, Qt::AscendingOrder /* ascending */ );
  mPopulated = true;
}
Exemplo n.º 4
0
void Navigator::createItemFromDesktopFile( NavigatorItem *topItem,
                                           const QString &file )
{
    KDesktopFile desktopFile( file );
    QString docPath = desktopFile.readDocPath();
    if ( !docPath.isNull() ) {
      // First parameter is ignored if second is an absolute path
      KUrl url(KUrl("help:/"), docPath);
      QString icon = desktopFile.readIcon();
      if ( icon.isEmpty() ) icon = "text-plain";
      DocEntry *entry = new DocEntry( desktopFile.readName(), url.url(), icon );
      NavigatorItem *item = new NavigatorItem( entry, topItem );
      item->setAutoDeleteDocEntry( true );
    }
}
Exemplo n.º 5
0
QString Navigator::createChildrenList( QTreeWidgetItem *child )
{
  ++mDirLevel;

  QString t;

  t += QLatin1String("<ul>\n");

  int cc = child->childCount();
  for (int i=0;i<cc;i++) 
  {
    NavigatorItem *childItem = static_cast<NavigatorItem *>( child->child(i) );

    DocEntry *e = childItem->entry();

    t += QLatin1String("<li><a href=\"") + e->url() + QLatin1String("\">");
    if ( e->isDirectory() ) t += QLatin1String("<b>");
    t += e->name();
    if ( e->isDirectory() ) t += QLatin1String("</b>");
    t += QLatin1String("</a>");

    if ( !e->info().isEmpty() ) {
      t += QLatin1String("<br>") + e->info();
    }

    t += QLatin1String("</li>\n");

    if ( childItem->childCount() > 0 && mDirLevel < 2 ) {
      t += createChildrenList( childItem );
    }

  }

  t += QLatin1String("</ul>\n");

  --mDirLevel;

  return t;
}
Exemplo n.º 6
0
void Navigator::insertIOSlaveDocs( const QString &name, NavigatorItem *topItem )
{
  kDebug(1400) << "Requested IOSlave documents for ID" << name;

  QStringList list = KProtocolInfo::protocols();
  list.sort();

  NavigatorItem *prevItem = 0;
  for ( QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it )
  {
    QString docPath = KProtocolInfo::docPath(*it);
    if ( !docPath.isNull() )
    {
      // First parameter is ignored if second is an absolute path
      KUrl url(KUrl("help:/"), docPath);
      QString icon = KProtocolInfo::icon(*it);
      if ( icon.isEmpty() ) icon = "text-plain";
      DocEntry *entry = new DocEntry( *it, url.url(), icon );
      NavigatorItem *item = new NavigatorItem( entry, topItem, prevItem );
      prevItem = item;
      item->setAutoDeleteDocEntry( true );
    }
  }
}
Exemplo n.º 7
0
void Navigator::selectItem( const KUrl &url )
{
  kDebug() << "Navigator::selectItem(): " << url.url();

  if ( url.url() == "khelpcenter:home" ) {
    clearSelection();
    return;
  }

  // help:/foo&anchor=bar gets redirected to help:/foo#bar
  // Make sure that we match both the original URL as well as
  // its counterpart.
  KUrl alternativeURL = url;
  if (url.hasRef())
  {
     alternativeURL.setQuery("anchor="+url.ref());
     alternativeURL.setRef(QString());
  }

  // If the navigator already has the given URL selected, do nothing.
  NavigatorItem *item;
  item = static_cast<NavigatorItem *>( mContentsTree->currentItem() );
  if ( item && mSelected ) {
    KUrl currentURL ( item->entry()->url() );
    if ( (currentURL == url) || (currentURL == alternativeURL) ) {
      kDebug() << "URL already shown.";
      return;
    }
  }

  // First, populate the NavigatorAppItems if we don't want the home page
  if ( url != homeURL() ) {
    QTreeWidgetItemIterator it1( mContentsTree );
    while( (*it1) ) 
    {
      NavigatorAppItem *appItem = dynamic_cast<NavigatorAppItem *>( (*it1) );
      if ( appItem ) appItem->populate( true );
      ++it1;
    }
  }
  
  QTreeWidgetItemIterator it( mContentsTree );
  while ( (*it) ) {
    NavigatorItem *item = static_cast<NavigatorItem *>( (*it) );
    KUrl itemUrl( item->entry()->url() );
    if ( (itemUrl == url) || (itemUrl == alternativeURL) ) {
      mContentsTree->setCurrentItem( item );
      // If the current item was not selected and remained unchanged it
      // needs to be explicitly selected
      mContentsTree->setCurrentItem(item);
      item->setExpanded( true );
      break;
    }
    ++it;
  }
  if ( !(*it) ) {
    clearSelection();
  } else {
    mSelected = true;
  }
}