1 /*
2  * This file is part of d-dazzle.
3  *
4  * d-dazzle is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * d-dazzle is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with d-dazzle; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module dazzle.FileChooserEntry;
20 
21 private import dazzle.c.functions;
22 public  import dazzle.c.types;
23 private import gio.FileIF;
24 private import glib.ConstructionException;
25 private import glib.Str;
26 private import gobject.ObjectG;
27 private import gtk.Bin;
28 private import gtk.BuildableIF;
29 private import gtk.BuildableT;
30 private import gtk.Entry;
31 private import gtk.Widget;
32 
33 
34 /** */
35 public class FileChooserEntry : Bin
36 {
37 	/** the main Gtk struct */
38 	protected DzlFileChooserEntry* dzlFileChooserEntry;
39 
40 	/** Get the main Gtk struct */
41 	public DzlFileChooserEntry* getFileChooserEntryStruct(bool transferOwnership = false)
42 	{
43 		if (transferOwnership)
44 			ownedRef = false;
45 		return dzlFileChooserEntry;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected override void* getStruct()
50 	{
51 		return cast(void*)dzlFileChooserEntry;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (DzlFileChooserEntry* dzlFileChooserEntry, bool ownedRef = false)
58 	{
59 		this.dzlFileChooserEntry = dzlFileChooserEntry;
60 		super(cast(GtkBin*)dzlFileChooserEntry, ownedRef);
61 	}
62 
63 
64 	/** */
65 	public static GType getType()
66 	{
67 		return dzl_file_chooser_entry_get_type();
68 	}
69 
70 	/** */
71 	public this(string title, GtkFileChooserAction action)
72 	{
73 		auto p = dzl_file_chooser_entry_new(Str.toStringz(title), action);
74 
75 		if(p is null)
76 		{
77 			throw new ConstructionException("null returned by new");
78 		}
79 
80 		this(cast(DzlFileChooserEntry*) p);
81 	}
82 
83 	/**
84 	 * Gets the entry used by the #GtkEntry.
85 	 *
86 	 * Returns: a #GtkEntry
87 	 *
88 	 * Since: 3.32
89 	 */
90 	public Entry getEntry()
91 	{
92 		auto p = dzl_file_chooser_entry_get_entry(dzlFileChooserEntry);
93 
94 		if(p is null)
95 		{
96 			return null;
97 		}
98 
99 		return ObjectG.getDObject!(Entry)(cast(GtkEntry*) p);
100 	}
101 
102 	/**
103 	 * Returns the currently selected file or %NULL if there is no selection.
104 	 *
105 	 * Returns: A #GFile or %NULL.
106 	 */
107 	public FileIF getFile()
108 	{
109 		auto p = dzl_file_chooser_entry_get_file(dzlFileChooserEntry);
110 
111 		if(p is null)
112 		{
113 			return null;
114 		}
115 
116 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p, true);
117 	}
118 
119 	/** */
120 	public void setFile(FileIF file)
121 	{
122 		dzl_file_chooser_entry_set_file(dzlFileChooserEntry, (file is null) ? null : file.getFileStruct());
123 	}
124 }