2 * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <Esmart/Esmart_File_Dialog.h>
22 #include <evas/rb_evas.h>
23 #include <evas/rb_evas_object.h>
25 #include "../rb_esmart.h"
33 static void on_action (void *data, Evas_Object *edje,
34 Esmart_File_Dialog_Op op);
38 static void c_mark (RbFileDialog *e)
40 c_evas_object_mark (&e->real);
42 if (!NIL_P (e->callback)) {
43 rb_gc_mark (e->callback);
48 static void c_free (RbFileDialog *e)
50 c_evas_object_free (&e->real, false);
55 static VALUE c_alloc (VALUE klass)
57 RbFileDialog *fd = NULL;
59 return Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd);
62 static VALUE c_init (VALUE self, VALUE evas, VALUE edj)
64 if (!rb_block_given_p ()) {
65 rb_raise (rb_eStandardError, "no block given");
69 CHECK_CLASS (evas, cEvas);
71 GET_OBJ (evas, RbEvas, e);
72 GET_OBJ (self, RbFileDialog, fd);
74 fd->real.real = esmart_file_dialog_new (e->real,
75 StringValuePtr (edj));
78 rb_raise (rb_eStandardError, "failed");
80 rb_call_super (1, &evas);
82 fd->callback = rb_block_proc ();
85 esmart_file_dialog_callback_add (fd->real.real, on_action,
86 (void *) fd->callback);
91 static void on_action (void *data, Evas_Object *edje,
92 Esmart_File_Dialog_Op op)
97 case ESMART_FILE_DIALOG_NEW:
98 sym = rb_intern ("new");
100 case ESMART_FILE_DIALOG_RENAME:
101 sym = rb_intern ("rename");
103 case ESMART_FILE_DIALOG_DELETE:
104 sym = rb_intern ("delete");
106 case ESMART_FILE_DIALOG_OK:
107 sym = rb_intern ("ok");
109 case ESMART_FILE_DIALOG_CANCEL:
110 sym = rb_intern ("cancel");
112 case ESMART_FILE_DIALOG_DIR_CHANGED:
113 sym = rb_intern ("dir_changed");
119 rb_funcall ((VALUE) data, rb_intern ("call"), 1, ID2SYM (sym));
122 static VALUE c_edje_get (VALUE self)
126 GET_OBJ (self, RbFileDialog, fd);
128 if (!NIL_P (fd->edje))
131 e = esmart_file_dialog_edje_get (fd->real.real);
132 fd->edje = rb_funcall (cEdje, rb_intern ("new_from_pointer"), 2,
133 TO_EVAS (self, evas_object_evas_get (e)),
139 static VALUE c_selections_get (VALUE self)
144 GET_OBJ (self, RbFileDialog, fd);
148 list = esmart_file_dialog_selections_get (fd->real.real);
152 for (l = list; l; l = l->next)
153 rb_ary_push (ary, rb_str_new2 (l->data));
158 static VALUE c_current_directory_get (VALUE self)
162 GET_OBJ (self, RbFileDialog, fd);
164 d = esmart_file_dialog_current_directory_get (fd->real.real);
166 return d ? rb_str_new2 (d) : Qnil;
169 void Init_esmart_file_dialog (void)
173 rb_require ("esmart");
176 m = rb_const_get (rb_cModule, rb_intern ("Edje"));
177 cEdje = rb_const_get (m, rb_intern ("Edje"));
179 c = rb_define_class_under (mEsmart, "FileDialog", cEvasObject);
181 rb_define_alloc_func (c, c_alloc);
182 rb_define_method (c, "initialize", c_init, 2);
183 rb_define_method (c, "edje", c_edje_get, 0);
184 rb_define_method (c, "selections", c_selections_get, 0);
185 rb_define_method (c, "current_directory", c_current_directory_get, 0);