예제 #1
0
 private FlickrNet.Photoset SafelyCreateNewAlbum(Album album)
 {
     FlickrNet.Photoset photoset;
     for (int i = 0; i < MAXTRIES; i++)
     {
         try {
             photoset = flickrObj.PhotosetsCreate(album.Title,
                                                  album.Desc, album.PrimaryPhotoid);
             return(photoset);
         } catch (FlickrNet.FlickrApiException e) {
             // Status quo, if can't create any new sets. Let the information
             // be there, so that we can retry.
             if (e.Code == 3)
             {
                 Gtk.Application.Invoke(delegate {
                     DeskFlickrUI.GetInstance().ShowMessageDialog(
                         "Can't create a new set. You've reached the maximum number"
                         + " of photosets limit.");
                 });
                 return(null); // No need to retry.
             }
             if (i == MAXTRIES - 1)
             {
                 PrintException(e);
                 if (e.Code == CODE_TIMEOUT)
                 {
                     _isConnected = false;
                 }
                 return(null);
             }
         }
         continue;
     }
     throw new Exception("FlickrCommunicator: CreateNewAlbum unreachable code");
 }
예제 #2
0
    public void AttemptConnection()
    {
        string token = PersistentInformation.GetInstance().Token;

        try {
            flickrObj = new Flickr(_apikey, _secret, token);
            flickrObj.TestLogin();
            _isConnected = true;
        } catch (FlickrNet.FlickrApiException e) {
            PrintException(e);
            _isConnected = false;
            return;
        }

        Gtk.Application.Invoke(delegate {
            if (_isConnected)
            {
                DeskFlickrUI.GetInstance().SetStatusLabel("Login Successful.");
            }
            else
            {
                DeskFlickrUI.GetInstance().SetStatusLabel("Unable to connect.");
            }
        });
        UpdateUIAboutConnection();
    }
예제 #3
0
    private void SyncBlogPosts()
    {
        ArrayList blogentries = PersistentInformation.GetInstance().GetAllBlogEntries();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Posting blog entries...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(blogentries.Count);
        });
        foreach (BlogEntry blogentry in blogentries)
        {
            string desc = blogentry.Desc
                          + "\nPosted using <a href='http://code.google.com/p/dfo/'>"
                          + "Desktop Flickr Organizer</a>.";
            try {
                if (flickrObj.BlogPostPhoto(blogentry.Blogid, blogentry.Photoid,
                                            blogentry.Title, desc))
                {
                    PersistentInformation.GetInstance().DeleteEntryFromBlog(
                        blogentry.Blogid, blogentry.Photoid);
                }
            } catch (FlickrNet.FlickrApiException e) {
                Gtk.Application.Invoke(delegate {
                    string operation = "Posting '" + blogentry.Title + "' to blog.";
                    string message   = operation + "\n Got response: " + e.Message;
                    DeskFlickrUI.GetInstance().ShowMessageDialog(message);
                });
            }
            DelegateIncrementProgressBar();
        }
    }
예제 #4
0
    private void SyncDirtyAlbumsToServer()
    {
        ArrayList albums = PersistentInformation.GetInstance().GetDirtyAlbums(true);

        if (albums.Count == 0)
        {
            return;
        }
        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Syncing sets to server...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(albums.Count);
        });
        foreach (Album album  in albums)
        {
            DelegateIncrementProgressBar();
            flickrObj.PhotosetsEditMeta(album.SetId, album.Title, album.Desc);
            // Sync the primary photo id of the set.
            ArrayList photoids =
                PersistentInformation.GetInstance().GetPhotoIdsForAlbum(album.SetId);
            // If no photos inside set, delete the set.
            if (photoids.Count == 0)
            {
                flickrObj.PhotosetsDelete(album.SetId);
                PersistentInformation.GetInstance().DeleteAlbum(album.SetId);
            }
            else
            {
                flickrObj.PhotosetsEditPhotos(album.SetId, album.PrimaryPhotoid,
                                              Utils.GetDelimitedString(photoids, ","));
                PersistentInformation.GetInstance().SetAlbumDirty(album.SetId, false);
            }
        }
    }
예제 #5
0
    private void SyncDirtyCommentsToServer()
    {
        ArrayList comments = PersistentInformation.GetInstance().GetDirtyComments();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Syncing comments to server...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(comments.Count);
        });
        foreach (Comment comment in comments)
        {
            if (comment.CommentId.IndexOf("new:") > -1)           // new comment
            {
                string newcommentid = flickrObj.PhotosCommentsAddComment(comment.PhotoId,
                                                                         comment.CommentHtml);
                if (newcommentid != null && !newcommentid.Trim().Equals(""))
                {
                    // Added the comment.
                    PersistentInformation.GetInstance().DeleteComment(comment.PhotoId, comment.CommentId);
                    PersistentInformation.GetInstance().InsertComment(comment.PhotoId,
                                                                      newcommentid, comment.CommentHtml, comment.UserName);
                }
            }
            else             // edited comment.
            {
                flickrObj.PhotosCommentsEditComment(comment.CommentId, comment.CommentHtml);
                PersistentInformation.GetInstance().SetCommentDirty(comment.PhotoId,
                                                                    comment.CommentId, false);
            }
            DelegateIncrementProgressBar();
        }
    }
