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>
26 #include "mainwidget.h"
28 extern QPtrList
<PM_DB
> syncs
;
30 MainWidget::MainWidget(QWidget
* parent
, const char * name
, WFlags f
) : QWidget (parent
, name
, f
)
32 QVBoxLayout
*topLayout
= new QVBoxLayout(this);
33 Q_CHECK_PTR(topLayout
);
36 QPopupMenu
*file
= new QPopupMenu(this);
39 QAction
*ExitAction
= new QAction("E&xit", CTRL
+Key_X
, this, "exit");
40 connect(ExitAction
, SIGNAL(activated()) , qApp
, SLOT(quit()) );
41 ExitAction
->addTo(file
);
43 QPopupMenu
*pacman
= new QPopupMenu(this);
45 QAction
*UpdateAction
= new QAction("&Update syncdb", CTRL
+Key_Y
, this, "foo");
46 connect(UpdateAction
, SIGNAL(activated()) , this, SLOT(updateSyncdb()) );
47 UpdateAction
->addTo(pacman
);
48 QAction
*UpgradeAction
= new QAction("&Upgrade packages", CTRL
+Key_U
, this, "foo");
49 connect(UpgradeAction
, SIGNAL(activated()) , this, SLOT(upgradePackages()) );
50 UpgradeAction
->addTo(pacman
);
52 QPopupMenu
*help
= new QPopupMenu(this);
55 QAction
*AboutAction
= new QAction("&About", NULL
, this, "about");
56 connect(AboutAction
, SIGNAL(activated()), this, SLOT(about()) );
57 QAction
*AboutQtAction
= new QAction("About &Qt", NULL
, this, "aboutQt");
58 connect(AboutQtAction
, SIGNAL(activated()), this, SLOT(aboutQt()) );
59 AboutAction
->addTo(help
);
60 AboutQtAction
->addTo(help
);
62 QMenuBar
*menubar
= new QMenuBar(this);
64 menubar
->insertItem( "&File", file
);
65 menubar
->insertItem( "&Pacman", pacman
);
66 menubar
->insertItem( "&Help", help
);
68 topLayout
->setMenuBar(menubar
);
71 GroupsView
= new QListView(this);
72 Q_CHECK_PTR(GroupsView
);
73 GroupsView
->addColumn("Groups");
75 GroupsView
->setSelectionMode( QListView::Single
);
77 connect( GroupsView
, SIGNAL( clicked( QListViewItem
* ) ), this, SLOT(groupItemSelected(QListViewItem
*)) );
80 PackagesView
= new QListView(this);
81 Q_CHECK_PTR(PackagesView
);
82 PackagesView
->addColumn("Name");
83 PackagesView
->addColumn("Status");
84 PackagesView
->addColumn("Version");
86 PackagesView
->setSelectionMode( QListView::Single
);
88 connect( PackagesView
, SIGNAL( clicked( QListViewItem
* ) ), this, SLOT(packageItemSelected(QListViewItem
*)) );
91 InfoView
= new QListView(this);
92 Q_CHECK_PTR(InfoView
);
93 InfoView
->header()->hide();
95 InfoView->setSorting(-1);*/
96 InfoView
->setSelectionMode(QListView::NoSelection
);
97 InfoView
->addColumn("Directive");
98 InfoView
->addColumn("Value");
101 QTabWidget
*pkgdetails
= new QTabWidget(this);
102 Q_CHECK_PTR(pkgdetails
);
103 pkgdetails
->addTab(InfoView
, "Info");
106 QHBoxLayout
*leftgrouplist
= new QHBoxLayout(topLayout
);
107 Q_CHECK_PTR(leftgrouplist
);
108 leftgrouplist
->addWidget(GroupsView
);
110 QVBoxLayout
*details
= new QVBoxLayout(leftgrouplist
);
111 Q_CHECK_PTR(details
);
112 details
->addWidget(PackagesView
);
113 details
->addWidget(pkgdetails
);
116 StatusBar
= new QStatusBar(this);
117 Q_CHECK_PTR(StatusBar
);
119 topLayout
->addWidget(StatusBar
);
122 MainWidget::~MainWidget()
127 void MainWidget::about() {
128 QMessageBox::about(this, "Kfpm for Frugalware",
129 "Kfpm is a graphical fronted for libpacman.\n\n"
130 "(c) 2007 Vöröskõi András");
133 void MainWidget::aboutQt() {
134 QMessageBox::aboutQt(this, "About Qt");
137 void MainWidget::updateGroupList() {
138 QStrList groupnames
= FPMClass
->sync_group(FPMClass
->getSync());
139 for (QStrList::Iterator it
= groupnames
.begin(); it
!= groupnames
.end(); it
++) {
140 (void) new QListViewItem(GroupsView
, *it
);
142 setStatusBarMessage("Grouplist loaded.");
145 void MainWidget::updateGroupPackageList(const char *groupname
) {
148 QStrList
*foo
= new QStrList();
149 foo
->append(groupname
);
150 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
151 QStrList pkgnames
= FPMClass
->sync_group(dbs
, foo
);
152 for (QStrList::Iterator it
= pkgnames
.begin(); it
!= pkgnames
.end(); it
++) {
153 /* FIXME it should check all sync db, not just the first one */
154 PM_PKG
*pkg
= pacman_db_readpkg(dbs
.first(), *it
);
155 PM_PKG
*localpkg
= pacman_db_readpkg(FPMClass
->LocalDB
, *it
);
157 QString version
= (char *)pacman_pkg_getinfo(pkg
, PM_PKG_VERSION
);
159 QString date
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
);
163 QString localversion
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_VERSION
);
164 if (localversion
!= version
)
168 QCheckListItem
*clitem
= new QCheckListItem(PackagesView
, *it
, QCheckListItem::CheckBox
);
169 clitem
->setPixmap(1, pm
);
170 clitem
->setText(2, version
);
174 void MainWidget::slot_initialize() {
175 FPMClass
= new FPM();
176 setStatusBarMessage("Initializing...");
177 qApp
->processEvents();
181 void MainWidget::setStatusBarMessage(QString message
) {
182 StatusBar
->message(message
);
185 void MainWidget::groupItemSelected( QListViewItem
*item
)
191 PackagesView
->clear();
192 updateGroupPackageList(item
->text(0));
196 void MainWidget::packageItemSelected(QListViewItem
*item
)
201 updateFullInfo(item
->text(0));
204 void MainWidget::updateFullInfo(const char *pkgname
)
210 char buffer
[50]; //for converting sizes
212 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
214 /* FIXME it should check all sync db, not just the first one */
215 PM_PKG
*pkg
= pacman_db_readpkg(dbs
.first(), (char *)pkgname
);
216 PM_PKG
*localpkg
= pacman_db_readpkg(FPMClass
->LocalDB
, (char *)pkgname
);
218 (void) new QListViewItem(InfoView
, "Name", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_NAME
));
220 (void) new QListViewItem(InfoView
, "Version", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_VERSION
));
222 long int size
= (long int)pacman_pkg_getinfo(pkg
, PM_PKG_SIZE
);
223 sprintf(buffer
, "%ld", size
);
224 (void) new QListViewItem(InfoView
, "Size (compressed)", buffer
);
226 size
= (long int)pacman_pkg_getinfo(localpkg
, PM_PKG_SIZE
);
227 sprintf(buffer
, "%ld", size
);
228 (void) new QListViewItem(InfoView
, "Size (uncompressed)", buffer
);
230 (void) new QListViewItem(InfoView
, "Description", (char *)pacman_pkg_getinfo(pkg
, PM_PKG_DESC
));
232 QString date
= (char *)pacman_pkg_getinfo(localpkg
, PM_PKG_INSTALLDATE
);
233 switch((long)pacman_pkg_getinfo(localpkg
, PM_PKG_REASON
)) {
234 case PM_PKG_REASON_EXPLICIT
:
236 (void) new QListViewItem(InfoView
, "Reason", "Not installed");
238 (void) new QListViewItem(InfoView
, "Reason", "Explicitly installed");
240 case PM_PKG_REASON_DEPEND
:
241 (void) new QListViewItem(InfoView
, "Reason", "Installed as a dependency for another package");
244 (void) new QListViewItem(InfoView
, "Reason", "Unknown");
248 (void) new QListViewItem(InfoView
, "Install Date", date
);
250 PM_LIST
*depends
= (PM_LIST
*)pacman_pkg_getinfo(pkg
, PM_PKG_DEPENDS
);
251 (void) new QListViewItem(InfoView
, "Depends", FPMClass
->PM_LISTtoQString(depends
));
255 void MainWidget::updateSyncdb() {
256 QValueVector
<PM_DB
*> dbs
= FPMClass
->getSync();
257 // FIXME - catch expections
258 FPMClass
->sync_synctree(0, dbs
);
261 void MainWidget::upgradePackages() {
262 // FIXME -- exceptions
263 FPMClass
->sync_upgrade();
266 // vim: sw=4 ts=4 noet