From fea6cd4404e06d0fd6f1a24786329dd4af38aa65 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Wed, 27 Jan 2016 00:52:15 +0300 Subject: [PATCH] Closes #98: Save last pdf directory and set FileChooserDialog to this directory. --- config/ws.backbone.laview.desktop.gschema.xml | 22 +++------- po/de/laview-desktop.po | 40 +++++------------ po/laview-desktop.pot | 40 +++++------------ po/ru/laview-desktop.po | 44 +++++-------------- src/AppCore.vala | 3 ++ src/MainWindow.vala | 10 +++-- src/Settings.vala | 30 ++++++++++--- src/main.vala | 1 - 8 files changed, 69 insertions(+), 121 deletions(-) diff --git a/config/ws.backbone.laview.desktop.gschema.xml b/config/ws.backbone.laview.desktop.gschema.xml index 5b04dfa..d503f31 100644 --- a/config/ws.backbone.laview.desktop.gschema.xml +++ b/config/ws.backbone.laview.desktop.gschema.xml @@ -1,22 +1,10 @@ - + - - "Hello, earthlings" - A greeting - Greeting of the invading martians - - - - 99 - Bottles of beer - Number of bottles of beer on the wall - - - - false - Is the light switched on? - State of an imaginary light switch. + + "" + Directory to save pdf files (last selected path). + It is too lazy to select a directory each time... diff --git a/po/de/laview-desktop.po b/po/de/laview-desktop.po index 19802b0..7031099 100644 --- a/po/de/laview-desktop.po +++ b/po/de/laview-desktop.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: laview-desktop\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-01-24 02:59+0300\n" +"POT-Creation-Date: 2016-01-27 04:50+0300\n" "PO-Revision-Date: 2015-10-24 20:19+0300\n" "Last-Translator: \n" "Language-Team: German\n" @@ -18,31 +18,11 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: config/ws.backbone.laview.desktop.gschema.xml.h:1 -msgid "\"Hello, earthlings\"" +msgid "Directory to save pdf files (last selected path)." msgstr "" #: config/ws.backbone.laview.desktop.gschema.xml.h:2 -msgid "A greeting" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:3 -msgid "Greeting of the invading martians" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:4 -msgid "Bottles of beer" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:5 -msgid "Number of bottles of beer on the wall" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:6 -msgid "Is the light switched on?" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:7 -msgid "State of an imaginary light switch." +msgid "It is too lazy to select a directory each time..." msgstr "" #: src/MainWindow.vala:58 @@ -50,7 +30,7 @@ msgid "We're ready, Commander! Select or create a template. :-)" msgstr "" #: src/MainWindow.vala:76 src/MainWindow.vala:120 src/MainWindow.vala:194 -#: src/MainWindow.vala:212 src/MainWindow.vala:302 +#: src/MainWindow.vala:212 src/MainWindow.vala:312 msgid "Error" msgstr "" @@ -90,15 +70,15 @@ msgstr "" msgid "_Save" msgstr "" -#: src/MainWindow.vala:297 -msgid "bytes copied/saved" -msgstr "" - -#: src/MainWindow.vala:297 +#: src/MainWindow.vala:305 msgid "bytes of" msgstr "" -#: src/MainWindow.vala:299 +#: src/MainWindow.vala:306 +msgid "bytes copied/saved" +msgstr "" + +#: src/MainWindow.vala:309 msgid "Save/Copy operation complete! :-)" msgstr "" diff --git a/po/laview-desktop.pot b/po/laview-desktop.pot index 8f145a8..16d1d10 100644 --- a/po/laview-desktop.pot +++ b/po/laview-desktop.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: laview-desktop\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-01-24 02:59+0300\n" +"POT-Creation-Date: 2016-01-27 04:50+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,31 +18,11 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" #: config/ws.backbone.laview.desktop.gschema.xml.h:1 -msgid "\"Hello, earthlings\"" +msgid "Directory to save pdf files (last selected path)." msgstr "" #: config/ws.backbone.laview.desktop.gschema.xml.h:2 -msgid "A greeting" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:3 -msgid "Greeting of the invading martians" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:4 -msgid "Bottles of beer" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:5 -msgid "Number of bottles of beer on the wall" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:6 -msgid "Is the light switched on?" -msgstr "" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:7 -msgid "State of an imaginary light switch." +msgid "It is too lazy to select a directory each time..." msgstr "" #: src/MainWindow.vala:58 @@ -50,7 +30,7 @@ msgid "We're ready, Commander! Select or create a template. :-)" msgstr "" #: src/MainWindow.vala:76 src/MainWindow.vala:120 src/MainWindow.vala:194 -#: src/MainWindow.vala:212 src/MainWindow.vala:302 +#: src/MainWindow.vala:212 src/MainWindow.vala:312 msgid "Error" msgstr "" @@ -90,15 +70,15 @@ msgstr "" msgid "_Save" msgstr "" -#: src/MainWindow.vala:297 -msgid "bytes copied/saved" -msgstr "" - -#: src/MainWindow.vala:297 +#: src/MainWindow.vala:305 msgid "bytes of" msgstr "" -#: src/MainWindow.vala:299 +#: src/MainWindow.vala:306 +msgid "bytes copied/saved" +msgstr "" + +#: src/MainWindow.vala:309 msgid "Save/Copy operation complete! :-)" msgstr "" diff --git a/po/ru/laview-desktop.po b/po/ru/laview-desktop.po index 289aa4a..5d3b85c 100644 --- a/po/ru/laview-desktop.po +++ b/po/ru/laview-desktop.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: laview-desktop\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-01-24 02:59+0300\n" +"POT-Creation-Date: 2016-01-27 04:50+0300\n" "PO-Revision-Date: 2015-10-24 20:19+0300\n" "Last-Translator: \n" "Language-Team: Russian\n" @@ -19,39 +19,19 @@ msgstr "" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" #: config/ws.backbone.laview.desktop.gschema.xml.h:1 -msgid "\"Hello, earthlings\"" -msgstr "\"Привет, земляне\"" +msgid "Directory to save pdf files (last selected path)." +msgstr "Директория для сохранения pdf файлов (последний выбранный путь)." #: config/ws.backbone.laview.desktop.gschema.xml.h:2 -msgid "A greeting" -msgstr "Приветствие" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:3 -msgid "Greeting of the invading martians" -msgstr "Приветствие вторгнувшихся марсиан" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:4 -msgid "Bottles of beer" -msgstr "Бутылки пива" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:5 -msgid "Number of bottles of beer on the wall" -msgstr "Число бутылок пива на стене" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:6 -msgid "Is the light switched on?" -msgstr "Включен ли свет?" - -#: config/ws.backbone.laview.desktop.gschema.xml.h:7 -msgid "State of an imaginary light switch." -msgstr "Состояние воображаемого выключателя света." +msgid "It is too lazy to select a directory each time..." +msgstr "Слишком лениво выбирать каждый раз директорию для сохранения..." #: src/MainWindow.vala:58 msgid "We're ready, Commander! Select or create a template. :-)" msgstr "Мы готовы, Командир! Выберите или создайте шаблон. :-)" #: src/MainWindow.vala:76 src/MainWindow.vala:120 src/MainWindow.vala:194 -#: src/MainWindow.vala:212 src/MainWindow.vala:302 +#: src/MainWindow.vala:212 src/MainWindow.vala:312 msgid "Error" msgstr "Ошибка" @@ -91,15 +71,15 @@ msgstr "Выберите назначение" msgid "_Save" msgstr "_Сохранить" -#: src/MainWindow.vala:297 -msgid "bytes copied/saved" -msgstr "байт скопировано/сохранено" - -#: src/MainWindow.vala:297 +#: src/MainWindow.vala:305 msgid "bytes of" msgstr "байт из" -#: src/MainWindow.vala:299 +#: src/MainWindow.vala:306 +msgid "bytes copied/saved" +msgstr "байт скопировано/сохранено" + +#: src/MainWindow.vala:309 msgid "Save/Copy operation complete! :-)" msgstr "Операция сохранения/копирования завершена! :-)" diff --git a/src/AppCore.vala b/src/AppCore.vala index cb8a9bc..f1f611c 100644 --- a/src/AppCore.vala +++ b/src/AppCore.vala @@ -2,9 +2,12 @@ namespace LAview.Desktop { class AppCore { public static LAview.Core.Core core; + public static AppSettings settings; public static void init (string[] args) throws Error { core = new LAview.Core.Core(); + settings = new AppSettings(); } + } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 4e1558b..f5190ae 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -273,6 +273,10 @@ namespace LAview.Desktop { filter.add_mime_type ("application/pdf"); filter.add_pattern ("*.pdf"); + // set folder + if (AppCore.settings.pdf_save_path != "") + chooser.set_current_folder(AppCore.settings.pdf_save_path); + // set current pdf file name or select an existance one var template_name = AppCore.core.get_template_path_by_index (indices[0]); template_name = File.new_for_path(template_name).get_basename (); @@ -292,15 +296,13 @@ namespace LAview.Desktop { // process response if (response == ResponseType.ACCEPT) { - var save_path = chooser.get_filename (); - var file_src = File.new_for_path (tmp_pdf); - var file_dest = File.new_for_path (save_path); try { - file_src.copy (file_dest, FileCopyFlags.OVERWRITE, null, + File.new_for_path (tmp_pdf).copy (chooser.get_file(), FileCopyFlags.OVERWRITE, null, (current_num_bytes, total_num_bytes) => { statusbar_show (@"$current_num_bytes "+_("bytes of")+ @" $total_num_bytes "+_("bytes copied/saved")+"."); }); + AppCore.settings.pdf_save_path = chooser.get_file().get_parent().get_path(); statusbar_show (_("Save/Copy operation complete! :-)")); } catch (Error err) { var msg = new MessageDialog (chooser, DialogFlags.MODAL, MessageType.ERROR, diff --git a/src/Settings.vala b/src/Settings.vala index fb43e15..cacc831 100644 --- a/src/Settings.vala +++ b/src/Settings.vala @@ -1,15 +1,31 @@ namespace LAview.Desktop { - class AppSettings { - //public static GLib.Settings settings; + public class AppSettings { + Settings settings; - public static void init (string[] args) throws Error { + string _pdf_save_path; + public string pdf_save_path { + get { return _pdf_save_path; } + set { + if (settings != null) settings.set_string ("pdf-save-path", value); + _pdf_save_path = value; + } + default = ""; + } + + public AppSettings () throws Error { SettingsSchemaSource sss = new SettingsSchemaSource.from_directory (AppDirs.settings_dir, null, false); - //SettingsSchema schema = sss.lookup ("ws.backbone.laview.desktop-"+Config.VERSION_MAJOR.to_string(), false); - if (sss.lookup == null) - throw new FileError.NOENT ("Schema ID not found"); + SettingsSchema schema = sss.lookup ("ws.backbone.laview.desktop-"+Config.VERSION_MAJOR.to_string(), false); + if (schema == null) { + stderr.printf ("ID not found.\n"); + throw new IOError.NOT_FOUND ("File "+AppDirs.settings_dir+"/gschemas.compiled not found"); + } + settings = new Settings.full (schema, null, null); - //settings = new Settings.full (schema, null, null); + _pdf_save_path = settings.get_string("pdf-save-path"); + settings.changed["pdf-save-path"].connect (() => { + _pdf_save_path = settings.get_string("pdf-save-path"); + }); } } } diff --git a/src/main.vala b/src/main.vala index b140d9b..ccdcc06 100644 --- a/src/main.vala +++ b/src/main.vala @@ -45,7 +45,6 @@ namespace LAview.Desktop { try { AppDirs.init (args); - AppSettings.init (args); AppCore.init (args); Resources.init (args);