2 * $Id: rb_esmart_file_dialog.c 336 2005-05-02 17:29:52Z tilman $
4 * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <Esmart/Esmart_File_Dialog.h>
24 #include <evas/rb_evas.h>
25 #include <evas/rb_evas_object.h>
27 #include "../rb_esmart.h"
35 static void c_mark (RbFileDialog *e)
37 c_evas_object_mark (&e->real);
39 if (!NIL_P (e->callback)) {
40 rb_gc_mark (e->callback);
45 static void c_free (RbFileDialog *e)
47 c_evas_object_free (&e->real, false);
52 static VALUE c_new (VALUE klass, VALUE evas, VALUE edj)
55 RbFileDialog *fd = NULL;
57 CHECK_CLASS (evas, cEvas);
59 GET_OBJ (evas, RbEvas, e);
61 self = Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd);
62 fd->real.real = esmart_file_dialog_new (e->real,
63 StringValuePtr (edj));
66 rb_raise (rb_eStandardError, "failed");
69 rb_obj_call_init (self, 1, argv);
77 static void on_action (void *data, Evas_Object *edje,
78 Esmart_File_Dialog_Op op)
83 case ESMART_FILE_DIALOG_NEW:
84 sym = rb_intern ("new");
86 case ESMART_FILE_DIALOG_RENAME:
87 sym = rb_intern ("rename");
89 case ESMART_FILE_DIALOG_DELETE:
90 sym = rb_intern ("delete");
92 case ESMART_FILE_DIALOG_OK:
93 sym = rb_intern ("ok");
95 case ESMART_FILE_DIALOG_CANCEL:
96 sym = rb_intern ("cancel");
98 case ESMART_FILE_DIALOG_DIR_CHANGED:
99 sym = rb_intern ("dir_changed");
105 rb_funcall ((VALUE) data, rb_intern ("call"), 1, ID2SYM (sym));
108 static VALUE c_on_action (VALUE self)
110 GET_OBJ (self, RbFileDialog, fd);
112 if (!rb_block_given_p ())
115 fd->callback = rb_block_proc ();
117 esmart_file_dialog_callback_add (fd->real.real, on_action,
118 (void *) fd->callback);
123 static VALUE c_edje_get (VALUE self)
126 VALUE mEdje, cEdje, s;
129 GET_OBJ (self, RbFileDialog, fd);
131 if (!NIL_P (fd->edje))
134 const_get = rb_intern ("const_get");
135 s = rb_str_new2 ("Edje");
137 mEdje = rb_funcall (rb_cModule, const_get, 1, s);
138 cEdje = rb_funcall (mEdje, const_get, 1, s);
140 e = esmart_file_dialog_edje_get (fd->real.real);
141 fd->edje = rb_funcall (cEdje, rb_intern ("new_from_pointer"), 2,
142 TO_EVAS (self, evas_object_evas_get (e)),
148 static VALUE c_selections_get (VALUE self)
153 GET_OBJ (self, RbFileDialog, fd);
157 list = esmart_file_dialog_selections_get (fd->real.real);
161 for (l = list; l; l = l->next)
162 rb_ary_push (ary, rb_str_new2 (l->data));
167 static VALUE c_current_directory_get (VALUE self)
171 GET_OBJ (self, RbFileDialog, fd);
173 d = esmart_file_dialog_current_directory_get (fd->real.real);
175 return d ? rb_str_new2 (d) : Qnil;
178 void Init_esmart_file_dialog (void)
182 rb_require ("esmart");
184 c = rb_define_class_under (mEsmart, "FileDialog", cEvasObject);
186 rb_define_singleton_method (c, "new", c_new, 2);
187 rb_define_method (c, "on_action", c_on_action, 0);
188 rb_define_method (c, "edje", c_edje_get, 0);
189 rb_define_method (c, "selections", c_selections_get, 0);
190 rb_define_method (c, "current_directory", c_current_directory_get, 0);