new patches
[webos-internals:jeffrotulls-modifications.git] / messaging / messaging-set-avatar-in-messaging.patch
1 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
2 index 484cd45..cca84fe 100644
3 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/chatview-assistant.js
5 @@ -126,6 +126,9 @@ var ChatviewAssistant = Class.create({
6         },
7         
8         setup: function() {
9 +               var cookie = new Mojo.Model.Cookie("myAvatarPath");
10 +               this.myAvatar = cookie.get() || "images/list-view-default-avatar.png";
11 +               
12                 Mojo.Log.info("++++++ChatviewAssistant::setup");
13                 this.controller.setupWidget(Mojo.Menu.appMenu, this.appMenuAttrs, this.appMenuModel);
14                 
15 @@ -1540,7 +1543,7 @@ var ChatviewAssistant = Class.create({
16                         if (ChatFlags.isOutgoing(msg.flags)) {
17                                 tmpClass.push("my-chat");
18                                 // Disabling MY avatar because we are not doing this for 1.0  2008-11-05
19 -                               //msg.avatar = this.myAvatar || 'images/my-avatar.png';
20 +                               msg.avatar = this.myAvatar;
21                         } else {
22                                 tmpClass.push("their-chat");
23                                 msg.avatar = this.avatarHash[msg.fromAddress] || this.contactAvatar || "images/list-view-default-avatar.png";
24 diff --git a/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js b/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js
25 index c301f25..14f4d4a 100644
26 --- a/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js
27 +++ b/usr/palm/applications/com.palm.app.messaging/app/controllers/listview-assistant.js
28 @@ -179,6 +179,24 @@ var ListviewAssistant = Class.create(App.Scene, {
29         },
30         
31         setup: function() {
32 +               var cookie = new Mojo.Model.Cookie("myAvatarPath");
33 +               this.myAvatar = cookie.get();
34 +               if(this.myAvatar) {
35 +                       this.controller.serviceRequest("palm://ca.canucksoftware.filemgr", {
36 +                               method: "exists",
37 +                               parameters: {file: this.myAvatar},
38 +                               onSuccess: function(response) {
39 +                                       if(!response.exists) {
40 +                                               cookie.remove();
41 +                                       }
42 +                               }.bind(this)
43 +                       });
44 +               }
45 +               this.controller.serviceRequest("palm://ca.canucksoftware.filemgr", {
46 +                       method: "createDir",
47 +                       parameters: {path: "/var/luna/files/"}
48 +               });
49 +
50                 this.appMenuAttrs = {
51                         omitDefaultItems: true
52                 };
53 @@ -402,9 +420,54 @@ var ListviewAssistant = Class.create(App.Scene, {
54                 }
55         },
56         
57 +       deleteAvatar: function() {
58 +               if(this.myAvatar) {
59 +                       this.controller.serviceRequest("palm://ca.canucksoftware.filemgr", {
60 +                               method: "delete",
61 +                               parameters: {
62 +                                       file: this.myAvatar,
63 +                               }
64 +                       });
65 +               }
66 +       },
67 +       
68 +       copyAvatar: function(filePath) {
69 +               this.timestamp = new Date().getTime();
70 +               this.avatarExt = filePath.substring(filePath.lastIndexOf("."));
71 +               this.controller.serviceRequest("palm://ca.canucksoftware.filemgr", {
72 +                       method: "copy",
73 +                       parameters: {
74 +                               from: filePath,
75 +                               to: "/var/luna/files/_my-avatar-" + this.timestamp + this.avatarExt,
76 +                       },
77 +                       onSuccess: function() {
78 +                               this.myAvatar = "/var/luna/files/_my-avatar-" + this.timestamp
79 +                                               + this.avatarExt;
80 +                               var cookie = new Mojo.Model.Cookie("myAvatarPath");
81 +                               cookie.put(this.myAvatar);
82 +                       }.bind(this)
83 +               });
84 +       },
85 +       
86         handleCommand: function(event) {
87                 // handle menu button command events
88                 if (event.type == Mojo.Event.command) {
89 +                       if (event.command === 'set-avatar') {
90 +                               var self = this;
91 +                               var params = {
92 +                                       extensions: ["bmp", "jpg", "jpeg", "png", "gif"],
93 +                                       kinds: ["image", "file"],
94 +                                       defaultKind: "image",
95 +                                       actionName: "Set Avatar",
96 +                                       onSelect: function(file){
97 +                                               self.deleteAvatar();
98 +                                               self.copyAvatar(file.fullPath);
99 +                                       }
100 +                               };
101 +                               Mojo.FilePicker.pickFile(params, this.controller.stageController);
102 +                               event.stop();
103 +                               return;
104 +                       }
105                         // determine if we have a target function for this command
106                         var menu = $H(this.COMMAND_MENU);
107                         menu.keys().each(function(key) {
108 @@ -439,6 +502,7 @@ var ListviewAssistant = Class.create(App.Scene, {
109                         enabled: true
110                 };
111                 var items = [Mojo.Menu.editItem];
112 +               items.push({label: "Set Avatar", command: "set-avatar"});
113  
114                 if (this.isOfflineCollapsed != undefined && this.currentListView == this.Messaging.Views.BUDDY) {
115                         var appMenuOfflineItem = {
116 diff --git a/usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css b/usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css
117 index 019deb5..23146f6 100644
118 --- a/usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css
119 +++ b/usr/palm/applications/com.palm.app.messaging/stylesheets/messaging.css
120 @@ -98,16 +98,11 @@ img.avatar-overlay {
121  }
122  
123  .chatRow img.avatar-location {
124 -               margin-top: -18px;
125 +               margin-top: -39px;
126  }
127  
128  .chatRow img.avatar-overlay {
129 -               margin-top: -21px;
130 -}
131 -
132 -.chatRow .avatar-container {
133 -               vertical-align: middle;
134 -               display: inline-block;
135 +               margin-top: -42.5px;
136  }
137  
138  .login-animation-available,
139 @@ -727,10 +722,7 @@ img.avatar-overlay {
140                 padding: 1px 0;
141                 font-size: 18px;
142                 word-wrap: break-word !important;
143 -}
144 -
145 -.their-chat .chat-balloon-wrapper {
146 -               padding-right: 8px;
147 +               padding-right: 40px;
148  }
149  
150  .their-chat .avatar {
151 @@ -740,13 +732,6 @@ img.avatar-overlay {
152  
153  /* Hide user avatar */
154  
155 -.my-chat .avatar-location,
156 -.my-chat .avatar-overlay,
157 -.my-chat .avatar-container {
158 -               display: none;
159 -               width: 40px;
160 -               height: 40px;
161 -}
162  
163  .message.status-success {
164                 color: #000000;