~ubuntu-branches/ubuntu/karmic/gtwitter/karmic

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
using System;
using System.IO;
using System.Diagnostics;
using Gtk;
using GConf;
using Gnome;
using Mono.Unix;

namespace gtwitter
{
	
	public partial class PreferencesWindow : Gtk.Dialog
	{
		public PreferencesWindow()
		{
			this.Build();
			
			//read from gconf
			UpdateFromGConf();
			MainWindow.client.AddNotify (MainWindow.GCONF_APP_PATH, new NotifyEventHandler (GConf_Changed));
			
			//notifications | sensitivity
			//notifications toggled event
			EnableNotifyCheckButton.Toggled += new EventHandler(this.EnableNotifyCheckButtonToggled);
			
			if (EnableNotifyCheckButton.Active == true)
			{
				NotifyOnDirect.Sensitive = true;
				NotifyOnPublicFriends.Sensitive = true;
				NotifyOnBoth.Sensitive = true;
			}
			
		}
		
		//gconf update
		void UpdateFromGConf () {
			
			try {
				
				SourceCombobox.Active = (int) MainWindow.client.Get (MainWindow.SOURCE_KEY);
				
				UsernameEntry.Text = (string) MainWindow.client.Get (MainWindow.USERNAME_KEY);
				PasswordEntry.Text = (string) MainWindow.client.Get (MainWindow.PASSWORD_KEY);
				
				RefreshCombobox.Active = (int) MainWindow.client.Get (MainWindow.REFRESH_KEY);
				
				HiddenCheckbutton.Active = (bool) MainWindow.client.Get (MainWindow.HIDDEN_KEY);
				
				//Notification options
				EnableNotifyCheckButton.Active = (bool) MainWindow.client.Get (MainWindow.NOTIFY_KEY);
				NotifyOnDirect.Active = (bool) MainWindow.client.Get (MainWindow.NOTIFY_DIRECT_KEY);
				NotifyOnPublicFriends.Active = (bool) MainWindow.client.Get (MainWindow.NOTIFY_PUBFRIE_KEY);
				NotifyOnBoth.Active = (bool) MainWindow.client.Get (MainWindow.NOTIFY_ALL_KEY);
			}
			catch (Exception ex)
			{
				if (MainClass.debug) {
					Console.WriteLine("Preferences Window GConf exception: PreferencesWindow.cs - UpdateFromGConf()");
					Console.WriteLine(ex.StackTrace);
				}
			}
			
		}
		public void GConf_Changed (object sender, NotifyEventArgs args) {
			
			UpdateFromGConf();
		}
		
		//ok button
		protected virtual void OnOkButtonClicked(object sender, System.EventArgs e)
		{
			MainWindow.client.Set (MainWindow.SOURCE_KEY, SourceCombobox.Active);
			
			MainWindow.client.Set (MainWindow.USERNAME_KEY, UsernameEntry.Text);
			MainWindow.client.Set (MainWindow.PASSWORD_KEY, PasswordEntry.Text);
			
			MainWindow.client.Set (MainWindow.REFRESH_KEY, RefreshCombobox.Active);
			
			MainWindow.client.Set (MainWindow.HIDDEN_KEY, HiddenCheckbutton.Active);
			
			//notifications
			MainWindow.client.Set (MainWindow.NOTIFY_KEY, EnableNotifyCheckButton.Active);
			MainWindow.client.Set (MainWindow.NOTIFY_DIRECT_KEY, NotifyOnDirect.Active);
			MainWindow.client.Set (MainWindow.NOTIFY_PUBFRIE_KEY, NotifyOnPublicFriends.Active);
			MainWindow.client.Set (MainWindow.NOTIFY_ALL_KEY, NotifyOnBoth.Active);
			
			ClearCacheLabel.Text = "";

			this.Hide();
		}
		
		protected virtual void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
		{
			ClearCacheLabel.Text = "";
			
			this.Hide();
			args.RetVal = true;
		}

		protected virtual void OnClearCacheButtonClicked(object sender, System.EventArgs e)
		{
			Directory.Delete(gtwitter.MainWindow.configDir + "images/", true);
			
			Directory.CreateDirectory(gtwitter.MainWindow.configDir + "images");
			
			ClearCacheLabel.Text = Catalog.GetString("Done!");
		}

		// call the GNOME Default browser to open the Twitter.com signup url
		protected virtual void OnSignUpClicked(object sender, System.EventArgs e)
		{
			Gnome.Url.Show ("http://twitter.com/signup");
		}
		
		//Toggle notifications event
		protected virtual void EnableNotifyCheckButtonToggled(object sender, System.EventArgs e)
		{
			if(EnableNotifyCheckButton.Active == true)
			{
				MainWindow.client.Set (MainWindow.NOTIFY_KEY, EnableNotifyCheckButton.Active);
				
				NotifyOnDirect.Sensitive = true;
				NotifyOnPublicFriends.Sensitive = true;
				NotifyOnBoth.Sensitive = true;
			}
			else
			{
				MainWindow.client.Set (MainWindow.NOTIFY_KEY, EnableNotifyCheckButton.Active);
				
				NotifyOnDirect.Sensitive = false;
				NotifyOnPublicFriends.Sensitive = false;
				NotifyOnBoth.Sensitive = false;
			}
		}

	}
}

//ghaefb