2 // AIBookmarkController.m
5 // Created by Erik Beerepoot on 21/07/07.
6 // Copyright 2007 __MyCompanyName__. All rights reserved.
9 #import "AIBookmarkController.h"
10 #import <AIUtilities/AIToolbarUtilities.h>
11 #import <AIUtilities/AIDictionaryAdditions.h>
12 #import <Adium/AIToolbarControllerProtocol.h>
13 #import <AIUtilities/MVMenuButton.h>
15 #import <AIPreferenceControllerProtocol.h>
16 #import <Adium/AIChatControllerProtocol.h>
17 #import <Adium/AIContactControllerProtocol.h>
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import "AIStandardToolbarItemsPlugin.h"
20 #import <Adium/AIToolbarControllerProtocol.h>
21 #import <AIUtilities/AIToolbarUtilities.h>
22 #import <AIUtilities/AIImageAdditions.h>
23 #import <Adium/AIListContact.h>
24 #import <Adium/AIListObject.h>
25 #import <AIListBookmark.h>
26 #import <AINewBookmarkWindowController.h>
28 #define BOOKMARKS_KEY @"bookmarks" //bookmark save & load key
29 #define PREF_GROUP_BOOKMARKS @"Bookmarks" //Contact list preference group
30 #define TOOLBAR_ITEM_IDENTIFIER @"Bookmark Chat" //bookmark chat item identifier
31 #define BOOKMARK @"Bookmark Chat"
32 #define CONTACT_DEFAULT_PREFS @"ContactPrefs"
35 #define PREF_GROUP_CONTACT_LIST @"Contact List"
36 #define KEY_FLAT_METACONTACTS @"FlatMetaContacts" //Metacontact objectID storage
38 #warning This class is incomplete
40 @implementation AIBookmarkController
43 if((self = [super init])){
45 bookmarks = [[NSMutableDictionary alloc] init];
46 // [self loadBookmarks];
51 /* @name loadBookmarks
52 * @brief Load bookmarks from the preferenceController
53 * with the correct key, store this in the bookmakrs
58 NSLog(@"%@", bookmarks);
59 bookmarks = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/bookmarks.plist"];
62 /* @name saveBookmarks
63 * @brief Save bookmarks for the correct key to the
64 * preference controller, from the bookmarks dictionary.
66 -(void)saveBookmark:(NSDictionary*)info
68 bookmarksForPlist = [[NSMutableArray alloc] init];
69 [bookmarksForPlist addObject:info];
70 NSLog(@"%d",[bookmarksForPlist writeToFile:@"/Documents/bookmarks.plist" atomically:YES]);
74 /* @name contactIsVisible
75 * @param bookmark - An AIListBookmark; the bookmark of which the visibility
76 * status has to be determined
77 * @brief This method returns a BOOLEAN value which represents the visiblity
78 * status of the bookmark.
84 -(BOOL)bookmarkIsVisible:(AIListBookmark*)bookmark
86 return contactIsVisible;
90 * @brief deallocation of objects
97 /* @name setBookmarkIsVisible
98 * @param bookmark - the bookmark whose visibilty status will be changed
99 * visible - the BOOLEAN value representing the visiblity status (YES - Visible, NO - not visible)
100 * @brief accessor method to set the visiblity status for a given bookmark
102 -(void)setBookmarkIsVisible:(AIListBookmark*)bookmark:(BOOL)visible
107 * @brief This method bookmarks the currently active chat.
108 * the bookmark will be added to the contact list.
110 -(void)promptForNewBookmark
113 activeChat = [[adium interfaceController] activeChat];
115 //prompt user for alias & group name
116 AINewBookmarkWindowController *newBookmarkController = [AINewBookmarkWindowController promptForNewBookmarkOnWindow:nil];
117 [newBookmarkController setDelegate:self];
123 /* @name createBookmarkWithInfo
124 * @param (NSDictionary*)chatInfo - dictionary with info about the chat, such as the servername, room, & handle.
125 * @brief Creates a new bookmark with info from the chat which the user wants to bookmark. (which is not the active chat)
126 * adds this bookmark to the userlist & notifies observers that the contaclist has changed. In addition, this method
127 * saves the bookmark in an array which is then saved by calling saveBookmarks:
130 -(void)createBookmarkWithInfo:(NSDictionary*)chatInfo
132 NSLog(@"active chat: %@", activeChat);
133 NSString* bookmarkName = [chatInfo objectForKey:@"bookmark name"];
134 AIListGroup *bookmarkGroup = [chatInfo objectForKey:@"bookmark group"];
136 //get chat information
137 AIAccount *account = [activeChat account];
138 AIService *service = [account service];
142 /*! create a bookmark
143 * NOTE: Since the UID is generated using the bookmarkName, this could turn out to be a problem when
144 * a user uses the same name for multiple bookmarks.
146 AIListBookmark *bookmark = [[AIListBookmark alloc] initWithUID:bookmarkName account:account service:service];
148 //set bookmark properties
149 [bookmark setAccount:[activeChat account]];
150 [bookmark setServer:[activeChat server]];
151 [bookmark setRoom:[activeChat room]];
152 [bookmark setHandle:[activeChat handle]];
153 [bookmark setName:[activeChat name]];
154 [bookmark setGroup:bookmarkGroup];
155 //add the bookmark to the contact list
156 contactList = [[adium contactController] contactList];
157 [contactList addObject:bookmark];
160 [bookmark setVisible:YES];
162 //move bookmark to the desired group
163 [[adium contactController] addContacts:[NSArray arrayWithObjects:bookmark,nil] toGroup:bookmarkGroup];
165 //notify observers that the contact list has changed
166 [[adium notificationCenter] postNotificationName:Contact_ListChanged
168 userInfo:(contactList ? [NSDictionary dictionaryWithObject:contactList forKey:@"ContainingGroup"] : nil)];
170 [bookmark setIdle:YES sinceDate:[NSDate date] notify:NotifyNow];
174 NSLog(@"info: %@", [bookmark info]);
175 [self saveBookmark:[bookmark info]];