예제 #6
0
    private UploadFileChooserUI()
    {
        Glade.XML gxml = new Glade.XML(null, "organizer.glade", "filechooserdialog1", null);
        gxml.Autoconnect(this);
        _job           = new ThreadStart(ProcessThumbnail);
        _previewthread = new Thread(_job);

        label16.WidthRequest = eventbox7.WidthRequest;

        eventbox7.ModifyBg(Gtk.StateType.Normal, bgcolor);
        eventbox8.ModifyBg(Gtk.StateType.Normal, bgcolor);
        eventbox9.ModifyBg(Gtk.StateType.Normal, bgcolor);

        filechooserdialog1.Title = "Select files to upload";
        filechooserdialog1.SetIconFromFile(DeskFlickrUI.ICON_PATH);
        filechooserdialog1.SetFilename(PersistentInformation.GetInstance().UploadFilename);
        filechooserdialog1.SelectMultiple = true;

        FileFilter imagefilter = new FileFilter();

        imagefilter.AddMimeType("image/jpeg");
        imagefilter.AddMimeType("image/png");
        filechooserdialog1.Filter = imagefilter;

        filechooserdialog1.SelectionChanged += new EventHandler(OnFileSelectedChanged);
        filechooserdialog1.FileActivated    += new EventHandler(OnOpenButtonClicked);
        button10.Clicked += new EventHandler(OnOpenButtonClicked);
        button11.Clicked += new EventHandler(OnCancelButtonClicked);
        DeskFlickrUI.GetInstance().SetUploadWindow(false);
        filechooserdialog1.ShowAll();
    }
예제 #7
0
 private void UpdateUploadStatus()
 {
     FlickrNet.UserStatus userstatus              = flickrObj.PeopleGetUploadStatus();
     PersistentInformation.GetInstance().UserId   = userstatus.UserId;
     PersistentInformation.GetInstance().UserName = userstatus.UserName;
     Gtk.Application.Invoke(delegate {
         DeskFlickrUI.GetInstance().SetUploadStatus(
             userstatus.BandwidthMax, userstatus.BandwidthUsed);
     });
 }
예제 #8
0
    // Tried to use OnUploadProgress event handler provided, but it proved
    // to be no good use. The bytes uploaded would reach the file size in
    // no time, but then it would take long to finish the upload. Maybe its
    // practically just tracking the bytes "read", rather than "uploaded".
    private void CheckPhotosToUpload()
    {
        ArrayList photos = PersistentInformation.GetInstance().GetPhotosToUpload();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Uploading photos...");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(photos.Count);
        });

        foreach (Photo photo in photos)
        {
            // Check if the file exists.
            string             filename = photo.Id;
            System.IO.FileInfo finfo    = new System.IO.FileInfo(filename);
            if (!finfo.Exists)
            {
                continue;
            }

            Gtk.Application.Invoke(delegate {
                DeskFlickrUI.GetInstance().SetStatusLabel(
                    String.Format("Uploading file {0}", filename));
            });

            // Upload the photo now.
            // Set the title to photo name. Set the photo to private mode for now.
            // Add a tag "dfo" to uploaded photo.
            string newphotoid = flickrObj.UploadPicture(
                filename, photo.Title, photo.Description,
                Utils.GetDelimitedString(photo.Tags, ","),
                (photo.IsPublic == 1), (photo.IsFamily == 1),
                (photo.IsFriend == 1));
            if (newphotoid == null)
            {
                continue;
            }

            // The photo has been successfully uploaded.
            DelegateIncrementProgressBar();
            PersistentInformation.GetInstance().DeleteThumbnail(photo.Id);
            PersistentInformation.GetInstance().DeleteSmallImage(photo.Id);
            PersistentInformation.GetInstance().DeleteEntryFromUpload(filename);
            // Try if we can retrieve the photo information, this could be a bit
            // to early for the information to be spread out to the server
            // clusters. Keep our fingers crossed!
            Photo p = RetrievePhoto(newphotoid);
            if (p == null)
            {
                continue;
            }
            PersistentInformation.GetInstance().UpdatePhoto(p);
            CheckProceedRoutinePermission();
        }
    }
예제 #9
0
 private void OnCancelButtonClicked(object sender, EventArgs args)
 {
     if (_processfilesthread != null)
     {
         _processfilesthread.Abort();
         DeskFlickrUI.GetInstance().UpdateToolBarButtons();
         DeskFlickrUI.GetInstance().RefreshUploadPhotos();
     }
     filechooserdialog1.Destroy();
     DeskFlickrUI.GetInstance().SetUploadWindow(true);
 }
예제 #10
0
 // To be run in a thread by OnOpenButtonClicked method.
 private void ProcessFiles()
 {
     string[] filenames = null;
     filenames = filechooserdialog1.Filenames;
     if (filenames == null)
     {
         return;
     }
     PersistentInformation.GetInstance().UploadFilename = filenames[0];
     Gdk.Pixbuf thumbnail;
     Gdk.Pixbuf smallimage;
     Gdk.Pixbuf sqimage;
     Gtk.Application.Invoke(delegate {
         progressbar3.Adjustment.Lower = 0;
         progressbar3.Adjustment.Upper = filenames.Length;
         progressbar3.Adjustment.Value = 0;
         progressbar3.Text             = "Processing files...";
         button10.Sensitive            = false;
     });
     foreach (string filename in filenames)
     {
         Gtk.Application.Invoke(delegate {
             progressbar3.Adjustment.Value += 1;
         });
         try {
             Gdk.Pixbuf buf = new Gdk.Pixbuf(filename);
             thumbnail  = buf.ScaleSimple(75, 75, Gdk.InterpType.Bilinear);
             smallimage = buf.ScaleSimple(240, 180, Gdk.InterpType.Bilinear);
             sqimage    = buf.ScaleSimple(150, 150, Gdk.InterpType.Bilinear);
             buf.Dispose();
         } catch (GLib.GException) {
             continue;
             // Couldn't process the file.
         }
         Gtk.Application.Invoke(delegate {
             label16.Markup = GetInfo(filename);
             image6.Pixbuf  = sqimage;
         });
         PersistentInformation.GetInstance().SetThumbnail(filename, thumbnail);
         thumbnail.Dispose();
         PersistentInformation.GetInstance().SetSmallImage(filename, smallimage);
         smallimage.Dispose();
         PersistentInformation.GetInstance().InsertEntryToUpload(filename);
     }
     Gtk.Application.Invoke(delegate {
         DeskFlickrUI.GetInstance().UpdateToolBarButtons();
         DeskFlickrUI.GetInstance().RefreshUploadPhotos();
         filechooserdialog1.Destroy();
         DeskFlickrUI.GetInstance().SetUploadWindow(true);
     });
 }
