Skip to content

Commit 233ca8a

Browse files
author
Adrià Arrufat
committed
fix segfault when no file was selected
1 parent a00908f commit 233ca8a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main.vala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public class Pdftag : ApplicationWindow {
219219

220220
/* tag button */
221221
this.tag_btn = new Gtk.Button.with_label ("Tag");
222-
this.tag_btn.clicked.connect (on_tag);
222+
this.tag_btn.clicked.connect (write_information);
223223
grid.attach (tag_btn, 5, row, 1, 1);
224224
row++;
225225

@@ -230,7 +230,7 @@ public class Pdftag : ApplicationWindow {
230230
/* handle first argument -- it only works as an absolute path */
231231
if (args[1] != null) {
232232
this.pdf_file = File.new_for_path (args[1]);
233-
update_information ();
233+
read_information ();
234234
}
235235

236236
}
@@ -292,14 +292,16 @@ public class Pdftag : ApplicationWindow {
292292
file_chooser.destroy ();
293293

294294
/* update text entries with current metadata */
295-
update_information ();
295+
if (this.pdf_file != null) {
296+
read_information ();
297+
}
296298
}
297299

298-
private void update_information () {
300+
private void read_information () {
299301
try {
300302
var base_name = Path.get_basename (pdf_file.get_path ());
301303
this.header.title = base_name;
302-
this.header.subtitle = this.pdf_file.get_parse_name ().replace (base_name, "");
304+
this.header.subtitle = this.pdf_file.get_path ().replace (base_name, "");
303305
this.document = new Poppler.Document.from_file (this.pdf_file.get_uri (), null);
304306
this.title_entry.text = this.document.title ?? "";
305307
this.author_entry.text = this.document.author ?? "";
@@ -336,7 +338,7 @@ public class Pdftag : ApplicationWindow {
336338
}
337339
}
338340

339-
private void on_tag () {
341+
private void write_information () {
340342
if (this.pdf_file != null) {
341343
this.document.title = this.title_entry.text;
342344
this.document.author = this.author_entry.text;

0 commit comments

Comments
 (0)