// HACK: should not create a form in a process object
        void ProvidePassword(PdfPasswordProviderArgs args)
        {
            using (PasswordForm form = new PasswordForm(this.path))
            {
                switch (form.ShowDialog())
                {
                case DialogResult.OK:
                    args.Password = form.Password;
                    break;

                case DialogResult.Cancel:
                    args.Abort = true;
                    break;
                }
            }
        }
Esempio n. 2
0
        public void PasswordProvider(PdfPasswordProviderArgs args)
        {
            // This method is called from some random thread, but we need
            // to do the dialog on the GUI thread; use the reset_event
            // to block this thread until the user is done with the dialog.
            ThreadAssist.BlockingProxyToMain(delegate {
                Log.Debug("Password requested to open document");
                var dialog = new Hyena.Widgets.HigMessageDialog(
                    Window, DialogFlags.Modal, MessageType.Question, ButtonsType.None,
                    Catalog.GetString("Document is Encrypted"),
                    Catalog.GetString("Enter the document's password to open it:")
                    );
                dialog.Image = Gtk.IconTheme.Default.LoadIcon("dialog-password", 48, 0);

                var password_entry = new Entry()
                {
                    Visibility = false
                };
                password_entry.Show();
                dialog.LabelVBox.PackStart(password_entry, false, false, 12);

                dialog.AddButton(Stock.Cancel, ResponseType.Cancel, false);
                dialog.AddButton(Stock.Ok, ResponseType.Ok, true);

                var response    = (ResponseType)dialog.Run();
                string password = password_entry.Text;
                dialog.Destroy();

                if (response == ResponseType.Ok)
                {
                    args.Password = Document.Password = password;
                }
                else
                {
                    Log.Information("Password dialog cancelled");
                    args.Abort = true;
                }
            });
        }
Esempio n. 3
0
 /// <summary>
 /// The 'get the password' call back function.
 /// </summary>
 static void PasswordProvider(PdfPasswordProviderArgs args)
 {
     // Show a dialog here in a real application.
     args.Password = "******";
 }