예제 #11
0
    private void ShowInformationForCurrentPhoto()
    {
        DeskFlickrUI.SelectedPhoto sel =
            (DeskFlickrUI.SelectedPhoto)_selectedphotos[_curphotoindex];
        Photo p = sel.photo;

        entry1.Text           = p.Title;
        textview5.Buffer.Text = p.Description;

        _ignorechangedevent = true;
        {
            combobox1.Active      = GetIndexOfPrivacyBox(p);
            combobox2.Active      = GetIndexOfLicenseBox(p);
            textview3.Buffer.Text = Utils.GetDelimitedString(p.Tags, " ");
        }
        _ignorechangedevent = false;

        if (_isconflictmode)
        {
            Photo  serverphoto = DeskFlickrUI.GetInstance().GetServerPhoto(p.Id);
            string text        = String.Format(
                "Title:\t\t{0}\n"
                + "Description:\t{1}\n"
                + "Visibility:\t\t{2}\n"
                + "License:\t\t{3}\n"
                + "Tags:\t\t{4}\n",
                serverphoto.Title, serverphoto.Description,
                serverphoto.PrivacyInfo, serverphoto.LicenseInfo,
                serverphoto.TagString);
            textview4.Buffer.Text = text;
            HighlightDifferences(serverphoto, p);
        }

        if (_isblogmode)
        {
            BlogEntry blogentry = ((DeskFlickrUI.BlogSelectedPhoto)sel).blogentry;
            entry4.Text           = blogentry.Title;
            textview7.Buffer.Text = blogentry.Desc;
        }

        image3.Sensitive = true;
        image3.Pixbuf    = p.SmallImage;
        label7.Sensitive = true;
        SetTitleTopRight(p.Title);
        SetPhotoLink(p.Id);
        button9.Sensitive = !_isuploadmode && IsPhotoEdited(p);
        PopulateComments(p.Id);
        SetActivateComments(!_isuploadmode);
    }
예제 #12
0
    private void CheckPhotosToDelete()
    {
        ArrayList photoids = PersistentInformation.GetInstance().GetPhotoIdsDeleted();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Deleting photos...");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(photoids.Count);
        });
        foreach (String photoid in photoids)
        {
            SafelyDeletePhotoFromServer(photoid);
            PersistentInformation.GetInstance().DeletePhoto(photoid);
            DelegateIncrementProgressBar();
        }
    }
예제 #13
0
 private void UpdateUIAboutConnection()
 {
     Gtk.Application.Invoke(delegate {
         int status = 0;
         if (_isConnected)
         {
             status = 1;
         }
         if (_isbusy)
         {
             status = 2;
         }
         DeskFlickrUI.GetInstance().SetIsConnected(status);
         DeskFlickrUI.GetInstance().SetSensitivityConnectionButtons(!_isbusy);
     });
 }
예제 #14
0
    private void SyncDeletedCommentsToServer()
    {
        ArrayList comments = PersistentInformation.GetInstance().GetDeletedComments();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Syncing deleted comments to server...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(comments.Count);
        });
        foreach (Comment comment in comments)
        {
            flickrObj.PhotosCommentsDeleteComment(comment.CommentId);
            PersistentInformation.GetInstance().DeleteComment(comment.PhotoId,
                                                              comment.CommentId);
            DelegateIncrementProgressBar();
        }
    }
예제 #15
0
    private void SyncNewAlbumsToServer()
    {
        ArrayList albums = PersistentInformation.GetInstance().GetNewAlbums();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Creating sets on server...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(albums.Count);
        });
        foreach (Album album in albums)
        {
            Gtk.Application.Invoke(delegate {
                DeskFlickrUI.GetInstance().SetStatusLabel(
                    "Creating sets on server... " + album.Title);
            });
            DelegateIncrementProgressBar();
            FlickrNet.Photoset photoset = SafelyCreateNewAlbum(album);
            if (photoset == null)
            {
                continue;
            }
            ArrayList photoids = PersistentInformation.GetInstance()
                                 .GetPhotoIdsForAlbum(album.SetId);
            // Remove the old fake album entry.
            PersistentInformation.GetInstance().DeleteAlbum(album.SetId);
            PersistentInformation.GetInstance().DeleteAllPhotosFromAlbum(album.SetId);
            // Create and add a new one.
            Album newalbum = new Album(photoset.PhotosetId, album.Title,
                                       album.Desc, album.PrimaryPhotoid);
            PersistentInformation.GetInstance().InsertAlbum(newalbum);
            // Set the album dirty, in case the photosetseditphotos operation
            // fails, in this round of updates. Then, we'll retry the updates
            // next time, without they being overridden.
            PersistentInformation.GetInstance().SetAlbumDirty(newalbum.SetId, true);
            foreach (string photoid in photoids)
            {
                PersistentInformation.GetInstance().AddPhotoToAlbum(photoid, newalbum.SetId);
            }
            // Add the photos to the new album.
            flickrObj.PhotosetsEditPhotos(newalbum.SetId, newalbum.PrimaryPhotoid,
                                          Utils.GetDelimitedString(photoids, ","));
            PersistentInformation.GetInstance().SetAlbumDirty(newalbum.SetId, false);
        }
    }
