Exemplo n.º 1
0
        public static void ChangeWallpaper(string path, bool applyChanges)
        {
            try
            {
                // WRONG!!! need to get largeimageURL again from parseJson File bruh

                int    id  = Wallpaper.currentID;
                string url = InfoProcessor.GetLargeImageUrl(id);
                MessageBox.Show("imageURL is: " + url);

                if (!String.IsNullOrEmpty(url))
                {
                    // Create directory if not yet created
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    // downloads the image
                    using (WebClient client = new WebClient())
                    {
                        client.DownloadFile(new Uri(url), path + @"\image1.jpg");
                    }

                    // returns a 1
                    // @"c:\temp\image1.jpg"
                    int result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, path + @"\image1.jpg", SPIF_SENDCHANGE);
                    SetRegistryKeyForWallpaper("WallPaper", path + @"\image1.jpg");
                }
                else
                {
                    MessageBox.Show("Could not apply wallpaper");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("ERROR" + e.Message);
            }
        }
Exemplo n.º 2
0
        private void searchBT_Click(object sender, EventArgs e)
        {
            // check if the query was just checked, and if they search was successful. DONT allow if true

            // Takes the key, search q, orietnation


            string searchQuery = searchQueryTB.Text;
            string orientation;

            if (verticalRB.Checked)
            {
                orientation = "vertical";
            }
            else
            {
                orientation = "horizontal";
            }
            JsonObject response;


            if (!String.IsNullOrEmpty(searchQuery) && !String.IsNullOrWhiteSpace(searchQuery))
            {
                searchQuery = searchQuery.Trim().Replace(" ", "+");
                // removes leading and trailing spaces
                // replaces spaces in string with + easier for Json query

                // calls JsonParser
                // MessageBox.Show(searchQuery + "/'");
                response = InfoProcessor.JsonParser(searchQuery, orientation);

                if (response == null || response.Hits.Count() == 0)
                {
                    MessageBox.Show("Couldn't find any pictures. Try another search term");
                    applyBT.Enabled     = false;
                    randomizeBT.Enabled = false;
                }
                else
                {
                    applyBT.Enabled     = true;
                    randomizeBT.Enabled = true;

                    // Stores the obj that is returned

                    Properties.Settings.Default.imageList = response;
                    Properties.Settings.Default.Save();

                    JsonObject tempObj = Properties.Settings.Default.imageList;

                    /*
                     * foreach (var item in tempObj.Hits)
                     * {
                     *  MessageBox.Show(item.largeImageURL);
                     * }
                     */

                    // Calls UpdatePictureBox

                    pictureBox1.Load(Wallpaper.UpdatePictureBox());
                }
            }
        }