[latexila] finance: re-open fundraising



commit 4260c3b4a04bd06476759a7ccf9d6f8dc5e2b8f9
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Aug 13 15:40:29 2016 +0200

    finance: re-open fundraising
    
    This reverts commit 1661787240dd00fd5abd60b30577e45a95ae8c6c.

 data/org.gnome.latexila.gschema.xml.in |   14 +++
 po/POTFILES.in                         |    1 +
 src/Makefile.am                        |    1 +
 src/finance.vala                       |  164 ++++++++++++++++++++++++++++++++
 src/latexila_app.vala                  |    6 +
 src/main_window.vala                   |   10 ++
 src/ui/menus.ui                        |    4 +
 src/ui/ui.xml                          |    1 +
 8 files changed, 201 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.latexila.gschema.xml.in b/data/org.gnome.latexila.gschema.xml.in
index 1edbe29..0a20cdc 100644
--- a/data/org.gnome.latexila.gschema.xml.in
+++ b/data/org.gnome.latexila.gschema.xml.in
@@ -185,6 +185,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/">
@@ -207,4 +208,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 f9a1586..ae6bee5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,6 +22,7 @@ src/document_view.vala
 src/encodings.vala
 src/error_entry.vala
 src/file_browser.vala
+src/finance.vala
 src/latexila_app.vala
 src/latex_menu.vala
 src/liblatexila/latexila-build-job.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 5a19f71..e649e5c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ vala_files =                          \
        encodings.vala                  \
        error_entry.vala                \
        file_browser.vala               \
+       finance.vala                    \
        latexila_app.vala               \
        latex_menu.vala                 \
        main.vala                       \
diff --git a/src/finance.vala b/src/finance.vala
new file mode 100644
index 0000000..1993470
--- /dev/null
+++ b/src/finance.vala
@@ -0,0 +1,164 @@
+/*
+ * 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 (Window parent_window, bool startup)
+    {
+        if (startup && ! should_show_dialog_on_startup ())
+            return;
+
+        Dialog dialog = new Dialog.with_buttons ("LaTeXila Finance",
+            parent_window,
+            DialogFlags.DESTROY_WITH_PARENT,
+            "_Close", ResponseType.CLOSE,
+            "LaTeXila _Fundraiser", ResponseType.ACCEPT,
+            null);
+
+        dialog.set_resizable (false);
+        dialog.set_default_response (ResponseType.ACCEPT);
+
+        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);
+
+        if (startup)
+        {
+            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);
+
+        CheckButton remind_later_checkbutton =
+            new CheckButton.with_mnemonic ("_Remind me later (in one month)");
+
+        remind_later_checkbutton.set_active (false);
+        remind_later_checkbutton.margin_top = 12;
+        remind_later_checkbutton.margin_bottom = 6;
+
+        content_area.add (remind_later_checkbutton);
+        content_area.show_all ();
+
+        while (true)
+        {
+            int response = dialog.run ();
+
+            if (response == ResponseType.ACCEPT)
+            {
+                open_donate_page (parent_window);
+                continue;
+            }
+
+            GLib.Settings settings =
+                new GLib.Settings ("org.gnome.latexila.state.dialogs.finance");
+
+            settings.set_boolean ("remind-later", remind_later_checkbutton.get_active ());
+            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 (Window parent_window)
+    {
+        try
+        {
+            string uri = "https://wiki.gnome.org/Apps/LaTeXila/donate";;
+            show_uri (parent_window.get_screen (), uri, Gdk.CURRENT_TIME);
+        }
+        catch (Error e)
+        {
+            warning ("Impossible to open the donate page: %s", e.message);
+        }
+    }
+}
diff --git a/src/latexila_app.vala b/src/latexila_app.vala
index 9ae4ec0..5ba1da2 100644
--- a/src/latexila_app.vala
+++ b/src/latexila_app.vala
@@ -31,6 +31,7 @@ public class LatexilaApp : Gtk.Application
         { "preferences", preferences_cb },
         { "manage-build-tools", manage_build_tools_cb },
         { "help", help_cb },
+        { "fundraiser", fundraiser_cb },
         { "about", about_cb },
         { "quit", quit_cb }
     };
@@ -211,6 +212,11 @@ public class LatexilaApp : Gtk.Application
         }
     }
 
+    private void fundraiser_cb ()
+    {
+        Finance.show_dialog (get_active_main_window (), false);
+    }
+
     private void about_cb ()
     {
         string comments =
diff --git a/src/main_window.vala b/src/main_window.vala
index b3bea00..b0a9a3b 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -64,6 +64,9 @@ public class MainWindow : ApplicationWindow
             N_("Open the LaTeXila documentation"), on_help_contents },
         { "HelpLatexReference", null, N_("_LaTeX Reference"), null,
             N_("The Kile LaTeX Reference"), on_help_latex_reference },
+        { "HelpFinance", null, "LaTeXila _Fundraiser", null,
+            "Donate to demonstrate your appreciation of LaTeXila and help its future development",
+            on_help_finance },
         { "HelpAbout", "help-about", N_("_About"), null,
             N_("About LaTeXila"), on_about_dialog }
     };
@@ -267,6 +270,8 @@ public class MainWindow : ApplicationWindow
         restore_state ();
         show_or_hide_widgets ();
         show ();
+
+        Finance.show_dialog (this, true);
     }
 
     // Force to show icons in the menu.
@@ -1157,6 +1162,11 @@ public class MainWindow : ApplicationWindow
         }
     }
 
+    public void on_help_finance ()
+    {
+        LatexilaApp.get_instance ().activate_action ("fundraiser", null);
+    }
+
     public void on_about_dialog ()
     {
         LatexilaApp.get_instance ().activate_action ("about", null);
diff --git a/src/ui/menus.ui b/src/ui/menus.ui
index 6155896..e0616c1 100644
--- a/src/ui/menus.ui
+++ b/src/ui/menus.ui
@@ -23,6 +23,10 @@
         <attribute name="action">app.help</attribute>
       </item>
       <item>
+        <attribute name="label" translatable="yes">LaTeXila _Fundraiser</attribute>
+        <attribute name="action">app.fundraiser</attribute>
+      </item>
+      <item>
         <attribute name="label" translatable="yes">_About</attribute>
         <attribute name="action">app.about</attribute>
       </item>
diff --git a/src/ui/ui.xml b/src/ui/ui.xml
index d2fcfe5..f0083d2 100644
--- a/src/ui/ui.xml
+++ b/src/ui/ui.xml
@@ -394,6 +394,7 @@ along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
     <menu action="Help">
       <menuitem action="HelpContents" />
       <menuitem action="HelpLatexReference" />
+      <menuitem action="HelpFinance" />
       <menuitem action="HelpAbout" />
     </menu>
   </menubar>


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