summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/packagelistview.cpp
blob: 70aa48ae03fa8bb23508e16b35fc47713aff99d0 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "packagelistview.h"

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

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

PackageListView::PackageListView(QWidget *p, const char* n, PackageManagerSettings *s)
	: QListView(p,n)
{
	settings = s;
	popupMenu = new QPopupMenu( this );	
	destsMenu = new QPopupMenu( popupMenu );
  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 )
{
  if ( !p ) return;
  activePackageListItem = (PackageListItem*)p;
  activePackage = activePackageListItem->getPackage();
  if (!activePackage)
  {
//		QDictIterator<QCheckListItem> it( rootItems );
//		while ( it.current() )
//    {
//			if ( it.current()==p )
//   			pvDebug(2,"current item");
//			++it;
//		}

		return;
  }
  popupTimer->start( 750, true );
}


void PackageListView::showPopup()
{
  popupMenu->clear();
  destsMenu->clear();
 		
 	QAction *popupAction;
  if ( !activePackage->installed() )
  {
	  popupMenu->insertItem( QObject::tr("Install to"), destsMenu );
  	QStringList dests = settings->getDestinationNames();
   	QString ad = settings->getDestinationName();
	  for (uint i = 0; i < dests.count(); i++ )
  	{		
	  	popupAction = new QAction( dests[i], QString::null, 0, this, 0 );
		  popupAction->addTo( destsMenu );
    	if ( dests[i] == ad && activePackage->toInstall() )
     	{
        popupAction->setToggleAction( true );
			  popupAction->setOn(true);
  		};
  	}
	  connect( destsMenu, SIGNAL( activated( int ) ),
		   this, SLOT( changePackageDest( int ) ) );
   }else{
   	popupAction = new QAction( QObject::tr("Remove"),QString::null,  0, this, 0 );
		popupAction->addTo( popupMenu );
  	connect( popupAction, SIGNAL( activated() ),
	   	this , SLOT( toggleProcess() ) );
   	popupAction = new QAction( QObject::tr("Reinstall"),QString::null,  0, this, 0 );
		popupAction->addTo( popupMenu );
  	popupAction->setEnabled( false );
   }
  popupMenu->popup( QCursor::pos() );
}

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


void PackageListView::changePackageDest( int i )
{
 	activePackage->setDest( destsMenu->text(i) );
  activePackage->setOn();
  activePackage->setLink( settings->createLinks() );
  activePackageListItem->displayDetails();
}

void PackageListView::toggleProcess()
{
  activePackage->toggleProcess() ;
  activePackageListItem->displayDetails();
}

void PackageListView::display()
{
	QDictIterator<PackageList> list( PackageLists );
	PackageList *packlist;
	Package *pack;
  PackageListItem *item;
  QCheckListItem *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);
 	QCheckListItem *item = new QCheckListItem(this,n);
 	rootItems.insert(n, item);
}