INCLUDES = $(all_includes) -I..
METASOURCES = AUTO
-noinst_HEADERS = writedialogbase.ui.h writetabwidget.h writeview.h \
- previewpart.h
+noinst_HEADERS =
lib_LTLIBRARIES = libkitawrite.la
libkitawrite_la_LDFLAGS = $(all_libraries)
-libkitawrite_la_SOURCES = writetabwidget.cpp writeview.cpp writedialogbase.ui \
- previewpart.cpp
+libkitawrite_la_SOURCES =
# this is where the XML-GUI resource file goes
rcdir = $(kde_datadir)/kita
-rc_DATA = writetabwidgetui.rc
+rc_DATA =
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2004 by Kita Developers *
- * ikemo@users.sourceforge.jp *
- * *
- * 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 "previewpart.h"
-
-#include <qcursor.h>
-
-#include <khtml_events.h>
-
-#include <dom/html_misc.h>
-
-#include "thread/respopup.h"
-#include "thread/htmlpart.h"
-
-#include "kitaui/htmlview.h"
-
-#include "libkita/kitaconfig.h"
-#include "libkita/datmanager.h"
-#include "libkita/kita_misc.h"
-#include "libkita/signalcollection.h"
-#include "libkita/config_xt.h"
-
-/*
- * Don't forget to call setup() later.
- */
-KitaPreviewPart::KitaPreviewPart( QWidget* parent, const char* name )
- : KHTMLPart( new KitaHTMLView( this, parent, name ) )
-{
- m_popup = NULL;
- m_datURL = QString::null;
-
- clearPart();
- createHTMLDocument();
- connectSignals();
-}
-
-KitaPreviewPart::~KitaPreviewPart()
-{
- clearPart();
-}
-
-void KitaPreviewPart::clearPart()
-{
- slotDeletePopup();
-
- if ( !m_datURL.isEmpty() ) {
- /* This part is opened. */
-
- /* don't forget to unlock previous datURL here. */
- Kita::DatManager::unlock( m_datURL );
- }
- m_datURL = QString::null;
-}
-
-bool KitaPreviewPart::setup( const KURL& url )
-{
- if ( url.isEmpty() ) return FALSE;
-
- clearPart();
-
- m_datURL = Kita::getDatURL( url );
-
- /* Lock datURL. Don't forget to unlock it later ! */
- Kita::DatManager::lock ( m_datURL );
-
- /* create HTML Document */
- createHTMLDocument();
-
- return TRUE;
-}
-
-void KitaPreviewPart::connectSignals()
-{
- Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
-
- /* rendering */
- connect( signalCollection, SIGNAL( threadFaceChanged() ), SLOT( slotSetFaceOfHTMLPart() ) );
- connect( signalCollection, SIGNAL( setStyleSheetOfHTMLPart() ), SLOT( slotSetStyleSheetOfHTMLPart() ) );
-
- /* popup */
- connect( this, SIGNAL( onURL( const QString& ) ), SLOT( slotOnURL( const QString& ) ) );
- connect( this, SIGNAL( isKitaActive() ), signalCollection, SIGNAL( isKitaActive() ) );
-
- connect( view(), SIGNAL( leave() ), SLOT( slotLeave() ) );
- connect( view(), SIGNAL( verticalSliderReleased() ), SLOT( slotVSliderReleased() ) );
- connect( view(), SIGNAL( horizontalSliderReleased() ), SLOT( slotHSliderReleased() ) );
-
- connect( signalCollection, SIGNAL( kitaIsActive() ), SLOT( slotKitaIsActive() ) );
- connect( signalCollection, SIGNAL( windowDeactivated() ), SLOT( slotHideChildPopup() ) );
-
- /* click */
- connect( this, SIGNAL( openURLRequestExt( const KURL&, const QString ) ),
- signalCollection, SIGNAL( openURLRequestExt( const KURL&, const QString ) ) );
-}
-
-void KitaPreviewPart::createHTMLDocument()
-{
- /* style */
- QString style = QString( "body { font-size: %1pt; font-family: \"%2\"; color: %3; background-color: %4; }" )
- .arg( Kita::Config::threadFont().pointSize() )
- .arg( Kita::Config::threadFont().family() )
- .arg( Kita::Config::threadColor().name() )
- .arg( Kita::Config::threadBackground().name() );
-
- QString text = "<html><head><style>";
- text += KitaConfig::defaultStyleSheetText();
- text += style;
- if ( Kita::Config::useStyleSheet() ) {
- text += KitaConfig::styleSheetText();
- }
- text += "</style></head><body></body></html>";
-
- setJScriptEnabled( false );
- setJavaEnabled( false );
-
- /* Use dummy URL here, and protocol should be "file:".
- If protocol is "http:", local image files are not shown
- (for security reasons ?).
- */
- begin( "file:/dummy.htm" );
- write( text );
- end();
-}
-
-void KitaPreviewPart::setInnerHTML( const QString& innerHTML )
-{
- createHTMLDocument();
- htmlDocument().body().setInnerHTML( innerHTML );
-}
-
-void KitaPreviewPart::slotSetFaceOfHTMLPart()
-{
- QFont font = Kita::Config::threadFont();
-
- DOM::CSSStyleDeclaration style = htmlDocument().body().style();
- style.setProperty( "font-family", font.family(), "" );
- style.setProperty( "font-size", QString( "%1pt" ).arg( font.pointSize() ), "" );
- style.setProperty( "color", Kita::Config::threadColor().name(), "" );
- style.setProperty( "background-color", Kita::Config::threadBackground().name(), "" );
-
- htmlDocument().applyChanges();
-}
-
-void KitaPreviewPart::slotSetStyleSheetOfHTMLPart()
-{
- /* [0]<html> -> [1]<head> -> [2]<style> */
- DOM::HTMLCollection collection = htmlDocument().all();
- DOM::HTMLElement element;
- unsigned int i;
- for ( i = 0 ; i < collection.length() ; i++ ) {
- element = collection.item( i );
- if ( element.tagName().upper() == "STYLE" ) {
- QString style = QString( "body { font-size: %1pt; font-family: %2; color: %3; background-color: %4; }" )
- .arg( Kita::Config::threadFont().pointSize() )
- .arg( Kita::Config::threadFont().family() )
- .arg( Kita::Config::threadColor().name() )
- .arg( Kita::Config::threadBackground().name() );
-
- QString style0 = KitaConfig::defaultStyleSheetText();
- style0 += style;
- if ( Kita::Config::useStyleSheet() ) {
- style0 += KitaConfig::styleSheetText();
- }
-
- element.setInnerText( style0 );
- htmlDocument().applyChanges();
- break;
- }
- }
-}
-
-/*
- * @Override
- */
-void KitaPreviewPart::customEvent( QCustomEvent * e )
-{
- if ( e->type() == EVENT_GotoAnchor ) {
- KHTMLPart::gotoAnchor( static_cast< GotoAnchorEvent* >( e ) ->getAnc() );
- return ;
- }
-
- KHTMLPart::customEvent( e );
-}
-
-/*
- * @Override
- */
-void KitaPreviewPart::khtmlMousePressEvent( khtml::MousePressEvent* e )
-{
- emit mousePressed(); /* to KitaThreadView to focus this view. */
-
- KURL kurl;
- if ( e->url().string() != QString::null ) {
- kurl = KURL( Kita::BoardManager::boardURL( m_datURL ), e->url().string() );
- }
-
- if ( e->qmouseEvent()->button() & Qt::RightButton ) {
- m_isPushedRightButton = TRUE;
- } else {
- m_isPushedRightButton = FALSE;
- }
-
- if ( e->url() != NULL ) {
-
- if ( e->url().string().at( 0 ) == '#' ) { /* anchor */
- kurl = m_datURL;
- kurl.setRef( e->url().string().mid( 1 ) ) ;
- }
-
- clickAnchor( kurl );
- m_isPushedRightButton = FALSE;
- return;
- }
-
- KHTMLPart::khtmlMousePressEvent( e );
-}
-
-/*
- * This function is called when user clicked res anchor
- */
-void KitaPreviewPart::clickAnchor( const KURL& urlin )
-{
- QString refstr;
- KURL datURL = Kita::getDatURL( urlin, refstr );
-
- /*--------------------------------*/
- /* If this is not anchor, then */
- /* emit openURLRequest and return */
- if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) {
- emit openURLRequestExt( urlin );
- return ;
- }
-
- if ( refstr == QString::null ) return ;
-
- /*-------------------------*/
- /* start multi-popup mdde */
- if ( m_isPushedRightButton && startMultiPopup() ) return ;
-
- int refNum, refNum2;
-
- int i = refstr.find( "-" );
- if ( i != -1 ) {
- refNum = refstr.left( i ).toInt();
- refNum2 = refstr.mid( i + 1 ).toInt();
- if ( refNum2 < refNum ) {
- refNum2 = refNum;
- }
- } else {
- refNum = refNum2 = refstr.toInt();
- }
-
- if ( !refNum ) return ;
-
- emit openURLRequestExt( urlin );
-}
-
-void KitaPreviewPart::slotDeletePopup()
-{
- if ( m_popup ) delete m_popup;
- m_popup = NULL;
- m_multiPopup = FALSE;
-}
-
-/*
- * for convenience
- */
-void KitaPreviewPart::showPopup( const KURL& url, const QString& innerHTML )
-{
- slotDeletePopup();
- m_multiPopup = FALSE;
-
- m_popup = new Kita::ResPopup( view() , url );
-
- connect( m_popup, SIGNAL( hideChildPopup() ), SLOT( slotHideChildPopup() ) );
-
- m_popup->setText( innerHTML );
- m_popup->adjustSize();
- m_popup->adjustPos( QCursor::pos() );
- m_popup->show();
-}
-
-/*
- * start multi-popup mode
- */
-bool KitaPreviewPart::startMultiPopup()
-{
- if ( m_popup && m_popup->isVisible() ) {
- m_multiPopup = TRUE;
- m_popup->moveMouseAbove();
- } else {
- m_multiPopup = FALSE;
- }
-
- return m_multiPopup;
-}
-
-/*
- * Is it multi-popup mode now ?
- */
-bool KitaPreviewPart::isMultiPopupMode()
-{
- if ( !m_popup ) {
- m_multiPopup = FALSE;
- } else if ( m_popup->isHidden() ) {
- m_multiPopup = FALSE;
- }
-
- return m_multiPopup;
-}
-
-void KitaPreviewPart::hidePopup()
-{
- if ( m_popup ) {
- m_popup->hide();
- }
-
- m_multiPopup = FALSE;
-}
-
-void KitaPreviewPart::slotLeave()
-{
- if ( isMultiPopupMode() ) return ;
- if ( view()->isHorizontalSliderPressed() ) return ;
- if ( view()->isVerticalSliderPressed () ) return ;
-
- hidePopup();
-}
-
-void KitaPreviewPart::slotVSliderReleased()
-{
- QScrollBar* bar = view()->verticalScrollBar();
- QRect rt = bar->sliderRect();
-
- hidePopup();
-}
-
-void KitaPreviewPart::slotHSliderReleased()
-{
- QScrollBar* bar = view()->horizontalScrollBar();
- QRect rt = bar->sliderRect();
-
- hidePopup();
-}
-
-void KitaPreviewPart::slotHideChildPopup()
-{
- hidePopup();
-}
-
-/*
- * called back when kita is active.
- * see also an explanation in slotOnURL.
- */
-void KitaPreviewPart::slotKitaIsActive()
-{
- m_kitaIsActive = TRUE;
-}
-
-/*
- * This slot is called when mouse moves onto the URL
- */
-void KitaPreviewPart::slotOnURL( const QString& url )
-{
- const int maxpopup = 10; /* max number of responses shown in the popup window */
-
- if ( isMultiPopupMode() ) return ;
-
- slotDeletePopup();
-
- if ( url.isEmpty() ) return ;
- if ( url.left( 7 ) == "mailto:" ) return ;
-
- /* Is Kita active now ?
-
- emit SIGNAL( isKitaActive() ) to KitaMainWindow, KitaNavi, etc. ,
- and if one of them is active, then slotKitaIsActive() is called
- back, and m_kitaIsActive is set to TRUE. */
- m_kitaIsActive = FALSE;
- emit isKitaActive();
- if ( !m_kitaIsActive ) return ;
-
- /* get reference */
- QString refstr;
- KURL datURL = m_datURL;
- if ( url.at( 0 ) == '#' ) {
- refstr = url.mid( 1 );
- } else {
- datURL = Kita::getDatURL( KURL( m_datURL, url ), refstr );
- }
-
- /*-------------------------*/
- /* popup for anchor */
-
- QString innerHTML = QString::null;
- int refNum;
- int refNum2;
-
- int i = refstr.find( "-" );
- if ( i != -1 ) { /* >>refNum-refNum2 */
-
- refNum = refstr.left( i ).toInt();
- refNum2 = refstr.mid( i + 1 ).toInt();
-
- if ( refNum ) {
- if ( refNum2 < refNum ) refNum2 = refNum;
- if ( refNum2 - refNum > maxpopup - 1 ) refNum2 = refNum + maxpopup - 1;
- }
-
- } else { /* >>refNum */
- refNum = refstr.toInt();
- refNum2 = refNum;
- }
-
- /* another thread ? */
- if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) {
-
- /* get board name */
- QString boardName = Kita::BoardManager::boardName( datURL );
- if ( boardName != QString::null ) {
- innerHTML += "[" + boardName + "] ";
- }
-
- /* If idx file of datURL is not read, thread name cannot be obtained.
- so, create DatInfo if cache exists, and read idx file in DatInfo::DatInfo(). */
- Kita::DatManager::getDatInfoPointer( datURL );
-
- /* get thread Name */
- QString subName = Kita::DatManager::threadName( datURL );
- if ( subName != QString::null ) {
- innerHTML += subName + "<br><br>";
- }
-
- if ( !refNum ) refNum = refNum2 = 1;
- }
-
- /* get HTML and show it */
- if ( !refNum ) return ;
-
- innerHTML += Kita::DatManager::getHtml( datURL, refNum, refNum2 );
- if ( innerHTML != QString::null ) {
- showPopup( datURL, innerHTML );
- }
-}
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2004 by Kita Developers *
- * ikemo@users.sourceforge.jp *
- * *
- * 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. *
- ***************************************************************************/
-
-#ifndef PREVIEWPART_H
-#define PREVIEWPART_H
-
-#include <khtml_part.h>
-
-/* ID of user defined event */
-#define EVENT_GotoAnchor ( QEvent::User + 100 )
-
-namespace Kita
-{
- class ResPopup;
-}
-
-class KitaPreviewPart : public KHTMLPart
-{
- Q_OBJECT
-
- Kita::ResPopup* m_popup;
-
- /* basic information */
- KURL m_datURL;
-
- /* mouse event */
- bool m_isPushedRightButton;
-
- /* res popup */
- bool m_multiPopup;
- bool m_kitaIsActive;
-
-public:
-
- KitaPreviewPart( QWidget* parent, const char* name = 0 );
- ~KitaPreviewPart();
- bool setup( const KURL& url );
-
- /* rendering */
- void setInnerHTML( const QString& innerHTML );
-
-public slots:
-
- /* rendering */
- void slotSetFaceOfHTMLPart();
- void slotSetStyleSheetOfHTMLPart();
-
- /* res popup */
- void slotDeletePopup();
-
-private:
-
- void clearPart();
-
- /* setup */
- void connectSignals();
- void createHTMLDocument();
-
- /* click */
- void clickAnchor( const KURL& urlin );
-
- /* res popup */
- void showPopup( const KURL& url, const QString& innerHTML );
- bool startMultiPopup();
- bool isMultiPopupMode();
- void hidePopup();
-
-protected:
-
- /* user event */
- virtual void customEvent( QCustomEvent * e );
-
- /* mouse event */
- virtual void khtmlMousePressEvent( khtml::MousePressEvent* e );
-
-private slots:
-
- /* res popup */
- void slotLeave();
- void slotVSliderReleased();
- void slotHSliderReleased();
- void slotHideChildPopup();
- void slotKitaIsActive();
- void slotOnURL( const QString& url );
-
-signals:
-
- void openURLRequestExt( const KURL& url, const QString mimetype = QString::null );
- void mousePressed(); /* to KitaThreadView */
-
- /* res popup */
- void isKitaActive();
-};
-
-#endif
+++ /dev/null
-<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
-<class>KitaWriteDialogBase</class>
-<widget class="QWidget">
- <property name="name">
- <cstring>KitaWriteDialogBase</cstring>
- </property>
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>534</width>
- <height>380</height>
- </rect>
- </property>
- <property name="caption">
- <string>Write in thread</string>
- </property>
- <vbox>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="QLayoutWidget">
- <property name="name">
- <cstring>layout4</cstring>
- </property>
- <hbox>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="QLabel">
- <property name="name">
- <cstring>textLabel1</cstring>
- </property>
- <property name="sizePolicy">
- <sizepolicy>
- <hsizetype>5</hsizetype>
- <vsizetype>5</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Board:</string>
- </property>
- </widget>
- <widget class="KSqueezedTextLabel">
- <property name="name">
- <cstring>boardNameLabel</cstring>
- </property>
- <property name="sizePolicy">
- <sizepolicy>
- <hsizetype>7</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>board name</string>
- </property>
- </widget>
- <widget class="QLabel">
- <property name="name">
- <cstring>textLabel1_2</cstring>
- </property>
- <property name="text">
- <string>Thread:</string>
- </property>
- </widget>
- <widget class="KLineEdit">
- <property name="name">
- <cstring>threadNameLine</cstring>
- </property>
- <property name="sizePolicy">
- <sizepolicy>
- <hsizetype>7</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>3</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </hbox>
- </widget>
- <widget class="QLayoutWidget">
- <property name="name">
- <cstring>layout4</cstring>
- </property>
- <hbox>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="QLabel">
- <property name="name">
- <cstring>nameLabel</cstring>
- </property>
- <property name="text">
- <string>name</string>
- </property>
- </widget>
- <widget class="KLineEdit">
- <property name="name">
- <cstring>nameLine</cstring>
- </property>
- </widget>
- <widget class="QLabel">
- <property name="name">
- <cstring>mailLabel</cstring>
- </property>
- <property name="text">
- <string>mail</string>
- </property>
- </widget>
- <widget class="KLineEdit">
- <property name="name">
- <cstring>mailLine</cstring>
- </property>
- </widget>
- <widget class="QCheckBox">
- <property name="name">
- <cstring>sageBox</cstring>
- </property>
- <property name="text">
- <string>&sage</string>
- </property>
- <property name="accel">
- <string>Alt+S</string>
- </property>
- </widget>
- <widget class="QCheckBox">
- <property name="name">
- <cstring>beBox</cstring>
- </property>
- <property name="text">
- <string>&be</string>
- </property>
- <property name="accel">
- <string>Alt+B</string>
- </property>
- </widget>
- </hbox>
- </widget>
- <widget class="QTabWidget">
- <property name="name">
- <cstring>qtw</cstring>
- </property>
- <widget class="QTextEdit">
- <property name="name">
- <cstring>bodyText</cstring>
- </property>
- <attribute name="title">
- <string>body</string>
- </attribute>
- </widget>
- </widget>
- <widget class="QLayoutWidget">
- <property name="name">
- <cstring>layout4</cstring>
- </property>
- <hbox>
- <property name="name">
- <cstring>unnamed</cstring>
- </property>
- <widget class="QComboBox">
- <property name="name">
- <cstring>faceCombo</cstring>
- </property>
- </widget>
- <spacer>
- <property name="name">
- <cstring>Horizontal Spacing2</cstring>
- </property>
- <property name="orientation">
- <enum>Horizontal</enum>
- </property>
- <property name="sizeType">
- <enum>Expanding</enum>
- </property>
- <property name="sizeHint">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget class="QLabel">
- <property name="name">
- <cstring>lengthLabel</cstring>
- </property>
- <property name="text">
- <string>XX/XX | XXXX/XXXX</string>
- </property>
- </widget>
- <widget class="QPushButton">
- <property name="name">
- <cstring>buttonOk</cstring>
- </property>
- <property name="text">
- <string>&OK</string>
- </property>
- <property name="accel">
- <string></string>
- </property>
- <property name="autoDefault">
- <bool>true</bool>
- </property>
- <property name="default">
- <bool>true</bool>
- </property>
- </widget>
- <widget class="QPushButton">
- <property name="name">
- <cstring>buttonCancel</cstring>
- </property>
- <property name="text">
- <string>&Cancel</string>
- </property>
- <property name="accel">
- <string></string>
- </property>
- <property name="autoDefault">
- <bool>true</bool>
- </property>
- </widget>
- </hbox>
- </widget>
- </vbox>
-</widget>
-<connections>
- <connection>
- <sender>sageBox</sender>
- <signal>toggled(bool)</signal>
- <receiver>KitaWriteDialogBase</receiver>
- <slot>sageBoxToggled(bool)</slot>
- </connection>
-</connections>
-<includes>
- <include location="local" impldecl="in implementation">writedialogbase.ui.h</include>
-</includes>
-<variables>
- <variable>QString m_mailswap;</variable>
-</variables>
-<slots>
- <slot access="protected">sageBoxToggled( bool on )</slot>
-</slots>
-<functions>
- <function access="protected" specifier="non virtual" returnType="const QString">name() const</function>
- <function access="protected" specifier="non virtual" returnType="const QString">mail() const</function>
- <function specifier="non virtual" returnType="const QString">body() const</function>
-</functions>
-<layoutdefaults spacing="6" margin="11"/>
-<includehints>
- <includehint>ksqueezedtextlabel.h</includehint>
- <includehint>klineedit.h</includehint>
- <includehint>klineedit.h</includehint>
- <includehint>klineedit.h</includehint>
-</includehints>
-</UI>
+++ /dev/null
-/****************************************************************************
-** ui.h extension file, included from the uic-generated form implementation.
-**
-** If you wish to add, delete or rename functions or slots use
-** Qt Designer which will update this file, preserving your code. Create an
-** init() function in place of a constructor, and a destroy() function in
-** place of a destructor.
-*****************************************************************************/
-
-
-void KitaWriteDialogBase::sageBoxToggled( bool on )
-{
- if ( on ) {
- m_mailswap = mailLine->text();
- mailLine->setText( "sage" );
- mailLine->setReadOnly( true );
- } else {
- mailLine->setReadOnly( false );
- mailLine->setText( m_mailswap );
- }
-}
-
-const QString KitaWriteDialogBase::name() const
-{
- return nameLine->text();
-}
-
-const QString KitaWriteDialogBase::mail() const
-{
- return mailLine->text();
-}
-
-const QString KitaWriteDialogBase::body() const
-{
- return bodyText->text();
-}
+++ /dev/null
-/***************************************************************************
-* Copyright (C) 2004 by Kita Developers *
-* ikemo@users.sourceforge.jp *
-* *
-* 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 "libkita/kita_misc.h"
-#include "libkita/signalcollection.h"
-#include "libkita/datmanager.h"
-#include "libkita/boardmanager.h"
-#include "writetabwidget.h"
-#include "writeview.h"
-
-#include <kdebug.h>
-#include <kstdaccel.h>
-#include <kaction.h>
-#include <klocale.h>
-#include <kpopupmenu.h>
-#include <kapplication.h>
-
-#include <qmessagebox.h>
-#include <qclipboard.h>
-
-/*--------------------------------------------------------------------------------*/
-
-
-KitaWriteTabWidget::KitaWriteTabWidget( QWidget* parent, const char* name, WFlags f )
- : KitaTabWidgetBase( parent, name, f )
-{
- setXMLFile( "writetabwidgetui.rc" );
-
- connectSignals();
- setupActions();
-}
-
-
-KitaWriteTabWidget::~KitaWriteTabWidget() {}
-
-
-/* public slot */
-void KitaWriteTabWidget::slotShowWriteView( const KURL& url,
- const QString& resStr )
-{
- openWriteView( WRITEMODE_NORMAL, url, resStr, QString::null );
-}
-
-
-/* private */
-void KitaWriteTabWidget::openWriteView( int mode, const KURL& url,
- const QString& resStr, const QString& subject )
-{
- // TODO: machiBBS kakiko support.
- if ( Kita::BoardManager::type( url ) == Kita::Board_MachiBBS ) {
-// QMessageBox::warning( this, QString( "<(_ _)>" ),
-// i18n( "Can't write to machi BBS in this version." ) );
-// return ;
- }
-
- /* view exists */
- KitaWriteView* view = findWriteView( url );
- if ( view ) {
-
- if ( view->body().length() ) {
-
- if ( QMessageBox::warning( this, "Kita",
- i18n( "Do you want to clear the text?" ),
- QMessageBox::Ok,
- QMessageBox::Cancel | QMessageBox::Default ) == QMessageBox::Cancel ) return ;
- }
-
- /* clear */
- view->setMessage( resStr );
- setCurrentPage( indexOf( view ) );
- return ;
- }
-
- // TODO: refactoring.
- /* create new write view & add it to tab */
- QString threadName;
-
- /* write res */
- KitaWriteView* new_dlg;
- threadName = Kita::DatManager::threadName( url );
- new_dlg = new KitaWriteView( this, url );
- new_dlg->setMessage( resStr );
- connect( new_dlg, SIGNAL( closeCurrentTab() ), SLOT( slotCloseCurrentTab() ) );
- addTab( new_dlg, threadName );
- showPage( new_dlg );
-}
-
-
-/* close view which URL is url. */ /* public slot */
-void KitaWriteTabWidget::slotCloseWriteTab( const KURL& url )
-{
- KitaWriteView * view = findWriteView( url );
- if ( view ) slotCloseTab( indexOf( view ) );
-}
-
-
-/* private */
-void KitaWriteTabWidget::connectSignals()
-{
- Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
-
- connect( signalCollection, SIGNAL( activateThreadView( const KURL& ) ),
- this, SLOT( slotChangeWriteTab( const KURL& ) ) );
- connect( signalCollection, SIGNAL( closeWriteTab( const KURL& ) ),
- SLOT( slotCloseWriteTab( const KURL& ) ) );
-}
-
-
-/* private */
-KitaWriteView* KitaWriteTabWidget::findWriteView( const KURL& url )
-{
- KURL datURL = Kita::getDatURL( url );
- if ( datURL.isEmpty() ) return NULL;
-
- int max = count();
- if ( max == 0 ) return NULL;
- int i = 0;
-
- while ( i < max ) {
- KitaWriteView * view = isWriteView( page ( i ) );
- if ( view ) {
- if ( view->datURL() == datURL ) return view;
- }
- i++;
- }
-
- return NULL;
-}
-
-
-/* private */
-KitaWriteView* KitaWriteTabWidget::isWriteView( QWidget* w )
-{
- KitaWriteView * view = NULL;
- if ( w ) {
- if ( w->isA( "KitaWriteView" ) ) view = static_cast< KitaWriteView* >( w );
- }
-
- return view;
-}
-
-
-
-/* when thread view is focused, this slot is called */
-/* See also KitaThreadView::setFocus. */ /* private slot */
-void KitaWriteTabWidget::slotChangeWriteTab( const KURL& url )
-{
- KitaWriteView * view;
- int max = count();
- if ( max == 0 ) return ;
-
- /* disable all ok buttons. */
- int i = 0;
- while ( i < max ) {
- view = isWriteView( page( i ) );
- if ( view ) view->slotEnableWriting( FALSE );
- i++;
- }
-
- /* show current url page. */
- view = findWriteView( url );
- if ( view ) {
- static_cast< KitaDockWidgetBase* >( parentWidget() ) ->slotShowDock( FALSE, FALSE );
- if ( currentPage() != view ) setCurrentPage( indexOf( view ) );
- view->slotEnableWriting( TRUE );
- }
-}
-
-
-/* protected */ /* virtual */
-void KitaWriteTabWidget::deleteWidget( QWidget* w )
-{
- KitaWriteView * view = isWriteView( w );
-
- if ( view == NULL ) return ;
-
- if ( view->body().length() ) {
- if ( QMessageBox::warning( this, "Kita",
- i18n( "If you close this dialog, you will lose text.\n"
- "Do you want to close?" ),
- QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
- == QMessageBox::Cancel ) return ;
- }
-
- KitaTabWidgetBase::deleteWidget( w );
-
- if ( count() == 0 ) {
- static_cast< KitaDockWidgetBase* >( parentWidget() ) ->slotHideDock();
- }
-}
-
-
-/*--------------------------------*/
-/* KitaWriteTabWidget actions */
-
-
-/* private */
-void KitaWriteTabWidget::setupActions()
-{
- new KAction( i18n( "quote clipboard" ),
- Key_F2,
- this,
- SLOT( slotQuoteClipboard() ),
- actionCollection(),
- "writeview_quoteclip" );
-}
-
-
-/* public slot */
-void KitaWriteTabWidget::slotQuoteClipboard()
-{
- KitaWriteView * view = isWriteView( currentPage() );
- if ( view ) {
- QClipboard * clipboard = QApplication::clipboard();
- QString str = clipboard->text( QClipboard::Selection );
- if ( str == QString::null ) str = clipboard->text( QClipboard::Clipboard );
- if ( str != QString::null ) {
-
- QString msg = "\n> " + str.replace( "\n", "\n> " ) + "\n";
- view->insertMessage( msg );
- }
- }
-}
-
-/*---------------------------------------------------------------------*/
-/*---------------------------------------------------------------------*/
-/*---------------------------------------------------------------------*/
-
-
-/* Don't forget to call setup later ! */
-KitaWriteDock::KitaWriteDock( KDockManager* dockManager,
- const char* name,
- const QPixmap &pixmap,
- QWidget* parent,
- const QString& strCaption,
- const QString& strTabPageLabel,
- WFlags f )
- : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ), m_writeTab( 0 ) {}
-
-
-KitaWriteDock::~KitaWriteDock() {}
-
-
-void KitaWriteDock::setup()
-{
- Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
- connect( signalCollection, SIGNAL( showWriteView( const KURL& , const QString& ) ),
- this, SLOT( slotShowWriteView( const KURL& , const QString& ) ) );
- connect( signalCollection, SIGNAL( switchToWritedock() ),
- this, SLOT( slotShowDock() ) );
-}
-
-
-void KitaWriteDock::slotShowWriteView( const KURL& url, const QString& resStr )
-{
- if ( !m_writeTab ) return ;
-
- slotShowDock();
- m_writeTab->slotShowWriteView( url, resStr );
-}
+++ /dev/null
-/***************************************************************************
-* Copyright (C) 2003 by Hideki Ikemoto, 2004 by 421 *
-* ikemo@users.sourceforge.jp *
-* *
-* 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. *
-***************************************************************************/
-
-#ifndef KITAWRITETABWIDGET_H
-#define KITAWRITETABWIDGET_H
-
-#include "kitaui/tabwidgetbase.h"
-
-class KitaWriteView;
-
-/*-----------------------------------------------*/
-
-
-class KitaWriteTabWidget : public KitaTabWidgetBase
-{
- Q_OBJECT
-
-public:
- KitaWriteTabWidget( QWidget* parent = 0, const char* name = 0, WFlags f = 0 );
- ~KitaWriteTabWidget();
-
-public slots:
- void slotShowWriteView( const KURL& url, const QString& resStr );
- void slotCloseWriteTab( const KURL& url );
-
-private:
- void openWriteView( int mode, const KURL& url, const QString& resStr = QString::null, const QString& subject = QString::null );
- void connectSignals();
- KitaWriteView* findWriteView( const KURL& url );
- KitaWriteView* isWriteView( QWidget* w );
-
-private slots:
- void slotChangeWriteTab( const KURL& url );
-
-protected:
- virtual void deleteWidget( QWidget* w );
-
-
- /*------------------------------------*/
- /* KitaWriteTabWidget actions */
-
-private:
- void setupActions();
-
-public slots:
- void slotQuoteClipboard();
-};
-
-
-/*--------------------------------------------------*/
-
-class KitaWriteDock : public KitaDockWidgetBase
-{
-
- Q_OBJECT
- KitaWriteTabWidget* m_writeTab;
-
-public:
- KitaWriteDock( KDockManager* dockManager,
- const char* name,
- const QPixmap &pixmap,
- QWidget* parent = 0L,
- const QString& strCaption = QString::null,
- const QString& strTabPageLabel = QString::fromLatin1( " " ),
- WFlags f = 0 );
- ~KitaWriteDock();
-
- void setup();
- void setWriteTabWidget( KitaWriteTabWidget* w ) { m_writeTab = w; }
-
-public slots:
- void slotShowWriteView( const KURL& url, const QString& resStr );
-};
-
-
-
-#endif
+++ /dev/null
-<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="kitaWriteTabWidget" version="1">
-</kpartgui>
+++ /dev/null
-/***************************************************************************
-* Copyright (C) 2004 by Kita Developers *
-* ikemo@users.sourceforge.jp *
-* *
-* 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 "writeview.h"
-
-#include "previewpart.h"
-
-#include "libkita/qcp932codec.h"
-#include "libkita/kitaconfig.h"
-#include "libkita/datmanager.h"
-#include "libkita/boardmanager.h"
-#include "libkita/signalcollection.h"
-#include "libkita/account.h"
-#include "libkita/kita-utf8.h"
-#include "libkita/kita_misc.h"
-#include "libkita/config_xt.h"
-#include "libkita/asciiart.h"
-#include "libkita/k2ch.h"
-#include "libkita/machibbs.h"
-#include "libkita/jbbs.h"
-#include "libkita/flashcgi.h"
-
-#include "thread/htmlpart.h"
-
-#include "kitaui/htmlview.h"
-
-#include <ksqueezedtextlabel.h>
-#include <klocale.h>
-#include <kdebug.h>
-#include <kstandarddirs.h>
-#include <klineedit.h>
-#include <kmessagebox.h>
-#include <kio/job.h>
-
-#include <qapplication.h>
-#include <qtextedit.h>
-#include <qpushbutton.h>
-#include <qlabel.h>
-#include <qcombobox.h>
-#include <qeucjpcodec.h>
-#include <qfile.h>
-#include <qmessagebox.h>
-#include <ktabwidget.h>
-#include <qcheckbox.h>
-#include <qlayout.h>
-
-
-
-/*--------------------------------------------------------------------*/
-
-QCp932Codec* KitaWriteView::m_cp932Codec = NULL;
-
-
-KitaWriteView::KitaWriteView( QWidget* parent )
- : KitaWriteDialogBase( parent )
-{
-}
-/*
-
-Call setMessage() to set message later.
-See also KitaWriteTabWidget::slotShowWriteView().
-
-Call slotPostMessage() to post the message.
-
-*/
-KitaWriteView::KitaWriteView( QWidget* parent, const KURL& url )
- : KitaWriteDialogBase( parent, 0 )
-{
- if ( !m_cp932Codec ) m_cp932Codec = new QCp932Codec();
-
- m_datURL = Kita::getDatURL( url );
-
- m_bbstype = Kita::BoardManager::type( m_datURL );
-
- m_bbscgi = Kita::getWriteURL( m_datURL );
-
- initUI();
- initThreadNameField();
-}
-
-void KitaWriteView::initUI()
-{
- Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
- /* connect signals */
- connect( buttonOk, SIGNAL( clicked() ),
- SLOT( slotPostMessage() ) );
-
- connect( buttonCancel, SIGNAL( clicked() ),
- SLOT( slotCancel() ) );
-
- connect( this, SIGNAL( openURLRequestExt( const KURL&, const QString ) ),
- signalCollection, SIGNAL( openURLRequestExt( const KURL&, const QString ) ) );
- connect( this, SIGNAL( openThread( const KURL& ) ), signalCollection, SIGNAL( openThread( const KURL& ) ) );
-
- connect( faceCombo, SIGNAL( activated( const QString& ) ),
- bodyText, SLOT( insert( const QString& ) ) );
-
- connect( qtw, SIGNAL( currentChanged ( QWidget * ) ),
- this, SLOT( slotCurrentChanged ( QWidget * ) ) );
-
- connect( bodyText, SIGNAL( textChanged() ),
- SLOT( slotBodyTextChanged() ) );
-
- /* setup preview view */
- m_preview = new KitaPreviewPart( NULL );
- qtw->addTab( m_preview->view(), i18n( "preview" ) );
- m_preview->setup( m_datURL );
- qtw->setCurrentPage( 0 );
-
- /* setup labels and edit lines */
- QFont font = Kita::Config::threadFont();
- bodyText->setFont( font );
- bodyText->setTabChangesFocus( TRUE );
-
- boardNameLabel->setText( Kita::BoardManager::boardName( m_datURL ) );
-
- if ( Kita::Config::defaultNameUseAlways() ) {
- nameLine->setText( Kita::Config::defaultName() );
- } else {
- QString defaultName = Kita::BoardManager::getBBSDefaultName( m_datURL );
- if ( defaultName == "fusianasan" || defaultName == "(default name)" ) {
- nameLine->setText( Kita::Config::defaultName() );
- } else {
- nameLine->setText( defaultName );
- }
- }
- QStringList compList = Kita::Config::self()->nameCompletionList();
- nameLine->completionObject()->setItems( compList );
-
- if ( Kita::Config::defaultSage() ) {
- mailLine->setText( "sage" );
- sageBox->setChecked( true );
- } else {
- mailLine->setText( Kita::Config::defaultMail() );
- }
- m_mailswap = "";
-
- QRegExp host_2ch( ".+\\.2ch\\.net" );
- if ( host_2ch.search( m_bbscgi.host() ) != -1
- && Kita::Config::beMailAddress().length() > 0
- && Kita::Config::beAuthCode().length() > 0 ) {
- beBox->setChecked( true );
- }
-
- /* setup AA */
- faceCombo->clear();
- faceCombo->setFont( Kita::Config::threadFont() );
- faceCombo->insertItem( "" );
- QStringList list = Kita::AsciiArtConfig::asciiArtList();
- QStringList::iterator it;
- for ( it = list.begin(); it != list.end(); ++it ) {
- faceCombo->insertItem( *it );
- }
-}
-
-void KitaWriteView::initThreadNameField()
-{
- threadNameLine->setText( Kita::DatManager::threadName( m_datURL ) );
- threadNameLine->setReadOnly( TRUE );
- threadNameLine->setFrame( FALSE );
- threadNameLine->setFocusPolicy( NoFocus );
-}
-
-KitaWriteView::~KitaWriteView()
-{
- if ( m_preview ) {
- delete m_preview;
- }
-}
-
-
-/* public */
-void KitaWriteView::setMessage( const QString& bodyStr )
-{
- bodyText->clear();
- bodyText->insert( bodyStr );
- bodyText->setFocus();
-}
-
-
-/* public */
-void KitaWriteView::insertMessage( const QString& str )
-{
- bodyText->insert( str );
- bodyText->setFocus();
-}
-
-
-/* public information */
-const KURL KitaWriteView::datURL() const
-{
- return m_datURL;
-}
-
-const QString KitaWriteView::threadName() const
-{
- return threadNameLine->text();
-}
-
-const QString KitaWriteView::boardID() const
-{
- return Kita::BoardManager::boardID( m_datURL );
-}
-
-const QString KitaWriteView::boardName() const
-{
- return Kita::BoardManager::boardName( m_datURL );
-}
-/* public slot */ /* virtual */
-void KitaWriteView::setFocus()
-{
- bodyText->setFocus();
-}
-
-bool KitaWriteView::checkFields()
-{
- if ( body().length() == 0 ) return false;
-
- /* fusianasan */
- if ( name().length() == 0
- && Kita::BoardManager::getBBSDefaultName( m_datURL ) == "fusianasan" ) {
- QMessageBox::warning( this, "Kita", i18n( "fusianasan." ) );
- return false;
- }
-
- if ( !slotBodyTextChanged() ) {
- QMessageBox::warning( this, "Kita", i18n( "Body text is too long." ) );
- return false;
- }
-
- return true;
-}
-
-QString KitaWriteView::buildPostMessage()
-{
- QString postStr;
- switch ( m_bbstype ) {
-
- case Kita::Board_JBBS: postStr = getJBBSPostStr(); break;
-
- case Kita::Board_FlashCGI: postStr = getFlashCGIPostStr(); break;
-
- case Kita::Board_MachiBBS: postStr = getMachiBBSPostStr(); break;
-
- default: postStr = getPostStr(); break;
- }
-
- return postStr;
-}
-
-/* call this slot to post the message. */ /* public slot */
-void KitaWriteView::slotPostMessage()
-{
- if ( !checkFields() ) return;
-
- QString name = nameLine->text();
- QStringList list = Kita::Config::nameCompletionList();
- list.append( name );
- Kita::Config::setNameCompletionList( list );
-
- /* build post message */
- QString postStr = buildPostMessage();
-
- /* referrer */
- QString refStr = Kita::BoardManager::boardURL( m_datURL );
-
- m_array.resize( 0 );
-
- KIO::TransferJob* job = KIO::http_post( m_bbscgi, postStr.utf8(), true );
- job->addMetaData( "content-type", "Content-type: application/x-www-form-urlencoded" );
- job->addMetaData( "referrer", refStr );
-
- /* 2ch.net cookie modify */
- if ( m_bbstype == Kita::Board_2ch && beBox->isChecked() ) {
- QString cookie = "Cookie: ";
- QString BeMailAddress = Kita::Config::beMailAddress();
- QString BeAuthCode = Kita::Config::beAuthCode();
- if ( BeMailAddress.length() > 0 && BeAuthCode.length() > 0 ) {
- cookie += "DMDM=" + BeMailAddress + "; ";
- cookie += "MDMD=" + BeAuthCode + "; ";
- }
- job->addMetaData( "customHTTPHeader", cookie );
- }
-
- connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
- this, SLOT( slotRecieveData( KIO::Job*, const QByteArray& ) ) );
-
- /* slotPostFinished() is called when done. */
- connect( job, SIGNAL( result( KIO::Job* ) ),
- this, SLOT( slotPostFinished( KIO::Job* ) ) );
-
-}
-
-
-/* public slot */
-void KitaWriteView::slotCancel()
-{
- if ( body().length() == 0 ) {
- emit closeCurrentTab(); /* to KitaWriteTabWidget */
- return ;
- }
-
- switch ( QMessageBox::warning( this, "Kita",
- i18n( "If you close this dialog, you will lose text.\n"
- "Do you want to close?" ),
- QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default ) ) {
- case QMessageBox::Ok:
- setMessage( QString::null );
- emit closeCurrentTab(); /* to KitaWriteTabWidget */
- break;
- case QMessageBox::Cancel:
- // do nothing
- break;
- }
-}
-
-
-/* public slot */
-void KitaWriteView::slotEnableWriting( bool enable )
-{
- buttonOk->setEnabled( enable );
-}
-
-
-/* see also slotPostMessage() */ /* private slot */
-void KitaWriteView::slotRecieveData( KIO::Job*, const QByteArray& data )
-{
- m_array.append( data.data() );
-}
-
-void KitaWriteView::processPostFinished()
-{
- QString response;
- QString ckstr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITECOOKIE );
-
- // x-euc-jp & euc-jp
- if ( m_array.contains( "euc-jp" ) ) {
- response = QTextCodec::codecForName( "eucJP" ) ->toUnicode( m_array );
- } else {
- response = QTextCodec::codecForName( "sjis" ) ->toUnicode( m_array );
- }
-
- int retcode = resultCode( response );
- switch ( retcode ) {
-
- case K2ch_True:
-
- /* save log */
- logPostMessage();
-
- /* clear message */
- setMessage( QString::null );
-
- /* reload thread */
- emit openThread( m_datURL );
-
- emit closeCurrentTab(); /* to KitaWriteTabWidget */
-
- break;
-
- case K2ch_Unknown:
- case K2ch_False:
- case K2ch_Check:
- case K2ch_Error:
-
- KMessageBox::error( 0, resultMessage( response ), resultTitle( response ) );
-
- break;
-
- /* eat cookie, then re-post message */
- case K2ch_Cookie:
-
- if ( KMessageBox::questionYesNo( 0,
- QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITECOOKIEMSG ),
- resultTitle( response ) )
- == KMessageBox::Yes ) {
- slotPostMessage();
- }
-
- break;
-
- default:
- break;
- }
-}
-
-/* This slot is called when posting is done. */
-/* see also slotPostMessage() */ /* private slot */
-void KitaWriteView::slotPostFinished( KIO::Job* )
-{
- processPostFinished();
-}
-
-int KitaWriteView::getWriteResNum()
-{
- return Kita::DatManager::getReadNum( m_datURL ) + 1;
-}
-
-/* update preview screen */ /* private slot */
-void KitaWriteView::slotCurrentChanged ( QWidget * w )
-{
- if ( w == bodyText ) {
- w->setFocus();
- return ;
- }
- if ( m_preview == NULL ) return ;
-
- int resnum = getWriteResNum();
-
- QDateTime now = QDateTime::currentDateTime();
- QString bodystr = body();
- bodystr.replace( "<", "<" ).replace( ">", ">" ).replace( "\n", " <br> " );
- QString namestr = name();
- if ( namestr == NULL || namestr.length() == 0 ) namestr = Kita::BoardManager::getBBSDefaultName( m_datURL );
- QString rawData = namestr + "<>" + mail() + "<>"
- + now.toString( "yy/MM/dd hh:mm:ss" )
- + "<> " + bodystr + " <>";
-
- QString htmlstr = Kita::datToHtml( rawData, resnum );
- m_preview->setInnerHTML( htmlstr );
-}
-
-
-/* private slot */
-bool KitaWriteView::slotBodyTextChanged()
-{
- int lines = bodyText->lines();
- int maxLines = Kita::BoardManager::getBBSMaxLine( m_datURL );
- int tmpln = bodyText->length();
- int length = m_cp932Codec->fromUnicode( body(), tmpln ).length();
-
- /* replace '\n' -> " <br> ", '>' -> "<", and etc. */
- length += ( ( body().contains( '\n' ) ) * 5
- + ( body().contains( '>' ) ) * 3
- + ( body().contains( '<' ) ) * 3
- );
-
- int maxLength = Kita::BoardManager::getBBSMsgCount( m_datURL );
-
- QString str;
- str = QString().setNum( lines ) + "/" + ( maxLines != 0 ? QString().setNum( maxLines ) : QString( "--" ) );
- str += " | " + QString().setNum( length ) + "/" + ( maxLength != 0 ? QString().setNum( maxLength ) : QString( "--" ) );
- lengthLabel->setText( str );
-
- if ( maxLines != 0 && lines > maxLines ) return FALSE;
- if ( maxLength != 0 && length > maxLength ) return FALSE;
-
- return TRUE;
-}
-
-/* create posting message for 2ch */ /* private */
-QString KitaWriteView::getPostStr()
-{
- QString sessionID;
- QString threadID = Kita::DatManager::threadID( m_datURL );
- int serverTime = Kita::DatManager::getServerTime( m_datURL );
-
- /* login */
- if ( Kita::DatManager::is2chThread( m_datURL ) && Kita::Account::isLogged() ) {
- sessionID = KURL::encode_string( Kita::Account::getSessionID() );
- }
-
- return K2ch::buildPostStr( name(), mail(),
- body(), boardID(),
- threadID, serverTime,
- sessionID );
-}
-
-QString KitaWriteView::getMachiBBSPostStr()
-{
- QString threadID = Kita::DatManager::threadID( m_datURL );
- int serverTime = Kita::DatManager::getServerTime( m_datURL );
-
- return MachiBBS::buildPostStr( name(), mail(),
- body(), boardID(),
- threadID, serverTime );
-}
-
-
-/* create posting message for JBBS */ /* private */ /* private */
-QString KitaWriteView::getJBBSPostStr()
-{
- QString threadID = Kita::DatManager::threadID( m_datURL );
- int serverTime = Kita::DatManager::getServerTime( m_datURL );
-
- return JBBS::buildPostStr( name(), mail(),
- body(), boardID(),
- threadID, serverTime );
-}
-
-
-/* create posting message for Flash CGI */ /* private */ /* private */
-QString KitaWriteView::getFlashCGIPostStr()
-{
- QString threadID = Kita::DatManager::threadID( m_datURL );
-
- QString ret;
-
- return FlashCGI::buildPostStr( name(), mail(),
- body(), boardID(),
- threadID );
-}
-
-
-/* save post log */ /* private */
-void KitaWriteView::logPostMessage()
-{
- QString threadURL = Kita::DatManager::threadURL( m_datURL );
-
- QDateTime now = QDateTime::currentDateTime();
- QString logPath = locateLocal( "appdata", "log.txt" );
-
- QFile file( logPath );
- if ( file.open( IO_WriteOnly | IO_Append ) ) {
- QTextStream stream( &file );
- stream.setEncoding( QTextStream::UnicodeUTF8 );
-
- stream << "Date : " << now.toString( "yyyy/MM/dd hh:mm:ss" ) << endl; // current time
- stream << "Board : " << boardName() << endl;
- stream << "Thread : " << threadName() << endl;
- stream << "URL : " << threadURL << endl;
- stream << "Name : " << name() << endl;
- stream << "Mail : " << mail() << endl << endl;
- stream << body() << endl;
- stream << "----------------------------------------" << endl;
-
- file.close();
- }
-}
-
-
-/* get result code from 2ch tag or title. */ /* private */
-int KitaWriteView::resultCode( const QString& response ) const
-{
- /* see also libkita/kita-utf8.h */
- QString errstr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITEERROR );
- QString truestr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITETRUE );
- QString ckstr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITECOOKIE );
-
- QRegExp regexp( "<!-- 2ch_X:(.*) -->" );
- int pos = regexp.search( response );
-
- if ( pos != -1 ) {
- /* get code from 2ch tag */
- QString k2ch_X = regexp.cap( 1 );
-
- if ( k2ch_X == "true" ) return K2ch_True;
- if ( k2ch_X == "false" ) return K2ch_False;
- if ( k2ch_X == "error" ) return K2ch_Error;
- if ( k2ch_X == "check" ) return K2ch_Check;
- if ( k2ch_X == "cookie" ) return K2ch_Cookie;
-
- return K2ch_Unknown;
- } else {
- /* get code from title */
- QString title = resultTitle( response );
- if ( title == QString::null ) return K2ch_Unknown;
-
- if ( title.contains( errstr ) ) return K2ch_Error;
- if ( title.contains( truestr ) ) return K2ch_True;
- if ( title.contains( ckstr ) ) return K2ch_Cookie;
-
- /* for Flash CGI */
- if ( m_bbstype == Kita::Board_FlashCGI ) {
- if ( title.contains( "ERROR!!" ) ) {
- return K2ch_Error;
- } else {
- return K2ch_True;
- }
- }
-
- /* for JBBS. adhoc... */
- if ( m_bbstype == Kita::Board_JBBS ) {
-
- // x-euc-jp & euc-jp
- if ( response.contains( "euc-jp" ) ) {
- return K2ch_True;
- } else {
- return K2ch_Error;
- }
- }
-
- return K2ch_Unknown;
- }
-}
-
-
-/* private */
-QString KitaWriteView::resultMessage( const QString& response ) const
-{
- QRegExp tags( "(<[^<]+>|</[^<]+>)" );
-
- if ( m_bbstype == Kita::Board_FlashCGI ) {
-
- QRegExp regexp( "<blockquote>(.*)</blockquote>" );
- int pos = regexp.search( response );
- if ( pos != -1 ) {
- return regexp.cap( 1 ).replace( "<br>", "\n" );
- }
-
- return QString::null;
- }
-
- {
- QRegExp bold_start( "<b>" );
- QRegExp bold_end( "</b>" );
- int startPos = bold_start.search( response );
- if ( startPos != -1 ) {
- startPos += 3;
- int endPos = bold_end.search( response );
- if ( endPos != -1 && startPos < endPos ) {
- QString message = response.mid( startPos, endPos - startPos );
- message.remove( tags );
- return message;
- }
- }
- }
-
- QRegExp body_regexp( "<body>([^<]*)</body>" );
- if ( body_regexp.search( response ) != -1 ) {
- return body_regexp.cap( 1 );
- }
-
- return QString::null;
-}
-
-
-/* private */
-QString KitaWriteView::resultTitle( const QString& response ) const
-{
- QRegExp regexp( "<title>(.*)</title>" );
- regexp.setCaseSensitive( FALSE );
- int pos = regexp.search( response );
- if ( pos != -1 ) {
- return regexp.cap( 1 );
- } else {
- return QString::null;
- }
-}
+++ /dev/null
-/***************************************************************************
-* Copyright (C) 2004 by Kita Developers *
-* ikemo@users.sourceforge.jp *
-* *
-* 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. *
-***************************************************************************/
-
-#ifndef _KITAWRITEDIALOG_H_
-#define _KITAWRITEDIALOG_H_
-
-#include <qwidget.h>
-#include <kio/job.h>
-#include <kparts/browserextension.h>
-
-#include "writedialogbase.h"
-
-class KitaPreviewPart;
-class QCp932Codec;
-
-/* mode */
-enum{
- WRITEMODE_NORMAL,
- WRITEMODE_NEWTHREAD
-};
-
-/* result code */
-enum{
- K2ch_Unknown,
- K2ch_True,
- K2ch_False,
- K2ch_Error,
- K2ch_Check,
- K2ch_Cookie,
- K2ch_NewThread
-};
-
-
-/**
- *
- * Hideki Ikemoto
- **/
-class KitaWriteView : public KitaWriteDialogBase
-{
- Q_OBJECT
-
- KitaPreviewPart *m_preview;
-
- QString getPostStr();
- QString getMachiBBSPostStr();
- QString getJBBSPostStr();
- QString getFlashCGIPostStr();
-
-protected:
-
- QCString m_array;
- KURL m_bbscgi;
- int m_bbstype;
- KURL m_datURL;
- static QCp932Codec* m_cp932Codec;
-
- void initUI();
- void initThreadNameField();
- bool checkFields();
- QString buildPostMessage();
- int getWriteResNum();
- void processPostFinished();
- void logPostMessage();
- int resultCode( const QString& response ) const;
- QString resultMessage( const QString& response ) const;
- QString resultTitle( const QString& response ) const;
-
-public:
-
- KitaWriteView( QWidget* parent );
- KitaWriteView( QWidget* parent, const KURL& url );
- virtual ~KitaWriteView();
- void setMessage( const QString& bodyStr );
- void insertMessage( const QString& str );
-
- const KURL datURL() const;
- const QString threadName() const;
- const QString boardName() const;
- const QString boardID() const;
-
-public slots:
-
- virtual void setFocus();
- void slotPostMessage();
- void slotCancel();
- void slotEnableWriting( bool enable );
-
-private slots:
-
- void slotRecieveData( KIO::Job*, const QByteArray& );
- void slotPostFinished( KIO::Job* );
- void slotCurrentChanged ( QWidget * w );
-
-protected slots:
- bool slotBodyTextChanged();
-
-signals:
-
- void openURLRequestExt( const KURL& url, const QString mimetype = QString::null );
- void openThread( const KURL& url );
- void closeCurrentTab();
-};
-#endif