summaryrefslogtreecommitdiffstats
path: root/kpackage/packageProperties.cpp
blob: b05a00ceb5e4f324a303dacad0554aa04394fad3 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
** 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 <stdio.h>
#include <kdebug.h>

#include <kapplication.h> 

#include "kpackage.h"
#include "packageProperties.h"
#include "pkgInterface.h"
#include "managementWidget.h"

packagePropertiesWidget::packagePropertiesWidget
  (QWidget *parent)
  : KTextBrowser(parent)
{
  QDict<QString> trl(53);
  QStringList  pList();
  QStringList  cList();

  //  hide();
  package=NULL;
  QColorGroup cg = colorGroup();
  setBackgroundColor(cg.base());
  initTranslate();
}

packagePropertiesWidget::~packagePropertiesWidget()
{
}

void packagePropertiesWidget::iList(const QString &txt, const QString &itxt)
{
  trl.insert(txt, new QString(itxt));
  pList.append(txt);
}


void packagePropertiesWidget::initTranslate()
{

  iList("name", i18n("name"));
  iList("summary", i18n("summary"));
  iList("version", i18n("version"));
  iList("old-version", i18n("old-version"));
  iList("status", i18n("status"));
  iList("group", i18n("group"));
  iList("size", i18n("size"));
  iList("file-size", i18n("file-size"));
  iList("description", i18n("description"));
  iList("url", i18n("url")); 
  iList("architecture", i18n("architecture"));

  iList("unsatisfied dependencies", i18n("unsatisfied dependencies"));
  iList("pre-depends", i18n("pre-depends"));
  iList("dependencies", i18n("dependencies"));
  iList("depends", i18n("depends"));
  iList("conflicts", i18n("conflicts"));
  iList("provides", i18n("provides"));
  iList("recommends", i18n("recommends"));
  iList("replaces", i18n("replaces"));
  iList("suggests", i18n("suggests"));
  iList("priority", i18n("priority"));

  iList("essential", i18n("essential"));
  iList("install time", i18n("install time"));
  iList("config-version", i18n("config-version"));
  iList("distribution", i18n("distribution"));
  iList("vendor", i18n("vendor"));
  iList("maintainer", i18n("maintainer"));
  iList("packager", i18n("packager"));
  iList("source", i18n("source"));
  iList("build-time", i18n("build-time"));
  iList("build-host", i18n("build-host"));
  iList("base", i18n("base"));
  iList("filename", i18n("filename"));
  iList("serial", i18n("serial"));

  iList("also in", i18n("also in"));
  iList("run depends", i18n("run depends"));
  iList("build depends", i18n("build depends"));
  iList("available as", i18n("available as"));
}

void packagePropertiesWidget::changePackage(packageInfo *p)
{

  package = p;
  cList.clear();
  if (p) {
    // append properties in ordered list to current list
    for ( QStringList::Iterator s = pList.begin();
	  s != pList.end();
	  ++s) {

      if (!p->getProperty(*s).isEmpty()) {
	cList.append(*s);
      }
    }
    // append other properties to end
    QMap<QString, QString>::Iterator it;
    for ( it = p->info.begin(); it != p->info.end(); ++it ) {
      if (!trl.find(it.key())) {
        if (!it.data().isEmpty())
	 cList.append(it.key());
      }
    }

    stmp = "";
    stmp += "<html><head></head><body>";
    stmp += "<h1 style='font-family: serif;'>";
    stmp += p->getProperty("name");
    stmp += "</h1><hr/>";
    stmp += "<table style='width: 100%; border: none; border-spacing: 4px;>";
    for ( QStringList::Iterator s = cList.begin();
	  s != cList.end();
	  ++s) {
      QString *pr = trl[*s];
      QString propName;
      if(pr) {
	propName = *pr;
      } else {
	propName = *s;
      }
      stmp += "<tr>";
      stmp += "<td style='vertical-align: top; font-weight: bold'>";
      stmp += propName;
      stmp += "</td><td>";
      QString f = p->getProperty(*s);
      if (*s == "maintainer" || *s == "packager") {
		f.replace(QRegExp("<"),"&lt;");
		f.replace(QRegExp(">"),"&gt;");
      }
      if (*s == "filename") {
	int p = f.findRev("/");
	if (p >= 0) {
	  f.insert(p+1,"\n");
	};
	stmp += f;
      } else if (*s == "depends" || *s == "conflicts"  ||
		  *s == "replaces" ||
		 *s == "suggests"  || *s == "recommends" ||
		 *s == "pre-depends" || *s == "unsatisfied dependencies") {
	depends(f);
      } else if (*s == "url") {
        if (f.right(1) == " ") f.remove(f.length()-1, 1);
        if  (f.startsWith("http:") || f.startsWith("ftp:"))  /*if (!(f == "(none)")) */
        stmp += "<a href=\"" + f +"\">" + f + "</a>";
        else stmp += i18n("none");
      } else {
	stmp += f;
      }
      stmp += "</td>";
      stmp += "</tr>";
    }
    stmp += "</table>";
    stmp += "</body></html>";
    setText(stmp);
  }
  update();
}

void  packagePropertiesWidget::depends(const QString &f) {
  //  printf("d=%s\n",f.data());

  int i = 0;
  QStringList list = QStringList::split(',',f);
  for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
    if (i++ > 0)
      stmp += ",";
    dor((*it));
  }
}

void  packagePropertiesWidget::dor(const QString &f) {
  //  printf("o=%s\n",f.data());

  int i = 0;
  QStringList list = QStringList::split('|',f);
  for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
    if (i++ > 0)
      stmp += "|";
    delement((*it));
  }
}

void  packagePropertiesWidget::delement(const QString &f) {
  int n = f.find("(");
  if (n < 0) {
    n = f.length();
  }

  QString u = f.left(n);
  QString uf =  package->interface->provMap(u.stripWhiteSpace());

  QString us = uf + package->interface->typeID;

  bool inst = false, uninst = false;
  if (kpackage->management->dirInstPackages->find(us)) {
    inst = true;
  } else if (kpackage->management->dirUninstPackages->find(us)) {
    uninst = true;
  }

  if (uninst)
    stmp += "<i>";
  if (inst||uninst) {
    stmp += "<a href=\"";
    stmp += uf;
    stmp += "\">";
    stmp += u;
    stmp += "</a>";
  } else {
    stmp += u;
  }
  if (uninst)
    stmp += "</i>";
  if (n < (signed)f.length())
    stmp += f.mid(n).replace(QRegExp("<"),"&lt;");
}

void  packagePropertiesWidget::setSource(const QString &name) {
  QString s = name;

  if (s.startsWith("http:") || s.startsWith("ftp:"))
  {
    KApplication::kApplication()->invokeBrowser( s );
    return;
  }
  
  if (s.startsWith("file:")) {
    s = s.mid(5);
  }
  else if (s.at(1) == '/') {
    s = s.mid(1);
  }
  
  QString ind = s + package->interface->typeID;
  packageInfo *p = kpackage->management->dirInstPackages->find(ind);
  if (p) {
     kpackage->management->treeList->changePack(p->getItem(), package->getItem() != 0);
  } else {
    kdDebug() << "nfound=" << ind << endl;
    p = kpackage->management->dirUninstPackages->find(ind);
    if (p) {
       kpackage->management->treeList->changePack(p->getItem(), package->getItem() != 0);
    } else {
      kdDebug() << "Nfound=" << ind << endl;
    }
  }
}
#include "packageProperties.moc"