示例#1
0
        private void buttonMoveImage_Click(object sender, EventArgs e)
        {
            if (selectedImages != null)
            {
                using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
                {
                    dialog.IsFolderPicker = true;

                    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                    {
                        if (WallpaperData.ThemeContainsFolder(dialog.FileName))
                        {
                            HandleImageRenaming(OptionsData.ThemeOptions.AllowTagBasedRenamingForMovedImages, new DirectoryInfo(dialog.FileName));
                        }
                        else
                        {
                            MessageBox.Show("The selected folder is not included in your theme");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("There are no images selected to move");
            }
        }
示例#2
0
        public WallpaperManagerForm()
        {
            WallpaperData.WallpaperManagerForm = this; //? this needs to be at the very front for a few other initializers

            InitializeComponent();

            Application.ApplicationExit += OnApplicationExit;
            this.Load    += OnLoad;
            this.Resize  += OnResize;
            this.Closing += OnClosing;

            DisplayData.Initialize();
            InitializeDisplayTabControl();

            InitializeImageSelector();
            InitializeImageInspector();

            WallpaperPathing.Validate();     // ensures that all needed folders exist
            WallpaperData.Initialize(false); // loads in all necessary data
            OptionsData.Initialize();

            InitializeWallpapers();
            InitializeTimer();
            InitializeKeys();
            InitializeNotifyIcon();
        }
示例#3
0
        private void RemoveImageFolders(string[] folderPaths)
        {
            // output properties
            string invalidFolderPaths = "";
            int    initialLength      = flowLayoutPanelImageFolders.Controls.Count;
            bool   pauseLayout        = folderPaths.Length > 1;

            // loops through selected paths and adds the paths that don't already exist
            if (pauseLayout)
            {
                flowLayoutPanelImageFolders.SuspendLayout();
            }                                                                 // prevents inefficiency by handling controls all at once instead of one-by-one
            foreach (string path in folderPaths)
            {
                if (WallpaperData.RemoveFolder(path)) // if the path exists, remove the checkBox at the index of path
                {
                    flowLayoutPanelImageFolders.Controls.RemoveAt(GetImageFolderPaths().IndexOf(path));
                }
                else
                {
                    invalidFolderPaths += "\n" + path;
                }
            }
            if (pauseLayout)
            {
                flowLayoutPanelImageFolders.ResumeLayout();
            }                                                                // prevents inefficiency by handling controls all at once instead of one-by-one

            // displays a list of folder paths the user attempted to add that already exist
            if (invalidFolderPaths != "")
            {
                MessageBox.Show("The following folders were invalid: " + invalidFolderPaths);
            }
        }
示例#4
0
        private void buttonRankImages_Click(object sender, EventArgs e)
        {
            if (selectedImages != null && selectedImages.Length > 0)
            {
                int newRank;
                try
                {
                    newRank = Int32.Parse(Interaction.InputBox("Enter a new rank for all selected images: ", "Select a new rank"));
                }
                catch // no response
                {
                    return;
                }

                if (newRank >= 0 && newRank <= WallpaperData.GetMaxRank())
                {
                    foreach (string image in selectedImages)
                    {
                        WallpaperData.GetImageData(image).Rank = newRank;
                        UpdateImageRanks();
                    }
                }
                else
                {
                    MessageBox.Show("The selected rank was out of range");
                }
            }
            else
            {
                MessageBox.Show("There are no images selected to rank");
            }
        }
示例#5
0
 private void HandleHotKey()
 {
     // opens the default theme
     if (OptionsData.EnableDefaultThemeHotkey)
     {
         WallpaperData.SaveData(WallpaperPathing.ActiveWallpaperTheme);
         WallpaperData.LoadDefaultTheme();
     }
 }
示例#6
0
        private void buttonSaveTheme_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog dialog = new SaveFileDialog())
            {
                dialog.Title  = "Save data to json";
                dialog.Filter = "Wallpaper Data JSON (*.json) | *.json";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    WallpaperData.SaveData(dialog.FileName);
                }
            }
        }
示例#7
0
        private void HandleImageRenaming(bool allowTagBasedNaming, DirectoryInfo moveDirectory = null)
        {
            List <ImageType> filter = new List <ImageType>();

            if (OptionsData.ThemeOptions.ExcludeRenamingStatic)
            {
                filter.Add(ImageType.Static);
            }
            if (OptionsData.ThemeOptions.ExcludeRenamingGif)
            {
                filter.Add(ImageType.GIF);
            }
            if (OptionsData.ThemeOptions.ExcludeRenamingVideo)
            {
                filter.Add(ImageType.Video);
            }

            switch (WallpaperManagerTools.ChooseSelectionType())
            {
            case SelectionType.Active:
                if (InspectedImage != "")
                {
                    if (WallpaperData.ContainsImage(InspectedImage))
                    {
                        int      imageIndex = selectedImages.IndexOf(InspectedImage);
                        string[] newName    = ImagePathing.RenameImage(InspectedImage, moveDirectory, allowTagBasedNaming);
                        if (newName != null && newName.Length > 0)     // this can occur if the given image is not able to be named
                        {
                            selectedImages[imageIndex] = newName[0];   // there will only be one entry in this array, the renamed image
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid image");
                    }
                }
                else
                {
                    MessageBox.Show("There is no image selected");
                }
                break;

            case SelectionType.All:
                if (MessageBox.Show("Are you sure you want to rename ALL " + selectedImages.Length + " selected images?", "Choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    // Doing this will require a rebuild of the image selector to keep it in tact
                    RebuildImageSelector(ImagePathing.RenameImages(selectedImages, moveDirectory, allowTagBasedNaming), false);
                }
                break;
            }
        }
示例#8
0
        private void buttonLoadTheme_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                // dialog properties
                dialog.Title  = "Select a compatible json file to load";
                dialog.Filter = "Wallpaper Data JSON (*.json) | *.json";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    WallpaperData.LoadData(dialog.FileName);
                    WallpaperPathing.ActiveWallpaperTheme = dialog.FileName;
                }
            }
        }
