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.DirectoryModel;
20 
21 private import dazzle.c.functions;
22 public  import dazzle.c.types;
23 private import gio.FileIF;
24 private import gio.ListModelIF;
25 private import gio.ListModelT;
26 private import glib.ConstructionException;
27 private import gobject.ObjectG;
28 
29 
30 /** */
31 public class DirectoryModel : ObjectG, ListModelIF
32 {
33 	/** the main Gtk struct */
34 	protected DzlDirectoryModel* dzlDirectoryModel;
35 
36 	/** Get the main Gtk struct */
37 	public DzlDirectoryModel* getDirectoryModelStruct(bool transferOwnership = false)
38 	{
39 		if (transferOwnership)
40 			ownedRef = false;
41 		return dzlDirectoryModel;
42 	}
43 
44 	/** the main Gtk struct as a void* */
45 	protected override void* getStruct()
46 	{
47 		return cast(void*)dzlDirectoryModel;
48 	}
49 
50 	/**
51 	 * Sets our main struct and passes it to the parent class.
52 	 */
53 	public this (DzlDirectoryModel* dzlDirectoryModel, bool ownedRef = false)
54 	{
55 		this.dzlDirectoryModel = dzlDirectoryModel;
56 		super(cast(GObject*)dzlDirectoryModel, ownedRef);
57 	}
58 
59 	// add the ListModel capabilities
60 	mixin ListModelT!(DzlDirectoryModel);
61 
62 
63 	/** */
64 	public static GType getType()
65 	{
66 		return dzl_directory_model_get_type();
67 	}
68 
69 	/**
70 	 * Creates a new #DzlDirectoryModel using @directory as the directory to monitor.
71 	 *
72 	 * Params:
73 	 *     directory = A #GFile
74 	 *
75 	 * Returns: A newly created #DzlDirectoryModel
76 	 *
77 	 * Throws: ConstructionException GTK+ fails to create the object.
78 	 */
79 	public this(FileIF directory)
80 	{
81 		auto p = dzl_directory_model_new((directory is null) ? null : directory.getFileStruct());
82 
83 		if(p is null)
84 		{
85 			throw new ConstructionException("null returned by new");
86 		}
87 
88 		this(cast(DzlDirectoryModel*) p, true);
89 	}
90 
91 	/**
92 	 * Gets the directory the model is observing.
93 	 *
94 	 * Returns: A #GFile
95 	 */
96 	public FileIF getDirectory()
97 	{
98 		auto p = dzl_directory_model_get_directory(dzlDirectoryModel);
99 
100 		if(p is null)
101 		{
102 			return null;
103 		}
104 
105 		return ObjectG.getDObject!(FileIF)(cast(GFile*) p);
106 	}
107 
108 	/** */
109 	public void setDirectory(FileIF directory)
110 	{
111 		dzl_directory_model_set_directory(dzlDirectoryModel, (directory is null) ? null : directory.getFileStruct());
112 	}
113 
114 	/** */
115 	public void setVisibleFunc(DzlDirectoryModelVisibleFunc visibleFunc, void* userData, GDestroyNotify userDataFreeFunc)
116 	{
117 		dzl_directory_model_set_visible_func(dzlDirectoryModel, visibleFunc, userData, userDataFreeFunc);
118 	}
119 }