1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
14 /* magic number, defines how long the name will stay centered before scrolling off. */
15 #define COUNTER_DELAY (20)
21 GtkWidget
*scrollerbox
;
33 /* randomly permute the list of contributors. */
34 static void rearrange_contribs (void) {
37 srand((unsigned int)time(NULL
));
38 for (i
= 0; i
< CONTRIBCOUNT
; ++i
) {
39 j
= rand()%CONTRIBCOUNT
;
41 contribs
[i
] = contribs
[j
];
47 static void homepage_cb (GtkWidget
*win
, GdkEventButton
*eb
, AboutUI
*aui
) {
48 spawn_url(GTK_WINDOW(aui
->win
), "http://example.com");
52 static GtkWidget
*make_title_box (AboutUI
*aui
) {
54 GtkWidget
*image
, *label
;
57 image
= gtk_image_new_from_stock("logjam-goat", GTK_ICON_SIZE_DIALOG
);
59 label
= gtk_label_new(NULL
);
60 text
= g_strdup_printf(_("<b><big>LogJam %s</big></b>\n" "<small>Copyright (C) 2000-2004 Evan Martin</small>"), PACKAGE_VERSION
);
61 gtk_label_set_markup(GTK_LABEL(label
), text
);
63 gtk_label_set_justify(GTK_LABEL(label
), GTK_JUSTIFY_CENTER
);
65 aui
->linkwin
= gtk_event_box_new();
66 g_signal_connect(G_OBJECT(aui
->linkwin
), "button-press-event", G_CALLBACK(homepage_cb
), aui
);
67 aui
->cursor
= gdk_cursor_new(GDK_HAND2
);
68 gtk_container_add(GTK_CONTAINER(aui
->linkwin
), label
);
70 hbox
= gtk_hbox_new(FALSE
, 10);
71 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 5);
72 gtk_box_pack_start(GTK_BOX(hbox
), image
, FALSE
, FALSE
, 0);
73 gtk_box_pack_start(GTK_BOX(hbox
), aui
->linkwin
, TRUE
, FALSE
, 0);
79 static gboolean
showthanks_cb (AboutUI
*aui
) {
82 if (!aui
->layout
|| aui
->y
> aui
->scroller
->allocation
.height
) {
84 g_object_unref(G_OBJECT(aui
->layout
));
85 aui
->curcontrib
= (aui
->curcontrib
+ 1) % CONTRIBCOUNT
;
86 gtk_tooltips_set_tip(app
.tooltips
, aui
->scrollerbox
, _(contribs
[aui
->curcontrib
].contribution
), NULL
);
88 aui
->layout
= gtk_widget_create_pango_layout(aui
->scroller
, contribs
[aui
->curcontrib
].name
);
89 pango_layout_get_pixel_size(aui
->layout
, &w
, &h
);
90 gtk_widget_set_size_request(aui
->scroller
, w
, h
);
91 gtk_widget_queue_resize(aui
->scroller
);
94 /* advance y, except when we get to zero we cycle through counter once. */
95 if (aui
->y
== 0) ++aui
->counter
; else ++aui
->y
;
96 if (aui
->counter
== COUNTER_DELAY
) {
101 if (aui
->scroller
->window
) gdk_window_invalidate_rect(aui
->scroller
->window
, NULL
, FALSE
);
102 return TRUE
; /* continue running. */
106 static void button_cb (GtkWidget
*widget
, GdkEventExpose
*event
, AboutUI
*aui
) {
107 /* force advance to next name. */
108 aui
->y
= aui
->scroller
->allocation
.height
+1;
115 static void expose_cb (GtkWidget
*widget
, GdkEventExpose
*event
, AboutUI
*aui
) {
116 gtk_paint_layout(widget
->style
, widget
->window
, GTK_STATE_NORMAL
, FALSE
, &event
->area
, widget
, "label", aui
->x
, aui
->y
, aui
->layout
);
120 static void configure_cb (GtkWidget
*widget
, GdkEventConfigure
*e
, AboutUI
*aui
) {
122 pango_layout_get_pixel_size(aui
->layout
, &w
, NULL
);
123 aui
->x
= (widget
->allocation
.width
-w
)/2;
124 gdk_window_invalidate_rect(widget
->window
, NULL
, FALSE
);
128 static void destroy_cb (GtkWidget
*win
, AboutUI
*aui
) {
129 if (aui
->layout
) g_object_unref(G_OBJECT(aui
->layout
));
130 if (aui
->timeout
) g_source_remove(aui
->timeout
);
131 if (aui
->cursor
) gdk_cursor_unref(aui
->cursor
);
136 void about_dlg (GtkWindow
*mainwin
) {
138 GtkWidget
*mainbox
, *fh
;
140 aui
= g_new0(AboutUI
, 1);
142 aui
->win
= gtk_dialog_new_with_buttons(_("About LogJam"), mainwin
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
, NULL
);
143 g_signal_connect_swapped(G_OBJECT(aui
->win
), "response", G_CALLBACK(gtk_widget_destroy
), aui
->win
);
144 g_signal_connect(G_OBJECT(aui
->win
), "destroy", G_CALLBACK(destroy_cb
), aui
);
146 /* make the bounding padding box */
147 mainbox
= gtk_vbox_new(FALSE
, 5);
149 gtk_box_pack_start(GTK_BOX(mainbox
), make_title_box(aui
), FALSE
, FALSE
, 0);
151 fh
= gtk_label_new(_("This program is free software; you can redistribute it and/or modify\n"
152 "it under the terms of the GNU General Public License as published by\n"
153 "the Free Software Foundation; either version 2 of the License, or\n"
154 "(at your option) any later version."));
156 gtk_box_pack_start(GTK_BOX(mainbox
), fh
, TRUE
, TRUE
, 0);
158 gtk_box_pack_start(GTK_BOX(mainbox
), gtk_label_new(_("LogJam was made with the help of many people, including:")), FALSE
, FALSE
, 0);
160 aui
->scrollerbox
= gtk_event_box_new();
161 gtk_box_pack_start(GTK_BOX(mainbox
), aui
->scrollerbox
, FALSE
, FALSE
, 0);
163 aui
->scroller
= gtk_drawing_area_new();
164 rearrange_contribs();
166 gtk_widget_add_events(aui
->scroller
, GDK_BUTTON_PRESS_MASK
);
167 g_signal_connect(G_OBJECT(aui
->scroller
), "button-press-event", G_CALLBACK(button_cb
), aui
);
168 g_signal_connect(G_OBJECT(aui
->scroller
), "expose-event", G_CALLBACK(expose_cb
), aui
);
169 g_signal_connect(G_OBJECT(aui
->scroller
), "configure-event", G_CALLBACK(configure_cb
), aui
);
170 gtk_container_add(GTK_CONTAINER(aui
->scrollerbox
), aui
->scroller
);
172 aui
->timeout
= g_timeout_add(50, (GSourceFunc
) showthanks_cb
, aui
);
174 jam_dialog_set_contents(GTK_DIALOG(aui
->win
), mainbox
);
176 gtk_widget_realize(aui
->win
);
177 gtk_widget_realize(aui
->linkwin
);
178 gdk_window_set_cursor(aui
->linkwin
->window
, aui
->cursor
);
179 gtk_widget_show(aui
->win
);