- split up load_pixmap in load_pixmap, load_pixmap_as_pixmap and

load_pixmap_as_pixbuf
- set minimize icon as suggested by Jordi (someone know how to make this
  work properly with windowmaker?)
- work around gcc complaining about %c in strftime


git-svn-id: http://svn.code.sf.net/p/xqf/code/trunk@563 d2ac09be-c843-0410-8b1f-f8a84130e0ec
This commit is contained in:
Ludwig Nussel 2003-11-28 22:50:04 +00:00 committed by l-n
parent 79ffc84c0a
commit e9725cec41
10 changed files with 154 additions and 51 deletions

View File

@ -1,3 +1,10 @@
Nov 28, 2003: Ludwig Nussel <l-n@users.sourceforge.net>
- split up load_pixmap in load_pixmap, load_pixmap_as_pixmap and
load_pixmap_as_pixbuf
- set minimize icon as suggested by Jordi (someone know how to make this
work properly with windowmaker?)
- work around gcc complaining about %c in strftime
Nov 27, 2003: Alex <alex_b@users.sourceforge.net>
- Changed version to 0.9.13.1

View File

@ -4,6 +4,7 @@ localedir = $(datadir)/locale
INCLUDES = -I$(top_srcdir)/intl \
-DLOCALEDIR=\"$(localedir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" \
-DPIXMAPSDIR=\"$(datadir)/pixmaps\" \
$(GTK_CFLAGS) \
$(QSTAT23) \
$(DEBUG) \

View File

