예제 #1
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();
        }
    }
예제 #2
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);
            }
        }
    }
예제 #3
0
 private void OnRevertButtonClicked(object sender, EventArgs args)
 {
     if (checkbutton1.Active || !checkbutton1.Sensitive)
     {
         Photo p         = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[_curphotoindex]).photo;
         Photo originalp = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
         if (originalp != null)
         {
             p.CopyContent(originalp);
         }
         ShowInformationForCurrentPhoto();
     }
     else
     {
         for (int i = 0; i < _selectedphotos.Count; i++)
         {
             Photo p         = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[i]).photo;
             Photo originalp = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
             if (originalp != null)
             {
                 p.CopyContent(originalp);
             }
         }
         EmbedCommonInformation();
     }
     button9.Sensitive = false;
 }
예제 #4
0
    private void OnDeleteCommentButtonClicked(object o, EventArgs args)
    {
        if (treeview3.Selection.GetSelectedRows().Length == 0)
        {
            return;
        }
        MessageDialog md = new MessageDialog(
            window2, DialogFlags.DestroyWithParent, MessageType.Question,
            ButtonsType.YesNo,
            "Are you sure you want to delete the comment?");
        ResponseType response = ResponseType.No;

        response = (ResponseType)md.Run();
        md.Destroy();
        if (response == ResponseType.No)
        {
            return;
        }
        Photo    p         = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[_curphotoindex]).photo;
        TreePath path      = treeview3.Selection.GetSelectedRows()[0];
        string   commentid = ((Comment)_comments[path.Indices[0]]).CommentId;

        if (commentid.IndexOf("new:") > -1)             // new comment.
        {
            PersistentInformation.GetInstance().DeleteComment(p.Id, commentid);
        }
        else
        {
            PersistentInformation.GetInstance().MarkCommentForDeletion(p.Id, commentid);
        }
        PopulateComments(p.Id);
    }
예제 #5
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();
        }
    }
예제 #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
    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();
    }
예제 #8
0
    private AlbumEditorUI(Album album, bool isnew)
    {
        Glade.XML gxml = new Glade.XML(null, "organizer.glade", "window3", null);
        gxml.Autoconnect(this);

        this._isnew   = isnew;
        this._album   = album;
        window3.Title = String.Format("Editing information for {0}", album.Title);
        window3.SetIconFromFile(DeskFlickrUI.ICON_PATH);

        label8.Text  = "Edit";
        label9.Text  = "Title: ";
        label10.Text = "Description: ";

        entry3.Text           = album.Title;
        textview6.Buffer.Text = album.Desc;

        entry3.Changed           += new EventHandler(OnTitleChanged);
        textview6.Buffer.Changed += new EventHandler(OnDescriptionChanged);

        button7.Clicked += new EventHandler(OnCancelButtonClicked);
        button8.Clicked += new EventHandler(OnSaveButtonClicked);

        image4.Pixbuf = PersistentInformation.GetInstance()
                        .GetSmallImage(album.PrimaryPhotoid);
        window3.ShowAll();
    }
예제 #9
0
    private void OnButtonPressDone(object sender, EventArgs e)
    {
        Auth   auth  = this.flickrObj.AuthGetToken(frob);
        string token = auth.Token;

        PersistentInformation.GetInstance().Token = token;
        dialog1.Destroy();
    }
예제 #10
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);
     });
 }
예제 #11
0
    private bool IsPhotoEdited(Photo p)
    {
        if (!PersistentInformation.GetInstance().HasOriginalPhoto(p.Id))
        {
            return(false);
        }
        Photo originalphoto = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);

        return(!originalphoto.isEqual(p));
    }
예제 #12
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();
        }
    }
예제 #13
0
    private void OnAddCommentButtonClicked(object o, EventArgs args)
    {
        string comment;

        if (!RunInputTextDialog("Add New Comment", Stock.Add, "", out comment))
        {
            return;
        }
        Photo p = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[_curphotoindex]).photo;

        PersistentInformation.GetInstance().InsertNewComment(p.Id, comment);
        PopulateComments(p.Id);
    }
