mail-notification

Fork of Jean-Yves Lefort's mail-notification, a tray icon to notify of new mail
git clone https://code.djc.id.au/git/mail-notification/

src/mn-evolution-folder-tree-server.gob (3714B) - raw

      1 /*
      2  * Mail Notification
      3  * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be>
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 3 of the License, or
      8  * (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License along
     16  * with this program; if not, write to the Free Software Foundation, Inc.,
     17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     18  */
     19 
     20 %privateheader{
     21 #include <gtk/gtk.h>
     22 %}
     23 
     24 %{
     25 #include <dbus/dbus.h>
     26 #include <libedataserver/eds-version.h>
     27 #if !EDS_CHECK_VERSION(2,29,0)
     28 #include <mail/mail-component.h>
     29 #endif
     30 #include <mail/em-folder-tree.h>
     31 #include "mn-evolution-plugin.h"
     32 #include "mn-evolution.h"
     33 
     34 #include "mn-evolution-folder-tree-server-dbus.h"
     35 %}
     36 
     37 class MN:Evolution:Folder:Tree:Server from G:Object
     38 {
     39   /* the GdkNativeWindow, which we also use as our ID */
     40   private guint32 id;
     41   property UINT id (flags = CONSTRUCT_ONLY, link);
     42 
     43   private GtkWidget *plug;
     44   private GtkWidget *tree;	/* plug's child, destroyed with it */
     45 
     46   property STRING uri
     47     set
     48     {
     49       em_folder_tree_set_selected(EM_FOLDER_TREE(selfp->tree), g_value_get_string(VAL), FALSE);
     50     };
     51 
     52   signal private NONE (STRING)
     53     void folder_selected (self, const char *uri);
     54 
     55   signal private NONE (NONE)
     56     void folder_activated (self);
     57 
     58   class_init (class)
     59   {
     60     dbus_g_object_type_install_info(TYPE_SELF, &dbus_glib_mn_evolution_folder_tree_server_object_info);
     61   }
     62 
     63   constructor (self)
     64   {
     65 #if EDS_CHECK_VERSION(2,29,0)
     66     selfp->tree = em_folder_tree_new();
     67 #else
     68     EMFolderTreeModel *model;
     69 
     70     model = mail_component_peek_tree_model(mail_component_peek());
     71     selfp->tree = em_folder_tree_new_with_model(model);
     72 #endif
     73 
     74     selfp->plug = gtk_plug_new((GdkNativeWindow) selfp->id);
     75     gtk_container_add(GTK_CONTAINER(selfp->plug), selfp->tree);
     76     gtk_widget_show_all(selfp->plug);
     77 
     78     g_signal_connect(selfp->plug, "destroy", G_CALLBACK(self_plug_destroy_h), self);
     79 
     80     g_object_connect(selfp->tree,
     81 		     "signal::folder-selected", self_selected_h, self,
     82 		     "signal::folder-activated", self_activated_h, self,
     83 		     NULL);
     84   }
     85 
     86   finalize (self)
     87   {
     88     g_signal_handlers_disconnect_by_func(selfp->plug, self_plug_destroy_h, self);
     89   }
     90 
     91   private void
     92     plug_destroy_h (GtkObject *object, gpointer user_data)
     93   {
     94     Self *self = user_data;
     95     char *service;
     96     GError *err = NULL;
     97 
     98     /* the MN side is gone: unregister and unreference the server */
     99 
    100     service = g_strdup_printf(MN_EVOLUTION_FOLDER_TREE_SERVER_SERVICE, selfp->id);
    101     if (! mn_evolution_plugin_unregister_server(service, &err))
    102       {
    103 	g_warning("unable to unregister D-Bus service \"%s\": %s", service, err->message);
    104 	g_error_free(err);
    105       }
    106     g_free(service);
    107 
    108     g_object_unref(self);
    109   }
    110 
    111   private void
    112     selected_h (EMFolderTree *tree,
    113 		const char *full_name,
    114 		const char *uri,
    115 		guint32 flags,
    116 		gpointer user_data)
    117   {
    118     Self *self = user_data;
    119     self_folder_selected(self, uri);
    120   }
    121 
    122   private void
    123     activated_h (EMFolderTree *tree,
    124 		 const char *full_name,
    125 		 const char *uri,
    126 		 gpointer user_data)
    127   {
    128     Self *self = user_data;
    129     self_folder_activated(self);
    130   }
    131 
    132   public MNEvolutionFolderTreeServer *
    133     new (guint32 id)
    134   {
    135     return GET_NEW_VARG(MN_EVOLUTION_FOLDER_TREE_SERVER_PROP_ID(id), NULL);
    136   }
    137 }