4 * Copyright (c) 2007 VOROSKOI Andras <voroskoi@frugalware.org>
6 * Copyright: See COPYING file that comes with this distribution.
11 #include <qlistview.h>
13 #include <qtabwidget.h>
16 #include <qapplication.h>
17 #include <qmessagebox.h>
18 #include <qstatusbar.h>
25 #include "mainwidget.h"
27 extern QPtrList
<PM_DB
> syncs
;
29 MainWidget::MainWidget(QWidget
* parent
, const char * name
, WFlags f
) : QWidget (parent
, name
, f
)
31 QVBoxLayout
*topLayout
= new QVBoxLayout(this);
32 Q_CHECK_PTR(topLayout
);
35 QPopupMenu
*file
= new QPopupMenu(this);
37 file
->insertItem( "E&xit", qApp
, SLOT(quit()), CTRL
+Key_Q
);
39 QPopupMenu
*help
= new QPopupMenu(this);
41 help
->insertItem( "&About", this, SLOT(about()) );
42 help
->insertItem( "About &Qt", this, SLOT(aboutQt()) );
44 QMenuBar
*menubar
= new QMenuBar(this);
46 menubar
->insertItem( "&File", file
);
47 menubar
->insertItem( "&Help", help
);
49 topLayout
->setMenuBar(menubar
);
52 GroupsView
= new QListView(this);
53 Q_CHECK_PTR(GroupsView
);
54 GroupsView
->addColumn("Groups");
56 GroupsView
->setSelectionMode( QListView::Single
);
58 connect( GroupsView
, SIGNAL( clicked( QListViewItem
* ) ), this, SLOT(groupItemSelected(QListViewItem
*)) );
61 PackagesView
= new QListView(this);
62 Q_CHECK_PTR(PackagesView
);
63 PackagesView
->addColumn("Name");
64 PackagesView
->addColumn("Status");
65 PackagesView
->addColumn("Version");
67 PackagesView
->setSelectionMode( QListView::Single
);
69 connect( PackagesView
, SIGNAL( clicked( QListViewItem
* ) ), this, SLOT(packageItemSelected(QListViewItem
*)) );
72 InfoView
= new QListView(this);
73 Q_CHECK_PTR(InfoView
);
74 InfoView
->header()->hide();
76 InfoView->setSorting(-1);*/
77 InfoView
->setSelectionMode(QListView::NoSelection
);
78 InfoView
->addColumn("Directive");
79 InfoView
->addColumn("Value");
82 QTabWidget
*pkgdetails
= new QTabWidget(this);
83 Q_CHECK_PTR(pkgdetails
);
84 pkgdetails
->addTab(InfoView
, "Info");
87 QHBoxLayout
*leftgrouplist
= new QHBoxLayout(topLayout
);
88 Q_CHECK_PTR(leftgrouplist
);
89 leftgrouplist
->addWidget(GroupsView
);
91 QVBoxLayout
*details
= new QVBoxLayout(leftgrouplist
);
93 details
->addWidget(PackagesView
);
94 details
->addWidget(pkgdetails
);
97 StatusBar
= new QStatusBar(this);
98 Q_CHECK_PTR(StatusBar
);
100 topLayout
->addWidget(StatusBar
);
103 MainWidget::~MainWidget()
108 void MainWidget::about() {
109 QMessageBox::about(this, "Kfpm for Frugalware",
110 "Kfpm is a graphical fronted for libpacman.\n\n"
111 "(c) 2007 Vöröskõi András");
114 void MainWidget::aboutQt() {
115 QMessageBox::aboutQt(this, "About Qt");
118 void MainWidget::updateGroupList() {
119 QStrList groupnames
= FPMClass
->sync_group(FPMClass
->getSync());
120 for (QStrList::Iterator it
= groupnames
.begin(); it
!= groupnames
.end(); it
++) {
121 (void) new QListViewItem(GroupsView
, *it
);
123 setStatusBarMessage("Grouplist loaded.");
126 void MainWidget::updateGroupPackageList(const char *groupname
) {
129 QStrList
*foo
= new QStrList();
130 foo
->append(groupname
);
131 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
132 QStrList pkgnames
= FPMClass
->sync_group(dbs
, foo
);
133 for (QStrList::Iterator it
= pkgnames
.begin(); it
!= pkgnames
.end(); it
++) {
134 /* FIXME it should check all sync db, not just the first one */
135 PM_PKG
*pkg
= pacman_db_readpkg(dbs
.first(), *it
);
136 PM_PKG
*localpkg
= pacman_db_readpkg(FPMClass
->LocalDB
, *it
);
138 QString version
= (char *)pacman_pkg_getinfo(pkg
, PM_PKG_VERSION
);
140 QString date
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
);
144 QString localversion
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_VERSION
);
145 if (localversion
!= version
)
149 QCheckListItem
*clitem
= new QCheckListItem(PackagesView
, *it
, QCheckListItem::CheckBox
);
150 clitem
->setPixmap(1, pm
);
151 clitem
->setText(2, version
);
155 void MainWidget::slot_initialize() {
156 FPMClass
= new FPM();
157 setStatusBarMessage("Initializing...");
158 qApp
->processEvents();
162 void MainWidget::setStatusBarMessage(QString message
) {
163 StatusBar
->message(message
);
166 void MainWidget::groupItemSelected( QListViewItem
*item
)
172 PackagesView
->clear();
173 updateGroupPackageList(item
->text(0));
177 void MainWidget::packageItemSelected(QListViewItem
*item
)
182 updateFullInfo(item
->text(0));
185 void MainWidget::updateFullInfo(const char *pkgname
)
192 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
193 /* FIXME it should check all sync db, not just the first one */
194 PM_PKG
*pkg
= pacman_db_readpkg(dbs
.first(), (char *)pkgname
);
195 PM_PKG
*localpkg
= pacman_db_readpkg(FPMClass
->LocalDB
, (char *)pkgname
);
196 char buffer
[50]; //for converting sizes
197 (void) new QListViewItem(InfoView
, "Name", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_NAME
));
198 (void) new QListViewItem(InfoView
, "Version", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_VERSION
));
199 long int size
= (long int)pacman_pkg_getinfo(pkg
, PM_PKG_SIZE
);
200 sprintf(buffer
, "%ld", size
);
201 (void) new QListViewItem(InfoView
, "Size (compressed)", buffer
);
202 size
= (long int)pacman_pkg_getinfo(localpkg
, PM_PKG_SIZE
);
203 sprintf(buffer
, "%ld", size
);
204 (void) new QListViewItem(InfoView
, "Size (uncompressed)", buffer
);
205 (void) new QListViewItem(InfoView
, "Description", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_DESC
));
206 QString date
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
);
207 switch((long)pacman_pkg_getinfo(localpkg
, PM_PKG_REASON
)) {
208 case PM_PKG_REASON_EXPLICIT
:
210 (void) new QListViewItem(InfoView
, "Reason", "Not installed");
212 (void) new QListViewItem(InfoView
, "Reason", "Explicitly installed");
214 case PM_PKG_REASON_DEPEND
:
215 (void) new QListViewItem(InfoView
, "Reason", "Installed as a dependency for another package");
218 (void) new QListViewItem(InfoView
, "Reason", "Unknown");
222 (void) new QListViewItem(InfoView
, "Install Date", date
);
226 // vim: sw=4 ts=4 noet