3
* Copyright (c) 2003 Michael Vogt
5
* Author: Michael Vogt <mvo@debian.org>
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.
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.
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
34
void RGFlushInterface()
36
XSync(gdk_display, False);
38
while (gtk_events_pending()) {
44
* SizeToStr: Converts a size long into a human-readable SI string
45
* ----------------------------------------------------
46
* A maximum of four digits are shown before conversion to the next highest
47
* unit. The maximum length of the string will be five characters unless the
48
* size is more than ten yottabytes.
50
* mvo: we use out own SizeToStr function as the SI spec says we need a
51
* space between the number and the unit (this isn't the case in stock apt
53
string SizeToStr(double Size)
63
/* Bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, exabytes,
64
* zettabytes, yottabytes.
66
char Ext[] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' };
69
if (ASize < 100 && I != 0) {
70
snprintf(S, 300, "%.1f %cB", ASize, Ext[I]);
75
snprintf(S, 300, "%.0f %cB", ASize, Ext[I]);
85
bool is_binary_in_path(const char *program)
87
gchar **path = g_strsplit(getenv("PATH"), ":", 0);
89
for (int i = 0; path[i] != NULL; i++) {
90
char *s = g_strdup_printf("%s/%s", path[i], program);
102
char *gtk_get_string_from_color(GdkColor * colp)
104
static char *_str = NULL;
111
_str = g_strdup_printf("#%4X%4X%4X", colp->red, colp->green, colp->blue);
112
for (char *ptr = _str; *ptr; ptr++)
119
void gtk_get_color_from_string(const char *cpp, GdkColor **colp)
125
if (strlen(cpp) == 0) {
130
GdkColormap *colormap = gdk_colormap_get_system();
132
new_color = g_new(GdkColor, 1);
133
result = gdk_color_parse(cpp, new_color);
134
gdk_colormap_alloc_color(colormap, new_color, FALSE, TRUE);
138
const char *utf8_to_locale(const char *str)
140
static char *_str = NULL;
143
if (g_utf8_validate(str, -1, NULL) == false)
147
_str = g_locale_from_utf8(str, -1, NULL, NULL, NULL);
151
const char *utf8(const char *str)
153
static char *_str = NULL;
156
if (g_utf8_validate(str, -1, NULL) == true)
160
_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL);
165
get_gdk_pixbuf(const gchar *name, int size=16)
169
GError *error = NULL;
171
theme = gtk_icon_theme_get_default();
172
pixbuf = gtk_icon_theme_load_icon(theme, name, size,
173
(GtkIconLookupFlags)0, &error);
175
std::cerr << "Warning, failed to load: " << name
176
<< error->message << std::endl;
181
GtkWidget *get_gtk_image(const gchar *name, int size)
184
buf = get_gdk_pixbuf(name, size);
187
return gtk_image_new_from_pixbuf(buf);
191
// -------------------------------------------------------------------
192
// RPackageStatus stuff
193
RGPackageStatus RGPackageStatus::pkgStatus;
195
void RGPackageStatus::initColors()
197
char *default_status_colors[N_STATUS_COUNT] = {
198
"#8ae234", // install
199
"#4e9a06", // re-install
200
"#fce94f", // upgrade
201
"#ad7fa8", // downgrade
205
"#a40000", // available-locked
206
NULL, // installed-updated
207
NULL, // installed-outdated
208
"#a40000", // installed-locked
213
gchar *config_string;
214
for (int i = 0; i < N_STATUS_COUNT; i++) {
215
config_string = g_strdup_printf("Synaptic::color-%s",
216
PackageStatusShortString[i]);
217
gtk_get_color_from_string(_config->
219
default_status_colors[i]).c_str(),
221
g_free(config_string);
225
void RGPackageStatus::initPixbufs()
228
for (int i = 0; i < N_STATUS_COUNT; i++) {
229
s = g_strdup_printf("package-%s", PackageStatusShortString[i]);
230
StatusPixbuf[i] = get_gdk_pixbuf(s);
232
supportedPix = get_gdk_pixbuf("package-supported");
235
// class that finds out what do display to get user
236
void RGPackageStatus::init()
238
RPackageStatus::init();
245
GdkColor *RGPackageStatus::getBgColor(RPackage *pkg)
247
return StatusColors[getStatus(pkg)];
250
GdkPixbuf *RGPackageStatus::getSupportedPix(RPackage *pkg)
258
GdkPixbuf *RGPackageStatus::getPixbuf(RPackage *pkg)
260
return StatusPixbuf[getStatus(pkg)];
263
void RGPackageStatus::setColor(int i, GdkColor * new_color)
265
StatusColors[i] = new_color;
268
void RGPackageStatus::saveColors()
270
gchar *color_string, *config_string;
271
for (int i = 0; i < N_STATUS_COUNT; i++) {
272
color_string = gtk_get_string_from_color(StatusColors[i]);
273
config_string = g_strdup_printf("Synaptic::color-%s",
274
PackageStatusShortString[i]);
276
_config->Set(config_string, color_string);
277
g_free(config_string);