1/* 2* Copyright (c) 2011-2018 Alecaddd (http://alecaddd.com) 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 2 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, write to the 16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17* Boston, MA 02110-1301 USA 18* 19* Authored by: Alessandro "Alecaddd" Castellani <castellani.ale@gmail.com> 20*/ 21 22namespace Sequeler { 23 public Sequeler.Services.Settings settings; 24 public Sequeler.Services.PasswordManager password_mngr; 25 public Sequeler.Services.UpgradeManager upgrade_mngr; 26 public Secret.Schema schema; 27} 28 29public class Sequeler.Application : Gtk.Application { 30 public GLib.List <Window> windows; 31 32 construct { 33 application_id = Constants.PROJECT_NAME; 34 flags |= ApplicationFlags.HANDLES_OPEN; 35 36 schema = new Secret.Schema (Constants.PROJECT_NAME, Secret.SchemaFlags.NONE, 37 "id", Secret.SchemaAttributeType.INTEGER, 38 "schema", Secret.SchemaAttributeType.STRING); 39 40 settings = new Sequeler.Services.Settings (); 41 password_mngr = new Sequeler.Services.PasswordManager (); 42 upgrade_mngr = new Sequeler.Services.UpgradeManager (); 43 44 windows = new GLib.List <Window> (); 45 } 46 47 public void new_window () { 48 new Sequeler.Window (this).present (); 49 } 50 51 public override void window_added (Gtk.Window window) { 52 windows.append (window as Window); 53 base.window_added (window); 54 } 55 56 protected override void open (File[] files, string hint) { 57 foreach (var file in files) { 58 var type = file.query_file_type (FileQueryInfoFlags.NONE); 59 60 switch (type) { 61 case FileType.DIRECTORY: // File handle represents a directory. 62 critical (_("Directories are not supported")); 63 continue; 64 65 case FileType.UNKNOWN: // File's type is unknown 66 case FileType.SPECIAL: // File is a "special" file, such as a socket, fifo, block device, or character device. 67 case FileType.MOUNTABLE: // File is a mountable location. 68 critical (_("Don't know what to do")); 69 continue; 70 71 case FileType.REGULAR: // File handle represents a regular file. 72 case FileType.SYMBOLIC_LINK: // File handle represents a symbolic link (Unix systems). 73 case FileType.SHORTCUT: // File is a shortcut (Windows systems). 74 var window = this.add_new_window (); 75 76 window.main.library.check_open_sqlite_file (file.get_uri (), file.get_basename ()); 77 break; 78 79 default: 80 error (_("Something completely unexpected happened")); 81 } 82 } 83 } 84 85 public override void window_removed (Gtk.Window window) { 86 windows.remove (window as Window); 87 base.window_removed (window); 88 } 89 90 private Sequeler.Window add_new_window () { 91 var window = new Sequeler.Window (this); 92 this.add_window (window); 93 94 return window; 95 } 96 97 protected override void activate () { 98 this.add_new_window (); 99 } 100} 101