ditz import
[kfpm.git] / kfpm_pacman.cpp
blob7134e0084813ce3129e793bad1d4bd27a1309def
1 /*
2 * kfpm_pacman.cpp
4 * Copyright (c) 2007 VOROSKOI Andras <voroskoi@frugalware.org>
6 * Copyright: See COPYING file that comes with this distribution.
8 */
10 #include <iostream>
12 #include "kfpm_pacman.h"
14 QValueVector<PM_DB*> pm_dblist;
16 FPM::FPM(char *root, char *configfile) {
17 pacman_init(root, configfile);
18 LocalDB = pacman_db_register((char*)"local");
21 FPM::~FPM () {
22 pacman_release();
23 std::cout << "FPM destructor called" << std::endl;
26 void FPM::setSync(QValueVector<PM_DB*> syncs)
28 this->Syncs = syncs;
31 QValueVector<PM_DB*> FPM::getSync(void) {
32 return Syncs;
35 QStrList FPM::sync_group(QValueVector<PM_DB*> syncs)
37 QStrList grpnames;
38 for(QValueVector<PM_DB*>::iterator it = syncs.begin(); it != syncs.end(); ++it) {
39 PM_LIST *lp;
40 for(lp = pacman_db_getgrpcache(*it); lp; lp = pacman_list_next(lp)) {
41 grpnames.append((char*)pacman_list_getdata(lp));
44 return(grpnames);
47 QStrList FPM::sync_group(QValueVector<PM_DB*> syncs, QStrList *targets)
49 QStrList pkgnames;
50 if (targets->isEmpty()) {
51 /* FIXME exception */
52 return NULL;
54 for(char *target = targets->first(); target; target = targets->next()) {
55 for(QValueVector<PM_DB*>::iterator jt = syncs.begin(); jt != syncs.end(); ++jt) {
56 PM_GRP *grp = pacman_db_readgrp(*jt, target);
57 PM_LIST *packages;
58 for(packages = (PM_LIST*)pacman_grp_getinfo(grp, PM_GRP_PKGNAMES); packages; packages = pacman_list_next(packages)) {
59 pkgnames.append((char*)pacman_list_getdata(packages));
63 return(pkgnames);
66 void cb_db_register(char *section, PM_DB *db)
68 pm_dblist.push_back(db);
71 void FPM::pacman_init(char *root, char *configfile)
73 pacman_initialize(root);
74 /* FIXME - exception handling */
75 if(pacman_parse_config(configfile, cb_db_register, "") != 0) {
76 std::cerr << "failed to parse config (" << pacman_strerror(pm_errno) << ")" << std::endl;
78 setSync(pm_dblist);
81 /* FIXME - do i need this at all?
82 QStrList FPM::PM_LISTtoQStringList(PM_LIST* pmlist)
84 QStrList stringlist;
85 for(pmlist = pacman_list_next(pmlist); pmlist; pmlist = pacman_list_next(pmlist)) {
86 stringlist.append((char*)pacman_list_getdata(pmlist));
88 return stringlist;
89 }*/
91 QString FPM::PM_LISTtoQString(PM_LIST* pmlist) {
92 QString string;
93 for (pmlist = pacman_list_first(pmlist); pmlist; pmlist = pacman_list_next(pmlist)) {
94 string += (char*)pacman_list_getdata(pmlist);
95 string += " ";
97 return string;
100 int FPM::sync_synctree(int force, QValueVector<PM_DB*> syncs) {
101 std::cout << "FPM::sync_synctree called\n";
102 int ret = 0;
103 for(QValueVector<PM_DB*>::iterator it = syncs.begin(); it != syncs.end(); ++it) {
104 // FIXME - check return values for all db - exceptions
105 ret = pacman_db_update (force, *it);
107 return ret;
110 int FPM::sync_upgrade() {
111 std::cout << "FPM::sync_upgrade called\n";
112 // FIXME - pff, quite shitty atm
113 if(pacman_trans_init(PM_TRANS_TYPE_SYNC, 0, NULL, NULL, NULL) == -1) {
114 std::cout << "pacman_trans_init failed";
115 return 1;
117 if (pacman_trans_sysupgrade() == -1) {
118 std::cout << "pacman_trans_sysupgrade failed";
119 return 1;
121 if (pacman_trans_release() == -1) {
122 std::cout << "pacman_trans_release failed";
123 return 1;
125 return 0;
128 // vim: sw=4 ts=4 noet