1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
8 #include <stdlib.h> /* atoi */
11 #include "userlabel.h"
13 struct _JamUserLabel
{
17 GtkWidget
*servericon
;
18 GtkWidget
*serverlabel
;
22 GtkWidget
*journalicon
;
23 GtkWidget
*journallabel
;
26 static GtkWidgetClass
*parent_class
= NULL
;
29 set_label_ljuser(GtkLabel
*label
, const char *user
) {
32 text
= g_strdup_printf(
33 "<span foreground='#0000FF' weight='bold' underline='single'>%s</span>",
35 gtk_label_set_markup(label
, text
);
40 jam_user_label_set_account(JamUserLabel
*jul
, JamAccount
*acc
) {
41 JamHost
*host
= jam_account_get_host(acc
);
42 gtk_image_set_from_stock(GTK_IMAGE(jul
->servericon
),
43 jam_host_get_stock_icon(host
), GTK_ICON_SIZE_MENU
);
44 gtk_label_set_text(GTK_LABEL(jul
->serverlabel
), host
->name
);
46 if (JAM_ACCOUNT_IS_LJ(acc
)) {
47 gtk_widget_show(jul
->usericon
);
48 set_label_ljuser(GTK_LABEL(jul
->userlabel
),
49 jam_account_get_username(acc
));
51 gtk_widget_hide(jul
->usericon
);
52 gtk_label_set_text(GTK_LABEL(jul
->userlabel
),
53 jam_account_get_username(acc
));
58 jam_user_label_set_journal(JamUserLabel
*jul
, const char *journalname
) {
60 gtk_widget_show(jul
->postingin
);
61 gtk_widget_show(jul
->journalicon
);
62 gtk_widget_show(jul
->journallabel
);
63 set_label_ljuser(GTK_LABEL(jul
->journallabel
), journalname
);
65 gtk_widget_hide(jul
->postingin
);
66 gtk_widget_hide(jul
->journalicon
);
67 gtk_widget_hide(jul
->journallabel
);
72 jam_user_label_init(JamUserLabel
*jul
) {
75 gtk_button_set_relief(GTK_BUTTON(jul
), GTK_RELIEF_NONE
);
76 GTK_WIDGET_UNSET_FLAGS(jul
, GTK_CAN_FOCUS
);
78 jul
->box
= gtk_hbox_new(FALSE
, 0);
80 jul
->servericon
= gtk_image_new();
81 jul
->serverlabel
= gtk_label_new(NULL
);
82 /* this string is the separator between the server and username
83 * next to the "submit" button. */
84 sep
= gtk_label_new(_("/"));
85 jul
->usericon
= gtk_image_new_from_stock("logjam-ljuser",
87 jul
->userlabel
= gtk_label_new(NULL
);
88 jul
->postingin
= gtk_label_new(_(", using "));
89 jul
->journalicon
= gtk_image_new_from_stock("logjam-ljcomm",
91 jul
->journallabel
= gtk_label_new(NULL
);
93 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->servericon
, FALSE
, FALSE
, 0);
94 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->serverlabel
, FALSE
, FALSE
, 0);
95 gtk_box_pack_start(GTK_BOX(jul
->box
), sep
, FALSE
, FALSE
, 0);
96 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->usericon
, FALSE
, FALSE
, 0);
97 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->userlabel
, FALSE
, FALSE
, 0);
98 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->postingin
, FALSE
, FALSE
, 0);
99 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->journalicon
, FALSE
, FALSE
, 0);
100 gtk_box_pack_start(GTK_BOX(jul
->box
), jul
->journallabel
, FALSE
, FALSE
, 0);
101 gtk_container_add(GTK_CONTAINER(jul
), jul
->box
);
103 gtk_widget_show(jul
->servericon
);
104 gtk_widget_show(jul
->serverlabel
);
105 gtk_widget_show(sep
);
106 gtk_widget_show(jul
->usericon
);
107 gtk_widget_show(jul
->userlabel
);
108 gtk_widget_show(jul
->box
);
109 gtk_widget_hide(jul
->postingin
);
110 gtk_widget_hide(jul
->journalicon
);
111 gtk_widget_hide(jul
->journallabel
);
115 jam_user_label_show_all(GtkWidget
*w
) {
117 /* don't show children. */
121 jam_user_label_class_init(GtkWidgetClass
*klass
) {
122 parent_class
= g_type_class_peek_parent(klass
);
123 klass
->show_all
= jam_user_label_show_all
;
127 jam_user_label_get_type(void) {
128 static GType jul_type
= 0;
130 static const GTypeInfo jul_info
= {
131 sizeof (GtkButtonClass
),
134 (GClassInitFunc
) jam_user_label_class_init
,
137 sizeof (JamUserLabel
),
139 (GInstanceInitFunc
) jam_user_label_init
,
141 jul_type
= g_type_register_static(GTK_TYPE_BUTTON
, "JamUserLabel",
148 jam_user_label_new(void) {
149 JamUserLabel
*jul
= JAM_USER_LABEL(g_object_new(jam_user_label_get_type(), NULL
));
150 return GTK_WIDGET(jul
);