OSDN Git Service

jump to anchor support.
[kita/kita.git] / src / kitathreadview.cpp
index 5299f55..260dba2 100644 (file)
@@ -1,6 +1,7 @@
 /***************************************************************************
  *   Copyright (C) 2003 by Hideki Ikemoto                                  *
  *   ikemo@wakaba.jp                                                       *
+ *   linuxÈÄ ¥³¥ó¥«¥é¤×¤é¤°¤¤¤ó¤Î¿Í                                        *
  *                                                                         *
  *   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  *
@@ -16,6 +17,7 @@
 #include "qcp932codec.h"
 #include <qsjiscodec.h>
 #include <qlabel.h>
+#include <qcombobox.h>
 
 #include <time.h>
 
@@ -30,6 +32,9 @@
 #include <kmessagebox.h>
 #include <krun.h>
 
+#include <dom/html_element.h>
+#include <dom/html_inline.h>
+
 #include "kitathreadview.h"
 #include "kitawritedialog.h"
 
@@ -68,6 +73,7 @@ KitaThreadView::KitaThreadView(QWidget *parent, const char *name)
   aLayout->addWidget(threadPart->view());
 
   connect(writeButton, SIGNAL(clicked()), SLOT(slotWriteButtonClicked()));
+  connect(threadPart, SIGNAL(nodeActivated(const DOM::Node &)), SLOT(slotDOMNodeActivated(const DOM::Node &)));
   connect(threadPart, SIGNAL(onURL(const QString&)), SLOT(slotOnURL(const QString&)));
   connect(threadPart->browserExtension(),
           SIGNAL(openURLRequest(const KURL&, const KParts::URLArgs&)),
@@ -76,6 +82,41 @@ KitaThreadView::KitaThreadView(QWidget *parent, const char *name)
 
 KitaThreadView::~KitaThreadView() {}
 
+void KitaThreadView::slotDOMNodeActivated(const DOM::Node &node)
+{
+  { //process Anchor tags.
+    DOM::HTMLAnchorElement anchor = node;
+
+    if ( ! anchor.href().isEmpty() )
+    {
+      KURL link;
+      QString boardName = m_datURL.path().section('/', 1, 1);
+      QString datnum = m_datURL.filename().section('.', 0, 0);
+      { // treat link as path.
+        link.setPath( anchor.href().string() );
+        if ( link.path().section('/', -5, -4) == "test/read.cgi"
+           && link.path().section('/', -3, -3) == boardName
+           && link.path().section('/', -2, -2) == datnum )
+        {
+          QString target;
+          bool ok;
+          link.filename().toInt( &ok );
+          if ( ok )
+            target = link.filename();
+          else if ( link.filename().contains('-') ) {
+            target = link.filename().section('-', 0, 0);
+            if( target.isEmpty() ) target = "1";
+          } else if ( link.filename().at(0) == 'l' )
+            target = QString().setNum( m_rescount - link.filename().remove('l').
+toInt() );
+          // do jump to target.
+          if ( ! target.isEmpty() ) threadPart->gotoAnchor( target );
+        }
+      } // end: tread link as path.
+    } // end: anchor.href().isEmpty()
+  } // end of Anchor tags.
+}
+
 void KitaThreadView::slotShowThread(const KURL& _datURL, const KURL& _boardURL, const QString& boardName)
 {
   KIO::SlaveConfig::self()->setConfigData("http", _datURL.host() ,
@@ -154,6 +195,9 @@ void KitaThreadView::slotThreadResult(KIO::Job* job)
       subjectLabel->setText(QString("[") + m_boardName + QString("] ") + subject);
     }
     text += "<dl><dt>";
+    text += "<a name=\"";
+    text += QString::number(num);
+    text += "\" />";
     text += QString::number(num);
     text += " ";
     if(address != "") {
@@ -169,6 +213,8 @@ void KitaThreadView::slotThreadResult(KIO::Job* job)
 
     num++;
   }
+  m_rescount = num - 1;
+  
   threadPart->begin(KURL(m_threadURL));
   threadPart->write(text);
   threadPart->end();