@ -30,10 +30,12 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "loadpixmap.h"
#include "pixmaps.h"
#include "i18n.h"
#include "debug.h"
/* This is an internally used function to check if a pixmap file exists. */
static gchar* check_file_exists (const gchar *directory,
gchar* check_file_exists (const gchar *directory,
const gchar *filename);
/* This is an internally used function to create pixmaps. */
@ -62,7 +64,7 @@ create_dummy_pixmap (GtkWidget *widget)
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
NULL, dummy_pixmap_xpm);
if (gdkpixmap == NULL)
g_error ("Couldn't create replacement pixmap.");
xqf_error ("Couldn't create replacement pixmap.");
pixmap = gtk_pixmap_new (gdkpixmap, mask);
gdk_pixmap_unref (gdkpixmap);
gdk_bitmap_unref (mask);
@ -95,40 +97,62 @@ gchar* find_pixmap_directory(const gchar* filename)
return found_filename;
}
/* This is an internally used function to create pixmaps. */
GtkWidget*
load_pixmap (GtkWidget *widget,
const gchar *filename)
GtkWidget* load_pixmap (GtkWidget* widget, const gchar* filename)
{
GtkWidget *pixmap;
struct pixmap pix;
if(!load_pixmap_as_pixmap(widget, filename, &pix))
{
return create_dummy_pixmap(widget);
}
pixmap = gtk_pixmap_new (pix.pix, pix.mask);
gdk_pixmap_unref (pix.pix);
if(pix.mask) gdk_bitmap_unref (pix.mask);
return pixmap;
}
/** find a pixmap file either absolute or in the pixmap search path.
* @returns filename if file exists, NULL otherwise. must be freed
*/
static char* find_pixmap_file(const char* filename)
{
char *found_filename = NULL;
g_return_val_if_fail(filename!=NULL,NULL);
if (!filename[0])
return NULL;
// load absolute paths directly
if(filename[0]=='/')
found_filename = check_file_exists(NULL, filename);
else
found_filename = find_pixmap_directory(filename);
return found_filename;
}
struct pixmap* load_pixmap_as_pixmap (GtkWidget* widget, const gchar* filename, struct pixmap* pix)
{
gchar *found_filename = NULL;
GdkColormap *colormap;
GdkPixmap *gdkpixmap;
GdkBitmap *mask;
GtkWidget *pixmap;
GdkColormap *colormap = NULL;
if (!filename || !filename[0])
return create_dummy_pixmap (widget);
g_return_val_if_fail(widget!=NULL,NULL);
g_return_val_if_fail(pix!=NULL,NULL);
found_filename = find_pixmap_directory(filename);
found_filename = find_pixmap_file(filename);
#if 0 //crap...
/* If we haven't found the pixmap, try the source directory. */
if (!found_filename)
if(!found_filename)
{
found_filename = check_file_exists ("src/xpm", filename);
}
#endif
if (!found_filename)
{
g_warning (_("Couldn't find pixmap file: %s"), filename);
return create_dummy_pixmap (widget);
xqf_warning (_("Error loading pixmap file: %s"), filename);
return NULL;
}
if(strlen(found_filename)>4 && !strcmp(found_filename+strlen(found_filename)-4,".xpm"))
{
colormap = gtk_widget_get_colormap (widget);
gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
pix->pix = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &pix->mask,
NULL, found_filename);
}
else
@ -142,43 +166,67 @@ load_pixmap (GtkWidget *widget,
#endif
if (pixbuf == NULL)
{
g_warning (_("Error loading pixmap file: %s"), found_filename);
xqf_warning (_("Error loading pixmap file: %s"), found_filename);
g_free (found_filename);
return create_dummy_pixmap (widget);
return NULL;
}
gdk_pixbuf_render_pixmap_and_mask(pixbuf,&gdkpixmap,&mask,255);
gdk_pixbuf_render_pixmap_and_mask(pixbuf,&pix->pix,&pix->mask,255);
gdk_pixbuf_unref(pixbuf);
}
if (gdkpixmap == NULL)
if (pix->pix == NULL)
{
g_warning (_("Error loading pixmap file: %s"), found_filename);
xqf_warning (_("Error loading pixmap file: %s"), found_filename);
g_free (found_filename);
return create_dummy_pixmap (widget);
return NULL;
}
g_free (found_filename);
pixmap = gtk_pixmap_new (gdkpixmap, mask);
gdk_pixmap_unref (gdkpixmap);
if(mask) gdk_bitmap_unref (mask);
return pixmap;
return pix;
}
/* This is an internally used function to check if a pixmap file exists. */
static gchar*
check_file_exists (const gchar *directory,
const gchar *filename)
void* load_pixmap_as_pixbuf (GtkWidget* widget, const gchar* filename)
{
gchar *found_filename = NULL;
GdkPixbuf* pixbuf = NULL;
g_return_val_if_fail(widget!=NULL,NULL);
found_filename = find_pixmap_file(filename);
if(!found_filename)
{
xqf_warning (_("Error loading pixmap file: %s"), filename);
return NULL;
}
/*FIXME_GTK2: need GError*/
#ifdef USE_GTK2
pixbuf = gdk_pixbuf_new_from_file(found_filename, NULL);
#else
pixbuf = gdk_pixbuf_new_from_file(found_filename);
#endif
if (pixbuf == NULL)
xqf_warning (_("Error loading pixmap file: %s"), found_filename);
g_free (found_filename);
return pixbuf;
}
/** directory may be null */
gchar* check_file_exists (const gchar* directory, const gchar* filename)
{
gchar *full_filename;
struct stat s;
gint status;
full_filename = (gchar*) g_malloc (strlen (directory) + 1
+ strlen (filename) + 1);
strcpy (full_filename, directory);
strcat (full_filename, G_DIR_SEPARATOR_S);
strcat (full_filename, filename);
if(directory)
full_filename = g_strconcat(directory, G_DIR_SEPARATOR_S, filename, NULL);
else
full_filename = g_strdup(filename);
status = stat (full_filename, &s);
if (status == 0 && S_ISREG (s.st_mode))
@ -186,4 +234,3 @@ check_file_exists (const gchar *directory,
g_free (full_filename);
return NULL;
}

View File

@ -29,10 +29,14 @@ void add_pixmap_directory (const gchar* directory);
*/
gchar* find_pixmap_directory(const gchar* filename);
/*
* Private Functions.
*/
/* This is used to create the pixmaps in the interface. */
/** This is used to create the pixmaps in the interface. */
GtkWidget* load_pixmap (GtkWidget* widget, const gchar* filename);
/** fill in passed pixmap struct, return pointer to this struct on success,
* NULL otherwise
*/
struct pixmap* load_pixmap_as_pixmap (GtkWidget* widget, const gchar* filename, struct pixmap* pix);
/** load a pixmap in search path as GdkPixbuf, void* just to avoid a special header */
void* load_pixmap_as_pixbuf (GtkWidget* widget, const gchar* filename);
#endif

View File

@ -32,6 +32,7 @@
#include "loadpixmap.h"
#include "i18n.h"
#include "pref.h"
#include "xutils.h"
static GtkWidget* splashscreen;

View File

@ -753,6 +753,11 @@ char* resolve_path(const char* path)
return dir;
}
/** workaround to prevent gcc from complaining about %c as suggested by "man strftime" */
static inline size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) {
return strftime(s, max, fmt, tm);
}
// return locale's string representation of t. must be freed manually
char* timet2string(const time_t* t)
{
@ -762,7 +767,7 @@ char* timet2string(const time_t* t)
char* str;
gmtime_r(t,&tm_s);
if(!strftime(timebuf,timebuf_len,"%c",&tm_s))
if(!my_strftime(timebuf,timebuf_len,"%c",&tm_s))
{
// error converting time to string representation, shouldn't happen
str=_("<error>");

View File

@ -92,6 +92,8 @@ time_t xqf_start_time;
char* xqf_PACKAGE_DATA_DIR = PACKAGE_DATA_DIR;
char* xqf_LOCALEDIR = LOCALEDIR;
char* xqf_PIXMAPSDIR = PIXMAPSDIR;
char* qstat_configfile = NULL;
GtkWidget *main_window = NULL;
@ -3580,6 +3582,8 @@ void create_main_window (void) {
restore_main_window_geometry ();
window_set_icon(main_window);
gtk_widget_show (main_window);
gtk_window_add_accel_group (GTK_WINDOW (main_window), accel_group);
@ -3750,6 +3754,10 @@ int main (int argc, char *argv[]) {
if(var)
xqf_LOCALEDIR = var;
var = getenv("xqf_PIXMAPSDIR");
if(var)
xqf_PIXMAPSDIR = var;
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, xqf_LOCALEDIR);
@ -3785,6 +3793,8 @@ int main (int argc, char *argv[]) {
g_free(defaultpixmapdir);
}
add_pixmap_directory (xqf_PIXMAPSDIR);
qstat_configfile = g_strconcat(xqf_PACKAGE_DATA_DIR, "/qstat.cfg", NULL);
dns_gtk_init ();

View File

@ -239,6 +239,8 @@ struct master {
extern time_t xqf_start_time;
extern char* xqf_PACKAGE_DATA_DIR;
extern char* xqf_LOCALEDIR;
extern char* xqf_PIXMAPSDIR;
extern char* qstat_configfile;
extern GSList *cur_source; /* GSList <struct master *> */

View File

@ -20,6 +20,9 @@
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include "pixmaps.h"
#include "loadpixmap.h"
void iconify_window (GdkWindow *window) {
Window xwindow;
@ -35,4 +38,25 @@ void iconify_window (GdkWindow *window) {
XIconifyWindow (GDK_DISPLAY (), xwindow, DefaultScreen (GDK_DISPLAY ()));
}
static const char* minimize_icon = "xqf_48x48.png";
void window_set_icon (GtkWidget *win)
{
#ifdef USE_GTK2
GdkPixbuf* pixbuf;
pixbuf = load_pixmap_as_pixbuf(minimize_icon);
if(pixbuf)
{
gtk_window_set_icon (GTK_WINDOW (main_window), pixbuf);
gdk_pixbuf_unref (pixbuf);
}
#else
static struct pixmap pix;
if(!load_pixmap_as_pixmap(win, minimize_icon, &pix))
return;
gdk_window_set_icon(win->window, NULL, pix.pix, pix.mask);
gdk_window_set_icon_name(win->window, "XQF");
#endif
}

View File

@ -24,5 +24,7 @@
extern void iconify_window (GdkWindow *window);
void window_set_icon (GtkWidget *window);
#endif /* __XUTILS_H__ */