[latexila/wip/finance-3-14] Show information about LaTeXila finance



commit e24ca5d3f1294484a8d3c18f3db363c44e19624e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jan 22 16:53:00 2015 +0100

    Show information about LaTeXila finance
    
    The dialog window is shown once on the first startup.

 data/org.gnome.latexila.gschema.xml.in |   14 +++
 po/POTFILES.in                         |    1 +
 src/Makefile.am                        |    1 +
 src/finance.vala                       |  160 ++++++++++++++++++++++++++++++++
 src/main_window.vala                   |   18 +---
 src/ui/ui.xml                          |    2 +-
 6 files changed, 183 insertions(+), 13 deletions(-)
---
diff --git a/data/org.gnome.latexila.gschema.xml.in b/data/org.gnome.latexila.gschema.xml.in
index 8a9cd63..81ed9e4 100644
--- a/data/org.gnome.latexila.gschema.xml.in
+++ b/data/org.gnome.latexila.gschema.xml.in
@@ -179,6 +179,7 @@
 
   <schema id="org.gnome.latexila.state" path="/org/gnome/latexila/state/">
     <child schema="org.gnome.latexila.state.window" name="window" />
+    <child schema="org.gnome.latexila.state.dialogs" name="dialogs" />
   </schema>
 
   <schema id="org.gnome.latexila.state.window" path="/org/gnome/latexila/state/window/">
@@ -201,4 +202,17 @@
       <default>100</default>
     </key>
   </schema>
+
+  <schema id="org.gnome.latexila.state.dialogs" path="/org/gnome/latexila/state/dialogs/">
+    <child schema="org.gnome.latexila.state.dialogs.finance" name="finance" />
+  </schema>
+
+  <schema id="org.gnome.latexila.state.dialogs.finance" path="/org/gnome/latexila/state/dialogs/finance/">
+    <key name="last-shown-date" type="s">
+      <default>''</default>
+    </key>
+    <key name="remind-later" type="b">
+      <default>false</default>
+    </key>
+  </schema>
 </schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a9b5988..9498427 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -27,6 +27,7 @@ src/document_view.vala
 src/encodings.vala
 src/error_entry.vala
 src/file_browser.vala
+src/finance.vala
 src/latexila.vala
 src/latex_menu.vala
 src/latex_post_processor.vala
diff --git a/src/Makefile.am b/src/Makefile.am
index 9728b21..84b2c94 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,7 @@ vala_files =                          \
        encodings.vala                  \
        error_entry.vala                \
        file_browser.vala               \
+       finance.vala                    \
        latexila.vala                   \
        latex_menu.vala                 \
        latex_post_processor.vala       \
