From: Tilman Sauerbeck Date: Mon, 2 May 2005 17:29:52 +0000 (+0000) Subject: Added esmart_file_dialog. X-Git-Url: http://git.code-monkey.de/?p=ruby-esmart.git;a=commitdiff_plain;h=afcdcdd3b9f7fa92ed327bb189cf6b09cc94c5bf Added esmart_file_dialog. --- diff --git a/Rakefile b/Rakefile index bfb8507..279727e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -# $Id: Rakefile 326 2005-04-27 14:25:18Z tilman $ +# $Id: Rakefile 336 2005-05-02 17:29:52Z tilman $ require "library" require "rake/clean" @@ -10,7 +10,7 @@ require "rake/contrib/sshpublisher" CLOBBER.include("src/**/*.{s,}o") -ext_libs = ["container", "draggies", "trans_x11"].map do |lib| +ext_libs = ["container", "draggies", "trans_x11", "file_dialog"].map do |lib| lib = "esmart_" + lib Library.new(lib, ENV["ESMART_PREFIX"] || "/usr/local", "src/#{lib}") end diff --git a/src/esmart_file_dialog/rb_esmart_file_dialog.c b/src/esmart_file_dialog/rb_esmart_file_dialog.c new file mode 100644 index 0000000..ad61a52 --- /dev/null +++ b/src/esmart_file_dialog/rb_esmart_file_dialog.c @@ -0,0 +1,191 @@ +/* + * $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 + +#include +#include +#include + +#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); +}