show installed state in PackagesView
[kfpm.git] / mainwidget.cpp
blob88426e64a78d2596d22749ba8d6ab72995ee2b66
1 /*
2 * mainwidget.cpp
4 * Copyright (c) 2007 VOROSKOI Andras <voroskoi@frugalware.org>
6 * Copyright: See COPYING file that comes with this distribution.
8 */
10 #include <iostream>
11 #include <qlistview.h>
12 #include <qlayout.h>
13 #include <qtabwidget.h>
14 #include <qlistbox.h>
15 #include <qmenubar.h>
16 #include <qapplication.h>
17 #include <qmessagebox.h>
18 #include <qstatusbar.h>
19 #include <qtimer.h>
21 #include <qstrlist.h>
23 #include "kfpm.h"
24 #include "mainwidget.h"
26 extern QPtrList<PM_DB> syncs;
28 MainWidget::MainWidget(QWidget * parent, const char * name, WFlags f) : QWidget (parent, name, f)
30 QVBoxLayout *topLayout = new QVBoxLayout(this);
31 Q_CHECK_PTR(topLayout);
33 /* Menubar */
34 QPopupMenu *file = new QPopupMenu(this);
35 Q_CHECK_PTR(file);
36 file->insertItem( "E&xit", qApp, SLOT(quit()), CTRL+Key_Q );
38 QPopupMenu *help = new QPopupMenu(this);
39 Q_CHECK_PTR(help);
40 help->insertItem( "&About", this, SLOT(about()) );
41 help->insertItem( "About &Qt", this, SLOT(aboutQt()) );
43 QMenuBar *menubar = new QMenuBar(this);
44 Q_CHECK_PTR(menubar);
45 menubar->insertItem( "&File", file );
46 menubar->insertItem( "&Help", help);
48 topLayout->setMenuBar(menubar);
50 /* Groups */
51 GroupsView = new QListView(this);
52 Q_CHECK_PTR(GroupsView);
53 GroupsView->addColumn("Groups");
55 GroupsView->setSelectionMode( QListView::Single );
57 connect( GroupsView, SIGNAL( clicked( QListViewItem* ) ), this, SLOT(groupItemSelected(QListViewItem*)) );
59 /* Packages */
60 PackagesView = new QListView(this);
61 Q_CHECK_PTR(PackagesView);
62 PackagesView->addColumn("Name");
63 PackagesView->addColumn("Status");
64 PackagesView->addColumn("Version");
66 PackagesView->setSelectionMode( QListView::Single );
68 connect( PackagesView, SIGNAL( clicked( QListViewItem* ) ), this, SLOT(packageItemSelected(QListViewItem*)) );
70 /* Info */
71 InfoView = new QListView(this);
72 Q_CHECK_PTR(InfoView);
73 InfoView->addColumn("Directive");
74 InfoView->addColumn("Value");
76 /* Details */
77 QTabWidget *pkgdetails = new QTabWidget(this);
78 Q_CHECK_PTR(pkgdetails);
79 pkgdetails->addTab(InfoView, "Info");
81 /* Layout */
82 QHBoxLayout *leftgrouplist = new QHBoxLayout(topLayout);
83 Q_CHECK_PTR(leftgrouplist);
84 leftgrouplist->addWidget(GroupsView);
86 QVBoxLayout *details = new QVBoxLayout(leftgrouplist);
87 Q_CHECK_PTR(details);
88 details->addWidget(PackagesView);
89 details->addWidget(pkgdetails);
91 /* StatusBar */
92 StatusBar = new QStatusBar(this);
93 Q_CHECK_PTR(StatusBar);
95 topLayout->addWidget(StatusBar);
98 MainWidget::~MainWidget()
100 delete FPMClass;
103 void MainWidget::about() {
104 QMessageBox::about(this, "Kfpm for Frugalware",
105 "Kfpm is a graphical fronted for libpacman.\n");
108 void MainWidget::aboutQt() {
109 QMessageBox::aboutQt(this, "About Qt");
112 void MainWidget::updateGroupList() {
113 QStrList groupnames = FPMClass->sync_group(FPMClass->getSync());
114 for (QStrList::Iterator it = groupnames.begin(); it != groupnames.end(); it++) {
115 (void) new QListViewItem(GroupsView, *it);
117 setStatusBarMessage("Grouplist loaded.");
120 void MainWidget::updateGroupPackageList(const char *groupname) {
121 QString status = "Installed";
122 QStrList *foo = new QStrList();
123 foo->append(groupname);
124 QValueVector<PM_DB*> dbs = FPMClass->getSync();
125 QStrList pkgnames = FPMClass->sync_group(dbs, foo);
126 for (QStrList::Iterator it = pkgnames.begin(); it != pkgnames.end(); it++) {
127 // PM_PKG *pacman_db_readpkg(PM_DB *db, char *name);
128 /* FIXME it should check all sync db, not just the first one */
129 PM_PKG *pkg = pacman_db_readpkg(dbs.first(), *it);
130 PM_PKG *localpkg = pacman_db_readpkg(FPMClass->LocalDB, *it);
132 QString date = (char *)pacman_pkg_getinfo(localpkg, PM_PKG_INSTALLDATE);
133 if (date.isEmpty()) {
134 status = "Not Installed";
137 QCheckListItem *clitem = new QCheckListItem(PackagesView, *it, QCheckListItem::CheckBox);
138 clitem->setText(1, status);
139 clitem->setText(2, (char *)pacman_pkg_getinfo(pkg, PM_PKG_VERSION));
143 void MainWidget::slot_initialize() {
144 FPMClass = new FPM();
145 setStatusBarMessage("Initializing...");
146 qApp->processEvents();
147 updateGroupList();
150 void MainWidget::setStatusBarMessage(QString message) {
151 StatusBar->message(message);
154 void MainWidget::groupItemSelected( QListViewItem *item )
156 if (item == 0) {
157 return;
159 else {
160 PackagesView->clear();
161 updateGroupPackageList(item->text(0));
165 void MainWidget::packageItemSelected(QListViewItem *item)
167 if (item == 0) {
168 return;
170 updateFullInfo(item->text(0));
173 void MainWidget::updateFullInfo(const char *pkgname)
175 if (pkgname == 0) {
176 return;
178 else {
179 InfoView->clear();
180 QValueVector<PM_DB*> dbs = FPMClass->getSync();
181 /* FIXME it should check all sync db, not just the first one */
182 PM_PKG *pkg = pacman_db_readpkg(dbs.first(), (char *)pkgname);
183 PM_PKG *localpkg = pacman_db_readpkg(FPMClass->LocalDB, (char *)pkgname);
184 char buffer[50]; //for converting sizes
185 (void) new QListViewItem(InfoView, "Name", (char *)pacman_pkg_getinfo(pkg, PM_PKG_NAME));
186 (void) new QListViewItem(InfoView, "Version", (char *)pacman_pkg_getinfo(pkg, PM_PKG_VERSION));
187 long int size = (long int)pacman_pkg_getinfo(pkg, PM_PKG_SIZE);
188 sprintf(buffer, "%ld", size);
189 (void) new QListViewItem(InfoView, "Size (compressed)", buffer);
190 (void) new QListViewItem(InfoView, "Description", (char *)pacman_pkg_getinfo(pkg, PM_PKG_DESC));
191 /* FIXME Says explicitly installed on uninstalled packages */
192 switch((long)pacman_pkg_getinfo(localpkg, PM_PKG_REASON)) {
193 case PM_PKG_REASON_EXPLICIT:
194 (void) new QListViewItem(InfoView, "Reason", "Explicitly installed");
195 break;
196 case PM_PKG_REASON_DEPEND:
197 (void) new QListViewItem(InfoView, "Reason", "Installed as a dependency for another package");
198 break;
199 default:
200 (void) new QListViewItem(InfoView, "Reason", "Unknown");
201 break;
203 (void) new QListViewItem(InfoView, "Install Date", (char *)pacman_pkg_getinfo(localpkg, PM_PKG_INSTALLDATE));
207 // vim: sw=4 ts=4 noet