00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "packagelistview.h"
00011
00012 #include <qpopupmenu.h>
00013 #include <qaction.h>
00014
00015 #include "listviewitemoipkg.h"
00016 #include "packagelistitem.h"
00017 #include "pksettings.h"
00018
00019 PackageListView::PackageListView(QWidget *p, const char* n, PackageManagerSettings *s)
00020 : QListView(p,n)
00021 {
00022 settings = s;
00023 popupTimer = new QTimer( this );
00024 setSelectionMode(QListView::NoSelection);
00025 addColumn( tr("Package") );
00026 setRootIsDecorated( true );
00027
00028 connect( popupTimer, SIGNAL(timeout()),
00029 this, SLOT(showPopup()) );
00030 connect( this, SIGNAL( pressed(QListViewItem*) ),
00031 this, SLOT( setCurrent(QListViewItem*) ) );
00032 connect( this, SIGNAL( clicked(QListViewItem*) ),
00033 this, SLOT( stopTimer(QListViewItem*) ) );
00034
00035 }
00036
00037
00038
00039
00040
00041 void PackageListView::setCurrent( QListViewItem* p )
00042 {
00043 qDebug("PackageListView::setCurrent ");
00044 activeItem = (ListViewItemOipkg*)p;
00045
00046 if ( activeItem != 0 ) popupTimer->start( 750, true );
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 qDebug("PackageListView::setCurrent popupTimer->start");
00065 }
00066
00067
00068 void PackageListView::showPopup()
00069 {
00070 qDebug("PackageListView::showPopup");
00071 QPopupMenu *popup = activeItem->getPopupMenu();
00072 if (popup == 0) return;
00073 popup->popup( QCursor::pos() );
00074 qDebug("PackageListView::showPopup");
00075 }
00076
00077 void PackageListView::stopTimer( QListViewItem* )
00078 {
00079 popupTimer->stop();
00080 }
00081
00082
00083 void PackageListView::display()
00084 {
00085 QDictIterator<PackageList> list( PackageLists );
00086 PackageList *packlist;
00087 OipkgPackage *pack;
00088 PackageListItem *item;
00089 ListViewItemOipkg *rootItem;
00090 QListViewItem* it;
00091 QListViewItem* itdel;
00092 while ( list.current() ) {
00093 packlist = list.current();
00094 rootItem = rootItems.find( list.currentKey() );
00095
00096 it=rootItem->firstChild();
00097 while ( it )
00098 {
00099 itdel = it;
00100 it = it->nextSibling();
00101 delete itdel;
00102 }
00103 pack = packlist->first();
00104 while( pack )
00105 {
00106 item = new PackageListItem( rootItem, pack, settings );
00107 pack = packlist->next();
00108 }
00109 ++list;
00110 }
00111 }
00112
00113 void PackageListView::addList( QString n, PackageList* pl)
00114 {
00115 PackageLists.insert(n, pl);
00116 ListViewItemOipkg *item = new ListViewItemOipkg(this,n,ListViewItemOipkg::Feed);
00117 rootItems.insert(n, item);
00118 }