File: MAdministratorController.m

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (301 lines) | stat: -rw-r--r-- 7,800 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#import "MAdministratorController.h"

#import "MAdministrator.h"

#import "MAHomePanel.h"
#import "MAServerInformation.h"
#import "MAUserAdministration.h"
#import "MABackup.h"
#import "MARestore.h"
#import "MAServerLogs.h"
#import "MAServerConnections.h"
#import "MACatalogs.h"
#import "MAHealth.h"
#import "MAServiceControl.h"
#import "MAStartupVariables.h"

#import <MySQLToolsCommon/MConnectionPanel.h>
#import <MySQLToolsCommon/MPreferences.h>
#import <MySQLToolsCommon/MPreferenceEditor.h>
#import <MySQLToolsCommon/MSyntaxColoring.h>

#include "config.h"

@interface MAdministratorController(Private)

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)connectionPanel:(MConnectionPanel*)panel finished:(MYSQL*)mysql info:(MConnectionInfo*)info;
- (void)connectionPanel:(MConnectionPanel*)panel aborted:(BOOL)error;

- (void)recentMenuActivate:(id)sender;
- (void)updateRecentMenu;
@end


@implementation MAdministratorController(Private)

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
  // don't need to instantiate, it's already done from the nib
  //[[MAdministratorController alloc] init];
  
  // register all modules/panels
//  MARegisterPanel([MAHomePanel class]);
  MARegisterPanel([MAServerInformation class]);
  MARegisterPanel([MAServiceControl class]);
  MARegisterPanel([MAStartupVariables class]);
  MARegisterPanel([MAUserAdministration class]);
  MARegisterPanel([MAServerConnections class]);
  MARegisterPanel([MAHealth class]);
  MARegisterPanel([MAServerLogs class]);
  MARegisterPanel([MABackup class]);
  MARegisterPanel([MARestore class]);
  MARegisterPanel([MACatalogs class]);
}


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
  [self newDocument:nil];
}


- (void)connectionPanel:(MConnectionPanel*)panel finished:(MYSQL*)mysql info:(MConnectionInfo*)info
{
  MAdministrator *admin;

  if (!mysql || !info)
  {
    admin= [[MAdministrator alloc] initWithoutConnection];
  }
  else
    admin= [[MAdministrator alloc] initWithConnection:mysql info:info];
  if (admin)
  {
    [self addInstance: admin];
    [admin show];
    [admin release];
  }
  else
    NSLog(@"Main window initialization failed!");

  [panel autorelease];
}

- (void)connectionPanel:(MConnectionPanel*)panel aborted:(BOOL)error
{
  [panel release];
}


- (void)recentMenuActivate:(id)sender
{
  [self openInstanceWithConnectionName:[sender representedObject]];
}


- (void)updateRecentMenu
{
  NSMenu *menu= [recentMenu submenu];
  unsigned int i;
  NSArray *array= [[NSUserDefaults standardUserDefaults] arrayForKey:@"RecentConnections"];
  
  while ([menu numberOfItems] > 2)
    [menu removeItemAtIndex:0];
   
  for (i= 0; i < [array count]; i++)
  {
    id item= [menu addItemWithTitle:[array objectAtIndex:i]
                             action:@selector(recentMenuActivate:)
                      keyEquivalent:@""];
    [item setRepresentedObject:[array objectAtIndex:i]];
  }
}

@end


//=======================================================================

@implementation MAdministratorController


static MAdministratorController *theSharedInstance= nil;


+ (MAdministratorController*)sharedDocumentController
{
  if (!theSharedInstance)
    theSharedInstance= [[MAdministratorController alloc] init];
  
  return theSharedInstance;
}


