Ejemplo n.º 1
0
    public void TryWebLogin()
    {
        frob = flickr.AuthGetFrob();
        string login_url = flickr.AuthCalcUrl(frob, FlickrNet.AuthLevel.Write);

        GnomeUtil.UrlShow(login_url);
    }
Ejemplo n.º 2
0
        protected override void OnLinkClicked(string url)
        {
            if (url.StartsWith("/"))
            {
                // do a lame job of creating a URI out of local paths
                url = "file://" + url;
            }

            GnomeUtil.UrlShow(null, url);
        }
Ejemplo n.º 3
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.º 4
0
        void HandleSetAsBackgroundCommand(object sender, EventArgs args)
        {
#if !NOGCONF
            IBrowsableItem current = image_view.Item.Current;

            if (current == null)
            {
                return;
            }

            GnomeUtil.SetBackgroundImage(current.DefaultVersionUri.LocalPath);
#endif
        }
Ejemplo n.º 5
0
        void HandleBrowseExisting(object sender, System.EventArgs args)
        {
#if GIO_2_16
            if (listwindow == null)
            {
                listwindow = new Gtk.Window("Pending files to write");
                listwindow.SetDefaultSize(400, 200);
                listwindow.DeleteEvent += delegate(object o, Gtk.DeleteEventArgs e) { (o as Gtk.Window).Destroy(); listwindow = null; };
                Gtk.TextView       view   = new Gtk.TextView();
                Gtk.TextBuffer     buffer = view.Buffer;
                Gtk.ScrolledWindow sw     = new Gtk.ScrolledWindow();
                sw.Add(view);
                listwindow.Add(sw);
            }
            else
            {
                ((listwindow.Child as Gtk.ScrolledWindow).Child as Gtk.TextView).Buffer.Text = "";
            }
            ListAll(((listwindow.Child as Gtk.ScrolledWindow).Child as Gtk.TextView).Buffer, dest);
            listwindow.ShowAll();
#else
            GnomeUtil.UrlShow(dest.ToString());
#endif
        }
Ejemplo n.º 6
0
	public static void UrlShow (Gtk.Window owner_window, string url)
	{
		GnomeUtil disp = new GnomeUtil (owner_window, url);
		Gtk.Application.Invoke (disp, null, delegate (object sender, EventArgs args) { ((GnomeUtil) disp).Show (); });
	}
