1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/*
* Size adjustment code (size_allocate_h(), find_icon_size()) taken
* from GtkStatusIcon,
* Copyright (C) 2003 Sun Microsystems, Inc.
* Copyright (C) 2005 Hans Breuer <hans@breuer.org>
* Copyright (C) 2005 Novell, Inc.
*
* Mail Notification
* Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
%headertop{
#include <gtk/gtk.h>
#include "eggtrayicon.h"
%}
%privateheader{
#include "mn-tooltips.h"
%}
%{
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include "mn-stock.h"
#include "mn-util.h"
#include "mn-mail-icon-widget.h"
%}
class MN:Mail:Icon from Egg:Tray:Icon
{
private MNTooltips *tooltips = {mn_tooltips_new()} unrefwith g_object_unref;
private GtkWidget *widget = {mn_mail_icon_widget_new()};
private char *stock_id destroywith g_free;
private int size;
private GtkWidget *menu = {gtk_menu_new()} destroywith gtk_widget_destroy;
public GtkWidget *mail_reader_item;
public GtkWidget *open_latest_message_item;
public GtkWidget *update_item;
public GtkWidget *consider_new_mail_as_read_item;
signal (ACTION) private NONE (NONE)
void activate (self);
signal (ACTION) private NONE (NONE)
void activate_mail_reader (self);
signal (ACTION) private NONE (NONE)
void activate_open_latest_message (self);
signal (ACTION) private NONE (NONE)
void activate_consider_new_mail_as_read (self);
signal (ACTION) private NONE (NONE)
void activate_update (self);
signal (ACTION) private NONE (NONE)
void activate_properties (self);
signal (ACTION) private NONE (NONE)
void activate_help (self);
signal (ACTION) private NONE (NONE)
void activate_about (self);
signal (ACTION) private NONE (NONE)
void activate_remove (self);
init (self)
{
GtkMenuShell *shell;
GtkWidget *properties_item;
GtkWidget *help_item;
GtkWidget *about_item;
GtkWidget *remove_item;
shell = GTK_MENU_SHELL(selfp->menu);
/* translators: header capitalization */
self->mail_reader_item = mn_menu_shell_append(shell, MN_STOCK_MAIL_READER, _("_Mail Reader"));
/* translators: header capitalization */
self->open_latest_message_item = mn_menu_shell_append(shell, MN_STOCK_OPEN_MESSAGE, _("_Open Latest Message"));
mn_menu_shell_append(shell, NULL, NULL);
/* translators: header capitalization */
self->consider_new_mail_as_read_item = mn_menu_shell_append(shell, MN_STOCK_CONSIDER_NEW_MAIL_AS_READ, _("_Consider New Mail as Read"));
/* translators: header capitalization */
self->update_item = mn_menu_shell_append(shell, GTK_STOCK_REFRESH, _("_Update"));
mn_menu_shell_append(shell, NULL, NULL);
properties_item = mn_menu_shell_append(shell, GTK_STOCK_PROPERTIES, NULL);
help_item = mn_menu_shell_append(shell, GTK_STOCK_HELP, NULL);
about_item = mn_menu_shell_append(shell, GTK_STOCK_ABOUT, NULL);
mn_menu_shell_append(shell, NULL, NULL);
/* translators: header capitalization */
remove_item = mn_menu_shell_append(shell, GTK_STOCK_REMOVE, _("R_emove From Notification Area"));
g_signal_connect_swapped(self->mail_reader_item, "activate", G_CALLBACK(self_activate_mail_reader), self);
g_signal_connect_swapped(self->open_latest_message_item, "activate", G_CALLBACK(self_activate_open_latest_message), self);
g_signal_connect_swapped(self->consider_new_mail_as_read_item, "activate", G_CALLBACK(self_activate_consider_new_mail_as_read), self);
g_signal_connect_swapped(self->update_item, "activate", G_CALLBACK(self_activate_update), self);
g_signal_connect_swapped(properties_item, "activate", G_CALLBACK(self_activate_properties), self);
g_signal_connect_swapped(help_item, "activate", G_CALLBACK(self_activate_help), self);
g_signal_connect_swapped(about_item, "activate", G_CALLBACK(self_activate_about), self);
g_signal_connect_swapped(remove_item, "activate", G_CALLBACK(self_activate_remove), self);
gtk_widget_add_events(GTK_WIDGET(self), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
gtk_container_add(GTK_CONTAINER(self), selfp->widget);
g_object_connect(self,
"signal::button-press-event", self_button_press_event_h, self,
"signal::button-release-event", self_button_release_event_h, self,
NULL);
g_signal_connect(selfp->widget, "size-allocate", G_CALLBACK(self_size_allocate_h), self);
gtk_widget_show(selfp->widget);
}
private void
size_allocate_h (GtkWidget *widget,
GtkAllocation *allocation,
gpointer user_data)
{
Self *self = user_data;
GtkOrientation orientation;
int size;
orientation = egg_tray_icon_get_orientation(EGG_TRAY_ICON(self));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
size = allocation->height;
else
size = allocation->width;
if (selfp->size != size)
{
selfp->size = size;
self_update_image(self);
}
}
private GtkIconSize
find_icon_size (Gtk:Widget *widget (check null type), int pixel_size)
{
GdkScreen *screen;
GtkSettings *settings;
GtkIconSize s, size;
int w, h, d, dist;
screen = gtk_widget_get_screen(widget);
if (! screen)
return GTK_ICON_SIZE_MENU;
settings = gtk_settings_get_for_screen(screen);
dist = G_MAXINT;
size = GTK_ICON_SIZE_MENU;
for (s = GTK_ICON_SIZE_MENU; s < GTK_ICON_SIZE_DIALOG; s++)
{
if (gtk_icon_size_lookup_for_settings(settings, s, &w, &h)
&& w <= pixel_size
&& h <= pixel_size)
{
d = MAX(pixel_size - w, pixel_size - h);
if (d < dist)
{
dist = d;
size = s;
}
}
}
return size;
}
private void
update_image (self)
{
GtkIconSize size;
size = self_find_icon_size(selfp->widget, selfp->size);
mn_mail_icon_widget_set_from_stock(MN_MAIL_ICON_WIDGET(selfp->widget), selfp->stock_id, size);
}
private gboolean
button_press_event_h (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
Self *self = user_data;
if (event->button == 1)
self_activate(self);
else if (event->button == 3)
{
gtk_menu_popup(GTK_MENU(selfp->menu), NULL, NULL, self_popup_menu_position_cb, self, event->button, event->time);
return TRUE; /* do not propagate event */
}
return FALSE; /* propagate event */
}
private gboolean
button_release_event_h (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
Self *self = user_data;
if (event->button == 3)
{
gtk_menu_popdown(GTK_MENU(selfp->menu));
return TRUE; /* do not propagate event */
}
return FALSE; /* propagate event */
}
private void
popup_menu_position_cb (GtkMenu *menu,
int *x,
int *y,
gboolean *push_in,
gpointer user_data)
{
GtkWidget *widget = user_data;
GtkAllocation allocation;
gdk_window_get_origin(gtk_widget_get_window(widget), x, y);
gtk_widget_get_allocation(widget, &allocation);
*x += allocation.x;
*y += allocation.y;
if (*y > gdk_screen_get_height(gtk_widget_get_screen(widget)) / 2)
{
GtkRequisition req;
gtk_widget_size_request(GTK_WIDGET(menu), &req);
*y -= req.height;
}
else
*y += allocation.height;
*push_in = TRUE;
}
public void
set_from_stock (self, const char *stock_id)
{
g_free(selfp->stock_id);
selfp->stock_id = g_strdup(stock_id);
self_update_image(self);
}
public void
set_blinking (self, gboolean blinking)
{
mn_mail_icon_widget_set_blinking(MN_MAIL_ICON_WIDGET(selfp->widget), blinking);
}
public void
set_count (self, int count)
{
mn_mail_icon_widget_set_count(MN_MAIL_ICON_WIDGET(selfp->widget), count);
}
public void
set_tip (self, const char *tip)
{
mn_tooltips_set_tip(selfp->tooltips, GTK_WIDGET(self), tip);
}
public void
set_tip_widget (self, Gtk:Widget *tip_widget)
{
mn_tooltips_set_tip_widget(selfp->tooltips, GTK_WIDGET(self), tip_widget);
}
public GtkWidget *
new (void)
{
return GTK_WIDGET(GET_NEW_VARG("title", _("Mail Notification"), NULL));
}
}
|