Ejemplo n.º 1
0
        public void HandleLoginClicked(object sender, EventArgs args)
        {
            account = new FacebookAccount();

            Uri token = account.CreateToken();

            GnomeUtil.UrlShow(token.ToString());

            HigMessageDialog mbox = new HigMessageDialog(Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Info, Gtk.ButtonsType.Ok, Catalog.GetString("Waiting for authentication"), Catalog.GetString("F-Spot will now launch your browser so that you can log into Facebook.  Turn on the \"Save my login information\" checkbox on Facebook and F-Spot will log into Facebook automatically from now on."));

            mbox.Run();
            mbox.Destroy();

            if (account.Authenticated == false)
            {
                HigMessageDialog error = new HigMessageDialog(Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString("Error logging into Facebook"), Catalog.GetString("There was a problem logging into Facebook.  Check your credentials and try again."));
                error.Run();
                error.Destroy();
            }
            else
            {
                login_button.Visible  = false;
                logout_button.Visible = true;

                album_info_vbox.Sensitive   = true;
                picture_info_vbox.Sensitive = true;

                User me = account.Facebook.GetLoggedInUser().GetUserInfo();
                // Note for translators: {0} and {1} are respectively firstname and surname of the user
                whoami_label.Text = String.Format(Catalog.GetString("{0} {1} is logged into Facebook"), me.FirstName, me.LastName);

                Friend[] friend_list = account.Facebook.GetFriends();
                long[]   uids        = new long [friend_list.Length];

                for (int i = 0; i < friend_list.Length; i++)
                {
                    uids [i] = friend_list [i].UId;
                }

                User[] infos = account.Facebook.GetUserInfo(uids, new string[] { "first_name", "last_name" });
                friends = new Dictionary <long, User> ();

                foreach (User user in infos)
                {
                    friends.Add(user.UId, user);
                }

                Album[]    albums = account.Facebook.GetAlbums();
                AlbumStore store  = new AlbumStore(albums);
                existing_album_combobox.Model  = store;
                existing_album_combobox.Active = 0;
            }
        }
Ejemplo n.º 2
0
        private void Upload()
        {
            Album album = null;

            if (create_album_radiobutton.Active)
            {
                string name = album_name_entry.Text;
                if (name.Length == 0)
                {
                    HigMessageDialog mbox = new HigMessageDialog(Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString("Album must have a name"), Catalog.GetString("Please name your album or choose an existing album."));
                    mbox.Run();
                    mbox.Destroy();
                    return;
                }

                string description = album_description_entry.Text;
                string location    = album_location_entry.Text;

                try {
                    album = account.Facebook.CreateAlbum(name, description, location);
                }
                catch (FacebookException fe) {
                    HigMessageDialog mbox = new HigMessageDialog(Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString("Creating a new album failed"), String.Format(Catalog.GetString("An error occurred creating a new album.\n\n{0}"), fe.Message));
                    mbox.Run();
                    mbox.Destroy();
                    return;
                }
            }
            else
            {
                AlbumStore store = (AlbumStore)existing_album_combobox.Model;
                album = store.Albums [existing_album_combobox.Active];
            }

            long sent_bytes = 0;

            FilterSet filters = new FilterSet();

            filters.Add(new JpegFilter());
            filters.Add(new ResizeFilter((uint)size));

            for (int i = 0; i < items.Length; i++)
            {
                try {
                    IBrowsableItem item = items [i];

                    FileInfo file_info;
                    Console.WriteLine("uploading {0}", i);

                    progress_dialog.Message      = String.Format(Catalog.GetString("Uploading picture \"{0}\" ({1} of {2})"), item.Name, i + 1, items.Length);
                    progress_dialog.ProgressText = string.Empty;
                    progress_dialog.Fraction     = i / (double)items.Length;

                    FilterRequest request = new FilterRequest(item.DefaultVersionUri);
                    filters.Convert(request);

                    file_info = new FileInfo(request.Current.LocalPath);

                    Mono.Facebook.Photo photo = album.Upload(captions [i] ?? "", request.Current.LocalPath);

                    sent_bytes += file_info.Length;
                }
                catch (Exception e) {
                    progress_dialog.Message      = String.Format(Catalog.GetString("Error Uploading To Facebook: {0}"), e.Message);
                    progress_dialog.ProgressText = Catalog.GetString("Error");
                    Console.WriteLine(e);

                    if (progress_dialog.PerformRetrySkip())
                    {
                        i--;
                    }
                }
            }

            progress_dialog.Message      = Catalog.GetString("Done Sending Photos");
            progress_dialog.Fraction     = 1.0;
            progress_dialog.ProgressText = Catalog.GetString("Upload Complete");
            progress_dialog.ButtonLabel  = Gtk.Stock.Ok;

            Dialog.Destroy();
        }
		public void HandleLoginClicked (object sender, EventArgs args)
		{
			account = new FacebookAccount();

			Uri token = account.CreateToken ();
			GnomeUtil.UrlShow (token.ToString ());

			HigMessageDialog mbox = new HigMessageDialog (Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Info, Gtk.ButtonsType.Ok, Catalog.GetString ("Waiting for authentication"), Catalog.GetString ("F-Spot will now launch your browser so that you can log into Facebook.  Turn on the \"Save my login information\" checkbox on Facebook and F-Spot will log into Facebook automatically from now on."));

			mbox.Run ();
			mbox.Destroy ();

			if (account.Authenticated == false) {
				HigMessageDialog error = new HigMessageDialog (Dialog, Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, Catalog.GetString ("Error logging into Facebook"), Catalog.GetString ("There was a problem logging into Facebook.  Check your credentials and try again."));
				error.Run ();
				error.Destroy ();
			}
			else {
				login_button.Visible = false;
				logout_button.Visible = true;

				album_info_vbox.Sensitive = true;
				picture_info_vbox.Sensitive = true;

				User me = account.Facebook.GetLoggedInUser ().GetUserInfo ();
				// Note for translators: {0} and {1} are respectively firstname and surname of the user 
				whoami_label.Text = String.Format (Catalog.GetString ("{0} {1} is logged into Facebook"), me.FirstName, me.LastName);

				Friend[] friend_list = account.Facebook.GetFriends ();
				long[] uids = new long [friend_list.Length];

				for (int i = 0; i < friend_list.Length; i++)
					uids [i] = friend_list [i].UId;

				User[] infos = account.Facebook.GetUserInfo (uids, new string[] { "first_name", "last_name" });
				friends = new Dictionary<long, User> ();

				foreach (User user in infos)
					friends.Add (user.UId, user);

				Album[] albums = account.Facebook.GetAlbums ();
				AlbumStore store = new AlbumStore (albums);
				existing_album_combobox.Model = store;
				existing_album_combobox.Active = 0;
			}
		}