/
rgpkgdetails.cc
416 lines (365 loc) · 14.4 KB
/
rgpkgdetails.cc
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* rgpkgdetails.cc - show details of a pkg
*
* Copyright (c) 2004 Michael Vogt
*
* Author: Michael Vogt <mvo@debian.org>
* Gustavo Niemeyer <niemeyer@conectiva.com>
*
* 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "config.h"
#include <cassert>
#include "rgwindow.h"
#include "rgmainwindow.h"
#include "rgpkgdetails.h"
#include "rggtkbuilderwindow.h"
#include "rpackage.h"
#include "rgpackagestatus.h"
#include "rgchangelogdialog.h"
#include "sections_trans.h"
RGPkgDetailsWindow::RGPkgDetailsWindow(RGWindow *parent)
: RGGtkBuilderWindow(parent, "details")
{
g_signal_connect(gtk_builder_get_object(_builder, "button_close"),
"clicked",
G_CALLBACK(cbCloseClicked), this);
GtkWidget *comboDepends = GTK_WIDGET(gtk_builder_get_object
(_builder, "combobox_depends"));
g_signal_connect(G_OBJECT(comboDepends),
"changed",
G_CALLBACK(cbDependsMenuChanged), this);
GtkListStore *relTypes = gtk_list_store_new(1, G_TYPE_STRING);
GtkTreeIter relIter;
// HACK: the labels for the combo box items are defined as
// the relOptions array in gtk/rgmainwindow.h.
// We already include it, so we get those for free.
for (int i = 0; relOptions[i] != NULL; i++) {
gtk_list_store_append(relTypes, &relIter);
gtk_list_store_set(relTypes, &relIter, 0, _(relOptions[i]), -1);
}
gtk_combo_box_set_model(GTK_COMBO_BOX(comboDepends),
GTK_TREE_MODEL(relTypes));
GtkCellRenderer *relRenderText = gtk_cell_renderer_text_new();
gtk_cell_layout_clear(GTK_CELL_LAYOUT(comboDepends));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(comboDepends),
relRenderText, FALSE);
gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(comboDepends),
relRenderText, "text", 0);
gtk_combo_box_set_active(GTK_COMBO_BOX(comboDepends), 0);
GtkWidget *label;
label = GTK_WIDGET(gtk_builder_get_object(_builder, "label_maintainer"));
g_signal_connect(G_OBJECT(label), "activate-link",
G_CALLBACK(cbOpenLink), NULL);
}
void RGPkgDetailsWindow::cbCloseClicked(GtkWidget *self, void *data)
{
RGPkgDetailsWindow *me = static_cast<RGPkgDetailsWindow*>(data);
me->hide();
}
vector<string>
RGPkgDetailsWindow::formatDepInformation(vector<DepInformation> deps)
{
vector<string> depStrings;
string depStr;
for(unsigned int i=0;i<deps.size();i++) {
depStr="";
// type in bold (Depends, PreDepends)
depStr += string("<b>") + _(DepTypeStr[deps[i].type]) + string(":</b> ");
// virutal is italic
if(deps[i].isVirtual) {
depStr += string("<i>") + deps[i].name + string("</i>");
} else {
// is real pkg
depStr += deps[i].name;
// additional version information
if(deps[i].version != NULL) {
gchar *s = g_markup_escape_text(deps[i].versionComp,-1);
depStr += string(" (") + s + deps[i].version + string(")");
g_free(s);
}
}
// this is for or-ed dependencies (make them one-line)
while(deps[i].isOr) {
depStr += " | ";
// next dep
i++;
depStr += deps[i].name;
// additional version information
if(deps[i].version != NULL) {
gchar *s = g_markup_escape_text(deps[i].versionComp,-1);
depStr += string(" (") + s + deps[i].version + string(")");
g_free(s);
}
}
depStrings.push_back(depStr);
}
return depStrings;
}
void RGPkgDetailsWindow::cbShowBigScreenshot(GtkWidget *box,
GdkEventButton *event,
void *data)
{
//cerr << "cbShowBigScreenshot" << endl;
RPackage *pkg = (RPackage *)data;
doShowBigScreenshot(pkg);
}
void RGPkgDetailsWindow::doShowBigScreenshot(RPackage *pkg)
{
RGFetchProgress *status = new RGFetchProgress(NULL);;
pkgAcquire fetcher(status);
string filename = pkg->getScreenshotFile(&fetcher, false);
GtkWidget *img = gtk_image_new_from_file(filename.c_str());
GtkWidget *win = gtk_dialog_new();
gtk_window_set_default_size(GTK_WINDOW(win), 500, 400);
gtk_dialog_add_button(GTK_DIALOG(win), _("_Close"), GTK_RESPONSE_CLOSE);
gtk_widget_show(img);
GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (win));
gtk_container_add(GTK_CONTAINER(content_area), img);
gtk_dialog_run(GTK_DIALOG(win));
gtk_widget_destroy(win);
}
void RGPkgDetailsWindow::cbShowScreenshot(GtkWidget *button, void *data)
{
struct screenshot_info *si = (struct screenshot_info*)data;
if(_config->FindB("Synaptic::InlineScreenshots") == false)
{
doShowBigScreenshot(si->pkg);
return;
} else {
// hide button
gtk_widget_hide(button);
// get screenshot
RGFetchProgress *status = new RGFetchProgress(NULL);;
pkgAcquire fetcher(status);
string filename = si->pkg->getScreenshotFile(&fetcher);
GtkWidget *event = gtk_event_box_new();
GtkWidget *img = gtk_image_new_from_file(filename.c_str());
gtk_container_add(GTK_CONTAINER(event), img);
g_signal_connect(G_OBJECT(event), "button_press_event",
G_CALLBACK(cbShowBigScreenshot),
(void*)si->pkg);
gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(si->textview),
GTK_WIDGET(event), si->anchor);
gtk_widget_show_all(event);
}
}
void RGPkgDetailsWindow::cbShowChangelog(GtkWidget *button, void *data)
{
RPackage *pkg = (RPackage*)data;
RGWindow *parent = (RGWindow*)g_object_get_data(G_OBJECT(button), "me");
ShowChangelogDialog(parent, pkg);
}
gboolean RGPkgDetailsWindow::cbOpenLink(GtkWidget *label,
gchar *uri,
void *data)
{
//std::cerr << "cbOpenLink: " << uri << std::endl;
std::vector<const gchar *> cmd;
cmd.push_back("xdg-open");
cmd.push_back(uri);
RunAsSudoUserCommand(cmd);
return TRUE;
}
gboolean RGPkgDetailsWindow::cbOpenHomepage(GtkWidget *button, void* data)
{
RPackage *pkg = (RPackage*)data;
std::vector<const gchar*> cmd = GetBrowserCommand(pkg->homepage());
//std::cerr << "cbOpenHomepage: " << cmd[0] << std::endl;
RunAsSudoUserCommand(cmd);
return TRUE;
}
void RGPkgDetailsWindow::fillInValues(RGGtkBuilderWindow *me,
RPackage *pkg,
bool setTitle)
{
assert(me!=NULL);
// TRANSLATORS: Title of the package properties dialog
// %s is the name of the package
if(setTitle) {
gchar *str = g_strdup_printf(_("%s Properties"),pkg->name());
me->setTitle(str);
g_free(str);
}
char *pkg_summary = g_strdup_printf("%s\n%s",
pkg->name(), pkg->summary());
me->setTextView("textview_pkgcommon", pkg_summary, true);
g_free(pkg_summary);
string maintainer = pkg->maintainer();
int start_index = maintainer.find("<");
int end_index = maintainer.rfind(">");
if (start_index != -1 && end_index != -1) {
gchar* maintainer_label = g_markup_printf_escaped(
"<a href=\"mailto:%s\">%s</a>",
maintainer.substr(start_index+1, end_index - start_index - 1).c_str(),
maintainer.c_str()
);
me->setMarkup("label_maintainer", maintainer_label);
g_free(maintainer_label);
} else {
me->setLabel("label_maintainer", pkg->maintainer());
}
me->setPixmap("image_state", RGPackageStatus::pkgStatus.getPixbuf(pkg));
me->setLabel("label_state", RGPackageStatus::pkgStatus.getLongStatusString(pkg));
me->setLabel("label_priority", pkg->priority());
me->setLabel("label_section", trans_section(pkg->section()).c_str());
me->setLabel("label_installed_version", pkg->installedVersion());
me->setLabel("label_installed_size", pkg->installedSize());
me->setLabel("label_latest_version", pkg->availableVersion());
me->setLabel("label_latest_size", pkg->availableInstalledSize());
me->setLabel("label_latest_download_size", pkg->availablePackageSize());
me->setLabel("label_source", pkg->srcPackage());
// format description nicely and use emblems
GtkWidget *textview;
GtkTextBuffer *buf;
GtkTextIter it, start, end;
GtkWidget *emblem;
const gchar *s;
textview = GTK_WIDGET(gtk_builder_get_object
(me->getGtkBuilder(), "text_descr"));
assert(textview);
buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
// clear old buffer
gtk_text_buffer_get_start_iter(buf, &start);
gtk_text_buffer_get_end_iter(buf, &end);
gtk_text_buffer_delete(buf, &start, &end);
// create bold tag
GtkTextTagTable *tag_table = gtk_text_buffer_get_tag_table(buf);
if(gtk_text_tag_table_lookup(tag_table, "bold") == NULL) {
gtk_text_buffer_create_tag(buf, "bold",
"weight", PANGO_WEIGHT_BOLD,
"scale", 1.1,
NULL);
}
// set summary
s = utf8(pkg->summary());
gtk_text_buffer_get_start_iter(buf, &it);
gtk_text_buffer_insert(buf, &it, s, -1);
gtk_text_buffer_get_start_iter(buf, &start);
gtk_text_buffer_apply_tag_by_name(buf, "bold", &start, &it);
// set emblems
GdkPixbuf *pixbuf = RGPackageStatus::pkgStatus.getSupportedPix(pkg);
if(pixbuf != NULL) {
// insert space
gtk_text_buffer_insert(buf, &it, " ", 1);
// make image
emblem = gtk_image_new_from_pixbuf(pixbuf);
gtk_image_set_pixel_size(GTK_IMAGE(emblem), 16);
// set eventbox and tooltip
GtkWidget *event = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(event), emblem);
gtk_widget_set_tooltip_text(event, _("This application is supported by the distribution"));
// create anchor
GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(buf, &it);
gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), event, anchor);
gtk_widget_show_all(event);
}
// add button to get screenshot
gtk_text_buffer_insert(buf, &it, "\n", 1);
GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(buf, &it);
GtkWidget *button = gtk_button_new_with_label(_("Get Screenshot"));
static struct screenshot_info si;
si.anchor = anchor;
si.textview = textview;
si.pkg = pkg;
g_signal_connect(G_OBJECT(button),"clicked",
G_CALLBACK(cbShowScreenshot),
&si);
gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), button, anchor);
gtk_widget_show(button);
// add button to get changelog
gtk_text_buffer_insert(buf, &it, " ", 1);
anchor = gtk_text_buffer_create_child_anchor(buf, &it);
button = gtk_button_new_with_label(_("Get Changelog"));
g_object_set_data(G_OBJECT(button), "me", me);
g_signal_connect(G_OBJECT(button),"clicked",
G_CALLBACK(cbShowChangelog),
pkg);
gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), button, anchor);
gtk_widget_show(button);
// add button to open the homepage
if (strlen(pkg->homepage())) {
gtk_text_buffer_insert(buf, &it, " ", 1);
anchor = gtk_text_buffer_create_child_anchor(buf, &it);
button = gtk_link_button_new_with_label(pkg->homepage(), _("Visit Homepage"));
char *homepage_tooltip = g_strdup_printf(_("Visit %s"),
pkg->homepage());
g_signal_connect(G_OBJECT(button),"activate-link",
G_CALLBACK(cbOpenHomepage),
pkg);
gtk_widget_set_tooltip_text(button, homepage_tooltip);
g_free(homepage_tooltip);
g_object_set_data(G_OBJECT(button), "me", me);
gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), button, anchor);
gtk_widget_show(button);
}
// show the rest of the description
gtk_text_buffer_insert(buf, &it, "\n", 1);
s = utf8(pkg->description());
gtk_text_buffer_insert(buf, &it, s, -1);
// build dependency lists
vector<DepInformation> deps;
deps = pkg->enumDeps();
me->setTreeList("treeview_deplist", formatDepInformation(deps), true);
// canidateVersion
deps = pkg->enumDeps(true);
me->setTreeList("treeview_availdep_list", formatDepInformation(deps), true);
// rdepends Version
deps = pkg->enumRDeps();
me->setTreeList("treeview_rdeps", formatDepInformation(deps), true);
// provides
me->setTreeList("treeview_provides", pkg->provides());
// file list
#ifndef HAVE_RPM
gtk_widget_show(GTK_WIDGET(gtk_builder_get_object
(me->getGtkBuilder(),
"scrolledwindow_filelist")));
me->setTextView("textview_files", pkg->installedFiles());
#endif
// versions
gchar *str;
vector<string> list;
vector<pair<string,string> > versions = pkg->getAvailableVersions();
for(int i=0;i<versions.size();i++) {
// TRANSLATORS: this the format of the available versions in
// the "Properties/Available versions" window
// e.g. "0.56 (unstable)"
// "0.53.4 (testing)"
str = g_strdup_printf(_("%s (%s)"),
versions[i].first.c_str(),
versions[i].second.c_str());
list.push_back(str);
g_free(str);
}
me->setTreeList("treeview_versions", list);
/*
g_signal_connect(gtk_builder_get_object
(me->getGtkBuilder(), "combobox_depends"),
"changed",
G_CALLBACK(cbDependsMenuChanged), me);
*/
}
void RGPkgDetailsWindow::cbDependsMenuChanged(GtkWidget *self, void *data)
{
RGPkgDetailsWindow *me = (RGPkgDetailsWindow*)data;
int nr = gtk_combo_box_get_active(GTK_COMBO_BOX(self));
GtkWidget *notebook = GTK_WIDGET(gtk_builder_get_object
(me->_builder, "notebook_dep_tab"));
assert(notebook);
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), nr);
}
RGPkgDetailsWindow::~RGPkgDetailsWindow()
{
}