[gnote] Save the preferences for the HTML export.



commit 98d1dabcf235d6c324952809271097c835556a3b
Author: Hubert Figuiere <hub figuiere net>
Date:   Wed May 20 15:21:36 2009 -0400

    Save the preferences for the HTML export.
---
 src/Makefile.am                                |    8 ++++-
 src/addins/exporttohtml/exporttohtmldialog.cpp |   38 ++++++++++++++++++++++-
 src/addins/exporttohtml/exporttohtmldialog.hpp |    2 +
 src/sharp/files.cpp                            |    5 ++-
 src/sharp/files.hpp                            |    1 +
 5 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index f44326b..522bcce 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,8 +20,8 @@ GNOTE_LIBS = libgnote.a @LIBGLIBMM_LIBS@ @LIBGTKMM_LIBS@ @LIBXMLPP_LIBS@ \
 
 noinst_LIBRARIES = libgnote.a
 bin_PROGRAMS = gnote
-check_PROGRAMS = trietest stringtest notetest dttest uritest
-TESTS = trietest stringtest notetest dttest uritest
+check_PROGRAMS = trietest stringtest notetest dttest uritest filestest
+TESTS = trietest stringtest notetest dttest uritest filestest
 
 
 trietest_SOURCES = test/trietest.cpp \
@@ -36,6 +36,10 @@ stringtest_SOURCES = test/stringtest.cpp \
 	sharp/string.cpp debug.cpp
 stringtest_LDADD =  @BOOST_REGEX_LIBS@ @LIBGLIBMM_LIBS@
 
+filestest_SOURCES = test/filestest.cpp \
+	sharp/files.cpp
+filestest_LDADD = @BOOST_FILESYSTEM_LIBS@
+
 uritest_SOURCES = test/uritest.cpp \
 	sharp/string.cpp  sharp/uri.cpp debug.cpp
 uritest_LDADD =  @BOOST_REGEX_LIBS@ @LIBGLIBMM_LIBS@
diff --git a/src/addins/exporttohtml/exporttohtmldialog.cpp b/src/addins/exporttohtml/exporttohtmldialog.cpp
index 881d3b6..bec5394 100644
--- a/src/addins/exporttohtml/exporttohtmldialog.cpp
+++ b/src/addins/exporttohtml/exporttohtmldialog.cpp
@@ -23,12 +23,15 @@
 #include <gtkmm/stock.h>
 #include <gtkmm/table.h>
 
+#include "sharp/files.hpp"
 #include "exporttohtmldialog.hpp"
-
+#include "preferences.hpp"
 
 namespace exporttohtml {
 
 
+using gnote::Preferences;
+
 ExportToHtmlDialog::ExportToHtmlDialog(const std::string & default_file)
   : Gtk::FileChooserDialog(_("Destination for HTML Export"),
                            Gtk::FILE_CHOOSER_ACTION_SAVE)
@@ -65,19 +68,50 @@ bool ExportToHtmlDialog::get_export_linked() const
   return m_export_linked.get_active();
 }
 
+
+void ExportToHtmlDialog::set_export_linked(bool value)
+{
+  m_export_linked.set_active(value);
+}
+
+
 bool ExportToHtmlDialog::get_export_linked_all() const
 {
   return m_export_linked_all.get_active();
 }
 
 
+void ExportToHtmlDialog::set_export_linked_all(bool value)
+{
+  m_export_linked_all.set_active(value);
+}
+
+
 void ExportToHtmlDialog::save_preferences()
 {
+  std::string dir = sharp::file_dirname(get_filename());
+  
+  Preferences::obj().set<std::string>(Preferences::EXPORTHTML_LAST_DIRECTORY, 
+                                      dir);
+
+  Preferences::obj().set<bool>(Preferences::EXPORTHTML_EXPORT_LINKED, 
+                               get_export_linked());
+  Preferences::obj().set<bool>(Preferences::EXPORTHTML_EXPORT_LINKED_ALL, 
+                               get_export_linked_all());
 }
 
 
-void ExportToHtmlDialog::load_preferences(const std::string & )
+void ExportToHtmlDialog::load_preferences(const std::string & default_file)
 {
+  std::string last_dir = Preferences::obj().get<std::string>(Preferences::EXPORTHTML_LAST_DIRECTORY);
+  if (last_dir.empty()) {
+    last_dir = Glib::get_home_dir();
+  }
+  set_current_folder (last_dir);
+  set_current_name(default_file);
+
+  set_export_linked(Preferences::obj().get<bool>(Preferences::EXPORTHTML_EXPORT_LINKED));
+  set_export_linked_all(Preferences::obj().get<bool>(Preferences::EXPORTHTML_EXPORT_LINKED_ALL));
 }
 
 
diff --git a/src/addins/exporttohtml/exporttohtmldialog.hpp b/src/addins/exporttohtml/exporttohtmldialog.hpp
index ea3cb4a..d27f411 100644
--- a/src/addins/exporttohtml/exporttohtmldialog.hpp
+++ b/src/addins/exporttohtml/exporttohtmldialog.hpp
@@ -37,7 +37,9 @@ public:
   void save_preferences();
 
   bool get_export_linked() const;
+  void set_export_linked(bool);
   bool get_export_linked_all() const;
+  void set_export_linked_all(bool);
 
 private:
   void on_export_linked_toggled();
diff --git a/src/sharp/files.cpp b/src/sharp/files.cpp
index bbef286..1035e7a 100644
--- a/src/sharp/files.cpp
+++ b/src/sharp/files.cpp
@@ -41,9 +41,12 @@ namespace sharp {
 #else
     return boost::filesystem::basename(boost::filesystem::path(p));
 #endif
-
   }
 
+  std::string file_dirname(const std::string & p)
+  {
+    return boost::filesystem::path(p).branch_path().string();
+  }
 
   void file_delete(const std::string & p)
   {
diff --git a/src/sharp/files.hpp b/src/sharp/files.hpp
index 35dd2ab..7f0c1ba 100644
--- a/src/sharp/files.hpp
+++ b/src/sharp/files.hpp
@@ -34,6 +34,7 @@ namespace sharp {
 
   void file_delete(const std::string & p);
   std::string file_basename(const std::string & p);
+  std::string file_dirname(const std::string & p);
   void file_copy(const std::string & source, const std::string & dest);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]