예제 #16
0
    // This method is run through a thread.
    private void ProcessThumbnail()
    {
        Gtk.Application.Invoke(delegate {
            progressbar3.Text = "Processing...";
            //progressbar3.PulseStep = 0.3;
            //progressbar3.Pulse();
        });
        Thread.Sleep(700);           // wait for 0.7 seconds. This way, if the user gets
        // jumpy and selects a lot of files quickly, the thread would be
        // interrupted before it reaches the processing of file stage, hence
        // saving processing power and RAM consumption.
        string[] filenames = filechooserdialog1.Filenames;
        if (filenames == null || filenames.Length == 0)
        {
            return;
        }
        string filename = filenames[filenames.Length - 1];

        if (System.IO.Directory.Exists(filename))
        {
            _buf = DeskFlickrUI.GetInstance().GetDFOThumbnail();
        }
        else
        {
            try {
                // Scalesimple creates a new pixbuf buffer, with the scaled
                // version of the image. If we do, _buf = _buf.ScaleSimple, the
                // originally loaded buffer remains referenced, and hence,
                // causes memory leak. Instead, we use a different buffer to load
                // file, and then dispose it once the image is scaled.
                Gdk.Pixbuf original = new Gdk.Pixbuf(filename);
                _buf = original.ScaleSimple(150, 150, Gdk.InterpType.Bilinear);
                original.Dispose();
            } catch (GLib.GException) {
                _buf = DeskFlickrUI.GetInstance().GetDFOThumbnail();
            }
        }
        Gtk.Application.Invoke(delegate {
            image6.Pixbuf     = _buf;
            label16.Markup    = GetInfo(filename);
            progressbar3.Text = "";
        });
    }
예제 #17
0
    private void UpdateStream()
    {
        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Updating photo stream...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
        });
        FlickrNet.PhotoSearchOptions options = new PhotoSearchOptions();
        options.UserId  = "me";
        options.Extras  = PhotoSearchExtras.LastUpdated;
        options.PerPage = 500;
        options.Page    = 1;
        Photos photos = flickrObj.PhotosSearch(options);

        CheckProceedRoutinePermission();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetLimitsProgressBar((int)photos.TotalPhotos);
        });
        ArrayList serverphotoids = new ArrayList();

        UpdatePhotos(photos.PhotoCollection, ref serverphotoids);
        for (int curpage = 2; curpage <= photos.TotalPages; curpage++)
        {
            options.Page = curpage;
            photos       = flickrObj.PhotosSearch(options);
            UpdatePhotos(photos.PhotoCollection, ref serverphotoids);
            CheckProceedRoutinePermission();
        }
        // Delete the photos not present on server.
        foreach (string photoid in
                 PersistentInformation.GetInstance().GetAllPhotoIds())
        {
            // DeletePhoto method takes care of deleting the tags as well.
            if (serverphotoids.Contains(photoid))
            {
                continue;
            }
            PersistentInformation.GetInstance().DeletePhoto(photoid);
        }
    }
예제 #18
0
    private void SyncPhotosDeletedFromPools()
    {
        ArrayList entries = PersistentInformation.GetInstance().GetPhotosDeletedFromPools();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Syncing photos deleted from pools...");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(entries.Count);
        });
        foreach (PersistentInformation.Entry entry in entries)
        {
            DelegateIncrementProgressBar();
            string groupid   = entry.entry1;
            string photoid   = entry.entry2;
            Photo  p         = PersistentInformation.GetInstance().GetPhoto(photoid);
            string pooltitle = PersistentInformation.GetInstance().GetPoolTitle(groupid);
            string operation = String.Format(
                "Deleting '{0}' from group pool '{1}'.", p.Title, pooltitle);
            Gtk.Application.Invoke(delegate {
                DeskFlickrUI.GetInstance().SetStatusLabel(
                    "Syncing photos deleted from pools... " + operation);
            });
            try {
                flickrObj.GroupPoolRemove(photoid, groupid); //photoid, groupid
            } catch (FlickrNet.FlickrApiException e) {
                if (e.Code == 2)                             // not present in the pool.
                {
                    PersistentInformation.GetInstance().DeletePhotoFromPool(photoid, groupid);
                }
                else
                {
                    Gtk.Application.Invoke(delegate {
                        string message = operation + "\n Got response: " + e.Message;
                        DeskFlickrUI.GetInstance().ShowMessageDialog(message);
                    });
                }
                continue;
            }
            PersistentInformation.GetInstance().DeletePhotoFromPool(photoid, groupid);
        }
    }
예제 #19
0
    private void UpdateBlogs()
    {
        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Updating blogs...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
        });
        FlickrNet.Blog[] blogs = SafelyGetBlogList();
        if (blogs == null)
        {
            UpdateUIAboutConnection();
            return;
        }
        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(blogs.Length);
        });
        ArrayList blogids = new ArrayList();

        foreach (PersistentInformation.Entry entry
                 in PersistentInformation.GetInstance().GetAllBlogs())
        {
            blogids.Add(entry.entry1);
        }
        PersistentInformation.GetInstance().DeleteAllBlogs();
        foreach (FlickrNet.Blog blog in blogs)
        {
            if (blog.NeedsPassword == 0)
            {
                PersistentInformation.GetInstance().InsertBlog(blog.BlogId, blog.BlogName);
            }
            DelegateIncrementProgressBar();
        }
        foreach (string blogid in blogids)
        {
            if (!PersistentInformation.GetInstance().HasBlog(blogid))
            {
                PersistentInformation.GetInstance().DeleteAllEntriesFromBlog(blogid);
            }
        }
    }
