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>
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
);
34 QPopupMenu
*file
= new QPopupMenu(this);
36 file
->insertItem( "E&xit", qApp
, SLOT(quit()), CTRL
+Key_Q
);
38 QPopupMenu
*help
= new QPopupMenu(this);
40 help
->insertItem( "&About", this, SLOT(about()) );
41 help
->insertItem( "About &Qt", this, SLOT(aboutQt()) );
43 QMenuBar
*menubar
= new QMenuBar(this);
45 menubar
->insertItem( "&File", file
);
46 menubar
->insertItem( "&Help", help
);
48 topLayout
->setMenuBar(menubar
);
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
*)) );
60 PackagesView
= new QListView(this);
61 Q_CHECK_PTR(PackagesView
);
62 PackagesView
->addColumn("Name");
63 PackagesView
->addColumn("Status");
64 PackagesView
->addColumn("Desctiption");
66 PackagesView
->setSelectionMode( QListView::Single
);
68 connect( PackagesView
, SIGNAL( clicked( QListViewItem
* ) ), this, SLOT(packageItemSelected(QListViewItem
*)) );
71 InfoView
= new QListView(this);
72 Q_CHECK_PTR(InfoView
);
73 InfoView
->addColumn("Directive");
74 InfoView
->addColumn("Value");
77 QTabWidget
*pkgdetails
= new QTabWidget(this);
78 Q_CHECK_PTR(pkgdetails
);
79 pkgdetails
->addTab(InfoView
, "Info");
82 QHBoxLayout
*leftgrouplist
= new QHBoxLayout(topLayout
);
83 Q_CHECK_PTR(leftgrouplist
);
84 leftgrouplist
->addWidget(GroupsView
);
86 QVBoxLayout
*details
= new QVBoxLayout(leftgrouplist
);
88 details
->addWidget(PackagesView
);
89 details
->addWidget(pkgdetails
);
92 StatusBar
= new QStatusBar(this);
93 Q_CHECK_PTR(StatusBar
);
95 topLayout
->addWidget(StatusBar
);
98 MainWidget::~MainWidget()
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 QStrList
*foo
= new QStrList();
122 foo
->append(groupname
);
123 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
124 QStrList pkgnames
= FPMClass
->sync_group(dbs
, foo
);
125 for (QStrList::Iterator it
= pkgnames
.begin(); it
!= pkgnames
.end(); it
++) {
126 // PM_PKG *pacman_db_readpkg(PM_DB *db, char *name);
127 /* FIXME it should check all sync db, not just the first one */
128 PM_PKG
*pkg
= pacman_db_readpkg(dbs
.first(), *it
);
129 PM_PKG
*localpkg
= pacman_db_readpkg(FPMClass
->LocalDB
, *it
);
131 QString date
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
);
132 if (date
.isEmpty()) {
133 std::cout
<< "not installed" << std::endl
;
136 QCheckListItem
*clitem
= new QCheckListItem(PackagesView
, *it
, QCheckListItem::CheckBox
);
137 clitem
->setText(1, (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
));
138 clitem
->setText(2, (char *)pacman_pkg_getinfo(pkg
, PM_PKG_VERSION
));
142 void MainWidget::slot_initialize() {
143 FPMClass
= new FPM();
144 setStatusBarMessage("Initializing...");
145 qApp
->processEvents();
149 void MainWidget::setStatusBarMessage(QString message
) {
150 StatusBar
->message(message
);
153 void MainWidget::groupItemSelected( QListViewItem
*item
)
159 PackagesView
->clear();
160 updateGroupPackageList(item
->text(0));
164 void MainWidget::packageItemSelected(QListViewItem
*item
)
169 updateFullInfo(item
->text(0));
172 void MainWidget::updateFullInfo(const char *pkgname
)
179 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
180 /* FIXME it should check all sync db, not just the first one */
181 PM_PKG
*pkg
= pacman_db_readpkg(dbs
.first(), (char *)pkgname
);
182 PM_PKG
*localpkg
= pacman_db_readpkg(FPMClass
->LocalDB
, (char *)pkgname
);
183 char buffer
[50]; //for converting sizes
184 (void) new QListViewItem(InfoView
, "Name", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_NAME
));
185 (void) new QListViewItem(InfoView
, "Version", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_VERSION
));
186 long int size
= (long int)pacman_pkg_getinfo(pkg
, PM_PKG_SIZE
);
187 sprintf(buffer
, "%ld", size
);
188 (void) new QListViewItem(InfoView
, "Size (compressed)", buffer
);
189 (void) new QListViewItem(InfoView
, "Description", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_DESC
));
190 /* FIXME Says explicitly installed on uninstalled packages */
191 switch((long)pacman_pkg_getinfo(localpkg
, PM_PKG_REASON
)) {
192 case PM_PKG_REASON_EXPLICIT
:
193 (void) new QListViewItem(InfoView
, "Reason", "Explicitly installed");
195 case PM_PKG_REASON_DEPEND
:
196 (void) new QListViewItem(InfoView
, "Reason", "Installed as a dependency for another package");
199 (void) new QListViewItem(InfoView
, "Reason", "Unknown");
202 (void) new QListViewItem(InfoView
, "Install Date", (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
));
206 // vim: sw=4 ts=4 noet