class PDFWalker::Walker::UsageRightsWizard

Public Class Methods

new(parent, pdf) click to toggle source
Calls superclass method
# File lib/pdfwalker/signing.rb, line 169
def initialize(parent, pdf)
    super()

    @parent = parent
    @pkey, @cert = nil, nil

    create_intro_page
    create_keypair_import_page
    create_rights_selection_page
    create_termination_page

    signal_connect('delete_event') { self.destroy }
    signal_connect('cancel') { self.destroy }
    signal_connect('close') { self.destroy }

    signal_connect('apply') {
        rights = selected_usage_rights

        begin
            pdf.enable_usage_rights(@cert, @pkey, *rights)

            set_page_title(@lastpage, "Usage Rights have been enabled")
            @msg_status.text = "Usage Rights have been enabled for the current document.\n You should consider saving it now."

            @parent.reload
        rescue
            @parent.error("#{$!}: #{$!.backtrace.join($/)}")

            set_page_title(@lastpage, "Usage Rights have not been enabled")
            @msg_status.text = "An error occured during the signature process."
        end
    }

    set_modal(true)

    show_all
end

Private Instance Methods

create_annotations_rights_frame() click to toggle source
# File lib/pdfwalker/signing.rb, line 279
def create_annotations_rights_frame
    frame = create_rights_frame(" Annotations ")

    annots_table = Table.new(4, 2)
    annots =
    [
        [ @annots_create = CheckButton.new("Create"), @annots_import = CheckButton.new("Import") ],
        [ @annots_delete = CheckButton.new("Delete"), @annots_export = CheckButton.new("Export") ],
        [ @annots_modify = CheckButton.new("Modify"), @annots_online = CheckButton.new("Online") ],
        [ @annots_copy = CheckButton.new("Copy"), @annots_sumview = CheckButton.new("Summary View") ]
    ]

    annots.each_with_index do |cols, row|
        col1, col2 = cols

        col1.active = true
        col2.active = true

        annots_table.attach(col1, 0, 1, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
        annots_table.attach(col2, 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
    end

    frame.add(annots_table)
end
create_document_rights_frame() click to toggle source
# File lib/pdfwalker/signing.rb, line 269
def create_document_rights_frame
    frame = create_rights_frame(" Document ")

    @document_fullsave = CheckButton.new("Full Save").set_active(true)

    doc_table = Table.new(1, 2)
    doc_table.attach(@document_fullsave, 0, 1, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
    frame.add(doc_table)
end
create_embedded_files_rights_frame() click to toggle source
# File lib/pdfwalker/signing.rb, line 339
def create_embedded_files_rights_frame
    frame = create_rights_frame(" Embedded files ")

    ef_table = Table.new(2,2)
    ef_buttons =
    [
        [ @ef_create = CheckButton.new("Create"), @ef_modify = CheckButton.new("Modify") ],
        [ @ef_delete = CheckButton.new("Delete"), @ef_import = CheckButton.new("Import") ]
    ]

    ef_buttons.each_with_index do |cols, row|
        col1, col2 = cols

        col1.active = true
        col2.active = true

        ef_table.attach(col1, 0, 1, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
        ef_table.attach(col2, 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
    end

    frame.add(ef_table)
end
create_form_rights_frame() click to toggle source
# File lib/pdfwalker/signing.rb, line 304
def create_form_rights_frame
    frame = create_rights_frame(" Forms ")

    form_table = Table.new(4, 2)
    forms =
    [
        [ @form_fillin = CheckButton.new("Fill in"), @form_spawntemplate = CheckButton.new("Spawn template") ],
        [ @form_import = CheckButton.new("Import"), @form_barcode = CheckButton.new("Barcode plaintext") ],
        [ @form_export = CheckButton.new("Export"), @form_online = CheckButton.new("Online") ],
        [ @form_submit = CheckButton.new("Submit stand-alone"), nil ]
    ]

    forms.each_with_index do |cols, row|
        col1, col2 = cols

        col1.active = true
        col2.active = true unless col2.nil?

        form_table.attach(col1, 0, 1, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
        form_table.attach(col2, 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4) unless col2.nil?
    end

    frame.add(form_table)
end
create_intro_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 240
            def create_intro_page
                intro = <<-INTRO.gsub(/^\s+/, '')
                    You are about to enable Usage Rights for the current PDF document.
                    To enable these features, you need to have an Adobe public/private key pair in your possession.

                    Make sure you have adobe.crt and adobe.key located in the current directory.
                INTRO

                vbox = VBox.new(false, 5)
                vbox.set_border_width(5)

                lbl = Label.new(intro).set_justify(Gtk::JUSTIFY_LEFT).set_wrap(true)

                vbox.pack_start(lbl, true, true, 0)

                append_page(vbox)
                set_page_title(vbox, "Usage Rights Wizard")
                set_page_type(vbox, Assistant::PAGE_INTRO)
                set_page_complete(vbox, true)
            end
create_rights_frame(name) click to toggle source
# File lib/pdfwalker/signing.rb, line 261
def create_rights_frame(name)
    frame = Frame.new(name)
    frame.border_width = 5
    frame.shadow_type = Gtk::SHADOW_IN

    frame
end
create_rights_selection_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 362
def create_rights_selection_page
    vbox = VBox.new(false, 5)

    vbox.add create_document_rights_frame
    vbox.add create_annotations_rights_frame
    vbox.add create_form_rights_frame
    vbox.add create_signature_rights_frame
    vbox.add create_embedded_files_rights_frame

    append_page(vbox)
    set_page_title(vbox, "Select Usage Rights to enable")
    set_page_type(vbox, Assistant::PAGE_CONFIRM)
    set_page_complete(vbox, true)
end
create_signature_rights_frame() click to toggle source
# File lib/pdfwalker/signing.rb, line 329
def create_signature_rights_frame
    frame = create_rights_frame(" Signature ")

    @signature_modify = CheckButton.new("Modify").set_active(true)

    signature_table = Table.new(1, 2)
    signature_table.attach(@signature_modify, 0, 1, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 4, 4)
    frame.add(signature_table)
end
create_termination_page() click to toggle source
# File lib/pdfwalker/signing.rb, line 377
def create_termination_page
    @lastpage = VBox.new(false, 5)

    @msg_status = Label.new
    @lastpage.pack_start(@msg_status, true, true, 0)

    append_page(@lastpage)
    set_page_title(@lastpage, "Usage Rights have not been enabled")
    set_page_type(@lastpage, Assistant::PAGE_SUMMARY)
end
selected_usage_rights() click to toggle source
# File lib/pdfwalker/signing.rb, line 209
def selected_usage_rights
    [
        [ Origami::UsageRights::Rights::DOCUMENT_FULLSAVE, @document_fullsave ],

        [ Origami::UsageRights::Rights::ANNOTS_CREATE, @annots_create ],
        [ Origami::UsageRights::Rights::ANNOTS_DELETE, @annots_delete ],
        [ Origami::UsageRights::Rights::ANNOTS_MODIFY, @annots_modify ],
        [ Origami::UsageRights::Rights::ANNOTS_COPY, @annots_copy ],
        [ Origami::UsageRights::Rights::ANNOTS_IMPORT, @annots_import ],
        [ Origami::UsageRights::Rights::ANNOTS_EXPORT, @annots_export ],
        [ Origami::UsageRights::Rights::ANNOTS_ONLINE, @annots_online ],
        [ Origami::UsageRights::Rights::ANNOTS_SUMMARYVIEW, @annots_sumview ],

        [ Origami::UsageRights::Rights::FORM_FILLIN, @form_fillin ],
        [ Origami::UsageRights::Rights::FORM_IMPORT, @form_import ],
        [ Origami::UsageRights::Rights::FORM_EXPORT, @form_export ],
        [ Origami::UsageRights::Rights::FORM_SUBMITSTANDALONE, @form_submit ],
        [ Origami::UsageRights::Rights::FORM_SPAWNTEMPLATE, @form_spawntemplate ],
        [ Origami::UsageRights::Rights::FORM_BARCODEPLAINTEXT, @form_barcode ],
        [ Origami::UsageRights::Rights::FORM_ONLINE, @form_online ],

        [ Origami::UsageRights::Rights::SIGNATURE_MODIFY, @signature_modify ],

        [ Origami::UsageRights::Rights::EF_CREATE, @ef_create ],
        [ Origami::UsageRights::Rights::EF_DELETE, @ef_delete ],
        [ Origami::UsageRights::Rights::EF_MODIFY, @ef_modify ],
        [ Origami::UsageRights::Rights::EF_IMPORT, @ef_import ],
    ].select { |_, button| button.active? }
     .map { |right, _| right }
end