2 * $Id: rb_esmart_file_dialog.c 391 2006-11-11 12:14:24Z 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);
40 static void c_mark (RbFileDialog *e)
42 c_evas_object_mark (&e->real);
44 if (!NIL_P (e->callback)) {
45 rb_gc_mark (e->callback);
50 static void c_free (RbFileDialog *e)
52 c_evas_object_free (&e->real, false);
57 static VALUE c_alloc (VALUE klass)
59 RbFileDialog *fd = NULL;
61 return Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd);
64 static VALUE c_init (VALUE self, VALUE evas, VALUE edj)
66 if (!rb_block_given_p ()) {
67 rb_raise (rb_eStandardError, "no block given");
71 CHECK_CLASS (evas, cEvas);
73 GET_OBJ (evas, RbEvas, e);
74 GET_OBJ (self, RbFileDialog, fd);
76 fd->real.real = esmart_file_dialog_new (e->real,
77 StringValuePtr (edj));
80 rb_raise (rb_eStandardError, "failed");
82 rb_call_super (1, &evas);
84 fd->callback = rb_block_proc ();
87 esmart_file_dialog_callback_add (fd->real.real, on_action,
88 (void *) fd->callback);
93 static void on_action (void *data, Evas_Object *edje,
94 Esmart_File_Dialog_Op op)
99 case ESMART_FILE_DIALOG_NEW:
100 sym = rb_intern ("new");
102 case ESMART_FILE_DIALOG_RENAME:
103 sym = rb_intern ("rename");
105 case ESMART_FILE_DIALOG_DELETE:
106 sym = rb_intern ("delete");
108 case ESMART_FILE_DIALOG_OK:
109 sym = rb_intern ("ok");
111 case ESMART_FILE_DIALOG_CANCEL:
112 sym = rb_intern ("cancel");
114 case ESMART_FILE_DIALOG_DIR_CHANGED:
115 sym = rb_intern ("dir_changed");
121 rb_funcall ((VALUE) data, rb_intern ("call"), 1, ID2SYM (sym));
124 static VALUE c_edje_get (VALUE self)
128 GET_OBJ (self, RbFileDialog, fd);
130 if (!NIL_P (fd->edje))
133 e = esmart_file_dialog_edje_get (fd->real.real);
134 fd->edje = rb_funcall (cEdje, rb_intern ("new_from_pointer"), 2,
135 TO_EVAS (self, evas_object_evas_get (e)),
141 static VALUE c_selections_get (VALUE self)
146 GET_OBJ (self, RbFileDialog, fd);
150 list = esmart_file_dialog_selections_get (fd->real.real);
154 for (l = list; l; l = l->next)
155 rb_ary_push (ary, rb_str_new2 (l->data));
160 static VALUE c_current_directory_get (VALUE self)
164 GET_OBJ (self, RbFileDialog, fd);
166 d = esmart_file_dialog_current_directory_get (fd->real.real);
168 return d ? rb_str_new2 (d) : Qnil;
171 void Init_esmart_file_dialog (void)
175 rb_require ("esmart");
178 m = rb_const_get (rb_cModule, rb_intern ("Edje"));
179 cEdje = rb_const_get (m, rb_intern ("Edje"));
181 c = rb_define_class_under (mEsmart, "FileDialog", cEvasObject);
183 rb_define_alloc_func (c, c_alloc);
184 rb_define_method (c, "initialize", c_init, 2);
185 rb_define_method (c, "edje", c_edje_get, 0);
186 rb_define_method (c, "selections", c_selections_get, 0);
187 rb_define_method (c, "current_directory", c_current_directory_get, 0);