void KitaMainWindow::slotURLLine()
{
- QString text = m_urlLine->text();
- QString datURL = Kita::threadToDat( text );
- m_threadTab->showThread( datURL, KitaConfig::alwaysUseTab() );
+ KURL url = m_urlLine->text();
+ KURL datURL = Kita::ParseMisc::parseURLonly( url );
+ m_threadTab->showThread( datURL.prettyURL(), KitaConfig::alwaysUseTab() );
}
void KitaMainWindow::saveProperties( KConfig* config )
QString Kita::datToThread( const QString& datURL )
{
- // http://<host>/<board>/dat/<datname>.dat
+ // http://<root>/<board>/dat/<datname>.dat
KURL url( datURL );
QString protocol = url.protocol();
- QString host = url.host();
+ QString root = url.host();
QStringList list = QStringList::split( ".", url.fileName() );
if ( list.size() != 2 ) {
QString board = url.fileName();
url.cd( ".." );
- if ( url.fileName() != "" ) {
- return "";
+ if ( url.path() != "/" ) {
+ root += url.path();
}
- KURL newURL;
- newURL.setProtocol( protocol );
- newURL.setHost( host );
+ KURL newURL = protocol + "://" + root;
// FIXME: TOOOOOOOOOOOOOOOOOOOOOO ugly.
QRegExp host_machibbs( ".*\\.machi\\.to" );
- if ( host_machibbs.search( host ) != -1 ) {
+ if ( host_machibbs.search( root ) != -1 ) {
newURL.addPath( "/bbs/read.pl" );
newURL.addQueryItem( "BBS", board );
newURL.addQueryItem( "KEY", datName );
QString Kita::datToCache( const QString& datURL )
{
- // http://<host>/<board>/dat/<datname>.dat
+ // http://<root>/<board>/dat/<datname>.dat
KURL url( datURL );
- QString protocol = url.protocol();
- QString host = url.host();
+ QString root = url.host();
QString filename = url.fileName();
url.cd( ".." );
QString board = url.fileName();
url.cd( ".." );
- if ( url.fileName() != "" ) {
- return QString::null;
+ if ( url.path() != "/" ) {
+ root += url.path().replace( "/", "." );
}
- return QString( "%1/%2/%3" ).arg( host ).arg( board ).arg( filename );
+ return QString( "%1/%2/%3" ).arg( root ).arg( board ).arg( filename );
}
QString Kita::httpToK2ch( const QString& httpURL )
parseBODYdatText( PARSEMODE_TEXT, resdat.name, resdat.parsedName );
resdat.address = list[ 1 ];
parseDateId(list[ 2 ],resdat.id,resdat.dateId,resdat.dateTime );
- resdat.body = list[ 3 ].mid( 1 ); /* remove space after <> */
+ if( list[ 3 ].at( 0 ) == ' ' ) resdat.body = list[ 3 ].mid( 1 ); /* remove space after <> */
+ else resdat.body = list[ 3 ];
/* get subject */
if (list[ 4 ] != QString::null ) {
KURL ParseMisc::parseURL( const KURL& url , QString& refstr )
{
KURL newURL = url;
+ QString root;
+ QString board;
+ QString thread;
+ QString refBase;
refstr = QString::null;
-
- if ( url.path().contains( "/test/read.cgi" ) ) {
- QString tmp = url.path().section( "/test/read.cgi", 1 );
- QString newPath = QString( "/%1/dat/%2.dat" )
- .arg( tmp.section( '/', 1, 1 ) )
- .arg( tmp.section( '/', 2, 2 ) );
- newURL.setPath( newPath );
+ if ( url.path().contains( "/read.cgi" ) ) {
- QString refBase = tmp.section( '/', 3 );
- if ( ! refBase.isEmpty() ) {
+ if ( url.path().contains( "/test/read.cgi" ) ) /* 2ch */
+ root = url.prettyURL().section( "/test/read.cgi", 0, 0 );
+ else root = url.prettyURL().section( "/read.cgi", 0, 0 );
- if ( refBase.at( 0 ) == '-' ) refstr = "1" + refBase;
- else refstr = refBase;
- }
+ QString tmp = url.path().section( "/read.cgi", 1 );
+
+ board = tmp.section( '/', 1, 1 );
+ thread = tmp.section( '/', 2, 2 );
+ refBase = tmp.section( '/', 3, 3 );
+
+ QRegExp reg( "\\d+" );
+ if( reg.exactMatch( thread ) ){
+
+ QString newPath = QString( "/%1/dat/%2.dat" ).arg( board ).arg( thread );
+
+ newURL = root + newPath;
+
+ if ( ! refBase.isEmpty() ){
+ if ( refBase.at( 0 ) == '-' ) refstr = "1" + refBase;
+ else refstr = refBase;
+ }
+
+ return newURL;
+ }
}
- else
- {
+
if( newURL.hasRef() )
{
refstr = newURL.ref();
newURL = newURL.protocol() + "://" + newURL.host() + newURL.path();
}
- }
+
kdDebug() << "newURL: " << newURL.url() << endl;
return newURL;