summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2015-09-16 14:40:38 +0200
committerMurray Cumming <murrayc@murrayc.com>2015-09-16 14:40:38 +0200
commitdd19e282d249dc6009834dad9c2af99039675348 (patch)
treea0d2d5235b454c41896ea2af34bb0d4bd18c37b9
parent3f808f395eaa9e638572fa72c7adfb304dff7baa (diff)
downloadglibmm-dd19e282d249dc6009834dad9c2af99039675348.tar.gz
Added Gio::ListModel
-rw-r--r--gio/giomm.h1
-rw-r--r--gio/src/filelist.am1
-rw-r--r--gio/src/gio_extra_objects.defs6
-rw-r--r--gio/src/listmodel.ccg23
-rw-r--r--gio/src/listmodel.hg96
5 files changed, 127 insertions, 0 deletions
diff --git a/gio/giomm.h b/gio/giomm.h
index 43f6ed55..1811973a 100644
--- a/gio/giomm.h
+++ b/gio/giomm.h
@@ -89,6 +89,7 @@
#include <giomm/initable.h>
#include <giomm/inputstream.h>
#include <giomm/iostream.h>
+#include <giomm/listmodel.h>
#include <giomm/loadableicon.h>
#include <giomm/memoryinputstream.h>
#include <giomm/memoryoutputstream.h>
diff --git a/gio/src/filelist.am b/gio/src/filelist.am
index 0f494e48..e47b6b2f 100644
--- a/gio/src/filelist.am
+++ b/gio/src/filelist.am
@@ -74,6 +74,7 @@ giomm_files_any_hg = \
initable.hg \
inputstream.hg \
iostream.hg \
+ listmodel.hg \
loadableicon.hg \
memoryinputstream.hg \
memoryoutputstream.hg \
diff --git a/gio/src/gio_extra_objects.defs b/gio/src/gio_extra_objects.defs
index c1ed447a..5ef3e06d 100644
--- a/gio/src/gio_extra_objects.defs
+++ b/gio/src/gio_extra_objects.defs
@@ -139,6 +139,12 @@
(gtype-id "G_TYPE_FILE_INFO")
)
+(define-object ListModel
+ (in-module "Gio")
+ (c-name "GListModel")
+ (gtype-id "G_TYPE_LIST_MODEL")
+)
+
(define-object Menu
(in-module "Gio")
(c-name "GMenu")
diff --git a/gio/src/listmodel.ccg b/gio/src/listmodel.ccg
new file mode 100644
index 00000000..27d1a1ee
--- /dev/null
+++ b/gio/src/listmodel.ccg
@@ -0,0 +1,23 @@
+/* Copyright (C) 2015 The giomm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gio/gio.h>
+
+namespace Gio
+{
+
+} // namespace Gio
diff --git a/gio/src/listmodel.hg b/gio/src/listmodel.hg
new file mode 100644
index 00000000..00b6f01d
--- /dev/null
+++ b/gio/src/listmodel.hg
@@ -0,0 +1,96 @@
+/* Copyright (C) 2015 The giomm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm/interface.h>
+#include <gio/gio.h>
+
+_DEFS(giomm,gio)
+_PINCLUDE(glibmm/private/interface_p.h)
+_PINCLUDE(gio/gio.h)
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+typedef struct _GListModelInterface GListModelInterface;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+
+namespace Gio
+{
+
+/** A dynamic list of objects.
+ *
+ * A ListModel represents a mutable list of
+ * Glib::Objects. Its main intention is as a model for various widgets in
+ * user interfaces, such as list views, but it can also be used as a
+ * convenient method of returning lists of data, with support for
+ * updates.
+ *
+ * Each object in the list may also report changes in itself via some
+ * mechanism (normally the #GObject::notify signal). Taken together
+ * with the signal_items_changed() signal, this provides for a list
+ * that can change its membership, and in which the members can change
+ * their individual properties.
+ *
+ * A good example would be the list of visible wireless network access
+ * points, where each access point can report dynamic properties such as
+ * signal strength.
+ *
+ * It is important to note that the ListModel itself does not report
+ * changes to the individual items. It only reports changes to the list
+ * membership. If you want to observe changes to the objects themselves
+ * then you need to connect signals to the objects that you are
+ * interested in.
+ *
+ * All items in a ListModel are of (or derived from) the same type.
+ * get_item_type() returns that type. The type may be an
+ * interface, in which case all objects in the list must implement it.
+ *
+ * The semantics are close to that of an array:
+ * get_n_items() returns the number of items in the list and
+ * get_item() returns an item at a (0-based) position. In
+ * order to allow implementations to calculate the list length lazily,
+ * you can also iterate over items: starting from 0, repeatedly call
+ * get_item() until it returns nullptr.
+ *
+ * This interface is intended only to be used from a single thread. The
+ * thread in which it is appropriate to use it depends on the particular
+ * implementation, but typically it will be from the thread that owns
+ * the thread-default main context
+ * in effect at the time that the model was created.
+ *
+ * @newin{2,46}
+ */
+class ListModel : public Glib::Interface
+{
+ _CLASS_INTERFACE(ListModel, GListModel, G_LIST_MODEL, GListModelInterface)
+
+public:
+ _WRAP_METHOD(GType get_item_type() const, g_list_model_get_item_type)
+ _WRAP_METHOD(guint get_n_items() const, g_list_model_get_n_items)
+
+ //g_list_model_get_item is useless as long as we have g_list_model_get_object().
+ //It doesn't do anything differently.
+ _IGNORE(g_list_model_get_item)
+
+ _WRAP_METHOD(Glib::RefPtr<Glib::Object> get_object(guint position), g_list_model_get_object)
+ _WRAP_METHOD(Glib::RefPtr<const Glib::Object> get_object(guint position) const, g_list_model_get_object, constversion)
+
+ _WRAP_METHOD(void items_changed(guint position, guint removed, guint added), g_list_model_items_changed)
+
+ _WRAP_SIGNAL(void items_changed(guint position, guint removed, guint added), "items-changed", no_default_handler)
+};
+
+} // namespace Gio