Skip to content

Commit 091fa3f

Browse files
author
Adrià Arrufat
committed
small tweaks to make it work on MS Windows
1 parent 0731ae5 commit 091fa3f

File tree

2 files changed

+25
-60
lines changed

2 files changed

+25
-60
lines changed

meson.build

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ if get_option('buildtype') == 'release'
88
endif
99
endif
1010

11+
if build_machine.system() == 'windows'
12+
add_global_arguments('-mwindows', language: 'c')
13+
endif
14+
15+
1116
glib = dependency('glib-2.0')
1217
gobject = dependency('gobject-2.0')
1318
gtk = dependency('gtk+-3.0')
@@ -24,13 +29,6 @@ pdftag = executable('pdftag',
2429
dependencies: deps,
2530
install: true)
2631

27-
libpdftag = library('pdftag',
28-
sources: srcs,
29-
dependencies: deps,
30-
vala_header: 'pdftag.h',
31-
vala_vapi: 'pdftag.vapi',
32-
install: false)
33-
3432
install_data('LICENSE',
3533
install_dir: '/usr/share/licenses/pdftag')
3634

src/main.vala

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public class Pdftag : ApplicationWindow {
1414
private Label format_label;
1515
private Label pages_label;
1616
private HeaderBar header;
17-
private CheckButton check;
18-
private bool overwrite = false;
1917

2018
private Button creation_date_btn;
2119
private SpinButton creation_hour_btn;
@@ -39,10 +37,10 @@ public class Pdftag : ApplicationWindow {
3937

4038
public Pdftag (ref unowned string[] args) {
4139

42-
header = new HeaderBar ();
43-
header.title = "pdftag";
44-
header.subtitle = "Add or modify metadata";
45-
header.set_show_close_button (true);
40+
this.header = new HeaderBar ();
41+
this.header.title = "pdftag";
42+
this.header.subtitle = "Add or modify metadata";
43+
this.header.set_show_close_button (true);
4644

4745
this.set_titlebar (header);
4846
this.destroy.connect (Gtk.main_quit);
@@ -53,7 +51,7 @@ public class Pdftag : ApplicationWindow {
5351
var open_button = new Button.from_icon_name ("document-open-symbolic", IconSize.SMALL_TOOLBAR);
5452
open_button.set_tooltip_text ("Select a PDF");
5553
open_button.clicked.connect (on_open_clicked);
56-
header.add (open_button);
54+
this.header.add (open_button);
5755

5856
/* grid configuration */
5957
var grid = new Grid ();
@@ -212,12 +210,6 @@ public class Pdftag : ApplicationWindow {
212210

213211
this.pages_label = new Label ("Pages: N/A");
214212
grid.attach (this.pages_label, 2, row, 1, 1);
215-
row++;
216-
217-
/* overwrite checkbox */
218-
this.check = new CheckButton.with_label ("Overwrite");
219-
check.toggled.connect (on_toggled);
220-
grid.attach (this.check, 1, row, 1, 1);
221213

222214
/* view button */
223215
viewer = AppInfo.get_default_for_type ("image/pdf", true);
@@ -230,7 +222,6 @@ public class Pdftag : ApplicationWindow {
230222
this.tag_btn = new Gtk.Button.with_label ("Tag");
231223
this.tag_btn.clicked.connect (write_information);
232224
grid.attach (tag_btn, 5, row, 1, 1);
233-
row++;
234225

235226
this.add (grid);
236227

@@ -293,8 +284,13 @@ public class Pdftag : ApplicationWindow {
293284
var file_chooser = new FileChooserDialog (
294285
"Open file", this, FileChooserAction.OPEN, "_Cancel", ResponseType.CANCEL, "_Open", ResponseType.ACCEPT);
295286
var filter = new FileFilter ();
296-
file_chooser.set_filter (filter);
297-
filter.add_mime_type ("image/pdf");
287+
filter.set_filter_name ("PDF files");
288+
filter.add_pattern ("*.pdf");
289+
file_chooser.add_filter (filter);
290+
filter = new FileFilter ();
291+
filter.set_filter_name ("All files");
292+
filter.add_pattern ("*");
293+
file_chooser.add_filter (filter);
298294
if (file_chooser.run () == ResponseType.ACCEPT) {
299295
this.pdf_file = file_chooser.get_file ();
300296
}
@@ -337,16 +333,6 @@ public class Pdftag : ApplicationWindow {
337333
}
338334
}
339335

340-
private void on_toggled () {
341-
if (this.check.active) {
342-
overwrite = true;
343-
message ("Output will be overwritten");
344-
} else {
345-
overwrite = false;
346-
message ("Original file will be kept");
347-
}
348-
}
349-
350336
private void view_document () {
351337
if (this.pdf_file != null) {
352338
var pdf_list = new List<File> ();
@@ -394,40 +380,21 @@ public class Pdftag : ApplicationWindow {
394380

395381
// save the modified document
396382
try {
397-
FileIOStream iostream;
398-
var tmp_pdf = File.new_tmp ("pdftag-tmp-XXXXXX.pdf", out iostream);
399-
this.document.save(tmp_pdf.get_uri ());
400-
if (overwrite) {
401-
var final_pdf = File.new_for_commandline_arg (this.pdf_file.get_path ());
402-
tmp_pdf.move (final_pdf, FileCopyFlags.OVERWRITE, null, null);
403-
}
383+
var tmp_file = File.new_for_path (this.header.subtitle + "tmp.pdf");
384+
this.document.save(tmp_file.get_uri ());
385+
uint8[] contents;
386+
string etag;
387+
tmp_file.load_contents (null, out contents, out etag);
388+
var pdf_stream = FileStream.open (this.pdf_file.get_path (), "w");
389+
pdf_stream.write (contents);
390+
tmp_file.delete ();
404391
} catch (Error e) {
405392
print ("%s\n", e.message);
406393
}
407394
} else {
408395
message ("No document was selected!");
409396
}
410397
}
411-
412-
private static void remove_dir_recursively (string path) {
413-
string content;
414-
try {
415-
var directory = Dir.open (path);
416-
while ((content = directory.read_name ()) != null) {
417-
var content_path = path + Path.DIR_SEPARATOR_S + content;
418-
if (FileUtils.test (content_path + Path.DIR_SEPARATOR_S + content, FileTest.IS_DIR)) {
419-
remove_dir_recursively (content_path);
420-
FileUtils.remove (content_path);
421-
} else {
422-
FileUtils.remove (content_path);
423-
}
424-
}
425-
FileUtils.remove (path);
426-
} catch (FileError e) {
427-
error ("%s\n", e.message);
428-
}
429-
}
430-
431398
}
432399

433400
int main (string[] args) {

0 commit comments

Comments
 (0)