--- /dev/null
+/*
+ * $Id: rb_esmart_file_dialog.c 336 2005-05-02 17:29:52Z tilman $
+ *
+ * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <ruby.h>
+
+#include <Esmart/Esmart_File_Dialog.h>
+#include <evas/rb_evas.h>
+#include <evas/rb_evas_object.h>
+
+#include "../rb_esmart.h"
+
+typedef struct {
+ RbEvasObject real;
+ VALUE callback;
+ VALUE edje;
+} RbFileDialog;
+
+static void c_mark (RbFileDialog *e)
+{
+ c_evas_object_mark (&e->real);
+
+ if (!NIL_P (e->callback)) {
+ rb_gc_mark (e->callback);
+ rb_gc_mark (e->edje);
+ }
+}
+
+static void c_free (RbFileDialog *e)
+{
+ c_evas_object_free (&e->real, false);
+
+ free (e);
+}
+
+static VALUE c_new (VALUE klass, VALUE evas, VALUE edj)
+{
+ VALUE self, argv[1];
+ RbFileDialog *fd = NULL;
+
+ CHECK_CLASS (evas, cEvas);
+ StringValue (edj);
+ GET_OBJ (evas, RbEvas, e);
+
+ self = Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd);
+ fd->real.real = esmart_file_dialog_new (e->real,
+ StringValuePtr (edj));
+
+ if (!fd->real.real)
+ rb_raise (rb_eStandardError, "failed");
+
+ argv[0] = evas;
+ rb_obj_call_init (self, 1, argv);
+
+ fd->callback = Qnil;
+ fd->edje = Qnil;
+
+ return self;
+}
+
+static void on_action (void *data, Evas_Object *edje,
+ Esmart_File_Dialog_Op op)
+{
+ ID sym;
+
+ switch (op) {
+ case ESMART_FILE_DIALOG_NEW:
+ sym = rb_intern ("new");
+ break;
+ case ESMART_FILE_DIALOG_RENAME:
+ sym = rb_intern ("rename");
+ break;
+ case ESMART_FILE_DIALOG_DELETE:
+ sym = rb_intern ("delete");
+ break;
+ case ESMART_FILE_DIALOG_OK:
+ sym = rb_intern ("ok");
+ break;
+ case ESMART_FILE_DIALOG_CANCEL:
+ sym = rb_intern ("cancel");
+ break;
+ case ESMART_FILE_DIALOG_DIR_CHANGED:
+ sym = rb_intern ("dir_changed");
+ break;
+ default:
+ sym = Qnil;
+ }
+
+ rb_funcall ((VALUE) data, rb_intern ("call"), 1, ID2SYM (sym));
+}
+
+static VALUE c_on_action (VALUE self)
+{
+ GET_OBJ (self, RbFileDialog, fd);
+
+ if (!rb_block_given_p ())
+ return Qnil;
+
+ fd->callback = rb_block_proc ();
+
+ esmart_file_dialog_callback_add (fd->real.real, on_action,
+ (void *) fd->callback);
+
+ return Qnil;
+}
+
+static VALUE c_edje_get (VALUE self)
+{
+ Evas_Object *e;
+ VALUE mEdje, cEdje, s;
+ ID const_get;
+
+ GET_OBJ (self, RbFileDialog, fd);
+
+ if (!NIL_P (fd->edje))
+ return fd->edje;
+
+ const_get = rb_intern ("const_get");
+ s = rb_str_new2 ("Edje");
+
+ mEdje = rb_funcall (rb_cModule, const_get, 1, s);
+ cEdje = rb_funcall (mEdje, const_get, 1, s);
+
+ e = esmart_file_dialog_edje_get (fd->real.real);
+ fd->edje = rb_funcall (cEdje, rb_intern ("new_from_pointer"), 2,
+ TO_EVAS (self, evas_object_evas_get (e)),
+ (VALUE) e);
+
+ return fd->edje;
+}
+
+static VALUE c_selections_get (VALUE self)
+{
+ Evas_List *list, *l;
+ VALUE ary;
+
+ GET_OBJ (self, RbFileDialog, fd);
+
+ ary = rb_ary_new ();
+
+ list = esmart_file_dialog_selections_get (fd->real.real);
+ if (!list)
+ return ary;
+
+ for (l = list; l; l = l->next)
+ rb_ary_push (ary, rb_str_new2 (l->data));
+
+ return ary;
+}
+
+static VALUE c_current_directory_get (VALUE self)
+{
+ const char *d;
+
+ GET_OBJ (self, RbFileDialog, fd);
+
+ d = esmart_file_dialog_current_directory_get (fd->real.real);
+
+ return d ? rb_str_new2 (d) : Qnil;
+}
+
+void Init_esmart_file_dialog (void)
+{
+ VALUE c;
+
+ rb_require ("esmart");
+
+ c = rb_define_class_under (mEsmart, "FileDialog", cEvasObject);
+
+ rb_define_singleton_method (c, "new", c_new, 2);
+ rb_define_method (c, "on_action", c_on_action, 0);
+ rb_define_method (c, "edje", c_edje_get, 0);
+ rb_define_method (c, "selections", c_selections_get, 0);
+ rb_define_method (c, "current_directory", c_current_directory_get, 0);
+}