Commit MetaInfo

修订版40d21b64bde5d95ce642ca593ca6e794642d5aa0 (tree)
时间2007-07-05 21:04:06
作者ikemo <ikemo@56b1...>
Commiterikemo

Log Message

move files.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1996 56b19765-1e22-0410-a548-a0f45d66c51a

更改概述

差异

--- a/kita/src/Makefile.am
+++ b/kita/src/Makefile.am
@@ -15,10 +15,10 @@ kita_LDFLAGS = $(KDE_RPATH) $(all_libraries)
1515 kita_LDADD = ./prefs/libkitapref.la ./libkita/libkita.la ./kitaui/libkitaui.la ./write/libkitawrite.la ./thread/libkitathread.la ./board/libkitaboard.la ./bbs/libkitabbs.la $(LIB_KFILE) $(LIB_KDEPRINT) $(LIB_KDEUI)
1616
1717 # which sources should be compiled for kita
18-kita_SOURCES = main.cpp mainwindow.cpp bbstabwidget.cpp bbsview.cpp
18+kita_SOURCES = main.cpp mainwindow.cpp bbstabwidget.cpp bbsview.cpp writetabwidget.cpp writeview.cpp writedialogbase.ui previewpart.cpp
1919
2020 # these are the headers for your project
21-noinst_HEADERS = mainwindow.h bbstabwidget.h bbsview.h
21+noinst_HEADERS = mainwindow.h bbstabwidget.h bbsview.h writedialogbase.ui.h writetabwidget.h writeview.h previewpart.h
2222
2323 # let automoc handle all of the meta source files (moc)
2424 METASOURCES = AUTO
@@ -38,7 +38,7 @@ kdelnk_DATA = kita.desktop
3838
3939 # this is where the XML-GUI resource file goes
4040 rcdir = $(kde_datadir)/kita
41-rc_DATA = kitaui.rc
41+rc_DATA = kitaui.rc writetabwidgetui.rc
4242
4343 appicondir = $(kde_datadir)/kita/icons
4444 appicon_ICON = newthread read unread open
--- a/kita/src/mainwindow.cpp
+++ b/kita/src/mainwindow.cpp
@@ -20,7 +20,7 @@
2020 #include "bbsview.h"
2121 #include "bbstabwidget.h"
2222
23-#include "write/writetabwidget.h"
23+#include "writetabwidget.h"
2424
2525 #include "libkita/threadinfo.h"
2626 #include "libkita/favoriteboards.h"
--- /dev/null
+++ b/kita/src/previewpart.cpp
@@ -0,0 +1,451 @@
1+/***************************************************************************
2+ * Copyright (C) 2004 by Kita Developers *
3+ * ikemo@users.sourceforge.jp *
4+ * *
5+ * This program is free software; you can redistribute it and/or modify *
6+ * it under the terms of the GNU General Public License as published by *
7+ * the Free Software Foundation; either version 2 of the License, or *
8+ * (at your option) any later version. *
9+ ***************************************************************************/
10+
11+#include "previewpart.h"
12+
13+#include <qcursor.h>
14+
15+#include <khtml_events.h>
16+
17+#include <dom/html_misc.h>
18+
19+#include "thread/respopup.h"
20+#include "thread/htmlpart.h"
21+
22+#include "kitaui/htmlview.h"
23+
24+#include "libkita/kitaconfig.h"
25+#include "libkita/datmanager.h"
26+#include "libkita/kita_misc.h"
27+#include "libkita/signalcollection.h"
28+#include "libkita/config_xt.h"
29+
30+/*
31+ * Don't forget to call setup() later.
32+ */
33+KitaPreviewPart::KitaPreviewPart( QWidget* parent, const char* name )
34+ : KHTMLPart( new KitaHTMLView( this, parent, name ) )
35+{
36+ m_popup = NULL;
37+ m_datURL = QString::null;
38+
39+ clearPart();
40+ createHTMLDocument();
41+ connectSignals();
42+}
43+
44+KitaPreviewPart::~KitaPreviewPart()
45+{
46+ clearPart();
47+}
48+
49+void KitaPreviewPart::clearPart()
50+{
51+ slotDeletePopup();
52+
53+ if ( !m_datURL.isEmpty() ) {
54+ /* This part is opened. */
55+
56+ /* don't forget to unlock previous datURL here. */
57+ Kita::DatManager::unlock( m_datURL );
58+ }
59+ m_datURL = QString::null;
60+}
61+
62+bool KitaPreviewPart::setup( const KURL& url )
63+{
64+ if ( url.isEmpty() ) return FALSE;
65+
66+ clearPart();
67+
68+ m_datURL = Kita::getDatURL( url );
69+
70+ /* Lock datURL. Don't forget to unlock it later ! */
71+ Kita::DatManager::lock ( m_datURL );
72+
73+ /* create HTML Document */
74+ createHTMLDocument();
75+
76+ return TRUE;
77+}
78+
79+void KitaPreviewPart::connectSignals()
80+{
81+ Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
82+
83+ /* rendering */
84+ connect( signalCollection, SIGNAL( threadFaceChanged() ), SLOT( slotSetFaceOfHTMLPart() ) );
85+ connect( signalCollection, SIGNAL( setStyleSheetOfHTMLPart() ), SLOT( slotSetStyleSheetOfHTMLPart() ) );
86+
87+ /* popup */
88+ connect( this, SIGNAL( onURL( const QString& ) ), SLOT( slotOnURL( const QString& ) ) );
89+ connect( this, SIGNAL( isKitaActive() ), signalCollection, SIGNAL( isKitaActive() ) );
90+
91+ connect( view(), SIGNAL( leave() ), SLOT( slotLeave() ) );
92+ connect( view(), SIGNAL( verticalSliderReleased() ), SLOT( slotVSliderReleased() ) );
93+ connect( view(), SIGNAL( horizontalSliderReleased() ), SLOT( slotHSliderReleased() ) );
94+
95+ connect( signalCollection, SIGNAL( kitaIsActive() ), SLOT( slotKitaIsActive() ) );
96+ connect( signalCollection, SIGNAL( windowDeactivated() ), SLOT( slotHideChildPopup() ) );
97+
98+ /* click */
99+ connect( this, SIGNAL( openURLRequestExt( const KURL&, const QString ) ),
100+ signalCollection, SIGNAL( openURLRequestExt( const KURL&, const QString ) ) );
101+}
102+
103+void KitaPreviewPart::createHTMLDocument()
104+{
105+ /* style */
106+ QString style = QString( "body { font-size: %1pt; font-family: \"%2\"; color: %3; background-color: %4; }" )
107+ .arg( Kita::Config::threadFont().pointSize() )
108+ .arg( Kita::Config::threadFont().family() )
109+ .arg( Kita::Config::threadColor().name() )
110+ .arg( Kita::Config::threadBackground().name() );
111+
112+ QString text = "<html><head><style>";
113+ text += KitaConfig::defaultStyleSheetText();
114+ text += style;
115+ if ( Kita::Config::useStyleSheet() ) {
116+ text += KitaConfig::styleSheetText();
117+ }
118+ text += "</style></head><body></body></html>";
119+
120+ setJScriptEnabled( false );
121+ setJavaEnabled( false );
122+
123+ /* Use dummy URL here, and protocol should be "file:".
124+ If protocol is "http:", local image files are not shown
125+ (for security reasons ?).
126+ */
127+ begin( "file:/dummy.htm" );
128+ write( text );
129+ end();
130+}
131+
132+void KitaPreviewPart::setInnerHTML( const QString& innerHTML )
133+{
134+ createHTMLDocument();
135+ htmlDocument().body().setInnerHTML( innerHTML );
136+}
137+
138+void KitaPreviewPart::slotSetFaceOfHTMLPart()
139+{
140+ QFont font = Kita::Config::threadFont();
141+
142+ DOM::CSSStyleDeclaration style = htmlDocument().body().style();
143+ style.setProperty( "font-family", font.family(), "" );
144+ style.setProperty( "font-size", QString( "%1pt" ).arg( font.pointSize() ), "" );
145+ style.setProperty( "color", Kita::Config::threadColor().name(), "" );
146+ style.setProperty( "background-color", Kita::Config::threadBackground().name(), "" );
147+
148+ htmlDocument().applyChanges();
149+}
150+
151+void KitaPreviewPart::slotSetStyleSheetOfHTMLPart()
152+{
153+ /* [0]<html> -> [1]<head> -> [2]<style> */
154+ DOM::HTMLCollection collection = htmlDocument().all();
155+ DOM::HTMLElement element;
156+ unsigned int i;
157+ for ( i = 0 ; i < collection.length() ; i++ ) {
158+ element = collection.item( i );
159+ if ( element.tagName().upper() == "STYLE" ) {
160+ QString style = QString( "body { font-size: %1pt; font-family: %2; color: %3; background-color: %4; }" )
161+ .arg( Kita::Config::threadFont().pointSize() )
162+ .arg( Kita::Config::threadFont().family() )
163+ .arg( Kita::Config::threadColor().name() )
164+ .arg( Kita::Config::threadBackground().name() );
165+
166+ QString style0 = KitaConfig::defaultStyleSheetText();
167+ style0 += style;
168+ if ( Kita::Config::useStyleSheet() ) {
169+ style0 += KitaConfig::styleSheetText();
170+ }
171+
172+ element.setInnerText( style0 );
173+ htmlDocument().applyChanges();
174+ break;
175+ }
176+ }
177+}
178+
179+/*
180+ * @Override
181+ */
182+void KitaPreviewPart::customEvent( QCustomEvent * e )
183+{
184+ if ( e->type() == EVENT_GotoAnchor ) {
185+ KHTMLPart::gotoAnchor( static_cast< GotoAnchorEvent* >( e ) ->getAnc() );
186+ return ;
187+ }
188+
189+ KHTMLPart::customEvent( e );
190+}
191+
192+/*
193+ * @Override
194+ */
195+void KitaPreviewPart::khtmlMousePressEvent( khtml::MousePressEvent* e )
196+{
197+ emit mousePressed(); /* to KitaThreadView to focus this view. */
198+
199+ KURL kurl;
200+ if ( e->url().string() != QString::null ) {
201+ kurl = KURL( Kita::BoardManager::boardURL( m_datURL ), e->url().string() );
202+ }
203+
204+ if ( e->qmouseEvent()->button() & Qt::RightButton ) {
205+ m_isPushedRightButton = TRUE;
206+ } else {
207+ m_isPushedRightButton = FALSE;
208+ }
209+
210+ if ( e->url() != NULL ) {
211+
212+ if ( e->url().string().at( 0 ) == '#' ) { /* anchor */
213+ kurl = m_datURL;
214+ kurl.setRef( e->url().string().mid( 1 ) ) ;
215+ }
216+
217+ clickAnchor( kurl );
218+ m_isPushedRightButton = FALSE;
219+ return;
220+ }
221+
222+ KHTMLPart::khtmlMousePressEvent( e );
223+}
224+
225+/*
226+ * This function is called when user clicked res anchor
227+ */
228+void KitaPreviewPart::clickAnchor( const KURL& urlin )
229+{
230+ QString refstr;
231+ KURL datURL = Kita::getDatURL( urlin, refstr );
232+
233+ /*--------------------------------*/
234+ /* If this is not anchor, then */
235+ /* emit openURLRequest and return */
236+ if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) {
237+ emit openURLRequestExt( urlin );
238+ return ;
239+ }
240+
241+ if ( refstr == QString::null ) return ;
242+
243+ /*-------------------------*/
244+ /* start multi-popup mdde */
245+ if ( m_isPushedRightButton && startMultiPopup() ) return ;
246+
247+ int refNum, refNum2;
248+
249+ int i = refstr.find( "-" );
250+ if ( i != -1 ) {
251+ refNum = refstr.left( i ).toInt();
252+ refNum2 = refstr.mid( i + 1 ).toInt();
253+ if ( refNum2 < refNum ) {
254+ refNum2 = refNum;
255+ }
256+ } else {
257+ refNum = refNum2 = refstr.toInt();
258+ }
259+
260+ if ( !refNum ) return ;
261+
262+ emit openURLRequestExt( urlin );
263+}
264+
265+void KitaPreviewPart::slotDeletePopup()
266+{
267+ if ( m_popup ) delete m_popup;
268+ m_popup = NULL;
269+ m_multiPopup = FALSE;
270+}
271+
272+/*
273+ * for convenience
274+ */
275+void KitaPreviewPart::showPopup( const KURL& url, const QString& innerHTML )
276+{
277+ slotDeletePopup();
278+ m_multiPopup = FALSE;
279+
280+ m_popup = new Kita::ResPopup( view() , url );
281+
282+ connect( m_popup, SIGNAL( hideChildPopup() ), SLOT( slotHideChildPopup() ) );
283+
284+ m_popup->setText( innerHTML );
285+ m_popup->adjustSize();
286+ m_popup->adjustPos( QCursor::pos() );
287+ m_popup->show();
288+}
289+
290+/*
291+ * start multi-popup mode
292+ */
293+bool KitaPreviewPart::startMultiPopup()
294+{
295+ if ( m_popup && m_popup->isVisible() ) {
296+ m_multiPopup = TRUE;
297+ m_popup->moveMouseAbove();
298+ } else {
299+ m_multiPopup = FALSE;
300+ }
301+
302+ return m_multiPopup;
303+}
304+
305+/*
306+ * Is it multi-popup mode now ?
307+ */
308+bool KitaPreviewPart::isMultiPopupMode()
309+{
310+ if ( !m_popup ) {
311+ m_multiPopup = FALSE;
312+ } else if ( m_popup->isHidden() ) {
313+ m_multiPopup = FALSE;
314+ }
315+
316+ return m_multiPopup;
317+}
318+
319+void KitaPreviewPart::hidePopup()
320+{
321+ if ( m_popup ) {
322+ m_popup->hide();
323+ }
324+
325+ m_multiPopup = FALSE;
326+}
327+
328+void KitaPreviewPart::slotLeave()
329+{
330+ if ( isMultiPopupMode() ) return ;
331+ if ( view()->isHorizontalSliderPressed() ) return ;
332+ if ( view()->isVerticalSliderPressed () ) return ;
333+
334+ hidePopup();
335+}
336+
337+void KitaPreviewPart::slotVSliderReleased()
338+{
339+ QScrollBar* bar = view()->verticalScrollBar();
340+ QRect rt = bar->sliderRect();
341+
342+ hidePopup();
343+}
344+
345+void KitaPreviewPart::slotHSliderReleased()
346+{
347+ QScrollBar* bar = view()->horizontalScrollBar();
348+ QRect rt = bar->sliderRect();
349+
350+ hidePopup();
351+}
352+
353+void KitaPreviewPart::slotHideChildPopup()
354+{
355+ hidePopup();
356+}
357+
358+/*
359+ * called back when kita is active.
360+ * see also an explanation in slotOnURL.
361+ */
362+void KitaPreviewPart::slotKitaIsActive()
363+{
364+ m_kitaIsActive = TRUE;
365+}
366+
367+/*
368+ * This slot is called when mouse moves onto the URL
369+ */
370+void KitaPreviewPart::slotOnURL( const QString& url )
371+{
372+ const int maxpopup = 10; /* max number of responses shown in the popup window */
373+
374+ if ( isMultiPopupMode() ) return ;
375+
376+ slotDeletePopup();
377+
378+ if ( url.isEmpty() ) return ;
379+ if ( url.left( 7 ) == "mailto:" ) return ;
380+
381+ /* Is Kita active now ?
382+
383+ emit SIGNAL( isKitaActive() ) to KitaMainWindow, KitaNavi, etc. ,
384+ and if one of them is active, then slotKitaIsActive() is called
385+ back, and m_kitaIsActive is set to TRUE. */
386+ m_kitaIsActive = FALSE;
387+ emit isKitaActive();
388+ if ( !m_kitaIsActive ) return ;
389+
390+ /* get reference */
391+ QString refstr;
392+ KURL datURL = m_datURL;
393+ if ( url.at( 0 ) == '#' ) {
394+ refstr = url.mid( 1 );
395+ } else {
396+ datURL = Kita::getDatURL( KURL( m_datURL, url ), refstr );
397+ }
398+
399+ /*-------------------------*/
400+ /* popup for anchor */
401+
402+ QString innerHTML = QString::null;
403+ int refNum;
404+ int refNum2;
405+
406+ int i = refstr.find( "-" );
407+ if ( i != -1 ) { /* >>refNum-refNum2 */
408+
409+ refNum = refstr.left( i ).toInt();
410+ refNum2 = refstr.mid( i + 1 ).toInt();
411+
412+ if ( refNum ) {
413+ if ( refNum2 < refNum ) refNum2 = refNum;
414+ if ( refNum2 - refNum > maxpopup - 1 ) refNum2 = refNum + maxpopup - 1;
415+ }
416+
417+ } else { /* >>refNum */
418+ refNum = refstr.toInt();
419+ refNum2 = refNum;
420+ }
421+
422+ /* another thread ? */
423+ if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) {
424+
425+ /* get board name */
426+ QString boardName = Kita::BoardManager::boardName( datURL );
427+ if ( boardName != QString::null ) {
428+ innerHTML += "[" + boardName + "] ";
429+ }
430+
431+ /* If idx file of datURL is not read, thread name cannot be obtained.
432+ so, create DatInfo if cache exists, and read idx file in DatInfo::DatInfo(). */
433+ Kita::DatManager::getDatInfoPointer( datURL );
434+
435+ /* get thread Name */
436+ QString subName = Kita::DatManager::threadName( datURL );
437+ if ( subName != QString::null ) {
438+ innerHTML += subName + "<br><br>";
439+ }
440+
441+ if ( !refNum ) refNum = refNum2 = 1;
442+ }
443+
444+ /* get HTML and show it */
445+ if ( !refNum ) return ;
446+
447+ innerHTML += Kita::DatManager::getHtml( datURL, refNum, refNum2 );
448+ if ( innerHTML != QString::null ) {
449+ showPopup( datURL, innerHTML );
450+ }
451+}
--- /dev/null
+++ b/kita/src/previewpart.h
@@ -0,0 +1,102 @@
1+/***************************************************************************
2+ * Copyright (C) 2004 by Kita Developers *
3+ * ikemo@users.sourceforge.jp *
4+ * *
5+ * This program is free software; you can redistribute it and/or modify *
6+ * it under the terms of the GNU General Public License as published by *
7+ * the Free Software Foundation; either version 2 of the License, or *
8+ * (at your option) any later version. *
9+ ***************************************************************************/
10+
11+#ifndef PREVIEWPART_H
12+#define PREVIEWPART_H
13+
14+#include <khtml_part.h>
15+
16+/* ID of user defined event */
17+#define EVENT_GotoAnchor ( QEvent::User + 100 )
18+
19+namespace Kita
20+{
21+ class ResPopup;
22+}
23+
24+class KitaPreviewPart : public KHTMLPart
25+{
26+ Q_OBJECT
27+
28+ Kita::ResPopup* m_popup;
29+
30+ /* basic information */
31+ KURL m_datURL;
32+
33+ /* mouse event */
34+ bool m_isPushedRightButton;
35+
36+ /* res popup */
37+ bool m_multiPopup;
38+ bool m_kitaIsActive;
39+
40+public:
41+
42+ KitaPreviewPart( QWidget* parent, const char* name = 0 );
43+ ~KitaPreviewPart();
44+ bool setup( const KURL& url );
45+
46+ /* rendering */
47+ void setInnerHTML( const QString& innerHTML );
48+
49+public slots:
50+
51+ /* rendering */
52+ void slotSetFaceOfHTMLPart();
53+ void slotSetStyleSheetOfHTMLPart();
54+
55+ /* res popup */
56+ void slotDeletePopup();
57+
58+private:
59+
60+ void clearPart();
61+
62+ /* setup */
63+ void connectSignals();
64+ void createHTMLDocument();
65+
66+ /* click */
67+ void clickAnchor( const KURL& urlin );
68+
69+ /* res popup */
70+ void showPopup( const KURL& url, const QString& innerHTML );
71+ bool startMultiPopup();
72+ bool isMultiPopupMode();
73+ void hidePopup();
74+
75+protected:
76+
77+ /* user event */
78+ virtual void customEvent( QCustomEvent * e );
79+
80+ /* mouse event */
81+ virtual void khtmlMousePressEvent( khtml::MousePressEvent* e );
82+
83+private slots:
84+
85+ /* res popup */
86+ void slotLeave();
87+ void slotVSliderReleased();
88+ void slotHSliderReleased();
89+ void slotHideChildPopup();
90+ void slotKitaIsActive();
91+ void slotOnURL( const QString& url );
92+
93+signals:
94+
95+ void openURLRequestExt( const KURL& url, const QString mimetype = QString::null );
96+ void mousePressed(); /* to KitaThreadView */
97+
98+ /* res popup */
99+ void isKitaActive();
100+};
101+
102+#endif
--- /dev/null
+++ b/kita/src/writedialogbase.ui
@@ -0,0 +1,258 @@
1+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
2+<class>KitaWriteDialogBase</class>
3+<widget class="QWidget">
4+ <property name="name">
5+ <cstring>KitaWriteDialogBase</cstring>
6+ </property>
7+ <property name="geometry">
8+ <rect>
9+ <x>0</x>
10+ <y>0</y>
11+ <width>534</width>
12+ <height>380</height>
13+ </rect>
14+ </property>
15+ <property name="caption">
16+ <string>Write in thread</string>
17+ </property>
18+ <vbox>
19+ <property name="name">
20+ <cstring>unnamed</cstring>
21+ </property>
22+ <widget class="QLayoutWidget">
23+ <property name="name">
24+ <cstring>layout4</cstring>
25+ </property>
26+ <hbox>
27+ <property name="name">
28+ <cstring>unnamed</cstring>
29+ </property>
30+ <widget class="QLabel">
31+ <property name="name">
32+ <cstring>textLabel1</cstring>
33+ </property>
34+ <property name="sizePolicy">
35+ <sizepolicy>
36+ <hsizetype>5</hsizetype>
37+ <vsizetype>5</vsizetype>
38+ <horstretch>0</horstretch>
39+ <verstretch>0</verstretch>
40+ </sizepolicy>
41+ </property>
42+ <property name="text">
43+ <string>Board:</string>
44+ </property>
45+ </widget>
46+ <widget class="KSqueezedTextLabel">
47+ <property name="name">
48+ <cstring>boardNameLabel</cstring>
49+ </property>
50+ <property name="sizePolicy">
51+ <sizepolicy>
52+ <hsizetype>7</hsizetype>
53+ <vsizetype>0</vsizetype>
54+ <horstretch>1</horstretch>
55+ <verstretch>0</verstretch>
56+ </sizepolicy>
57+ </property>
58+ <property name="text">
59+ <string>board name</string>
60+ </property>
61+ </widget>
62+ <widget class="QLabel">
63+ <property name="name">
64+ <cstring>textLabel1_2</cstring>
65+ </property>
66+ <property name="text">
67+ <string>Thread:</string>
68+ </property>
69+ </widget>
70+ <widget class="KLineEdit">
71+ <property name="name">
72+ <cstring>threadNameLine</cstring>
73+ </property>
74+ <property name="sizePolicy">
75+ <sizepolicy>
76+ <hsizetype>7</hsizetype>
77+ <vsizetype>0</vsizetype>
78+ <horstretch>3</horstretch>
79+ <verstretch>0</verstretch>
80+ </sizepolicy>
81+ </property>
82+ </widget>
83+ </hbox>
84+ </widget>
85+ <widget class="QLayoutWidget">
86+ <property name="name">
87+ <cstring>layout4</cstring>
88+ </property>
89+ <hbox>
90+ <property name="name">
91+ <cstring>unnamed</cstring>
92+ </property>
93+ <widget class="QLabel">
94+ <property name="name">
95+ <cstring>nameLabel</cstring>
96+ </property>
97+ <property name="text">
98+ <string>name</string>
99+ </property>
100+ </widget>
101+ <widget class="KLineEdit">
102+ <property name="name">
103+ <cstring>nameLine</cstring>
104+ </property>
105+ </widget>
106+ <widget class="QLabel">
107+ <property name="name">
108+ <cstring>mailLabel</cstring>
109+ </property>
110+ <property name="text">
111+ <string>mail</string>
112+ </property>
113+ </widget>
114+ <widget class="KLineEdit">
115+ <property name="name">
116+ <cstring>mailLine</cstring>
117+ </property>
118+ </widget>
119+ <widget class="QCheckBox">
120+ <property name="name">
121+ <cstring>sageBox</cstring>
122+ </property>
123+ <property name="text">
124+ <string>&amp;sage</string>
125+ </property>
126+ <property name="accel">
127+ <string>Alt+S</string>
128+ </property>
129+ </widget>
130+ <widget class="QCheckBox">
131+ <property name="name">
132+ <cstring>beBox</cstring>
133+ </property>
134+ <property name="text">
135+ <string>&amp;be</string>
136+ </property>
137+ <property name="accel">
138+ <string>Alt+B</string>
139+ </property>
140+ </widget>
141+ </hbox>
142+ </widget>
143+ <widget class="QTabWidget">
144+ <property name="name">
145+ <cstring>qtw</cstring>
146+ </property>
147+ <widget class="QTextEdit">
148+ <property name="name">
149+ <cstring>bodyText</cstring>
150+ </property>
151+ <attribute name="title">
152+ <string>body</string>
153+ </attribute>
154+ </widget>
155+ </widget>
156+ <widget class="QLayoutWidget">
157+ <property name="name">
158+ <cstring>layout4</cstring>
159+ </property>
160+ <hbox>
161+ <property name="name">
162+ <cstring>unnamed</cstring>
163+ </property>
164+ <widget class="QComboBox">
165+ <property name="name">
166+ <cstring>faceCombo</cstring>
167+ </property>
168+ </widget>
169+ <spacer>
170+ <property name="name">
171+ <cstring>Horizontal Spacing2</cstring>
172+ </property>
173+ <property name="orientation">
174+ <enum>Horizontal</enum>
175+ </property>
176+ <property name="sizeType">
177+ <enum>Expanding</enum>
178+ </property>
179+ <property name="sizeHint">
180+ <size>
181+ <width>40</width>
182+ <height>20</height>
183+ </size>
184+ </property>
185+ </spacer>
186+ <widget class="QLabel">
187+ <property name="name">
188+ <cstring>lengthLabel</cstring>
189+ </property>
190+ <property name="text">
191+ <string>XX/XX | XXXX/XXXX</string>
192+ </property>
193+ </widget>
194+ <widget class="QPushButton">
195+ <property name="name">
196+ <cstring>buttonOk</cstring>
197+ </property>
198+ <property name="text">
199+ <string>&amp;OK</string>
200+ </property>
201+ <property name="accel">
202+ <string></string>
203+ </property>
204+ <property name="autoDefault">
205+ <bool>true</bool>
206+ </property>
207+ <property name="default">
208+ <bool>true</bool>
209+ </property>
210+ </widget>
211+ <widget class="QPushButton">
212+ <property name="name">
213+ <cstring>buttonCancel</cstring>
214+ </property>
215+ <property name="text">
216+ <string>&amp;Cancel</string>
217+ </property>
218+ <property name="accel">
219+ <string></string>
220+ </property>
221+ <property name="autoDefault">
222+ <bool>true</bool>
223+ </property>
224+ </widget>
225+ </hbox>
226+ </widget>
227+ </vbox>
228+</widget>
229+<connections>
230+ <connection>
231+ <sender>sageBox</sender>
232+ <signal>toggled(bool)</signal>
233+ <receiver>KitaWriteDialogBase</receiver>
234+ <slot>sageBoxToggled(bool)</slot>
235+ </connection>
236+</connections>
237+<includes>
238+ <include location="local" impldecl="in implementation">writedialogbase.ui.h</include>
239+</includes>
240+<variables>
241+ <variable>QString m_mailswap;</variable>
242+</variables>
243+<slots>
244+ <slot access="protected">sageBoxToggled( bool on )</slot>
245+</slots>
246+<functions>
247+ <function access="protected" specifier="non virtual" returnType="const QString">name() const</function>
248+ <function access="protected" specifier="non virtual" returnType="const QString">mail() const</function>
249+ <function specifier="non virtual" returnType="const QString">body() const</function>
250+</functions>
251+<layoutdefaults spacing="6" margin="11"/>
252+<includehints>
253+ <includehint>ksqueezedtextlabel.h</includehint>
254+ <includehint>klineedit.h</includehint>
255+ <includehint>klineedit.h</includehint>
256+ <includehint>klineedit.h</includehint>
257+</includehints>
258+</UI>
--- /dev/null
+++ b/kita/src/writedialogbase.ui.h
@@ -0,0 +1,36 @@
1+/****************************************************************************
2+** ui.h extension file, included from the uic-generated form implementation.
3+**
4+** If you wish to add, delete or rename functions or slots use
5+** Qt Designer which will update this file, preserving your code. Create an
6+** init() function in place of a constructor, and a destroy() function in
7+** place of a destructor.
8+*****************************************************************************/
9+
10+
11+void KitaWriteDialogBase::sageBoxToggled( bool on )
12+{
13+ if ( on ) {
14+ m_mailswap = mailLine->text();
15+ mailLine->setText( "sage" );
16+ mailLine->setReadOnly( true );
17+ } else {
18+ mailLine->setReadOnly( false );
19+ mailLine->setText( m_mailswap );
20+ }
21+}
22+
23+const QString KitaWriteDialogBase::name() const
24+{
25+ return nameLine->text();
26+}
27+
28+const QString KitaWriteDialogBase::mail() const
29+{
30+ return mailLine->text();
31+}
32+
33+const QString KitaWriteDialogBase::body() const
34+{
35+ return bodyText->text();
36+}
--- /dev/null
+++ b/kita/src/writetabwidget.cpp
@@ -0,0 +1,267 @@
1+/***************************************************************************
2+* Copyright (C) 2004 by Kita Developers *
3+* ikemo@users.sourceforge.jp *
4+* *
5+* This program is free software; you can redistribute it and/or modify *
6+* it under the terms of the GNU General Public License as published by *
7+* the Free Software Foundation; either version 2 of the License, or *
8+* (at your option) any later version. *
9+***************************************************************************/
10+
11+#include "libkita/kita_misc.h"
12+#include "libkita/signalcollection.h"
13+#include "libkita/datmanager.h"
14+#include "libkita/boardmanager.h"
15+#include "writetabwidget.h"
16+#include "writeview.h"
17+
18+#include <kdebug.h>
19+#include <kstdaccel.h>
20+#include <kaction.h>
21+#include <klocale.h>
22+#include <kpopupmenu.h>
23+#include <kapplication.h>
24+
25+#include <qmessagebox.h>
26+#include <qclipboard.h>
27+
28+/*--------------------------------------------------------------------------------*/
29+
30+
31+KitaWriteTabWidget::KitaWriteTabWidget( QWidget* parent, const char* name, WFlags f )
32+ : KitaTabWidgetBase( parent, name, f )
33+{
34+ setXMLFile( "writetabwidgetui.rc" );
35+
36+ connectSignals();
37+ setupActions();
38+}
39+
40+
41+KitaWriteTabWidget::~KitaWriteTabWidget() {}
42+
43+
44+/* public slot */
45+void KitaWriteTabWidget::slotShowWriteView( const KURL& url,
46+ const QString& resStr )
47+{
48+ openWriteView( WRITEMODE_NORMAL, url, resStr, QString::null );
49+}
50+
51+
52+/* private */
53+void KitaWriteTabWidget::openWriteView( int mode, const KURL& url,
54+ const QString& resStr, const QString& subject )
55+{
56+ // TODO: machiBBS kakiko support.
57+ if ( Kita::BoardManager::type( url ) == Kita::Board_MachiBBS ) {
58+// QMessageBox::warning( this, QString( "<(_ _)>" ),
59+// i18n( "Can't write to machi BBS in this version." ) );
60+// return ;
61+ }
62+
63+ /* view exists */
64+ KitaWriteView* view = findWriteView( url );
65+ if ( view ) {
66+
67+ if ( view->body().length() ) {
68+
69+ if ( QMessageBox::warning( this, "Kita",
70+ i18n( "Do you want to clear the text?" ),
71+ QMessageBox::Ok,
72+ QMessageBox::Cancel | QMessageBox::Default ) == QMessageBox::Cancel ) return ;
73+ }
74+
75+ /* clear */
76+ view->setMessage( resStr );
77+ setCurrentPage( indexOf( view ) );
78+ return ;
79+ }
80+
81+ // TODO: refactoring.
82+ /* create new write view & add it to tab */
83+ QString threadName;
84+
85+ /* write res */
86+ KitaWriteView* new_dlg;
87+ threadName = Kita::DatManager::threadName( url );
88+ new_dlg = new KitaWriteView( this, url );
89+ new_dlg->setMessage( resStr );
90+ connect( new_dlg, SIGNAL( closeCurrentTab() ), SLOT( slotCloseCurrentTab() ) );
91+ addTab( new_dlg, threadName );
92+ showPage( new_dlg );
93+}
94+
95+
96+/* close view which URL is url. */ /* public slot */
97+void KitaWriteTabWidget::slotCloseWriteTab( const KURL& url )
98+{
99+ KitaWriteView * view = findWriteView( url );
100+ if ( view ) slotCloseTab( indexOf( view ) );
101+}
102+
103+
104+/* private */
105+void KitaWriteTabWidget::connectSignals()
106+{
107+ Kita::SignalCollection * signalCollection = Kita::SignalCollection::getInstance();
108+
109+ connect( signalCollection, SIGNAL( activateThreadView( const KURL& ) ),
110+ this, SLOT( slotChangeWriteTab( const KURL& ) ) );
111+ connect( signalCollection, SIGNAL( closeWriteTab( const KURL& ) ),
112+ SLOT( slotCloseWriteTab( const KURL& ) ) );
113+}
114+
115+
116+/* private */
117+KitaWriteView* KitaWriteTabWidget::findWriteView( const KURL& url )
118+{
119+ KURL datURL = Kita::getDatURL( url );
120+ if ( datURL.isEmpty() ) return NULL;
121+
122+ int max = count();
123+ if ( max == 0 ) return NULL;
124+ int i = 0;
125+
126+ while ( i < max ) {
127+ KitaWriteView * view = isWriteView( page ( i ) );
128+ if ( view ) {
129+ if ( view->datURL() == datURL ) return view;
130+ }
131+ i++;
132+ }
133+
134+ return NULL;
135+}
136+
137+
138+/* private */
139+KitaWriteView* KitaWriteTabWidget::isWriteView( QWidget* w )
140+{
141+ KitaWriteView * view = NULL;
142+ if ( w ) {
143+ if ( w->isA( "KitaWriteView" ) ) view = static_cast< KitaWriteView* >( w );
144+ }
145+
146+ return view;
147+}
148+
149+
150+
151+/* when thread view is focused, this slot is called */
152+/* See also KitaThreadView::setFocus. */ /* private slot */
153+void KitaWriteTabWidget::slotChangeWriteTab( const KURL& url )
154+{
155+ KitaWriteView * view;
156+ int max = count();
157+ if ( max == 0 ) return ;
158+
159+ /* disable all ok buttons. */
160+ int i = 0;
161+ while ( i < max ) {
162+ view = isWriteView( page( i ) );
163+ if ( view ) view->slotEnableWriting( FALSE );
164+ i++;
165+ }
166+
167+ /* show current url page. */
168+ view = findWriteView( url );
169+ if ( view ) {
170+ static_cast< KitaDockWidgetBase* >( parentWidget() ) ->slotShowDock( FALSE, FALSE );
171+ if ( currentPage() != view ) setCurrentPage( indexOf( view ) );
172+ view->slotEnableWriting( TRUE );
173+ }
174+}
175+
176+
177+/* protected */ /* virtual */
178+void KitaWriteTabWidget::deleteWidget( QWidget* w )
179+{
180+ KitaWriteView * view = isWriteView( w );
181+
182+ if ( view == NULL ) return ;
183+
184+ if ( view->body().length() ) {
185+ if ( QMessageBox::warning( this, "Kita",
186+ i18n( "If you close this dialog, you will lose text.\n"
187+ "Do you want to close?" ),
188+ QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
189+ == QMessageBox::Cancel ) return ;
190+ }
191+
192+ KitaTabWidgetBase::deleteWidget( w );
193+
194+ if ( count() == 0 ) {
195+ static_cast< KitaDockWidgetBase* >( parentWidget() ) ->slotHideDock();
196+ }
197+}
198+
199+
200+/*--------------------------------*/
201+/* KitaWriteTabWidget actions */
202+
203+
204+/* private */
205+void KitaWriteTabWidget::setupActions()
206+{
207+ new KAction( i18n( "quote clipboard" ),
208+ Key_F2,
209+ this,
210+ SLOT( slotQuoteClipboard() ),
211+ actionCollection(),
212+ "writeview_quoteclip" );
213+}
214+
215+
216+/* public slot */
217+void KitaWriteTabWidget::slotQuoteClipboard()
218+{
219+ KitaWriteView * view = isWriteView( currentPage() );
220+ if ( view ) {
221+ QClipboard * clipboard = QApplication::clipboard();
222+ QString str = clipboard->text( QClipboard::Selection );
223+ if ( str == QString::null ) str = clipboard->text( QClipboard::Clipboard );
224+ if ( str != QString::null ) {
225+
226+ QString msg = "\n> " + str.replace( "\n", "\n> " ) + "\n";
227+ view->insertMessage( msg );
228+ }
229+ }
230+}
231+
232+/*---------------------------------------------------------------------*/
233+/*---------------------------------------------------------------------*/
234+/*---------------------------------------------------------------------*/
235+
236+
237+/* Don't forget to call setup later ! */
238+KitaWriteDock::KitaWriteDock( KDockManager* dockManager,
239+ const char* name,
240+ const QPixmap &pixmap,
241+ QWidget* parent,
242+ const QString& strCaption,
243+ const QString& strTabPageLabel,
244+ WFlags f )
245+ : KitaDockWidgetBase( dockManager, name, pixmap, parent, strCaption, strTabPageLabel, f ), m_writeTab( 0 ) {}
246+
247+
248+KitaWriteDock::~KitaWriteDock() {}
249+
250+
251+void KitaWriteDock::setup()
252+{
253+ Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
254+ connect( signalCollection, SIGNAL( showWriteView( const KURL& , const QString& ) ),
255+ this, SLOT( slotShowWriteView( const KURL& , const QString& ) ) );
256+ connect( signalCollection, SIGNAL( switchToWritedock() ),
257+ this, SLOT( slotShowDock() ) );
258+}
259+
260+
261+void KitaWriteDock::slotShowWriteView( const KURL& url, const QString& resStr )
262+{
263+ if ( !m_writeTab ) return ;
264+
265+ slotShowDock();
266+ m_writeTab->slotShowWriteView( url, resStr );
267+}
--- /dev/null
+++ b/kita/src/writetabwidget.h
@@ -0,0 +1,84 @@
1+/***************************************************************************
2+* Copyright (C) 2003 by Hideki Ikemoto, 2004 by 421 *
3+* ikemo@users.sourceforge.jp *
4+* *
5+* This program is free software; you can redistribute it and/or modify *
6+* it under the terms of the GNU General Public License as published by *
7+* the Free Software Foundation; either version 2 of the License, or *
8+* (at your option) any later version. *
9+***************************************************************************/
10+
11+#ifndef KITAWRITETABWIDGET_H
12+#define KITAWRITETABWIDGET_H
13+
14+#include "kitaui/tabwidgetbase.h"
15+
16+class KitaWriteView;
17+
18+/*-----------------------------------------------*/
19+
20+
21+class KitaWriteTabWidget : public KitaTabWidgetBase
22+{
23+ Q_OBJECT
24+
25+public:
26+ KitaWriteTabWidget( QWidget* parent = 0, const char* name = 0, WFlags f = 0 );
27+ ~KitaWriteTabWidget();
28+
29+public slots:
30+ void slotShowWriteView( const KURL& url, const QString& resStr );
31+ void slotCloseWriteTab( const KURL& url );
32+
33+private:
34+ void openWriteView( int mode, const KURL& url, const QString& resStr = QString::null, const QString& subject = QString::null );
35+ void connectSignals();
36+ KitaWriteView* findWriteView( const KURL& url );
37+ KitaWriteView* isWriteView( QWidget* w );
38+
39+private slots:
40+ void slotChangeWriteTab( const KURL& url );
41+
42+protected:
43+ virtual void deleteWidget( QWidget* w );
44+
45+
46+ /*------------------------------------*/
47+ /* KitaWriteTabWidget actions */
48+
49+private:
50+ void setupActions();
51+
52+public slots:
53+ void slotQuoteClipboard();
54+};
55+
56+
57+/*--------------------------------------------------*/
58+
59+class KitaWriteDock : public KitaDockWidgetBase
60+{
61+
62+ Q_OBJECT
63+ KitaWriteTabWidget* m_writeTab;
64+
65+public:
66+ KitaWriteDock( KDockManager* dockManager,
67+ const char* name,
68+ const QPixmap &pixmap,
69+ QWidget* parent = 0L,
70+ const QString& strCaption = QString::null,
71+ const QString& strTabPageLabel = QString::fromLatin1( " " ),
72+ WFlags f = 0 );
73+ ~KitaWriteDock();
74+
75+ void setup();
76+ void setWriteTabWidget( KitaWriteTabWidget* w ) { m_writeTab = w; }
77+
78+public slots:
79+ void slotShowWriteView( const KURL& url, const QString& resStr );
80+};
81+
82+
83+
84+#endif
--- /dev/null
+++ b/kita/src/writetabwidgetui.rc
@@ -0,0 +1,3 @@
1+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
2+<kpartgui name="kitaWriteTabWidget" version="1">
3+</kpartgui>
--- /dev/null
+++ b/kita/src/writeview.cpp
@@ -0,0 +1,646 @@
1+/***************************************************************************
2+* Copyright (C) 2004 by Kita Developers *
3+* ikemo@users.sourceforge.jp *
4+* *
5+* This program is free software; you can redistribute it and/or modify *
6+* it under the terms of the GNU General Public License as published by *
7+* the Free Software Foundation; either version 2 of the License, or *
8+* (at your option) any later version. *
9+***************************************************************************/
10+
11+#include "writeview.h"
12+
13+#include "previewpart.h"
14+
15+#include "libkita/qcp932codec.h"
16+#include "libkita/kitaconfig.h"
17+#include "libkita/datmanager.h"
18+#include "libkita/boardmanager.h"
19+#include "libkita/signalcollection.h"
20+#include "libkita/account.h"
21+#include "libkita/kita-utf8.h"
22+#include "libkita/kita_misc.h"
23+#include "libkita/config_xt.h"
24+#include "libkita/asciiart.h"
25+#include "libkita/k2ch.h"
26+#include "libkita/machibbs.h"
27+#include "libkita/jbbs.h"
28+#include "libkita/flashcgi.h"
29+
30+#include "thread/htmlpart.h"
31+
32+#include "kitaui/htmlview.h"
33+
34+#include <ksqueezedtextlabel.h>
35+#include <klocale.h>
36+#include <kdebug.h>
37+#include <kstandarddirs.h>
38+#include <klineedit.h>
39+#include <kmessagebox.h>
40+#include <kio/job.h>
41+
42+#include <qapplication.h>
43+#include <qtextedit.h>
44+#include <qpushbutton.h>
45+#include <qlabel.h>
46+#include <qcombobox.h>
47+#include <qeucjpcodec.h>
48+#include <qfile.h>
49+#include <qmessagebox.h>
50+#include <ktabwidget.h>
51+#include <qcheckbox.h>
52+#include <qlayout.h>
53+
54+
55+
56+/*--------------------------------------------------------------------*/
57+
58+QCp932Codec* KitaWriteView::m_cp932Codec = NULL;
59+
60+
61+KitaWriteView::KitaWriteView( QWidget* parent )
62+ : KitaWriteDialogBase( parent )
63+{
64+}
65+/*
66+
67+Call setMessage() to set message later.
68+See also KitaWriteTabWidget::slotShowWriteView().
69+
70+Call slotPostMessage() to post the message.
71+
72+*/
73+KitaWriteView::KitaWriteView( QWidget* parent, const KURL& url )
74+ : KitaWriteDialogBase( parent, 0 )
75+{
76+ if ( !m_cp932Codec ) m_cp932Codec = new QCp932Codec();
77+
78+ m_datURL = Kita::getDatURL( url );
79+
80+ m_bbstype = Kita::BoardManager::type( m_datURL );
81+
82+ m_bbscgi = Kita::getWriteURL( m_datURL );
83+
84+ initUI();
85+ initThreadNameField();
86+}
87+
88+void KitaWriteView::initUI()
89+{
90+ Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
91+ /* connect signals */
92+ connect( buttonOk, SIGNAL( clicked() ),
93+ SLOT( slotPostMessage() ) );
94+
95+ connect( buttonCancel, SIGNAL( clicked() ),
96+ SLOT( slotCancel() ) );
97+
98+ connect( this, SIGNAL( openURLRequestExt( const KURL&, const QString ) ),
99+ signalCollection, SIGNAL( openURLRequestExt( const KURL&, const QString ) ) );
100+ connect( this, SIGNAL( openThread( const KURL& ) ), signalCollection, SIGNAL( openThread( const KURL& ) ) );
101+
102+ connect( faceCombo, SIGNAL( activated( const QString& ) ),
103+ bodyText, SLOT( insert( const QString& ) ) );
104+
105+ connect( qtw, SIGNAL( currentChanged ( QWidget * ) ),
106+ this, SLOT( slotCurrentChanged ( QWidget * ) ) );
107+
108+ connect( bodyText, SIGNAL( textChanged() ),
109+ SLOT( slotBodyTextChanged() ) );
110+
111+ /* setup preview view */
112+ m_preview = new KitaPreviewPart( NULL );
113+ qtw->addTab( m_preview->view(), i18n( "preview" ) );
114+ m_preview->setup( m_datURL );
115+ qtw->setCurrentPage( 0 );
116+
117+ /* setup labels and edit lines */
118+ QFont font = Kita::Config::threadFont();
119+ bodyText->setFont( font );
120+ bodyText->setTabChangesFocus( TRUE );
121+
122+ boardNameLabel->setText( Kita::BoardManager::boardName( m_datURL ) );
123+
124+ if ( Kita::Config::defaultNameUseAlways() ) {
125+ nameLine->setText( Kita::Config::defaultName() );
126+ } else {
127+ QString defaultName = Kita::BoardManager::getBBSDefaultName( m_datURL );
128+ if ( defaultName == "fusianasan" || defaultName == "(default name)" ) {
129+ nameLine->setText( Kita::Config::defaultName() );
130+ } else {
131+ nameLine->setText( defaultName );
132+ }
133+ }
134+ QStringList compList = Kita::Config::self()->nameCompletionList();
135+ nameLine->completionObject()->setItems( compList );
136+
137+ if ( Kita::Config::defaultSage() ) {
138+ mailLine->setText( "sage" );
139+ sageBox->setChecked( true );
140+ } else {
141+ mailLine->setText( Kita::Config::defaultMail() );
142+ }
143+ m_mailswap = "";
144+
145+ QRegExp host_2ch( ".+\\.2ch\\.net" );
146+ if ( host_2ch.search( m_bbscgi.host() ) != -1
147+ && Kita::Config::beMailAddress().length() > 0
148+ && Kita::Config::beAuthCode().length() > 0 ) {
149+ beBox->setChecked( true );
150+ }
151+
152+ /* setup AA */
153+ faceCombo->clear();
154+ faceCombo->setFont( Kita::Config::threadFont() );
155+ faceCombo->insertItem( "" );
156+ QStringList list = Kita::AsciiArtConfig::asciiArtList();
157+ QStringList::iterator it;
158+ for ( it = list.begin(); it != list.end(); ++it ) {
159+ faceCombo->insertItem( *it );
160+ }
161+}
162+
163+void KitaWriteView::initThreadNameField()
164+{
165+ threadNameLine->setText( Kita::DatManager::threadName( m_datURL ) );
166+ threadNameLine->setReadOnly( TRUE );
167+ threadNameLine->setFrame( FALSE );
168+ threadNameLine->setFocusPolicy( NoFocus );
169+}
170+
171+KitaWriteView::~KitaWriteView()
172+{
173+ if ( m_preview ) {
174+ delete m_preview;
175+ }
176+}
177+
178+
179+/* public */
180+void KitaWriteView::setMessage( const QString& bodyStr )
181+{
182+ bodyText->clear();
183+ bodyText->insert( bodyStr );
184+ bodyText->setFocus();
185+}
186+
187+
188+/* public */
189+void KitaWriteView::insertMessage( const QString& str )
190+{
191+ bodyText->insert( str );
192+ bodyText->setFocus();
193+}
194+
195+
196+/* public information */
197+const KURL KitaWriteView::datURL() const
198+{
199+ return m_datURL;
200+}
201+
202+const QString KitaWriteView::threadName() const
203+{
204+ return threadNameLine->text();
205+}
206+
207+const QString KitaWriteView::boardID() const
208+{
209+ return Kita::BoardManager::boardID( m_datURL );
210+}
211+
212+const QString KitaWriteView::boardName() const
213+{
214+ return Kita::BoardManager::boardName( m_datURL );
215+}
216+/* public slot */ /* virtual */
217+void KitaWriteView::setFocus()
218+{
219+ bodyText->setFocus();
220+}
221+
222+bool KitaWriteView::checkFields()
223+{
224+ if ( body().length() == 0 ) return false;
225+
226+ /* fusianasan */
227+ if ( name().length() == 0
228+ && Kita::BoardManager::getBBSDefaultName( m_datURL ) == "fusianasan" ) {
229+ QMessageBox::warning( this, "Kita", i18n( "fusianasan." ) );
230+ return false;
231+ }
232+
233+ if ( !slotBodyTextChanged() ) {
234+ QMessageBox::warning( this, "Kita", i18n( "Body text is too long." ) );
235+ return false;
236+ }
237+
238+ return true;
239+}
240+
241+QString KitaWriteView::buildPostMessage()
242+{
243+ QString postStr;
244+ switch ( m_bbstype ) {
245+
246+ case Kita::Board_JBBS: postStr = getJBBSPostStr(); break;
247+
248+ case Kita::Board_FlashCGI: postStr = getFlashCGIPostStr(); break;
249+
250+ case Kita::Board_MachiBBS: postStr = getMachiBBSPostStr(); break;
251+
252+ default: postStr = getPostStr(); break;
253+ }
254+
255+ return postStr;
256+}
257+
258+/* call this slot to post the message. */ /* public slot */
259+void KitaWriteView::slotPostMessage()
260+{
261+ if ( !checkFields() ) return;
262+
263+ QString name = nameLine->text();
264+ QStringList list = Kita::Config::nameCompletionList();
265+ list.append( name );
266+ Kita::Config::setNameCompletionList( list );
267+
268+ /* build post message */
269+ QString postStr = buildPostMessage();
270+
271+ /* referrer */
272+ QString refStr = Kita::BoardManager::boardURL( m_datURL );
273+
274+ m_array.resize( 0 );
275+
276+ KIO::TransferJob* job = KIO::http_post( m_bbscgi, postStr.utf8(), true );
277+ job->addMetaData( "content-type", "Content-type: application/x-www-form-urlencoded" );
278+ job->addMetaData( "referrer", refStr );
279+
280+ /* 2ch.net cookie modify */
281+ if ( m_bbstype == Kita::Board_2ch && beBox->isChecked() ) {
282+ QString cookie = "Cookie: ";
283+ QString BeMailAddress = Kita::Config::beMailAddress();
284+ QString BeAuthCode = Kita::Config::beAuthCode();
285+ if ( BeMailAddress.length() > 0 && BeAuthCode.length() > 0 ) {
286+ cookie += "DMDM=" + BeMailAddress + "; ";
287+ cookie += "MDMD=" + BeAuthCode + "; ";
288+ }
289+ job->addMetaData( "customHTTPHeader", cookie );
290+ }
291+
292+ connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
293+ this, SLOT( slotRecieveData( KIO::Job*, const QByteArray& ) ) );
294+
295+ /* slotPostFinished() is called when done. */
296+ connect( job, SIGNAL( result( KIO::Job* ) ),
297+ this, SLOT( slotPostFinished( KIO::Job* ) ) );
298+
299+}
300+
301+
302+/* public slot */
303+void KitaWriteView::slotCancel()
304+{
305+ if ( body().length() == 0 ) {
306+ emit closeCurrentTab(); /* to KitaWriteTabWidget */
307+ return ;
308+ }
309+
310+ switch ( QMessageBox::warning( this, "Kita",
311+ i18n( "If you close this dialog, you will lose text.\n"
312+ "Do you want to close?" ),
313+ QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default ) ) {
314+ case QMessageBox::Ok:
315+ setMessage( QString::null );
316+ emit closeCurrentTab(); /* to KitaWriteTabWidget */
317+ break;
318+ case QMessageBox::Cancel:
319+ // do nothing
320+ break;
321+ }
322+}
323+
324+
325+/* public slot */
326+void KitaWriteView::slotEnableWriting( bool enable )
327+{
328+ buttonOk->setEnabled( enable );
329+}
330+
331+
332+/* see also slotPostMessage() */ /* private slot */
333+void KitaWriteView::slotRecieveData( KIO::Job*, const QByteArray& data )
334+{
335+ m_array.append( data.data() );
336+}
337+
338+void KitaWriteView::processPostFinished()
339+{
340+ QString response;
341+ QString ckstr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITECOOKIE );
342+
343+ // x-euc-jp & euc-jp
344+ if ( m_array.contains( "euc-jp" ) ) {
345+ response = QTextCodec::codecForName( "eucJP" ) ->toUnicode( m_array );
346+ } else {
347+ response = QTextCodec::codecForName( "sjis" ) ->toUnicode( m_array );
348+ }
349+
350+ int retcode = resultCode( response );
351+ switch ( retcode ) {
352+
353+ case K2ch_True:
354+
355+ /* save log */
356+ logPostMessage();
357+
358+ /* clear message */
359+ setMessage( QString::null );
360+
361+ /* reload thread */
362+ emit openThread( m_datURL );
363+
364+ emit closeCurrentTab(); /* to KitaWriteTabWidget */
365+
366+ break;
367+
368+ case K2ch_Unknown:
369+ case K2ch_False:
370+ case K2ch_Check:
371+ case K2ch_Error:
372+
373+ KMessageBox::error( 0, resultMessage( response ), resultTitle( response ) );
374+
375+ break;
376+
377+ /* eat cookie, then re-post message */
378+ case K2ch_Cookie:
379+
380+ if ( KMessageBox::questionYesNo( 0,
381+ QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITECOOKIEMSG ),
382+ resultTitle( response ) )
383+ == KMessageBox::Yes ) {
384+ slotPostMessage();
385+ }
386+
387+ break;
388+
389+ default:
390+ break;
391+ }
392+}
393+
394+/* This slot is called when posting is done. */
395+/* see also slotPostMessage() */ /* private slot */
396+void KitaWriteView::slotPostFinished( KIO::Job* )
397+{
398+ processPostFinished();
399+}
400+
401+int KitaWriteView::getWriteResNum()
402+{
403+ return Kita::DatManager::getReadNum( m_datURL ) + 1;
404+}
405+
406+/* update preview screen */ /* private slot */
407+void KitaWriteView::slotCurrentChanged ( QWidget * w )
408+{
409+ if ( w == bodyText ) {
410+ w->setFocus();
411+ return ;
412+ }
413+ if ( m_preview == NULL ) return ;
414+
415+ int resnum = getWriteResNum();
416+
417+ QDateTime now = QDateTime::currentDateTime();
418+ QString bodystr = body();
419+ bodystr.replace( "<", "&lt;" ).replace( ">", "&gt;" ).replace( "\n", " <br> " );
420+ QString namestr = name();
421+ if ( namestr == NULL || namestr.length() == 0 ) namestr = Kita::BoardManager::getBBSDefaultName( m_datURL );
422+ QString rawData = namestr + "<>" + mail() + "<>"
423+ + now.toString( "yy/MM/dd hh:mm:ss" )
424+ + "<> " + bodystr + " <>";
425+
426+ QString htmlstr = Kita::datToHtml( rawData, resnum );
427+ m_preview->setInnerHTML( htmlstr );
428+}
429+
430+
431+/* private slot */
432+bool KitaWriteView::slotBodyTextChanged()
433+{
434+ int lines = bodyText->lines();
435+ int maxLines = Kita::BoardManager::getBBSMaxLine( m_datURL );
436+ int tmpln = bodyText->length();
437+ int length = m_cp932Codec->fromUnicode( body(), tmpln ).length();
438+
439+ /* replace '\n' -> " <br> ", '>' -> "&lt;", and etc. */
440+ length += ( ( body().contains( '\n' ) ) * 5
441+ + ( body().contains( '>' ) ) * 3
442+ + ( body().contains( '<' ) ) * 3
443+ );
444+
445+ int maxLength = Kita::BoardManager::getBBSMsgCount( m_datURL );
446+
447+ QString str;
448+ str = QString().setNum( lines ) + "/" + ( maxLines != 0 ? QString().setNum( maxLines ) : QString( "--" ) );
449+ str += " | " + QString().setNum( length ) + "/" + ( maxLength != 0 ? QString().setNum( maxLength ) : QString( "--" ) );
450+ lengthLabel->setText( str );
451+
452+ if ( maxLines != 0 && lines > maxLines ) return FALSE;
453+ if ( maxLength != 0 && length > maxLength ) return FALSE;
454+
455+ return TRUE;
456+}
457+
458+/* create posting message for 2ch */ /* private */
459+QString KitaWriteView::getPostStr()
460+{
461+ QString sessionID;
462+ QString threadID = Kita::DatManager::threadID( m_datURL );
463+ int serverTime = Kita::DatManager::getServerTime( m_datURL );
464+
465+ /* login */
466+ if ( Kita::DatManager::is2chThread( m_datURL ) && Kita::Account::isLogged() ) {
467+ sessionID = KURL::encode_string( Kita::Account::getSessionID() );
468+ }
469+
470+ return K2ch::buildPostStr( name(), mail(),
471+ body(), boardID(),
472+ threadID, serverTime,
473+ sessionID );
474+}
475+
476+QString KitaWriteView::getMachiBBSPostStr()
477+{
478+ QString threadID = Kita::DatManager::threadID( m_datURL );
479+ int serverTime = Kita::DatManager::getServerTime( m_datURL );
480+
481+ return MachiBBS::buildPostStr( name(), mail(),
482+ body(), boardID(),
483+ threadID, serverTime );
484+}
485+
486+
487+/* create posting message for JBBS */ /* private */ /* private */
488+QString KitaWriteView::getJBBSPostStr()
489+{
490+ QString threadID = Kita::DatManager::threadID( m_datURL );
491+ int serverTime = Kita::DatManager::getServerTime( m_datURL );
492+
493+ return JBBS::buildPostStr( name(), mail(),
494+ body(), boardID(),
495+ threadID, serverTime );
496+}
497+
498+
499+/* create posting message for Flash CGI */ /* private */ /* private */
500+QString KitaWriteView::getFlashCGIPostStr()
501+{
502+ QString threadID = Kita::DatManager::threadID( m_datURL );
503+
504+ QString ret;
505+
506+ return FlashCGI::buildPostStr( name(), mail(),
507+ body(), boardID(),
508+ threadID );
509+}
510+
511+
512+/* save post log */ /* private */
513+void KitaWriteView::logPostMessage()
514+{
515+ QString threadURL = Kita::DatManager::threadURL( m_datURL );
516+
517+ QDateTime now = QDateTime::currentDateTime();
518+ QString logPath = locateLocal( "appdata", "log.txt" );
519+
520+ QFile file( logPath );
521+ if ( file.open( IO_WriteOnly | IO_Append ) ) {
522+ QTextStream stream( &file );
523+ stream.setEncoding( QTextStream::UnicodeUTF8 );
524+
525+ stream << "Date : " << now.toString( "yyyy/MM/dd hh:mm:ss" ) << endl; // current time
526+ stream << "Board : " << boardName() << endl;
527+ stream << "Thread : " << threadName() << endl;
528+ stream << "URL : " << threadURL << endl;
529+ stream << "Name : " << name() << endl;
530+ stream << "Mail : " << mail() << endl << endl;
531+ stream << body() << endl;
532+ stream << "----------------------------------------" << endl;
533+
534+ file.close();
535+ }
536+}
537+
538+
539+/* get result code from 2ch tag or title. */ /* private */
540+int KitaWriteView::resultCode( const QString& response ) const
541+{
542+ /* see also libkita/kita-utf8.h */
543+ QString errstr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITEERROR );
544+ QString truestr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITETRUE );
545+ QString ckstr = QTextCodec::codecForName( "utf8" ) ->toUnicode( KITAUTF8_WRITECOOKIE );
546+
547+ QRegExp regexp( "<!-- 2ch_X:(.*) -->" );
548+ int pos = regexp.search( response );
549+
550+ if ( pos != -1 ) {
551+ /* get code from 2ch tag */
552+ QString k2ch_X = regexp.cap( 1 );
553+
554+ if ( k2ch_X == "true" ) return K2ch_True;
555+ if ( k2ch_X == "false" ) return K2ch_False;
556+ if ( k2ch_X == "error" ) return K2ch_Error;
557+ if ( k2ch_X == "check" ) return K2ch_Check;
558+ if ( k2ch_X == "cookie" ) return K2ch_Cookie;
559+
560+ return K2ch_Unknown;
561+ } else {
562+ /* get code from title */
563+ QString title = resultTitle( response );
564+ if ( title == QString::null ) return K2ch_Unknown;
565+
566+ if ( title.contains( errstr ) ) return K2ch_Error;
567+ if ( title.contains( truestr ) ) return K2ch_True;
568+ if ( title.contains( ckstr ) ) return K2ch_Cookie;
569+
570+ /* for Flash CGI */
571+ if ( m_bbstype == Kita::Board_FlashCGI ) {
572+ if ( title.contains( "ERROR!!" ) ) {
573+ return K2ch_Error;
574+ } else {
575+ return K2ch_True;
576+ }
577+ }
578+
579+ /* for JBBS. adhoc... */
580+ if ( m_bbstype == Kita::Board_JBBS ) {
581+
582+ // x-euc-jp & euc-jp
583+ if ( response.contains( "euc-jp" ) ) {
584+ return K2ch_True;
585+ } else {
586+ return K2ch_Error;
587+ }
588+ }
589+
590+ return K2ch_Unknown;
591+ }
592+}
593+
594+
595+/* private */
596+QString KitaWriteView::resultMessage( const QString& response ) const
597+{
598+ QRegExp tags( "(<[^<]+>|</[^<]+>)" );
599+
600+ if ( m_bbstype == Kita::Board_FlashCGI ) {
601+
602+ QRegExp regexp( "<blockquote>(.*)</blockquote>" );
603+ int pos = regexp.search( response );
604+ if ( pos != -1 ) {
605+ return regexp.cap( 1 ).replace( "<br>", "\n" );
606+ }
607+
608+ return QString::null;
609+ }
610+
611+ {
612+ QRegExp bold_start( "<b>" );
613+ QRegExp bold_end( "</b>" );
614+ int startPos = bold_start.search( response );
615+ if ( startPos != -1 ) {
616+ startPos += 3;
617+ int endPos = bold_end.search( response );
618+ if ( endPos != -1 && startPos < endPos ) {
619+ QString message = response.mid( startPos, endPos - startPos );
620+ message.remove( tags );
621+ return message;
622+ }
623+ }
624+ }
625+
626+ QRegExp body_regexp( "<body>([^<]*)</body>" );
627+ if ( body_regexp.search( response ) != -1 ) {
628+ return body_regexp.cap( 1 );
629+ }
630+
631+ return QString::null;
632+}
633+
634+
635+/* private */
636+QString KitaWriteView::resultTitle( const QString& response ) const
637+{
638+ QRegExp regexp( "<title>(.*)</title>" );
639+ regexp.setCaseSensitive( FALSE );
640+ int pos = regexp.search( response );
641+ if ( pos != -1 ) {
642+ return regexp.cap( 1 );
643+ } else {
644+ return QString::null;
645+ }
646+}
--- /dev/null
+++ b/kita/src/writeview.h
@@ -0,0 +1,110 @@
1+/***************************************************************************
2+* Copyright (C) 2004 by Kita Developers *
3+* ikemo@users.sourceforge.jp *
4+* *
5+* This program is free software; you can redistribute it and/or modify *
6+* it under the terms of the GNU General Public License as published by *
7+* the Free Software Foundation; either version 2 of the License, or *
8+* (at your option) any later version. *
9+***************************************************************************/
10+
11+#ifndef _KITAWRITEDIALOG_H_
12+#define _KITAWRITEDIALOG_H_
13+
14+#include <qwidget.h>
15+#include <kio/job.h>
16+#include <kparts/browserextension.h>
17+
18+#include "writedialogbase.h"
19+
20+class KitaPreviewPart;
21+class QCp932Codec;
22+
23+/* mode */
24+enum{
25+ WRITEMODE_NORMAL,
26+ WRITEMODE_NEWTHREAD
27+};
28+
29+/* result code */
30+enum{
31+ K2ch_Unknown,
32+ K2ch_True,
33+ K2ch_False,
34+ K2ch_Error,
35+ K2ch_Check,
36+ K2ch_Cookie,
37+ K2ch_NewThread
38+};
39+
40+
41+/**
42+ *
43+ * Hideki Ikemoto
44+ **/
45+class KitaWriteView : public KitaWriteDialogBase
46+{
47+ Q_OBJECT
48+
49+ KitaPreviewPart *m_preview;
50+
51+ QString getPostStr();
52+ QString getMachiBBSPostStr();
53+ QString getJBBSPostStr();
54+ QString getFlashCGIPostStr();
55+
56+protected:
57+
58+ QCString m_array;
59+ KURL m_bbscgi;
60+ int m_bbstype;
61+ KURL m_datURL;
62+ static QCp932Codec* m_cp932Codec;
63+
64+ void initUI();
65+ void initThreadNameField();
66+ bool checkFields();
67+ QString buildPostMessage();
68+ int getWriteResNum();
69+ void processPostFinished();
70+ void logPostMessage();
71+ int resultCode( const QString& response ) const;
72+ QString resultMessage( const QString& response ) const;
73+ QString resultTitle( const QString& response ) const;
74+
75+public:
76+
77+ KitaWriteView( QWidget* parent );
78+ KitaWriteView( QWidget* parent, const KURL& url );
79+ virtual ~KitaWriteView();
80+ void setMessage( const QString& bodyStr );
81+ void insertMessage( const QString& str );
82+
83+ const KURL datURL() const;
84+ const QString threadName() const;
85+ const QString boardName() const;
86+ const QString boardID() const;
87+
88+public slots:
89+
90+ virtual void setFocus();
91+ void slotPostMessage();
92+ void slotCancel();
93+ void slotEnableWriting( bool enable );
94+
95+private slots:
96+
97+ void slotRecieveData( KIO::Job*, const QByteArray& );
98+ void slotPostFinished( KIO::Job* );
99+ void slotCurrentChanged ( QWidget * w );
100+
101+protected slots:
102+ bool slotBodyTextChanged();
103+
104+signals:
105+
106+ void openURLRequestExt( const KURL& url, const QString mimetype = QString::null );
107+ void openThread( const KURL& url );
108+ void closeCurrentTab();
109+};
110+#endif
Show on old repository browser