summaryrefslogtreecommitdiffstats
path: root/src/newphonebook.cs
blob: 1424977ab27628b6c810c169e5ba14b914f29544 (plain)
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
//  GFAX - Gnome fax application
//  Copyright (C) 2003 - 2008 George A. Farris
//
// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

//************************************************************************
// NewPhoneBook class
//
// A new phone book druid, should make it easier for people to create
// new phone books.  The old way was a little confusing.
//

namespace gfax {
	using Mono.Unix;
	using System;
	using System.IO;
	using GLib;
	using Gtk;
	using Gnome;
	using Glade;
	using GConf.PropertyEditors;
	using GtkSharp;
	using System.Runtime.InteropServices;
	using System.Collections;
	using System.Diagnostics;
	using System.Reflection;
	
	public class NewPhoneBook
	{
		[Glade.Widget] Gtk.Dialog NewPhoneBookDialog;
		[Glade.Widget] Gnome.Druid NewPhoneBookDruid;
    	[Glade.Widget] Gnome.DruidPage EvoDruidPageStandard;
    	[Glade.Widget] Gnome.DruidPage druidpagestandard12;
        [Glade.Widget] Gtk.RadioButton GfaxRadioButton;
        [Glade.Widget] Gtk.RadioButton EvolutionRadioButton;
        [Glade.Widget] Gtk.RadioButton DatabaseRadioButton;
	    [Glade.Widget] Gtk.RadioButton LDAPRadioButton;
	    [Glade.Widget] Gtk.Entry NewPhoneBookNameEntry;
		[Glade.Widget] Gtk.TreeView EvolutionTreeView;
	
		// Properties
		ArrayList booknames;
		string phonebooktype;
		
		Gtk.ListStore store;
		G_ListView view;
	
		const int COLUMN_0 = 0;
		const int COLUMN_1 = 1;
    
		public NewPhoneBook ()
	    {
			booknames = new ArrayList();
    		
			Glade.XML xml = new Glade.XML (null, "gfax.glade","NewPhoneBookDialog",null);
            xml.Autoconnect (this);
    
            GfaxRadioButton.Active = true;
              
	        EvolutionRadioButton.Sensitive = true;
            // turn these off until somewhere near supported
			DatabaseRadioButton.Visible = false;
	        LDAPRadioButton.Visible = false;
			
			store = new ListStore(
				typeof (Boolean),
			typeof (string));
	
			view = new G_ListView(EvolutionTreeView, store);
	
			view.AddColumnTitleToggle(Catalog.GetString("Use"), 0, COLUMN_0);
			view.AddColumnTitle(Catalog.GetString("Phone Book"), 0, COLUMN_1);
	
			EvolutionTreeView.HeadersVisible = true;
		
			NewPhoneBookDruid.ShowAll();
	    }
    
		public ArrayList PhoneBookNames
		{
			get { return booknames; }
		}
	
		public string PhoneBookType
		{
			get { return phonebooktype; }
		}
	
    	public void Run()
    	{
    	    NewPhoneBookDialog.Run();
    	}
          
    	private void on_NewPhoneBookDialog_delete_event (object o, DeleteEventArgs args)
		{
			NewPhoneBookDialog.Hide();
			NewPhoneBookDialog.Dispose();
    	    args.RetVal = true;
    	}

    	private void on_NewPhoneBookDruidEdge_finish (object o, Gnome.FinishClickedArgs args)
        {
	                     
	        if (GfaxRadioButton.Active) {
				phonebooktype = "gfax";
    			booknames.Add( NewPhoneBookNameEntry.Text );
			} else if (EvolutionRadioButton.Active) {
	    	    phonebooktype = "evolution";
					
				Gtk.TreeIter iter = new Gtk.TreeIter();
			
				// Get the first row.
				store.GetIterFirst(out iter);
	
				try {
					if ( (bool)store.GetValue(iter, 0) ) {	// if use is true (toggle set)
						booknames.Add( (string)store.GetValue(iter, 1) );
					}
				} catch (Exception e) {}
			
				// get the rest of the rows			
				while (store.IterNext(ref iter)) {
	
					try {
						if ( (bool)store.GetValue(iter, 0) ) {
							booknames.Add( (string)store.GetValue(iter, 1) );
						}
					}
    				catch (Exception e) {}
    			}
			}
		    else if (DatabaseRadioButton.Active)
                phonebooktype = "sql";
	    	else if (LDAPRadioButton.Active)
	            phonebooktype = "ldap";
			
			NewPhoneBookDialog.Hide();
			NewPhoneBookDialog.Dispose();
    	}
	
	    private void on_NewPhoneBookDruid_cancel (object o, EventArgs args)
	    {
			NewPhoneBookDialog.Hide();
			NewPhoneBookDialog.Dispose();
		}
		
		private void on_druidpagestandard12_next (object o, Gnome.NextClickedArgs args)
		{	
			// we're on the gfax phone book enter name pages
			// skip to finish on next signal
			NewPhoneBookDruid.Page = EvoDruidPageStandard;
		}
		
		
		private void on_BookDruidPageStandard_next (object o, Gnome.NextClickedArgs args)
		{
			// skip next page if active
			if (EvolutionRadioButton.Active) {
				NewPhoneBookDruid.Page = druidpagestandard12;

				EdsPhoneBooks eds = new EdsPhoneBooks();
				ArrayList ebooks = new ArrayList();
				ebooks = eds.GetPhoneBooks();
		
				Gtk.TreeIter iter = new Gtk.TreeIter();
			
				IEnumerator enu = ebooks.GetEnumerator();
	  			while ( enu.MoveNext() ) {
					iter = store.AppendValues(false, enu.Current);
					EvolutionTreeView.Model = store;
				}
			}
		}
	}
}