QString( "Monazilla/1.00 (Kita/%1)" ).arg( VERSION ) );
QString subjectPath = Cache::getSubjectPath( url );
KIO::NetAccess::download( subjectURL( url ), subjectPath, NULL );
-
- /* download SETTING.TXT */
- loadBBSSetting( url );
}
/* open and read subject.txt */
return TRUE;
}
-
-
-/*--------------------------------*/
-/* SETTING.TXT */
-
-
-/* public */ /* static */
-bool BoardManager::loadBBSSetting( const KURL& url, bool reload )
-{
- /* Is board enrolled ? */
- BoardData * bdata = getBoardData( url );
- if ( bdata == NULL ) return FALSE;
- if ( bdata->type() != Board_2ch ) return FALSE;
-
- KURL settingURL = bdata->settingURL();
- QString path = Cache::getSettingPath( url );
-
- /* now loading */
- if ( DownloadManager::isLoadingNow( settingURL ) ) return FALSE;
-
- /* already loaded */
- if ( bdata->settingLoaded() && !reload ) return TRUE;
-
- /* reset names, linenum, etc. */
- bdata->setSettingLoaded( FALSE );
-
- /* download SETTING.TXT.*/
- DownloadManager::download( settingURL, path );
- bdata->setSettingLoaded( TRUE );
-
- return TRUE;
-}
-
-
-/* public */ /* static */
-QString BoardManager::getBBSDefaultName( const KURL& url )
-{
- BoardData * bdata = openSettingTxt( url );
- if ( bdata == NULL ) bdata = getBoardData( url );
- if ( bdata == NULL ) return "(default name)";
- if ( bdata->defaultName() == QString::null ) return "(default name)";
- return bdata->defaultName();
-}
-
-
-/* public */ /* static */
-int BoardManager::getBBSMaxLine( const KURL& url )
-{
- BoardData * bdata = openSettingTxt( url );
- if ( bdata == NULL ) bdata = getBoardData( url );
- if ( bdata == NULL ) return 0;
- return bdata->lineNum();
-}
-
-/* public */ /* static */
-int BoardManager::getBBSMsgCount( const KURL& url )
-{
- BoardData * bdata = openSettingTxt( url );
- if ( bdata == NULL ) bdata = getBoardData( url );
- if ( bdata == NULL ) return 0;
- return bdata->msgCount();
-}
-
-
-/* public */ /* static */
-const KURL BoardManager::titleImgURL( const KURL& url )
-{
- BoardData * bdata = openSettingTxt( url );
- if ( bdata == NULL ) bdata = getBoardData( url );
- if ( bdata == NULL ) return QString::null;
- return bdata->titleImgURL();
-}
-
-/* open local SETTING.TXT, then get names, linenum, etc. */ /* private */ /* static */
-BoardData* BoardManager::openSettingTxt( const KURL& url )
-{
- BoardData * bdata = getBoardData( url );
- if ( bdata == NULL ) return NULL;
- if ( !bdata->settingLoaded() ) return NULL;
- if ( DownloadManager::isLoadingNow( bdata->settingURL() ) ) return NULL;
- if ( bdata->defaultName() != QString::null ) return bdata;
-
- QFile file( Cache::getSettingPath( url ) );
- if ( file.open( IO_ReadOnly ) ) {
-
- QTextStream ts( &file );
- if ( m_cp932Codec == NULL ) m_cp932Codec = new QCp932Codec();
- ts.setCodec( m_cp932Codec );
-
- QString line;
- while ( !ts.eof() ) {
-
- line = ts.readLine();
-
- /* default name */
- QString key = "BBS_NONAME_NAME=";
- if ( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
-
- /* 0ch type */
- key = "NANASI_NAME=";
- if ( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
-
- /* line number */
- key = "BBS_LINE_NUMBER=";
- if ( line.find( key ) != -1 ) bdata->setLineNum( line.remove( key ).toInt() * 2 );
-
- /* msg count */
- key = "BBS_MESSAGE_COUNT=";
- if ( line.find( key ) != -1 ) bdata->setMsgCount( line.remove( key ).toInt() );
-
- /* title image */
- key = "BBS_TITLE_PICTURE=";
- if ( line.find( key ) != -1 ) {
- QString path = line.remove( key );
- KURL titleImgURL = KURL( bdata->basePath(), path );
- bdata->setTitleImgURL( titleImgURL );
- }
- }
-
- file.close();
- }
-
- if ( bdata->defaultName() == QString::null ) bdata->setDefaultName( "(default name)" );
-
- return bdata;
-}
static bool loadBBSHistory( const KURL& url );
static bool moveBoard( const KURL& fromURL, const KURL& toURL );
- /* SETTING.TXT */
- static bool loadBBSSetting( const KURL& url, bool reload = FALSE );
- static QString getBBSDefaultName( const KURL& url );
- static int getBBSMaxLine( const KURL& url );
- static int getBBSMsgCount( const KURL& url );
- static const KURL titleImgURL( const KURL& url );
-
private:
/* BoardData */
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
-
-/* This is the class to download files. */
-
-#include "downloadmanager.h"
-#include "kita_misc.h"
-
-#include <qregexp.h>
-#include <qfileinfo.h>
-#include <qdir.h>
-#include <qapplication.h>
-
-using namespace Kita;
-
-
-DownloadManager* DownloadManager::instance = NULL;
-
-
-/* Download file. Return value is pointer of FileLoader.
- If path = QString::null, DownloadManager does not open local file.
-
- ex.1 )
-
- If you just want to download "http://www.hoge.com/foo.jpg", then:
-
- Kita::DownloadManager::download( "http://www.hoge.com/foo.jpg", "/tmp/foo.jpg" );
-
-
- ex.2 )
-
- If you want to do someting when received the data and when done,
- then connect signals like this:
-
- FileLoader* loader = Kita::DownloadManager::download( "http://www.hoge.com/foo.jpg", "/tmp/foo.jpg" );
- connect( loader, SIGNAL( data( const Kita::LoaderData&, const QByteArray& ) ),
- SLOT( slotData( const Kita::LoaderData&, const QByteArray& ) ) );
- connect( loader, SIGNAL( result( const Kita::LoaderData& ) ),
- SLOT( slotResult( const Kita::LoaderData& ) ) );
-*/ /* public */ /* static */
-FileLoader* DownloadManager::download( const KURL& url, const QString& path,
- const LoaderOption& option /* option user data */
- )
-{
- /* to use SIGNAL & SLOT, create instance of DownloadManager here. */
- /* ( You CANNOT use SIGNAL & SLOT without instance. ) */
- if ( instance == NULL ) instance = new DownloadManager();
-
- return instance->downloadPrivate( url, path, option );
-}
-
-
-/* public */ /* static */
-void DownloadManager::stopLoading( const KURL& url )
-{
- if ( instance ) instance->stopLoadingPrivate( url );
-}
-
-
-/* public */ /* static */
-bool DownloadManager::isLoadingNow( const KURL& url )
-{
- if ( instance == NULL ) return FALSE;
-
- return instance->isLoadingNowPrivate( url );
-}
-
-
-
-
-/*---------------------------------*/
-/* internal functions */
-
-DownloadManager::DownloadManager()
-{
- m_loaderList.clear();
-}
-
-DownloadManager::~DownloadManager()
-{
- /* delete all loaders */
- FileLoader * loader;
- QPtrListIterator< FileLoader > it( m_loaderList );
- while ( ( loader = it.current() ) != NULL ) {
- delete loader;
- ++it;
- }
-}
-
-/* private */
-FileLoader* DownloadManager::downloadPrivate( const KURL& url, const QString& path,
- const LoaderOption& option )
-{
- if ( isLoadingNowPrivate( url ) ) return NULL;
-
- FileLoader* loader;
- loader = new FileLoader( url, path, option );
- m_loaderList.append( loader );
-
- if ( loader->get() ) {
- connect( loader, SIGNAL( result( const Kita::LoaderData& ) ),
- SLOT( slotResult( const Kita::LoaderData& ) ) );
- }
- else {
- deleteLoader( loader );
- return NULL;
- }
-
- return loader;
-}
-
-
-/* private */
-void DownloadManager::stopLoadingPrivate( const KURL& url )
-{
- FileLoader * loader = getLoader( url );
- if ( !loader ) return ;
-
- loader->stopJob(); /* slotResult() will be called later. */
-}
-
-
-/* private */
-bool DownloadManager::isLoadingNowPrivate( const KURL& url )
-{
- if ( getLoader( url ) ) return TRUE;
-
- return FALSE;
-}
-
-
-/* private */
-FileLoader* DownloadManager::getLoader( const KURL& url )
-{
- if ( m_loaderList.count() == 0 ) return NULL;
-
- FileLoader* loader;
- QPtrListIterator< FileLoader > it( m_loaderList );
- while ( ( loader = it.current() ) != NULL ) {
- if ( loader->getData().url == url ) {
- return loader;
- }
- ++it;
- }
-
- return NULL;
-}
-
-
-/* private */
-void DownloadManager::deleteLoader( FileLoader* loader )
-{
- m_loaderList.remove( loader );
- delete loader;
-}
-
-
-/* This slot is called when loading is done. */ /* private slot */
-void DownloadManager::slotResult( const LoaderData& data )
-{
- FileLoader * loader = getLoader( data.url );
-
- /* Deleting the FileLoader here may crush kita,
- because loader may be also used in the other classes.
- So, delete it later. See also customEvent(). */
- DeleteLoaderEvent * e = new DeleteLoaderEvent( loader );
- QApplication::postEvent( this, e ); // Qt will delete it when done
-}
-
-
-/* protected */ /* virtual */
-void DownloadManager::customEvent( QCustomEvent * e )
-{
- /* delete loader */
- if ( e->type() == EVENT_DeleteLoader ) {
- FileLoader * loader = static_cast< DeleteLoaderEvent* >( e ) ->getLoader();
- if ( loader ) deleteLoader( loader );
- }
-}
-
-
-
-/*------------------------------------------------------------*/
-/*------------------------------------------------------------*/
-
-/* class FileLoader */
-
-
-/*
-
-url: url of target
-path: path of save file. It can be QString::null. Then data is not saved in HDD.
-option: user defined option. See also downloadmanager.h
-
-Call get() to start. Call stopJob() to stop.
-SIGNAL data() is emitted when data is received.
-SIGNAL result() is emitted when done.
-
-The pointer of struct Kita::LoaderData is sent by SIGNAL data() and result().
-For example, to get result code:
-
-void TmpClass::slotResult( const Kita::LoaderData& data )
-{
- int result_code = data.code;
-}
-*/
-FileLoader::FileLoader( const KURL& url, const QString& path, const LoaderOption& option )
-{
- m_data.url = url;
- m_data.path = path;
- m_data.tmppath = path;
- if ( path != QString::null ) m_data.tmppath += ".tmp";
- m_data.option = option;
-
- m_ds = NULL;
- m_file = NULL;
- m_data.totalsize = 0;
- m_data.size = 0;
-
- m_currentJob = NULL;
- m_data.code = 0;
- m_data.header = QString::null;
-}
-
-FileLoader::~FileLoader()
-{
- killJob();
-}
-
-
-/* terminate job. slotResult is NOT called. */ /* public */
-void FileLoader::killJob()
-{
- /* now loading */
- if ( m_currentJob ) {
-
- m_currentJob->kill(); /* without emitting result SIGNAL */
- m_currentJob = NULL;
- m_data.code = 0;
- closeFile();
- }
-}
-
-
-/* stop job. slotResult is called later. */ /* public */
-void FileLoader::stopJob()
-{
- if ( m_currentJob ) m_currentJob->kill( FALSE ); /* with emitting result SIGNL */
-}
-
-
-/* start downloading */
-/* When done, slotResult() will be called. */ /* public */
-bool FileLoader::get()
-{
- /* now loading */
- if ( m_currentJob ) return FALSE;
-
- /* create directory */
- if ( m_data.tmppath != QString::null ) {
- QFileInfo qi( m_data.tmppath );
- if ( !Kita::mkdir( qi.dirPath( TRUE ) ) ) return FALSE;
- }
-
- m_data.totalsize = 0;
- m_data.size = 0;
- m_data.code = 0;
- m_data.header = QString::null;
- m_data.redirection = FALSE;
- m_file = NULL;
- m_ds = NULL;
-
- /* If path of file is not QString::null, open file here */
- /* Note that data is saved as "m_data.tmppath".
- This file will be renamed in FileLoader::slotResult(). */
- if ( m_data.tmppath != QString::null ) {
- m_file = new QFile( m_data.tmppath );
- if ( m_file == NULL || ! m_file->open( IO_WriteOnly ) ) {
- closeFile();
- return FALSE;
- }
- m_ds = new QDataStream( m_file );
- }
-
- /* create job */
- m_currentJob = KIO::get( m_data.url, TRUE, FALSE );
- if ( m_currentJob == NULL ) {
- closeFile();
- return FALSE;
- }
-
- connect( m_currentJob, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
- SLOT( slotData( KIO::Job*, const QByteArray& ) ) );
-
- connect( m_currentJob, SIGNAL( result( KIO::Job* ) ),
- SLOT( slotResult( KIO::Job* ) ) );
-
- connect( m_currentJob, SIGNAL( redirection( KIO::Job *, const KURL& ) ),
- SLOT( slotRedirection( KIO::Job *, const KURL& ) ) );
-
- connect( m_currentJob, SIGNAL( totalSize( KIO::Job*, KIO::filesize_t ) ),
- SLOT( slotTotalSize( KIO::Job*, KIO::filesize_t ) ) );
-
- /* use 'HTTP-Headers' metadata.*/
- m_currentJob->addMetaData( "PropagateHttpHeader", "true" );
-
- return TRUE;
-}
-
-/* public */
-const bool FileLoader::isRunning() const
-{
- if ( m_currentJob ) return TRUE;
- return FALSE;
-}
-
-/* public */
-const LoaderData& FileLoader::getData() const
-{
- return m_data;
-}
-
-/* close file */
-/* if code != 200, then remove file. */ /* private */
-void FileLoader::closeFile()
-{
- if ( m_file ) m_file->close();
- if ( m_ds ) delete m_ds;
- if ( m_file ) delete m_file;
-
- m_ds = NULL;
- m_file = NULL;
-
- /* If loading failed, remove file */
- if ( m_data.code != 200 && m_data.tmppath != QString::null && QFile::exists( m_data.tmppath ) ) {
-
- QFile::remove( m_data.tmppath );
- }
-}
-
-/* private */ /* copied from Access::responseCode() */
-int FileLoader::responseCode()
-{
- // parse HTTP headers
- QStringList headerList = QStringList::split( "\n", m_data.header );
- QRegExp regexp( "HTTP/1\\.[01] ([0-9]+) .*" );
- QString dateStr = headerList.grep( regexp ) [ 0 ];
- if ( regexp.search( dateStr ) == -1 ) {
- // invalid response
- return 0;
- } else {
- return regexp.cap( 1 ).toInt();
- }
-}
-
-
-/* slots called from job */ /* private slots */
-
-void FileLoader::slotData( KIO::Job* job, const QByteArray& barray )
-{
- if ( job->error() == 0 ) {
-
- m_data.size += barray.size();
- if ( m_ds ) m_ds->writeRawBytes( barray.data(), barray.size() );
-
- emit data( m_data, barray );
- }
-}
-
-
-void FileLoader::slotTotalSize( KIO::Job * job, KIO::filesize_t size )
-{
- if ( job->error() == 0 ) m_data.totalsize = size;
-}
-
-
-void FileLoader::slotRedirection( KIO::Job*, const KURL& url )
-{
- stopJob();
- m_data.redirection = TRUE;
- m_data.redirectURL = url;
-}
-
-
-void FileLoader::slotResult( KIO::Job* job )
-{
- m_currentJob = NULL;
- if ( job->error() == 0 ) m_data.header = job->queryMetaData( "HTTP-Headers" );
- m_data.code = responseCode();
- closeFile();
-
- /* rename */
- if ( m_data.code == 200 && m_data.tmppath != QString::null ) {
- if ( QFile::exists( m_data.path ) ) QFile::remove( m_data.path );
- QDir qdir;
- qdir.rename( m_data.tmppath, m_data.path );
- }
-
- emit result( m_data );
-}
#ifndef KITAFILELOADER_H
#define KITAFILELOADER_H
-#include "event.h"
-
-#include <kio/job.h>
-#include <qmutex.h>
-
-class QFile;
-
-namespace Kita
-{
- class FileLoader;
-
-
- /* user option */
- struct LoaderOption
- {
- KURL usrurl;
- QString usrstr;
- QStringList userstrlist;
- int usrnum;
- };
-
-
- /* data */
- struct LoaderData
- {
- /* URL and path of target */
- KURL url;
- QString path;
-
- /* path of tmpfile */
- QString tmppath;
-
- /* redirection */
- bool redirection;
- KURL redirectURL; /* = new URL */
-
- /* file info */
- int code;
- QString header;
- KIO::filesize_t size;
- KIO::filesize_t totalsize;
-
- /* user option */
- LoaderOption option;
- };
-
-
- /*-----------------------------------------*/
-
-
- class DownloadManager : public QObject
- {
- Q_OBJECT
-
- static DownloadManager* instance;
- QPtrList< FileLoader > m_loaderList;
-
- public:
- DownloadManager();
- ~DownloadManager();
-
- static FileLoader* download( const KURL& url, const QString& path,
- const LoaderOption& option = LoaderOption() );
- static void stopLoading( const KURL& url );
- static bool isLoadingNow( const KURL& url );
-
- private:
- FileLoader* downloadPrivate( const KURL& url, const QString& path, const LoaderOption& option );
- void stopLoadingPrivate( const KURL& url );
- bool isLoadingNowPrivate( const KURL& url );
-
- FileLoader* getLoader( const KURL& url );
- void deleteLoader( Kita::FileLoader* );
-
- private slots:
- void slotResult( const Kita::LoaderData& );
-
- protected:
- virtual void customEvent( QCustomEvent * e );
- };
-
-
- /*-----------------------------------------*/
-
- /* loader */
- class FileLoader : public QObject
- {
- Q_OBJECT
-
- LoaderData m_data;
-
- KIO::Job* m_currentJob;
- QFile *m_file;
- QDataStream *m_ds;
-
- public:
- FileLoader( const KURL& url, const QString& path, const LoaderOption& option );
- ~FileLoader();
-
- void killJob();
- void stopJob();
- bool get();
-
- const bool isRunning() const;
- const LoaderData& getData() const;
-
- private:
- void closeFile();
- int responseCode();
-
- private slots:
- void slotData( KIO::Job* , const QByteArray& );
- void slotTotalSize( KIO::Job * , KIO::filesize_t );
- void slotRedirection( KIO::Job* , const KURL& );
- void slotResult( KIO::Job* );
-
- signals:
- void data( const Kita::LoaderData&, const QByteArray& );
- void result( const Kita::LoaderData& );
- };
-
-
- /*-----------------------------------------*/
-
- /* delete loader event */
- class DeleteLoaderEvent : public QCustomEvent
- {
- Kita::FileLoader* m_loader;
-
- public:
- DeleteLoaderEvent( Kita::FileLoader* loader ) : QCustomEvent( EVENT_DeleteLoader )
- , m_loader( loader ) {}
-
- Kita::FileLoader* getLoader() const { return m_loader; }
- };
-}
-
-
#endif
***************************************************************************/
#include "previewpart.h"
-
-#include <qcursor.h>
-
-#include <khtml_events.h>
-
-#include <dom/html_misc.h>
-
-#include "respopup.h"
-#include "htmlpart.h"
-#include "viewmediator.h"
-
-#include "kitaui/htmlview.h"
-
-#include "libkita/kitaconfig.h"
-#include "libkita/datmanager.h"
-#include "libkita/kita_misc.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();
-
- m_datURL = QString::null;
-}
-
-bool KitaPreviewPart::setup( const KURL& url )
-{
- if ( url.isEmpty() ) return FALSE;
-
- clearPart();
-
- m_datURL = Kita::getDatURL( url );
-
- /* create HTML Document */
- createHTMLDocument();
-
- return TRUE;
-}
-
-void KitaPreviewPart::connectSignals()
-{
- /* popup */
- connect( this, SIGNAL( onURL( const QString& ) ), SLOT( slotOnURL( const QString& ) ) );
-
- connect( view(), SIGNAL( leave() ), SLOT( slotLeave() ) );
- connect( view(), SIGNAL( verticalSliderReleased() ), SLOT( slotVSliderReleased() ) );
- connect( view(), SIGNAL( horizontalSliderReleased() ), SLOT( slotHSliderReleased() ) );
-}
-
-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();
-}
-
-/*
- * @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() ) {
- ViewMediator::getInstance()->openURL( 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 ;
-
- ViewMediator::getInstance()->openURL( 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();
-}
-
-/*
- * 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 ? */
- if ( ViewMediator::getInstance()->isKitaActive() == FALSE ) 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 );
- }
-}
#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;
-
-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();
-
- /* 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 slotOnURL( const QString& url );
-
-signals:
- void mousePressed(); /* to KitaThreadView */
-};
-
#endif
/* reset search direction */
m_revsearch = FALSE;
-
- /* load SETTING.TXT */
- Kita::BoardManager::loadBBSSetting( m_datURL, FALSE );
}
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 */
boardNameLabel->setText( Kita::BoardManager::boardName( m_datURL ) );
// setup name field.
- 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 );
- }
- }
+ nameLine->setText( Kita::Config::defaultName() );
QStringList compList = Kita::Config::self()->nameCompletionList();
nameLine->completionObject()->setItems( compList );
KitaWriteView::~KitaWriteView()
{
- delete m_preview;
}
/* public */
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." ) );
+ if ( body().length() == 0 ) {
return FALSE;
+ } else {
+ return TRUE;
}
-
- return TRUE;
}
QString KitaWriteView::buildPostMessage()
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();
+ ( 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( "--" ) );
+ str = QString().setNum( lines );
+ str += " | " + QString().setNum( length );
lengthLabel->setText( str );
- if ( maxLines != 0 && lines > maxLines ) return FALSE;
- if ( maxLength != 0 && length > maxLength ) return FALSE;
-
return TRUE;
}
{
Q_OBJECT
- KitaPreviewPart *m_preview;
KitaWriteTabWidget* m_parent;
QString getPostStr();
void slotRecieveData( KIO::Job*, const QByteArray& );
void slotPostFinished( KIO::Job* );
- void slotCurrentChanged ( QWidget * w );
protected slots:
bool slotBodyTextChanged();