예제 #20
0
    private void UpdatePhotosForAlbum(Album album)
    {
        // Don't update photos if the album is dirty, we need to flush our
        // changes first.
        if (PersistentInformation.GetInstance().IsAlbumDirty(album.SetId))
        {
            return;
        }

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel(
                String.Format("Retrieving photos for set: {0}", album.Title));
            DeskFlickrUI.GetInstance().SetProgressBarText("");
        });
        // Step 1: Get list of photos.
        FlickrNet.PhotoCollection photos = SafelyGetPhotos(album);
        if (photos == null)
        {
            UpdateUIAboutConnection();
            return;
        }

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(photos.Length);
        });

        // Step 2: Link the photos to the set, in the database.
        PersistentInformation.GetInstance().DeleteAllPhotosFromAlbum(album.SetId);
        foreach (FlickrNet.Photo p in photos)
        {
            DelegateIncrementProgressBar();
            if (!PersistentInformation.GetInstance().HasPhoto(p.PhotoId))
            {
                continue;
            }
            PersistentInformation.GetInstance().AddPhotoToAlbum(p.PhotoId, album.SetId);
        }
    }
예제 #21
0
 public void OnSaveButtonClicked(object o, EventArgs args)
 {
     PersistentInformation.GetInstance().SaveAlbum(_album, _isnew);
     window3.Destroy();
     DeskFlickrUI.GetInstance().PopulateAlbums();
 }
예제 #22
0
    private void CheckPhotosToDownload()
    {
        ArrayList entries = PersistentInformation.GetInstance().GetEntriesToDownload();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Downloading photos...");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(entries.Count);
        });
        foreach (PersistentInformation.Entry entry in entries)
        {
            string          photoid    = entry.entry1;
            string          foldername = entry.entry2;
            FlickrNet.Sizes photosizes = SafelyGetSizes(photoid);
            if (photosizes == null)
            {
                continue;
            }
            Photo p = PersistentInformation.GetInstance().GetPhoto(photoid);
            Gtk.Application.Invoke(delegate {
                string label = String.Format(
                    "Downloading {0}... Saving to {1}", p.Title, foldername);
                DeskFlickrUI.GetInstance().SetStatusLabel(label);
            });

            Hashtable table = new Hashtable();
            foreach (FlickrNet.Size size in photosizes.SizeCollection)
            {
                table.Add(size.Label.ToLower(), size.Source);
            }
            string sourceurl;
            if (table.ContainsKey("original"))
            {
                sourceurl = (string)table["original"];
            }
            else if (table.ContainsKey("large"))
            {
                sourceurl = (string)table["large"];
            }
            else if (table.ContainsKey("medium"))
            {
                sourceurl = (string)table["medium"];
            }
            else
            {
                PersistentInformation.GetInstance().DeleteEntryFromDownload(photoid);
                continue;
            }
            string safetitle = p.Title.Replace("/", "");
            string extension = sourceurl.Substring(sourceurl.LastIndexOf('.'));
            string filename  = String.Format(
                "{0}/{1}_{2}{3}", foldername, safetitle, p.Id, extension);
            Utils.IfExistsDeleteFile(filename);
            try {
                webclient.DownloadFile(sourceurl, filename);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                continue;
            }
            DelegateIncrementProgressBar();
            PersistentInformation.GetInstance().DeleteEntryFromDownload(photoid);
            CheckProceedRoutinePermission();
        }
    }
예제 #23
0
    /*
     * This method is the one which takes care of all the sync operations,
     * uploading and downloading of photos. Call it the master method,
     * everything else follows.
     */
    public void RoutineCheck()
    {
        _isbusy = true;
        try {
            UpdateUIAboutConnection();
            CheckProceedRoutinePermission();

            UpdateUploadStatus();
            CheckProceedRoutinePermission();

            UpdateStream();
            PersistentInformation.GetInstance().DeleteAllOriginalPhotos();
            CheckProceedRoutinePermission();

            UpdateAlbums();
            CheckProceedRoutinePermission();

            foreach (Album a in PersistentInformation.GetInstance().GetAlbums())
            {
                if (PersistentInformation.GetInstance().IsAlbumNew(a.SetId))
                {
                    continue;
                }
                UpdatePhotosForAlbum(a);
                CheckProceedRoutinePermission();
            }
            Gtk.Application.Invoke(delegate {
                if (DeskFlickrUI.GetInstance().IsAlbumTabSelected())
                {
                    DeskFlickrUI.GetInstance().RefreshLeftTreeView();
                }
            });

            UpdatePools();
            CheckProceedRoutinePermission();

            UpdateBlogs();
            CheckProceedRoutinePermission();

            // Sync photos at the end. It takes time for the changes done to server
            // to propagate. If we keep these sync methods before updates, then
            // the changes would be synced to server, however, the server would
            // respond back with the old values to update methods. So, the application
            // would end up removing the changes, and only show them again at
            // the next update.
            SyncDirtyPhotosToServer();
            CheckProceedRoutinePermission();

            SyncDeletedCommentsToServer();
            CheckProceedRoutinePermission();

            SyncDirtyCommentsToServer();
            CheckProceedRoutinePermission();

            SyncNewAlbumsToServer();
            CheckProceedRoutinePermission();

            SyncDirtyAlbumsToServer();
            Gtk.Application.Invoke(delegate {
                DeskFlickrUI.GetInstance().UpdateToolBarButtons();
            });
            CheckProceedRoutinePermission();

            SyncPhotosDeletedFromPools();
            CheckProceedRoutinePermission();

            SyncPhotosAddedToPools();
            CheckProceedRoutinePermission();

            SyncBlogPosts();
            CheckProceedRoutinePermission();

            CheckPhotosToDownload();
            CheckProceedRoutinePermission();

            CheckPhotosToUpload();
            CheckProceedRoutinePermission();

            // Flickr server never catches up with updates soon. So, we'll
            // do all the album updates required by photo deletion on our side,
            // and then just flush them to server. Hope they spread around by
            // the next time this routine runs.
            CheckPhotosToDelete();
            Gtk.Application.Invoke(delegate {
                DeskFlickrUI.GetInstance().RefreshLeftTreeView();
            });
        } catch (Exception e) {
            if (!e.Message.Equals(ROUTINE_EXCEPTION_MSG))
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            else
            {
                _stopSync = false;
            }
        }
        _isbusy = false;
        UpdateUIAboutConnection();
    }
