File: Pref_Sources.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 (249 lines) | stat: -rw-r--r-- 5,258 bytes parent folder | download | duplicates (6)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
copyright 2002 Alexander Malmberg <alexander@malmberg.org>
*/

#include <Foundation/NSObject.h>
#include <Foundation/NSString.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSBundle.h>

#include <AppKit/NSTableView.h>
#include <AppKit/NSTableColumn.h>
#include <AppKit/NSButton.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSClipView.h>
#include <GNUstepGUI/GSHbox.h>
#include <GNUstepGUI/GSVbox.h>

#include "PrefBox.h"
#include "Pref_Sources.h"

#include "MsgDB.h"

#include "GUISource.h"
#include "NNTPSource.h"


@implementation Pref_Sources

-(void) addSource: (id)sender
{ /* TODO: support different kinds of sources. need at least two kinds first */
	[mdb addSourceOfType: [NNTPSource class]];
}

-(void) removeSource: (id)sender
{ /* TODO: confirm with user first? */
	if ([source_list selectedRow]!=-1)
		[mdb removeSource: [sources objectAtIndex: [source_list selectedRow]]];
}

-(void) sourceProperties: (id)sender
{
	if ([source_list selectedRow]!=-1)
		[[sources objectAtIndex: [source_list selectedRow]] displayPropertiesWindow];
}


-(int) numberOfRowsInTableView: (NSTableView *)tv
{
	return [sources count];
}

-(id) tableView: (NSTableView *)tv  objectValueForTableColumn: (NSTableColumn *)tc  row: (int)row
{
	id<Msg_Source,GUISource> s;
	s=[sources objectAtIndex: row];

	if (tc==c_num)
	{
		return [NSNumber numberWithInt: row];
	}
	else if (tc==c_name)
	{
		return [s sourceName];
	}
	else if (tc==c_type)
	{
		return [s sourceType];
	}
	else
		return @"Unknown column";
}


-(void) _getSources
{
	DESTROY(sources);
	sources=[[mdb sources] retain];
	[source_list reloadData];
}


-(void) _createViews
{
	GSHbox *hbox;

	NSScrollView *sv;

	hbox=[[GSHbox alloc] init];
	[hbox setDefaultMinXMargin: 4];

	sv=[[NSScrollView alloc] init];
	[sv setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
	[sv setHasVerticalScroller: YES];
	[sv setHasHorizontalScroller: NO];
	[sv setBorderType: NSBezelBorder];
	
	c_num=[[NSTableColumn alloc] initWithIdentifier: @"Id"];
	[[c_num headerCell] setStringValue: _(@"Id")];
	[c_num setEditable: NO];
	[c_num setResizable: YES];
	[c_num setWidth: 32];
	
	c_name=[[NSTableColumn alloc] initWithIdentifier: @"Name"];
	[[c_name headerCell] setStringValue: _(@"Name")];
	[c_name setEditable: NO];
	[c_name setResizable: YES];
	[c_name setWidth: 128];
	
	c_type=[[NSTableColumn alloc] initWithIdentifier: @"Type"];
	[[c_type headerCell] setStringValue: _(@"Type")];
	[c_type setEditable: NO];
	[c_type setResizable: YES];
	[c_type setWidth: 64];
	
	source_list=[[NSTableView alloc] initWithFrame: [[sv contentView] frame]];
	[source_list setAllowsColumnReordering: YES];
	[source_list setAllowsColumnResizing: YES];
	[source_list setAllowsMultipleSelection: NO];
	[source_list setAllowsColumnSelection: NO];
	[source_list addTableColumn: c_num];
	[source_list addTableColumn: c_name];
	[source_list addTableColumn: c_type];
	[source_list setDataSource: self];
	[source_list setDelegate: self];
	[source_list setDoubleAction: @selector(sourceProperties:)];
	
	[sv setDocumentView: source_list];
	[hbox addView: sv enablingXResizing: YES];
	[sv release];
	
	{
		GSVbox *vb;
		NSButton *b;
	
		vb=[[GSVbox alloc] init];
		[vb setDefaultMinYMargin: 4];
		[vb setAutoresizingMask: NSViewMinYMargin];
	
		b=[[NSButton alloc] init];
		[b setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
		[b setTitle: _(@"Remove")];
		[b setTarget: self];
		[b setAction: @selector(removeSource:)];
		[b sizeToFit];
		[vb addView: b];
		[b release];
	
		b=[[NSButton alloc] init];
		[b setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
		[b setTitle: _(@"Add")];
		[b setTarget: self];
		[b setAction: @selector(addSource:)];
		[b sizeToFit];
		[vb addView: b];
		[b release];
	
		b=[[NSButton alloc] init];
		[b setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
		[b setTitle: _(@"Properties...")];
		[b setTarget: self];
		[b setAction: @selector(sourceProperties:)];
		[b sizeToFit];
		[vb addView: b];
		[b release];
	
		[hbox addView: vb  enablingXResizing: NO];
	
		[vb release];
	}
	
	[hbox setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];

	top=hbox;

	[[NSNotificationCenter defaultCenter]
		addObserver: self
		selector: @selector(_getSources)
		name: MsgDB_SourceAddNotification
		object: mdb];
	[[NSNotificationCenter defaultCenter]
		addObserver: self
		selector: @selector(_getSources)
		name: MsgDB_SourceRemoveNotification
		object: mdb];
	[[NSNotificationCenter defaultCenter]
		addObserver: self
		selector: @selector(_getSources)
		name: MsgDB_SourceChangeNotification
		object: mdb];

	[self _getSources];
}


- initWithMsgDB: (MsgDB *)m
{
	self=[super init];
	ASSIGN(mdb,m);
	return self;
}

-(void) dealloc
{
	[[NSNotificationCenter defaultCenter]
		removeObserver: self];

	DESTROY(sources);
	DESTROY(mdb);
	DESTROY(source_list);
	DESTROY(c_num);
	DESTROY(c_name);
	DESTROY(c_type);
	DESTROY(top);
	[super dealloc];
}

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

-(void) willHide
{
}

-(NSView *) willShow
{
	if (!top)
		[self _createViews];
	return top;
}

-(NSString *) name
{
	return _(@"Message sources");
}

-(void) revert
{
	[self _getSources];
}

-(void) save
{
}

@end