/** -*- C++ -*- @file adept/packageinfo.cpp @author Peter Rockai */ #include #include #include #include #include #include #include using namespace adept; using namespace cache; PackageInfo::PackageInfo( TQWidget *p, const char *n ) : PackageInfoUi( p, n ), m_specificVersion( false ) { observeComponent< component::State >(); } void PackageInfo::adjustFontSize( int s ) { adept::adjustFontSize( m_status, s ); adept::adjustFontSize( m_change, s ); adept::adjustFontSize( m_section, s ); adept::adjustFontSize( m_installedSize, s ); adept::adjustFontSize( m_maintainer, s ); adept::adjustFontSize( m_candidateVer, s ); adept::adjustFontSize( m_installedVer, s ); } void PackageInfo::hideStatus() { m_status->hide(); m_change->hide(); } namespace adept { TQColor statusColor( entity::Package p ) { if ( !p.valid() ) return TQt::black; TQColor c = TQt::blue; if (p.isInstalled()) c = TQt::darkGreen; if (p.isUpgradable()) c = TQt::darkYellow; if (p.isBroken()) c = TQt::red; return c; } TQColor actionColor( entity::Package p ) { if ( !p.valid() ) return TQt::black; TQColor c = TQt::blue; if (p.markedNewInstall()) c = TQt::darkGreen; if (p.markedUpgrade()) c = TQt::darkYellow; if (p.markedReInstall()) c = TQt::darkYellow; if (p.markedRemove()) c = TQt::darkRed; if (p.markedPurge()) c = TQt::red; if (p.willBreak()) c = TQt::red; return c; } /* TQString hexColor( TQColor c ) { TQString r( "#%1%2%3" ); return r.arg( c.red(), -2, 16 ).arg( c.green(), -2, 16 ).arg( c.blue(), -2, 16 ); } */ TQString colorify( TQColor c, TQString s ) { return TQString( "" + s + ""; } TQString formatLongDescription( TQString l ) { TQRegExp rx( u8( "^(.*)\n" ) ); rx.setMinimal( true ); l.replace( rx, u8( "\\1

" ) ); rx = TQRegExp( u8( "\\n[ ]*\\.\\n" ) ); l.replace( rx, u8( "

" ) ); rx = TQRegExp( u8( "\n " ) ); l.replace( rx, u8( " " ) ); rx = TQRegExp( u8( "\n - (.*)(\n|$)" ) ); rx.setMinimal( true ); l.replace( rx, u8( "\n

  • \\1
  • \n" ) ); l.replace( rx, u8( "\n
  • \\1
  • \n" ) ); return TQString( "

    " ) + l + u8( "

    " ); } void PackageInfo::setPackage( entity::Package p ) { kdDebug() << "PackageInfo::setPackage()" << endl; // ho hum, probably XXX fix libapt-front? setVersion( p.valid() ? p.anyVersion() : entity::Version(), false ); } void PackageInfo::setVersion( entity::Version v, bool specific ) { m_specificVersion = specific; m_version = v.stable(); if ( !m_version.valid() ) return; kdDebug() << "PackageInfo::setVersion() (valid)" << endl; m_section->setText( labelFormat( i18n( "Section:" ), u8( v.section( u8( i18n( "Unknown" ) ) ) ) ) ); m_maintainer->setText( labelFormat( i18n( "Maintainer:" ), u8( v.maintainer( u8( i18n( "Unknown" ) ) ) ), false ) ); notifyPostChange( 0 ); } void PackageInfo::notifyPostRebuild( component::Base *b ) { return notifyPostChange( b ); } void PackageInfo::notifyPostChange( component::Base * ) { if ( !m_version.valid() ) return; entity::Version v = m_version; entity::Package p = v.package(); TQString cv = i18n( "n/a" ), iv = i18n( "n/a" ), is = i18n( "n/a" ), status, action; if (p.valid()) { entity::Version _cv = p.candidateVersion(); entity::Version _iv = p.installedVersion(); if (_cv.valid()) { cv = u8( _cv.versionString() ); is = u8( _cv.installedSizeString() ); } if (_iv.valid()) { iv = _iv.versionString(); } } std::string unk = u8( i18n( "unknown" ) ); /* m_status->setText( i18n( "Currently " ) + colorify( statusColor( p ), u8( p.statusString( unk ) ) ) + i18n( ", " ) + colorify( actionColor( p ), u8( p.actionString( unk ) ) ) + i18n( " requested" ) ); */ m_status->setText( labelFormat( i18n( "Status:" ), colorify( statusColor( p ), u8( p.statusString( u8( i18n( "Unknown" ) ) ) ) ) ) ); m_change->setText( labelFormat( i18n( "Requested change:" ), colorify( actionColor( p ), u8( p.actionString( u8( i18n( "Unknown" ) ) ) ) ) ) ); m_candidateVer->setText( m_specificVersion ? labelFormat( i18n( "Version:" ), v.versionString() + "(" + i18n( "candidate" ) + " " + cv + ")" ) : labelFormat( i18n( "Candidate Version:" ), cv ) ); m_installedVer->setText( labelFormat( i18n( "Installed Version:" ), iv ) ); m_installedSize->setText( labelFormat( i18n( "Installed Size:" ), is ) ); } }