-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBriquetteDelegate.rb
executable file
·210 lines (167 loc) · 7 KB
/
BriquetteDelegate.rb
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
# BriquetteDelegate.rb
# briquette
#
# Created by Dominic Dagradi on 10/24/10.
# Copyright 2010 Bearded. All rights reserved.
#
# Application Delegate
class BriquetteDelegate
SPELLING_CORRECTION_ENABLED = "spelling_correction_enabled"
attr_accessor :windowController
def applicationDidFinishLaunching(notification)
NSApplication.sharedApplication.setPresentationOptions (1<<10) # Substitute for NSApplicationPresentationFullScreen
GrowlApplicationBridge.setGrowlDelegate self
setAppDefaults
monitorNetwork
showMainWindow
showLoginSheet if Preferences.sharedPreferences.firstLaunch?
end
def setAppDefaults
# Set defaults
Preferences.sharedPreferences.setDefaultIfNil 1, BriquetteDelegate::SPELLING_CORRECTION_ENABLED
Preferences.sharedPreferences.setDefaultIfNil true, MessagesPreferences::JOINLEAVE
Preferences.sharedPreferences.setDefaultIfNil true, MessagesPreferences::IMAGES
Preferences.sharedPreferences.setDefaultIfNil true, MessagesPreferences::TIMESTAMPS
Preferences.sharedPreferences.setDefaultIfNil false, NotificationPreferences::NEW_GROWL
Preferences.sharedPreferences.setDefaultIfNil false, NotificationPreferences::NEW_GROWL_PERSIST
Preferences.sharedPreferences.setDefaultIfNil true, NotificationPreferences::MENTION_GROWL
Preferences.sharedPreferences.setDefaultIfNil true, NotificationPreferences::MENTION_GROWL_PERSIST
Preferences.sharedPreferences.setDefaultIfNil true, NotificationPreferences::NEW_BOUNCE
Preferences.sharedPreferences.setDefaultIfNil true, NotificationPreferences::MENTION_BOUNCE
Preferences.sharedPreferences.setDefaultIfNil false, NotificationPreferences::SOUND_ANNOUNCE_ALL
Preferences.sharedPreferences.setDefaultIfNil false, NotificationPreferences::SOUND_ANNOUNCE_MENTION
Preferences.sharedPreferences.setDefaultIfNil [], NotificationPreferences::CUSTOM_NOTIFICATIONS
end
def monitorNetwork
@notifier = NetworkNotifier.alloc.init
@notifier.delegate = ConnectionManager.sharedManager
end
def showMainWindow
@windowController = MainWindowController.alloc().initWithWindowNibName("MainWindow") if @windowController.nil?
@windowController.window.makeKeyAndOrderFront(self)
end
def showPreferencesWindow
unless @preferenceController
controllers = []
accountPreferences = AccountPreferences.new
messagePreferences = MessagesPreferences.new
controllers << accountPreferences
controllers << messagePreferences
controllers << NotificationPreferences.new
@preferenceController = PreferencesWindowController.alloc().initWithViewControllers(controllers, title:"Preferences")
@preferenceController.messagePreferences = messagePreferences
accountPreferences.window = @preferenceController.window
end
@preferenceController.window.makeKeyAndOrderFront(self)
end
def updateWindowTitle(title = "Briquette")
@windowController.window.setTitle(title) unless @windowController.nil?
end
def showSearchWindow(search_term = nil)
@searchController = SearchWindowController.alloc().initWithWindowNibName("SearchWindow") unless @searchController
@searchController.starting_term = search_term unless search_term.nil?
@searchController.window.makeKeyAndOrderFront(self)
@searchController.updateSearchFieldAndSearch(nil)
end
# Load and manage login sheet on first run
def showLoginSheet
NSApp.beginSheet(@windowController.sheet,
:modalForWindow => @windowController.window,
:modalDelegate => self,
:didEndSelector => NSSelectorFromString("closeLoginSheet:returnCode:contextInfo:"),
:contextInfo => nil)
end
def closeLoginSheet sheet, returnCode:code, contextInfo:info
sheet = @windowController.sheet
@windowController.sheet.orderOut self
end
########################################
# Application Events
########################################
#when this app gets focus mark the current room's messages as read.
def applicationWillBecomeActive event
@windowController.markCurrentRoomAsRead unless @windowController.nil?
end
def applicationShouldHandleReopen app, hasVisibleWindows:flag
showMainWindow if !flag
true
end
def applicationShouldTerminate sender
#leave all rooms before quitting
@windowController.sites.values.each{|site| site.leaveAllRooms({"exiting" => true}) }
return NSTerminateNow
end
def growlNotificationWasClicked context
NSApp.activateIgnoringOtherApps true
showMainWindow
@windowController.selectRoomWithId context
end
# Refreshes all the messages in our currently open rooms
def refreshRoomViews
@windowController.sites.each_value do |site|
site.rooms.each_value do |room|
room.controller.view.updateVisibleMessages if room.controller
end
end
end
# Manage notification highlights in views
def addNotificationToViews notification_string
@windowController.sites.each_value do |site|
site.rooms.each_value do |room|
room.controller.view.addNotification notification_string if room.joined
end
end
end
def removeNotificationFromViews notification_string
@windowController.sites.each_value do |site|
site.rooms.each_value do |room|
room.controller.view.removeNotification notification_string if room.joined
end
end
end
####################################
# Application Status
####################################
# Posts application status message to specified room without sending through Campfire
def addStatusMessage(status, toRoom:room)
message = { 'type' => Message::SYSTEM,
'created_at' => Time.now.to_s,
'room_id' => room.id,
'body' => status,
'user_id' => 'null',
'id' => "status-#{Time.now.to_i}"
}
room.messageReceived message
end
def addAlert(title, message, type, room = nil)
messageView = @windowController.messagesView
alert = AlertView.alloc.initWithFrame NSMakeRect(0,messageView.frame.size.height-48,messageView.frame.size.width,48)
alert.title = title
alert.message = message
alert.type = type
messageView.addSubview alert
end
####################################
# Navigation
####################################
def selectNextRoom
@windowController.roomList.selectNextRoomView
end
def selectPreviousRoom
@windowController.roomList.selectPrevRoomView
end
####################################
# Spelling Correction
####################################
def toggleSpellingCorrection
@windowController.rooms.each_value do |room|
unless room.controller.nil?
input = room.controller.messageInput
input.toggleAutomaticSpellingCorrection self
end
end
# puts Preferences.sharedPreferences.getDefault(BriquetteDelegate::SPELLING_CORRECTION_ENABLED)
#puts value
#Preferences.sharedPreferences.setDefault(value,BriquetteDelegate::SPELLING_CORRECTION_ENABLED)
end
end