Package: gscan2pdf Version: 1.0.2-1 Tags: patch Hi,
I updated my proposal which include 1) support title, tags etc in multi-language. previous patch has a bug that cause MOJIBAKE in Japanese. at least, Chinese, Korean and Japanese works. 2) more security consideration 3) check dependencies to wine 4) fix minor bug: gray out when startup 5) now use $SETTING{Title} as title of note. nixnote have never supported a command line option now. It is because this patch don't enable nixnote as an option, but it include a snippet for nixnote. Could you please find and review an attachment? Known issues and ToDo: 1) should check an existence of evernote client: $HOME/.wine/drive_c/Program Files/Evernote/Evernote/ENScript.exe 2) Add GUI button. 3) A nixnote support (nixnote need to have import feature from command line) 4) translations 5) human readable pdf filename Hiroshi
--- gscan2pdf-1.0.2/bin/gscan2pdf 2012-03-27 20:40:46.000000000 +0900 +++ gscan2pdf-1.0.2-miura01/bin/gscan2pdf 2012-04-08 10:41:33.903622536 +0900 @@ -146,6 +146,7 @@ # To sort out LC_NUMERIC and $SIG{CHLD} use POSIX qw(locale_h :signal_h :errno_h :sys_wait_h); use Locale::gettext 1.05; # For translations +use Encode; my $prog_name = 'gscan2pdf'; my $version = '1.0.2'; @@ -240,6 +241,9 @@ push @device_list, { name => $_, label => $_ }; } +# Get working Locale +our $wlocale = setlocale(LC_CTYPE); + # Set LC_NUMERIC to C to prevent decimal commas (or anything else) confusing # scanimage setlocale( LC_NUMERIC, "C" ); @@ -464,7 +468,7 @@ # Define application-wide variables here so that they can be referenced # in the menu callbacks my ( - $slist, $windowi, $windowe, $windows, $windows2, $windowh, $windowo, $windowrn, + $slist, $windowi, $windowe, $windowv, $windows, $windows2, $windowh, $windowo, $windowrn, $windowu, $vboxd, $labeld, $combobd, $combobp, $vboxm, @undo_buffer, @redo_buffer, @undo_selection, @redo_selection, %dependencies, %helperTag, @@ -534,10 +538,15 @@ ], [ 'Email as PDF', 'gtk-edit', - $d->get('_Email as PDF'), '<control>e', + $d->get('E_mail as PDF'), '<control>m', $d->get('Attach as PDF to a new email'), \&email ], [ + 'Send to Evernote', 'gtk-edit', + $d->get('Send to _Evernote'), '<control>e', + $d->get('Attach as PDF to your Evernote notebook'), \&evernote + ], + [ 'Print', 'gtk-print', $d->get('_Print'), '<control>p', $d->get('Print'), \&print_dialog ], @@ -757,6 +766,7 @@ <menuitem action='Scan'/> <menuitem action='Save'/> <menuitem action='Email as PDF'/> + <menuitem action='Send to Evernote'/> <menuitem action='Print'/> <separator/> <menuitem action='Compress'/> @@ -824,6 +834,7 @@ <toolitem action='Scan'/> <toolitem action='Save'/> <toolitem action='Email as PDF'/> + <toolitem action='Send to Evernote'/> <toolitem action='Print'/> <separator/> <toolitem action='Undo'/> @@ -875,6 +886,7 @@ <popup name='Thumb_Popup'> <menuitem action='Save'/> <menuitem action='Email as PDF'/> + <menuitem action='Send to Evernote'/> <menuitem action='Print'/> <separator/> <menuitem action='Renumber'/> @@ -1666,6 +1678,8 @@ $dependencies{djvu} = check_command('cjb2'); $dependencies{unpaper} = check_command('unpaper'); $dependencies{libtiff} = check_command('tiffcp'); + $dependencies{nixnote} = check_command('nixnote'); + $dependencies{wine} = check_command('wine'); $logger->info("Found Image::Magick") if ( $dependencies{perlmagick} ); $logger->info("Found ImageMagick") if ( $dependencies{imagemagick} ); $logger->info("Found scanadf") if ( $dependencies{scanadf} ); @@ -1676,6 +1690,8 @@ $logger->info("Found cjb2 (djvu)") if ( $dependencies{djvu} ); $logger->info("Found unpaper") if ( $dependencies{unpaper} ); $logger->info("Found libtiff") if ( $dependencies{libtiff} ); + $logger->info("Found nixnote") if ( $dependencies{nixnote} ); + $logger->info("Found wine") if ( $dependencies{wine} ); # OCR engine options push @ocr_engine, @@ -1714,6 +1730,10 @@ $msg .= $d->get("Email as PDF requires xdg-email\n") if ( !$dependencies{xdg} ); + # Ghost evernote item if wine or nixnote not available + $msg .= $d->get("Send to Evernote requires WINE/evernote or nixnote\n") + if ( !$dependencies{wine} && !$dependencies{nixnote} ); + # Undo/redo start off ghosted anyway- $uimanager->get_widget('/MenuBar/Edit/Undo')->set_sensitive(FALSE); $uimanager->get_widget('/MenuBar/Edit/Redo')->set_sensitive(FALSE); @@ -1723,12 +1743,15 @@ # save * start off ghosted anyway- $uimanager->get_widget('/MenuBar/File/Save')->set_sensitive(FALSE); $uimanager->get_widget('/MenuBar/File/Email as PDF')->set_sensitive(FALSE); + $uimanager->get_widget('/MenuBar/File/Send to Evernote')->set_sensitive(FALSE); $uimanager->get_widget('/MenuBar/File/Print')->set_sensitive(FALSE); $uimanager->get_widget('/ToolBar/Save')->set_sensitive(FALSE); $uimanager->get_widget('/ToolBar/Email as PDF')->set_sensitive(FALSE); + $uimanager->get_widget('/ToolBar/Send to Evernote')->set_sensitive(FALSE); $uimanager->get_widget('/ToolBar/Print')->set_sensitive(FALSE); $uimanager->get_widget('/Thumb_Popup/Save')->set_sensitive(FALSE); $uimanager->get_widget('/Thumb_Popup/Email as PDF')->set_sensitive(FALSE); + $uimanager->get_widget('/Thumb_Popup/Send to Evernote')->set_sensitive(FALSE); $uimanager->get_widget('/Thumb_Popup/Print')->set_sensitive(FALSE); $uimanager->get_widget('/MenuBar/Tools/Threshold')->set_sensitive(FALSE); @@ -1873,6 +1896,10 @@ $uimanager->get_widget('/ToolBar/Print')->set_sensitive(TRUE); $uimanager->get_widget('/Thumb_Popup/Print')->set_sensitive(TRUE); + $uimanager->get_widget('/MenuBar/File/Send to Evernote')->set_sensitive(TRUE); + $uimanager->get_widget('/ToolBar/Send to Evernote')->set_sensitive(TRUE); + $uimanager->get_widget('/Thumb_Popup/Send to Evernote')->set_sensitive(TRUE); + $dependencies{pages} = $#{ $slist->{data} }; } } @@ -1894,6 +1921,11 @@ $uimanager->get_widget('/Thumb_Popup/Print')->set_sensitive(FALSE); $windowi->hide if defined $windowi; + $uimanager->get_widget('/MenuBar/File/Send to Evernote')->set_sensitive(FALSE); + $uimanager->get_widget('/ToolBar/Send to Evernote')->set_sensitive(FALSE); + $uimanager->get_widget('/Thumb_Popup/Send to Evernote')->set_sensitive(FALSE); + $windowv->hide if defined $windowv; + $dependencies{pages} = $#{ $slist->{data} }; } } @@ -3767,6 +3799,181 @@ return; } +# Display page selector and evernote. +# copy snippet from mail() + +sub evernote { + + if ( defined $windowv ) { + $windowv->present; + return; + } + + ( $windowv, my $vbox ) = + create_window( $window, $d->get('Send to Evernote'), FALSE ); + + # PDF options + my ( $entrya, $entryt, $entrys, $entryk ) = add_pdf_metadata($vbox); + + # Frame for page range + add_page_range($vbox); + + # Compression options + my ( $buttond, $spinbuttond, $combob, $hboxq, $spinbuttonq, @compression ) = + add_pdf_compression($vbox); + + # HBox for buttons + my $hboxb = Gtk2::HBox->new; + $vbox->pack_start( $hboxb, FALSE, TRUE, 0 ); + + # OK button + my $sbutton = Gtk2::Button->new_from_stock('gtk-ok'); + $hboxb->pack_start( $sbutton, TRUE, TRUE, 0 ); + $sbutton->signal_connect( + clicked => sub { + + # Set options + update_PDF_settings( $entrya, $entryt, $entrys, $entryk ); + + # Compile list of pages + my @list_of_pages; + my @pagelist = get_page_index(); + for (@pagelist) { + push @list_of_pages, $slist->{data}[$_][2]; + } + + # dig out the compression + $SETTING{'downsample'} = $buttond->get_active; + $SETTING{'downsample dpi'} = $spinbuttond->get_value; + $SETTING{'pdf compression'} = $compression[ $combob->get_active ][0]; + $SETTING{'quality'} = $spinbuttonq->get_value; + + # Compile options + my %options = ( + compression => $SETTING{'pdf compression'}, + downsample => $SETTING{downsample}, + 'downsample dpi' => $SETTING{'downsample dpi'}, + quality => $SETTING{quality}, + font => $SETTING{'pdf font'}, + ); + + my $pdf = File::Temp->new( DIR => $session, SUFFIX => '.pdf' ); + + # Create the PDF + my $signal; + $slist->save_pdf( + $pdf->filename, + \@list_of_pages, + get_pdf_metadata(), + \%options, + sub { # queued + my ( $process, $completed, $total, $message, $progress ) = @_; + return update_tpbar( 1, $process, $completed, $total, $message, + $progress ); + }, + sub { # started + my ( $thread, $process, $completed, $total, $pid ) = @_; + $signal = setup_tpbar( $thread, $process, $completed, $total, $pid ); + return TRUE if ( defined $signal ); + }, + sub { # running + my ( $thread, $process, $completed, $total, $message, $progress ) = @_; + return update_tpbar( $thread, $process, $completed, $total, $message, + $progress ); + }, + sub { # finished + my ( $new_page, $pending ) = @_; + $thbox->hide_all unless $pending; + $tcbutton->signal_handler_disconnect($signal) if ( defined $signal ); + mark_pages(@pagelist); + system("xdg-open", $pdf, "&") + if ( defined( $SETTING{'view files toggle'} ) + and $SETTING{'view files toggle'} ); + + # Create note text + my $etitle = "gscan2pdf"; + $etitle = $SETTING{title} if defined $SETTING{title}; + my @keywords=("gscan2pdf"); + if (defined $SETTING{keywords}) { + unshift(@keywords, split( /,/, $SETTING{keywords})); + } + + my @evernote_client = evernote_windows_client($pdf, $etitle, \@keywords); + + $logger->info(join(',',@evernote_client)); + show_message_dialog( $main::window, 'error', 'close', + $main::d->get('Error sending to Evernote') ) + if ( system(@evernote_client) ); + }, + sub { # error + show_message_dialog( $main::window, 'error', 'close', + $Gscan2pdf::_self->{message} ); + } + ); + + $windowv->hide; + + } + ); + + # Cancel button + my $cbutton = Gtk2::Button->new_from_stock('gtk-cancel'); + $hboxb->pack_end( $cbutton, FALSE, FALSE, 0 ); + $cbutton->signal_connect( clicked => sub { $windowv->hide; } ); + + $windowv->show_all; + $hboxq->hide_all if ( $compression[ $combob->get_active ][0] ne 'jpg' ); + return; +} + +sub evernote_nixnote_client { + my ($pdf, $etitle,$keywords) = @_; + + # There is no command line support for document import now. + #FIXME: this is mock codes. + my @nixnote_cmd = ("/usr/bin/nixnote", "--add", + "--title", $etitle, + "--tags", join(':',\$keywords), + "--attachments", $pdf); + return @nixnote_cmd +} + +sub evernote_windows_client { + my ($pdf, $etitle, $keywords) = @_; + my $txt = File::Temp->new( DIR => $session, SUFFIX => '.txt' ); + # FIXME: command line locale concideration + my @evernote_cmd = ("/usr/bin/wine", + $ENV{HOME}."/.wine/drive_c/Program Files/Evernote/Evernote/Enscript.exe", + "createNote", + "/s", $txt, + "/i", $etitle, + "/a", $pdf); + foreach my $kw (@$keywords) { + push(@evernote_cmd, "/t"); + push(@evernote_cmd, $kw); + } + #Windows(WINE) evernote client use other than UTF-8 + #FIXME: support Arabic and other languages + #CJK + if ($wlocale =~ /^ja/) { + open (OUT, ">:encoding(shiftjis)", $txt); + } elsif ($wlocale =~ /^ko/) { + open (OUT, ">:encoding(euc-kr)", $txt); + } elsif ($wlocale =~ /^zh_CN/) { + open (OUT, ">:encoding(gb2312)", $txt); + } elsif ($wlocale =~ /^zh_TW/) { + open (OUT, ">:encoding(big5)", $txt); + } else { + open (OUT, ">:encoding(windows-1252)", $txt); #default: Western + } + print (OUT $etitle."\n"); + print (OUT join(',', $SETTING{keywords})."\n") if defined $SETTING{keywords}; + print (OUT "scanned by gscan2pdf\n"); + close (OUT); + + return @evernote_cmd; +} + # Scan sub scan_dialog { @@ -11023,6 +11230,14 @@ A command line OCR. See L<http://launchpad.net/cuneiform-linux> +=item evernote + +A MS Windows client application running on WINE. See L<http://www.evernote.com/> + +=item nixnote + +A evernote client clone on Linux. See L<http://nevernote.sourceforge.net/> + =back =back @@ -11208,6 +11423,13 @@ This requires xdg-email, which is in the xdg-utils package. If this is not present, the option is ghosted out. +=head3 Send to Evernote + +Attaches the selected or all pages as a PDF to your Evernote default notebook. +This requires evernote client utility ENscript.exe on WINE where is +in .wine/drive_c/Program Files/Evernote/Evernote/. +If this is not present, the option is ghosted out. + =head3 Print Prints the selected or all pages.