Fixed a bunch of unit tests to restore state after they complete.
[adiumx.git] / Source / AIBookmarkController.m
blob542e619168d5f6158a91bb43bdb5fff54eb43a3e
1 //
2 //  AIBookmarkController.m
3 //  Adium
4 //
5 //  Created by Erik Beerepoot on 21/07/07.
6 //  Copyright 2007 __MyCompanyName__. All rights reserved.
7 //
9 #import "AIBookmarkController.h"
10 #import <AIUtilities/AIToolbarUtilities.h>
11 #import <AIUtilities/AIDictionaryAdditions.h>
12 #import <Adium/AIToolbarControllerProtocol.h>
13 #import <AIUtilities/MVMenuButton.h>
14 #import <AIChat.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"
34 //temp
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
41 -(id)init
43         if((self = [super init])){
44                 //init containers
45                 bookmarks = [[NSMutableDictionary alloc] init];
46                 //      [self loadBookmarks];
47         }
48         return self;
51 /* @name        loadBookmarks
52  * @brief       Load bookmarks from the preferenceController
53  *                      with the correct key, store this in the bookmakrs
54  *                      dictionary
55  */
56 -(void)loadBookmarks
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.
65  */
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. 
79  *                      YES - Visible
80  *                      NO      - Not Visible
81  *                      default is visible.
82  */
84 -(BOOL)bookmarkIsVisible:(AIListBookmark*)bookmark
86         return contactIsVisible;
89 /* @name deallc
90  * @brief deallocation of objects
91  */
92 -(void)dealloc
94         [super dealloc];
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
101  */
102 -(void)setBookmarkIsVisible:(AIListBookmark*)bookmark:(BOOL)visible
106 /* @name        addBookmark
107  * @brief       This method bookmarks the currently active chat.
108  *                      the bookmark will be added to the contact list.
109  */  
110 -(void)promptForNewBookmark
111 {       
112         //save active chat
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:
128  */
130 -(void)createBookmarkWithInfo:(NSDictionary*)chatInfo
132         NSLog(@"active chat: %@", activeChat);
133         NSString* bookmarkName = [chatInfo objectForKey:@"bookmark name"];
134         AIListGroup *bookmarkGroup = [chatInfo objectForKey:@"bookmark group"];
135         
136         //get chat information
137         AIAccount       *account = [activeChat account];
138         AIService       *service = [account service];
141         
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. 
145          */
146         AIListBookmark *bookmark = [[AIListBookmark alloc] initWithUID:bookmarkName account:account service:service];
147         
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];
158         
159         //set UI data
160         [bookmark setVisible:YES];
161         
162         //move bookmark to the desired group
163         [[adium contactController] addContacts:[NSArray arrayWithObjects:bookmark,nil] toGroup:bookmarkGroup];
164         
165         //notify observers that the contact list has changed
166         [[adium notificationCenter] postNotificationName:Contact_ListChanged
167                                                                                           object:bookmark
168                                                                                         userInfo:(contactList ? [NSDictionary dictionaryWithObject:contactList forKey:@"ContainingGroup"] : nil)];
169         
170         [bookmark setIdle:YES sinceDate:[NSDate date] notify:NotifyNow];
173         //save bookmark
174         NSLog(@"info: %@", [bookmark info]);
175         [self saveBookmark:[bookmark info]];
179 @end