respect https prefix
[k8lowj.git] / src / docklet.c
blobf529eda109690f31d1acada16ee5ba98a0e9845e
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
3 */
4 #include "gtk-all.h"
6 #include "about.h"
7 #include "conf.h"
8 #include "eggtrayicon.h"
9 #include "jam.h"
10 #include "menu.h"
11 #include "settings.h"
14 static void docklet_destroy_cb (GtkWidget *widget) {
15 app.docklet = NULL;
19 static void docklet_menu (GtkWidget *win) {
20 static GtkWidget *menu = NULL;
21 GtkWidget *menuitem;
22 GtkWidget *image;
23 if (menu) gtk_widget_destroy(menu);
24 menu = gtk_menu_new();
26 /* About... */
27 menuitem = gtk_image_menu_item_new_with_mnemonic(_("About LogJam..."));
28 image = gtk_image_new_from_stock("logjam-goat", GTK_ICON_SIZE_MENU);
29 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
30 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
31 g_signal_connect_swapped(G_OBJECT(menuitem), "activate", G_CALLBACK(about_dlg), win);
32 gtk_widget_show_all(menuitem);
35 /* Friends... */
36 menuitem = gtk_menu_item_new_with_mnemonic(_("Friends..."));
37 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
38 g_signal_connect_swapped(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_friends_manager), win);
39 gtk_widget_show_all(menuitem);
42 /* Preferences... */
43 menuitem = gtk_image_menu_item_new_with_mnemonic(_("Preferences..."));
44 image = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU);
45 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
46 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
47 g_signal_connect_swapped(G_OBJECT(menuitem), "activate", G_CALLBACK(settings_run), win);
48 gtk_widget_show_all(menuitem);
51 /* -------------- */
52 menuitem = gtk_separator_menu_item_new();
53 gtk_widget_show(menuitem);
54 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
57 /* Quit */
58 menuitem = gtk_image_menu_item_new_with_mnemonic(_("Quit"));
59 image = gtk_image_new_from_stock(GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU);
60 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
61 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
62 g_signal_connect_swapped(G_OBJECT(menuitem), "activate", G_CALLBACK(jam_quit), win);
63 gtk_widget_show_all(menuitem);
65 gtk_widget_show_all(menu);
66 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL/*ui_ops->position_menu */, NULL, 0, gtk_get_current_event_time());
70 static gboolean click_cb (GtkWidget *w, GdkEventButton *ev, GtkWidget *win) {
71 /* right-clicks start context menu (note: this case is terminal) */
72 if (ev->button == 3) {
73 docklet_menu(win);
74 return TRUE;
76 if (GTK_WIDGET_VISIBLE(win)) gtk_widget_hide(win); else gtk_widget_show(win);
77 #if 0
78 /* *all* left-clicks move CF_NEW to CF_ON */
79 if (cfm->state == CF_NEW) cfmgr_set_state(cfm, CF_ON);
80 /* and double-clicks open up the browser, too */
81 if (ev->type == GDK_2BUTTON_PRESS) {
82 open_friends_list(GTK_WINDOW(cfi->parent));
83 return TRUE;
85 /* this help box will only be called once in a double-click,
86 * thankfully, because the above is terminal on double-clicks. */
87 if (cfm->state == CF_DISABLED) jam_message(GTK_WINDOW(cfi->parent), JAM_MSG_INFO, TRUE, _("Check Friends"), _(cf_help));
88 #endif
89 return TRUE;
93 void docklet_setup (GtkWidget *win) {
94 EggTrayIcon *docklet;
95 GtkWidget *box, *image;
97 image = gtk_image_new();
98 gtk_image_set_from_stock(GTK_IMAGE(image), "logjam-goat", GTK_ICON_SIZE_MENU);
100 box = gtk_event_box_new();
101 gtk_tooltips_set_tip(app.tooltips, box, _("LogJam"), _("LogJam"));
102 gtk_container_set_border_width(GTK_CONTAINER(box), 3);
103 gtk_container_add(GTK_CONTAINER(box), image);
105 docklet = egg_tray_icon_new("LogJam");
107 /* This could be used to tell the calling app that the docklet has been
108 * successfully embedded into a dock :
109 * g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(cf_docklet_embedded), NULL); */
110 g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_destroy_cb), NULL);
111 g_signal_connect(G_OBJECT(box), "button_press_event", G_CALLBACK(click_cb), win);
113 gtk_container_add(GTK_CONTAINER(docklet), box);
114 gtk_widget_show_all(GTK_WIDGET(docklet));
116 app.docklet = docklet;
120 void docklet_enable (GtkWidget *win, gboolean enable) {
121 if ((enable == TRUE) == (app.docklet != NULL)) return;
122 if (enable) docklet_setup(win); else gtk_widget_destroy(app.docklet);