2 * $Id: rb_esmart_file_dialog.c 337 2005-05-02 17:48:20Z 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 on_action (void *data, Evas_Object *edje,
36 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_new (VALUE klass, VALUE evas, VALUE edj)
58 RbFileDialog *fd = NULL;
60 if (!rb_block_given_p ()) {
61 rb_raise (rb_eStandardError, "no block given");
65 CHECK_CLASS (evas, cEvas);
67 GET_OBJ (evas, RbEvas, e);
69 self = Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd);
70 fd->real.real = esmart_file_dialog_new (e->real,
71 StringValuePtr (edj));
74 rb_raise (rb_eStandardError, "failed");
77 rb_obj_call_init (self, 1, argv);
79 fd->callback = rb_block_proc ();
82 esmart_file_dialog_callback_add (fd->real.real, on_action,
83 (void *) fd->callback);
88 static void on_action (void *data, Evas_Object *edje,
89 Esmart_File_Dialog_Op op)
94 case ESMART_FILE_DIALOG_NEW:
95 sym = rb_intern ("new");
97 case ESMART_FILE_DIALOG_RENAME:
98 sym = rb_intern ("rename");
100 case ESMART_FILE_DIALOG_DELETE:
101 sym = rb_intern ("delete");
103 case ESMART_FILE_DIALOG_OK:
104 sym = rb_intern ("ok");
106 case ESMART_FILE_DIALOG_CANCEL:
107 sym = rb_intern ("cancel");
109 case ESMART_FILE_DIALOG_DIR_CHANGED:
110 sym = rb_intern ("dir_changed");
116 rb_funcall ((VALUE) data, rb_intern ("call"), 1, ID2SYM (sym));
119 static VALUE c_edje_get (VALUE self)
122 VALUE mEdje, cEdje, s;
125 GET_OBJ (self, RbFileDialog, fd);
127 if (!NIL_P (fd->edje))
130 const_get = rb_intern ("const_get");
131 s = rb_str_new2 ("Edje");
133 mEdje = rb_funcall (rb_cModule, const_get, 1, s);
134 cEdje = rb_funcall (mEdje, const_get, 1, s);
136 e = esmart_file_dialog_edje_get (fd->real.real);
137 fd->edje = rb_funcall (cEdje, rb_intern ("new_from_pointer"), 2,
138 TO_EVAS (self, evas_object_evas_get (e)),
144 static VALUE c_selections_get (VALUE self)
149 GET_OBJ (self, RbFileDialog, fd);
153 list = esmart_file_dialog_selections_get (fd->real.real);
157 for (l = list; l; l = l->next)
158 rb_ary_push (ary, rb_str_new2 (l->data));
163 static VALUE c_current_directory_get (VALUE self)
167 GET_OBJ (self, RbFileDialog, fd);
169 d = esmart_file_dialog_current_directory_get (fd->real.real);
171 return d ? rb_str_new2 (d) : Qnil;
174 void Init_esmart_file_dialog (void)
178 rb_require ("esmart");
180 c = rb_define_class_under (mEsmart, "FileDialog", cEvasObject);
182 rb_define_singleton_method (c, "new", c_new, 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);