예제 #24
0
    private void UpdateAlbums()
    {
        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Updating photo sets...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
        });

        // Step 1: Retrieve album list.
        FlickrNet.Photoset[] sets = SafelyGetAlbumList();
        if (sets == null)
        {
            UpdateUIAboutConnection();
            return;
        }

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(sets.Length);
        });

        ArrayList setids = new ArrayList();

        // Iterate through the sets, and retrieve their primary photos.
        foreach (Photoset s in sets)
        {
            DelegateIncrementProgressBar();
            setids.Add(s.PhotosetId);
            // Skip the checkings, if the album is dirty.
            if (PersistentInformation.GetInstance().IsAlbumDirty(s.PhotosetId))
            {
                continue;
            }

            Album album = new Album(s.PhotosetId, s.Title,
                                    s.Description, s.PrimaryPhotoId);

            Photo p = PersistentInformation.GetInstance().GetPhoto(s.PrimaryPhotoId);
            if (p == null)
            {
                p = RetrievePhoto(s.PrimaryPhotoId);
            }
            if (p == null)
            {
                UpdateUIAboutConnection();
                return;
            }
            PersistentInformation.GetInstance().UpdateAlbum(album);
            // Well the photo should just have been updated by UpdateStream()
            // method, but heck! this is just one photo. Just leave this method
            // here for now, may be useful in some "impossible" kinda situation.
            PersistentInformation.GetInstance().UpdatePhoto(p);

            // Make sure not to overwrite any of user specified changes,
            // when doing updates, namely the isdirty=1 rows.
            PersistentInformation.GetInstance().AddPhotoToAlbum(p.Id, album.SetId);
        }

        // Now remove the albums which are no longer present on the server.
        ArrayList allalbums = PersistentInformation.GetInstance().GetAlbums();

        foreach (Album album in allalbums)
        {
            // If the album is new, skip the deletion.
            if (!setids.Contains(album.SetId) &&
                !PersistentInformation.GetInstance().IsAlbumNew(album.SetId))
            {
                PersistentInformation.GetInstance().DeleteAlbum(album.SetId);
                PersistentInformation.GetInstance().DeleteAllPhotosFromAlbum(album.SetId);
            }
        }

        PersistentInformation.GetInstance().OrderedSetsList =
            Utils.GetDelimitedString(setids, ",");

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Done");
            DeskFlickrUI.GetInstance().SetValueProgressBar(0);
            DeskFlickrUI.GetInstance().SetProgressBarText("Photo Sets Updated");
            if (DeskFlickrUI.GetInstance().IsAlbumTabSelected())
            {
                DeskFlickrUI.GetInstance().RefreshLeftTreeView();
            }
            DeskFlickrUI.GetInstance().ShowAllInWindow();
        });
    }
예제 #25
0
    private void OnSaveButtonClick(object o, EventArgs args)
    {
        foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos)
        {
            Photo p = sel.photo;
            if (_isuploadmode)
            {
                PersistentInformation.GetInstance().UpdateInfoForUploadPhoto(p);
            }
            else
            {
                if (_isconflictmode)
                {
                    Photo serverphoto = DeskFlickrUI.GetInstance().GetServerPhoto(p.Id);
                    p.LastUpdate = serverphoto.LastUpdate;
                    DeskFlickrUI.GetInstance().RemoveServerPhoto(p.Id);
                }
                if (_isblogmode)
                {
                    BlogEntry blogentry = ((DeskFlickrUI.BlogSelectedPhoto)sel).blogentry;
                    PersistentInformation.GetInstance().UpdateEntryToBlog(blogentry);
                }
                // This original photo is the photo sent to the editor initially.
                // Note that this photo is different from the photos stored in
                // originalphoto table, which are the ones originally retrieved from
                // the server.
                Photo originalp = _originalphotos[p.Id];
                bool  ischanged = false;
                if (!p.isMetaDataEqual(originalp))
                {
                    ischanged = true;
                    PersistentInformation.GetInstance().UpdateMetaInfoPhoto(p);
                }
                if (!p.isTagsEqual(originalp))
                {
                    ischanged = true;
                    p.SortTags();
                    PersistentInformation.GetInstance().UpdateTagsForPhoto(p);
                }

                // Get the originally retrieved photo from server.
                Photo originalcleanphoto = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
                if (originalcleanphoto == null || p.isEqual(originalcleanphoto))
                {
                    PersistentInformation.GetInstance().SetPhotoDirty(p.Id, false);
                }
                else if (ischanged)
                {
                    PersistentInformation.GetInstance().SetPhotoDirty(p.Id, true);
                }
                else
                {
                    Console.Error.WriteLine(
                        "Inconsistent State: Photo seems to be different than stored"
                        + " in server, but the metadata and tags are unchanged.");
                    Console.Out.WriteLine("=== Local photo ===");
                    Console.Out.WriteLine(p.PrettyPrint());
                    Console.Out.WriteLine("=== Server Photo ===");
                    Console.Out.WriteLine(originalcleanphoto.PrettyPrint());
                }
            }
        }
        window2.Destroy();
        DeskFlickrUI.GetInstance().UpdateToolBarButtons();
        if (_isconflictmode)
        {
            DeskFlickrUI.GetInstance().OnConflictButtonClicked(null, null);
        }
        else
        {
            DeskFlickrUI.GetInstance().UpdatePhotos(_selectedphotos);
        }
    }
