Example #1
0
        public override int AddItem(Album album,
				     string path,
				     string filename,
				     string caption,
				     string description,
				     bool autorotate)
        {
            FormClient client = new FormClient (cookies);

            client.Add ("cmd", "add-item");
            client.Add ("protocol_version", "2.9");
            client.Add ("set_albumName", album.Name);
            client.Add ("caption", caption);
            client.Add ("userfile_name", filename);
            client.Add ("force_filename", filename);
            client.Add ("auto_rotate", autorotate ? "yes" : "no");
            client.Add ("userfile", new FileInfo (path));
            client.Add ("extrafield.Description", description);
            client.expect_continue = expect_continue;

            return ParseAddItem (client.Submit (Uri, Progress));
        }
Example #2
0
        public override int AddItem(Album album,
				     string path,
				     string filename,
				     string caption,
				     string description,
				     bool autorotate)
        {
            FormClient client = new FormClient (cookies);

            client.Add ("g2_form[cmd]", "add-item");
            client.Add ("g2_form[protocol_version]", "2.10");
            client.Add ("g2_form[set_albumName]", album.Name);
            client.Add ("g2_form[caption]", caption);
            client.Add ("g2_form[userfile_name]", filename);
            client.Add ("g2_form[force_filename]", filename);
            client.Add ("g2_form[auto_rotate]", autorotate ? "yes" : "no");
            client.Add ("g2_form[extrafield.Description]", description);
            client.Add ("g2_userfile", new FileInfo (path));
            client.expect_continue = expect_continue;
            AddG2Specific (client);

            return ParseAddItem (client.Submit (Uri, Progress));
        }
        public ArrayList ParseFetchAlbums(HttpWebResponse response)
        {
            //Console.WriteLine ("in ParseFetchAlbums()");
            string [] data;
            StreamReader reader = null;
            ResultCode status = ResultCode.UnknownResponse;
            string status_text = "Error: Unable to parse server response";
            albums = new ArrayList ();
            try {

                Album current_album = null;
                reader = findResponse (response);
                while ((data = GetNextLine (reader)) != null) {
                    //Console.WriteLine ("Parsing Line: {0}={1}", data[0], data[1]);
                    if (data[0] == "status") {
                        status = (ResultCode) int.Parse (data [1]);
                    } else if (data[0].StartsWith ("status_text")) {
                        status_text = data[1];
                        Log.DebugFormat ("StatusText : {0}", data[1]);
                    } else if (data[0].StartsWith ("album.name")) {
                        //this is the URL name
                        int ref_num = -1;
                        if (this.Version == GalleryVersion.Version1) {
                            string [] segments = data[0].Split (new char[1]{'.'});
                            ref_num = int.Parse (segments[segments.Length -1]);
                        } else {
                            ref_num = int.Parse (data[1]);
                        }
                        current_album = new Album (this, data[1], ref_num);
                        albums.Add (current_album);
                        //Console.WriteLine ("current_album: " + data[1]);
                    } else if (data[0].StartsWith ("album.title")) {
                        //this is the display name
                        current_album.Title = data[1];
                    } else if (data[0].StartsWith ("album.summary")) {
                        current_album.Summary = data[1];
                    } else if (data[0].StartsWith ("album.parent")) {
                        //FetchAlbums and G2 FetchAlbumsPrune return ints
                        //G1 FetchAlbumsPrune returns album names (and 0 for root albums)
                        try {
                            current_album.ParentRefNum = int.Parse (data[1]);
                        } catch (System.FormatException) {
                            current_album.ParentRefNum = LookupAlbum (data[1]).RefNum;
                        }
                        //Console.WriteLine ("album.parent data[1]: " + data[1]);
                    } else if (data[0].StartsWith ("album.resize_size")) {
                        current_album.ResizeSize = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("album.thumb_size")) {
                        current_album.ThumbSize = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("album.info.extrafields")) {
                        //ignore, this is the album description
                    } else if (data[0].StartsWith ("album.perms.add")) {
                        if (data[1] == "true")
                            current_album.Perms |= AlbumPermission.Add;
                    } else if (data[0].StartsWith ("album.perms.write")) {
                        if (data[1] == "true")
                            current_album.Perms |= AlbumPermission.Write;
                    } else if (data[0].StartsWith ("album.perms.del_item")) {
                        if (data[1] == "true")
                            current_album.Perms |= AlbumPermission.Delete;
                    } else if (data[0].StartsWith ("album.perms.del_alb")) {
                        if (data[1] == "true")
                            current_album.Perms |= AlbumPermission.DeleteAlbum;
                    } else if (data[0].StartsWith ("album.perms.create_sub")) {
                        if (data[1] == "true")
                            current_album.Perms |= AlbumPermission.CreateSubAlbum;
                    } else if (data[0].StartsWith ("album_count")) {
                        if (Albums.Count != int.Parse (data[1]))
                            Log.Warning ("Parsed album count does not match album_count.  Something is amiss");
                    } else if (data[0].StartsWith ("auth_token")) {
                        AuthToken = data [1];
                    } else {
                        Log.DebugFormat ("Unparsed Line in ParseFetchAlbums(): {0}={1}", data[0], data[1]);
                    }
                }
                //Console.WriteLine ("Found: {0} cookies", response.Cookies.Count);
                if (status != ResultCode.Success) {
                    Log.Debug (status_text);
                    throw new GalleryCommandException (status_text, status);
                }

                //Console.WriteLine (After parse albums.Count + " albums parsed");
                return albums;
            } finally {
                if (reader != null)
                    reader.Close ();

                response.Close ();
            }
        }
 public abstract bool MoveAlbum(Album album, string end_name);
 public abstract string GetAlbumUrl(Album album);
 public abstract ArrayList FetchAlbumImages(Album album, bool include_ablums);
 public abstract int AddItem(Album album, string path, string filename, string caption, string description, bool autorotate);
