/*************************************************************************** * Copyright (C) 2003 by Sylvain Joyeux * * sylvain.joyeux@m4x.org * * * * 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. * ***************************************************************************/ #include #include "dpkg.h" #include "debug.h" #include #include #include #include Dpkg::Dpkg(QObject *parent, const char *name) : PackageManager(parent, name) { connect(&m_process, SIGNAL(readReady (KProcIO *)), this, SLOT(readReady(KProcIO*))); } Dpkg::~Dpkg() { } int Dpkg::capabilities( int query ) const { if ( (query & SEARCH_FILE) && (query & OFFLINE) ) return query | INSTALLED_ONLY; if ( (query & LIST_FILES) && (query & OFFLINE) ) return query | INSTALLED_ONLY; if ( query & ONLINE ) return query; return NOT_SUPPORTED; } void Dpkg::readReady(KProcIO*) { bool partial; QString newline; QStringList lines; while(m_process.readln(newline, true, &partial) != -1) { if (partial) m_buffer += newline; else { newline.truncate(newline.length()); QString line(m_buffer + newline); lines << line; m_buffer = ""; } } (this->*m_receive)(lines); } bool Dpkg::search( const QString & file ) { m_process.resetAll(); m_buffer = QString::null; m_process.clearArguments(); m_process << "dpkg" << "-S" << file; m_receive = &Dpkg::receiveSearch; return m_process.start(KProcess::Block, KProcess::Stdout ); } void Dpkg::receiveSearch( const QStringList & line ) { static QRegExp rx_notfound("dpkg: (.*) not found"); // the format of the dpkg -S answer is // package1[, package2[, package3...]]: file for (QStringList::ConstIterator i = line.begin(); i != line.end(); ++i) { //kdDebug(DEBUG_ZONE) << *i << endl; if ((*i).isEmpty()) continue; if (rx_notfound.exactMatch(*i)) { emit token("error", i18n("%1 not found").arg(rx_notfound.cap(1))); continue; } int semicolon = (*i).find(':'); if (semicolon == -1) { kdDebug(DEBUG_ZONE) << "receiveSearch unmatched line : " << *i << endl; continue; } QStringList packages = QStringList::split(',', (*i).left(semicolon)); QString file = (*i).right( (*i).length() - semicolon - 1 ); emit token("file", file.stripWhiteSpace()); for (QStringList::ConstIterator j = packages.begin(); j != packages.end(); ++j) emit token("package", (*j).stripWhiteSpace()); } } bool Dpkg::list( const QString & package ) { m_process.resetAll(); m_buffer = QString::null; m_process.clearArguments(); m_process << "dpkg" << "-L" << package; m_receive = &Dpkg::receiveList; return m_process.start(KProcess::Block, KProcess::Stdout ); } void Dpkg::receiveList( const QStringList & line ) { static QRegExp rx_notfound("Package (.*) is not installed"); for (QStringList::ConstIterator i = line.begin(); i != line.end(); ++i) { if (rx_notfound.search(*i) > -1) emit token("error", i18n("Package %1 is not installed").arg(rx_notfound.cap(1))); else if ((*i).startsWith("/")) emit token("file", *i); } } static const QString html_form_begin("\n
\n" "\n"); static QString make_title(const QString& title) { return "\t\n"; } static const QString html_form_end("\n" "\t\n" "\n" "
" + title + "
\n" "\t\t\n" "\t\t\n" "\t\t\n" "\t
\n" "
\n"); static const QString html_form_line_begin("\n" "\t\n" "\t\n"); static const QString html_form_line_end("\n\n"); static const QString html_form_combo("").arg(type).arg(type) + html_form_line_end; } static QString begin_form_combo(const QString& type, const QString& label) { return html_form_line_begin.arg(type).arg(label) + QString("\t\n\t\n\n"; } QString Dpkg::getOnlineForm() { QString buffer; QTextOStream stream(&buffer); stream << html_form_begin << make_title( i18n("packages.ubuntu.com")) << make_form_text("word", i18n("File to search")) << begin_form_combo("arch", i18n("Architecture")) << make_form_option("i386", i18n("Intel x86")) << make_form_option("amd64", i18n("AMD64")) << make_form_option("sparc", i18n("SPARC")) << make_form_option("powerpc", i18n("PowerPC")) << make_form_option("hppa", i18n("HP PA/RISC")) << make_form_option("ia64", i18n("Intel IA-64")) << end_form_combo() << begin_form_combo("version", i18n("Version")) << make_form_option("gutsy", "gutsy") << make_form_option("feisty", "feisty") << make_form_option("edgy", "edgy") << make_form_option("dapper", "dapper") << make_form_option("breezy", "breezy") << make_form_option("hoary", "hoary") << make_form_option("warty", "warty") << end_form_combo() << html_form_end.arg(i18n("Go online!")); return buffer; } #include "dpkg.moc"