File: Pref_ReadAhead.m

package info (click to toggle)
lusernet.app 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 828 kB
  • sloc: objc: 8,495; makefile: 22
file content (235 lines) | stat: -rw-r--r-- 4,768 bytes parent folder | download | duplicates (2)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
copyright 2002 Alexander Malmberg <alexander@malmberg.org>
*/

#include <Foundation/NSObject.h>
#include <Foundation/NSString.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSBundle.h>
#include <AppKit/NSButton.h>
#include <AppKit/NSTextField.h>
#include <GNUstepGUI/GSVbox.h>
#include <GNUstepGUI/GSHbox.h>
#include <AppKit/NSBox.h>

#include "Pref_ReadAhead.h"


#define ReadAheadKey @"ReadAhead"
#define ReadAheadSizeLimitKey @"ReadAheadSizeLimit"

#define ReadAheadNextKey @"ReadAheadNext"
#define ReadAheadPreviousKey @"ReadAheadPrevious"
#define ReadAheadNextThreadKey @"ReadAheadNextThread"
#define ReadAheadNextUnreadKey @"ReadAheadNextUnread"

static NSUserDefaults *sd;


@implementation Pref_ReadAhead

+(void) initialize
{
	if (!sd)
		sd=[NSUserDefaults standardUserDefaults];
}

+(int) readAheadSizeLimit
{
	if ([sd objectForKey: ReadAheadSizeLimitKey])
		return [sd integerForKey: ReadAheadSizeLimitKey];
	else
		return 16*1024;
}

/*
The underscores in the names are ugly, but gcc 2.95.3 doesn't accept
eg. 'RA_GET_BOOL()'.
*/
#define readAhead_ readAhead
#define ReadAhead_Key ReadAheadKey
#define b_ReadAhead_ b_ReadAhead

#define RA_GET_BOOL(x) \
	+(BOOL) readAhead##x \
	{ \
		if (![sd objectForKey: ReadAhead##x##Key] || \
		    [sd boolForKey: ReadAhead##x##Key]) \
			return YES; \
		else \
			return NO; \
	}

RA_GET_BOOL(_)

RA_GET_BOOL(NextUnread)
RA_GET_BOOL(NextThread)
RA_GET_BOOL(Next)
RA_GET_BOOL(Previous)

#undef RA_GET_BOOL

-(void) save
{
	NSUserDefaults *sd=[NSUserDefaults standardUserDefaults];
	BOOL b;

	if (!top) return;

#define SAVE_BOOL(x) \
	b=[b_ReadAhead##x state]?YES:NO; \
	[sd setBool: b forKey: ReadAhead##x##Key];

	SAVE_BOOL(_)

	SAVE_BOOL(NextUnread)
	SAVE_BOOL(NextThread)
	SAVE_BOOL(Next)
	SAVE_BOOL(Previous)

#undef SAVE_BOOL

	[sd setInteger: [f_ReadAheadSizeLimit intValue] forKey: ReadAheadSizeLimitKey];
}

-(void) revert
{
#define REVERT_BOOL(x) \
	if ([Pref_ReadAhead readAhead##x]) \
		[b_ReadAhead##x setState: 1]; \
	else \
		[b_ReadAhead##x setState: 0];

	REVERT_BOOL(_)

	REVERT_BOOL(NextUnread)
	REVERT_BOOL(NextThread)
	REVERT_BOOL(Next)
	REVERT_BOOL(Previous)

#undef REVERT_BOOL

	[f_ReadAheadSizeLimit setIntValue: [Pref_ReadAhead readAheadSizeLimit]];
}


-(NSString *) name
{
	return _(@"Read-ahead");
}

-(void) setupButton: (NSButton *)b
{
	[b setTitle: _(@"Read-\nahead")];
	[b sizeToFit];
}

-(void) willHide
{
}

-(NSView *) willShow
{
	if (!top)
	{
		top=[[GSVbox alloc] init];
		[top setDefaultMinYMargin: 4];

		{
			NSTextField *f;
			GSHbox *hb;

			hb=[[GSHbox alloc] init];
			[hb setDefaultMinXMargin: 4];
			[hb setAutoresizingMask: NSViewWidthSizable];

			f=[[NSTextField alloc] init];
			[f setStringValue: _(@"Read-ahead downloads messages smaller than:")];
			[f setEditable: NO];
			[f setDrawsBackground: NO];
			[f setBordered: NO];
			[f setBezeled: NO];
			[f setSelectable: NO];
			[f sizeToFit];
			[f setAutoresizingMask: 0];
			[hb addView: f  enablingXResizing: NO];
			DESTROY(f);

			f_ReadAheadSizeLimit=f=[[NSTextField alloc] init];
			[f setAutoresizingMask: NSViewWidthSizable];
			[f sizeToFit];
			[hb addView: f  enablingXResizing: YES];
			DESTROY(f);

			[top addView: hb enablingYResizing: NO];
			DESTROY(hb);
		}

		{
			NSButton *b;

			NSBox *box;
			GSVbox *vb;

			box=[[NSBox alloc] init];
			[box setTitle: _(@"Read ahead what?")];

			vb=[[GSVbox alloc] init];
			[vb setDefaultMinYMargin: 4];

			b_ReadAheadNextThread=b=[[NSButton alloc] init];
			[b setTitle: _(@"Next unread past the current thread.")];
			[b setButtonType: NSSwitchButton];
			[b sizeToFit];
			[vb addView: b enablingYResizing: NO];
			DESTROY(b);

			b_ReadAheadNextUnread=b=[[NSButton alloc] init];
			[b setTitle: _(@"Next unread.")];
			[b setButtonType: NSSwitchButton];
			[b sizeToFit];
			[vb addView: b enablingYResizing: NO];
			DESTROY(b);

			b_ReadAheadPrevious=b=[[NSButton alloc] init];
			[b setTitle: _(@"Previous.")];
			[b setButtonType: NSSwitchButton];
			[b sizeToFit];
			[vb addView: b enablingYResizing: NO];
			DESTROY(b);

			b_ReadAheadNext=b=[[NSButton alloc] init];
			[b setTitle: _(@"Next.")];
			[b setButtonType: NSSwitchButton];
			[b sizeToFit];
			[vb addView: b enablingYResizing: NO];
			DESTROY(b);

			[vb sizeToFit];
			[box setContentView: vb];
			[box sizeToFit];
			DESTROY(vb);
			[top addView: box enablingYResizing: NO];
			DESTROY(box);

			b_ReadAhead_=b=[[NSButton alloc] init];
			[b setTitle: _(@"Read ahead (ie. start downloading related messages\nwhen a message is selected).")];
			[b setButtonType: NSSwitchButton];
			[b sizeToFit];
			[top addView: b enablingYResizing: NO];
			DESTROY(b);
		}

		[self revert];
	}
	return top;
}

-(void) dealloc
{
	DESTROY(top);
	[super dealloc];
}

@end