예제 #26
0
 public static DeskFlickrUI GetInstance()
 {
     if (deskflickr == null) {
         deskflickr = new DeskFlickrUI();
       }
       return deskflickr;
 }
예제 #27
0
/*
 * gmcs -pkg:glade-sharp-2.0 -pkg:gconf-sharp-2.0 -r:lib/FlickrNet.dll
 * -resource:glade/organizer.glade Main.cs *.cs
 */
    public static void Main(string[] args)
    {
        DeskFlickrUI.GetInstance().CreateGUI();
    }
예제 #28
0
 public static void FireUp(ArrayList selectedphotos, DeskFlickrUI.ModeSelected mode)
 {
     new PhotoEditorUI(selectedphotos, mode);
 }
예제 #29
0
    private PhotoEditorUI(ArrayList selectedphotos, DeskFlickrUI.ModeSelected mode)
    {
        Glade.XML gxml = new Glade.XML (null, "organizer.glade", "window2", null);
          gxml.Autoconnect (this);
          _isconflictmode = (mode == DeskFlickrUI.ModeSelected.ConflictMode);
          _isuploadmode = (mode == DeskFlickrUI.ModeSelected.UploadMode);
          _isblogmode = (mode == DeskFlickrUI.ModeSelected.BlogMode);
          if (mode == DeskFlickrUI.ModeSelected.BlogAndConflictMode) {
        _isconflictmode = true;
        _isblogmode = true;
          }
          _tags = new ArrayList();
          _comments = new ArrayList();
          window2.Title = "Edit information for " + selectedphotos.Count + " photos";
          window2.SetIconFromFile(DeskFlickrUI.ICON_PATH);
          notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Information");
          notebook1.NextPage();
          notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Tags");
          notebook1.NextPage();
          notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Comments");

          tips = new Tooltips();
          SetCommentsToolBar();
          tips.Enable();
          SetCommentsTree();

          if (_isconflictmode) {
            notebook1.NextPage();
            notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Information at Server");
          } else {
            notebook1.RemovePage(3);
          }

          if (_isblogmode) {
            notebook1.NextPage();
            notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Blog Entry");
            notebook1.Page = 3; // Default page is blog entry if editor is in Blog mode.
          } else {
            if (_isconflictmode) notebook1.RemovePage(4);
            else notebook1.RemovePage(3);
            notebook1.Page = 0; // Default page is photo editing.
          }

          table1.SetColSpacing(0, 50);
          // Set Labels
          label6.Text = "Edit";
          label5.Text = "Title:";
          label4.Text = "Description:";
          label3.Text = "Visibility:";
          label2.Text = "License:";
          if (_isuploadmode) label2.Sensitive = false;
          // Labels for blog tab.
          label17.Text = "Title: ";
          label18.Text = "Description: ";

          // Search box
          label15.Markup = "<span weight='bold'>Search: </span>";
          entry2.Changed += new EventHandler(OnFilterEntryChanged);

          // Revert button
          button9.Label = "Revert Photo(s)";
          button9.Clicked += new EventHandler(OnRevertButtonClicked);

          // entry1.ModifyFont(Pango.FontDescription.FromString("FreeSerif 10"));
          SetPrivacyComboBox();
          SetLicenseComboBox();
          SetTagTreeView();

          // Make previous and next buttons insensitive. They'll become sensitive
          // only when the user ticks the 'Per Photo' checkbutton.
          button3.Sensitive = false;
          button4.Sensitive = false;
          checkbutton1.Toggled += new EventHandler(OnPerPageCheckToggled);
          button3.Clicked += new EventHandler(OnPrevButtonClick);
          button4.Clicked += new EventHandler(OnNextButtonClick);
          button5.Clicked += new EventHandler(OnSaveButtonClick);
          button6.Clicked += new EventHandler(OnCancelButtonClick);

          entry1.Changed += new EventHandler(OnTitleChanged);
          textview5.Buffer.Changed += new EventHandler(OnDescChanged);

          combobox1.Changed += new EventHandler(OnPrivacyChanged);
          combobox2.Changed += new EventHandler(OnLicenseChanged);

          entry4.Changed += new EventHandler(OnBlogTitleChanged);
          textview7.Buffer.Changed += new EventHandler(OnBlogDescChanged);

          textview3.Buffer.Changed += new EventHandler(OnTagsChanged);

          TextTag texttag = new TextTag("conflict");
          texttag.Font = "Times Italic 10";
          texttag.WrapMode = WrapMode.Word;
          texttag.ForegroundGdk = new Gdk.Color(0x99, 0, 0);
          textview4.Buffer.TagTable.Add(texttag);

          // Showing photos should be the last step.
          this._selectedphotos = selectedphotos;
          if (selectedphotos.Count == 1) {
        checkbutton1.Sensitive = false;
        ShowInformationForCurrentPhoto();
          } else {
        EmbedCommonInformation();
          }
          // Save a copy of the original photos, so that only those photos
          // which  have been edited, would have their dirty bit set. Advantage:
          // this would reduce the number of dirty photos, and hence there'll
          // be lesser photos to update when sycing with server.
          _originalphotos = new System.Collections.Generic.Dictionary<string, Photo>();
          foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
        Photo p = sel.photo;
        _originalphotos.Add(p.Id, new Photo(p));
          }

          eventbox5.ButtonPressEvent += OnLinkPressed;
          eventbox5.EnterNotifyEvent += MouseOnLink;
          eventbox5.LeaveNotifyEvent += MouseLeftLink;

          window2.ShowAll();
    }
