summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/packagelistview.cpp
blob: 3c7435defc6e050efcfbbaa121b9f20b1418b7e6 (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
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
#include "packagelistview.h"

#include <qpopupmenu.h>
#include <qaction.h>

#include "listviewitemoipkg.h"
#include "packagelistitem.h"
#include "pksettings.h"

PackageListView::PackageListView(QWidget *p, const char* n, PackageManagerSettings *s)
  : QListView(p,n)
{
  settings = s;
  popupTimer = new QTimer( this );
  setSelectionMode(QListView::NoSelection);
  addColumn( tr("Package") );
  setRootIsDecorated( true );

  connect( popupTimer, SIGNAL(timeout()),
	   this, SLOT(showPopup()) );
  connect( this, SIGNAL( pressed( QListViewItem* ) ),
	   this, SLOT( setCurrent( QListViewItem* ) ) );
  connect( this, SIGNAL( clicked( QListViewItem* ) ),
	   this, SLOT( stopTimer( QListViewItem* ) ) );	

}

//PackageListView::~PackageListView()
//{
//}

void PackageListView::setCurrent( QListViewItem* p )
{
  qDebug("PackageListView::setCurrent ");
  activeItem = (ListViewItemOipkg*)p;

  if ( activeItem != 0 ) popupTimer->start( 750, true );
  
//  if ( activeItem->getType() != ListViewItemOipkg::Package ){
//    qDebug("PackageListView::setCurrent !p ");
//    activePackage = 0;
//	  activePackageListItem = 0;
//    qDebug("PackageListView::setCurrent returning ");
//    return;
//  };
//  activePackageListItem = (PackageListItem*)p;
//  activePackage = activePackageListItem->getPackage();
//  if (activePackage == 0 )
//    {
//      qDebug("PackageListView::setCurrent  if (!activePackage)");
//      return;
//    }
  

  qDebug("PackageListView::setCurrent popupTimer->start");
}


void PackageListView::showPopup()
{
  qDebug("PackageListView::showPopup");
  QPopupMenu *popup = activeItem->getPopupMenu();
  if (popup == 0) return;
  popup->popup( QCursor::pos() );
  qDebug("PackageListView::showPopup");
}

void PackageListView::stopTimer( QListViewItem* )
{
  popupTimer->stop();
}


void PackageListView::display()
{
  QDictIterator<PackageList> list( PackageLists );
  PackageList *packlist;
  OipkgPackage *pack;
  PackageListItem *item;
  ListViewItemOipkg *rootItem;
  QListViewItem* it;
  QListViewItem* itdel;
  while ( list.current() ) {
    packlist = list.current();
    rootItem = rootItems.find( list.currentKey() );
    //rootItem->clear();
    it=rootItem->firstChild();
    while ( it )
      {
	itdel = it;
	it    = it->nextSibling();
	delete itdel;
      }
    pack = packlist->first();
    while( pack )
      {
	item = new PackageListItem( rootItem, pack, settings );				
    	pack = packlist->next();
      }	
    ++list;
  }
}

void PackageListView::addList( QString n, PackageList* pl)
{
  PackageLists.insert(n, pl);
  ListViewItemOipkg *item = new ListViewItemOipkg(this,n,ListViewItemOipkg::Feed);
  rootItems.insert(n, item);
}