respect https prefix
[k8lowj.git] / src / userlabel.c
blob5c262fbdd23ecdc576ef94bb5e7d30a6be1b8479
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
3 */
5 #include "gtk-all.h"
7 #include <stdlib.h>
9 #include "account.h"
10 #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;
27 static GtkWidgetClass *parent_class = NULL;
30 static void set_label_ljuser(GtkLabel *label, const char *user) {
31 char *text = g_strdup_printf("<span foreground='#0000FF' weight='bold' underline='single'>%s</span>", user);
32 gtk_label_set_markup(label, text);
33 g_free(text);
37 void jam_user_label_set_account (JamUserLabel *jul, JamAccount *acc) {
38 JamHost *host = jam_account_get_host(acc);
39 gtk_image_set_from_stock(GTK_IMAGE(jul->servericon), jam_host_get_stock_icon(host), GTK_ICON_SIZE_MENU);
40 gtk_label_set_text(GTK_LABEL(jul->serverlabel), host->name);
41 if (JAM_ACCOUNT_IS_LJ(acc)) {
42 gtk_widget_show(jul->usericon);
43 set_label_ljuser(GTK_LABEL(jul->userlabel), jam_account_get_username(acc));
44 } else {
45 gtk_widget_hide(jul->usericon);
46 gtk_label_set_text(GTK_LABEL(jul->userlabel), jam_account_get_username(acc));
51 void jam_user_label_set_journal (JamUserLabel *jul, const char *journalname) {
52 if (journalname) {
53 gtk_widget_show(jul->postingin);
54 gtk_widget_show(jul->journalicon);
55 gtk_widget_show(jul->journallabel);
56 set_label_ljuser(GTK_LABEL(jul->journallabel), journalname);
57 } else {
58 gtk_widget_hide(jul->postingin);
59 gtk_widget_hide(jul->journalicon);
60 gtk_widget_hide(jul->journallabel);
65 static void jam_user_label_init (JamUserLabel *jul) {
66 GtkWidget *sep;
68 gtk_button_set_relief(GTK_BUTTON(jul), GTK_RELIEF_NONE);
69 GTK_WIDGET_UNSET_FLAGS(jul, GTK_CAN_FOCUS);
71 jul->box = gtk_hbox_new(FALSE, 0);
73 jul->servericon = gtk_image_new();
74 jul->serverlabel = gtk_label_new(NULL);
75 /* this string is the separator between the server and username
76 * next to the "submit" button. */
77 sep = gtk_label_new(_("/"));
78 jul->usericon = gtk_image_new_from_stock("logjam-ljuser", GTK_ICON_SIZE_MENU);
79 jul->userlabel = gtk_label_new(NULL);
80 jul->postingin = gtk_label_new(_(", using "));
81 jul->journalicon = gtk_image_new_from_stock("logjam-ljcomm", GTK_ICON_SIZE_MENU);
82 jul->journallabel = gtk_label_new(NULL);
84 gtk_box_pack_start(GTK_BOX(jul->box), jul->servericon, FALSE, FALSE, 0);
85 gtk_box_pack_start(GTK_BOX(jul->box), jul->serverlabel, FALSE, FALSE, 0);
86 gtk_box_pack_start(GTK_BOX(jul->box), sep, FALSE, FALSE, 0);
87 gtk_box_pack_start(GTK_BOX(jul->box), jul->usericon, FALSE, FALSE, 0);
88 gtk_box_pack_start(GTK_BOX(jul->box), jul->userlabel, FALSE, FALSE, 0);
89 gtk_box_pack_start(GTK_BOX(jul->box), jul->postingin, FALSE, FALSE, 0);
90 gtk_box_pack_start(GTK_BOX(jul->box), jul->journalicon, FALSE, FALSE, 0);
91 gtk_box_pack_start(GTK_BOX(jul->box), jul->journallabel, FALSE, FALSE, 0);
92 gtk_container_add(GTK_CONTAINER(jul), jul->box);
94 gtk_widget_show(jul->servericon);
95 gtk_widget_show(jul->serverlabel);
96 gtk_widget_show(sep);
97 gtk_widget_show(jul->usericon);
98 gtk_widget_show(jul->userlabel);
99 gtk_widget_show(jul->box);
100 gtk_widget_hide(jul->postingin);
101 gtk_widget_hide(jul->journalicon);
102 gtk_widget_hide(jul->journallabel);
106 static void jam_user_label_show_all (GtkWidget *w) {
107 gtk_widget_show(w);
108 /* don't show children. */
112 static void jam_user_label_class_init (GtkWidgetClass *klass) {
113 parent_class = g_type_class_peek_parent(klass);
114 klass->show_all = jam_user_label_show_all;
118 GType jam_user_label_get_type (void) {
119 static GType jul_type = 0;
120 if (!jul_type) {
121 static const GTypeInfo jul_info = {
122 sizeof(GtkButtonClass),
123 NULL,
124 NULL,
125 (GClassInitFunc) jam_user_label_class_init,
126 NULL,
127 NULL,
128 sizeof(JamUserLabel),
130 (GInstanceInitFunc) jam_user_label_init,
132 jul_type = g_type_register_static(GTK_TYPE_BUTTON, "JamUserLabel", &jul_info, 0);
134 return jul_type;
138 GtkWidget *jam_user_label_new (void) {
139 JamUserLabel *jul = JAM_USER_LABEL(g_object_new(jam_user_label_get_type(), NULL));
140 return GTK_WIDGET(jul);