Ejemplo n.º 1
0
        private void AvatarImg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            XmppVCard vCard = UserSetting.VCard;

            if (Guard.AlertIfNull(vCard, this, "Unable to set avatar now, vCard not retrieved yet from the server. If the problem persists, the server may not support this feature."))
            {
                return;
            }

            string fileName = DialogUtils.SelectFileToOpen("All Avatar types (*.jpg,*.jpeg,*.gif,*.png)|*.jpg;*.jpeg;*.gif;*.png", null);

            if (string.IsNullOrWhiteSpace(fileName))
            {
                return;
            }

            string hash = null;

            try {
                Avatar.GenerateFromFile(fileName, out hash);
                vCard.PhotoType   = "image/png";
                vCard.PhotoBinVal = Avatar.GetData(hash);
            }
            catch (Exception ex) {
                DialogUtils.ShowException(this, "Unable to set avatar :-( Internal error.", ex);
                return;
            }

            Log("avatar updating");
            int id = client.SendVCardUpdate(vCard);

            Signals.Register(id, (par) => {
                if (par.Type == XmppIqType.Result)
                {
                    UpdateAvatar(hash);
                    Log("avatar updated");
                }
                else if (par.Type == XmppIqType.Error)
                {
                    DialogUtils.ShowError(this, string.Format("Unable to set avatar :-( Server error, be sad! {0} {0} {1}", Environment.NewLine, ParseStreamError(par.xStream)));
                }
            });
        }