You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
adept/adept/libadept/packageinfo.cpp

182 lines
5.1 KiB

/** -*- C++ -*-
@file adept/packageinfo.cpp
@author Peter Rockai <me@mornfall.net>
*/
#include <tqcolor.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <kdebug.h>
#include <klocale.h>
#include <adept/packageinfo.h>
#include <adept/utils.h>
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::hidetqStatus() {
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.tqarg( c.red(), -2, 16 ).tqarg( c.green(), -2, 16 ).tqarg( c.blue(), -2, 16 );
} */
TQString colorify( TQColor c, TQString s )
{
return TQString( "<font color=\"" ) + c.name()
+ "\">" + s + "</font>";
}
TQString formatLongDescription( TQString l )
{
TQRegExp rx( u8( "^(.*)\n" ) );
rx.setMinimal( true );
l.replace( rx, u8( "\\1</p><p>" ) );
rx = TQRegExp( u8( "\\n[ ]*\\.\\n" ) );
l.replace( rx, u8( "</p><p>" ) );
rx = TQRegExp( u8( "\n " ) );
l.replace( rx, u8( " " ) );
rx = TQRegExp( u8( "\n - (.*)(\n|$)" ) );
rx.setMinimal( true );
l.replace( rx, u8( "\n<li>\\1</li>\n" ) );
l.replace( rx, u8( "\n<li>\\1</li>\n" ) );
return TQString( "<p>" ) + l + u8( "</p>" );
}
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( "<nobr>Currently " ) + colorify(
statusColor( p ),
u8( p.statusString( unk ) ) )
+ i18n( ", " ) + colorify(
actionColor( p ),
u8( p.actionString( unk ) ) ) + i18n( "
requested</nobr>" ) ); */
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 ) );
}
}