Ejemplo n.º 7
0
        private void Upload()
        {
            sent_bytes  = 0;
            approx_size = 0;

            System.Uri album_uri = null;

            System.Console.WriteLine("Starting Upload to Smugmug, album {0} - {1}", album.Title, album.AlbumID);

            FilterSet filters = new FilterSet();

            filters.Add(new JpegFilter());

            if (scale)
            {
                filters.Add(new ResizeFilter((uint)size));
            }

            if (rotate)
            {
                filters.Add(new OrientationFilter());
            }

            while (photo_index < items.Length)
            {
                try {
                    IBrowsableItem item = items[photo_index];

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

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

                    FilterRequest request = new FilterRequest(item.DefaultVersionUri);

                    filters.Convert(request);

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

                    if (approx_size == 0)                     //first image
                    {
                        approx_size = file_info.Length * items.Length;
                    }
                    else
                    {
                        approx_size = sent_bytes * items.Length / (photo_index - 1);
                    }

                    int image_id = account.SmugMug.Upload(request.Current.LocalPath, album.AlbumID);
                    if (Core.Database != null)
                    {
                        Core.Database.Exports.Create((item as Photo).Id,
                                                     (item as Photo).DefaultVersionId,
                                                     ExportStore.SmugMugExportType,
                                                     account.SmugMug.GetAlbumUrl(image_id).ToString());
                    }

                    sent_bytes += file_info.Length;

                    if (album_uri == null)
                    {
                        album_uri = account.SmugMug.GetAlbumUrl(image_id);
                    }
                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format(Mono.Unix.Catalog.GetString("Error Uploading To Gallery: {0}"),
                                                            e.Message);
                    progress_dialog.ProgressText = Mono.Unix.Catalog.GetString("Error");
                    System.Console.WriteLine(e);

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

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

            if (browser && album_uri != null)
            {
                GnomeUtil.UrlShow(null, album_uri.ToString());
            }
        }
Ejemplo n.º 8
0
        private void Upload()
        {
            album.UploadProgress += HandleUploadProgress;
            sent_bytes            = 0;
            approx_size           = 0;

            System.Console.WriteLine("Starting Upload to Picasa");

            FilterSet filters = new FilterSet();

            filters.Add(new JpegFilter());

            if (scale)
            {
                filters.Add(new ResizeFilter((uint)size));
            }

            if (rotate)
            {
                filters.Add(new OrientationFilter());
            }

            while (photo_index < items.Length)
            {
                try {
                    IBrowsableItem item = items[photo_index];

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

                    progress_dialog.Message = String.Format(Catalog.GetString("Uploading picture \"{0}\" ({1} of {2})"),
                                                            item.Name, photo_index + 1, items.Length);
                    photo_index++;

                    FilterRequest request = new FilterRequest(item.DefaultVersionUri);

                    filters.Convert(request);

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

                    if (approx_size == 0)                     //first image
                    {
                        approx_size = file_info.Length * items.Length;
                    }
                    else
                    {
                        approx_size = sent_bytes * items.Length / (photo_index - 1);
                    }

                    PicasaPicture picture = album.UploadPicture(request.Current.LocalPath, Path.ChangeExtension(item.Name, "jpg"), item.Description);
                    if (Core.Database != null && item is Photo)
                    {
                        Core.Database.Exports.Create((item as Photo).Id,
                                                     (item as Photo).DefaultVersionId,
                                                     ExportStore.PicasaExportType,
                                                     picture.Link);
                    }

                    sent_bytes += file_info.Length;

                    request.Dispose();
                    //tagging
                    if (item.Tags != null)
                    {
                        foreach (Tag tag in item.Tags)
                        {
                            picture.AddTag(tag.Name);
                        }
                    }
                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format(Catalog.GetString("Error Uploading To Gallery: {0}"),
                                                            e.Message);
                    progress_dialog.ProgressText = Catalog.GetString("Error");
                    System.Console.WriteLine(e);

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

            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;

            if (browser)
            {
                GnomeUtil.UrlShow(null, album.Link);
            }
        }
        private void Upload()
        {
            progress_item                   = new ProgressItem();
            progress_item.Changed          += HandleProgressChanged;
            fr.Connection.OnUploadProgress += HandleFlickrProgress;

            System.Collections.ArrayList ids = new System.Collections.ArrayList();
            for (int index = 0; index < selection.Items.Length; index++)
            {
                try {
                    IBrowsableItem photo = selection.Items [index];
                    progress_dialog.Message = System.String.Format(
                        Catalog.GetString("Uploading picture \"{0}\""), photo.Name);

                    progress_dialog.Fraction = photo_index / (double)selection.Count;
                    photo_index++;
                    progress_dialog.ProgressText = System.String.Format(
                        Catalog.GetString("{0} of {1}"), photo_index,
                        selection.Count);

                    info = new FileInfo(photo.DefaultVersionUri.LocalPath);
                    FilterSet stack = new Filters.FilterSet();
                    if (scale)
                    {
                        stack.Add(new ResizeFilter((uint)size));
                    }

                    string id = fr.Upload(photo, stack, is_public, is_family, is_friend);
                    ids.Add(id);

                    if (Core.Database != null && photo is Photo)
                    {
                        Core.Database.Exports.Create((photo as Photo).Id,
                                                     (photo as Photo).DefaultVersionId,
                                                     ExportStore.FlickrExportType,
                                                     auth.User.UserId + ":" + auth.User.Username + ":" + current_service.Name + ":" + id);
                    }

                    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;
                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format(Catalog.GetString("Error Uploading To {0}: {1}"),
                                                            current_service.Name,
                                                            e.Message);
                    progress_dialog.ProgressText = Catalog.GetString("Error");
                    System.Console.WriteLine(e);

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

            if (open && ids.Count != 0)
            {
                string view_url = string.Format("http://www.{0}/tools/uploader_edit.gne?ids", current_service.Name);
                bool   first    = true;

                foreach (string id in ids)
                {
                    view_url = view_url + (first ? "=" : ",") + id;
                    first    = false;
                }

                GnomeUtil.UrlShow(progress_dialog, view_url);
            }
        }
Ejemplo n.º 10
0
        private void HandleResponse(object sender, Gtk.ResponseArgs args)
        {
            int  size          = 0;
            bool UserCancelled = false;
            bool rotate        = true;

            // Lets remove the mail "create mail" dialog
            Dialog.Destroy();

            if (args.ResponseId != Gtk.ResponseType.Ok)
            {
                return;
            }
            ProgressDialog progress_dialog = null;

            progress_dialog = new ProgressDialog(Catalog.GetString("Preparing email"),
                                                 ProgressDialog.CancelButtonType.Stop,
                                                 selection.Count,
                                                 parent_window);

            size = GetScaleSize();             // Which size should we scale to. 0 --> Original

            // evaluate mailto command and define attachment args for cli
            System.Text.StringBuilder attach_arg = new System.Text.StringBuilder();
            switch (Preferences.Get <string> (Preferences.GNOME_MAILTO_COMMAND))
            {
            case "thunderbird %s":
            case "mozilla-thunderbird %s":
            case "seamonkey -mail -compose %s":
            case "icedove %s":
                attach_arg.Append(",");
                break;

            case "kmail %s":
                attach_arg.Append(" --attach ");
                break;

            default:                      //evolution falls into default, since it supports mailto uri correctly
                attach_arg.Append("&attach=");
                break;
            }

            rotate = rotate_check.Active;              // Should we automatically rotate original photos.
            Preferences.Set(Preferences.EXPORT_EMAIL_ROTATE, rotate);

            // Initiate storage for temporary files to be deleted later
            tmp_paths = new System.Collections.ArrayList();

            // Create a tmp directory.
            tmp_mail_dir = System.IO.Path.GetTempFileName();                    // Create a tmp file
            System.IO.File.Delete(tmp_mail_dir);                                // Delete above tmp file
            System.IO.Directory.CreateDirectory(tmp_mail_dir);                  // Create a directory with above tmp name

            System.Text.StringBuilder mail_attach = new System.Text.StringBuilder();

            FilterSet filters = new FilterSet();

            if (size != 0)
            {
                filters.Add(new ResizeFilter((uint)size));
            }
            else if (rotate)
            {
                filters.Add(new OrientationFilter());
            }
            filters.Add(new UniqueNameFilter(tmp_mail_dir));


            for (int i = 0; i < selection.Count; i++)
            {
                Photo photo = selection [i] as Photo;
                if ((photo != null) && (!UserCancelled))
                {
                    if (progress_dialog != null)
                    {
                        UserCancelled = progress_dialog.Update(String.Format
                                                                   (Catalog.GetString("Exporting picture \"{0}\""), photo.Name));
                    }

                    if (UserCancelled)
                    {
                        break;
                    }

                    try {
                        // Prepare a tmp_mail file name
                        FilterRequest request = new FilterRequest(photo.DefaultVersionUri);

                        filters.Convert(request);
                        request.Preserve(request.Current);

                        mail_attach.Append(attach_arg.ToString() + request.Current.ToString());

                        // Mark the path for deletion
                        tmp_paths.Add(request.Current.LocalPath);
                    } catch (Exception e) {
                        Console.WriteLine("Error preparing {0}: {1}", selection[photo_index].Name, e.Message);
                        HigMessageDialog md = new HigMessageDialog(parent_window,
                                                                   DialogFlags.DestroyWithParent,
                                                                   MessageType.Error,
                                                                   ButtonsType.Close,
                                                                   Catalog.GetString("Error processing image"),
                                                                   String.Format(Catalog.GetString("An error occured while processing \"{0}\": {1}"), selection[photo_index].Name, e.Message));
                        md.Run();
                        md.Destroy();
                        UserCancelled = true;
                    }
                }
            }             // foreach

            if (progress_dialog != null)
            {
                progress_dialog.Destroy();                  // No need to keep this window
            }
            if (UserCancelled)
            {
                DeleteTempFile();
            }
            else
            {
                // Send the mail :)
                string mail_subject = Catalog.GetString("my photos");
                switch (Preferences.Get <string> (Preferences.GNOME_MAILTO_COMMAND))
                {
                // openSuSE
                case "thunderbird %s":
                    System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
                    break;

                case "icedove %s":
                    System.Diagnostics.Process.Start("icedove", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
                    break;

                case "mozilla-thunderbird %s":
                    System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
                    break;

                case "seamonkey -mail -compose %s":
                    System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=" + mail_subject + ",attachment='" + mail_attach + "'\"");
                    break;

                case "kmail %s":
                    System.Diagnostics.Process.Start("kmail", "  --composer --subject \"" + mail_subject + "\"" + mail_attach);
                    break;

                default:
                    GnomeUtil.UrlShow("mailto:?subject=" + System.Web.HttpUtility.UrlEncode(mail_subject) + mail_attach);
                    break;
                }

                // Check if we have any temporary files to be deleted
                if (tmp_paths.Count > 0)
                {
                    // Fetch timeout value from preferences. In seconds. Needs to be multiplied with 1000 to get msec
                    uint delete_timeout;
                    delete_timeout = (uint)(Preferences.Get <int> (Preferences.EXPORT_EMAIL_DELETE_TIMEOUT_SEC));
                    delete_timeout = delete_timeout * 1000;                     // to get milliseconds.

                    // Start a timer and when it occurs, delete the temp files.
                    GLib.Timeout.Add(delete_timeout, new GLib.TimeoutHandler(DeleteTempFile));
                }
            }
        }
Ejemplo n.º 11
0
    public static void UrlShow(Gtk.Window owner_window, string url)
    {
        GnomeUtil disp = new GnomeUtil(owner_window, url);

        Gtk.Application.Invoke(disp, null, delegate(object sender, EventArgs args) { ((GnomeUtil)disp).Show(); });
    }
Ejemplo n.º 12
0
 void HandleBrowseExisting(object sender, System.EventArgs args)
 {
     GnomeUtil.UrlShow(null, dest.ToString());
 }
        public void Upload()
        {
            // FIXME use mkstemp

            Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;

            try {
                Dialog.Hide();

                Gnome.Vfs.Uri source = new Gnome.Vfs.Uri(Path.Combine(gallery_path, gallery_name));
                Gnome.Vfs.Uri target = dest.Clone();
                target = target.AppendFileName(source.ExtractShortName());

                if (dest.IsLocal)
                {
                    gallery_path = Gnome.Vfs.Uri.GetLocalPathFromUri(dest.ToString());
                }

                progress_dialog.Message  = Catalog.GetString("Building Gallery");
                progress_dialog.Fraction = 0.0;

                FolderGallery gallery;
                if (static_radio.Active)
                {
                    gallery = new HtmlGallery(selection, gallery_path, gallery_name);
                }
                else if (original_radio.Active)
                {
                    gallery = new OriginalGallery(selection, gallery_path, gallery_name);
                }
                else
                {
                    gallery = new FolderGallery(selection, gallery_path, gallery_name);
                }

                if (scale)
                {
                    System.Console.WriteLine("setting scale to {0}", size);
                    gallery.SetScale(size);
                }
                else
                {
                    System.Console.WriteLine("Exporting full size image");
                }

                if (rotate)
                {
                    System.Console.WriteLine("Exporting rotated image");
                    gallery.SetRotate();
                }

                gallery.Description = description;

                gallery.GenerateLayout();
                Filters.FilterSet filter_set = new Filters.FilterSet();
                if (scale)
                {
                    filter_set.Add(new Filters.ResizeFilter((uint)size));
                }
                else if (rotate)
                {
                    filter_set.Add(new Filters.OrientationFilter());
                }
                filter_set.Add(new Filters.ChmodFilter());
                filter_set.Add(new Filters.UniqueNameFilter(gallery_path));

                for (int photo_index = 0; photo_index < selection.Count; photo_index++)
                {
                    try {
                        progress_dialog.Message  = System.String.Format(Catalog.GetString("Uploading picture \"{0}\""), selection[photo_index].Name);
                        progress_dialog.Fraction = photo_index / (double)selection.Count;
                        gallery.ProcessImage(photo_index, filter_set);
                        progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), photo_index, selection.Count);
                    }
                    catch (Exception e) {
                        progress_dialog.Message = String.Format(Catalog.GetString("Error uploading picture \"{0}\" to Gallery:{2}{1}"),
                                                                selection[photo_index].Name, e.Message, Environment.NewLine);
                        progress_dialog.ProgressText = Catalog.GetString("Error");

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

                //create the zip tarballs for original
                if (gallery is OriginalGallery && (bool)Preferences.Get(Preferences.EXPORT_FOLDER_INCLUDE_TARBALLS))
                {
                    (gallery as OriginalGallery).CreateZip();
                }

                // we've created the structure, now if the destination was local we are done
                // otherwise we xfer
                if (!dest.IsLocal)
                {
                    Console.WriteLine(target);
                    System.Console.WriteLine("Xfering {0} to {1}", source.ToString(), target.ToString());
                    result = Gnome.Vfs.Xfer.XferUri(source, target,
                                                    Gnome.Vfs.XferOptions.Default,
                                                    Gnome.Vfs.XferErrorMode.Abort,
                                                    Gnome.Vfs.XferOverwriteMode.Replace,
                                                    Progress);
                }

                if (result == Gnome.Vfs.Result.Ok)
                {
                    progress_dialog.Message      = Catalog.GetString("Done Sending Photos");
                    progress_dialog.Fraction     = 1.0;
                    progress_dialog.ProgressText = Catalog.GetString("Transfer Complete");
                    progress_dialog.ButtonLabel  = Gtk.Stock.Ok;
                }
                else
                {
                    progress_dialog.ProgressText = result.ToString();
                    progress_dialog.Message      = Catalog.GetString("Error While Transferring");
                }

                if (open)
                {
                    GnomeUtil.UrlShow(null, target.ToString());
                }

                // Save these settings for next time
                Preferences.Set(Preferences.EXPORT_FOLDER_SCALE, scale);
                Preferences.Set(Preferences.EXPORT_FOLDER_SIZE, size);
                Preferences.Set(Preferences.EXPORT_FOLDER_OPEN, open);
                Preferences.Set(Preferences.EXPORT_FOLDER_ROTATE, rotate);
                Preferences.Set(Preferences.EXPORT_FOLDER_METHOD, static_radio.Active ? "static" : original_radio.Active ? "original" : "folder");
                Preferences.Set(Preferences.EXPORT_FOLDER_URI, uri_chooser.Uri);
            } catch (System.Exception e) {
                // Console.WriteLine (e);
                progress_dialog.Message      = e.ToString();
                progress_dialog.ProgressText = Catalog.GetString("Error Transferring");
            } finally {
                // if the destination isn't local then we want to remove the temp directory we
                // created.
                if (!dest.IsLocal)
                {
                    System.IO.Directory.Delete(gallery_path, true);
                }

                Gtk.Application.Invoke(delegate { Dialog.Destroy(); });
            }
        }
Ejemplo n.º 14
0
        private void HandleResponse(object sender, Gtk.ResponseArgs args)
        {
            long new_size = 0;
//			long orig_size = 0;
            long actual_total_size = 0;
            int  size = 0;

            System.IO.FileInfo file_info;
            bool UserCancelled = false;
            bool rotate        = true;

            // Lets remove the mail "create mail" dialog
            Dialog.Destroy();

            if (args.ResponseId != Gtk.ResponseType.Ok)
            {
                return;
            }
            ProgressDialog progress_dialog = null;

            actual_total_size = 0;

            progress_dialog = new ProgressDialog(Catalog.GetString("Preparing email"),
                                                 ProgressDialog.CancelButtonType.Stop,
                                                 selection.Items.Length,
                                                 parent_window);

            size = GetScaleSize();             // Which size should we scale to. 0 --> Original

            // evaluate mailto command and define attachment args for cli
            System.Text.StringBuilder attach_arg = new System.Text.StringBuilder();
            switch (Preferences.Get(Preferences.GNOME_MAILTO_COMMAND) as string)
            {
            case "thunderbird %s":
            case "mozilla-thunderbird %s":
            case "seamonkey -mail -compose %s":
            case "icedove %s":
                attach_arg.Append(",");
                break;

            case "kmail %s":
                attach_arg.Append(" --attach ");
                break;

            default:                      //evolution falls into default, since it supports mailto uri correctly
                attach_arg.Append("&attach=");
                break;
            }

            rotate = rotate_check.Active;              // Should we automatically rotate original photos.
            Preferences.Set(Preferences.EXPORT_EMAIL_ROTATE, rotate);

            // Initiate storage for temporary files to be deleted later
            tmp_paths = new System.Collections.ArrayList();

            // Create a tmp directory.
            tmp_mail_dir = System.IO.Path.GetTempFileName();                    // Create a tmp file
            System.IO.File.Delete(tmp_mail_dir);                                // Delete above tmp file
            System.IO.Directory.CreateDirectory(tmp_mail_dir);                  // Create a directory with above tmp name

            System.Text.StringBuilder mail_attach = new System.Text.StringBuilder();

            FilterSet filters = new FilterSet();

            if (size != 0)
            {
                filters.Add(new ResizeFilter((uint)size));
            }
            else if (rotate)
            {
                filters.Add(new OrientationFilter());
            }
            filters.Add(new UniqueNameFilter(tmp_mail_dir));


            foreach (Photo photo in selection.Items)
            {
                if ((photo != null) && (!UserCancelled))
                {
                    if (progress_dialog != null)
                    {
                        UserCancelled = progress_dialog.Update(String.Format
                                                                   (Catalog.GetString("Exporting picture \"{0}\""), photo.Name));
                    }

                    if (UserCancelled)
                    {
                        break;
                    }

                    file_info = new System.IO.FileInfo(photo.GetVersionPath(photo.DefaultVersionId));
//					orig_size = file_info.Length;

                    // Prepare a tmp_mail file name
                    FilterRequest request = new FilterRequest(photo.DefaultVersionUri);

                    filters.Convert(request);
                    request.Preserve(request.Current);

                    mail_attach.Append(attach_arg.ToString() + System.Web.HttpUtility.UrlEncode(request.Current.ToString()));

                    // Mark the path for deletion
                    tmp_paths.Add(request.Current.LocalPath);

                    // Update the running total of the actual file sizes.
                    file_info          = new System.IO.FileInfo(request.Current.LocalPath);
                    new_size           = file_info.Length;
                    actual_total_size += new_size;

                    // Update dialog to indicate Actual size!
                    // This is currently disabled, since the dialog box is not visible at this stage.
                    // string approxresult = SizeUtil.ToHumanReadable (actual_total_size);
                    // ActualMailSize.Text = approxresult;


                    //System.Console.WriteLine ("Orig file size {0}, New file size {1}, % {4}, Scaled to size {2}, new name {3}",
                    //orig_size, new_size, size, tmp_path, 1 - ((orig_size-new_size)/orig_size));
                }
            }             // foreach

            if (progress_dialog != null)
            {
                progress_dialog.Destroy();                  // No need to keep this window
            }
            if (UserCancelled)
            {
                DeleteTempFile();
            }
            else
            {
                // Send the mail :)
                switch (Preferences.Get(Preferences.GNOME_MAILTO_COMMAND) as string)
                {
                // openSuSE
                case "thunderbird %s":
                    System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
                    break;

                case "icedove %s":
                    System.Diagnostics.Process.Start("thunderbird", " -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
                    break;

                case "mozilla-thunderbird %s":
                    System.Diagnostics.Process.Start("mozilla-thunderbird", " -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
                    break;

                case "seamonkey -mail -compose %s":
                    System.Diagnostics.Process.Start("seamonkey", " -mail -compose \"subject=my photos,attachment='" + mail_attach + "'\"");
                    break;

                case "kmail %s":
                    System.Diagnostics.Process.Start("kmail", "  --composer --subject \"my photos\"" + mail_attach);
                    break;

                default:
                    GnomeUtil.UrlShow(parent_window, "mailto:?subject=my%20photos" + mail_attach);
                    break;
                }

                // Check if we have any temporary files to be deleted
                if (tmp_paths.Count > 0)
                {
                    // Fetch timeout value from preferences. In seconds. Needs to be multiplied with 1000 to get msec
                    uint delete_timeout;
                    delete_timeout = (uint)((int)Preferences.Get(Preferences.EXPORT_EMAIL_DELETE_TIMEOUT_SEC));
                    delete_timeout = delete_timeout * 1000;                     // to get milliseconds.

                    // Start a timer and when it occurs, delete the temp files.
                    GLib.Timeout.Add(delete_timeout, new GLib.TimeoutHandler(DeleteTempFile));
                }
            }
        }
Ejemplo n.º 15
0
        private void Upload()
        {
            account.Gallery.Progress          = new ProgressItem();
            account.Gallery.Progress.Changed += HandleProgressChanged;

            System.Console.WriteLine("Starting upload");

            FilterSet filters = new FilterSet();

            if (account.Version == GalleryVersion.Version1)
            {
                filters.Add(new WhiteListFilter(new string [] { ".jpg", ".jpeg", ".png", ".gif" }));
            }
            if (scale)
            {
                filters.Add(new ResizeFilter((uint)size));
            }
            else if (rotate)
            {
                filters.Add(new OrientationFilter());
            }


            while (photo_index < items.Length)
            {
                IBrowsableItem item = items [photo_index];

                System.Console.WriteLine("uploading {0}", photo_index);

                progress_dialog.Message  = System.String.Format(Catalog.GetString("Uploading picture \"{0}\""), item.Name);
                progress_dialog.Fraction = photo_index / (double)items.Length;
                photo_index++;

                progress_dialog.ProgressText = System.String.Format(Catalog.GetString("{0} of {1}"), photo_index, items.Length);


                FilterRequest req = new FilterRequest(item.DefaultVersionUri);

                filters.Convert(req);
                try {
                    int id = album.Add(item, req.Current.LocalPath);

                    if (item != null && item is Photo && Core.Database != null && id != 0)
                    {
                        Core.Database.Exports.Create((item as Photo).Id, (item as Photo).DefaultVersionId,
                                                     ExportStore.Gallery2ExportType,
                                                     String.Format("{0}:{1}", album.Gallery.Uri.ToString(), id.ToString()));
                    }
                } catch (System.Exception e) {
                    progress_dialog.Message      = String.Format(Catalog.GetString("Error uploading picture \"{0}\" to Gallery: {1}"), item.Name, e.Message);
                    progress_dialog.ProgressText = Catalog.GetString("Error");
                    Console.WriteLine(e);

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

            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;

            if (browser)
            {
                GnomeUtil.UrlShow(album.GetUrl());
            }
        }