File: mn-webmail-mailbox-properties.gob

package info (click to toggle)
mail-notification 5.4.dfsg.1-14
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,468 kB
  • ctags: 9,615
  • sloc: ansic: 13,970; sh: 2,770; xml: 2,113; makefile: 57
file content (172 lines) | stat: -rw-r--r-- 6,145 bytes parent folder | download | duplicates (4)
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
/*
 * 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 "mn-authenticated-mailbox-properties.h"
%}

%{
#include <glib/gi18n.h>
#include "mn-webmail-mailbox.h"
#include "mn-mailbox-properties-private.h"
#include "mn-authenticated-mailbox-properties-private.h"
#include "mn-util.h"
%}

class MN:Webmail:Mailbox:Properties from MN:Authenticated:Mailbox:Properties (abstract)
{
  private GtkWidget *inbox_radio;
  private GtkWidget *other_radio;
  private GtkWidget *folder_entry;

  property BOOLEAN complete (override)
    get
    {
      gboolean complete;

      complete = mn_authenticated_mailbox_properties_is_complete(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self));
      if (complete)
	{
	  gboolean other_active;
	  const char *folder;

	  other_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio));
	  folder = gtk_entry_get_text(GTK_ENTRY(selfp->folder_entry));

	  if (other_active && ! *folder)
	    complete = FALSE;
	}

      g_value_set_boolean(VAL, complete);
    };

  property STRING default_name (override)
    get
    {
      const char *username;
      gboolean other_active;
      const char *folder;
      MNMailboxClass *class;

      username = gtk_entry_get_text(GTK_ENTRY(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self)->username_entry));
      g_assert(*username != 0);

      other_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio));
      folder = gtk_entry_get_text(GTK_ENTRY(selfp->folder_entry));

      class = mn_mailbox_get_class_from_name(MN_MAILBOX_PROPERTIES_CLASS(SELF_GET_CLASS(self))->type);
      g_value_take_string(VAL, mn_webmail_mailbox_build_name(MN_WEBMAIL_MAILBOX_CLASS(class),
							     username,
							     other_active ? folder : NULL));
      g_type_class_unref(class);
    };

  init (self)
  {
    MNMailboxProperties *properties = MN_MAILBOX_PROPERTIES(self);
    MNAuthenticatedMailboxProperties *auth = MN_AUTHENTICATED_MAILBOX_PROPERTIES(self);
    GtkWidget *folder_vbox;
    GtkWidget *hbox;

    gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->username_vbox, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->password_vbox, FALSE, FALSE, 0);

    /* translators: header capitalization */
    folder_vbox = mn_mailbox_properties_add_general_section(properties, _("Folder"));

    selfp->inbox_radio = gtk_radio_button_new_with_mnemonic(NULL, _("In_box"));
    gtk_size_group_add_widget(properties->label_size_group, selfp->inbox_radio);

    gtk_box_pack_start(GTK_BOX(folder_vbox), selfp->inbox_radio, FALSE, FALSE, 0);

    selfp->other_radio = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(selfp->inbox_radio), _("_Other:"));
    gtk_size_group_add_widget(properties->label_size_group, selfp->other_radio);

    selfp->folder_entry = gtk_entry_new();
    gtk_widget_set_sensitive(selfp->folder_entry, FALSE);

    hbox = gtk_hbox_new(FALSE, 12);
    gtk_box_pack_start(GTK_BOX(hbox), selfp->other_radio, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(hbox), selfp->folder_entry, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(folder_vbox), hbox, FALSE, FALSE, 0);
    gtk_widget_show_all(folder_vbox);

    properties->entries = mn_g_slist_append_elements(properties->entries,
						     auth->username_entry,
						     auth->password_entry,
						     selfp->folder_entry,
						     NULL);

    g_signal_connect(selfp->inbox_radio, "toggled", G_CALLBACK(self_radio_toggled_h), self);
    g_signal_connect(selfp->other_radio, "toggled", G_CALLBACK(self_radio_toggled_h), self);

    g_object_connect(auth->username_entry,
		     "swapped-signal::changed", mn_mailbox_properties_notify_complete, self,
		     "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self,
		     NULL);

    g_object_connect(selfp->folder_entry,
		     "swapped-signal::changed", mn_mailbox_properties_notify_complete, self,
		     "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self,
		     NULL);
  }

  private void
    radio_toggled_h (GtkToggleButton *togglebutton, gpointer user_data)
  {
    Self *self = user_data;

    gtk_widget_set_sensitive(selfp->folder_entry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio)));

    g_object_notify(G_OBJECT(self), "complete");
    g_object_notify(G_OBJECT(self), "default-name");
  }

  override (MN:Mailbox:Properties) void
    set_mailbox (MNMailboxProperties *properties, MNMailbox *mailbox)
  {
    Self *self = SELF(properties);
    MNWebmailMailbox *webmail_mailbox = MN_WEBMAIL_MAILBOX(mailbox);

    PARENT_HANDLER(properties, mailbox);

    if (! strcmp(webmail_mailbox->folder, "Inbox"))
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->inbox_radio), TRUE);
    else
      {
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->other_radio), TRUE);
	gtk_entry_set_text(GTK_ENTRY(selfp->folder_entry), webmail_mailbox->folder);
      }
  }

  override (MN:Mailbox:Properties) MNMailbox *
    get_mailbox (MNMailboxProperties *properties)
  {
    Self *self = SELF(properties);
    MNMailbox *mailbox;

    mailbox = PARENT_HANDLER(properties);

    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio)))
      g_object_set(mailbox, MN_WEBMAIL_MAILBOX_PROP_FOLDER((char *) gtk_entry_get_text(GTK_ENTRY(selfp->folder_entry))), NULL);

    return mailbox;
  }
}