Esempio n. 1
0
    protected void refreshRoomList()
    {
        var liststore = new ListStore(typeof(Gdk.Pixbuf), typeof(string));

        foreach (var channel in this.rooms.Values)
        {
            var label = getRoomLabel(channel);
            System.Drawing.Image avatar = null;

            if (channel.Members.Count == 2)
            {
                var other = getOtherRoomMember(channel);
                if (this.avatars.ContainsKey(other))
                {
                    avatar = this.avatars [other];
                }
            }

            var icon = AvatarGenerator.createRoomAvatar(label, channel.Encryption != null, avatar);
            liststore.AppendValues(icon, label);

            channel.OnMessage -= onRoomMessage;
            channel.OnMessage += onRoomMessage;
        }

        channelList.Model = liststore;
    }
Esempio n. 2
0
    public void MatrixRoutine()
    {
        var storage = new Storage();

        client = new MatrixClient(storage.Server);
        cache  = new Cache(client);

        try{
            client.UseExistingToken(storage.UserId, storage.Token);
            this.user = client.GetUser();
            Gtk.Application.Invoke(delegate {
                var statusContext = statusbar.GetContextId("matrix");
                statusbar.Push(statusContext, "Logged in to " + storage.Server + " as " + storage.UserId);
                displayName.Text = user.DisplayName;
            });
        }catch (Exception loginException) {
            Gtk.Application.Invoke(delegate {
                var statusContext = statusbar.GetContextId("matrix");
                statusbar.Push(statusContext, "Login failed: " + loginException.Message);
            });

            storage.Token = null;
            storage.Save();
        }

        var rooms = client.GetAllRooms();

        channelList.AppendColumn("Icon", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
        channelList.AppendColumn("Artist", new Gtk.CellRendererText(), "text", 1);


        var liststore = new ListStore(typeof(Gdk.Pixbuf), typeof(string));

        int roomIndex = 0;

        foreach (var channel in rooms)
        {
            var label = getRoomLabel(channel);
            var icon  = AvatarGenerator.createRoomAvatar(label, channel.Encryption != null);
            liststore.AppendValues(icon, label);
            this.rooms.Add(roomIndex, channel);
            roomIndex++;

            foreach (var member in channel.Members)
            {
                if (!this.users.ContainsKey(member.Key))
                {
                    this.users.Add(member.Key, member.Value);
                }
            }
        }

        channelList.Model = liststore;
        var avatar       = cache.GetAvatarObject(user.AvatarURL);
        var avatarScaled = Utils.resizeImage(System.Drawing.Image.FromStream(avatar), 48, 48);

        profileImage.Pixbuf = Utils.bitmapToPixbuf(avatarScaled);

        foreach (var member in this.users)
        {
            if (member.Value.avatar_url != null)
            {
                var memberAvatar = cache.GetAvatarObject(member.Value.avatar_url);
                var scaled       = Utils.resizeImage(System.Drawing.Image.FromStream(memberAvatar), 32, 32);
                this.avatars.Add(member.Key, scaled);
            }
        }
        refreshRoomList();
        Console.WriteLine("Matrix thread done");
    }
Esempio n. 3
0
    protected void loadRoom(MatrixRoom room)
    {
        this.currentRoom = room;

        foreach (var widget in chatBox.Children)
        {
            chatBox.Remove(widget);
        }

        foreach (var message in room.Messages)
        {
            Widget messageContents = null;
            if (message.msgtype == "m.text")
            {
                messageContents = new Label(message.body);
                ((Label)messageContents).Justify = Justification.Left;
            }
            if (message.msgtype == "m.image")
            {
                messageContents = new VBox();
                var imageLabel = new Label(message.body);
                imageLabel.Justify = Justification.Left;

                var loader        = new AsyncImageLoader((MMessageImage)message, this.client);
                var imageContents = loader.GetImageWidget(250, 200);

                ((VBox)messageContents).PackStart(imageLabel);
                ((VBox)messageContents).PackStart(imageContents);
            }
            if (messageContents != null)
            {
                var    messageContainer = new HBox();
                string senderName;

                senderName = this.users [message.sender].displayname;
                if (senderName == null)
                {
                    senderName = message.sender;
                }

                var alignmentBox = new Gtk.Alignment(0, -1, 0, 0);
                if (this.avatars.ContainsKey(message.sender))
                {
                    var senderIcon = new System.Drawing.Bitmap(this.avatars [message.sender]);
                    alignmentBox.Add(new Gtk.Image(Utils.bitmapToPixbuf(senderIcon)));
                }
                else
                {
                    var senderIcon = AvatarGenerator.createRoomAvatar(senderName);
                    alignmentBox.Add(new Gtk.Image(senderIcon));
                }
                messageContainer.PackStart(alignmentBox, false, false, 6);

                messageContainer.PackStart(messageContents, false, false, 6);
                chatBox.PackStart(messageContainer, false, false, 0);
            }

            Console.WriteLine(message.msgtype);
        }
        chatBox.ShowAll();
    }