Esempio n. 1
0
        private void ClickDeleteImage(object sender, RoutedEventArgs e)
        {
            if (view.imageSelection == null || view.imageSelection == "")
            {
                return;
            }
            PersistentData data = new PersistentData(SettingsLoader.GetCurrentSettingsData());

            //dont delete active wallpaper
            if (new Uri(view.imageSelection) == new Uri(Wallpaper.active))
            {
                return;
            }

            for (int i = 0; i < data.imageData.Count; i++)
            {
                if (data.imageData[i].fileName == view.imageSelection)
                {
                    ImageCacheLoader.UnloadImage(data.imageData[i].fileName, (WrapPanel)Scroll.Content);
                    SelectedImageBox.Source = null;
                    PathHandling.DeleteFile(data.imageData[i].fileName);
                    return;
                }
            }
        }
Esempio n. 2
0
        private void DisplayWeatherData()
        {
            WeatherData data = weatherHandler.GetCurrentWeatherData();

            if (data == null)
            {
                return;
            }

            view.city = data.data.name;

            TimeSpan timeZone = TimeSpan.FromSeconds(data.data.timezone);
            string   relative = data.data.timezone >= 0 ? "Timezone: GMT +" : "GMT -";

            relative     += string.Format("{0:D2}:{1:D2}", timeZone.Hours, timeZone.Minutes);
            view.timeZone = relative;

            if (data.data.main.temp == 0)
            {
                view.temperature = "-";
            }
            else
            {
                view.temperature = (int)(data.data.main.temp - 273.15) + "°C";
            }

            view.weatherIcon = PathHandling.GetCorrespondingIconPath(Helperfunctions.ConvertOWMDescrToWeather(data.data.weather[0].description), true);
        }
        public static void LoadSettingsFromDisk()
        {
            data = new PersistentData();
            string path = PathHandling.GetSettingsPath();

            //if file does not exist, create with default settings
            if (!PathHandling.CheckIfFileExists(path))
            {
                FileStream stream = File.Create(path);
                stream.Close();
                data.InitializeToDefaultValues();
                JsonSerializerOptions options = new JsonSerializerOptions
                {
                    WriteIndented = true
                };
                string jsonString = JsonSerializer.Serialize(data, options);
                File.WriteAllText(path, jsonString);
            }
            else
            {
                //file does exist, read file
                string jsonString = File.ReadAllText(path);
                data = JsonSerializer.Deserialize <PersistentData>(jsonString);
            }
            dataLoaded = true;
        }
        public static PersistentData GetCurrentSettingsData()
        {
            string path = PathHandling.GetSettingsPath();

            if (PathHandling.CheckIfFileExists(path))
            {
                string jsonString = File.ReadAllText(path);
                data = JsonSerializer.Deserialize <PersistentData>(jsonString);
                return(data);
            }

            return(null);
        }
        public static void UpdateSettings()
        {
            if (!dataLoaded)
            {
                return;
            }

            if (changedData.imageData.Count != 0)
            {
                data.imageData = changedData.imageData;
            }
            if (changedData.timeZone != "")
            {
                data.timeZone = changedData.timeZone;
            }
            if (changedData.plz != "")
            {
                data.plz = changedData.plz;
            }
            if (changedData.maxImageCount != 0)
            {
                data.maxImageCount = changedData.maxImageCount;
            }
            if (changedData.startWithWindows != null)
            {
                data.startWithWindows = changedData.startWithWindows;
            }
            if (changedData.changeInBackground != null)
            {
                data.changeInBackground = changedData.changeInBackground;
            }
            if (changedData.autoImageSearch != null)
            {
                data.autoImageSearch = changedData.autoImageSearch;
            }
            if (changedData.openWeatherMapAPIKey != "")
            {
                data.openWeatherMapAPIKey = changedData.openWeatherMapAPIKey;
            }

            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented = true
            };
            string jsonString = JsonSerializer.Serialize(data, options);

            File.WriteAllText(PathHandling.GetSettingsPath(), jsonString);
        }
        public static WrapPanel LoadImages()
        {
            string        cachePath = PathHandling.GetCachePath();
            List <string> fileList  = new List <string>();

            fileList.AddRange(Directory.GetFiles(cachePath, "*.jpg"));
            fileList.AddRange(Directory.GetFiles(cachePath, "*.png"));
            fileList.AddRange(Directory.GetFiles(cachePath, "*.bmp"));
            filePaths = fileList.ToArray();

            WrapPanel cachePanel = new WrapPanel();



            if (filePaths.Length == 0)
            {
                Label noCacheLabel = new Label();
                noCacheLabel.Content = "No cached files";
                cachePanel.Children.Add(noCacheLabel);
            }
            else
            {
                cachePanel.SizeChanged += (s, args) => HandleResizing(cachePanel);
                for (int i = 0; i < filePaths.Length; i++)
                {
                    Image img = new Image();
                    img.Width = 300;
                    img.SnapsToDevicePixels = true;
                    BitmapImage image = new BitmapImage();
                    image.BeginInit();
                    image.CacheOption = BitmapCacheOption.OnLoad;
                    image.UriSource   = new Uri(filePaths[i], UriKind.Relative);
                    image.EndInit();
                    img.Source = image;


                    img.MouseDown  += (s, args) => MouseDown(img);
                    img.MouseEnter += (s, args) => MouseEnter(img);
                    img.MouseLeave += (s, args) => MouseLeave(img);

                    cachePanel.Children.Add(img);
                }
            }

            return(cachePanel);
        }
Esempio n. 7
0
 private void ClickImportImages(object sender, RoutedEventArgs e)
 {
     PathHandling.ImportFiles();
     Scroll.Content = null;
     Scroll.Content = ImageCacheLoader.LoadImages();
 }