예제 #1
0
        public PhotoScreensaver(List <string> imageFiles, int windowIndex)
        {
            // This is required to get the binding hooked up to the XAML
            DataContext = this;

            InitializeComponent();

            ImageFiles = imageFiles;

            RandomGenerator = new Random(windowIndex * (DateTime.Now.Hour * 1000000 + DateTime.Now.Minute * 10000 + DateTime.Now.Millisecond));

            var screenHeight = this.ActualHeight;
            var screenWidth  = this.ActualWidth;

            this.Height = screenHeight;
            this.Width  = screenWidth;

            // Setup Timer for updating images
            // Timeperiod needs to be configured by settings
            TimerCallback callback    = ShowNextImage;
            object        delay       = SettingsUtilities.LoadSetting("delay");
            int           timerPeriod = 5000;

            if (int.TryParse(delay.ToString(), out int settingsPeriod))
            {
                timerPeriod = settingsPeriod * 1000;
            }

            UpdateTimer = new Timer(callback, null, 0, timerPeriod);
        }
예제 #2
0
        public Settings()
        {
            InitializeComponent();
            var delay = SettingsUtilities.LoadSetting("delay");
            var path  = SettingsUtilities.LoadSetting("photopath");
            var imageDiscoveryMode = SettingsUtilities.LoadSetting("imagediscoverymode");

            if (path != null)
            {
                filePathBox.Text = path.ToString();
            }

            if (delay != null)
            {
                delayTextBox.Text = delay.ToString();
            }
            else
            {
                delayTextBox.Text = "5";
            }

            if (imageDiscoveryMode == null || imageDiscoveryMode.ToString() == "AllFiles")
            {
                DiscoverAllImages.IsChecked = true;
            }
            else if (imageDiscoveryMode.ToString() == "FilesInRandomDirectory")
            {
                ImagesFromRandomDirectory.IsChecked = true;
            }
            else if (imageDiscoveryMode.ToString() == "RandomSelection")
            {
                RandomSelection.IsChecked = true;
            }
        }
예제 #3
0
        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            if (int.TryParse(delayTextBox.Text, out int delay))
            {
                SettingsUtilities.SaveSetting("delay", delay);
            }

            SettingsUtilities.SaveSetting("photopath", filePathBox.Text);

            if (DiscoverAllImages.IsChecked.GetValueOrDefault())
            {
                SettingsUtilities.SaveSetting("imagediscoverymode", "AllFiles");
            }
            else if (ImagesFromRandomDirectory.IsChecked.GetValueOrDefault())
            {
                SettingsUtilities.SaveSetting("imagediscoverymode", "FilesInRandomDirectory");
            }
            else if (RandomSelection.IsChecked.GetValueOrDefault())
            {
                SettingsUtilities.SaveSetting("imagediscoverymode", "RandomSelection");
            }

            System.Windows.Application.Current.Shutdown();
        }
예제 #4
0
        /// <summary>
        /// Shows screen saver by creating one instance of PhotoScreenSaver for each monitor.
        /// </summary>
        /// <remarks>
        /// Uses WinForms's Screen class to get monitor info.
        /// </remarks>
        void ShowScreensaver()
        {
            try
            {
                var log = new System.Text.StringBuilder();

                object rootPath = SettingsUtilities.LoadSetting("photopath");
                if (rootPath == null)
                {
                    MessageBox.Show("No folder with photos has been set. Open settings to add your folder.", "Photos not found!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // Load the image files here so they are available for all screens
                var rootDirectory = new DirectoryInfo(rootPath.ToString());

                var    imageDiscoveryMode   = FileDiscoveryMode.AllFiles;
                object discoveryModeSetting = SettingsUtilities.LoadSetting("imagediscoverymode");

                if (discoveryModeSetting != null)
                {
                    imageDiscoveryMode = (FileDiscoveryMode)Enum.Parse(typeof(FileDiscoveryMode), discoveryModeSetting.ToString());
                }

                var imageFiles = FileDiscovery.DiscoverImageFiles(rootDirectory, imageDiscoveryMode);

                int windowIndex = 1;
                // Creates window on each screen
                foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
                {
                    log.Append($"{screen.DeviceName}:{screen.Bounds}").AppendLine();
                    log.AppendLine("Create Window");
                    var window = new PhotoScreensaver(imageFiles, windowIndex++);

                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                    System.Drawing.Rectangle location = screen.Bounds;

                    //covers entire monitor
                    window.Left   = location.X;
                    window.Top    = location.Y;
                    window.Width  = location.Width;
                    window.Height = location.Height;
                    // Tip, if this isn't the primary window and you set
                    // window.WindowState = WindowState.Maximized;
                    // Before the window has been generated, it'll maximise into the primary

                    // In any case, using normal seems fine.
                    window.WindowState = WindowState.Normal;
                }

                //Show the windows
                foreach (Window window in Current.Windows)
                {
                    log.Append($"Show {window.Width}-{window.Height}-{window.Left}-{window.Top}");
                    window.Show();
                }

                // Debugging
                // System.IO.File.WriteAllText(@"C:\Temp\text.txt", log.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }