summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/packagelistitem.cpp
blob: 0c7c9280c70f955a5993ba0c97607c331fdbe27b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "packagelistitem.h"

#include <qpe/resource.h>
#include <qobject.h>

#include "debug.h"

static QPixmap *pm_uninstalled=0;
static QPixmap *pm_installed=0;
static QPixmap *pm_uninstall=0;
static QPixmap *pm_install=0;

PackageListItem::PackageListItem(QListView* lv, Package *pi, PackageManagerSettings *s)
  :	QCheckListItem(lv,pi->name(),CheckBox)
{
  package = pi;
  settings = s;
  setExpandable( true );
	QCheckListItem *item;
	nameItem = new QCheckListItem( this, "" );
	item = new QCheckListItem( this, QObject::tr("Description: ")+pi->desc() );
	item = new QCheckListItem( this, QObject::tr("Size: ")+pi->size() );
	destItem = new QCheckListItem( this, "" );
	linkItem = new QCheckListItem( this, "" );
  displayDetails();

  if (!pm_uninstalled)
  {
    pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled"));
    pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed"));
    pm_install = new QPixmap(Resource::loadPixmap("oipkg/install"));
    pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall"));
  }
}

void PackageListItem::paintCell( QPainter *p,  const QColorGroup & cg,
				 int column, int width, int alignment )
{
  if ( !p )
    return;

  p->fillRect( 0, 0, width, height(),
	       isSelected()? cg.highlight() : cg.base() );

  if ( column != 0 ) {
    // The rest is text
    QListViewItem::paintCell( p, cg, column, width, alignment );
    return;
  }

  QListView *lv = listView();
  if ( !lv )
    return;
  int marg = lv->itemMargin();
  int r = marg;

  QPixmap pm = statePixmap();
  p->drawPixmap(marg,(height()-pm.height())/2,pm);
  r += pm.width()+1;

  p->translate( r, 0 );
  QListViewItem::paintCell( p, cg, column, width - r, alignment );
}


void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg,
				  const QRect & r )
{
  // Skip QCheckListItem
  // (makes you wonder what we're getting from QCheckListItem)
  QListViewItem::paintFocus(p,cg,r);
}

QPixmap PackageListItem::statePixmap() const
{
  bool installed = package->installed();
  if ( !package->toProcess() ) {
    if ( !installed )
      return *pm_uninstalled;
    else
      return *pm_installed;
  } else {
    if ( !installed )
      return *pm_install;
    else
      return *pm_uninstall;
  }
}

QString PackageListItem::key( int column, bool ascending ) const
{
  if ( column == 2 ) {
    QString t = text(2);
    double bytes=t.toDouble();
    if ( t.contains('M') ) bytes*=1024*1024;
    else if ( t.contains('K') || t.contains('k') ) bytes*=1024;
    if ( !ascending ) bytes=999999999-bytes;
    return QString().sprintf("%09d",(int)bytes);
  } else {
    return QListViewItem::key(column,ascending);
  }
}

void PackageListItem::setOn( bool b )
{
  QCheckListItem::setOn( b );
  package->toggleProcess();
  package->setLink( settings->createLinks() );
  displayDetails();
}

void PackageListItem::displayDetails()
{
	QString sod = " ("+package->sizeUnits();
 	sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest());
  sod += ")";
  setText(0, package->name()+sod );
	nameItem->setText( 0, QObject::tr("Name: ")+package->name());
	linkItem->setText( 0, QObject::tr("Link: ")+QString(package->link()?QObject::tr("Yes"):QObject::tr("No")) );
  destItem->setText( 0, QObject::tr("Destination: ")+package->dest() );
  repaint();
}