Example #8
0
 public override string GetAlbumUrl(Album album)
 {
     return(Uri.ToString() + "?g2_view=core.ShowItem&g2_itemId=" + album.Name);
 }
        public override bool MoveAlbum(Album album, string end_name)
        {
            FormClient client = new FormClient (cookies);

            client.Add ("cmd", "move-album");
            client.Add ("protocol_version", "2.7");
            client.Add ("set_albumName", album.Name);
            client.Add ("set_destalbumName", end_name);

            return ParseMoveAlbum (client.Submit (uri));
        }
 public override string GetAlbumUrl(Album album)
 {
     return Uri.ToString() + "?g2_view=core.ShowItem&g2_itemId=" + album.Name;
 }
        public override ArrayList FetchAlbumImages(Album album, bool include_ablums)
        {
            FormClient client = new FormClient (cookies);
            client.Add ("g2_form[cmd]", "fetch-album-images");
            client.Add ("g2_form[protocol_version]","2.10");
            client.Add ("g2_form[set_albumName]", album.Name);
            client.Add ("g2_form[albums_too]", include_ablums ? "yes" : "no");
            AddG2Specific (client);

            album.Images = ParseFetchAlbumImages (client.Submit (uri), album);
            return album.Images;
        }
Example #12
0
 public abstract List<Image> FetchAlbumImages(Album album, bool include_ablums);
Example #13
0
        private void HandleResponse(object sender, Gtk.ResponseArgs args)
        {
            if (args.ResponseId != Gtk.ResponseType.Ok) {
                export_dialog.Destroy ();
                return;
            }

            if (scale_check != null) {
                scale = scale_check.Active;
                size = size_spin.ValueAsInt;
            } else
                scale = false;

            browser = browser_check.Active;
            meta = meta_check.Active;

            if (account != null) {
                //System.Console.WriteLine ("history = {0}", album_optionmenu.History);
                album = account.Gallery.Albums [Math.Max (0, album_optionmenu.Active)];
                photo_index = 0;

                export_dialog.Destroy ();

                command_thread = new System.Threading.Thread (new System.Threading.ThreadStart (this.Upload));
                command_thread.Name = Catalog.GetString ("Uploading Pictures");

                progress_dialog = new ThreadProgressDialog (command_thread, items.Length);
                progress_dialog.Start ();

                // Save these settings for next time
                Preferences.Set (SCALE_KEY, scale);
                Preferences.Set (SIZE_KEY, size);
                Preferences.Set (BROWSER_KEY, browser);
                Preferences.Set (META_KEY, meta);
            }
        }