예제 #14
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);
     });
 }
예제 #15
0
    private void SetPhotoLink(string photoid)
    {
        string userid = PersistentInformation.GetInstance().UserId;

        if (_isuploadmode || photoid.Equals("") || userid.Equals(""))
        {
            _currenturl  = "";
            label14.Text = "";
            return;
        }
        _currenturl = String.Format(
            "http://www.flickr.com/photos/{0}/{1}", userid, photoid);
        label14.Markup = "<span foreground='#666666' style='italic'>View in browser</span>";
    }
예제 #16
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();
        }
    }
예제 #17
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();
        }
    }
예제 #18
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);
        }
    }
예제 #19
0
    private void PopulateComments(string photoid)
    {
        _comments.Clear();
        ListStore store = new Gtk.ListStore(typeof(string));

        foreach (Comment comment in
                 PersistentInformation.GetInstance().GetCommentsForPhoto(photoid))
        {
            string username    = comment.UserName;
            string safecomment = Utils.EscapeForPango(comment.CommentHtml);
            string text        = String.Format(
                "<span weight='bold'>{0}:</span> {1}",
                username, safecomment);
            store.AppendValues(text);
            _comments.Add(comment);
        }
        treeview3.Model = store;
        treeview3.ShowAll();
    }
예제 #20
0
    private void SetTagTreeView()
    {
        ListStore tagstore = new ListStore(typeof(string));

        _tags.Clear();
        foreach (PersistentInformation.Entry entry in
                 PersistentInformation.GetInstance().GetAllTags())
        {
            string tag     = entry.entry1;
            string numpics = entry.entry2;
            _tags.Add(tag);
            tagstore.AppendValues(tag + "(" + numpics + ")");
        }
        _filter                  = new TreeModelFilter(tagstore, null);
        _filter.VisibleFunc      = new TreeModelFilterVisibleFunc(FilterTags);
        iconview1.Model          = _filter;
        iconview1.TextColumn     = 0;
        iconview1.ItemActivated += new ItemActivatedHandler(OnTagClicked);
    }
예제 #21
0
 private void UpdatePhotos(FlickrNet.PhotoCollection photos,
                           ref ArrayList serverphotoids)
 {
     foreach (FlickrNet.Photo p in photos)
     {
         DelegateIncrementProgressBar();
         if (!PersistentInformation.GetInstance().HasLatestPhoto(
                 p.PhotoId, p.lastupdate_raw))
         {
             Photo photo = RetrievePhoto(p.PhotoId);
             if (photo == null)
             {
                 continue;
             }
             PersistentInformation.GetInstance().UpdatePhoto(photo);
         }
         serverphotoids.Add(p.PhotoId);
     }
 }
예제 #22
0
    private void OnEditCommentButtonClicked(object o, EventArgs args)
    {
        if (treeview3.Selection.GetSelectedRows().Length == 0)
        {
            return;
        }
        Photo    p               = ((DeskFlickrUI.SelectedPhoto)_selectedphotos[_curphotoindex]).photo;
        TreePath path            = treeview3.Selection.GetSelectedRows()[0];
        Comment  comment         = (Comment)_comments[path.Indices[0]];
        string   originalcomment = comment.CommentHtml;
        string   commenthtml;

        if (!RunInputTextDialog(
                "Edit Comment", Stock.Ok, originalcomment, out commenthtml))
        {
            return;
        }
        PersistentInformation.GetInstance().UpdateComment(
            p.Id, comment.CommentId, commenthtml, true);
        PopulateComments(p.Id);
    }
예제 #23
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);
        }
    }
예제 #24
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);
        }
    }
예제 #25
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);
            }
        }
    }
예제 #26
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);
        }
    }
예제 #27
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();
        });
    }
예제 #28
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);
        }
    }
예제 #29
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);
            }
        }
    }
예제 #30
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);
        }
    }