mirror of
https://github.com/transmission/transmission
synced 2025-03-16 00:39:34 +00:00
Replace the old progress cell renderer with a new one for silly license reasons.
This commit is contained in:
parent
bf69e47d5d
commit
e128a854ea
6 changed files with 417 additions and 402 deletions
10
gtk/main.c
10
gtk/main.c
|
@ -44,7 +44,7 @@
|
|||
#include "ipc.h"
|
||||
#include "tr_backend.h"
|
||||
#include "tr_torrent.h"
|
||||
#include "tr_cell_renderer_torrent.h"
|
||||
#include "tr_cell_renderer_progress.h"
|
||||
#include "transmission.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -456,10 +456,10 @@ makewind_list(struct cbdata *data, GObject **sizehack) {
|
|||
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
||||
|
||||
progrend = tr_cell_renderer_torrent_new();
|
||||
progrend = tr_cell_renderer_progress_new();
|
||||
/* this string is only used to determing the size of the progress bar */
|
||||
str = g_markup_printf_escaped("<big>%s</big>", _(" fnord fnord "));
|
||||
g_object_set(progrend, "label", str, NULL);
|
||||
g_object_set(progrend, "bar-sizing", str, NULL);
|
||||
g_free(str);
|
||||
col = gtk_tree_view_column_new_with_attributes(_("Progress"), progrend, NULL);
|
||||
gtk_tree_view_column_set_cell_data_func(col, progrend, dfprog, NULL, NULL);
|
||||
|
@ -650,7 +650,7 @@ setupdrag(GtkWidget *widget, struct cbdata *data) {
|
|||
static void
|
||||
stylekludge(GObject *obj, GParamSpec *spec, gpointer gdata) {
|
||||
if(0 == strcmp("style", spec->name)) {
|
||||
tr_cell_renderer_torrent_reset_style(TR_CELL_RENDERER_TORRENT(gdata));
|
||||
tr_cell_renderer_progress_reset_style(TR_CELL_RENDERER_PROGRESS(gdata));
|
||||
gtk_widget_queue_draw(GTK_WIDGET(obj));
|
||||
}
|
||||
}
|
||||
|
@ -766,7 +766,7 @@ dfprog(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
|||
str = g_strdup_printf(_("DL: %s/s\nUL: %s/s"), dlstr, ulstr);
|
||||
}
|
||||
marked = g_markup_printf_escaped("<small>%s</small>", str);
|
||||
g_object_set(rend, "text", str, "value", prog, NULL);
|
||||
g_object_set(rend, "markup", str, "progress", prog, NULL);
|
||||
g_free(dlstr);
|
||||
g_free(ulstr);
|
||||
g_free(str);
|
||||
|
|
332
gtk/tr_cell_renderer_progress.c
Normal file
332
gtk/tr_cell_renderer_progress.c
Normal file
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
$Id$
|
||||
|
||||
Copyright (c) 2006 Joshua Elsasser. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "tr_cell_renderer_progress.h"
|
||||
#include "transmission.h"
|
||||
#include "util.h"
|
||||
|
||||
enum {
|
||||
P_TEXT = 1,
|
||||
P_MARKUP,
|
||||
P_SPACER,
|
||||
P_PROG,
|
||||
};
|
||||
|
||||
static void
|
||||
class_init(gpointer gclass, gpointer gdata);
|
||||
static void
|
||||
init(GTypeInstance *instance, gpointer gclass);
|
||||
static void
|
||||
set_property(GObject *obj, guint id, const GValue *val, GParamSpec *pspec);
|
||||
static void
|
||||
get_property(GObject *obj, guint id, GValue *val, GParamSpec *pspec);
|
||||
static void
|
||||
dispose(GObject *obj);
|
||||
static void
|
||||
finalize(GObject *obj);
|
||||
static void
|
||||
get_size(GtkCellRenderer *rend, GtkWidget *widget, GdkRectangle *cell,
|
||||
gint *xoff, gint *yoff, gint *width, gint *height);
|
||||
static void
|
||||
render(GtkCellRenderer *rend, GdkWindow *win, GtkWidget *widget,
|
||||
GdkRectangle *bg, GdkRectangle *cell, GdkRectangle *expose,
|
||||
GtkCellRendererState flags);
|
||||
static GtkStyle *
|
||||
getstyle(TrCellRendererProgress *self, GtkWidget *wid, GdkWindow *win);
|
||||
|
||||
GType
|
||||
tr_cell_renderer_progress_get_type(void) {
|
||||
static GType type = 0;
|
||||
|
||||
if(0 == type) {
|
||||
static const GTypeInfo info = {
|
||||
sizeof (TrCellRendererProgressClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
class_init, /* class_init */
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (TrCellRendererProgress),
|
||||
0, /* n_preallocs */
|
||||
init, /* instance_init */
|
||||
NULL,
|
||||
};
|
||||
type = g_type_register_static(GTK_TYPE_CELL_RENDERER,
|
||||
"TrCellRendererProgressType", &info, 0);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
class_init(gpointer gclass, gpointer gdata SHUTUP) {
|
||||
GObjectClass *gobjclass = G_OBJECT_CLASS(gclass);
|
||||
GtkCellRendererClass *rendclass = GTK_CELL_RENDERER_CLASS(gclass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobjclass->set_property = set_property;
|
||||
gobjclass->get_property = get_property;
|
||||
gobjclass->dispose = dispose;
|
||||
gobjclass->finalize = finalize;
|
||||
rendclass->get_size = get_size;
|
||||
rendclass->render = render;
|
||||
|
||||
pspec = g_param_spec_string("markup", "Markup", "Marked up text to render",
|
||||
NULL, G_PARAM_READWRITE);
|
||||
g_object_class_install_property(gobjclass, P_MARKUP, pspec);
|
||||
|
||||
pspec = g_param_spec_string("bar-sizing", "Bar sizing",
|
||||
"Text to determine size of progress bar",
|
||||
NULL, G_PARAM_READWRITE);
|
||||
g_object_class_install_property(gobjclass, P_SPACER, pspec);
|
||||
|
||||
pspec = g_param_spec_float("progress", "Progress", "Progress",
|
||||
0.0, 1.0, 0.0, G_PARAM_READWRITE);
|
||||
g_object_class_install_property(gobjclass, P_PROG, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
init(GTypeInstance *instance, gpointer gclass SHUTUP) {
|
||||
TrCellRendererProgress *self = (TrCellRendererProgress *)instance;
|
||||
|
||||
self->rend = gtk_cell_renderer_text_new();
|
||||
self->style = NULL;
|
||||
self->text = NULL;
|
||||
self->spacer = NULL;
|
||||
self->barwidth = -1;
|
||||
self->barheight = -1;
|
||||
self->progress = 0.0;
|
||||
self->disposed = FALSE;
|
||||
|
||||
g_object_ref(self->rend);
|
||||
gtk_object_sink(GTK_OBJECT(self->rend));
|
||||
}
|
||||
|
||||
static void
|
||||
set_property(GObject *obj, guint id, const GValue *val,
|
||||
GParamSpec *pspec) {
|
||||
TrCellRendererProgress *self = (TrCellRendererProgress*)obj;
|
||||
|
||||
if(self->disposed)
|
||||
return;
|
||||
|
||||
switch(id) {
|
||||
case P_MARKUP:
|
||||
g_free(self->text);
|
||||
self->text = g_value_dup_string(val);
|
||||
g_object_set_property(G_OBJECT(self->rend), "markup", val);
|
||||
break;
|
||||
case P_SPACER:
|
||||
g_free(self->spacer);
|
||||
self->spacer = g_value_dup_string(val);
|
||||
self->barwidth = -1;
|
||||
self->barheight = -1;
|
||||
break;
|
||||
case P_PROG:
|
||||
self->progress = g_value_get_float(val);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_property(GObject *obj, guint id, GValue *val,
|
||||
GParamSpec *pspec) {
|
||||
TrCellRendererProgress *self = (TrCellRendererProgress*)obj;
|
||||
|
||||
if(self->disposed)
|
||||
return;
|
||||
|
||||
switch(id) {
|
||||
case P_MARKUP:
|
||||
g_value_set_string(val, self->text);
|
||||
break;
|
||||
case P_SPACER:
|
||||
g_value_set_string(val, self->spacer);
|
||||
break;
|
||||
case P_PROG:
|
||||
g_value_set_float(val, self->progress);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dispose(GObject *obj) {
|
||||
GObjectClass *parent =
|
||||
g_type_class_peek(g_type_parent(TR_CELL_RENDERER_PROGRESS_TYPE));
|
||||
TrCellRendererProgress *self = (TrCellRendererProgress*)obj;
|
||||
|
||||
if(self->disposed)
|
||||
return;
|
||||
self->disposed = TRUE;
|
||||
|
||||
g_object_unref(self->rend);
|
||||
tr_cell_renderer_progress_reset_style(self);
|
||||
|
||||
/* Chain up to the parent class */
|
||||
parent->dispose(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize(GObject *obj) {
|
||||
GObjectClass *parent =
|
||||
g_type_class_peek(g_type_parent(TR_CELL_RENDERER_PROGRESS_TYPE));
|
||||
TrCellRendererProgress *self = (TrCellRendererProgress*)obj;
|
||||
|
||||
g_free(self->text);
|
||||
g_free(self->spacer);
|
||||
|
||||
/* Chain up to the parent class */
|
||||
parent->finalize(obj);
|
||||
}
|
||||
|
||||
GtkCellRenderer *
|
||||
tr_cell_renderer_progress_new(void) {
|
||||
return g_object_new(TR_CELL_RENDERER_PROGRESS_TYPE, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
get_size(GtkCellRenderer *rend, GtkWidget *wid, GdkRectangle *cell,
|
||||
gint *xoff, gint *yoff, gint *width, gint *height) {
|
||||
TrCellRendererProgress *self;
|
||||
GdkRectangle rect;
|
||||
int xpad, ypad;
|
||||
|
||||
TR_IS_CELL_RENDERER_PROGRESS(rend);
|
||||
self = TR_CELL_RENDERER_PROGRESS(rend);
|
||||
|
||||
/* calculate and cache minimum bar width and height */
|
||||
if(0 > self->barwidth || 0 > self->barheight) {
|
||||
xpad = self->rend->xpad;
|
||||
ypad = self->rend->ypad;
|
||||
g_object_set(self->rend, "markup", self->spacer, "xpad", 0, "ypad", 0,
|
||||
NULL);
|
||||
gtk_cell_renderer_get_size(self->rend, wid, NULL, NULL, NULL,
|
||||
&self->barwidth, &self->barheight);
|
||||
g_object_set(self->rend, "markup", self->text, "xpad", xpad, "ypad", ypad,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/* get the text size */
|
||||
if(NULL != cell) {
|
||||
rect = *cell;
|
||||
rect.height -= self->barheight;
|
||||
cell = ▭
|
||||
}
|
||||
gtk_cell_renderer_get_size(self->rend, wid, cell, xoff, yoff, width, height);
|
||||
|
||||
if(NULL != width && self->barwidth > *width)
|
||||
*width = self->barwidth;
|
||||
if(NULL != height)
|
||||
*height += self->barheight + (NULL == yoff ? 0 : *yoff);
|
||||
}
|
||||
|
||||
static void
|
||||
render(GtkCellRenderer *rend, GdkWindow *win, GtkWidget *wid, GdkRectangle *bg,
|
||||
GdkRectangle *cell, GdkRectangle *expose, GtkCellRendererState flags) {
|
||||
TrCellRendererProgress *self;
|
||||
GdkRectangle rect, full, empty;
|
||||
GtkStyle *style;
|
||||
|
||||
TR_IS_CELL_RENDERER_PROGRESS(rend);
|
||||
self = TR_CELL_RENDERER_PROGRESS(rend);
|
||||
|
||||
style = getstyle(self, wid, win);
|
||||
|
||||
/* make sure we have a cached bar width */
|
||||
if(0 > self->barwidth || 0 > self->barheight)
|
||||
get_size(rend, wid, NULL, NULL, NULL, NULL, NULL);
|
||||
g_assert(0 < self->barwidth && 0 < self->barheight);
|
||||
|
||||
/* set up the dimensions for the bar and text */
|
||||
rect = *cell;
|
||||
rect.x += rend->xpad + style->xthickness;
|
||||
rect.y += rend->ypad + style->ythickness;
|
||||
rect.width -= (rend->xpad + style->xthickness) * 2;
|
||||
rect.height -= (rend->ypad + style->ythickness) * 2;
|
||||
empty = rect;
|
||||
empty.height = self->barheight;
|
||||
full = empty;
|
||||
full.x += style->xthickness;
|
||||
full.y += style->ythickness;
|
||||
full.width -= style->xthickness * 2;
|
||||
full.height -= style->ythickness * 2;
|
||||
rect.y += self->barheight;
|
||||
rect.height -= self->barheight;
|
||||
|
||||
/* draw the bar background */
|
||||
gtk_paint_box(style, win, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, wid,
|
||||
"trough", empty.x, empty.y, empty.width, empty.height);
|
||||
|
||||
/* figure the width of the complete portion of the bar */
|
||||
if(PANGO_DIRECTION_RTL ==
|
||||
pango_context_get_base_dir(gtk_widget_get_pango_context(wid)))
|
||||
full.x += full.width - (full.width * self->progress);
|
||||
full.width *= self->progress;
|
||||
|
||||
/* draw the complete portion of the bar */
|
||||
if(0 < full.width)
|
||||
gtk_paint_box(style, win, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, NULL,
|
||||
wid, "bar", full.x, full.y, full.width, full.height);
|
||||
|
||||
/* draw the text */
|
||||
if(0 < rect.height)
|
||||
gtk_cell_renderer_render(self->rend, win, wid, bg, &rect, expose, flags);
|
||||
}
|
||||
|
||||
/* ugly hack to get the style for GtkProgressBar */
|
||||
static GtkStyle *
|
||||
getstyle(TrCellRendererProgress *self, GtkWidget *wid, GdkWindow *win) {
|
||||
if(NULL == self->style) {
|
||||
self->style = gtk_rc_get_style_by_paths(gtk_widget_get_settings(wid), NULL,
|
||||
NULL, GTK_TYPE_PROGRESS_BAR);
|
||||
if(NULL != self->style)
|
||||
self->style = gtk_style_attach(gtk_style_ref(self->style), win);
|
||||
}
|
||||
|
||||
return (NULL == self->style ? wid->style : self->style);
|
||||
}
|
||||
|
||||
/* hack to make the GtkProgressBar style hack work when the theme changes */
|
||||
void
|
||||
tr_cell_renderer_progress_reset_style(TrCellRendererProgress *self) {
|
||||
TR_IS_CELL_RENDERER_PROGRESS(self);
|
||||
|
||||
if(NULL != self->style) {
|
||||
gtk_style_detach(self->style);
|
||||
gtk_style_unref(self->style);
|
||||
self->style = NULL;
|
||||
}
|
||||
}
|
79
gtk/tr_cell_renderer_progress.h
Normal file
79
gtk/tr_cell_renderer_progress.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
$Id$
|
||||
|
||||
Copyright (c) 2006 Joshua Elsasser. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef TR_CELL_RENDERER_PROGRESS_H
|
||||
#define TR_CELL_RENDERER_PROGRESS_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define TR_CELL_RENDERER_PROGRESS_TYPE (tr_cell_renderer_progress_get_type())
|
||||
#define TR_CELL_RENDERER_PROGRESS(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), TR_CELL_RENDERER_PROGRESS_TYPE, \
|
||||
TrCellRendererProgress))
|
||||
#define TR_CELL_RENDERER_PROGRESS_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), TR_CELL_RENDERER_PROGRESS_TYPE,\
|
||||
TrCellRendererProgressClass))
|
||||
#define TR_IS_CELL_RENDERER_PROGRESS(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), TR_CELL_RENDERER_PROGRESS_TYPE))
|
||||
#define TR_IS_CELL_RENDERER_PROGRESS_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), TR_CELL_RENDERER_PROGRESS_TYPE))
|
||||
#define TR_CELL_RENDERER_PROGRESS_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), TR_CELL_RENDERER_PROGRESS_TYPE, \
|
||||
TrCellRendererProgressClass))
|
||||
|
||||
typedef struct _TrCellRendererProgress TrCellRendererProgress;
|
||||
typedef struct _TrCellRendererProgressClass TrCellRendererProgressClass;
|
||||
|
||||
/* treat the contents of this structure as private */
|
||||
struct _TrCellRendererProgress {
|
||||
GtkCellRenderer parent;
|
||||
GtkCellRenderer *rend;
|
||||
GtkStyle *style;
|
||||
char *text;
|
||||
char *spacer;
|
||||
int barwidth;
|
||||
int barheight;
|
||||
gfloat progress;
|
||||
gboolean disposed;
|
||||
};
|
||||
|
||||
struct _TrCellRendererProgressClass {
|
||||
GtkCellRendererClass parent;
|
||||
};
|
||||
|
||||
GType
|
||||
tr_cell_renderer_progress_get_type(void);
|
||||
|
||||
GtkCellRenderer *
|
||||
tr_cell_renderer_progress_new(void);
|
||||
|
||||
void
|
||||
tr_cell_renderer_progress_reset_style(TrCellRendererProgress *self);
|
||||
|
||||
#endif
|
|
@ -1,326 +0,0 @@
|
|||
/* trcellrenderertorrent.c
|
||||
* Copyright (C) 2002 Naba Kumar <kh_naba@users.sourceforge.net>
|
||||
* heavily modified by Jörgen Scheibengruber <mfcn@gmx.de>
|
||||
* heavily modified by Marco Pesenti Gritti <marco@gnome.org>
|
||||
* heavily modified by Josh Elsasser <josh@elsasser.org> for transmission
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-2004. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "tr_cell_renderer_torrent.h"
|
||||
#include "util.h"
|
||||
|
||||
enum { PROP_0, PROP_VALUE, PROP_TEXT, PROP_LABEL };
|
||||
|
||||
struct _TrCellRendererTorrentPrivate {
|
||||
gfloat value;
|
||||
gchar *text;
|
||||
PangoAttrList *text_attrs;
|
||||
gchar *label;
|
||||
PangoAttrList *label_attrs;
|
||||
GtkStyle *style;
|
||||
};
|
||||
|
||||
static void
|
||||
finalize(GObject *object);
|
||||
static void
|
||||
get_property(GObject *obj, guint id, GValue *value, GParamSpec *spec);
|
||||
static void
|
||||
set_property(GObject *obj, guint id, const GValue *value, GParamSpec *spec);
|
||||
static void
|
||||
get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *area,
|
||||
gint *xoff, gint *yoff, gint *width, gint *height);
|
||||
static void
|
||||
render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget,
|
||||
GdkRectangle *bg, GdkRectangle *area, GdkRectangle *exp, guint flags);
|
||||
|
||||
|
||||
G_DEFINE_TYPE(TrCellRendererTorrent, tr_cell_renderer_torrent, GTK_TYPE_CELL_RENDERER);
|
||||
|
||||
static void
|
||||
tr_cell_renderer_torrent_class_init (TrCellRendererTorrentClass *klass) {
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
|
||||
|
||||
object_class->finalize = finalize;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
cell_class->get_size = get_size;
|
||||
cell_class->render = render;
|
||||
|
||||
g_object_class_install_property(
|
||||
object_class, PROP_VALUE,
|
||||
g_param_spec_float("value", "Value", "Value of the torrent bar",
|
||||
0.0, 1.0, 0.0, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property(
|
||||
object_class, PROP_TEXT,
|
||||
g_param_spec_string ("text", "Text", "Text under the torrent bar",
|
||||
/* XXX should I have NULL or "" here, and is initial strdup needed? */
|
||||
NULL, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property(
|
||||
object_class, PROP_LABEL,
|
||||
g_param_spec_string ("label", "Label", "Text on the torrent bar",
|
||||
NULL, G_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (object_class,
|
||||
sizeof (TrCellRendererTorrentPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
tr_cell_renderer_torrent_init(TrCellRendererTorrent *tcell) {
|
||||
tcell->priv = G_TYPE_INSTANCE_GET_PRIVATE(
|
||||
tcell, GTK_TYPE_CELL_RENDERER_TORRENT, TrCellRendererTorrentPrivate);
|
||||
tcell->priv->value = 0.0;
|
||||
tcell->priv->text = g_strdup("");
|
||||
tcell->priv->text_attrs = NULL;
|
||||
tcell->priv->label = g_strdup("");
|
||||
tcell->priv->label_attrs = NULL;
|
||||
tcell->priv->style = NULL;
|
||||
}
|
||||
|
||||
GtkCellRenderer*
|
||||
tr_cell_renderer_torrent_new(void) {
|
||||
return g_object_new (GTK_TYPE_CELL_RENDERER_TORRENT, NULL);
|
||||
}
|
||||
|
||||
/* XXX need to do this better somehow */
|
||||
void
|
||||
tr_cell_renderer_torrent_reset_style(TrCellRendererTorrent *tor) {
|
||||
if(NULL != tor->priv->style) {
|
||||
gtk_style_detach(tor->priv->style);
|
||||
gtk_style_unref(tor->priv->style);
|
||||
tor->priv->style = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finalize(GObject *object) {
|
||||
TrCellRendererTorrent *tcell = TR_CELL_RENDERER_TORRENT(object);
|
||||
|
||||
g_free(tcell->priv->text);
|
||||
g_free(tcell->priv->label);
|
||||
|
||||
if(NULL != tcell->priv->text_attrs)
|
||||
pango_attr_list_unref(tcell->priv->text_attrs);
|
||||
if(NULL != tcell->priv->label_attrs)
|
||||
pango_attr_list_unref(tcell->priv->label_attrs);
|
||||
if(NULL != tcell->priv->style) {
|
||||
gtk_style_detach(tcell->priv->style);
|
||||
gtk_style_unref(tcell->priv->style);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (tr_cell_renderer_torrent_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
get_property(GObject *object, guint id, GValue *value, GParamSpec *pspec) {
|
||||
TrCellRendererTorrent *tcell = TR_CELL_RENDERER_TORRENT (object);
|
||||
|
||||
switch (id) {
|
||||
case PROP_VALUE:
|
||||
g_value_set_float (value, tcell->priv->value);
|
||||
break;
|
||||
case PROP_TEXT:
|
||||
g_value_set_string (value, tcell->priv->text);
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, tcell->priv->label);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property(GObject *obj, guint id, const GValue *value, GParamSpec *spec) {
|
||||
TrCellRendererTorrent *tcell = TR_CELL_RENDERER_TORRENT(obj);
|
||||
gchar **prop = NULL;
|
||||
PangoAttrList **attrs = NULL;
|
||||
/*GError *err = NULL;*/
|
||||
const gchar *markup;
|
||||
|
||||
switch(id) {
|
||||
case PROP_VALUE:
|
||||
tcell->priv->value = g_value_get_float(value);
|
||||
break;
|
||||
|
||||
case PROP_TEXT:
|
||||
prop = &tcell->priv->text;
|
||||
attrs = &tcell->priv->text_attrs;
|
||||
/* fallthrough */
|
||||
|
||||
case PROP_LABEL:
|
||||
if(PROP_LABEL == id) {
|
||||
prop = &tcell->priv->label;
|
||||
attrs = &tcell->priv->label_attrs;
|
||||
}
|
||||
|
||||
if(NULL == (markup = g_value_get_string(value)))
|
||||
markup = "";
|
||||
|
||||
g_free(*prop);
|
||||
if(NULL != *attrs)
|
||||
pango_attr_list_unref(*attrs);
|
||||
|
||||
*prop = g_strdup(markup);
|
||||
|
||||
/*
|
||||
if(pango_parse_markup(markup, -1, 0, attrs, prop, NULL, &err))
|
||||
break;
|
||||
|
||||
g_warning ("Failed to parse markup: %s", err->message);
|
||||
g_error_free(err);
|
||||
*/
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *area,
|
||||
gint *xoff, gint *yoff, gint *width, gint *height) {
|
||||
TrCellRendererTorrent *tcell = TR_CELL_RENDERER_TORRENT(cell);
|
||||
/* XXX do I have to unref the context? */
|
||||
PangoLayout *layout = pango_layout_new(gtk_widget_get_pango_context(widget));
|
||||
PangoRectangle rect;
|
||||
gint h = cell->ypad * 2;
|
||||
gint w1, w2;
|
||||
|
||||
pango_layout_set_markup(layout, tcell->priv->label, -1);
|
||||
pango_layout_get_pixel_extents(layout, NULL, &rect);
|
||||
w1 = rect.width;
|
||||
h += rect.height;
|
||||
|
||||
pango_layout_set_markup(layout, tcell->priv->text, -1);
|
||||
pango_layout_get_pixel_extents(layout, NULL, &rect);
|
||||
w2 = rect.width;
|
||||
h += rect.height;
|
||||
|
||||
if(NULL != xoff)
|
||||
*xoff = 0;
|
||||
if(NULL != yoff)
|
||||
*yoff = (area->height - h) / 2;
|
||||
if(NULL != width)
|
||||
*width = MAX(w1, w2) + cell->xpad * 2;
|
||||
if(NULL != height)
|
||||
*height = h;
|
||||
|
||||
g_object_unref(layout);
|
||||
}
|
||||
|
||||
#define RECTARGS(rect) (rect).x, (rect).y, (rect).width, (rect).height
|
||||
|
||||
static void
|
||||
render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget,
|
||||
GdkRectangle *bg SHUTUP, GdkRectangle *area, GdkRectangle *exp SHUTUP,
|
||||
guint flags) {
|
||||
TrCellRendererTorrent *tcell = TR_CELL_RENDERER_TORRENT(cell);
|
||||
PangoContext *ctx = gtk_widget_get_pango_context(widget);
|
||||
PangoLayout *llayout, *tlayout;
|
||||
PangoRectangle lrect, trect;
|
||||
GdkRectangle bar, complete, text;
|
||||
gboolean rtl;
|
||||
GtkStyle *style;
|
||||
GtkCellRendererState textstate;
|
||||
|
||||
/* try to use the style for GtkProgressBar */
|
||||
if(NULL == tcell->priv->style)
|
||||
if(NULL != (tcell->priv->style = gtk_rc_get_style_by_paths(
|
||||
gtk_widget_get_settings(widget), NULL, NULL,
|
||||
gtk_progress_bar_get_type())))
|
||||
tcell->priv->style = gtk_style_attach(gtk_style_ref(tcell->priv->style),
|
||||
window);
|
||||
style = (NULL == tcell->priv->style ? widget->style : tcell->priv->style);
|
||||
|
||||
rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||
|
||||
/* get the text layouts */
|
||||
llayout = pango_layout_new(ctx);
|
||||
/* XXX cache parsed markup? */
|
||||
pango_layout_set_markup(llayout, tcell->priv->label, -1);
|
||||
pango_layout_get_pixel_extents(llayout, NULL, &lrect);
|
||||
tlayout = pango_layout_new(ctx);
|
||||
pango_layout_set_markup(tlayout, tcell->priv->text, -1);
|
||||
pango_layout_get_pixel_extents (tlayout, NULL, &trect);
|
||||
|
||||
/* set up the dimensions for the bar */
|
||||
bar.x = area->x + cell->xpad;
|
||||
bar.y = area->y + cell->ypad +
|
||||
(area->height - lrect.height - trect.height) / 2;
|
||||
bar.width = area->width - cell->xpad * 2;
|
||||
bar.height = lrect.height;
|
||||
|
||||
/* set up the dimensions for the complete portion of the bar */
|
||||
complete.x = bar.x + style->xthickness;
|
||||
complete.y = bar.y + style->ythickness;
|
||||
complete.width = (bar.width - style->xthickness * 2) * tcell->priv->value;
|
||||
complete.height = bar.height - style->ythickness * 2;
|
||||
if(rtl)
|
||||
complete.x += bar.width - (complete.width + style->xthickness * 2);
|
||||
|
||||
/* set up the dimensions for the text under the bar */
|
||||
text.x = bar.x;
|
||||
text.y = bar.y + bar.height;
|
||||
text.width = bar.width;
|
||||
text.height = area->height - bar.height;
|
||||
if(rtl && text.width > trect.width)
|
||||
text.x += text.width - trect.width;
|
||||
|
||||
/* determine the state to render the text as */
|
||||
if(GTK_CELL_RENDERER_INSENSITIVE & flags || !cell->sensitive)
|
||||
textstate = GTK_STATE_INSENSITIVE;
|
||||
else if(GTK_CELL_RENDERER_SELECTED & flags)
|
||||
textstate = (GTK_WIDGET_HAS_FOCUS(widget) ?
|
||||
GTK_STATE_SELECTED : GTK_STATE_ACTIVE);
|
||||
else if(GTK_CELL_RENDERER_PRELIT & flags &&
|
||||
GTK_STATE_PRELIGHT == GTK_WIDGET_STATE(widget))
|
||||
textstate = GTK_STATE_PRELIGHT;
|
||||
else if(GTK_STATE_INSENSITIVE == GTK_WIDGET_STATE(widget))
|
||||
textstate = GTK_STATE_INSENSITIVE;
|
||||
else
|
||||
textstate = GTK_STATE_NORMAL;
|
||||
|
||||
/* draw the background of the bar */
|
||||
if(complete.width < bar.width)
|
||||
gtk_paint_box(style, window, GTK_STATE_NORMAL, GTK_SHADOW_IN,
|
||||
NULL, widget, "trough", RECTARGS(bar));
|
||||
|
||||
/* draw the complete portion of the bar */
|
||||
if(0 < complete.width)
|
||||
gtk_paint_box(style, window, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
|
||||
NULL, widget, "bar", RECTARGS(complete));
|
||||
|
||||
/* draw the text under the bar */
|
||||
gtk_paint_layout(widget->style, window, textstate, TRUE, &text,
|
||||
widget, "cellrenderertext", text.x, text.y, tlayout);
|
||||
|
||||
/* free memory */
|
||||
g_object_unref(llayout);
|
||||
g_object_unref(tlayout);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/* trcellrenderertorrent.h
|
||||
* Copyright (C) 2002 Naba Kumar <kh_naba@users.sourceforge.net>
|
||||
* modified by Jörgen Scheibengruber <mfcn@gmx.de>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-2004. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __TR_CELL_RENDERER_TORRENT_H__
|
||||
#define __TR_CELL_RENDERER_TORRENT_H__
|
||||
|
||||
#include <gtk/gtkcellrenderer.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_CELL_RENDERER_TORRENT (tr_cell_renderer_torrent_get_type ())
|
||||
#define TR_CELL_RENDERER_TORRENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CELL_RENDERER_TORRENT, TrCellRendererTorrent))
|
||||
#define TR_CELL_RENDERER_TORRENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CELL_RENDERER_TORRENT, TrCellRendererTorrentClass))
|
||||
#define GTK_IS_CELL_RENDERER_TORRENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CELL_RENDERER_TORRENT))
|
||||
#define GTK_IS_CELL_RENDERER_TORRENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CELL_RENDERER_TORRENT))
|
||||
#define TR_CELL_RENDERER_TORRENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_RENDERER_TORRENT, TrCellRendererTorrentClass))
|
||||
|
||||
typedef struct _TrCellRendererTorrent TrCellRendererTorrent;
|
||||
typedef struct _TrCellRendererTorrentClass TrCellRendererTorrentClass;
|
||||
typedef struct _TrCellRendererTorrentPrivate TrCellRendererTorrentPrivate;
|
||||
|
||||
struct _TrCellRendererTorrent
|
||||
{
|
||||
GtkCellRenderer parent_instance;
|
||||
|
||||
/*< private >*/
|
||||
TrCellRendererTorrentPrivate *priv;
|
||||
};
|
||||
|
||||
struct _TrCellRendererTorrentClass
|
||||
{
|
||||
GtkCellRendererClass parent_class;
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gtk_reserved1) (void);
|
||||
void (*_gtk_reserved2) (void);
|
||||
void (*_gtk_reserved3) (void);
|
||||
void (*_gtk_reserved4) (void);
|
||||
};
|
||||
|
||||
GType tr_cell_renderer_torrent_get_type (void) G_GNUC_CONST;
|
||||
GtkCellRenderer* tr_cell_renderer_torrent_new (void);
|
||||
void tr_cell_renderer_torrent_reset_style(TrCellRendererTorrent *);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __TR_CELL_RENDERER_TORRENT_H__ */
|
|
@ -4,7 +4,7 @@ include ../mk/config.mk
|
|||
include ../mk/common.mk
|
||||
|
||||
SRCS = conf.c dialogs.c io.c ipc.c main.c tr_backend.c tr_torrent.c \
|
||||
tr_cell_renderer_torrent.c util.c
|
||||
tr_cell_renderer_progress.c util.c
|
||||
OBJS = $(SRCS:%.c=%.o)
|
||||
|
||||
CFLAGS += $(CFLAGS_GTK) -I../libtransmission
|
||||
|
|
Loading…
Add table
Reference in a new issue