1/* 2* Copyright (c) 2017-2018 Carlos Suárez (https://gitlab.com/bitseater) 3* 4* This program is free software; you can redistribute it and/or 5* modify it under the terms of the GNU General Public 6* License as published by the Free Software Foundation; either 7* version 3 of the License, or (at your option) any later version. 8* 9* This program is distributed in the hope that it will be useful, 10* but WITHOUT ANY WARRANTY; without even the implied warranty of 11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12* General Public License for more details. 13* 14* You should have received a copy of the GNU General Public 15* License along with this program; If not, see <http://www.gnu.org/licenses/>. 16* 17* Authored by: Carlos Suárez <bitseater@gmail.com> 18*/ 19namespace Meteo.Utils { 20 21 public static string to_string2 (double d) { 22 char [] cadena = new char [16]; 23 d.format (cadena, "%-.2f"); 24 string texto = (string) cadena; 25 return texto; 26 } 27 28 public static string to_string0 (double d) { 29 char [] cadena = new char [16]; 30 d.format (cadena, "%-.0f"); 31 string texto = (string) cadena; 32 return texto; 33 } 34 35 public static string get_units () { 36 string lang = Gtk.get_default_language ().to_string ().substring (0, 2); 37 string units = ""; 38 switch (lang) { 39 case "C": 40 units = "imperial"; 41 break; 42 case "en_US": 43 units = "imperial"; 44 break; 45 case "my_MM": 46 units = "imperial"; 47 break; 48 case "en_GB": 49 units = "british"; 50 break; 51 default: 52 units = "metric"; 53 break; 54 } 55 return units; 56 } 57 58 public void set_start_on_boot () { 59 string origin = Constants.DATADIR + "/applications/" + Constants.EXEC_NAME + ".desktop"; 60 string destine = Environment.get_user_config_dir () + "/autostart/" + Constants.EXEC_NAME + ".desktop"; 61 try { 62 var file = File.new_for_path (destine); 63 file.make_symbolic_link (origin, null); 64 stdout.printf ("Added to autostart\n"); 65 66 } catch (Error e) { 67 stdout.printf ("Error: %s\n", e.message); 68 } 69 } 70 71 public void reset_start_on_boot () { 72 try { 73 var file = File.new_for_path (Environment.get_user_config_dir () + "/autostart/com.gitlab.bitseater.meteo.desktop"); 74 if (file.query_exists ()) { 75 file.delete (); 76 stdout.printf ("Removed from autostart\n"); 77 } 78 } catch (Error e) { 79 stdout.printf ("Error: %s\n", e.message); 80 } 81 } 82} 83