2 // Radegast Metaverse Client
\r
3 // Copyright (c) 2009, Radegast Development Team
\r
4 // All rights reserved.
\r
6 // Redistribution and use in source and binary forms, with or without
\r
7 // modification, are permitted provided that the following conditions are met:
\r
9 // * Redistributions of source code must retain the above copyright notice,
\r
10 // this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the distribution.
\r
14 // * Neither the name of the application "Radegast", nor the names of its
\r
15 // contributors may be used to endorse or promote products derived from
\r
16 // this software without specific prior written permission.
\r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 using System.Collections.Generic;
\r
33 using System.Windows.Forms;
\r
34 using OpenMetaverse;
\r
35 using OpenMetaverse.Assets;
\r
39 public partial class Notecard : DettachableControl
\r
41 private RadegastInstance instance;
\r
42 private GridClient client { get { return instance.Client; } }
\r
43 private InventoryNotecard notecard;
\r
44 private AssetNotecard recievedNotecard;
\r
46 public Notecard(RadegastInstance instance, InventoryNotecard notecard)
\r
48 InitializeComponent();
\r
49 Disposed += new EventHandler(Notecard_Disposed);
\r
51 this.instance = instance;
\r
52 this.notecard = notecard;
\r
53 Text = notecard.Name;
\r
55 rtbContent.DetectUrls = false;
\r
58 if (notecard.AssetUUID == UUID.Zero)
\r
60 UpdateStatus("Blank");
\r
64 rtbContent.Text = " ";
\r
65 UpdateStatus("Loading...");
\r
66 client.Assets.RequestInventoryAsset(notecard, true, Assets_OnAssetReceived);
\r
70 void Notecard_Disposed(object sender, EventArgs e)
\r
74 void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
\r
78 BeginInvoke(new MethodInvoker(delegate()
\r
80 Assets_OnAssetReceived(transfer, asset);
\r
86 if (transfer.Success)
\r
88 AssetNotecard n = (AssetNotecard)asset;
\r
90 recievedNotecard = n;
\r
92 string noteText = string.Empty;
\r
95 for (int i = 0; i < n.BodyText.Length; i++)
\r
97 char c = n.BodyText[i];
\r
99 if ((int)c == 0xdbc0)
\r
101 int index = (int)n.BodyText[++i] - 0xdc00;
\r
102 InventoryItem e = n.EmbeddedItems[index];
\r
103 rtbContent.AppendText(noteText);
\r
104 rtbContent.InsertLink(e.Name, string.Format("radegast://embeddedasset/{0}", index));
\r
105 noteText = string.Empty;
\r
113 rtbContent.Text += noteText;
\r
115 if (n.EmbeddedItems != null && n.EmbeddedItems.Count > 0)
\r
117 tbtnAttachments.Enabled = true;
\r
118 tbtnAttachments.Visible = true;
\r
119 foreach (InventoryItem item in n.EmbeddedItems)
\r
121 int ix = InventoryConsole.GetItemImageIndex(item.AssetType.ToString().ToLower());
\r
122 ToolStripMenuItem titem = new ToolStripMenuItem(item.Name);
\r
126 titem.Image = frmMain.ResourceImages.Images[ix];
\r
127 titem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
\r
131 titem.DisplayStyle = ToolStripItemDisplayStyle.Text;
\r
134 titem.Name = item.UUID.ToString(); ;
\r
136 titem.Click += new EventHandler(attachmentMenuItem_Click);
\r
137 tbtnAttachments.DropDownItems.Add(titem);
\r
140 UpdateStatus("OK");
\r
141 rtbContent.Focus();
\r
145 UpdateStatus("Failed");
\r
146 rtbContent.Text = "Failed to download notecard.";
\r
150 void attachmentMenuItem_Click(object sender, EventArgs e)
\r
152 if (sender is ToolStripMenuItem)
\r
154 ToolStripMenuItem titem = (ToolStripMenuItem)sender;
\r
155 InventoryItem item = (InventoryItem)titem.Tag;
\r
157 switch (item.AssetType)
\r
159 case AssetType.Texture:
\r
160 SLImageHandler ih = new SLImageHandler(instance, item.AssetUUID, string.Empty);
\r
161 ih.Text = item.Name;
\r
165 case AssetType.Landmark:
\r
166 Landmark ln = new Landmark(instance, (InventoryLandmark)item);
\r
173 private void btnRefresh_Click(object sender, EventArgs e)
\r
175 if (notecard.AssetUUID == UUID.Zero) return;
\r
177 rtbContent.Text = "Loading...";
\r
178 client.Assets.RequestInventoryAsset(notecard, true, Assets_OnAssetReceived);
\r
181 private void rtbContent_LinkClicked(object sender, LinkClickedEventArgs e)
\r
183 //instance.MainForm.processLink(e.LinkText);
\r
187 #region Detach/Attach
\r
188 protected override void ControlIsNotRetachable()
\r
190 tbtnAttach.Visible = false;
\r
193 protected override void Detach()
\r
196 tbtnAttach.Text = "Attach";
\r
197 tbtnExit.Enabled = true;
\r
200 protected override void Retach()
\r
203 tbtnAttach.Text = "Detach";
\r
204 tbtnExit.Enabled = false;
\r
207 private void tbtnAttach_Click(object sender, EventArgs e)
\r
220 private void tbtnExit_Click(object sender, EventArgs e)
\r
224 FindForm().Close();
\r
228 private void tbtnSave_Click(object sender, EventArgs e)
\r
230 bool success = false;
\r
231 string message = "";
\r
232 AssetNotecard n = new AssetNotecard();
\r
233 n.BodyText = rtbContent.Text;
\r
234 n.EmbeddedItems = new List<InventoryItem>();
\r
236 if (recievedNotecard != null)
\r
238 for (int i = 0; i < recievedNotecard.EmbeddedItems.Count; i++)
\r
240 n.EmbeddedItems.Add(recievedNotecard.EmbeddedItems[i]);
\r
241 int indexChar = 0xdc00 + i;
\r
242 n.BodyText += (char)0xdbc0;
\r
243 n.BodyText += (char)indexChar;
\r
249 UpdateStatus("Saving...");
\r
252 client.Inventory.RequestUploadNotecardAsset(n.AssetData, notecard.UUID,
\r
253 delegate(bool uploadSuccess, string status, UUID itemID, UUID assetID)
\r
255 success = uploadSuccess;
\r
256 if (itemID == notecard.UUID)
\r
260 UpdateStatus("OK");
\r
261 notecard.AssetUUID = assetID;
\r
265 UpdateStatus("Failed");
\r
269 message = status ?? "Unknown error uploading notecard asset";
\r
274 void UpdateStatus(string status)
\r
276 if (InvokeRequired)
\r
278 BeginInvoke(new MethodInvoker(delegate() { UpdateStatus(status); }));
\r
281 instance.TabConsole.DisplayNotificationInChat("Notecard status: " + status, ChatBufferTextStyle.Invisible);
\r
282 tlblStatus.Text = status;
\r
285 private void rtbContent_KeyDown(object sender, KeyEventArgs e)
\r
287 if (e.KeyCode == Keys.S && e.Control)
\r
294 tbtnSave_Click(this, EventArgs.Empty);
\r
295 e.Handled = e.SuppressKeyPress = true;
\r
301 private void rtbContent_Enter(object sender, EventArgs e)
\r
303 instance.TabConsole.DisplayNotificationInChat("Editing notecard", ChatBufferTextStyle.Invisible);
\r