ImgManager::~ImgManager()
{
/* delete all loaders */
- FileLoader* loader;
+ FileLoader * loader;
QPtrListIterator< FileLoader > it( m_loaderList );
- while( ( loader = it.current() ) != NULL ){
- delete loader;
- ++it;
+ while ( ( loader = it.current() ) != NULL ) {
+ delete loader;
+ ++it;
}
}
/* public */ /* static */
void ImgManager::deleteInstance()
{
- if( instance ) delete instance;
+ if ( instance ) delete instance;
}
bool ImgManager::load( const KURL& url, const KURL& datURL )
{
QMutexLocker locker( &m_mutex );
-
+
return instance->loadPrivate( url, datURL );
-}
+}
/* public */ /* static */
QMutexLocker locker( &m_mutex );
instance->stopPrivate( url );
-}
+}
/* public */ /* static */
QMutexLocker locker( &m_mutex );
return instance->deleteCachePrivate( url, parent );
-}
+}
/* public */ /* static */
bool ImgManager::copyCache( const KURL& url, QWidget* parent )
{
- QMutexLocker locker( &m_mutex );
+ QMutexLocker locker( &m_mutex );
return instance->copyCachePrivate( url, parent );
-}
+}
/* public */ /* static */
bool ImgManager::mosaic( const KURL& url )
{
instance->cacheExists( url ); /* to create IMGDAT if cache exists */
-
+
IMGDAT* imgdat = instance->getImgDat( url );
- if( !imgdat ) return TRUE;
+ if ( !imgdat ) return TRUE;
return imgdat->mosaic;
}
/* return -1 if IMGDAT doesn't exist. */ /* public */ /* static */
int ImgManager::code( const KURL& url )
{
- instance->cacheExists( url ); /* to create IMGDAT if cache exists */
+ instance->cacheExists( url ); /* to create IMGDAT if cache exists */
IMGDAT* imgdat = instance->getImgDat( url );
- if( !imgdat ) return -1;
+ if ( !imgdat ) return -1;
return imgdat->code;
}
/* public */ /* static */
unsigned int ImgManager::size( const KURL& url )
{
- instance->cacheExists( url ); /* to create IMGDAT if cache exists */
+ instance->cacheExists( url ); /* to create IMGDAT if cache exists */
IMGDAT* imgdat = instance->getImgDat( url );
- if( !imgdat ) return 0;
+ if ( !imgdat ) return 0;
return imgdat->size;
}
/* public */ /* static */
int ImgManager::width( const KURL& url )
{
- instance->cacheExists( url ); /* to create IMGDAT if cache exists */
+ instance->cacheExists( url ); /* to create IMGDAT if cache exists */
IMGDAT* imgdat = instance->getImgDat( url );
- if( !imgdat ) return 0;
- if( imgdat->width == 0 ) instance->getSize( url );
+ if ( !imgdat ) return 0;
+ if ( imgdat->width == 0 ) instance->getSize( url );
return imgdat->width;
}
/* public */ /* static */
int ImgManager::height( const KURL& url )
{
- instance->cacheExists( url ); /* to create IMGDAT if cache exists */
+ instance->cacheExists( url ); /* to create IMGDAT if cache exists */
IMGDAT* imgdat = instance->getImgDat( url );
- if( !imgdat ) return 0;
- if( imgdat->height == 0 ) instance->getSize( url );
-
+ if ( !imgdat ) return 0;
+ if ( imgdat->height == 0 ) instance->getSize( url );
+
return imgdat->height;
}
/* get icon pixmap */ /* public */ /* static */
-QPixmap ImgManager::icon( const KURL& url )
+QPixmap ImgManager::icon( const KURL& url )
{
const int iconsize = 32;
/*---------------------------*/
-
+
QPixmap pixmap;
QString path = Cache::getImgPath( url );
QImage img = QImage( path );
- if( img.isNull() ) return QPixmap();
-
+ if ( img.isNull() ) return QPixmap();
+
pixmap.convertFromImage( img.scale( iconsize, iconsize, QImage::ScaleMin ) );
return pixmap;
}
/* public */ /* static */
KURL ImgManager::datURL( const KURL& url )
{
- instance->cacheExists( url ); /* to create IMGDAT if cache exists */
+ instance->cacheExists( url ); /* to create IMGDAT if cache exists */
IMGDAT* imgdat = instance->getImgDat( url );
- if( !imgdat ) return KURL();
+ if ( !imgdat ) return KURL();
return imgdat->datURL;
}
bool ImgManager::isImgFilePrivate( const KURL& url, bool use_mimetype )
{
/* don't use mimetype */
- if( !use_mimetype ){
-
- QStringList extlist; // = KitaConfig::imgExtList();
- extlist = "jpg";
- extlist += "jpeg";
- extlist += "gif";
- extlist += "png";
- extlist += "bmp";
-
- for ( QStringList::iterator it = extlist.begin(); it != extlist.end(); ++it ){
- QRegExp reg_ext = ".*\\."+(*it)+"$";
- if ( reg_ext.search( url.fileName().lower() ) != -1 ) return TRUE;
-
- }
-
- return FALSE;
+ if ( !use_mimetype ) {
+
+ QStringList extlist; // = KitaConfig::imgExtList();
+ extlist = "jpg";
+ extlist += "jpeg";
+ extlist += "gif";
+ extlist += "png";
+ extlist += "bmp";
+
+ for ( QStringList::iterator it = extlist.begin(); it != extlist.end(); ++it ) {
+ QRegExp reg_ext = ".*\\." + ( *it ) + "$";
+ if ( reg_ext.search( url.fileName().lower() ) != -1 ) return TRUE;
+
+ }
+
+ return FALSE;
}
/*-----------------------------------*/
/* use mimetype ( very slow! ) */
- if( cacheExists( url ) ) return TRUE;
-
+ if ( cacheExists( url ) ) return TRUE;
+
#if KDE_IS_VERSION( 3, 2, 0 )
QString mimetype = KIO::NetAccess::mimetype( url, m_mainwidget );
#else
QString mimetype = KIO::NetAccess::mimetype( url );
#endif
- if( mimetype.left( 6 ) == "image/" ) return TRUE;
-
+ if ( mimetype.left( 6 ) == "image/" ) return TRUE;
+
return FALSE;
}
/*-----------------------------------------*/
- if( isLoadingNowPrivate( url ) ) return FALSE;
-
+ if ( isLoadingNowPrivate( url ) ) return FALSE;
+
/* cache exists? */
- if( cacheExists( url ) ){
+ if ( cacheExists( url ) ) {
- /* create EmitFinishEvent to emit finishImgLoad SIGNAL later. */
- /* See also customEvent(). */
- EmitFinishEvent* e = new EmitFinishEvent( url );
- QApplication::postEvent( this, e ); // Qt will delete it when done
+ /* create EmitFinishEvent to emit finishImgLoad SIGNAL later. */
+ /* See also customEvent(). */
+ EmitFinishEvent * e = new EmitFinishEvent( url );
+ QApplication::postEvent( this, e ); // Qt will delete it when done
- return TRUE;
+ return TRUE;
}
-
- if( m_loaderList.count() >= maxload ) return FALSE;
-
+
+ if ( m_loaderList.count() >= maxload ) return FALSE;
+
/* create directry of cache */
- QString path = Cache::getImgPath( url );
+ QString path = Cache::getImgPath( url );
KURL cacheDir = KURL( path, "." );
KURL cacheDir2 = KURL( cacheDir, ".." );
#if KDE_IS_VERSION( 3, 2, 0 )
- if ( !KIO::NetAccess::exists( cacheDir2, TRUE, m_mainwidget ) ) KIO::NetAccess::mkdir( cacheDir2, m_mainwidget );
- if ( !KIO::NetAccess::exists( cacheDir, TRUE, m_mainwidget ) ) KIO::NetAccess::mkdir( cacheDir, m_mainwidget );
+ if ( !KIO::NetAccess::exists( cacheDir2, TRUE, m_mainwidget ) ) KIO::NetAccess::mkdir( cacheDir2, m_mainwidget );
+ if ( !KIO::NetAccess::exists( cacheDir, TRUE, m_mainwidget ) ) KIO::NetAccess::mkdir( cacheDir, m_mainwidget );
#else
if ( !KIO::NetAccess::exists( cacheDir2 ) ) KIO::NetAccess::mkdir( cacheDir2 );
if ( !KIO::NetAccess::exists( cacheDir ) ) KIO::NetAccess::mkdir( cacheDir );
-#endif
+#endif
deleteImgDat( url );
-
+
/* create new loader, and start loading the file */
/* slotResult is called when done. */
FileLoader* loader = new FileLoader( url, datURL, path );
- if( loader->get() ){
- m_loaderList.append( loader );
-
- connect( loader, SIGNAL( data( Kita::FileLoader*, const QByteArray& ) ),
- SLOT( slotData( Kita::FileLoader*, const QByteArray& ) ) );
-
- connect( loader, SIGNAL( result( Kita::FileLoader* ) ),
- SLOT( slotResult( Kita::FileLoader* ) ) );
+ if ( loader->get() ) {
+ m_loaderList.append( loader );
+
+ connect( loader, SIGNAL( data( Kita::FileLoader*, const QByteArray& ) ),
+ SLOT( slotData( Kita::FileLoader*, const QByteArray& ) ) );
+
+ connect( loader, SIGNAL( result( Kita::FileLoader* ) ),
+ SLOT( slotResult( Kita::FileLoader* ) ) );
}
- else{
- deleteLoader( loader );
- return FALSE;
+ else {
+ deleteLoader( loader );
+ return FALSE;
}
-
+
return TRUE;
}
/* stop loading */ /* private */
void ImgManager::stopPrivate( const KURL& url )
{
- FileLoader* loader = getLoader( url );
- if( !loader ) return;
+ FileLoader * loader = getLoader( url );
+ if ( !loader ) return ;
loader->stopJob(); /* slotResult() will be called later. */
}
/* private */
bool ImgManager::isLoadingNowPrivate( const KURL& url )
{
- if( getLoader( url ) ) return TRUE;
+ if ( getLoader( url ) ) return TRUE;
return FALSE;
}
/* when done, cacheDeleted SIGNAL emitted */ /* private */
bool ImgManager::deleteCachePrivate( const KURL& url, QWidget* parent )
{
- if( !cacheExists( url ) ) return FALSE;
-
- if( QMessageBox::warning( parent,
- "Kita",
- i18n( "Do you want to delete the image ?" ),
- QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
- ==QMessageBox::Ok ){
-
- bool ret;;
-
- QString path = Cache::getImgPath( url );
- QString idxpath = Cache::getImgIdxPath( url );
-
-#if KDE_IS_VERSION( 3, 2, 0 )
- KIO::NetAccess::del( idxpath, m_mainwidget );
- ret = KIO::NetAccess::del( path, m_mainwidget );
-#else
- KIO::NetAccess::del( idxpath );
- ret = KIO::NetAccess::del( path );
+ if ( !cacheExists( url ) ) return FALSE;
+
+ if ( QMessageBox::warning( parent,
+ "Kita",
+ i18n( "Do you want to delete the image ?" ),
+ QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
+ == QMessageBox::Ok ) {
+
+ bool ret;;
+
+ QString path = Cache::getImgPath( url );
+ QString idxpath = Cache::getImgIdxPath( url );
+
+#if KDE_IS_VERSION( 3, 2, 0 )
+ KIO::NetAccess::del( idxpath, m_mainwidget );
+ ret = KIO::NetAccess::del( path, m_mainwidget );
+#else
+ KIO::NetAccess::del( idxpath );
+ ret = KIO::NetAccess::del( path );
#endif
- if( ret ){
- deleteImgDat( url );
- emit cacheDeleted( url );
- }
+ if ( ret ) {
+ deleteImgDat( url );
+ emit cacheDeleted( url );
+ }
- return ret;
- }
+ return ret;
+ }
- return FALSE;
+ return FALSE;
}
/* copy cache */ /* public */
bool ImgManager::copyCachePrivate( const KURL& url, QWidget* parent )
{
- if( !cacheExists( url ) ) return FALSE;
+ if ( !cacheExists( url ) ) return FALSE;
/* make filter */
QString filter;
QString file = url.fileName().lower();
- int i = file.findRev('.');
- if(i == -1) filter = "*|All files";
- else{
- QString ext = file.mid(i);
- filter = "*"+ext+"|*"+ext;
+ int i = file.findRev( '.' );
+ if ( i == -1 ) filter = "*|All files";
+ else {
+ QString ext = file.mid( i );
+ filter = "*" + ext + "|*" + ext;
}
/* get filename */
- QString savefile = KFileDialog::getSaveFileName( url.fileName(), filter,parent );
- if( savefile.isEmpty() ) return FALSE;
+ QString savefile = KFileDialog::getSaveFileName( url.fileName(), filter, parent );
+ if ( savefile.isEmpty() ) return FALSE;
/* file exists */
- if(
-#if KDE_IS_VERSION( 3, 2, 0 )
- KIO::NetAccess::exists( savefile, TRUE, m_mainwidget )
-#else
- KIO::NetAccess::exists( savefile )
-#endif
- ){
-
- if(QMessageBox::warning( parent,
- "Kita",
- i18n( "Do you want to replace the file?" ),
- QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
- != QMessageBox::Ok ) return FALSE;
+ if (
+#if KDE_IS_VERSION( 3, 2, 0 )
+ KIO::NetAccess::exists( savefile, TRUE, m_mainwidget )
+#else
+ KIO::NetAccess::exists( savefile )
+#endif
+ ) {
+
+ if ( QMessageBox::warning( parent,
+ "Kita",
+ i18n( "Do you want to replace the file?" ),
+ QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default )
+ != QMessageBox::Ok ) return FALSE;
#if KDE_IS_VERSION( 3, 2, 0 )
- KIO::NetAccess::del( savefile, m_mainwidget );
-#else
- KIO::NetAccess::del( savefile );
-#endif
+ KIO::NetAccess::del( savefile, m_mainwidget );
+#else
+ KIO::NetAccess::del( savefile );
+#endif
+
}
/* copy */
QString src = Cache::getImgPath( url );
-#if KDE_IS_VERSION( 3, 2, 0 )
+#if KDE_IS_VERSION( 3, 2, 0 )
KIO::NetAccess::copy( src, savefile, m_mainwidget );
#else
KIO::NetAccess::copy( src, savefile );
-#endif
-
+#endif
+
return TRUE;
}
/* private */
void ImgManager::setMosaicPrivate( const KURL& url, bool status )
{
- IMGDAT* imgdat = getImgDat( url );
- if( !imgdat ) return;
- if( imgdat->code != 200 ) return;
+ IMGDAT * imgdat = getImgDat( url );
+ if ( !imgdat ) return ;
+ if ( imgdat->code != 200 ) return ;
imgdat->mosaic = status;
/* get loader from url */ /* private */
FileLoader* ImgManager::getLoader( const KURL& url )
{
- if( m_loaderList.count() == 0 ) return NULL;
+ if ( m_loaderList.count() == 0 ) return NULL;
FileLoader* loader;
QPtrListIterator< FileLoader > it( m_loaderList );
- while( ( loader = it.current() ) != NULL ){
-
- if( loader->url() == url ){
- return loader;
- }
- ++it;
+ while ( ( loader = it.current() ) != NULL ) {
+
+ if ( loader->url() == url ) {
+ return loader;
+ }
+ ++it;
}
return NULL;
functions ( e.g. slotResult() ) causes many
problems. Maybe kita will crush. So,
delete it later. See also customEvent(). */
- DeleteLoaderEvent* e = new DeleteLoaderEvent( loader );
+ DeleteLoaderEvent * e = new DeleteLoaderEvent( loader );
QApplication::postEvent( this, e ); // Qt will delete it when done
}
/* private */
void ImgManager::createImgDat( const KURL& url, int code )
{
- IMGDAT* imgdat = getImgDat( url );
- if( !imgdat ){
- imgdat = new IMGDAT;
- m_imgDatDict.insert( url.prettyURL(), imgdat );
+ IMGDAT * imgdat = getImgDat( url );
+ if ( !imgdat ) {
+ imgdat = new IMGDAT;
+ m_imgDatDict.insert( url.prettyURL(), imgdat );
}
-
+
KConfig cfg( Cache::getImgIdxPath( url ) );
- if( code == 200 ) cfg.writeEntry( "URL", url.prettyURL() );
+ if ( code == 200 ) cfg.writeEntry( "URL", url.prettyURL() );
imgdat->mosaic = cfg.readBoolEntry( "Mosaic", KitaConfig::useMosaic() );
imgdat->height = cfg.readNumEntry( "Height", 0 );
/* private */
void ImgManager::deleteImgDat( const KURL& url )
{
- IMGDAT* imgdat = getImgDat( url );
- if( !imgdat ) return;
-
- if( m_imgDatDict.remove( url.prettyURL() )){
- delete imgdat;
+ IMGDAT * imgdat = getImgDat( url );
+ if ( !imgdat ) return ;
+
+ if ( m_imgDatDict.remove( url.prettyURL() ) ) {
+ delete imgdat;
}
}
/* private */
void ImgManager::getSize( const KURL& url )
{
- IMGDAT* imgdat = getImgDat( url );
- if( !imgdat ) return;
- if( imgdat->code != 200 ) return;
+ IMGDAT * imgdat = getImgDat( url );
+ if ( !imgdat ) return ;
+ if ( imgdat->code != 200 ) return ;
QString path = Cache::getImgPath( url );
QImage img = QImage( path );
- if( !img.isNull() ){
-
- imgdat->width = img.width();
- imgdat->height = img.height();
+ if ( !img.isNull() ) {
+
+ imgdat->width = img.width();
+ imgdat->height = img.height();
- /* save size */
- KConfig cfg( Cache::getImgIdxPath( url ) );
- cfg.writeEntry( "Width", imgdat->width );
- cfg.writeEntry( "Height", imgdat->height );
+ /* save size */
+ KConfig cfg( Cache::getImgIdxPath( url ) );
+ cfg.writeEntry( "Width", imgdat->width );
+ cfg.writeEntry( "Height", imgdat->height );
}
}
/* private */
bool ImgManager::cacheExists( const KURL& url )
{
- if( isLoadingNowPrivate( url ) ) return FALSE;
-
+ if ( isLoadingNowPrivate( url ) ) return FALSE;
+
bool ret;
QString path = Cache::getImgPath( url );
ret = KIO::NetAccess::exists( path );
#endif
- if( ret && !getImgDat( url ) ) createImgDat( url, 200 );
+ if ( ret && !getImgDat( url ) ) createImgDat( url, 200 );
return ret;
}
void ImgManager::slotData( Kita::FileLoader* loader, const QByteArray& barray )
{
/* check BMP header */
- if( barray.size() > 2 && loader->size() == barray.size()
- && barray[ 0 ] == 'B' && barray[ 1 ] == 'M' ){
- loader->stopJob();
- return;
+ if ( barray.size() > 2 && loader->size() == barray.size()
+ && barray[ 0 ] == 'B' && barray[ 1 ] == 'M' ) {
+ loader->stopJob();
+ return ;
}
/* I assume that file size is smaller than 2^32 byte */
{
createImgDat( loader->url(), loader->code() );
m_loaderList.remove( loader );
-
+
/* save size, datURL, etc */
- if( loader->code() == 200 ){
- unsigned int totalsize = loader->totalsize();
- KURL datURL = loader->datURL();
- KConfig cfg( Cache::getImgIdxPath( loader->url() ) );
- cfg.writeEntry( "Size", totalsize );
- cfg.writeEntry( "datURL", datURL.prettyURL() );
- IMGDAT* imgdat = instance->getImgDat( loader->url() );
- imgdat->size = totalsize;
- imgdat->datURL = datURL;
+ if ( loader->code() == 200 ) {
+ unsigned int totalsize = loader->totalsize();
+ KURL datURL = loader->datURL();
+ KConfig cfg( Cache::getImgIdxPath( loader->url() ) );
+ cfg.writeEntry( "Size", totalsize );
+ cfg.writeEntry( "datURL", datURL.prettyURL() );
+ IMGDAT* imgdat = instance->getImgDat( loader->url() );
+ imgdat->size = totalsize;
+ imgdat->datURL = datURL;
}
-
+
emit finishImgLoad( loader->url() );
deleteLoader( loader );
void ImgManager::customEvent( QCustomEvent * e )
{
/* delete loader */
- if ( e->type() == EVENT_DeleteLoader ){
- FileLoader* loader = static_cast< DeleteLoaderEvent* >( e )->getLoader();
- if( loader ){
-
- m_loaderList.remove( loader );
-
- /* error file is also deleted here. */
- if( loader->code() != 200 ) KIO::del( loader->path(), FALSE, FALSE );
-
- delete loader;
- }
+ if ( e->type() == EVENT_DeleteLoader ) {
+ FileLoader * loader = static_cast< DeleteLoaderEvent* >( e ) ->getLoader();
+ if ( loader ) {
+
+ m_loaderList.remove( loader );
+
+ /* error file is also deleted here. */
+ if ( loader->code() != 200 ) KIO::del( loader->path(), FALSE, FALSE );
+
+ delete loader;
+ }
}
/* emit finishImgLoad SIGNAL */
- else if ( e->type() == EVENT_EmitFinigh ){
- KURL url = static_cast< EmitFinishEvent* >( e )->url();
- emit finishImgLoad( url );
+ else if ( e->type() == EVENT_EmitFinigh ) {
+ KURL url = static_cast< EmitFinishEvent* >( e ) ->url();
+ emit finishImgLoad( url );
}
}
-FileLoader::FileLoader( const KURL& url, /* target */
- const KURL& datURL, /* The URL of thread that refers url. */
- const QString& path /* save path */
- )
+FileLoader::FileLoader( const KURL& url,
+ const KURL& datURL,
+ const QString& path
+ )
{
m_url = url;
m_datURL = datURL;
/* terminate job. */ /* public */
void FileLoader::killJob()
{
- if ( m_currentJob == NULL ) return;
+ if ( m_currentJob == NULL ) return ;
m_currentJob->kill(); /* without emitting result SIGNAL */
m_currentJob = NULL;
/* When done, signal loadFinished is emitted. */ /* public */
bool FileLoader::get()
{
- /* now loading */
- if( m_currentJob ) return FALSE;
+ /* now loading */
+ if ( m_currentJob ) return FALSE;
m_totalsize = 0;
m_size = 0;
/* open file */
m_file = new QFile( m_path );
- if( m_file == NULL || ! m_file->open( IO_WriteOnly ) ){
- closeFile();
- return FALSE;
+ 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_url, TRUE, FALSE );
- if( m_currentJob == NULL ){
- closeFile();
- return 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( result( KIO::Job* ) ),
+ SLOT( slotResult( KIO::Job* ) ) );
connect( m_currentJob, SIGNAL( redirection( KIO::Job *, const KURL& ) ),
- SLOT( slotRedirection( 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 ) ) );
- 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" );
/* public */
const bool FileLoader::isRunning() const
{
- if( m_currentJob ) return TRUE;
+ if ( m_currentJob ) return TRUE;
return FALSE;
}
const KIO::filesize_t FileLoader::totalsize() const
{
return m_totalsize;
-}
+}
/* public */
const KURL FileLoader::datURL() const
/* private */
void FileLoader::closeFile()
{
- if( m_file ) m_file->close();
- if( m_ds ) delete m_ds;
- if( m_file ) delete m_file;
+ if ( m_file ) m_file->close();
+ if ( m_ds ) delete m_ds;
+ if ( m_file ) delete m_file;
m_ds = NULL;
m_file = NULL;
void FileLoader::slotData( KIO::Job* job, const QByteArray& barray )
{
- if( job->error() == 0 ){
+ if ( job->error() == 0 ) {
- m_size += barray.size();
- m_ds->writeRawBytes( barray.data(), barray.size() );
+ m_size += barray.size();
+ m_ds->writeRawBytes( barray.data(), barray.size() );
- emit data( this, barray );
+ emit data( this, barray );
}
}
void FileLoader::slotTotalSize( KIO::Job * job, KIO::filesize_t size )
{
- if( job->error() == 0 ) m_totalsize = size;
+ if ( job->error() == 0 ) m_totalsize = size;
}
void FileLoader::slotResult( KIO::Job* job )
{
m_currentJob = NULL;
- if ( job->error() ==0 ) m_header = job->queryMetaData( "HTTP-Headers" );
+ if ( job->error() == 0 ) m_header = job->queryMetaData( "HTTP-Headers" );
m_code = responseCode();
closeFile();
class FileLoader;
class ImgManager : public QObject
- {
+ {
Q_OBJECT
static ImgManager* instance;
- static QMutex m_mutex;
- QPtrList< FileLoader > m_loaderList;
- QDict< IMGDAT > m_imgDatDict;
- QWidget* m_mainwidget;
+ static QMutex m_mutex;
+ QPtrList< FileLoader > m_loaderList;
+ QDict< IMGDAT > m_imgDatDict;
+ QWidget* m_mainwidget;
public:
- ImgManager( QWidget* mainwidget );
- ~ImgManager();
-
- static void setup( QWidget* mainwidget );
- static void deleteInstance();
- static ImgManager* getInstance();
- static bool isImgFile( const KURL& url, bool use_mimetype );
- static bool isAnimationGIF( const KURL& url );
- static bool isBMP( const KURL& url );
-
- static bool load( const KURL& url, const KURL& datURL );
- static void stop( const KURL& url );
- static QString getPath( const KURL& url );
- static bool isLoadingNow( const KURL& url );
- static bool deleteCache( const KURL& url, QWidget* parent );
- static bool copyCache( const KURL& url, QWidget* parent );
-
- static bool mosaic( const KURL& url );
- static void setMosaic( const KURL& url, bool status );
- static int code( const KURL& url );
- static int width( const KURL& url );
- static int height( const KURL& url );
- static unsigned int size( const KURL& url );
- static QPixmap icon( const KURL& url );
- static KURL datURL( const KURL& url );
-
+ ImgManager( QWidget* mainwidget );
+ ~ImgManager();
+
+ static void setup( QWidget* mainwidget );
+ static void deleteInstance();
+ static ImgManager* getInstance();
+ static bool isImgFile( const KURL& url, bool use_mimetype );
+ static bool isAnimationGIF( const KURL& url );
+ static bool isBMP( const KURL& url );
+
+ static bool load( const KURL& url, const KURL& datURL );
+ static void stop( const KURL& url );
+ static QString getPath( const KURL& url );
+ static bool isLoadingNow( const KURL& url );
+ static bool deleteCache( const KURL& url, QWidget* parent );
+ static bool copyCache( const KURL& url, QWidget* parent );
+
+ static bool mosaic( const KURL& url );
+ static void setMosaic( const KURL& url, bool status );
+ static int code( const KURL& url );
+ static int width( const KURL& url );
+ static int height( const KURL& url );
+ static unsigned int size( const KURL& url );
+ static QPixmap icon( const KURL& url );
+ static KURL datURL( const KURL& url );
+
private:
- bool isImgFilePrivate( const KURL& url, bool use_mimetype );
- bool loadPrivate( const KURL& url, const KURL& datURL );
- void stopPrivate( const KURL& url );
- bool isLoadingNowPrivate( const KURL& url );
- bool deleteCachePrivate( const KURL& url, QWidget* parent );
- bool copyCachePrivate( const KURL& url, QWidget* parent );
- void setMosaicPrivate( const KURL& url, bool status );
-
- FileLoader* getLoader( const KURL& url );
- void deleteLoader( FileLoader* loader );
- void createImgDat( const KURL& url, int code );
- IMGDAT* getImgDat( const KURL& url );
- void deleteImgDat( const KURL& url );
- void getSize( const KURL& url );
- bool cacheExists( const KURL& url );
-
+ bool isImgFilePrivate( const KURL& url, bool use_mimetype );
+ bool loadPrivate( const KURL& url, const KURL& datURL );
+ void stopPrivate( const KURL& url );
+ bool isLoadingNowPrivate( const KURL& url );
+ bool deleteCachePrivate( const KURL& url, QWidget* parent );
+ bool copyCachePrivate( const KURL& url, QWidget* parent );
+ void setMosaicPrivate( const KURL& url, bool status );
+
+ FileLoader* getLoader( const KURL& url );
+ void deleteLoader( FileLoader* loader );
+ void createImgDat( const KURL& url, int code );
+ IMGDAT* getImgDat( const KURL& url );
+ void deleteImgDat( const KURL& url );
+ void getSize( const KURL& url );
+ bool cacheExists( const KURL& url );
+
private slots:
- void slotData( Kita::FileLoader*, const QByteArray& );
- void slotResult( Kita::FileLoader* );
+ void slotData( Kita::FileLoader*, const QByteArray& );
+ void slotResult( Kita::FileLoader* );
protected:
- virtual void customEvent( QCustomEvent * e );
+ virtual void customEvent( QCustomEvent * e );
signals:
- void receiveImgData( const KURL&, unsigned int, unsigned int );
- void finishImgLoad( const KURL& );
- void cacheDeleted( const KURL& );
- };
+ void receiveImgData( const KURL&, unsigned int, unsigned int );
+ void finishImgLoad( const KURL& );
+ void cacheDeleted( const KURL& );
+ };
+
+ /*---------------------------------------------------------*/
-/*---------------------------------------------------------*/
-
class FileLoader : public QObject
{
Q_OBJECT
-
- KURL m_url;
- KURL m_datURL;
- QString m_path;
-
- /* job */
- KIO::Job* m_currentJob;
- int m_code;
- QString m_header;
-
- /* file */
- QFile *m_file;
- QDataStream *m_ds;
- KIO::filesize_t m_size;
- KIO::filesize_t m_totalsize;
-
- public:
- FileLoader( const KURL& url, const KURL& datURL, const QString& path );
- ~FileLoader();
-
- void killJob();
- void stopJob();
- bool get();
-
- const bool isRunning() const;
- const int code() const;
- const KURL url() const;
- const QString path() const;
- const KIO::filesize_t size() const;
- const KIO::filesize_t totalsize() const;
- const KURL datURL() 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( Kita::FileLoader*, const QByteArray& );
- void result( Kita::FileLoader* );
+
+ /* target */
+ KURL m_url;
+ /* The URL of thread that refers url. */
+ KURL m_datURL;
+ /* save path */
+ QString m_path;
+
+ /* job */
+ KIO::Job* m_currentJob;
+ int m_code;
+ QString m_header;
+
+ /* file */
+ QFile *m_file;
+ QDataStream *m_ds;
+ KIO::filesize_t m_size;
+ KIO::filesize_t m_totalsize;
+
+ public:
+ FileLoader( const KURL& url, const KURL& datURL, const QString& path );
+ ~FileLoader();
+
+ void killJob();
+ void stopJob();
+ bool get();
+
+ const bool isRunning() const;
+ const int code() const;
+ const KURL url() const;
+ const QString path() const;
+ const KIO::filesize_t size() const;
+ const KIO::filesize_t totalsize() const;
+ const KURL datURL() 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( Kita::FileLoader*, const QByteArray& );
+ void result( Kita::FileLoader* );
};
}
class EmitFinishEvent : public QCustomEvent
{
KURL m_url;
-
- public:
- EmitFinishEvent( KURL url ):QCustomEvent( EVENT_EmitFinigh ),m_url( url ){}
+
+public:
+ EmitFinishEvent( KURL url ) : QCustomEvent( EVENT_EmitFinigh ), m_url( url ) {}
KURL url() const { return m_url; }
};
class DeleteLoaderEvent : public QCustomEvent
{
Kita::FileLoader* m_loader;
-
- public:
- DeleteLoaderEvent( Kita::FileLoader* loader ):QCustomEvent( EVENT_DeleteLoader )
- ,m_loader( loader ){}
+
+public:
+ DeleteLoaderEvent( Kita::FileLoader* loader ) : QCustomEvent( EVENT_DeleteLoader )
+ , m_loader( loader ) {}
Kita::FileLoader* getLoader() const { return m_loader; }
};
m_usePart( KitaConfig::defaultUsePart() ),
m_useImageViewer( KitaConfig::defaultUseImageViewer() ),
m_useImagePopup( KitaConfig::defaultUseImagePopup() ),
- m_useMosaic( KitaConfig::defaultUseMosaic() ),
+ m_useMosaic( KitaConfig::defaultUseMosaic() ),
m_useKitaNavi( KitaConfig::defaultUseKitaNavi() ),
m_partMimeList( KitaConfig::defaultPartMimeList() ),
m_userID( KitaConfig::defaultUserID() ),
config->writeEntry( "UsePart", KitaConfig::usePart() );
config->writeEntry( "UseImageViewer", KitaConfig::useImageViewer() );
config->writeEntry( "UseImagePopup", KitaConfig::useImagePopup() );
- config->writeEntry( "UseMosaic", KitaConfig::useMosaic() );
+ config->writeEntry( "UseMosaic", KitaConfig::useMosaic() );
config->writeEntry( "UseKitaNavi", KitaConfig::useKitaNavi() );
config->writeEntry( "UseStyleSheet", KitaConfig::useStyleSheet() );
config->writeEntry( "PartMimeList", KitaConfig::partMimeList() );
KitaConfig::setUseImageViewer( config->readBoolEntry( "UseImageViewer", KitaConfig::defaultUseImageViewer() ) );
KitaConfig::setUseImagePopup( config->readBoolEntry( "UseImagePopup", KitaConfig::defaultUseImagePopup() ) );
KitaConfig::setUseMosaic( config->readBoolEntry( "UseMosaic", KitaConfig::defaultUseMosaic() ) );
-
+
KitaConfig::setUseKitaNavi( config->readBoolEntry( "UseKitaNavi", KitaConfig::defaultUseKitaNavi() ) );
KitaConfig::setUseStyleSheet( config->readBoolEntry( "UseStyleSheet", KitaConfig::defaultUseStyleSheet() ) );
static void setUseImagePopup( bool value ) { getInstance() ->m_useImagePopup = value; }
static bool defaultUseImagePopup() { return true; }
- static bool useMosaic() { return getInstance()->m_useMosaic; }
- static void setUseMosaic( bool value ) { getInstance()->m_useMosaic = value; }
+ static bool useMosaic() { return getInstance() ->m_useMosaic; }
+ static void setUseMosaic( bool value ) { getInstance() ->m_useMosaic = value; }
static bool defaultUseMosaic() { return true; }
static bool useKitaNavi() { return getInstance() ->m_useKitaNavi; }
/***************************************************************************
- * Copyright (C) 2003 by Hideki Ikemoto *
- * ikemo@wakaba.jp *
- * *
- * Permission is hereby granted, free of charge, to any person obtaining *
- * a copy of this software and associated documentation files (the *
- * "Software"), to deal in the Software without restriction, including *
- * without limitation the rights to use, copy, modify, merge, publish, *
- * distribute, sublicense, and/or sell copies of the Software, and to *
- * permit persons to whom the Software is furnished to do so, subject to *
- * the following conditions: *
- * *
- * The above copyright notice and this permission notice shall be *
- * included in all copies or substantial portions of the Software. *
- * *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
- * OTHER DEALINGS IN THE SOFTWARE. *
+* Copyright (C) 2003 by Hideki Ikemoto *
+* ikemo@wakaba.jp *
+* *
+* Permission is hereby granted, free of charge, to any person obtaining *
+* a copy of this software and associated documentation files (the *
+* "Software"), to deal in the Software without restriction, including *
+* without limitation the rights to use, copy, modify, merge, publish, *
+* distribute, sublicense, and/or sell copies of the Software, and to *
+* permit persons to whom the Software is furnished to do so, subject to *
+* the following conditions: *
+* *
+* The above copyright notice and this permission notice shall be *
+* included in all copies or substantial portions of the Software. *
+* *
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
+* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
+* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
+* OTHER DEALINGS IN THE SOFTWARE. *
***************************************************************************/
#include "qcp932codec.h"
#define QValidChar(u) ((u) ? QChar((ushort)(u)) : QChar::replacement)
-static unsigned short const jisx0208_ibm_extension_to_unicode[] = {
+static unsigned short const jisx0208_ibm_extension_to_unicode[] =
+ {
/* 115 ku */
- 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176,
+ 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176,
0x2177, 0x2178, 0x2179, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164,
0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0xffe2, 0xffe4, 0xff07,
0xff02, 0x3231, 0x2116, 0x2121, 0x2235, 0x7e8a, 0x891c, 0x9348,
0xfa0e, 0x549c, 0x548a, 0x54a9, 0x54ff, 0x5586, 0x5759, 0x5765,
0x57ac, 0x57c8, 0x57c7, 0xfa0f, 0xfa10, 0x589e, 0x58b2,
/* 116 ku */
- 0x590b, 0x5953, 0x595b, 0x595d, 0x5963, 0x59a4, 0x59ba,
+ 0x590b, 0x5953, 0x595b, 0x595d, 0x5963, 0x59a4, 0x59ba,
0x5b56, 0x5bc0, 0x752f, 0x5bd8, 0x5bec, 0x5c1e, 0x5ca6, 0x5cba,
0x5cf5, 0x5d27, 0x5d53, 0xfa11, 0x5d42, 0x5d6d, 0x5db8, 0x5db9,
0x5dd0, 0x5f21, 0x5f34, 0x5f67, 0x5fb7, 0x5fde, 0x605d, 0x6085,
0x6a6b, 0x6a46, 0x6a73, 0x6a7e, 0x6ae2, 0x6ae4, 0x6bd6, 0x6c3f,
0x6c5c, 0x6c86, 0x6c6f, 0x6cda, 0x6d04, 0x6d87, 0x6d6f,
/* 117 ku */
- 0x6d96, 0x6dac, 0x6dcf, 0x6df8, 0x6df2, 0x6dfc, 0x6e39,
+ 0x6d96, 0x6dac, 0x6dcf, 0x6df8, 0x6df2, 0x6dfc, 0x6e39,
0x6e5c, 0x6e27, 0x6e3c, 0x6ebf, 0x6f88, 0x6fb5, 0x6ff5, 0x7005,
0x7007, 0x7028, 0x7085, 0x70ab, 0x710f, 0x7104, 0x715c, 0x7146,
0x7147, 0xfa15, 0x71c1, 0x71fe, 0x72b1, 0x72be, 0x7324, 0xfa16,
0x7f47, 0x7fa1, 0xfa1e, 0x8301, 0x8362, 0x837f, 0x83c7, 0x83f6,
0x8448, 0x84b4, 0x8553, 0x8559, 0x856b, 0xfa1f, 0x85b0,
/* 118 ku */
- 0xfa20, 0xfa21, 0x8807, 0x88f5, 0x8a12, 0x8a37, 0x8a79,
+ 0xfa20, 0xfa21, 0x8807, 0x88f5, 0x8a12, 0x8a37, 0x8a79,
0x8aa7, 0x8abe, 0x8adf, 0xfa22, 0x8af6, 0x8b53, 0x8b7f, 0x8cf0,
0x8cf4, 0x8d12, 0x8d76, 0xfa23, 0x8ecf, 0xfa24, 0xfa25, 0x9067,
0x90de, 0xfa26, 0x9115, 0x9127, 0x91da, 0x91d7, 0x91de, 0x91ed,
0x973b, 0x9743, 0x974d, 0x974f, 0x9751, 0x9755, 0x9857, 0x9865,
0xfa2a, 0xfa2b, 0x9927, 0xfa2c, 0x999e, 0x9a4e, 0x9ad9,
/* 119 ku */
- 0x9adc, 0x9b75, 0x9b72, 0x9b8f, 0x9bb1, 0x9bbb, 0x9c00,
+ 0x9adc, 0x9b75, 0x9b72, 0x9b8f, 0x9bb1, 0x9bbb, 0x9c00,
0x9d70, 0x9d6b, 0xfa2d, 0x9e19, 0x9ed1, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-};
+ };
-static uint cp932ToUnicode(QJpUnicodeConv* conv, uint h, uint l)
+static uint cp932ToUnicode( QJpUnicodeConv* conv, uint h, uint l )
{
- uint ku;
- uint ten;
+ uint ku;
+ uint ten;
- if(h >= 0x81 && h <= 0x9f) {
- ku = h * 2 - 257;
- } else if(h >= 0xe0 && h <= 0xfc) {
- ku = h * 2 - 385;
- } else {
- return 0x0000;
- }
+ if ( h >= 0x81 && h <= 0x9f ) {
+ ku = h * 2 - 257;
+ } else if ( h >= 0xe0 && h <= 0xfc ) {
+ ku = h * 2 - 385;
+ } else {
+ return 0x0000;
+ }
- if(l >= 0x40 && l <= 0x7e) {
- ten = l - 63;
- } else if(l >= 0x80 && l <= 0x9e) {
- ten = l - 64;
- } else if(l >= 0x9f && l <= 0xfc) {
- ten = l - 158;
- ku++;
- } else {
- return 0x0000;
- }
+ if ( l >= 0x40 && l <= 0x7e ) {
+ ten = l - 63;
+ } else if ( l >= 0x80 && l <= 0x9e ) {
+ ten = l - 64;
+ } else if ( l >= 0x9f && l <= 0xfc ) {
+ ten = l - 158;
+ ku++;
+ } else {
+ return 0x0000;
+ }
- if(ku >= 115 && ku <= 119 && ten <= 94) {
- return jisx0208_ibm_extension_to_unicode[(ku - 115) * 94 + (ten - 1)];
- }
- return conv->jisx0208ToUnicode(ku + 0x20, ten + 0x20);
+ if ( ku >= 115 && ku <= 119 && ten <= 94 ) {
+ return jisx0208_ibm_extension_to_unicode[ ( ku - 115 ) * 94 + ( ten - 1 ) ];
+ }
+ return conv->jisx0208ToUnicode( ku + 0x20, ten + 0x20 );
}
QCp932Codec::QCp932Codec() : QTextCodec(),
- conv(QJpUnicodeConv::newConverter(QJpUnicodeConv::Microsoft_CP932 |
- QJpUnicodeConv::NEC_VDC |
- QJpUnicodeConv::IBM_VDC)){
-}
+ conv( QJpUnicodeConv::newConverter( QJpUnicodeConv::Microsoft_CP932 |
+ QJpUnicodeConv::NEC_VDC |
+ QJpUnicodeConv::IBM_VDC ) )
+{}
QCp932Codec::~QCp932Codec()
{
- if(conv) {
- delete conv;
- }
+ if ( conv ) {
+ delete conv;
+ }
}
const char * QCp932Codec::name() const
{
- return "CP932";
+ return "CP932";
}
// see http://www.iana.org/assignments/character-sets
const char * QCp932Codec::mimeName() const
{
- return "Windows-31J";
+ return "Windows-31J";
}
int QCp932Codec::mibEnum() const
{
- return 2024;
+ return 2024;
}
QTextDecoder* QCp932Codec::makeDecoder() const
{
- return new QCp932Decoder(conv);
+ return new QCp932Decoder( conv );
}
/*
{
}*/
-static uint jisx0212ToSjis(uint h, uint l)
+static uint jisx0212ToSjis( uint h, uint l )
{
- if ((0x0021 <= h) && (h <= 0x007e) && (0x0021 <= l) && (l <= 0x007e)) {
- return ((((h - 1) >> 1) + ((h <= 0x5e) ? 0x71 : 0xb1)) << 8) |
- (l + ((h & 1) ? ((l < 0x60) ? 0x1f : 0x20) : 0x7e));
+ if ( ( 0x0021 <= h ) && ( h <= 0x007e ) && ( 0x0021 <= l ) && ( l <= 0x007e ) ) {
+ return ( ( ( ( h - 1 ) >> 1 ) + ( ( h <= 0x5e ) ? 0x71 : 0xb1 ) ) << 8 ) |
+ ( l + ( ( h & 1 ) ? ( ( l < 0x60 ) ? 0x1f : 0x20 ) : 0x7e ) );
}
return 0x0000;
}
-QCString QCp932Codec::fromUnicode(const QString& uc, int& lenInOut) const
+QCString QCp932Codec::fromUnicode( const QString& uc, int& lenInOut ) const
{
- int ulen = QMAX((int)uc.length(), lenInOut);
- int clen = ulen * 2 + 1;
- QCString ret(clen);
- char *pos = (char *)ret.data();
+ int ulen = QMAX( ( int ) uc.length(), lenInOut );
+ int clen = ulen * 2 + 1;
+ QCString ret( clen );
+ char *pos = ( char * ) ret.data();
- for(int i=0; i<ulen; i++) {
- uint c = uc[i].unicode();
- uint j;
+ for ( int i = 0; i < ulen; i++ ) {
+ uint c = uc[ i ].unicode();
+ uint j;
- /* convert WAVE DASH to FULLWIDTH TILDE */
- if( c == 0x301C ) c = 0xFF5E;
-
- if((j = conv->unicodeToJisx0201(c)) != 0) {
- // ascii(jis x 0201) or hankaku-kana
- *pos++ = j;
- } else if((j = conv->unicodeToSjis(c)) != 0) {
- *pos++ = (j >> 8);
- *pos++ = (j & 0xff);
- } else if((j = conv->unicodeToJisx0212(c)) != 0) {
- // support NEC and IBM extension...
- j = jisx0212ToSjis((j & 0xff00) >> 8, j & 0x00ff);
- *pos++ = (j >> 8);
- *pos++ = (j & 0xff);
- } else {
- // invalid
- *pos++ = '?';
+ /* convert WAVE DASH to FULLWIDTH TILDE */
+ if ( c == 0x301C ) c = 0xFF5E;
+
+ if ( ( j = conv->unicodeToJisx0201( c ) ) != 0 ) {
+ // ascii(jis x 0201) or hankaku-kana
+ *pos++ = j;
+ } else if ( ( j = conv->unicodeToSjis( c ) ) != 0 ) {
+ *pos++ = ( j >> 8 );
+ *pos++ = ( j & 0xff );
+ } else if ( ( j = conv->unicodeToJisx0212( c ) ) != 0 ) {
+ // support NEC and IBM extension...
+ j = jisx0212ToSjis( ( j & 0xff00 ) >> 8, j & 0x00ff );
+ *pos++ = ( j >> 8 );
+ *pos++ = ( j & 0xff );
+ } else {
+ // invalid
+ *pos++ = '?';
+ }
}
- }
- lenInOut = pos - (char *)ret.data();
- ret.truncate(lenInOut);
- return ret;
+ lenInOut = pos - ( char * ) ret.data();
+ ret.truncate( lenInOut );
+ return ret;
}
/*bool QCp932Codec::canEncode(QChar ch) const
{
}
-
+
bool QCp932Codec::canEncode(const QString& s) const
{
}*/
// XXX
-int QCp932Codec::heuristicContentMatch(const char*, int) const
+int QCp932Codec::heuristicContentMatch( const char*, int ) const
{
- kdWarning( 7743 ) << "XXX heuristicContentMatch" << endl;
- return 0;
+ kdWarning( 7743 ) << "XXX heuristicContentMatch" << endl;
+ return 0;
}
// XXX
-int QCp932Codec::heuristicNameMatch(const char * hint) const
+int QCp932Codec::heuristicNameMatch( const char * hint ) const
{
- kdWarning( 7743 ) << "XXX heuristicNameMatch hint = " << hint << endl;
- return 0;
+ kdWarning( 7743 ) << "XXX heuristicNameMatch hint = " << hint << endl;
+ return 0;
}
-QCp932Decoder::QCp932Decoder(QJpUnicodeConv* _conv) : QTextDecoder(), conv(_conv)
-{
-}
+QCp932Decoder::QCp932Decoder( QJpUnicodeConv* _conv ) : QTextDecoder(), conv( _conv )
+{}
QCp932Decoder::~QCp932Decoder()
-{
-}
+{}
-QString QCp932Decoder::toUnicode(const char* chars, int len)
+QString QCp932Decoder::toUnicode( const char* chars, int len )
{
- QString ret;
- static int buf = -1;
+ QString ret;
+ static int buf = -1;
- for(int i=0; i<len; i++) {
- unsigned char c = chars[i];
- if(buf >= 0) { // 2-byte
- if((c >= 0x40 && c <= 0x7e) || (c >= 0x80 && c <= 0xfc)) {
- // valid kanji
- uint u = cp932ToUnicode(conv, buf, c);
- ret += QValidChar(u);
- } else {
- // invalid
- ret += QChar::replacement;
- }
- buf = -1;
- } else {
- if((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) {
- // 1st-byte of 2-byte character.
- buf = (int)c;
- } else if(c >= 0xa1 && c <= 0xdf) {
- // hankaku-kana
- uint u = conv->jisx0201ToUnicode(c);
- ret += QValidChar(u);
- } else {
- // 1-byte character.
- uint u = conv->asciiToUnicode(c);
- ret += QValidChar(u);
- }
+ for ( int i = 0; i < len; i++ ) {
+ unsigned char c = chars[ i ];
+ if ( buf >= 0 ) { // 2-byte
+ if ( ( c >= 0x40 && c <= 0x7e ) || ( c >= 0x80 && c <= 0xfc ) ) {
+ // valid kanji
+ uint u = cp932ToUnicode( conv, buf, c );
+ ret += QValidChar( u );
+ } else {
+ // invalid
+ ret += QChar::replacement;
+ }
+ buf = -1;
+ } else {
+ if ( ( c >= 0x81 && c <= 0x9f ) || ( c >= 0xe0 && c <= 0xfc ) ) {
+ // 1st-byte of 2-byte character.
+ buf = ( int ) c;
+ } else if ( c >= 0xa1 && c <= 0xdf ) {
+ // hankaku-kana
+ uint u = conv->jisx0201ToUnicode( c );
+ ret += QValidChar( u );
+ } else {
+ // 1-byte character.
+ uint u = conv->asciiToUnicode( c );
+ ret += QValidChar( u );
+ }
+ }
}
- }
- return ret;
+ return ret;
}