summaryrefslogtreecommitdiffstats
path: root/kpackage/debDpkgInterface.cpp
blob: a1c4504d0345a1613e6c7d54e0e917531590468e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
**
*/

/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-devel@kde.org
*/

#include "../config.h"

#include <unistd.h>
#include <stdlib.h>		// for getenv
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>		// for O_RDONLY
#include <setjmp.h>
#include <iostream>

#include <kurl.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kdebug.h>

#include "packageInfo.h"
#include "debDpkgInterface.h"
#include "updateLoc.h"
#include "kpackage.h"
#include "managementWidget.h"
#include "utils.h"
#include "options.h"
#include "cache.h"
#include <klocale.h>


extern KApplication *app;
extern Opts *params;

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
DEBDPKG::DEBDPKG():DEB()
{
  head = "DEBDPKG";
  name = i18n("DPKG: Debian");
  defaultHandle = 0;

  queryMsg = i18n("Querying DEB package list: ");
  procMsg = i18n("Kpackage: Waiting on DPKG");

  locatedialog = new Locations(i18n("Location of Debian Package Archives"));
  locatedialog->cLocations(3, 2,  this, i18n("Location", "L"),
			   "Deb",
			   i18n("Version\nArchitecture"),
			   i18n("Location of Base Folder of Debian Distribution"),
			   "stable frozen unstable\ni386 alpha sparc powerpc arm m68k");
  locatedialog->pLocations(3, 6, this, i18n("Packages", "P"),
			   "Deb", "*.deb Packages Packages.gz status available",
			   i18n("Location of 'Packages' Files for Sections of Debian Distributions"),
			   i18n("Location of Base Folder of Debian Distribution"));
  locatedialog->dLocations(2, 6, this, i18n("Folders", "F"),
			   "Deb", "*.deb",
			   i18n("Location of Folders Containing Debian Packages"));
  connect(locatedialog,TQT_SIGNAL(returnVal(LcacheObj *)),
	  this,TQT_SLOT(setAvail(LcacheObj *)));
  locatedialog->apply_slot();

  paramsInst.append(new param(i18n("Allow Downgrade"),TRUE,TRUE,"--refuse-downgrade"));
  paramsInst.append(new param(i18n("Check Conflicts"),TRUE,TRUE,"--force-conflicts"));
  paramsInst.append(new param(i18n("Check Dependencies"),TRUE,TRUE,"--force-depends"));
  paramsInst.append(new  param(i18n("Test (do not install)"),FALSE,FALSE,"--no-act"));

  paramsUninst.append(new param(i18n("Purge Config Files"),TRUE,FALSE,
			    "--purge","--remove"));
  paramsUninst.append(new param(i18n("Check Dependencies"),TRUE,TRUE,"--force-depends"));
  paramsUninst.append(new param(i18n("Test (do not uninstall)"),FALSE,FALSE,"--no-act"));

  hasProgram = ifExe("dpkg");
  
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
DEBDPKG::~DEBDPKG()
{
}

//////////////////////////////////////////////////////////////////////////////
void DEBDPKG::distPackages(TQPtrList<packageInfo> *pki, cacheObj *cp)
{
  LcacheObj *cList = new LcacheObj();
  TQString loc = cp->base;

  TQStringList opt = TQStringList::split('\n',cp->option);
  TQStringList::Iterator ocIt = opt.begin();
  TQString rel = *ocIt;
  TQString arch = *(++ocIt);

  TQString parts[3] = {"main", "contrib", "non-free"};
  for (int i = 0; i < 3; i++) {
    TQString file = loc + "/dists/";
    file += rel;
    file += "/";
    file += parts[i];
    file += "/binary-";
    file += arch;
    file += "/Packages";
    TQString s;
    TQString tmp = cp->cacheFile;
    tmp += s.setNum(i);
    cacheObj *cp = new cacheObj(loc,file,tmp);
    cList->append(cp);
  }

  listUnIPackages(pki, cList);
}

void DEBDPKG::listPackages(TQPtrList<packageInfo> *pki)
{
  listInstalledPackages(pki);
  if (packageLoc) {
    listUnIPackages(pki, packageLoc);
  }
}




//////////////////////////////////////////////////////////////////////////////
// Call the script to uninstall packages setting parameters
// to dpkg dependent on flags, returning whether everyting worked
//////////////////////////////////////////////////////////////////////////////
TQString DEBDPKG::doUninstall(int uninstallFlags, const TQString &packs, bool &test)
{
  TQString s = "dpkg ";
  // The -r or -p flag is set by setOptions
  s += setOptions(uninstallFlags, paramsUninst);
  s +=  packs;

  if (uninstallFlags>>3 & 1)
    test = 1;

  kdDebug() << "uCMD=" << s << "\n";

  return s;
}

#include "debDpkgInterface.moc"