diff --git a/src/finance.vala b/src/finance.vala
new file mode 100644
index 0000000..d601aab
--- /dev/null
+++ b/src/finance.vala
@@ -0,0 +1,160 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2015 - Sébastien Wilmet
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+namespace Finance
+{
+    public void show_dialog (MainWindow window, bool startup)
+    {
+        if (startup && ! should_show_dialog_on_startup ())
+            return;
+
+        Dialog dialog = new Dialog.with_buttons ("LaTeXila Finance",
+            window,
+            DialogFlags.DESTROY_WITH_PARENT,
+            "_Close", ResponseType.CLOSE,
+            "_Remind me later", ResponseType.YES,
+            "_More information", ResponseType.ACCEPT,
+            null);
+
+        dialog.set_resizable (false);
+        dialog.set_default_response (ResponseType.ACCEPT);
+
+        Widget close_button = dialog.get_widget_for_response (ResponseType.CLOSE);
+        close_button.tooltip_text = "Do not show again this information.";
+
+        Widget remind_button = dialog.get_widget_for_response (ResponseType.YES);
+        remind_button.tooltip_text = "Show again this information in one month.";
+
+        unowned Box content_area = dialog.get_content_area ();
+        content_area.set_spacing (6);
+        content_area.margin = 12;
+        content_area.margin_top = 6;
+
+        Image image = new Image.from_file (Config.DATA_DIR + "/images/app/logo.png");
+        content_area.add (image);
+
+        Label label = new Label (null);
+        label.set_markup ("<big>Did you know...</big>");
+        content_area.add (label);
+
+        label = new Label ("...that you can support LaTeXila financially?");
+        content_area.add (label);
+
+        label = new Label (null);
+        label.set_markup ("LaTeXila is a free/<i>libre</i> LaTeX editor and comes" +
+            " free of charge. But if you appreciate this software, you are encouraged" +
+            " to make a donation to help its future development.");
+        label.max_width_chars = 60;
+        label.set_line_wrap (true);
+        label.xalign = 0;
+        content_area.add (label);
+
+        label = new Label ("You can see again this information at any time by going to the Help menu.");
+        label.max_width_chars = 60;
+        label.set_line_wrap (true);
+        label.xalign = 0;
+        content_area.add (label);
+
+        label = new Label ("Thanks!");
+        label.xalign = 0;
+        content_area.add (label);
+
+        content_area.show_all ();
+
+        while (true)
+        {
+            int response = dialog.run ();
+
+            if (response == ResponseType.ACCEPT)
+            {
+                open_donate_page (window);
+                continue;
+            }
+
+            GLib.Settings settings =
+                new GLib.Settings ("org.gnome.latexila.state.dialogs.finance");
+
+            settings.set_boolean ("remind-later", response == ResponseType.YES);
+            break;
+        }
+
+        dialog.destroy ();
+        save_date ();
+    }
+
+    private bool should_show_dialog_on_startup ()
+    {
+        GLib.Settings settings =
+            new GLib.Settings ("org.gnome.latexila.state.dialogs.finance");
+
+        string date = settings.get_string ("last-shown-date");
+
+        if (date == "")
+            return true;
+
+        if (settings.get_boolean ("remind-later"))
+        {
+            string[] ymd = date.split ("-");
+            if (ymd.length != 3)
+                return false;
+
+            int year = int.parse (ymd[0]);
+            int month = int.parse (ymd[1]);
+            int day = int.parse (ymd[2]);
+
+            DateTime last_time = new DateTime.utc (year, month, day, 0, 0, 0);
+            DateTime cur_time = new DateTime.now_utc ();
+
+            // Remind one month later.
+            DateTime time_limit = last_time.add_months (1);
+
+            if (time_limit.compare (cur_time) <= 0)
+                return true;
+        }
+
+        return false;
+    }
+
+    private void save_date ()
+    {
+        GLib.Settings settings =
+            new GLib.Settings ("org.gnome.latexila.state.dialogs.finance");
+
+        DateTime time = new DateTime.now_utc ();
+        string date = "%d-%d-%d".printf (time.get_year (), time.get_month (),
+            time.get_day_of_month ());
+
+        settings.set_string ("last-shown-date", date);
+    }
+
+    private void open_donate_page (MainWindow window)
+    {
+        try
+        {
+            string uri = "https://wiki.gnome.org/Apps/LaTeXila/donate";;
+            show_uri (window.get_screen (), uri, Gdk.CURRENT_TIME);
+        }
+        catch (Error e)
+        {
+            warning ("Impossible to open the donate page: %s", e.message);
+        }
+    }
+}
diff --git a/src/main_window.vala b/src/main_window.vala
index 4d18de0..800037b 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -64,9 +64,9 @@ public class MainWindow : Window
             N_("Open the LaTeXila documentation"), on_help_contents },
         { "HelpLatexReference", null, N_("_LaTeX Reference"), null,
             N_("The Kile LaTeX Reference"), on_help_latex_reference },
-        { "HelpDonate", null, N_("_Donate"), null,
+        { "HelpFinance", null, N_("_Donate"), null,
             N_("Donate to demonstrate your appreciation of LaTeXila and help its future development"),
-            on_help_donate },
+            on_help_finance },
         { "HelpAbout", Stock.ABOUT, null, null,
             N_("About LaTeXila"), on_about_dialog }
     };
@@ -267,6 +267,8 @@ public class MainWindow : Window
         restore_state ();
         show_or_hide_widgets ();
         show ();
+
+        Finance.show_dialog (this, true);
     }
 
     // Force to show icons in the menu.
@@ -1165,17 +1167,9 @@ public class MainWindow : Window
         }
     }
 
-    public void on_help_donate ()
+    public void on_help_finance ()
     {
-        try
-        {
-            string uri = "https://wiki.gnome.org/Apps/LaTeXila/donate";;
-            show_uri (this.get_screen (), uri, Gdk.CURRENT_TIME);
-        }
-        catch (Error e)
-        {
-            warning ("Impossible to open the donate page: %s", e.message);
-        }
+        Finance.show_dialog (this, false);
     }
 
     public void on_about_dialog ()
diff --git a/src/ui/ui.xml b/src/ui/ui.xml
index c5d9464..a3e8581 100644
--- a/src/ui/ui.xml
+++ b/src/ui/ui.xml
@@ -387,7 +387,7 @@ along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
     <menu action="Help">
       <menuitem action="HelpContents" />
       <menuitem action="HelpLatexReference" />
-      <menuitem action="HelpDonate" />
+      <menuitem action="HelpFinance" />
       <menuitem action="HelpAbout" />
     </menu>
   </menubar>


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