removed libsoup support
[k8lowj.git] / src / userlabel.c
blobe8ba2b718b85759ffa8266879585d4267c56cb2e
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
5 */
7 #include "gtk-all.h"
8 #include <stdlib.h> /* atoi */
10 #include "account.h"
11 #include "userlabel.h"
13 struct _JamUserLabel {
14 GtkButton parent;
16 GtkWidget *box;
17 GtkWidget *servericon;
18 GtkWidget *serverlabel;
19 GtkWidget *usericon;
20 GtkWidget *userlabel;
21 GtkWidget *postingin;
22 GtkWidget *journalicon;
23 GtkWidget *journallabel;
26 static GtkWidgetClass *parent_class = NULL;
28 static void
29 set_label_ljuser(GtkLabel *label, const char *user) {
30 char *text;
32 text = g_strdup_printf(
33 "<span foreground='#0000FF' weight='bold' underline='single'>%s</span>",
34 user);
35 gtk_label_set_markup(label, text);
36 g_free(text);
39 void
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));
50 } else {
51 gtk_widget_hide(jul->usericon);
52 gtk_label_set_text(GTK_LABEL(jul->userlabel),
53 jam_account_get_username(acc));
57 void
58 jam_user_label_set_journal(JamUserLabel *jul, const char *journalname) {
59 if (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);
64 } else {
65 gtk_widget_hide(jul->postingin);
66 gtk_widget_hide(jul->journalicon);
67 gtk_widget_hide(jul->journallabel);
71 static void
72 jam_user_label_init(JamUserLabel *jul) {
73 GtkWidget *sep;
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",
86 GTK_ICON_SIZE_MENU);
87 jul->userlabel = gtk_label_new(NULL);
88 jul->postingin = gtk_label_new(_(", using "));
89 jul->journalicon = gtk_image_new_from_stock("logjam-ljcomm",
90 GTK_ICON_SIZE_MENU);
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);
114 static void
115 jam_user_label_show_all(GtkWidget *w) {
116 gtk_widget_show(w);
117 /* don't show children. */
120 static void
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;
126 GType
127 jam_user_label_get_type(void) {
128 static GType jul_type = 0;
129 if (!jul_type) {
130 static const GTypeInfo jul_info = {
131 sizeof (GtkButtonClass),
132 NULL,
133 NULL,
134 (GClassInitFunc) jam_user_label_class_init,
135 NULL,
136 NULL,
137 sizeof (JamUserLabel),
139 (GInstanceInitFunc) jam_user_label_init,
141 jul_type = g_type_register_static(GTK_TYPE_BUTTON, "JamUserLabel",
142 &jul_info, 0);
144 return jul_type;
147 GtkWidget*
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);