- (id)init
{
  NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
  NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
    [NSArray array], @"RecentConnections",
    [NSNumber numberWithBool:NO], @"DisplayGlobalPrivileges",
    [NSNumber numberWithBool:NO], @"DisplayTablePrivileges",
    [NSNumber numberWithInt:0], @"ConnectionListRefreshDelay",
    [MPreferences checkDirectory:@"Administrator/Profiles"], @"BackupProfileDirectory",
    nil];

  [appDefaults addEntriesFromDictionary:[MSyntaxColoring defaultColorDictionary]];

  [defaults registerDefaults:appDefaults];

  [NSApp setDelegate:self];
  
  self= [super init];
  if (!self)
    return nil;

  _instances= [[NSMutableArray alloc] init];

  theSharedInstance= self;
  
  return self;
}

- (void)awakeFromNib
{
  [self updateRecentMenu];
}


- (void)dealloc
{
  [_prefPanel release];
  [_instances release];
  [super dealloc];
}


- (void)newDocument: (id)sender
{
  MConnectionPanel *panel;

  panel= [[MConnectionPanel alloc] initWithConnectionsFile: 
    [[MPreferences preferences] pathForFile:@"mysqlx_user_connections.xml"]];
  [panel setDelegate:self];
  [panel show];
  [panel setAllowSkip];
  [panel setHeaderImage: [[[NSImage alloc] initWithContentsOfFile: 
    [[NSBundle mainBundle] pathForResource:@"connect_header_admin"
                                    ofType:@"png"]] autorelease]];
}


- (void)openInstanceWithConnectionName: (NSString*)connectionName
{
  MConnectionPanel *panel;
  
  panel= [[MConnectionPanel alloc] initWithConnectionsFile: 
    [[MPreferences preferences] pathForFile:@"mysqlx_user_connections.xml"]];
  [panel setDelegate:self];
  [panel setAllowSkip];
  [panel showAndConnectTo:connectionName];
  [panel setHeaderImage: [[[NSImage alloc] initWithContentsOfFile: 
    [[NSBundle mainBundle] pathForResource:@"connect_header_admin"
                                    ofType:@"png"]] autorelease]];
}


- (void)addInstance: (MAdministrator*)instance
{
  [_instances addObject: instance];
  if ([instance serverInfo])
    [self noteNewRecentConnection:[instance serverInfo]];
}


- (void)removeInstance: (MAdministrator*)instance
{
  [_instances removeObject: instance];
}


- (void)noteNewRecentConnection: (MConnectionInfo*)info
{
  NSString *name;
  NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
  NSMutableArray *array= [NSMutableArray arrayWithArray:[defaults objectForKey:@"RecentConnections"]];
  
  name= [info description];
  
  [array removeObject:name];
  
  while ([array count] > 9)
  {
    [array removeLastObject];
  }
  
  [array insertObject:name atIndex:0];
  [defaults setObject:array forKey:@"RecentConnections"];
  [self updateRecentMenu];
}


- (IBAction)showAbout:(id)sender
{
  [versionLabel setStringValue:[NSString stringWithFormat:@"Version %@", 
    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];

  [aboutPanel makeKeyAndOrderFront:sender];
}


- (IBAction)showPreferences:(id)sender
{
  if (!_prefPanel)
  {
    _prefPanel= [[MPreferenceEditor alloc] initForConnectionsFile:
      [[MPreferences preferences] pathForFile:@"mysqlx_user_connections.xml"]];

    [_prefPanel registerPageNib:@"Preferences" withLabel:@"Administrator"];
  }
  [_prefPanel show];
}


- (IBAction)clearRecentMenu:(id)sender
{
  [[NSUserDefaults standardUserDefaults] setObject:[NSArray array] forKey:@"RecentConnections"];
  [self updateRecentMenu];
}

- (IBAction)enterpriseHome:(id)sender
{
  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/"]];
}

- (IBAction)enterpriseSoftware:(id)sender
{
  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/software/enterprise.php"]];
}

- (IBAction)enterpriseKB:(id)sender
{
  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://kb.mysql.com/index.php"]];
}

- (IBAction)enterpriseUpdate:(id)sender
{
  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/updates/index.php"]];
}

- (IBAction)enterpriseMonitoring:(id)sender
{
  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://enterprise.mysql.com/monitoring/"]];
}

- (IBAction)enterpriseSupport:(id)sender
{
  [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://support.mysql.com/main.php"]];
}

@end