summaryrefslogtreecommitdiffstats
path: root/kpackage/fbsdInterface.h
blob: 270b0c9c17b5164716b0e56c033d2b310f915ffb (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
/*
** Copyright (C) 2000 by Alex Hayward
**
*/


/*
** 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
*/

#ifndef FBSD_IFACE_H
#define FBSD_IFACE_H

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

//#ifdef HAVE_FBSD_PKGTOOLS

#include <qptrlist.h>
#include <qmap.h>

#include "packageInfo.h"
#include "pkgInterface.h"

class KDir;
class cacheObj;
class bsdPortsIndexItem;

class fbsdInterface : public pkgInterface
{
 Q_OBJECT

public:
  fbsdInterface();
  ~fbsdInterface();

  void init();

  bool isType(char *buf, const QString &fname);

  packageInfo *getPackageInfo(char mode, const QString &name, const QString &version);
  QStringList getFileList(packageInfo *p);
  QStringList getChangeLog(packageInfo *p);

  bool filesTab(packageInfo *p);
  // If files tab is to be enabled

  bool changeTab(packageInfo *p);
  // If change log tab is to be enabled

  QString uninstall(int uninstallFlags, QPtrList<packageInfo> *p, bool &test);
  QString uninstall(int uninstallFlags, packageInfo *p, bool &test);
  QString doUninstall(int uninstallFlags, const QString &packs, bool &test);
  QString doInstall(int installFlags, const QString &packs, bool &test);

  QStringList FindFile(const QString &name, bool seachAll=false);
  void collectDepends(packageInfo *p, const QString &name, int src);
  bool parseName(const QString& name, QString *n, QString *v);

  void listInstalledPackages(QPtrList<packageInfo> *pki);
  void listPackages(QPtrList<packageInfo> *pki);

  QDict <bsdPortsIndexItem> ports;
public slots:
  void setLocation();
  void setAvail(LcacheObj *);

private:
  /**
   * @short Add the name and version identifiers to a QMap<QString, QString>.
   *
   * name is parsed in to name and version and these are added to
   * d. Errors are handled.
   */
  void addNV(QMap<QString, QString> &d, const QString &name);
  int parseItem(QStringList::Iterator &it, QString &name, QString &value, QString separator, QStringList list );
  int pathInfo(QMap<QString, QString> &a);

};

/**
 * @short Ports description linked list item
 *
 * Each item in the list describes one port from the ports collection.
 */
class bsdPortsIndexItem {
public:
  /**
   * desc is a line from the INDEX file (/usr/ports/INDEX under FreeBSD)
   * which has a particular format:
   *
   * name|port path|inst prefix|1 line commect|DESCR file|maintainer|categories|build-deps|run-deps
   *
   * Multiple space separated categories may be specified.
   *
   * desc must remain allocated (ie, its not copied) will be modified.
   *
   * binaries should be true if this is a binary package.
   *
   * dname is the name of the base directory of this ports/packages tree.
   */
  bsdPortsIndexItem(fbsdInterface *parent, char *desc, bool binaries, const QString &dname);

  /** @short true if this has a binary packages. */
  bool bin;

  /** @short true if this has a source port available. */
  bool port;

  /** @short true if this package is installed (set in listInstalledPackages) */
  bool installed;

  /** @short The next item in this linked list */
  bsdPortsIndexItem *next;

  QStringList fields;

  enum {NAME=0, PATH, PREFIX, COMMENT, DESC_PATH, MAINT, CATS, BDEPS, RDEPS};

  QString bin_filename;
  QString bin_filename_base;
  QString port_dirname;

   /**
   * @short Given the path to an INDEX file process each port in it.
   *
   * binaries should be true if the file is an index for packages, false for ports.
   * dname is the base directory.
   */
  static void processFile(fbsdInterface *parent, const QString &fname, bool binaries, const QString &dname);

private:
  unsigned int name_hash;
  static unsigned char calc_hash1(const char *name);
  static unsigned int calc_hash4(const char *name);
  static unsigned char hash1(unsigned int hash4);
};

#endif