private async void MainForm_Shown(object sender, EventArgs e) { AuthForm f = new AuthForm(); await f.Auth(); AppEvents.Dispatch(AppEventType.AuthCompleted, API.API.Session); }
protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (!_close && !_authCompleted) { if (MessageBox.Show("You are not authorized!\nClose application?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { AppEvents.Dispatch(AppEventType.AuthFailedNoInternet); _close = true; Application.Exit(); } else { e.Cancel = true; } } }
private void Done(String u) { _result = u; if (u.StartsWith("res://ieframe.dll/navcancl.htm")) { MessageBox.Show("No internet connection", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); AppEvents.Dispatch(AppEventType.AuthFailedNoInternet); this.Close(); } else if (u.StartsWith("https://oauth.vk.com/blank.html")) { _authCompleted = true; this.Close(); } else if (u.StartsWith("https://oauth.vk.com/authorize")) { } }
protected override void OnPaint(PaintEventArgs e) { this.OnPaintBackground(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; if (!loaded) { g.FillRectangle(new SolidBrush(Color.FromArgb(164, Color.White)), this.ClientRectangle); Drawer.DrawString(g, "Loading chats...", this.Font, Brushes.Black, this.ClientRectangle); } else { int y = -this.ScrollOffset; int i = -1; foreach (Dialog chat in this.chats) { i++; if (y < -50) { y += 50; continue; } if (y > this.Height) { break; } ControlState s = ControlState.Idle; int my = this.Mouse.Position.Y; if (this.Mouse.Position.X != -1 && my > y && my < y + 50) { s = ControlState.Hover; if (this.Mouse.Clicked) { s = ControlState.Pressed; this._cActive = i; AppEvents.Dispatch(AppEventType.OpenChat, chat); this.Mouse.Clicked = false; this.Invalidate(); } } if (i == this._cActive) { s = ControlState.Active; } Drawer.DrawChat(g, chat, this.Font, s, y, this.Width); y += 50; } } base.OnPaint(e); }
private void OpenChat(AppEvent e) { this._chat = (Dialog)e.Data[0]; (new Thread(async() => { List <Message> messages = await this._chat.GetMessages(); List <int> ids = new List <int>(); lock (_messages_lock) { this._messages = messages; if (this._chat.Crypt) { this.InvokeEx(t => { DecryptMessagesForm frm = new DecryptMessagesForm(); if (frm.ShowDialog(t.FindForm()) == DialogResult.OK) { t._chat.CryptKey = frm.Passphrase; } }); } this._so = 0; this._oldH = 0; if (this._messages != null) { this._messages = this._messages.Reverse <Message>().ToList(); foreach (Message msg in this._messages) { if (!ids.Contains(msg.UserID)) { ids.Add(msg.UserID); } if (msg.CryptedNow && this._chat.CryptKey != null) { msg.Decrypt(this._chat.CryptKey); } if (msg.Attachments != null && msg.Attachments.Length > 0) { foreach (Attachment a in msg.Attachments) { if (a.Type == "photo" && a.Photo != null) { a.Photo.Load(); } } } } } } User[] users = await User.GetAll(ids); if (users != null) { foreach (User u in users) { u.GetPhoto(); } } this._loaded = true; this._heightCalculated = false; AppEvents.Dispatch(AppEventType.ChatOpened, this._chat); this.InvokeEx(t => { t.Invalidate(); }); })).Start(); }