示例#9
0
        private void imageFolderCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (sender is CheckBox folderCheckBox)
            {
                string folderPath = folderCheckBox.Text;

                if (Directory.Exists(folderPath)) // activate or deactive images within folder based on option selected
                {
                    if (folderCheckBox.Checked)
                    {
                        WallpaperData.ActivateFolder(folderPath);
                    }
                    else
                    {
                        WallpaperData.DeactivateFolder(folderPath);
                    }
                }
                else // folder path does not exist, display error message and as if user wants to remove invalid folder
                {
                    DialogResult result = MessageBox.Show("Invalid folder path encountered: \n" + folderPath + "\n\nRemove folder?", "Invalid Folder Path", MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        int folderIndex = GetImageFolderPaths().IndexOf(folderPath);

                        if (folderIndex != -1) // yes this can happen
                        {
                            flowLayoutPanelImageFolders.Controls.RemoveAt(GetImageFolderPaths().IndexOf(folderPath));
                        }
                        else
                        {
                            MessageBox.Show("Error: This folder was not found in your collection \n (That is, your collection within the application not file explorer)");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("An error occured. Check Box item is invalid");
            }

            flowLayoutPanelImageFolders.Focus(); // prevents the weird behavior where clicking on a checkbox resets the scroll every second
        }
示例#10
0
        private void AddImageFolders(Dictionary <string, bool> imageFolders)
        {
            // output properties
            string duplicateFolderPaths = "";
            int    initialLength        = flowLayoutPanelImageFolders.Controls.Count;
            bool   pauseLayout          = imageFolders.Count > 1;

            // loops through selected paths and adds the paths that don't already exist
            if (pauseLayout)
            {
                flowLayoutPanelImageFolders.SuspendLayout();
            }                                                                 // prevents inefficiency by handling controls all at once instead of one-by-one
            foreach (string path in imageFolders.Keys)
            {
                if (WallpaperData.AddFolder(path))  // if the path does not exist, create a new CheckBox with this path as the text and add it to flowLayoutPanelImageFolders
                {
                    CheckBox newCheckBox = new CheckBox {
                        AutoSize = true, Text = path, ForeColor = Color.White
                    };
                    newCheckBox.Checked = imageFolders[path];
                    //? The below event must be added after declaring Checked since AddFolder() already handles activation
                    newCheckBox.CheckedChanged += imageFolderCheckBox_CheckedChanged;

                    flowLayoutPanelImageFolders.Controls.Add(newCheckBox);
                }
                else
                {
                    duplicateFolderPaths += "\n" + path;
                }
            }
            if (pauseLayout)
            {
                flowLayoutPanelImageFolders.ResumeLayout();
            }                                                                // prevents inefficiency by handling controls all at once instead of one-by-one

            // displays a list of folder paths the user attempted to add that already exist
            if (duplicateFolderPaths != "")
            {
                MessageBox.Show("The following folders already exist: " + duplicateFolderPaths);
            }
        }
示例#11
0
        public void NextWallpaper(int index, bool ignoreErrorMessages)
        {
            if (!WallpaperData.IsLoadingData) // Rank Percentiles won't be properly set-up until after a theme is loaded, which can cause a crash is NextWallpaper is called
            {
                if (!WallpaperData.FileDataIsEmpty())
                {
                    if (!WallpaperData.NoImagesActive() && WallpaperData.GetAllRankedImages().Length != 0)
                    {
                        //? Note that Previous Wallpaper should only be set when Next Wallpaper is updated
                        // Set push the current wallpaper to its corresponding index in previous wallpapers if a wallpaper exists
                        if (WallpaperPathing.ActiveWallpapers[index] != null)
                        {
                            WallpaperPathing.PreviousWallpapers[index].Push(WallpaperPathing.ActiveWallpapers[index]);
                        }

                        ResetTimer(index);
                        SetWallpaper(index, false); // randomize wallpaper will check if it even can randomize the wallpapers first
                    }
                    else
                    {
                        if (!ignoreErrorMessages)
                        {
                            MessageBox.Show("No active wallpapers were found " +
                                            "\n(This can occur is none of your images have been ranked, you can rank them by selecting " +
                                            "the images with the Select Image(s) button)");
                        }
                    }
                }
                else
                {
                    if (!ignoreErrorMessages)
                    {
                        MessageBox.Show("Add some wallpapers first! Use the Add Folder button to add a collection of images that'll be used as potential wallpapers" +
                                        "\n(Before they can be used, you'll have to rank your images. You can rank them by selecting the images the Select Image(s) button)");
                    }
                }
            }
        }
示例#12
0
        private void SetWallpaper(int index, bool ignoreIdenticalWallpapers)
        {
            //-----Set Next Wallpaper-----
            string wallpaperPath = WallpaperPathing.SetNextWallpaperOrder(index, ignoreIdenticalWallpapers);

            //-----Update Notify Icons-----
            string wallpaperName = new FileInfo(wallpaperPath).Name; // pathless string of file name

            if (WallpaperData.ContainsImage(wallpaperPath))
            {
                /*x
                 * wallpaperMenuItems[index].Text = WallpaperData.ContainsImage(wallpaperPath) ?
                 *  index + 1 + " | R: " + WallpaperData.GetImageRank(wallpaperPath) + " | " + wallpaperName :
                 *  index + 1 + " | [NOT FOUND]" + wallpaperName;
                 */

                wallpaperMenuItems[index].Text = index + 1 + " | R: " + WallpaperData.GetImageRank(wallpaperPath) + " | " + wallpaperName;
            }
            else //? this can occur after swapping themes as next wallpaper still holds data from the previous theme
            {
                WallpaperPathing.SetNextWallpaperOrder(index, ignoreIdenticalWallpapers);
            }

            //? without this, if the inspector wasn't open prior to setting a new wallpaper it would never allow it's MvpPlayer to display
            // TODO find a permanent solution to this | Using a different player such as VLC did not work
            WallpaperData.WallpaperManagerForm.FixInspectorPlayer(WallpaperPathing.ActiveWallpapers[index]);

            //-----Update Wallpaper Forms-----
            //? This needs to be above the call to WallpaperForum's SetWallpaper() otherwise the form will call its load event second & override some settings
            //! the moment this is shown, any new MpvPlayers will stop working, only the ones that were started by the player previously will continue to function
            if (!wallpapers[index].Visible)
            {
                wallpapers[index].Show();                             // this is processed only once after the first wallpaper change
            }
            wallpapers[index].SetWallpaper(WallpaperPathing.ActiveWallpapers[index]);
        }
示例#13
0
        public void RebuildImageSelector(string[] selectedImages, bool reverseOrder, int imagesPerPage = 30, int maxLoadedTabs = 25)
        {
            // Cancel the rebuild early if there were no images selected
            if (selectedImages == null)
            {
                MessageBox.Show("No images were selected");
                return;
            }

            // Check for null images (The EnableDetectionOfInactiveImages function is handled further down)
            int invalidCounter = 0;

            foreach (string image in selectedImages)
            {
                if (image == null)
                {
                    invalidCounter++;
                }
            }

            if (invalidCounter == selectedImages.Length)
            {
                MessageBox.Show("No images were selected");
                return;
            }

            if (invalidCounter > 0)
            {
                MessageBox.Show("Error, some of the images selected were null (Does not include disabled images)");
                return;
            }

            ClearImageSelector();

            if (reverseOrder)
            {
                Array.Reverse(selectedImages);               // generally, with the way the collections have been handled an "in-order" result will start from z, or backwards
            }
            // Ensure that only enabled images are selected
            if (!OptionsData.ThemeOptions.EnableDetectionOfInactiveImages)
            {
                HashSet <string> activeSelectedImages = new HashSet <string>();
                foreach (string image in selectedImages)
                {
                    if (WallpaperData.ContainsImage(image)) // nothing's stopping you from seleting any image in the file explorer search
                    {
                        if (WallpaperData.GetImageData(image).Active)
                        {
                            activeSelectedImages.Add(image);
                        }
                    }
                }

                selectedImages = activeSelectedImages.ToArray();
            }

            if (selectedImages.Length == 0)
            {
                MessageBox.Show("No images were selected");
                return;
            }

            int pageCount = (selectedImages.Length / imagesPerPage) + 1;

            for (int i = 0; i < pageCount; i++)
            {
                tabControlImagePages.TabPages.Add((i + 1).ToString() + " Key", (i + 1).ToString());

                TabPage curTab = tabControlImagePages.TabPages[i];
                curTab.BackColor = Color.Black;
            }

            // Finalization
            this.selectedImages = selectedImages;
            this.imagesPerPage  = imagesPerPage;
            this.maxLoadedTabs  = maxLoadedTabs;

            LoadTab(0);
            //tabControlImagePages.Refresh();
            tabControlImagePages.ResumeLayout();

            panelImageSelector.Visible = true;
        }
示例#14
0
        private async void LoadTab(int tabIndex)
        {
            if (tabIndex != -1 && selectedImages != null) // tabIndex will equal -1 when resetting the tabControl | selectedImages may equal null when clearing
            {
                tabControlImagePages.SuspendLayout();
                ClearLoadedImages();

                // Add controls to their panels
                activeTabLayoutPanel?.Dispose();

                SmoothScrollFlowLayoutPanel tabLayoutPanel = new SmoothScrollFlowLayoutPanel();
                tabLayoutPanel.Size       = new Size(tabControlImagePages.Size.Width - 5, tabControlImagePages.Size.Height - tabControlImagePages.ItemSize.Height - 5);
                tabLayoutPanel.AutoScroll = true;
                tabLayoutPanel.HorizontalScroll.Visible = false;
                tabLayoutPanel.MouseClick += tabLayoutPanel_MouseClick;

                if (tabControlImagePages.TabPages[tabIndex].Controls.Count > 0)
                {
                    tabControlImagePages.TabPages[tabIndex].Controls.RemoveAt(0);
                }

                tabControlImagePages.TabPages[tabIndex].Controls.Add(tabLayoutPanel); // panel added here

                // Load in image editors
                int indexOffset = tabIndex * imagesPerPage;
                int maxIndex    = imagesPerPage + indexOffset - 1;
                maxIndex = maxIndex < selectedImages.Length ? maxIndex : selectedImages.Length;

                string invalidImageSelection        = "The following images are not included in your theme: ";
                string invalidImageSelectionDefault = invalidImageSelection;

                tabLayoutPanel.SuspendLayout();
                for (int i = indexOffset; i <= maxIndex; i++)
                {
                    if (i != selectedImages.Length)
                    {
                        if (selectedImages[i] != null && File.Exists(selectedImages[i]) && WallpaperData.ContainsImage(selectedImages[i]))
                        {
                            tabLayoutPanel.Controls.Add(new ImageEditorControl(WallpaperData.GetImageData(selectedImages[i]), false));
                        }
                        else
                        {
                            invalidImageSelection += "\n" + selectedImages[i];
                        }
                    }
                }

                //?tabLayoutPanel.UpdateScroll(); Used in the FastScrollFlowLayoutPanel version of the tabLayoutPanel, may swap back to this in the future
                tabLayoutPanel.ResumeLayout();

                // Loading all of these at the same time is not ideal
                await Task.Run(() =>
                {
                    ImageEditorControl[] imageEditorControls = tabLayoutPanel.Controls.OfType <ImageEditorControl>().ToArray();

                    foreach (ImageEditorControl control in imageEditorControls)
                    {
                        LoadImage(control, control.ImageData.Path);
                    }
                });

                tabLayoutPanel.Focus(); // clicking on the Tab Control to change pages loses the focus of the panel
                activeTabLayoutPanel = tabLayoutPanel;
                //tabControlImagePages.Refresh();
                tabControlImagePages.ResumeLayout();

                if (invalidImageSelectionDefault != invalidImageSelection)
                {
                    MessageBox.Show(invalidImageSelection);
                }
            }
        }
示例#15
0
 private void buttonUpdateTheme_Click(object sender, EventArgs e)
 {
     WallpaperData.EvaluateImageFolders(); // scans for new images
     WallpaperData.SaveData(WallpaperPathing.ActiveWallpaperTheme);
 }