Sevenfourforty / transmission-remote-dotnet

Automatically exported from code.google.com/p/transmission-remote-dotnet
0 stars 0 forks source link

Download locations editor #378

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
First, love this app despite the fact that sometimes it uses 100mb+ of ram. It 
has almost the same functionality as uTorrent, but few things annoys me. Among 
them is poor functionality to organize download locations - as for now it's a 
simple list of locations saved in registry that consists of 15 lines and is 
refreshed as LIFOqueue. There is no ability to edit locations if you want 
somehow change them, so i'm proposing to implement a sort of bookmarks manager. 
Being a c# developer in half an hour i've written few lines of code to 
implement a (poor dirty) edits of download locations. Sure, this must be 
improved (addition, sorting etc.). 
//add button named "button1" to TorrentLoadDialog.cs and bind following handler 
to it
private void buttonEditDirs_Click(object sender, EventArgs e)
        {
            const int elementsWidth = 400;
            const int panelWidth = elementsWidth + 10;
            const int formWidth = panelWidth + 10;

            var newForm = new Form
                              {
                                  StartPosition = FormStartPosition.CenterScreen,
                                  Text = "Directory settings",
                                  Width = formWidth,
                                  Height = 300,
                                  ControlBox = false
                              };
            //newForm.TopMost = true;

            var panel = new FlowLayoutPanel {Width = panelWidth, Dock = DockStyle.Fill};

            var listBox = new ListBox {Width = elementsWidth};
            panel.Controls.Add(listBox);
            foreach (var s in Program.Settings.Current.DestPathHistory)
            {
                listBox.Items.Add(s);
            }
            var textBox = new TextBox {Width = elementsWidth, Text = (string) listBox.Items[0]};

            var button = new Button {Text = "Save", Width = elementsWidth};

            var button2 = new Button {Text = "Close", Width = elementsWidth};

            button.Click += delegate
            {
                Program.Settings.Current.AddDestinationPath(textBox.Text);
                //listBox.Items.Add(textBox.Text);
                listBox.Enabled = true;
                button.Enabled = false;
                Program.Settings.Current.SaveToJson();
            };

            button2.Click += delegate
                                 {
                                     destinationComboBox.Items.Clear();
                                     foreach (var s in Program.Settings.Current.DestPathHistory)
                                     {
                                             destinationComboBox.Items.Add(s);
                                     }
                                     newForm.Close();
                                 };
            listBox.SelectedIndexChanged += delegate
                                                {
                                                    button.Enabled = true;
                                                    var currentPath = (string) listBox.SelectedItem;
                                                    textBox.Text = currentPath;
                                                    Program.Settings.Current.RemoveDestinationPath(currentPath);
                                                    //listBox.Items.RemoveAt(currentId);
                                                    listBox.Enabled = false;
                                                };

            panel.Controls.Add(textBox);
            panel.Controls.Add(button);
            panel.Controls.Add(button2);
            newForm.Controls.Add(panel);
            newForm.ShowDialog();
        }

Original issue reported on code.google.com by crow...@gmail.com on 8 Mar 2011 at 11:45

Attachments: