Exemple #1
0
        private void on_okButton_clicked(object o, EventArgs args)
        {
            dialog.Respond((int)Gtk.ResponseType.None);

            ArrayList badOptions = new ArrayList();

            if (nicknameEntry.Text == String.Empty)
            {
                badOptions.Add("Nickname");
            }

            if (Directory.Exists(completedDownloadsChooser.CurrentFolder) == false)
            {
                badOptions.Add("Completed dowmnloads directory");
            }

            if (Directory.Exists(downloadsChooser.CurrentFolder) == false)
            {
                badOptions.Add("Incomplete dowmnloads directory");
            }


            if (Common.IsValidIP(externalIPv4AddressEntry.Text) == false)
            {
                badOptions.Add("External IP Address");
            }

            if (networksListStore.IterNChildren() == 0)
            {
                badOptions.Add("Please define at least one network");
            }

            if (badOptions.Count > 0)
            {
                BadOptionsDialog badOptionsWindow = new BadOptionsDialog(dialog, badOptions);
                badOptionsWindow.Run();
                return;
            }

            settings.NickName = nicknameEntry.Text;
            settings.RealName = nameEntry.Text;
            settings.Email    = emailEntry.Text;

            settings.Networks.Clear();
            foreach (object[] row in networksListStore)
            {
                settings.Networks.Add((NetworkInfo)row[0]);
            }

            var newSharedDirectories = new List <string>();

            TreeIter iter;

            sharedFoldersListStore.GetIterFirst(out iter);
            if (sharedFoldersListStore.IterIsValid(iter))
            {
                foreach (object[] currentRow in sharedFoldersListStore)
                {
                    newSharedDirectories.Add((string)currentRow[0]);
                }
            }

            settings.SharedDirectories = newSharedDirectories.ToArray();

            settings.CompletedDownloadDir  = completedDownloadsChooser.CurrentFolder;
            settings.IncompleteDownloadDir = downloadsChooser.CurrentFolder;

            settings.SavedDestinationInfos.Clear();

            TCPIPv4Destination destination    = new TCPIPv4Destination(IPAddress.Parse(externalIPv4AddressEntry.Text), (uint)nodePortSpinButton.Value, nodePortOpenCheckButton.Active);
            DestinationInfo    externalIPInfo = destination.CreateDestinationInfo();

            externalIPInfo.Local = true;
            settings.SavedDestinationInfos.Add(externalIPInfo);

            settings.TcpListenPortOpen = nodePortOpenCheckButton.Active;
            settings.TcpListenPort     = (int)nodePortSpinButton.Value;

            if (ipv6LocalInterfaceComboBox.GetActiveIter(out iter))
            {
                int index = (int)ipv6LocalInterfaceComboBox.Model.GetValue(iter, 1);
                settings.IPv6LinkLocalInterfaceIndex = index;
            }
            else
            {
                settings.IPv6LinkLocalInterfaceIndex = -1;
            }

            if (stunServerEntry.Text != String.Empty)
            {
                settings.StunServer = stunServerEntry.Text;
            }
            else
            {
                settings.StunServer = Settings.DefaultStunServer;
            }

            settings.StartInTray      = startInTrayCheckButton.Active;
            settings.AutoConnectCount = autoConnectCountSpinButton.ValueAsInt;

            string avatarDirectory = Path.Combine(Settings.ConfigurationDirectory, "avatars");

            if (Directory.Exists(avatarDirectory) == false)
            {
                Directory.CreateDirectory(avatarDirectory);
            }

            string myAvatarFile = Path.Combine(avatarDirectory, String.Format("{0}.png", nodeid));

            //if (avatarImage.Pixbuf != null)
            if (avatarImage.Sensitive == true)
            {
                avatarImage.Pixbuf.Save(myAvatarFile, "png");
            }
            else
            if (File.Exists(myAvatarFile))
            {
                File.Delete(myAvatarFile);
            }

            settings.Plugins.Clear();
            foreach (object[] row in pluginsListStore)
            {
                PluginInfo info = (PluginInfo)row[0];
                settings.Plugins.Add(info.FilePath);
            }


            settings.SetFirstRun(false);
            settings.SaveSettings();

            if (Core.AvatarManager != null)
            {
                Core.AvatarManager.UpdateMyAvatar();
            }

            // Advanced -> File Transfer
            settings.EnableGlobalDownloadSpeedLimit = limitDownSpeedCheckButton.Active;
            settings.GlobalDownloadSpeedLimit       = Convert.ToInt32(limitDownSpeedSpinButton.Value);

            settings.EnableGlobalUploadSpeedLimit = limitUpSpeedCheckButton.Active;
            settings.GlobalUploadSpeedLimit       = Convert.ToInt32(limitUpSpeedSpinButton.Value);

            // Save and go!
            Core.ReloadSettings();
            dialog.Respond((int)Gtk.ResponseType.Ok);
        }
        private void on_okButton_clicked(object o, EventArgs args)
        {
            dialog.Respond((int)Gtk.ResponseType.None);

            ArrayList badOptions = new ArrayList();

            if (nicknameEntry.Text == String.Empty)
                badOptions.Add("Nickname");

            if (Directory.Exists(completedDownloadsChooser.CurrentFolder) == false)
                badOptions.Add("Completed dowmnloads directory");

            if (Directory.Exists(downloadsChooser.CurrentFolder) == false)
                badOptions.Add("Incomplete dowmnloads directory");

             			if (Common.IsValidIP(externalIPv4AddressEntry.Text) == false) {
                badOptions.Add("External IP Address");
            }

            if (networksListStore.IterNChildren() == 0) {
                badOptions.Add("Please define at least one network");
            }

            if (badOptions.Count > 0) {
                BadOptionsDialog badOptionsWindow = new BadOptionsDialog(dialog, badOptions);
                badOptionsWindow.Run();
                return;
            }

            settings.NickName = nicknameEntry.Text;
            settings.RealName = nameEntry.Text;
            settings.Email = emailEntry.Text;

            settings.Networks.Clear();
            foreach (object[] row in networksListStore) {
                settings.Networks.Add((NetworkInfo)row[0]);
            }

            var newSharedDirectories = new List<string>();

            TreeIter iter;
            sharedFoldersListStore.GetIterFirst(out iter);
            if (sharedFoldersListStore.IterIsValid(iter)) {
                foreach (object[] currentRow in sharedFoldersListStore) {
                    newSharedDirectories.Add((string)currentRow[0]);
                }
            }

            settings.SharedDirectories = newSharedDirectories.ToArray();

            settings.CompletedDownloadDir = completedDownloadsChooser.CurrentFolder;
            settings.IncompleteDownloadDir = downloadsChooser.CurrentFolder;

            settings.SavedDestinationInfos.Clear();

            TCPIPv4Destination destination = new TCPIPv4Destination(IPAddress.Parse(externalIPv4AddressEntry.Text), (uint)nodePortSpinButton.Value, nodePortOpenCheckButton.Active);
            DestinationInfo externalIPInfo = destination.CreateDestinationInfo();
            externalIPInfo.Local = true;
            settings.SavedDestinationInfos.Add(externalIPInfo);

            settings.TcpListenPortOpen = nodePortOpenCheckButton.Active;
            settings.TcpListenPort = (int)nodePortSpinButton.Value;

            if (ipv6LocalInterfaceComboBox.GetActiveIter(out iter)) {
                int index = (int)ipv6LocalInterfaceComboBox.Model.GetValue(iter, 1);
                settings.IPv6LinkLocalInterfaceIndex = index;
            } else {
                settings.IPv6LinkLocalInterfaceIndex = -1;
            }

            if (stunServerEntry.Text != String.Empty) {
                settings.StunServer = stunServerEntry.Text;
            } else {
                settings.StunServer = Settings.DefaultStunServer;
            }

            settings.StartInTray = startInTrayCheckButton.Active;
            settings.AutoConnectCount = autoConnectCountSpinButton.ValueAsInt;

            string avatarDirectory = Path.Combine(Settings.ConfigurationDirectory, "avatars");

            if (Directory.Exists(avatarDirectory) == false)
                Directory.CreateDirectory(avatarDirectory);

            string myAvatarFile = Path.Combine(avatarDirectory, String.Format("{0}.png", nodeid));

            //if (avatarImage.Pixbuf != null)
            if (avatarImage.Sensitive == true)
                avatarImage.Pixbuf.Save(myAvatarFile, "png");
            else
                if (File.Exists(myAvatarFile))
                File.Delete(myAvatarFile);

            settings.Plugins.Clear();
            foreach (object[] row in pluginsListStore) {
                PluginInfo info = (PluginInfo)row[0];
                settings.Plugins.Add(info.FilePath);
            }

            settings.SetFirstRun(false);
            settings.SaveSettings();

            if (Core.AvatarManager != null)
                Core.AvatarManager.UpdateMyAvatar();

            // Advanced -> File Transfer
            settings.EnableGlobalDownloadSpeedLimit = limitDownSpeedCheckButton.Active;
            settings.GlobalDownloadSpeedLimit = Convert.ToInt32(limitDownSpeedSpinButton.Value);

            settings.EnableGlobalUploadSpeedLimit = limitUpSpeedCheckButton.Active;
            settings.GlobalUploadSpeedLimit = Convert.ToInt32(limitUpSpeedSpinButton.Value);

            // Save and go!
            Core.ReloadSettings();
            dialog.Respond ((int)Gtk.ResponseType.Ok);
        }