예제 #1
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);
        }
예제 #2
0
        private void ComboboxUpdated(object sender, SelectionChangedEventArgs args)
        {
            if (view.imageSelection == null || view.imageSelection == "")
            {
                return;
            }
            PersistentData data = new PersistentData(SettingsLoader.GetCurrentSettingsData());

            for (int i = 0; i < data.imageData.Count; i++)
            {
                if (data.imageData[i].fileName == view.imageSelection)
                {
                    DataStructures.ImageData temp = data.imageData[i];
                    temp.targetDaytime         = Helperfunctions.ConvertComboIntToDaytime(view.selectedItemDayTime);
                    temp.targetSeason          = Helperfunctions.ConvertComboIntToSeason(view.selectedItemSeason);
                    temp.targetWeather         = Helperfunctions.ConvertComboIntToWeather(view.selectedItemWeather);
                    data.imageData[i]          = temp;
                    SettingsLoader.changedData = data;
                    SettingsLoader.UpdateSettings();
                }
            }
        }
예제 #3
0
        public void ImageClicked(Image sender)
        {
            string filePath = sender.Source.ToString();

            view.imageSelection = filePath;
            BitmapImage image = new BitmapImage();

            image.BeginInit();
            image.CacheOption = BitmapCacheOption.OnLoad;
            image.UriSource   = new Uri(filePath);
            image.EndInit();
            SelectedImageBox.Source = image;
            PersistentData data = SettingsLoader.GetCurrentSettingsData();

            for (int i = 0; i < data.imageData.Count(); i++)
            {
                if (data.imageData[i].fileName == filePath)
                {
                    //update displayed imagedata
                    view.selectedItemWeather = Helperfunctions.ConvertWeatherEnumToComboInt(data.imageData[i].targetWeather);
                    view.selectedItemDayTime = Helperfunctions.ConvertDayTimeToComboInt(data.imageData[i].targetDaytime);
                    view.selectedItemSeason  = Helperfunctions.ConvertSeasonToComboInt(data.imageData[i].targetSeason);
                    view.chkBxBanUse         = data.imageData[i].banUse;
                    return;
                }
            }

            //file has no data yet, write entry
            DataStructures.ImageData newEntry = new DataStructures.ImageData();
            newEntry.fileName      = filePath;
            newEntry.targetDaytime = DataStructures.enumDayTime.DAWN;
            newEntry.targetSeason  = DataStructures.enumSeason.SPRING;
            newEntry.targetWeather = DataStructures.enumWeather.CLEAR_SKY;
            newEntry.banUse        = false;
            data.imageData.Add(newEntry);
            SettingsLoader.changedData.imageData = data.imageData;
            SettingsLoader.UpdateSettings();
            ImageClicked(sender);
        }
예제 #4
0
        private static void ThreadRun()
        {
            try
            {
                while (true)
                {
                    WeatherData    currentWeather  = weatherHandler.GetCurrentWeatherData();
                    DateTime       now             = DateTime.Now;
                    PersistentData currentSettings = SettingsLoader.GetCurrentSettingsData();

                    //check if transition allowed
                    if ((bool)currentSettings.changeInBackground)
                    {
                        if (!AppFocus.OtherAppIsInFullScreen())
                        {
                            Wait();
                            continue;
                        }
                    }

                    DataStructures.ImageData[] images = currentSettings.imageData.ToArray();

                    DataStructures.enumDayTime targetDayTime = Helperfunctions.ConvertTimeToDayTime(now, currentWeather);
                    DataStructures.enumSeason  targetSeason  = Helperfunctions.ConvertDateToEnumSeason(now);
                    DataStructures.enumWeather targetWeather = Helperfunctions.ConvertOWMDescrToWeather(currentWeather.data.weather[0].description);

                    //filter images to new list after priority
                    //importance desc: season, daytime, weather
                    List <DataStructures.ImageData> filteredImages = new List <DataStructures.ImageData>();
                    for (int ignorance = 0; ignorance <= 3; ignorance++)
                    {
                        for (int i = 0; i < images.Length; i++)
                        {
                            if (images[i].targetSeason == targetSeason)
                            {
                                if (images[i].targetDaytime == targetDayTime)
                                {
                                    if (images[i].targetWeather == targetWeather)
                                    {
                                        if (!images[i].banUse)
                                        {
                                            filteredImages.Add(images[i]);
                                        }
                                    }
                                    else if (ignorance > 0)
                                    {
                                        filteredImages.Add(images[i]);
                                    }
                                }
                                else if (ignorance > 1)
                                {
                                    filteredImages.Add(images[i]);
                                }
                            }
                            else if (ignorance > 2)
                            {
                                filteredImages.Add(images[i]);
                            }
                        }
                        if (filteredImages.Count > 0)
                        {
                            break;
                        }
                    }

                    if (filteredImages.Count == 0)
                    {
                        Wait();
                        continue;
                    }

                    //select random from filtered list
                    Random rnd      = new Random();
                    int    selected = rnd.Next(0, filteredImages.Count);

                    //change background
                    Uri wallFile = new Uri(filteredImages[selected].fileName);
                    Wallpaper.Set(wallFile, Wallpaper.Style.Stretched);

                    Wait();
                }
            } catch
            {
                return;
            }
        }