Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

packagelistitem.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 // (c) 2002 Patrick S. Vogt <tille@handhelds.org>
00010 #include "packagelistitem.h"
00011 
00012 #include <qpe/resource.h>
00013 #include <qobject.h>
00014 #include <qpopupmenu.h>
00015 #include <qaction.h>
00016 
00017 #include "debug.h"
00018 
00019 static QPixmap *pm_uninstalled=0;
00020 static QPixmap *pm_uninstalled_old=0;
00021 static QPixmap *pm_installed=0;
00022 static QPixmap *pm_installed_old=0;
00023 static QPixmap *pm_uninstall=0;
00024 static QPixmap *pm_install=0;
00025 static QPixmap *pm_uninstalled_old_installed_new=0;
00026 static QPixmap *pm_uninstalled_installed_old=0;
00027 
00028 PackageListItem::PackageListItem(ListViewItemOipkg *parent, QString name, Type ittype)
00029   : ListViewItemOipkg(parent,name,ittype)
00030 {
00031 
00032 }
00033 
00034 PackageListItem::PackageListItem(QListView* lv, OipkgPackage *pi, PackageManagerSettings *s)
00035   :     ListViewItemOipkg(lv,pi->name(),ListViewItemOipkg::Package)
00036 {
00037   init(pi,s);
00038 }
00039 
00040 PackageListItem::PackageListItem(ListViewItemOipkg *lvi, OipkgPackage *pi, PackageManagerSettings *s)
00041   :     ListViewItemOipkg(lvi,pi->name(),ListViewItemOipkg::Package)
00042 {
00043   init(pi,s);
00044 }
00045 PackageListItem::~PackageListItem()
00046 {
00047    delete popupMenu;
00048    delete destsMenu;
00049 }
00050 
00051 void PackageListItem::init( OipkgPackage *pi, PackageManagerSettings *s)
00052 {
00053   //waring pass something different than 0
00054   popupMenu = new QPopupMenu( 0 );
00055   destsMenu = new QPopupMenu( 0 );
00056   package = pi;
00057   settings = s;
00058   setExpandable( true );
00059   ListViewItemOipkg *item;
00060   nameItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute,"name"  );
00061   item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Description: ")+pi->desc()  );
00062   item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Size: ")+pi->size() );
00063   destItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "dest" );
00064   linkItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "link" );
00065   statusItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "status" );
00066   ListViewItemOipkg *otherItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("other") );
00067   item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QObject::tr("Install Name: ")+pi->installName() );
00068   QDict<QString> *fields = pi->getFields();
00069   QDictIterator<QString> it( *fields );
00070   while ( it.current() ) {
00071     item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QString(it.currentKey()+": "+*it.current()) );
00072     ++it;
00073   }
00074   displayDetails();
00075 
00076   if (!pm_uninstalled)
00077     {
00078       pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled"));
00079       pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld"));
00080       pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew"));
00081       pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld"));
00082       pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed"));
00083       pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld"));
00084       pm_install = new QPixmap(Resource::loadPixmap("oipkg/install"));
00085       pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall"));
00086     }
00087 }
00088 
00089 void PackageListItem::paintCell( QPainter *p,  const QColorGroup & cg,
00090                                  int column, int width, int alignment )
00091 {
00092   if ( !p )
00093     return;
00094 
00095   p->fillRect( 0, 0, width, height(),
00096                isSelected()? cg.highlight() : cg.base() );
00097 
00098   if ( column != 0 ) {
00099     // The rest is text
00100     QListViewItem::paintCell( p, cg, column, width, alignment );
00101     return;
00102   }
00103 
00104   QListView *lv = listView();
00105   if ( !lv )
00106     return;
00107   int marg = lv->itemMargin();
00108   int r = marg;
00109 
00110   QPixmap pm = statePixmap();
00111   p->drawPixmap(marg,(height()-pm.height())/2,pm);
00112   r += pm.width()+1;
00113 
00114   p->translate( r, 0 );
00115   QListViewItem::paintCell( p, cg, column, width - r, alignment );
00116 }
00117 
00118 
00119 void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg,
00120                                   const QRect & r )
00121 {
00122   // Skip QCheckListItem
00123   // (makes you wonder what we're getting from QCheckListItem)
00124   QListViewItem::paintFocus(p,cg,r);
00125 }
00126 
00127 QPixmap PackageListItem::statePixmap() const
00128 {
00129   bool installed = package->installed();
00130   bool old = package->isOld();
00131   bool verinstalled = package->otherInstalled();
00132   if ( !package->toProcess() ) {
00133     if ( !installed )
00134       if (old)
00135         {
00136           if (verinstalled) return *pm_uninstalled_old_installed_new;
00137           else return *pm_uninstalled_old;
00138         }
00139       else
00140         {
00141           if (verinstalled) return *pm_uninstalled_installed_old;
00142           else return *pm_uninstalled;
00143         }
00144     else
00145       if (old) return *pm_installed_old;
00146       else return *pm_installed;
00147   } else { //toProcess() == true
00148     if ( !installed )
00149       return *pm_install;
00150     else
00151       return *pm_uninstall;
00152   }
00153 }
00154 
00155 QString PackageListItem::key( int column, bool ascending ) const
00156 {
00157   if ( column == 2 ) {
00158     QString t = text(2);
00159     double bytes=t.toDouble();
00160     if ( t.contains('M') ) bytes*=1024*1024;
00161     else if ( t.contains('K') || t.contains('k') ) bytes*=1024;
00162     if ( !ascending ) bytes=999999999-bytes;
00163     return QString().sprintf("%09d",(int)bytes);
00164   } else {
00165     return QListViewItem::key(column,ascending);
00166   }
00167 }
00168 
00169 void PackageListItem::setOn( bool b )
00170 {
00171   QCheckListItem::setOn( b );
00172   package->toggleProcess();
00173   package->setLink( settings->createLinks() );
00174   displayDetails();
00175 }
00176 
00177 void PackageListItem::displayDetails()
00178 {
00179   QString sod;
00180   sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits());
00181   //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest());
00182   sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest());
00183   sod = sod.isEmpty()?QString(""):QString(" ("+sod+")");
00184   setText(0, package->name()+sod );
00185   nameItem->setText( 0, QObject::tr("Name: ")+package->name());
00186   linkItem->setText( 0, QObject::tr("Link: ")+(package->link()?QObject::tr("Yes"):QObject::tr("No")));
00187   destItem->setText( 0, QObject::tr("Destination: ")+package->dest() );
00188   statusItem->setText( 0, QObject::tr("Status: ")+package->status() );
00189   repaint();
00190 }
00191 
00192 QPopupMenu* PackageListItem::getPopupMenu()
00193 {
00194   popupMenu->clear();
00195   destsMenu->clear();
00196 
00197   QAction *popupAction;
00198   qDebug("PackageListItem::showPopup ");
00199 
00200   if (!package->installed()){
00201     popupMenu->insertItem( QObject::tr("Install to"), destsMenu );
00202     QStringList dests = settings->getDestinationNames();
00203     QString ad = settings->getDestinationName();
00204     for (uint i = 0; i < dests.count(); i++ )
00205         {
00206      popupAction = new QAction( dests[i], QString::null, 0, popupMenu, 0 );
00207      popupAction->addTo( destsMenu );
00208      if ( dests[i] == ad && getPackage()->toInstall() )
00209             {
00210               popupAction->setToggleAction( true );
00211               popupAction->setOn(true);
00212             }
00213     }
00214   connect( destsMenu, SIGNAL( activated(int) ),
00215                this, SLOT( menuAction(int) ) );
00216       popupMenu->popup( QCursor::pos() );
00217   }else{
00218     popupMenu->insertItem( QObject::tr("Remove"));
00219   connect( popupMenu, SIGNAL( activated(int) ),
00220                this, SLOT( menuAction(int) ) );
00221       popupMenu->popup( QCursor::pos() );   
00222   }
00223   return popupMenu;
00224 }
00225 
00226 void PackageListItem::menuAction( int i )
00227 {
00228   if (!package->installed()){
00229     package->setDest( destsMenu->text(i) );
00230     package->setLink( settings->createLinks() );
00231   }
00232   package->setOn();
00233   displayDetails();
00234 }
00235 
00236 //void PackageListItem::toggleProcess()
00237 //{
00238 //  package->toggleProcess() ;
00239 //  displayDetails();
00240 //}

Generated on Sat Nov 5 16:18:10 2005 for OPIE by  doxygen 1.4.2