예제 #30
0
    private void SyncDirtyPhotosToServer()
    {
        ArrayList photos = PersistentInformation.GetInstance().GetDirtyPhotos();

        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Syncing photos to server...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
            DeskFlickrUI.GetInstance().SetLimitsProgressBar(photos.Count);
        });
        foreach (Photo photo in photos)
        {
            DelegateIncrementProgressBar();
            Photo serverphoto = RetrievePhoto(photo.Id);
            bool  ismodified  = !serverphoto.LastUpdate.Equals(photo.LastUpdate);

            // Sync meta information.
            bool ismetachanged = false;
            if (!photo.Title.Equals(serverphoto.Title))
            {
                ismetachanged = true;
            }
            if (!photo.Description.Equals(serverphoto.Description))
            {
                ismetachanged = true;
            }
            if (ismetachanged && !ismodified)
            {
                flickrObj.PhotosSetMeta(photo.Id, photo.Title, photo.Description);
            }
            if (!photo.License.Equals(serverphoto.License))
            {
                Console.Error.WriteLine("License sync functionality is not yet present.");
                // TODO: update the license info.
            }
            // Sync Permissions.
            bool isvischanged = false;
            if (photo.IsPublic != serverphoto.IsPublic)
            {
                isvischanged = true;
            }
            if (photo.IsFriend != serverphoto.IsFriend)
            {
                isvischanged = true;
            }
            if (photo.IsFamily != serverphoto.IsFamily)
            {
                isvischanged = true;
            }
            if (isvischanged && !ismodified)
            {
                // TODO: Need to add ways to set the comment and add meta permissions.
                flickrObj.PhotosSetPerms(photo.Id, photo.IsPublic, photo.IsFriend,
                                         photo.IsFamily, PermissionComment.Everybody,
                                         PermissionAddMeta.Everybody);
            }
            // Sync tags as well.
            bool istagschanged = !photo.IsSameTags(serverphoto.Tags);
            if (istagschanged && !ismodified)
            {
                flickrObj.PhotosSetTags(photo.Id, photo.TagString);
            }
            // If the photo has been modified both at the server, and in dfo,
            // store it as a conflict.
            if (ismodified &&
                (ismetachanged || isvischanged || istagschanged))
            {
                DeskFlickrUI.GetInstance().AddServerPhoto(serverphoto);
                continue;
            }
            // Photo has been synced, now remove the dirty bit.
            PersistentInformation.GetInstance().SetPhotoDirty(photo.Id, false);
        }
    }
예제 #31
0
    private void UpdatePools()
    {
        Gtk.Application.Invoke(delegate {
            DeskFlickrUI.GetInstance().SetStatusLabel("Updating group pools...");
            DeskFlickrUI.GetInstance().SetProgressBarText("");
        });
        // Refresh all the pool entries in pool table. If the user has left
        // any group, it would be removed in this process.
        FlickrNet.MemberGroupInfo[] pools = flickrObj.GroupPoolGetGroups();
        PersistentInformation.GetInstance().DeleteAllPools();
        foreach (FlickrNet.MemberGroupInfo pool in pools)
        {
            PersistentInformation.GetInstance().InsertPool(pool.GroupId, pool.GroupName);
        }

        foreach (FlickrNet.MemberGroupInfo pool in pools)
        {
            Gtk.Application.Invoke(delegate {
                DeskFlickrUI.GetInstance().SetStatusLabel("Updating pool " + pool.GroupName);
            });
            ArrayList photoids = PersistentInformation.GetInstance().GetPhotoidsForPool(pool.GroupId);
            bool      alreadysetprogresslimit = false;
            int       totalpages = 1;
            // Retrieve all the photos posted by the user.
            for (int curpage = 1; curpage <= totalpages; curpage++)
            {
                FlickrNet.Photos photos;
                try {
                    string userid = PersistentInformation.GetInstance().UserId;
                    photos = flickrObj.GroupPoolGetPhotos(pool.GroupId, null, userid,
                                                          PhotoSearchExtras.None, 500, curpage);
                } catch (Exception) {
                    // This exception is thrown when trying to parse totalpages, if
                    // no photos are returned. Its a bug with FlickrNet library.
                    totalpages = 0;
                    continue;
                }
                if (!alreadysetprogresslimit)
                {
                    Gtk.Application.Invoke(delegate {
                        DeskFlickrUI.GetInstance().SetLimitsProgressBar((int)photos.TotalPhotos);
                    });
                }
                totalpages = (int)photos.TotalPages;
                foreach (FlickrNet.Photo photo in photos.PhotoCollection)
                {
                    if (photoids.Contains(photo.PhotoId))
                    {
                        photoids.Remove(photo.PhotoId);
                    }
                    else
                    {
                        PersistentInformation.GetInstance().InsertPhotoToPool(photo.PhotoId, pool.GroupId);
                    }
                    DelegateIncrementProgressBar();
                }
            }
            // These are the photos which have been removed at the server side.
            // Also, the photos which haven't been yet added to the server, will
            // be present in the list. Don't delete them.
            foreach (string photoid in photoids)
            {
                if (PersistentInformation.GetInstance()
                    .IsPhotoAddedToPool(photoid, pool.GroupId))
                {
                    continue;
                }
                PersistentInformation.GetInstance().DeletePhotoFromPool(photoid, pool.GroupId);
            }
        }
    }
예제 #32
0
 private void DelegateIncrementProgressBar()
 {
     Gtk.Application.Invoke(delegate {
         DeskFlickrUI.GetInstance().IncrementProgressBar(1);
     });
 }