~jibel/synaptic/bugs.290524.502582

« back to all changes in this revision

Viewing changes to gtk/rgpackagestatus.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-08-22 12:40:10 UTC
  • Revision ID: james.westby@ubuntu.com-20080822124010-5z3kuzjp2jozl13a
Tags: 0.62.1ubuntu8
* common/rpackageview.cc:
  - add new "Missing Recommends" default filter
* common/rpackage.cc:
  - fix code to get candidate origin
  - support getting the candidate release file name
* common/rpackagestatus.cc:
  - support maintenanceEndTime() (if the distro supports that)
* 10_ubuntu_maintenance_gui.dpatch:
  - add support for displaying when the maintaince ends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rgpackagestatus.cc  - package status UI stuff
 
2
 * 
 
3
 * Copyright (c) 2003 Michael Vogt
 
4
 * 
 
5
 * Author: Michael Vogt <mvo@debian.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or 
 
8
 * modify it under the terms of the GNU General Public License as 
 
9
 * published by the Free Software Foundation; either version 2 of the
 
10
 * License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
20
 * USA
 
21
 */
 
22
 
 
23
#include <gtk/gtk.h>
 
24
#include <gdk/gdkx.h>
 
25
#include <string>
 
26
#include <stdio.h>
 
27
#include <cstdlib>
 
28
#include <cstring>
 
29
 
 
30
#include "rgutils.h"
 
31
#include "rgpackagestatus.h"
 
32
 
 
33
// helper
 
34
static GdkPixbuf *
 
35
get_gdk_pixbuf(const gchar *name, int size=16)
 
36
{
 
37
   GtkIconTheme *theme;
 
38
   GdkPixbuf *pixbuf;
 
39
   GError *error = NULL;
 
40
 
 
41
   theme = gtk_icon_theme_get_default();
 
42
   pixbuf = gtk_icon_theme_load_icon(theme, name, size, 
 
43
                                     (GtkIconLookupFlags)0, &error);
 
44
   if (pixbuf == NULL) 
 
45
      std::cerr << "Warning, failed to load: " << name 
 
46
                << error->message << std::endl;
 
47
 
 
48
   return pixbuf;
 
49
}
 
50
 
 
51
GtkWidget *get_gtk_image(const gchar *name, int size)
 
52
{
 
53
   GdkPixbuf *buf;
 
54
   buf = get_gdk_pixbuf(name, size);
 
55
   if(!buf)
 
56
      return NULL;
 
57
   return gtk_image_new_from_pixbuf(buf);
 
58
}
 
59
 
 
60
// RPackageStatus stuff
 
61
RGPackageStatus RGPackageStatus::pkgStatus;
 
62
 
 
63
void RGPackageStatus::initColors()
 
64
{
 
65
   char *default_status_colors[N_STATUS_COUNT] = {
 
66
      "#8ae234",  // install
 
67
      "#4e9a06",  // re-install
 
68
      "#fce94f",  // upgrade
 
69
      "#ad7fa8",  // downgrade
 
70
      "#ef2929",  // remove
 
71
      "#a40000",  // purge
 
72
      NULL,       // available
 
73
      "#a40000",  // available-locked
 
74
      NULL,       // installed-updated
 
75
      NULL,       // installed-outdated
 
76
      "#a40000",  // installed-locked 
 
77
      NULL,       // broken
 
78
      NULL        // new
 
79
   };
 
80
 
 
81
   gchar *config_string;
 
82
   for (int i = 0; i < N_STATUS_COUNT; i++) {
 
83
      config_string = g_strdup_printf("Synaptic::color-%s",
 
84
                                      PackageStatusShortString[i]);
 
85
      gtk_get_color_from_string(_config->
 
86
                                Find(config_string,
 
87
                                     default_status_colors[i]).c_str(),
 
88
                                &StatusColors[i]);
 
89
      g_free(config_string);
 
90
   }
 
91
}
 
92
 
 
93
void RGPackageStatus::initPixbufs()
 
94
{
 
95
   gchar *s;
 
96
   for (int i = 0; i < N_STATUS_COUNT; i++) {
 
97
      s = g_strdup_printf("package-%s", PackageStatusShortString[i]);
 
98
      StatusPixbuf[i] = get_gdk_pixbuf(s);
 
99
   }
 
100
   supportedPix = get_gdk_pixbuf("package-supported");
 
101
}
 
102
 
 
103
// class that finds out what do display to get user
 
104
void RGPackageStatus::init()
 
105
{
 
106
   RPackageStatus::init();
 
107
 
 
108
   initColors();
 
109
   initPixbufs();
 
110
}
 
111
 
 
112
 
 
113
GdkColor *RGPackageStatus::getBgColor(RPackage *pkg)
 
114
{
 
115
   return StatusColors[getStatus(pkg)];
 
116
}
 
117
 
 
118
GdkPixbuf *RGPackageStatus::getSupportedPix(RPackage *pkg)
 
119
{
 
120
   if(isSupported(pkg))
 
121
      return supportedPix;
 
122
   else
 
123
      return NULL;
 
124
}
 
125
 
 
126
GdkPixbuf *RGPackageStatus::getPixbuf(RPackage *pkg)
 
127
{
 
128
   return StatusPixbuf[getStatus(pkg)];
 
129
}
 
130
 
 
131
void RGPackageStatus::setColor(int i, GdkColor * new_color)
 
132
{
 
133
   StatusColors[i] = new_color;
 
134
}
 
135
 
 
136
void RGPackageStatus::saveColors()
 
137
{
 
138
   gchar *color_string, *config_string;
 
139
   for (int i = 0; i < N_STATUS_COUNT; i++) {
 
140
      color_string = gtk_get_string_from_color(StatusColors[i]);
 
141
      config_string = g_strdup_printf("Synaptic::color-%s",
 
142
                                      PackageStatusShortString[i]);
 
143
 
 
144
      _config->Set(config_string, color_string);
 
145
      g_free(config_string);
 
146
   }
 
147
}