source: projects/synaptic/trunk/gtk/rgpkgdetails.cc @ 280

Revision 280, 5.8 KB checked in by yasumichi, 15 years ago (diff)

first import

Line 
1/* rgpkgdetails.cc - show details of a pkg
2 *
3 * Copyright (c) 2004 Michael Vogt
4 *
5 * Author: Michael Vogt <mvo@debian.org>
6 *         Gustavo Niemeyer <niemeyer@conectiva.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
22 */
23
24#include "config.h"
25
26#include <cassert>
27#include "rgwindow.h"
28#include "rgmainwindow.h"
29#include "rgpkgdetails.h"
30#include "rggladewindow.h"
31#include "rpackage.h"
32#include "sections_trans.h"
33
34
35
36RGPkgDetailsWindow::RGPkgDetailsWindow(RGWindow *parent)
37   : RGGladeWindow(parent, "details")
38{
39   glade_xml_signal_connect_data(_gladeXML,
40                                 "on_button_close_clicked",
41                                 G_CALLBACK(cbCloseClicked),
42                                 this); 
43   // fill in all the pkg-values
44   skipTaskbar(true);
45}
46
47void RGPkgDetailsWindow::cbCloseClicked(GtkWidget *self, void *data)
48{
49   RGPkgDetailsWindow *me = static_cast<RGPkgDetailsWindow*>(data);
50
51   me->hide();
52}
53
54vector<string> 
55RGPkgDetailsWindow::formatDepInformation(vector<DepInformation> deps)
56{
57   vector<string> depStrings;
58   string depStr;
59   
60   for(unsigned int i=0;i<deps.size();i++) {
61      depStr="";
62
63      // type in bold (Depends, PreDepends)
64      depStr += string("<b>") + _(DepTypeStr[deps[i].type]) + string(":</b> ");
65
66      // virutal is italic
67      if(deps[i].isVirtual) {
68         depStr += string("<i>") + deps[i].name + string("</i>");
69      } else {
70         // is real pkg
71         depStr += deps[i].name;
72         // additional version information
73         if(deps[i].version != NULL) {
74            gchar *s = g_markup_escape_text(deps[i].versionComp,-1);
75            depStr += string(" (") + s + deps[i].version + string(")");
76            g_free(s);
77         }
78      }
79
80      // this is for or-ed dependencies (make them one-line)
81      while(deps[i].isOr) {
82         depStr += " | ";
83         // next dep
84         i++;
85         depStr += deps[i].name;
86         // additional version information
87         if(deps[i].version != NULL) {
88            gchar *s = g_markup_escape_text(deps[i].versionComp,-1);
89            depStr += string(" (") + s + deps[i].version + string(")");
90            g_free(s);
91         }
92      }
93     
94      depStrings.push_back(depStr);
95   }
96   return depStrings;
97}
98
99void RGPkgDetailsWindow::fillInValues(RGGladeWindow *me, RPackage *pkg,
100                                      bool setTitle)
101{
102   assert(me!=NULL);
103
104   // TRANSLATORS: Title of the package properties dialog
105   //              %s is the name of the package
106   if(setTitle) {
107      gchar *str = g_strdup_printf(_("%s Properties"),pkg->name());
108      me->setTitle(str);
109      g_free(str);
110   }
111
112   char *pkg_summary = g_strdup_printf("%s\n%s",
113                                             pkg->name(), pkg->summary());
114   me->setTextView("textview_pkgcommon", pkg_summary, true);
115   g_free(pkg_summary);
116
117   me->setLabel("label_maintainer", pkg->maintainer());
118   me->setPixmap("image_state", RGPackageStatus::pkgStatus.getPixbuf(pkg));
119   me->setLabel("label_state", RGPackageStatus::pkgStatus.getLongStatusString(pkg));
120   me->setLabel("label_priority", pkg->priority());
121   me->setLabel("label_section", trans_section(pkg->section()).c_str());
122   me->setLabel("label_installed_version", pkg->installedVersion());
123   me->setLabel("label_installed_size", pkg->installedSize());
124
125   me->setLabel("label_latest_version", pkg->availableVersion());
126   me->setLabel("label_latest_size", pkg->availableInstalledSize());
127   me->setLabel("label_latest_download_size", pkg->availablePackageSize());
128
129   string descr = string(pkg->summary()) + "\n" + string(pkg->description());
130   me->setTextView("text_descr", descr.c_str(), true);
131
132   // build dependency lists
133   vector<DepInformation> deps;
134   deps = pkg->enumDeps();
135   me->setTreeList("treeview_deplist", formatDepInformation(deps), true);
136   
137   // canidateVersion
138   deps = pkg->enumDeps(true);
139   me->setTreeList("treeview_availdep_list", formatDepInformation(deps), true);
140
141   // rdepends Version
142   deps = pkg->enumRDeps();
143   me->setTreeList("treeview_rdeps", formatDepInformation(deps), true);
144   
145   // provides
146   me->setTreeList("treeview_provides", pkg->provides());
147
148
149   // file list
150#ifndef HAVE_RPM
151   gtk_widget_show(glade_xml_get_widget(me->getGladeXML(),
152                                        "scrolledwindow_filelist"));
153   me->setTextView("textview_files", pkg->installedFiles());
154#endif
155
156   // versions
157   gchar *str;
158   vector<string> list;
159   vector<pair<string,string> > versions = pkg->getAvailableVersions();
160   for(int i=0;i<versions.size();i++) {
161      // TRANSLATORS: this the format of the available versions in
162      // the "Properties/Available versions" window
163      // e.g. "0.56 (unstable)"
164      //      "0.53.4 (testing)"
165      str = g_strdup_printf(_("%s (%s)"), 
166                            versions[i].first.c_str(), 
167                            versions[i].second.c_str());
168      list.push_back(str);
169      g_free(str);
170   }
171   me->setTreeList("treeview_versions", list);
172
173   glade_xml_signal_connect_data(me->getGladeXML(), 
174                                 "on_optionmenu_depends_changed",
175                                 G_CALLBACK(cbDependsMenuChanged), me);
176}
177
178void RGPkgDetailsWindow::cbDependsMenuChanged(GtkWidget *self, void *data)
179{
180   RGPkgDetailsWindow *me = (RGPkgDetailsWindow*)data;
181
182   int nr =  gtk_option_menu_get_history(GTK_OPTION_MENU(self));
183   GtkWidget *notebook = glade_xml_get_widget(me->_gladeXML, 
184                                              "notebook_dep_tab");
185   assert(notebook);
186   gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), nr);
187}
188
189RGPkgDetailsWindow::~RGPkgDetailsWindow()
190{
191   
192}
Note: See TracBrowser for help on using the repository browser.