Package: gscan2pdf
Version: 1.0.2-1
Severity: normal
Tags: patch

Hi,

Recent scanners promote features for submission to Evernote.com.
It may be great that gscan2pdf support evernote and other online storage
service.

An attachment is a patch to primitive support for evernote submission.

We can use two option to submit pdf to evernote.com
1) use Evernote client for MS Windows on WINE.
2) use nixnote Evernote client clone.

A patch attached is against (1) client on WINE.
It will need further work but it is useful for you and users.


Hiroshi

--- gscan2pdf-1.0.2/bin/gscan2pdf	2012-03-27 20:40:46.000000000 +0900
+++ gscan2pdf-1.0.2-miura01/bin/gscan2pdf	2012-04-07 14:35:30.171428474 +0900
@@ -464,7 +464,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 +534,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 +762,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 +830,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 +882,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 +1674,7 @@
  $dependencies{djvu}        = check_command('cjb2');
  $dependencies{unpaper}     = check_command('unpaper');
  $dependencies{libtiff}     = check_command('tiffcp');
+ $dependencies{nixnote}     = check_command('nixnote');
  $logger->info("Found Image::Magick") if ( $dependencies{perlmagick} );
  $logger->info("Found ImageMagick")   if ( $dependencies{imagemagick} );
  $logger->info("Found scanadf")       if ( $dependencies{scanadf} );
@@ -1676,6 +1685,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} );
+
 
  # OCR engine options
  push @ocr_engine,
@@ -1726,9 +1737,11 @@
  $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 +1886,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 +1911,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 +3789,146 @@
  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' );
+   my $txt = File::Temp->new( DIR => $session, SUFFIX => '.txt' );
+
+   # 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};
+     # FIXME: sanitize title and keywords characters
+
+     # my $evernote = "/usr/bin/wine \"".$ENV{HOME}."/.wine/drive_c/Program Files/Evernote/Evernote/Enscript.exe\" createNote /s $txt /t gscan2pdf /i \"$etitle\" /a $pdf";
+
+     my $evernote = "/usr/bin/wine \"".$ENV{HOME}."/.wine/drive_c/Program Files/Evernote/Evernote/Enscript.exe\" createNote /s $txt /t gscan2pdf /a $pdf";
+
+     #if defined $SETTING{keywords} {
+     #   my @keywords = split( /,/, $SETTING{keywords});
+     #   foreach my $kw (@keywords) {
+     #     $evernote .= " /t \"".$kw."\"";
+     #   }
+     #}
+
+     open (OUT, ">$txt");
+     print (OUT $etitle."\n");
+     print (OUT $SETTING{keywords}."\n") if defined $SETTING{keywords};
+     print (OUT "scanned by gscan2pdf\n");
+     close (OUT);
+
+     $logger->info($evernote);
+     show_message_dialog( $main::window, 'error', 'close',
+      $main::d->get('Error sending to Evernote') )
+       if ( system($evernote) );
+    },
+    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;
+}
+
 # Scan
 
 sub scan_dialog {
@@ -11023,6 +11185,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 +11378,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.

Reply via email to