Ejemplo n.º 1
0
        static void item_load_Click(object sender, EventArgs e)
        {
            MenuItem mItem  = sender as MenuItem;
            Form     form   = mItem.GetMainMenu().GetForm();
            Panel    cpanel = (Panel)form.Controls["cpanel"];

            if (cpanel == null)
            {
                return;
            }

            OpenFileDialog dia = new OpenFileDialog();

            dia.Title  = "Select JSON File";
            dia.Filter = "JSON files|*.json";
            if (dia.ShowDialog() == DialogResult.OK)
            {
                Stream       fstream = dia.OpenFile();
                StreamReader sreader = new StreamReader(fstream);
                String       content = sreader.ReadToEnd();
                sreader.Close();

                DmConversation convo = Twitter.ParseConversation(content);
                if (convo == null)
                {
                    MessageBox.Show("The file you chose doesn't contain any conversation data.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                cpanel.BackColor = Color.LightGray;
                Console.Clear();

                while (cpanel.Controls.Count > 0)
                {
                    cpanel.Controls.Remove(cpanel.Controls[0]);
                }

                foreach (Message msg in convo.messages)
                {
                    MColor color;
                    if (msg.sender.id == convo.userTwo.id)
                    {
                        color = MColor.Blue;
                    }
                    else
                    {
                        color = MColor.Grey;
                    }

                    Console.WriteLine("[{0}] {1}", msg.date.ToShortTimeString(), msg.text);
                    Graphing.AddMessage(msg.text, msg.date, cpanel, color, true);
                }

                cpanel.BackColor = Color.White;
            }
        }
Ejemplo n.º 2
0
        public static void PingUpdate(Twitter twt, Form form)
        {
            PictureBox indic = (PictureBox)form.Controls["indic"];

            Wait(800);
            twt.Ping();
            if (twt.network)
            {
                indic.Image = Graphing.indic_green();
            }
            else
            {
                indic.Image = Graphing.indic_red();
            }
        }
Ejemplo n.º 3
0
        public static Label[] AddMessage(String text, DateTime date, Control parent, MColor color, bool attach = false)
        {
            int y_plus = 5;

            if (parent.Controls.Count > 1)
            {
                Control prev = parent.Controls[parent.Controls.Count - 1];
                y_plus += prev.Location.Y + prev.Height;
            }
            else if (parent.Controls.Count > 0)
            {
                y_plus += parent.Controls[0].Height;
            }
            else if (parent.Controls.Count == 0)
            {
                y_plus = 15;
            }

            if (text.Length > 10000)
            {
                text = text.Substring(0, 10000);
            }

            int max_width = (int)((parent.ClientSize.Width - 25) / 2);
            int min_width = (int)(max_width / 4);

            if (max_width < 0)
            {
                max_width = 0;
            }
            if (min_width < 0)
            {
                min_width = 0;
            }

            Label label = new Label();

            label.Text        = text;
            label.Font        = new Font("Segoe UI", 12);
            label.MaximumSize = new Size(max_width, 2048);
            label.MinimumSize = new Size(min_width, 15);
            label.AutoSize    = true;


            label.BackColor = Graphing.MsgColor(color);

            Label label2 = new Label();

            label2.AutoSize = true;

            label2.Font = new Font("Segoe UI", 8);
            label2.Text = date.ToShortTimeString();


            int x    = 10;
            int x_sm = 15;

            if (color == MColor.Blue)
            {
                label.ForeColor = Color.White;
                x    = parent.Width - 30 - label.PreferredWidth;
                x_sm = parent.Width - 35 - label2.PreferredWidth;
            }



            label.Location  = new Point(x, y_plus);
            label2.Location = new Point(x_sm, label.Location.Y + 5 + label.PreferredHeight);

            if (attach)
            {
                parent.Controls.AddRange(new [] { label, label2 });
            }

            return(new Label[] { label, label2 });
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            Twitter twt = new Twitter();

//			FreeConsole();
            Application.EnableVisualStyles();

            Icon icon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("icon"));

            Form window = new Form();

            window.Icon            = icon;
            window.Text            = "DMPeek";
            window.Width           = 550;
            window.Height          = 675;
            window.MaximizeBox     = false;
            window.FormBorderStyle = FormBorderStyle.FixedSingle;

            MainMenu menu = new MainMenu();

            window.Menu = menu;

            MenuItem menu_file = new MenuItem("File");
            MenuItem menu_help = new MenuItem("Help");

            MenuItem item_ping = new MenuItem("Check connection");

            item_ping.Click += item_ping_Click;
            menu_help.MenuItems.Add(item_ping);

            MenuItem item_load = new MenuItem("Load file");

            item_load.Click += item_load_Click;
            menu_file.MenuItems.Add(item_load);


            menu.MenuItems.AddRange(new [] {
                menu_file,
                menu_help,
            });

            Panel cpanel = new Panel();

            cpanel.Name                   = "cpanel";
            cpanel.Width                  = 500;
            cpanel.Height                 = 600;
            cpanel.BorderStyle            = BorderStyle.Fixed3D;
            cpanel.BackColor              = Color.White;
            cpanel.VerticalScroll.Visible = true;
            cpanel.AutoScroll             = true;

            window.Controls.Add(cpanel);
            Graphing.AlignCenter(cpanel);

            PictureBox indic = new PictureBox();

            indic.Name     = "indic";
            indic.Image    = Graphing.indic_white();
            indic.Width    = 8;
            indic.Height   = 8;
            indic.SizeMode = PictureBoxSizeMode.StretchImage;
            window.Controls.Add(indic);
            Graphing.Move(indic, 2, 2, Corner.Bottom_Right, window);

            Utils.PingUpdate(twt, window);

            window.Show();
            Application.Run(window);
        }