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-imap-mailbox-properties.gob (7891B) - 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 %headertop{
     21 #include "mn-pi-mailbox-properties.h"
     22 %}
     23 
     24 %privateheader{
     25 #include "mn-imap-mailbox.h"
     26 %}
     27 
     28 %{
     29 #include <glib/gi18n.h>
     30 #include "mn-mailbox-properties.h"
     31 #include "mn-mailbox-properties-private.h"
     32 #include "mn-authenticated-mailbox-properties-private.h"
     33 #include "mn-pi-mailbox-properties-private.h"
     34 #include "mn-auth-combo-box.h"
     35 #include "mn-util.h"
     36 #include "mn-properties-dialog.h"
     37 %}
     38 
     39 class MN:IMAP:Mailbox:Properties from MN:PI:Mailbox:Properties
     40 {
     41   private GtkWidget *inbox_radio;
     42   private GtkWidget *other_radio;
     43   private GtkWidget *mailbox_entry;
     44   private GtkWidget *use_idle_radio[MN_IMAP_MAILBOX_N_USE_IDLE];
     45 
     46   property BOOLEAN complete (override)
     47     get
     48     {
     49       gboolean complete;
     50 
     51       complete = mn_pi_mailbox_properties_is_complete(MN_PI_MAILBOX_PROPERTIES(self));
     52       if (complete)
     53 	{
     54 	  gboolean other_active;
     55 	  const char *mailbox;
     56 
     57 	  other_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio));
     58 	  mailbox = gtk_entry_get_text(GTK_ENTRY(selfp->mailbox_entry));
     59 
     60 	  if (other_active && ! *mailbox)
     61 	    complete = FALSE;
     62 	}
     63 
     64       g_value_set_boolean(VAL, complete);
     65     };
     66 
     67   property STRING default_name (override)
     68     get
     69     {
     70       const char *username;
     71       const char *server;
     72       gboolean other_active;
     73       const char *mailbox;
     74 
     75       mn_authenticated_mailbox_properties_get_contents(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self),
     76 						       &username,
     77 						       NULL);
     78       mn_pi_mailbox_properties_get_contents(MN_PI_MAILBOX_PROPERTIES(self),
     79 					    NULL,
     80 					    NULL,
     81 					    &server,
     82 					    NULL);
     83 
     84       other_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio));
     85       mailbox = gtk_entry_get_text(GTK_ENTRY(selfp->mailbox_entry));
     86 
     87       g_value_take_string(VAL, mn_imap_mailbox_build_name(username, server, other_active ? mailbox : NULL));
     88     };
     89 
     90   class_init (class)
     91   {
     92     MNMailboxPropertiesClass *p_class = MN_MAILBOX_PROPERTIES_CLASS(class);
     93 
     94     p_class->type = "imap";
     95     p_class->combo_label = "IMAP";
     96   }
     97 
     98   init (self)
     99   {
    100     MNMailboxProperties *properties = MN_MAILBOX_PROPERTIES(self);
    101     MNPIMailboxProperties *pi = MN_PI_MAILBOX_PROPERTIES(self);
    102     GtkWidget *hbox;
    103     GtkWidget *folder_vbox;
    104     GtkWidget *idle_section;
    105     GtkWidget *idle_vbox;
    106     int i;
    107 
    108     /* translators: header capitalization */
    109     folder_vbox = mn_mailbox_properties_add_general_section(properties, _("IMAP Mailbox"));
    110 
    111     selfp->inbox_radio = gtk_radio_button_new_with_mnemonic(NULL, _("In_box"));
    112     gtk_size_group_add_widget(properties->label_size_group, selfp->inbox_radio);
    113 
    114     gtk_box_pack_start(GTK_BOX(folder_vbox), selfp->inbox_radio, FALSE, FALSE, 0);
    115 
    116     selfp->other_radio = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(selfp->inbox_radio), _("_Other:"));
    117     gtk_size_group_add_widget(properties->label_size_group, selfp->other_radio);
    118 
    119     selfp->mailbox_entry = gtk_entry_new();
    120     gtk_widget_set_sensitive(selfp->mailbox_entry, FALSE);
    121 
    122     hbox = gtk_hbox_new(FALSE, 12);
    123     gtk_box_pack_start(GTK_BOX(hbox), selfp->other_radio, FALSE, FALSE, 0);
    124     gtk_box_pack_start(GTK_BOX(hbox), selfp->mailbox_entry, TRUE, TRUE, 0);
    125     gtk_box_pack_start(GTK_BOX(folder_vbox), hbox, FALSE, FALSE, 0);
    126     gtk_widget_show_all(folder_vbox);
    127 
    128     /* translators: header capitalization */
    129     idle_section = mn_hig_section_new_with_box(_("Use the IDLE Extension"), NULL, &idle_vbox);
    130     gtk_box_pack_start(GTK_BOX(pi->connection_page), idle_section, FALSE, FALSE, 0);
    131     gtk_widget_show(idle_section);
    132 
    133     self_add_idle_usage(self, GTK_BOX(idle_vbox), MN_IMAP_MAILBOX_USE_IDLE_NEVER, Q_("IMAP connection tab|_Never"));
    134     self_add_idle_usage(self, GTK_BOX(idle_vbox), MN_IMAP_MAILBOX_USE_IDLE_AUTODETECT, _("A_utodetect"));
    135     self_add_idle_usage(self, GTK_BOX(idle_vbox), MN_IMAP_MAILBOX_USE_IDLE_ALWAYS, _("Al_ways"));
    136 
    137     /* by default, autodetect is enabled */
    138     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->use_idle_radio[MN_IMAP_MAILBOX_USE_IDLE_AUTODETECT]), TRUE);
    139 
    140     mn_auth_combo_box_append(MN_AUTH_COMBO_BOX(pi->auth_combo), "+LOGIN", "IMAP LOGIN");
    141 
    142     for (i = 0; i < MN_PI_MAILBOX_N_CONNECTION_TYPES; i++)
    143       gtk_spin_button_set_value(GTK_SPIN_BUTTON(pi->port_spin[i]), mn_imap_mailbox_default_ports[i]);
    144 
    145     properties->entries = g_slist_append(properties->entries, selfp->mailbox_entry);
    146 
    147     g_signal_connect(selfp->inbox_radio, "toggled", G_CALLBACK(self_radio_toggled_h), self);
    148     g_signal_connect(selfp->other_radio, "toggled", G_CALLBACK(self_radio_toggled_h), self);
    149 
    150     g_object_connect(selfp->mailbox_entry,
    151 		     "swapped-signal::changed", mn_mailbox_properties_notify_complete, self,
    152 		     "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self,
    153 		     NULL);
    154   }
    155 
    156   private void
    157     add_idle_usage (self,
    158 		    Gtk:Box *idle_vbox (check null),
    159 		    MNIMAPMailboxUseIDLE usage,
    160 		    const char *mnemonic (check null))
    161   {
    162     selfp->use_idle_radio[usage] = usage == 0
    163       ? gtk_radio_button_new_with_mnemonic(NULL, mnemonic)
    164       : gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(selfp->use_idle_radio[0]), mnemonic);
    165 
    166     gtk_box_pack_start(idle_vbox, selfp->use_idle_radio[usage], TRUE, TRUE, 0);
    167     gtk_widget_show(selfp->use_idle_radio[usage]);
    168   }
    169 
    170   private void
    171     radio_toggled_h (GtkToggleButton *togglebutton, gpointer user_data)
    172   {
    173     Self *self = user_data;
    174 
    175     gtk_widget_set_sensitive(selfp->mailbox_entry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio)));
    176 
    177     g_object_notify(G_OBJECT(self), "complete");
    178     g_object_notify(G_OBJECT(self), "default-name");
    179   }
    180 
    181   override (MN:Mailbox:Properties) void
    182     set_mailbox (MNMailboxProperties *properties, MNMailbox *mailbox)
    183   {
    184     Self *self = SELF(properties);
    185     MNIMAPMailbox *imap_mailbox = MN_IMAP_MAILBOX(mailbox);
    186 
    187     PARENT_HANDLER(properties, mailbox);
    188 
    189     if (! mn_utf8_strcasecmp(imap_mailbox->mailbox, "INBOX"))
    190       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->inbox_radio), TRUE);
    191     else
    192       {
    193 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->other_radio), TRUE);
    194 	gtk_entry_set_text(GTK_ENTRY(selfp->mailbox_entry), imap_mailbox->mailbox);
    195       }
    196 
    197     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->use_idle_radio[imap_mailbox->use_idle_extension]), TRUE);
    198   }
    199 
    200   override (MN:Mailbox:Properties) MNMailbox *
    201     get_mailbox (MNMailboxProperties *properties)
    202   {
    203     Self *self = SELF(properties);
    204     MNIMAPMailboxUseIDLE use_idle;
    205     MNMailbox *mailbox;
    206 
    207     mailbox = PARENT_HANDLER(properties);
    208 
    209     for (use_idle = 0; use_idle < MN_IMAP_MAILBOX_N_USE_IDLE; use_idle++)
    210       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->use_idle_radio[use_idle])))
    211 	break;
    212 
    213     g_object_set(mailbox, MN_IMAP_MAILBOX_PROP_USE_IDLE_EXTENSION(use_idle), NULL);
    214 
    215     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio)))
    216       g_object_set(mailbox, MN_IMAP_MAILBOX_PROP_MAILBOX((char *) gtk_entry_get_text(GTK_ENTRY(selfp->mailbox_entry))), NULL);
    217 
    218     return mailbox;
    219   }
    220 }