Example #14
0
        public List<Image> ParseFetchAlbumImages(HttpWebResponse response, Album album)
        {
            string [] data;
            StreamReader reader = null;
            ResultCode status = ResultCode.UnknownResponse;
            string status_text = "Error: Unable to parse server response";
            try {
                Image current_image = null;
                string baseUrl = Uri.ToString () + "?g2_view=core.DownloadItem&g2_itemId=";
                reader = findResponse (response);
                while ((data = GetNextLine (reader)) != null) {
                    if (data [0] == "status")
                        status = (ResultCode)int.Parse (data [1]);
                    else if (data [0].StartsWith ("status_text")) {
                        status_text = data [1];
                        Log.DebugFormat ("StatusText : {0}", data [1]);
                    } else if (data [0].StartsWith ("image.name")) {
                        //for G2 this is the number used to download the image.
                        current_image = new Image (album, "awaiting 'title'");
                        album.Images.Add (current_image);
                        current_image.Url = baseUrl + data [1];
                    } else if (data [0].StartsWith ("image.title"))
                        //for G2 the "title" is the name"
                        current_image.Name = data [1];
                    else if (data [0].StartsWith ("image.raw_width"))
                        current_image.RawWidth = int.Parse (data [1]);
                    else if (data [0].StartsWith ("image.raw_height"))
                        current_image.RawHeight = int.Parse (data [1]);
                    else if (data [0].StartsWith ("image.raw_height"))
                        current_image.RawHeight = int.Parse (data [1]);
                    //ignore these for now
                    else if (data [0].StartsWith ("image.raw_filesize")) {
                    } else if (data [0].StartsWith ("image.forceExtension")) {
                    } else if (data [0].StartsWith ("image.capturedate.year")) {
                    } else if (data [0].StartsWith ("image.capturedate.mon")) {
                    } else if (data [0].StartsWith ("image.capturedate.mday")) {
                    } else if (data [0].StartsWith ("image.capturedate.hours")) {
                    } else if (data [0].StartsWith ("image.capturedate.minutes")) {
                    } else if (data [0].StartsWith ("image.capturedate.seconds")) {
                    } else if (data [0].StartsWith ("image.hidden")) {
                    } else if (data [0].StartsWith ("image.resizedName"))
                        current_image.ResizedName = data [1];
                    else if (data [0].StartsWith ("image.resized_width"))
                        current_image.ResizedWidth = int.Parse (data [1]);
                    else if (data [0].StartsWith ("image.resized_height"))
                        current_image.ResizedHeight = int.Parse (data [1]);
                    else if (data [0].StartsWith ("image.thumbName"))
                        current_image.ThumbName = data [1];
                    else if (data [0].StartsWith ("image.thumb_width"))
                        current_image.ThumbWidth = int.Parse (data [1]);
                    else if (data [0].StartsWith ("image.thumb_height"))
                        current_image.ThumbHeight = int.Parse (data [1]);
                    else if (data [0].StartsWith ("image.caption"))
                        current_image.Caption = data [1];
                    else if (data [0].StartsWith ("image.extrafield.Description"))
                        current_image.Description = data [1];
                    else if (data [0].StartsWith ("image.clicks"))
                        try {
                            current_image.Clicks = int.Parse (data [1]);
                        } catch (System.FormatException) {
                            current_image.Clicks = 0;
                        }
                    else if (data [0].StartsWith ("baseurl"))
                        album.BaseURL = data [1];
                    else if (data [0].StartsWith ("image_count"))
                    if (album.Images.Count != int.Parse (data [1]))
                        Log.Warning ("Parsed image count for " + album.Name + "(" + album.Images.Count + ") does not match image_count (" + data [1] + ").  Something is amiss");
                    else
                        Log.DebugFormat ("Unparsed Line in ParseFetchAlbumImages(): {0}={1}", data [0], data [1]);
                }
                Log.DebugFormat ("Found: {0} cookies", response.Cookies.Count);
                if (status != ResultCode.Success) {
                    Log.Debug (status_text);
                    throw new GalleryCommandException (status_text, status);
                }

                return album.Images;

            } finally {
                if (reader != null)
                    reader.Close ();

                response.Close ();
            }
        }
        public override ArrayList FetchAlbumImages(Album album, bool include_ablums)
        {
            FormClient client = new FormClient (cookies);
            client.Add ("cmd", "fetch-album-images");
            client.Add ("protocol_version","2.3");
            client.Add ("set_albumName", album.Name);
            client.Add ("albums_too", include_ablums ? "yes" : "no");

            album.Images = ParseFetchAlbumImages (client.Submit (uri), album);
            return album.Images;
        }
        public override bool MoveAlbum(Album album, string end_name)
        {
            FormClient client = new FormClient (cookies);

            client.Add ("g2_form[cmd]", "move-album");
            client.Add ("g2_form[protocol_version]", "2.10");
            client.Add ("g2_form[set_albumName]", album.Name);
            client.Add ("g2_form[set_destalbumName]", end_name);
            AddG2Specific (client);

            return ParseMoveAlbum (client.Submit (uri));
        }
        public override string GetAlbumUrl(Album album)
        {
            string url = Uri.ToString();
            url = url.Remove (url.Length - script_name.Length, script_name.Length);

            string path = album.Name;

            url = url + path;
            url = url.Replace (" ", "+");
            return url;
        }
 public Image(Album album, string name)
 {
     Name = name;
     Owner = album;
 }
        public ArrayList ParseFetchAlbumImages(HttpWebResponse response, Album album)
        {
            string [] data;
            StreamReader reader = null;
            ResultCode status = ResultCode.UnknownResponse;
            string status_text = "Error: Unable to parse server response";
            try {
                Image current_image = null;
                reader = findResponse (response);
                while ((data = GetNextLine (reader)) != null) {
                    if (data[0] == "status") {
                        status = (ResultCode) int.Parse (data [1]);
                    } else if (data[0].StartsWith ("status_text")) {
                        status_text = data[1];
                        Log.DebugFormat ("StatusText : {0}", data[1]);
                    } else if (data[0].StartsWith ("image.name")) {
                        current_image = new Image (album, data[1]);
                        album.Images.Add (current_image);
                    } else if (data[0].StartsWith ("image.raw_width")) {
                        current_image.RawWidth = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.raw_height")) {
                        current_image.RawHeight = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.raw_height")) {
                        current_image.RawHeight = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.raw_filesize")) {
                    } else if (data[0].StartsWith ("image.capturedate.year")) {
                    } else if (data[0].StartsWith ("image.capturedate.mon")) {
                    } else if (data[0].StartsWith ("image.capturedate.mday")) {
                    } else if (data[0].StartsWith ("image.capturedate.hours")) {
                    } else if (data[0].StartsWith ("image.capturedate.minutes")) {
                    } else if (data[0].StartsWith ("image.capturedate.seconds")) {
                    } else if (data[0].StartsWith ("image.hidden")) {
                    } else if (data[0].StartsWith ("image.resizedName")) {
                        current_image.ResizedName = data[1];
                    } else if (data[0].StartsWith ("image.resized_width")) {
                        current_image.ResizedWidth = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.resized_height")) {
                        current_image.ResizedHeight = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.thumbName")) {
                        current_image.ThumbName = data[1];
                    } else if (data[0].StartsWith ("image.thumb_width")) {
                        current_image.ThumbWidth = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.thumb_height")) {
                        current_image.ThumbHeight = int.Parse (data[1]);
                    } else if (data[0].StartsWith ("image.caption")) {
                        current_image.Caption = data[1];
                    } else if (data[0].StartsWith ("image.extrafield.Description")) {
                        current_image.Description = data[1];
                    } else if (data[0].StartsWith ("image.clicks")) {
                        try {
                            current_image.Clicks = int.Parse (data[1]);
                        } catch (System.FormatException) {
                            current_image.Clicks = 0;
                        }
                    } else if (data[0].StartsWith ("baseurl")) {
                        album.BaseURL = data[1];
                    } else if (data[0].StartsWith ("image_count")) {
                        if (album.Images.Count != int.Parse (data[1]))
                            Log.Warning ("Parsed image count for " + album.Name + "(" + album.Images.Count + ") does not match image_count (" + data[1] + ").  Something is amiss");
                    } else {
                        Log.DebugFormat ("Unparsed Line in ParseFetchAlbumImages(): {0}={1}", data[0], data[1]);
                    }
                }
                //Console.WriteLine ("Found: {0} cookies", response.Cookies.Count);
                if (status != ResultCode.Success) {
                    Log.Debug (status_text);
                    throw new GalleryCommandException (status_text, status);
                }

                //Set the Urls for downloading the images.
                string baseUrl = album.BaseURL + "/";
                foreach (Image image in album.Images) {
                    image.Url = baseUrl + image.Name;
                }

                return album.Images;
            } finally {
                if (reader != null)
                    reader.Close ();

                response.Close ();
            }
        }
