@@ -3,7 +3,7 @@ using GLib;
33using Gtk ;
44
55public class Pdftag : ApplicationWindow {
6- private string filename ;
6+ private File pdf_file ;
77 private Poppler . Document document;
88 private Entry title_entry;
99 private Entry author_entry;
@@ -15,7 +15,6 @@ public class Pdftag : ApplicationWindow {
1515 private Label pages_label;
1616 private HeaderBar header;
1717 private CheckButton check;
18- private string document_path;
1918 private bool overwrite = false ;
2019
2120 private Button creation_date_btn;
@@ -230,8 +229,7 @@ public class Pdftag : ApplicationWindow {
230229
231230 /* handle first argument -- it only works as an absolute path */
232231 if (args[1 ] != null ) {
233- this . filename = args[1 ];
234- this . document_path = " file://" + this . filename;
232+ this . pdf_file = File . new_for_path (args[1 ]);
235233 update_information ();
236234 }
237235
@@ -289,20 +287,20 @@ public class Pdftag : ApplicationWindow {
289287 file_chooser. set_filter (filter);
290288 filter. add_mime_type (" image/pdf" );
291289 if (file_chooser. run () == ResponseType . ACCEPT ) {
292- this . filename = file_chooser. get_filename ();
290+ this . pdf_file = file_chooser. get_file ();
293291 }
294292 file_chooser. destroy ();
295- this . document_path = " file://" + filename;
296293
297294 /* update text entries with current metadata */
298295 update_information ();
299296 }
300297
301298 private void update_information () {
302299 try {
303- this . header. title = Path . get_basename (filename);
304- this . header. subtitle = filename. replace (Path . get_basename (filename), " " );
305- this . document = new Poppler .Document .from_file (this . document_path, null );
300+ var base_name = Path . get_basename (pdf_file. get_path ());
301+ this . header. title = base_name;
302+ this . header. subtitle = this . pdf_file. get_parse_name (). replace (base_name, " " );
303+ this . document = new Poppler .Document .from_file (this . pdf_file. get_uri (), null );
306304 this . title_entry. text = this . document. title ?? " " ;
307305 this . author_entry. text = this . document. author ?? " " ;
308306 this . subject_entry. text = this . document. subject ?? " " ;
@@ -339,7 +337,7 @@ public class Pdftag : ApplicationWindow {
339337 }
340338
341339 private void on_tag () {
342- if (this . document_path != null ) {
340+ if (this . pdf_file != null ) {
343341 this . document. title = this . title_entry. text;
344342 this . document. author = this . author_entry. text;
345343 this . document. subject = this . subject_entry. text;
@@ -372,10 +370,10 @@ public class Pdftag : ApplicationWindow {
372370 // save the modified document
373371 try {
374372 FileIOStream iostream;
375- var tmp_pdf = File . new_tmp (" tmp-XXXXXX.pdf" , out iostream);
376- this . document. save(" file:// " + tmp_pdf. get_path ());
373+ var tmp_pdf = File . new_tmp (" pdftag- tmp-XXXXXX.pdf" , out iostream);
374+ this . document. save(tmp_pdf. get_uri ());
377375 if (overwrite) {
378- var final_pdf = File . new_for_commandline_arg (this . document_path );
376+ var final_pdf = File . new_for_commandline_arg (this . pdf_file . get_path () );
379377 tmp_pdf. move (final_pdf, FileCopyFlags . OVERWRITE , null , null );
380378 }
381379 } catch (Error e) {
0 commit comments