/*************************************************************************** * KSystemLog, a system log viewer tool * * Copyright (C) 2007 by Nicolas Ternisien * * nicolas.ternisien@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include "logging.h" class FindIncompatibleKioTest : public QObject { Q_OBJECT private slots: void initTestCase(); void find(); private: void displayFoundMethods(const QStringList& methods, const KUrl& url, QTextStream& out); QStringList headerContent(const KUrl& url); QString convertMethod(const QString& method); QMap findMethods(const QStringList& methods, const KUrl& url); }; void FindIncompatibleKioTest::initTestCase() { } void FindIncompatibleKioTest::find() { QString kdelibs = QLatin1String("/home/nicolas/workspace/kdelibs"); QString kdebase = QLatin1String("/home/nicolas/workspace/kdebase"); QString outputPath = QLatin1String("/home/nicolas/compatibleKioSlaves.html"); QStringList existingMethods; existingMethods << QLatin1String("void SlaveBase::openConnection(void)"); existingMethods << QLatin1String("void SlaveBase::closeConnection(void)"); existingMethods << QLatin1String("void SlaveBase::stat(KUrl const &)"); existingMethods << QLatin1String("void SlaveBase::put(KUrl const &, int, bool, bool)"); existingMethods << QLatin1String("void SlaveBase::special(const QByteArray &)"); existingMethods << QLatin1String("void SlaveBase::listDir(KUrl const &)"); existingMethods << QLatin1String("void SlaveBase::get(KUrl const & )"); existingMethods << QLatin1String("void SlaveBase::open(KUrl const &, QIODevice::OpenMode)"); existingMethods << QLatin1String("void SlaveBase::read(KIO::filesize_t)"); existingMethods << QLatin1String("void SlaveBase::write(const QByteArray &)"); existingMethods << QLatin1String("void SlaveBase::seek(KIO::filesize_t)"); existingMethods << QLatin1String("void SlaveBase::close()"); existingMethods << QLatin1String("void SlaveBase::mimetype(KUrl const &url)"); existingMethods << QLatin1String("void SlaveBase::rename(KUrl const &, KUrl const &, bool)"); existingMethods << QLatin1String("void SlaveBase::symlink(QString const &, KUrl const &, bool)"); existingMethods << QLatin1String("void SlaveBase::copy(KUrl const &, KUrl const &, int, bool)"); existingMethods << QLatin1String("void SlaveBase::del(KUrl const &, bool)"); existingMethods << QLatin1String("void SlaveBase::setLinkDest(const KUrl &, const QString&)"); existingMethods << QLatin1String("void SlaveBase::mkdir(KUrl const &, int)"); existingMethods << QLatin1String("void SlaveBase::chmod(KUrl const &, int)"); existingMethods << QLatin1String("void SlaveBase::setModificationTime(KUrl const &, const QDateTime&)"); existingMethods << QLatin1String("void SlaveBase::chown(KUrl const &, const QString &, const QString &)"); existingMethods << QLatin1String("void SlaveBase::setSubUrl(KUrl const &)"); existingMethods << QLatin1String("void SlaveBase::multiGet(const QByteArray &)"); //logDebug() << existingMethods << endl; QFile file(outputPath); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { logError() << "Unable to open the output file" << outputPath << endl; return; } QTextStream out(&file); out << "" << endl; out << "" << endl; out << "" << endl; out << "" << endl; out << "" << endl; out << "
KIO Slaves Analyzing
" << endl; out << "" << endl; QList parsingUrls; parsingUrls.append(KUrl(kdelibs + QLatin1String("/kioslave/http/http.h"))); parsingUrls.append(KUrl(kdelibs + QLatin1String("/kioslave/ftp/ftp.h"))); parsingUrls.append(KUrl(kdelibs + QLatin1String("/kioslave/file/file.h"))); parsingUrls.append(KUrl(kdelibs + QLatin1String("/kioslave/metainfo/metainfo.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/about/kio_about.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/cgi/cgi.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/filter/filter.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/finger/kio_finger.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/fish/fish.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/floppy/kio_floppy.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/info/info.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/man/kio_man.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/media/kio_media.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/nfs/kio_nfs.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/remote/kio_remote.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/settings/kio_settings.cc"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/sftp/kio_sftp.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/smb/kio_smb.h"))); //parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/tar/tar.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/thumbnail/thumbnail.h"))); parsingUrls.append(KUrl(kdebase + QLatin1String("/runtime/kioslave/trash/kio_trash.h"))); out << "
" << endl; out << "

Analyzed KIO Slaves

" << endl; out << "
    " << endl; foreach(const KUrl &url, parsingUrls) { out << "
  • " << url.path() << "
  • " << endl; } out << "
" << endl; foreach(const KUrl &url, parsingUrls) { displayFoundMethods(existingMethods, url, out); } out << "
" << endl; out << "

SlaveBase methods to implement

" << endl; out << "
    " << endl; foreach(const QString &method, existingMethods) { out << "
  • " << method << "
  • " << endl; } out << "
" << endl; out << "" << endl; out << "" << endl; file.close(); } void FindIncompatibleKioTest::displayFoundMethods(const QStringList& methods, const KUrl& url, QTextStream& out) { QMap foundMethods = findMethods(methods, url); out << endl; out << "
" << endl; out << "

" << url.path() << "

" << endl; if (foundMethods.isEmpty()) { out << "No file found" << endl; out << "
" << endl; return; } out << "
" << endl; out << "

Found and Not Found methods :

" << endl; out << "
    " << endl; //Found methods QMapIterator i(foundMethods); while (i.hasNext()) { i.next(); if (i.value() == true) { out << "
  • " << i.key() << "
  • " << endl; } } //Found methods i = foundMethods; while (i.hasNext()) { i.next(); if (i.value() == false) { out << "
  • " << i.key() << "
  • " << endl; } } out << "
" << endl; } QMap FindIncompatibleKioTest::findMethods(const QStringList& methods, const KUrl& url) { QStringList lines = headerContent(url); if (lines.isEmpty()) return QMap(); QMap foundMethods; foreach(const QString &method, methods) { foundMethods.insert(method, false); } foreach(QString line, lines) { line = convertMethod(line); if (line.contains(QLatin1String("void")) == false) continue; //logDebug() << "Line" << convertMethod(line) << endl; foreach(const QString &method, methods) { if (line == convertMethod(method)) { foundMethods.insert(method, true); } /* else { logDebug() << method << " != " << line << endl; } */ } } logDebug() << endl; return foundMethods; } QString FindIncompatibleKioTest::convertMethod(const QString& method) { QString result(method); result = result.remove(QLatin1String("SlaveBase::")); result = result.remove(QLatin1String("virtual")); // result = result.remove(QLatin1String(" ")); // result = result.replace('\t', ' '); result = result.remove(QLatin1String(";")); result = result.simplified(); int firstParenthesis = result.indexOf(QLatin1String("(")); int lastParenthesis = result.indexOf(QLatin1String(")")); if (firstParenthesis != -1&& lastParenthesis != -1) result = result.remove(firstParenthesis+1, lastParenthesis-firstParenthesis-1); return result; } QStringList FindIncompatibleKioTest::headerContent(const KUrl& url) { QStringList kioHeaderContent; QString tmpFile; if (KIO::NetAccess::download(url, tmpFile, new QWidget()) ) { QFile file(tmpFile); file.open(QIODevice::ReadOnly); //If the file does not exist if (!file.exists()) { return QStringList(); } QTextStream inputStream(&file); while (inputStream.atEnd() == false) { kioHeaderContent.append(inputStream.readLine()); } file.close(); KIO::NetAccess::removeTempFile(tmpFile ); } else { logDebug() << KIO::NetAccess::lastErrorString() << endl;; } return kioHeaderContent; } QTEST_KDEMAIN(FindIncompatibleKioTest, GUI) #include "FindIncompatibleKioTest.moc"