void STab::handleStreamSourcePage() { qDebug("STab::handleStreamSourcePage"); QNetworkReply* reply = qobject_cast<QNetworkReply*>(const_cast<QObject*>(sender())); ui->progressBar->setValue(80); disconnect(reply, SIGNAL(finished()), this, SLOT(handleStreamSourcePage())); if (reply->error() != 0) { emit titleChanged(trUtf8("Stream not found")); qDebug() << QString("Response error: ") << reply->error(); showMessage(trUtf8("Error: Stream not found")); return; } QUrl url = reply->url(); QRegExp wwwRegExp(QString("^www."), Qt::CaseInsensitive); QString host = url.host().replace(wwwRegExp, QString("")); qDebug() << QString("Host") << host; QSettings* const settings = Settings::getHostsInstance(); settings->beginGroup(host); QString type = settings->value("type").toString(); settings->endGroup(); if (type.isEmpty()) { this->currentGroup = QString("default"); } else { this->currentGroup = host; } QString content = QString::fromUtf8(reply->readAll()); if (!exeStream(this->currentGroup, content)) { showMessage(trUtf8("Stream not found on cerrent page")); return; } // Получаем title для таба QString titleRegExp = QString("<title>([^<]+)</title>"); QRegExp titleRx(titleRegExp, Qt::CaseInsensitive); titleRx.indexIn(content); this->title = titleRx.cap(1); emit titleChanged(this->title); }
QString StyleGetter::styledHtml( const int blogid, const QString &title, const QString &content ) { kDebug(); // BilboBlog tempBlog = DBMan::self()->getBlogInfo( blogid ); // if ( tempBlog.isError() ) { // kDebug() << DBMan::self()->lastErrorText(); // return "<html><body><b>" + title + "</b><br>" + content + "</html>"; // } // // QString blogDir = tempBlog.url().host(); //QString url = QString( "bilbo/%1/" ).arg( blogid ); QString url = QString( "blogilo/%1/" ).arg( blogid ); url = KStandardDirs::locateLocal( "data", url , true ); KUrl dest( url ); dest.addPath("style.html"); dest.setScheme("file"); QString buffer; if ( !dest.isValid() ) { return "<html><body><h2 align='center'>" + title + "</h2><br>" + content + "</html>"; } QFile file( dest.pathOrUrl() ); if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { return "<html><body><h2 align='center'>" + title + "</h2><br>" + content + "</html>"; } while ( !file.atEnd() ) { QByteArray line = file.readLine(); buffer.append( QString::fromUtf8( line ) ); } QRegExp typeRx ( QString( "(TYPE[^>]+>)" ) ); buffer.remove( typeRx ); QRegExp titleRx( QString( "%1[\\d]*" ).arg( POST_TITLE ) ); QRegExp contentRx( QString( "%1[\\d]*" ).arg( POST_CONTENT ) ); buffer.replace( titleRx, title ); buffer.replace( contentRx, content ); return buffer; }