2005-10-03 [colin] 1.9.15cvs1
[claws.git] / src / plugins / trayicon / trayicon.c
index c7add0aff50f3b7218ef9c57506e4d7074617efc..9d6ea5bbfc80ad15f8007bcd821bf823ae98cefa 100644 (file)
@@ -14,7 +14,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -24,6 +24,7 @@
 #include <stdio.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include "common/sylpheed.h"
 #include "folder.h"
 #include "mainwindow.h"
 #include "gtkutils.h"
-#include "intl.h"
 #include "menu.h"
 #include "toolbar.h"
 #include "prefs_common.h"
 #include "main.h"
 #include "alertpanel.h"
+#include "gtk/manage_window.h"
 
 #include "eggtrayicon.h"
+#include "newmarkedmail.xpm"
+#include "unreadmarkedmail.xpm"
 #include "newmail.xpm"
 #include "unreadmail.xpm"
 #include "nomail.xpm"
@@ -52,6 +55,10 @@ static GdkPixmap *newmail_pixmap;
 static GdkPixmap *newmail_bitmap;
 static GdkPixmap *unreadmail_pixmap;
 static GdkPixmap *unreadmail_bitmap;
+static GdkPixmap *newmarkedmail_pixmap;
+static GdkPixmap *newmarkedmail_bitmap;
+static GdkPixmap *unreadmarkedmail_pixmap;
+static GdkPixmap *unreadmarkedmail_bitmap;
 static GdkPixmap *nomail_pixmap;
 static GdkPixmap *nomail_bitmap;
 
@@ -66,9 +73,10 @@ guint destroy_signal_id;
 typedef enum
 {
        TRAYICON_NEW,
+       TRAYICON_NEWMARKED,
        TRAYICON_UNREAD,
        TRAYICON_UNREADMARKED,
-       TRAYICON_NOTHING,
+       TRAYICON_NOTHING
 } TrayIconType;
 
 static void trayicon_get_cb        (gpointer data, guint action, GtkWidget *widget);
@@ -93,40 +101,61 @@ static void set_trayicon_pixmap(TrayIconType icontype)
 {
        GdkPixmap *pixmap = NULL;
        GdkBitmap *bitmap = NULL;
+       static GdkPixmap *last_pixmap = NULL;
 
        switch(icontype) {
        case TRAYICON_NEW:
                pixmap = newmail_pixmap;
                bitmap = newmail_bitmap;
                break;
+       case TRAYICON_NEWMARKED:
+               pixmap = newmarkedmail_pixmap;
+               bitmap = newmarkedmail_bitmap;
+               break;
        case TRAYICON_UNREAD:
-       case TRAYICON_UNREADMARKED:
                pixmap = unreadmail_pixmap;
                bitmap = unreadmail_bitmap;
                break;
+       case TRAYICON_UNREADMARKED:
+               pixmap = unreadmarkedmail_pixmap;
+               bitmap = unreadmarkedmail_bitmap;
+               break;
        default:
                pixmap = nomail_pixmap;
                bitmap = nomail_bitmap;
                break;
        }
 
+       if (pixmap == last_pixmap)
+               return;
+
        gtk_image_set_from_pixmap(GTK_IMAGE(image), pixmap, bitmap);
-       gtk_widget_shape_combine_mask(GTK_WIDGET(trayicon), bitmap, GTK_WIDGET(image)->allocation.x, GTK_WIDGET(image)->allocation.y);
 
+       last_pixmap = pixmap;
 }
 
 static void update(void)
 {
-       gint new, unread, unreadmarked, total;
+       guint new, unread, unreadmarked, marked, total;
        gchar *buf;
+       TrayIconType icontype = TRAYICON_NOTHING;
 
-       folder_count_total_msgs(&new, &unread, &unreadmarked, &total);
-       buf = g_strdup_printf("New %d, Unread: %d, Total: %d", new, unread, total);
+       folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total);
+       buf = g_strdup_printf(_("New %d, Unread: %d, Total: %d"), new, unread, total);
 
         gtk_tooltips_set_tip(tooltips, eventbox, buf, "");
        g_free(buf);
-
-       set_trayicon_pixmap(new > 0 ? TRAYICON_NEW : (unread > 0 ? TRAYICON_UNREAD : TRAYICON_NOTHING));
+       
+       if (new > 0 && unreadmarked > 0)
+               icontype = TRAYICON_NEWMARKED;
+       else if (new > 0)
+               icontype = TRAYICON_NEW;
+       else if (unreadmarked > 0)
+               icontype = TRAYICON_UNREADMARKED;
+       else if (unread > 0)
+               icontype = TRAYICON_UNREAD;
+
+       set_trayicon_pixmap(icontype);
 }
 
 static gboolean folder_item_update_hook(gpointer source, gpointer data)
@@ -195,6 +224,8 @@ static void create_trayicon()
         PIXMAP_CREATE(GTK_WIDGET(trayicon), nomail_pixmap, nomail_bitmap, nomail_xpm);
         PIXMAP_CREATE(GTK_WIDGET(trayicon), unreadmail_pixmap, unreadmail_bitmap, unreadmail_xpm);
         PIXMAP_CREATE(GTK_WIDGET(trayicon), newmail_pixmap, newmail_bitmap, newmail_xpm);
+        PIXMAP_CREATE(GTK_WIDGET(trayicon), unreadmarkedmail_pixmap, unreadmarkedmail_bitmap, unreadmarkedmail_xpm);
+        PIXMAP_CREATE(GTK_WIDGET(trayicon), newmarkedmail_pixmap, newmarkedmail_bitmap, newmarkedmail_xpm);
 
         eventbox = gtk_event_box_new();
         gtk_container_set_border_width(GTK_CONTAINER(eventbox), 0);
@@ -309,7 +340,7 @@ static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        if (prefs_common.confirm_on_exit) {
                if (alertpanel(_("Exit"), _("Exit this program?"),
-                              _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
+                              GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL) != G_ALERTDEFAULT)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }