Esempio n. 1
0
        public void ProcessPicture(PictureBatch pb, string config)
        {
            List<Picture> lp = pb.GetPictures(1);
            if (!lp.Any()) return;
            Picture p = lp.First();

            //deserialize configuration
            WallpaperSetterSettings wss = null;

            if (!string.IsNullOrEmpty(config)) { wss = WallpaperSetterSettings.LoadFromXML(config); }
            else wss = new WallpaperSetterSettings();

            //set wallpaper style (tiled, centered, etc...)
            //SetWallpaperType(wss.Position);

            //set desktop background color
            //Code came roughly form http://www.tek-tips.com/viewthread.cfm?qid=1449619
            if (wss.BackgroundColorMode == WallpaperSetterSettings.BackgroundColorModes.Specific)
            {
                Desktop.SetDesktopBackgroundColor(wss.Color);
            }
            else if (wss.BackgroundColorMode == WallpaperSetterSettings.BackgroundColorModes.Computed)
            {
                using(Bitmap bmp = (Bitmap)Image.FromFile(p.LocalPath)) {
                    Desktop.SetDesktopBackgroundColor(PictureManager.CalcAverageColor(bmp));
                }
            }

            Desktop.SetWallpaperUsingActiveDesktop(p.LocalPath);
        }
Esempio n. 2
0
        public void ProcessPicture(Pulse.Base.PictureBatch pb, string config)
        {
            List <Picture> lp = pb.GetPictures(1);

            if (!lp.Any())
            {
                return;
            }
            Picture p = lp.First();

            ManualResetEvent mre = new ManualResetEvent(false);

            int stepCount = 13;

            //get color to start with
            Color currentAero = Desktop.GetCurrentAeroColor();
            Color endAeroColor;

            //load file
            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(p.LocalPath)))
            {
                using (Bitmap bmp = (Bitmap)Bitmap.FromStream(ms))
                {
                    //get final color
                    endAeroColor = PictureManager.CalcAverageColor(bmp);
                }
            }

            //build transition
            Color[] transitionColors = CalcColorTransition(currentAero, endAeroColor, stepCount);

            //build timer
            System.Timers.Timer t = new System.Timers.Timer(100);

            int currentStep = 0;

            t.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
            {
                //double check (I've seen cases where timer fires even though currentStep is past {stepCount}
                if (currentStep >= stepCount)
                {
                    mre.Set(); t.Stop(); return;
                }

                //set to next color
                Desktop.SetDwmColor(transitionColors[currentStep]);

                //increment steps and check if we should stop the timer
                currentStep++;
                if (currentStep >= stepCount)
                {
                    mre.Set(); t.Stop();
                }
            };

            t.Start();

            mre.WaitOne();
        }
Esempio n. 3
0
        public void ProcessPicture(PictureBatch pb, string config)
        {
            List<Picture> pics = pb.GetPictures(5);

            if (!pics.Any()) return;

            //for starters lets use an existing image as the backdrop
            Picture pBackdrop = pics.First();
            string savePath = System.IO.Path.Combine(Settings.CurrentSettings.CachePath,
                                                string.Format("{0}.jpg", Guid.NewGuid()));

            List<Rectangle> existingImages = new List<Rectangle>();

            using (Image bmpBackdrop = Image.FromFile(pBackdrop.LocalPath))
            {
                Graphics g = Graphics.FromImage(bmpBackdrop);

                //now get 4 or 5 other pics and strew them about
                foreach (Picture p in pics.Skip(1))
                {
                    Picture pPile = p;
                    using (Bitmap bmpToRotate = (Bitmap)Bitmap.FromFile(pPile.LocalPath))
                    {
                        //draw a 5px white border around the image
                        using (Bitmap bmpWithBorder = PictureManager.AppendBorder(bmpToRotate, 25, Color.White))
                        {

                            using (Bitmap bmpPile = PictureManager.RotateImage(bmpWithBorder, (float)_rand.Next(-30, 30)))
                            {
                                //pick a random x,y coordinate to draw the image, shrink to 25%
                                Rectangle r = Rectangle.Empty;

                                while (r == Rectangle.Empty)
                                {
                                    Rectangle tmp = new Rectangle(_rand.Next(50, bmpBackdrop.Width - 50),
                                                                    _rand.Next(50, bmpBackdrop.Height - 50),
                                                                    Convert.ToInt32(bmpBackdrop.Width * .1),
                                                                    Convert.ToInt32(bmpBackdrop.Height * .1));

                                    if (existingImages.Where(x => Rectangle.Intersect(x, tmp) != Rectangle.Empty).Count() == 0)
                                    {
                                        r = tmp;
                                        existingImages.Add(r);
                                    }
                                }

                                g.DrawImage(bmpPile, r);
                            }
                        }
                    }
                }

                bmpBackdrop.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            Desktop.SetWallpaperUsingActiveDesktop(savePath);
        }
Esempio n. 4
0
        public void ProcessPicture(PictureBatch pb, string config)
        {
            List<Picture> lp = pb.GetPictures(1);
            if (!lp.Any()) return;
            Picture p = lp.First();

            OEMBackgroundManager oembm = new OEMBackgroundManager();
            oembm.SetNewPicture(p);
        }
Esempio n. 5
0
 private void PreviousBatchCleanupRecursive(int myDepth)
 {
     if (myDepth > Settings.CurrentSettings.MaxPreviousPictureDepth)
     {
         _previousBatch = null;
     }
     else
     {
         if (PreviousBatch != null)
         {
             PreviousBatch.PreviousBatchCleanupRecursive(myDepth + 1);
         }
     }
 }
Esempio n. 6
0
        public void ProcessPicture(PictureBatch pb, string config)
        {
            List<Picture> lp = pb.GetPictures(1);
            if (!lp.Any()) return;
            Picture p = lp.First();

            string applScript =
            @"set theUnixPath to POSIX file ""{0}"" as text
            tell application ""Finder""
            set desktop picture to {{theUnixPath}} as alias
            end tell";

            MonoDevelop.MacInterop.AppleScript.Run(string.Format(applScript, p.LocalPath));
        }
Esempio n. 7
0
        public void PreFetchFiles(PictureBatch pb)
        {
            if (pb == null || pb.AllPictures.Count == 0)
            {
                return;
            }

            foreach (PictureList pl in pb.AllPictures)
            {
                foreach (Picture pic in pl.Pictures)
                {
                    GetPicture(pic, true);
                }
            }
        }
Esempio n. 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            PictureSearch ps = new PictureSearch();
            ps.SearchProvider = new ActiveProviderInfo(providerComboBox1.SelectedItem.ToString()) { Active = true, ProviderConfig = _current.SaveConfiguration() };
            ps.MaxPictureCount = (int)numericUpDown1.Value;

            ps.SaveFolder = txtDownloadPath.Text;

            IInputProvider p = ps.SearchProvider.Instance as IInputProvider;
            var pl = p.GetPictures(ps);

            PictureBatch pb = new PictureBatch();
            pb.AllPictures.Add(pl);

            DownloadManager.Current.SaveFolder = txtDownloadPath.Text;
            DownloadManager.Current.PreFetchFiles(pb);
        }
Esempio n. 9
0
        protected void DownloadNextPicture()
        {
            if (CurrentInputProviders.Count == 0)
            {
                return;
            }
            //create the new picture batch
            PictureBatch pb = new PictureBatch()
            {
                PreviousBatch = CurrentBatch
            };

            //create another view of the input providers, otherwise if the list changes
            // because user changes options then it breaks :)
            foreach (KeyValuePair <Guid, ActiveProviderInfo> kvpGAPI in CurrentInputProviders.ToArray())
            {
                ActiveProviderInfo api = kvpGAPI.Value;

                var ps = new PictureSearch()
                {
                    SaveFolder      = Settings.CurrentSettings.CachePath,
                    MaxPictureCount = Settings.CurrentSettings.MaxPictureDownloadCount,
                    SearchProvider  = api,
                    BannedURLs      = Settings.CurrentSettings.BannedImages
                };

                //get new pictures
                PictureList pl = PictureManager.GetPictureList(ps);

                //save to picturebatch
                pb.AllPictures.Add(pl);
            }

            //process downloaded picture list
            ProcessDownloadedPicture(pb);

            //if prefetch is enabled, validate that all pictures have been downloaded
            if (Settings.CurrentSettings.PreFetch)
            {
                DownloadManager.PreFetchFiles(pb);
            }
        }
Esempio n. 10
0
        private void ProcessDownloadedPicture(PictureBatch pb)
        {
            if (pb != null && pb.AllPictures.Any())
            {
                this.CurrentBatch = pb;

                if (BatchChanging != null)
                    BatchChanging(pb);

                //Clear the download Queue
                DownloadManager.ClearQueue();

                List<ManualResetEvent> manualEvents = new List<ManualResetEvent>();

                //call all activated output providers in order
                foreach (var op in Settings.CurrentSettings.ProviderSettings.Values.Where(x => x.Active && x.Instance != null).OrderBy(x => x.ExecutionOrder))
                {
                    if (!typeof(IOutputProvider).IsAssignableFrom(op.Instance.GetType())) continue;
                    //wrap each in a try/catch block so we avoid killing pulse on error
                    try
                    {
                        //check if this can be run in async
                        bool asyncOK = ProviderManager.GetAsyncStatusForType(op.Instance.GetType());

                        IOutputProvider ip = ((IOutputProvider)op.Instance);
                        string config = op.ProviderConfig;

                        if (asyncOK)
                        {
                            ThreadStart threadStarter = () =>
                            {
                                ManualResetEvent mre = new ManualResetEvent(false);
                                manualEvents.Add(mre);
                                try
                                {
                                    ip.ProcessPicture(pb, config);
                                }
                                catch (Exception ex) {
                                    Log.Logger.Write(string.Format("Error processing output plugin '{0}'.  Error: {1}", op.ProviderName, ex.ToString()), Log.LoggerLevels.Warnings);
                                }
                                finally { mre.Set(); }
                            };
                            Thread thread = new Thread(threadStarter);
                            thread.Start();
                        }
                        else
                        {
                            ip.ProcessPicture(pb, config);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.Write(string.Format("Error processing output plugin '{0}'.  Error: {1}", op.ProviderName, ex.ToString()), Log.LoggerLevels.Errors);
                    }
                }
                //make sure async operations finish before
                if (manualEvents.Count > 1)
                {
                    WaitHandle.WaitAll(manualEvents.ToArray(), 60 * 1000);
                }
                else if (manualEvents.Count == 1)
                {
                    manualEvents[0].WaitOne();
                }

                if (BatchChanged != null)
                    BatchChanged(pb);
            }
        }
Esempio n. 11
0
        protected void DownloadNextPicture()
        {
            if (CurrentInputProviders.Count == 0) return;
            //create the new picture batch
            PictureBatch pb = new PictureBatch() {PreviousBatch = CurrentBatch};

            //create another view of the input providers, otherwise if the list changes
            // because user changes options then it breaks :)
            foreach (KeyValuePair<Guid, ActiveProviderInfo> kvpGAPI in CurrentInputProviders.ToArray())
            {
                ActiveProviderInfo api = kvpGAPI.Value;

                var ps = new PictureSearch()
                {
                    SaveFolder = Settings.CurrentSettings.CachePath,
                    MaxPictureCount = Settings.CurrentSettings.MaxPictureDownloadCount,
                    SearchProvider = api,
                    BannedURLs = Settings.CurrentSettings.BannedImages
                };

                //get new pictures
                PictureList pl = PictureManager.GetPictureList(ps);

                //save to picturebatch
                pb.AllPictures.Add(pl);
            }

            //process downloaded picture list
            ProcessDownloadedPicture(pb);

            //if prefetch is enabled, validate that all pictures have been downloaded
            if (Settings.CurrentSettings.PreFetch) DownloadManager.PreFetchFiles(pb);
        }
Esempio n. 12
0
        public void PreFetchFiles(PictureBatch pb)
        {
            if (pb == null || pb.AllPictures.Count == 0) return;

            foreach (PictureList pl in pb.AllPictures.ToList())
            {
                foreach (Picture pic in pl.Pictures.ToList())
                {
                    GetPicture(pic, true);
                }
            }
        }
Esempio n. 13
0
 private void PreviousBatchCleanupRecursive(int myDepth)
 {
     if (myDepth > Settings.CurrentSettings.MaxPreviousPictureDepth)
     {
         _previousBatch = null;
     }
     else
     {
         if(PreviousBatch != null)
             PreviousBatch.PreviousBatchCleanupRecursive(myDepth + 1);
     }
 }
Esempio n. 14
0
 void Runner_PictureChanged(PictureBatch obj)
 {
     this.Invoke((Action)delegate
     {
         banImageToolStripMenuItem.Enabled = obj.CurrentPictures.Count > 0;
         previousPictureToolStripMenuItem.Enabled = (obj.PreviousBatch != null && obj.PreviousBatch.CurrentPictures.Count > 0);
     });
 }
Esempio n. 15
0
        private void ProcessDownloadedPicture(PictureBatch pb)
        {
            if (pb != null && pb.AllPictures.Any())
            {
                this.CurrentBatch = pb;

                if (BatchChanging != null)
                {
                    BatchChanging(pb);
                }

                //Clear the download Queue
                DownloadManager.ClearQueue();

                List <ManualResetEvent> manualEvents = new List <ManualResetEvent>();

                //call all activated output providers in order
                foreach (var op in Settings.CurrentSettings.ProviderSettings.Values.Where(x => x.Active && x.Instance != null).OrderBy(x => x.ExecutionOrder))
                {
                    if (!typeof(IOutputProvider).IsAssignableFrom(op.Instance.GetType()))
                    {
                        continue;
                    }
                    //wrap each in a try/catch block so we avoid killing pulse on error
                    try
                    {
                        //check if this can be run in async
                        bool asyncOK = ProviderManager.GetAsyncStatusForType(op.Instance.GetType());

                        IOutputProvider ip     = ((IOutputProvider)op.Instance);
                        string          config = op.ProviderConfig;

                        if (asyncOK)
                        {
                            ThreadStart threadStarter = () =>
                            {
                                ManualResetEvent mre = new ManualResetEvent(false);
                                manualEvents.Add(mre);
                                try
                                {
                                    ip.ProcessPicture(pb, config);
                                }
                                catch (Exception ex) {
                                    Log.Logger.Write(string.Format("Error processing output plugin '{0}'.  Error: {1}", op.ProviderName, ex.ToString()), Log.LoggerLevels.Warnings);
                                }
                                finally { mre.Set(); }
                            };
                            Thread thread = new Thread(threadStarter);
                            thread.Start();
                        }
                        else
                        {
                            ip.ProcessPicture(pb, config);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.Write(string.Format("Error processing output plugin '{0}'.  Error: {1}", op.ProviderName, ex.ToString()), Log.LoggerLevels.Errors);
                    }
                }
                //make sure async operations finish before
                if (manualEvents.Count > 1)
                {
                    WaitHandle.WaitAll(manualEvents.ToArray(), 60 * 1000);
                }
                else if (manualEvents.Count == 1)
                {
                    manualEvents[0].WaitOne();
                }

                if (BatchChanged != null)
                {
                    BatchChanged(pb);
                }
            }
        }