Example #20
0
        public List <Image> ParseFetchAlbumImages(HttpWebResponse response, Album album)
        {
            string []    data;
            StreamReader reader      = null;
            ResultCode   status      = ResultCode.UnknownResponse;
            string       status_text = "Error: Unable to parse server response";

            try {
                Image  current_image = null;
                string baseUrl       = Uri.ToString() + "?g2_view=core.DownloadItem&g2_itemId=";
                reader = findResponse(response);
                while ((data = GetNextLine(reader)) != null)
                {
                    if (data [0] == "status")
                    {
                        status = (ResultCode)int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("status_text"))
                    {
                        status_text = data [1];
                        Log.DebugFormat("StatusText : {0}", data [1]);
                    }
                    else if (data [0].StartsWith("image.name"))
                    {
                        //for G2 this is the number used to download the image.
                        current_image = new Image(album, "awaiting 'title'");
                        album.Images.Add(current_image);
                        current_image.Url = baseUrl + data [1];
                    }
                    else if (data [0].StartsWith("image.title"))
                    {
                        //for G2 the "title" is the name"
                        current_image.Name = data [1];
                    }
                    else if (data [0].StartsWith("image.raw_width"))
                    {
                        current_image.RawWidth = int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("image.raw_height"))
                    {
                        current_image.RawHeight = int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("image.raw_height"))
                    {
                        current_image.RawHeight = int.Parse(data [1]);
                    }
                    //ignore these for now
                    else if (data [0].StartsWith("image.raw_filesize"))
                    {
                    }
                    else if (data [0].StartsWith("image.forceExtension"))
                    {
                    }
                    else if (data [0].StartsWith("image.capturedate.year"))
                    {
                    }
                    else if (data [0].StartsWith("image.capturedate.mon"))
                    {
                    }
                    else if (data [0].StartsWith("image.capturedate.mday"))
                    {
                    }
                    else if (data [0].StartsWith("image.capturedate.hours"))
                    {
                    }
                    else if (data [0].StartsWith("image.capturedate.minutes"))
                    {
                    }
                    else if (data [0].StartsWith("image.capturedate.seconds"))
                    {
                    }
                    else if (data [0].StartsWith("image.hidden"))
                    {
                    }
                    else if (data [0].StartsWith("image.resizedName"))
                    {
                        current_image.ResizedName = data [1];
                    }
                    else if (data [0].StartsWith("image.resized_width"))
                    {
                        current_image.ResizedWidth = int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("image.resized_height"))
                    {
                        current_image.ResizedHeight = int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("image.thumbName"))
                    {
                        current_image.ThumbName = data [1];
                    }
                    else if (data [0].StartsWith("image.thumb_width"))
                    {
                        current_image.ThumbWidth = int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("image.thumb_height"))
                    {
                        current_image.ThumbHeight = int.Parse(data [1]);
                    }
                    else if (data [0].StartsWith("image.caption"))
                    {
                        current_image.Caption = data [1];
                    }
                    else if (data [0].StartsWith("image.extrafield.Description"))
                    {
                        current_image.Description = data [1];
                    }
                    else if (data [0].StartsWith("image.clicks"))
                    {
                        try {
                            current_image.Clicks = int.Parse(data [1]);
                        } catch (System.FormatException) {
                            current_image.Clicks = 0;
                        }
                    }
                    else if (data [0].StartsWith("baseurl"))
                    {
                        album.BaseURL = data [1];
                    }
                    else if (data [0].StartsWith("image_count"))
                    {
                        if (album.Images.Count != int.Parse(data [1]))
                        {
                            Log.Warning("Parsed image count for " + album.Name + "(" + album.Images.Count + ") does not match image_count (" + data [1] + ").  Something is amiss");
                        }
                        else
                        {
                            Log.DebugFormat("Unparsed Line in ParseFetchAlbumImages(): {0}={1}", data [0], data [1]);
                        }
                    }
                }
                Log.DebugFormat("Found: {0} cookies", response.Cookies.Count);
                if (status != ResultCode.Success)
                {
                    Log.Debug(status_text);
                    throw new GalleryCommandException(status_text, status);
                }

                return(album.Images);
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }

                response.Close();
            }
        }