diff --git a/gui/graph_view.c b/gui/graph_view.c index d9fdf36d..c0640d69 100644 --- a/gui/graph_view.c +++ b/gui/graph_view.c @@ -113,7 +113,14 @@ static void app_removed(void * context, uint64_t id) world_tree_remove_app(context, id); } -static void project_properties_changed(void * context, const char * project_dir, const char * project_name) +static +void +project_properties_changed( + void * context, + const char * project_dir, + const char * project_name, + const char * project_description, + const char * project_notes) { bool empty; char * project_name_buffer; diff --git a/gui/menu.c b/gui/menu.c index 8cd5262b..f0b31374 100644 --- a/gui/menu.c +++ b/gui/menu.c @@ -29,6 +29,7 @@ #include "gtk_builder.h" #include "studio.h" #include "dynmenu.h" +#include "project_properties.h" static GtkWidget * g_menu_item_new_studio; static GtkWidget * g_menu_item_start_studio; @@ -415,6 +416,10 @@ void fill_view_popup_menu(GtkMenu * menu, graph_view_handle view) g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_save_project_as, NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + menuitem = gtk_menu_item_new_with_label("Project Properties..."); + g_signal_connect(menuitem, "activate", (GCallback)ladish_project_properties_dialog_run, NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + menuitem = gtk_separator_menu_item_new(); /* separator */ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); diff --git a/gui/project_properties.c b/gui/project_properties.c new file mode 100644 index 00000000..326a3067 --- /dev/null +++ b/gui/project_properties.c @@ -0,0 +1,88 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains implements the project properties dialog helpers + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "common.h" +#include "gtk_builder.h" +#include "graph_view.h" + +void ladish_project_properties_dialog_run(void) +{ + GtkDialog * dialog_ptr; + GtkEntry * name_entry_ptr; + GtkEntry * description_entry_ptr; + GtkTextView * notes_text_view_ptr; + ladish_room_proxy_handle proxy; + const char * dir; + const char * name; + const char * description; + const char * notes; + GtkTextBuffer * notes_buffer; + GtkTextIter start; + GtkTextIter end; + guint result; + bool ok; + + dialog_ptr = GTK_DIALOG(get_gtk_builder_widget("project_properties_dialog")); + name_entry_ptr = GTK_ENTRY(get_gtk_builder_widget("project_name")); + description_entry_ptr = GTK_ENTRY(get_gtk_builder_widget("project_description")); + notes_text_view_ptr = GTK_TEXT_VIEW(get_gtk_builder_widget("project_notes")); + + proxy = graph_view_get_room(get_current_view()); + ladish_room_proxy_get_project_properties(proxy, &dir, &name, &description, ¬es); + + gtk_entry_set_text(name_entry_ptr, name); + gtk_widget_set_sensitive(GTK_WIDGET(name_entry_ptr), FALSE); /* rename is not implemented yet */ + + gtk_entry_set_text(description_entry_ptr, description); + gtk_window_set_focus(GTK_WINDOW(dialog_ptr), GTK_WIDGET(description_entry_ptr)); + + notes_buffer = gtk_text_view_get_buffer(notes_text_view_ptr); + gtk_text_buffer_set_text(notes_buffer, notes, -1); + + gtk_widget_show(GTK_WIDGET(dialog_ptr)); + + result = gtk_dialog_run(dialog_ptr); + ok = result == 2; + if (ok) + { + if (!ladish_room_proxy_set_project_description(proxy, gtk_entry_get_text(description_entry_ptr))) + { + error_message_box("Setting of project description failed, please inspect logs."); + } + else + { + gtk_text_buffer_get_start_iter(notes_buffer, &start); + gtk_text_buffer_get_end_iter(notes_buffer, &end); + + if (!ladish_room_proxy_set_project_notes(proxy, gtk_text_buffer_get_text(notes_buffer, &start, &end, FALSE))) + { + error_message_box("Setting of project description failed, please inspect logs."); + } + } + } + + gtk_widget_hide(GTK_WIDGET(dialog_ptr)); +} diff --git a/gui/project_properties.cpp b/gui/project_properties.cpp deleted file mode 100644 index 35889ca2..00000000 --- a/gui/project_properties.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C ; c-basic-offset: 2 -*- */ -/* - * LADI Session Handler (ladish) - * - * Copyright (C) 2008 Nedko Arnaudov - * - ************************************************************************** - * This file contains interface of the project_properties_dialog class - ************************************************************************** - * - * LADI Session Handler is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * LADI Session Handler 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LADI Session Handler. If not, see - * or write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "common.h" - -#include -#include - -#include "project.hpp" -#include "project_properties.hpp" -#include "Widget.hpp" -#include "globals.hpp" - -struct project_properties_dialog_impl -{ - Widget _dialog; - Widget _name; - Widget _description; - Widget _notes; - - project_properties_dialog_impl(); -}; - -project_properties_dialog::project_properties_dialog() -{ - _impl_ptr = new project_properties_dialog_impl; - -} - -project_properties_dialog::~project_properties_dialog() -{ - delete _impl_ptr; -} - -void -project_properties_dialog::run( - boost::shared_ptr project_ptr) -{ - std::string name; - std::string description; - std::string notes; - Glib::RefPtr buffer; - int result; - - project_ptr->get_name(name); - _impl_ptr->_name->set_text(name); - - project_ptr->get_description(description); - _impl_ptr->_description->set_text(description); - - project_ptr->get_notes(notes); - buffer = _impl_ptr->_notes->get_buffer(); - buffer->set_text(notes); - - result = _impl_ptr->_dialog->run(); - if (result == 2) - { - project_ptr->do_change_description(_impl_ptr->_description->get_text()); - project_ptr->do_change_notes(buffer->get_text()); - project_ptr->do_rename(_impl_ptr->_name->get_text()); - } - - _impl_ptr->_dialog->hide(); -} - -project_properties_dialog_impl::project_properties_dialog_impl() -{ - _dialog.init(g_xml, "project_properties_dialog"); - _name.init(g_xml, "project_name"); - _description.init(g_xml, "project_description"); - _notes.init(g_xml, "project_notes"); -} diff --git a/gui/project_properties.hpp b/gui/project_properties.h similarity index 61% rename from gui/project_properties.hpp rename to gui/project_properties.h index d025084a..9c7cafe9 100644 --- a/gui/project_properties.hpp +++ b/gui/project_properties.h @@ -2,10 +2,10 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2008 Nedko Arnaudov + * Copyright (C) 2010 Nedko Arnaudov * ************************************************************************** - * This file contains interface of the project_properties_dialog class + * This file contains interface for the project properties dialog helpers ************************************************************************** * * LADI Session Handler is free software; you can redistribute it and/or modify @@ -24,21 +24,9 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef PROJECT_PROPERTIES_HPP__B854A265_3660_4DAA_87E7_104020C5962D__INCLUDED -#define PROJECT_PROPERTIES_HPP__B854A265_3660_4DAA_87E7_104020C5962D__INCLUDED +#ifndef PROJECT_PROPERTIES_H__B854A265_3660_4DAA_87E7_104020C5962D__INCLUDED +#define PROJECT_PROPERTIES_H__B854A265_3660_4DAA_87E7_104020C5962D__INCLUDED -struct project_properties_dialog_impl; +void ladish_project_properties_dialog_run(void); -class project_properties_dialog -{ -public: - project_properties_dialog(); - ~project_properties_dialog(); - - void run(boost::shared_ptr project_ptr); - -private: - project_properties_dialog_impl * _impl_ptr; -}; - -#endif // #ifndef PROJECT_PROPERTIES_HPP__B854A265_3660_4DAA_87E7_104020C5962D__INCLUDED +#endif // #ifndef PROJECT_PROPERTIES_H__B854A265_3660_4DAA_87E7_104020C5962D__INCLUDED diff --git a/gui/room.c b/gui/room.c index 54c7a814..310d0f18 100644 --- a/gui/room.c +++ b/gui/room.c @@ -89,20 +89,13 @@ void menu_request_unload_project(void) void menu_request_save_project(void) { bool new_project; - char * project_dir; - char * project_name; + const char * project_dir; + const char * project_name; - if (!ladish_room_proxy_get_project_properties(graph_view_get_room(get_current_view()), &project_dir, &project_name)) - { - error_message_box("Get project properties failed, please inspect logs."); - return; - } + ladish_room_proxy_get_project_properties(graph_view_get_room(get_current_view()), &project_dir, &project_name, NULL, NULL); new_project = strlen(project_dir) == 0; - free(project_name); - free(project_dir); - if (new_project) { menu_request_save_as_project(); diff --git a/gui/save_project_dialog.c b/gui/save_project_dialog.c index e41ec3d5..679fc9ac 100644 --- a/gui/save_project_dialog.c +++ b/gui/save_project_dialog.c @@ -55,8 +55,8 @@ void ladish_run_save_project_dialog(ladish_room_proxy_handle room) GtkEntry * name = NULL; GtkResponseType response; - char * project_dir; - char * project_name; + const char * project_dir; + const char * project_name; dialog = get_gtk_builder_widget("project_save_as_dialog"); path_button = get_gtk_builder_widget("project_save_as_path_button"); @@ -65,18 +65,11 @@ void ladish_run_save_project_dialog(ladish_room_proxy_handle room) g_signal_connect( G_OBJECT(path_button), "clicked", G_CALLBACK(on_path_button_clicked), NULL); - if (!ladish_room_proxy_get_project_properties(room, &project_dir, &project_name)) - { - error_message_box("Get project properties failed, please inspect logs."); - return; - } + ladish_room_proxy_get_project_properties(room, &project_dir, &project_name, NULL, NULL); gtk_entry_set_text(path, project_dir); gtk_entry_set_text(name, project_name); - free(project_name); - free(project_dir); - gtk_widget_show(dialog); response = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(dialog); diff --git a/proxies/room_proxy.c b/proxies/room_proxy.c index 4a7852a5..599293df 100644 --- a/proxies/room_proxy.c +++ b/proxies/room_proxy.c @@ -36,11 +36,15 @@ struct ladish_room_proxy void (* project_properties_changed)( void * project_properties_changed_context, const char * project_dir, - const char * project_name); + const char * project_name, + const char * project_description, + const char * project_notes); uint64_t project_properties_version; char * project_name; char * project_dir; + char * project_description; + char * project_notes; }; static bool update_project_properties(struct ladish_room_proxy * proxy_ptr, DBusMessage * message_ptr, const char * context) @@ -50,14 +54,18 @@ static bool update_project_properties(struct ladish_room_proxy * proxy_ptr, DBus dbus_uint64_t version; const char * name; const char * dir; + const char * description; + const char * notes; char * name_buffer; char * dir_buffer; + char * description_buffer; + char * notes_buffer; signature = dbus_message_get_signature(message_ptr); if (strcmp(signature, "ta{sv}") != 0) { log_error("%s signature mismatch. '%s'", context, signature); - return false; + goto fail; } dbus_message_iter_init(message_ptr, &iter); @@ -68,12 +76,12 @@ static bool update_project_properties(struct ladish_room_proxy * proxy_ptr, DBus if (version == 0) { log_error("%s contains project properties version 0", context); - return false; + goto fail; } if (proxy_ptr->project_properties_version >= version) { - return true; + goto fail; } if (!dbus_iter_get_dict_entry_string(&iter, "name", &name)) @@ -86,19 +94,42 @@ static bool update_project_properties(struct ladish_room_proxy * proxy_ptr, DBus dir = ""; } + if (!dbus_iter_get_dict_entry_string(&iter, "description", &description)) + { + description = ""; + } + + if (!dbus_iter_get_dict_entry_string(&iter, "notes", ¬es)) + { + notes = ""; + } + name_buffer = strdup(name); if (name_buffer == NULL) { log_error("strdup() failed for project name"); - return false; + goto fail; } dir_buffer = strdup(dir); if (dir_buffer == NULL) { log_error("strdup() failed for project dir"); - free(name_buffer); - return false; + goto fail_free_name_buffer; + } + + description_buffer = strdup(description); + if (description_buffer == NULL) + { + log_error("strdup() failed for project description"); + goto fail_free_dir_buffer; + } + + notes_buffer = strdup(notes); + if (notes_buffer == NULL) + { + log_error("strdup() failed for project notes"); + goto fail_free_description_buffer; } proxy_ptr->project_properties_version = version; @@ -115,17 +146,42 @@ static bool update_project_properties(struct ladish_room_proxy * proxy_ptr, DBus } proxy_ptr->project_dir = dir_buffer; + if (proxy_ptr->project_description != NULL) + { + free(proxy_ptr->project_description); + } + proxy_ptr->project_description = description_buffer; + + if (proxy_ptr->project_notes != NULL) + { + free(proxy_ptr->project_notes); + } + proxy_ptr->project_notes = notes_buffer; + /* log_info("Room '%s' project properties changed:", proxy_ptr->object); /\* TODO: cache project name *\/ */ /* log_info(" Properties version: %"PRIu64, proxy_ptr->project_properties_version); */ /* log_info(" Project name: '%s'", proxy_ptr->project_name); */ /* log_info(" Project dir: '%s'", proxy_ptr->project_dir); */ + /* log_info(" Project description: '%s'", proxy_ptr->project_description); */ + /* log_info(" Project notes: '%s'", proxy_ptr->project_notes); */ proxy_ptr->project_properties_changed( proxy_ptr->project_properties_changed_context, proxy_ptr->project_dir, - proxy_ptr->project_name); + proxy_ptr->project_name, + proxy_ptr->project_description, + proxy_ptr->project_notes); return true; + +fail_free_description_buffer: + free(description_buffer); +fail_free_dir_buffer: + free(dir_buffer); +fail_free_name_buffer: + free(name_buffer); +fail: + return false; } bool ladish_room_proxy_get_project_properties_internal(struct ladish_room_proxy * proxy_ptr) @@ -175,7 +231,9 @@ ladish_room_proxy_create( void (* project_properties_changed)( void * project_properties_changed_context, const char * project_dir, - const char * project_name), + const char * project_name, + const char * project_description, + const char * project_notes), ladish_room_proxy_handle * handle_ptr) { struct ladish_room_proxy * proxy_ptr; @@ -204,6 +262,8 @@ ladish_room_proxy_create( proxy_ptr->project_properties_version = 0; proxy_ptr->project_name = NULL; proxy_ptr->project_dir = NULL; + proxy_ptr->project_description = NULL; + proxy_ptr->project_notes = NULL; proxy_ptr->project_properties_changed_context = project_properties_changed_context; proxy_ptr->project_properties_changed = project_properties_changed; @@ -256,6 +316,16 @@ void ladish_room_proxy_destroy(ladish_room_proxy_handle proxy) free(proxy_ptr->project_dir); } + if (proxy_ptr->project_description != NULL) + { + free(proxy_ptr->project_description); + } + + if (proxy_ptr->project_notes != NULL) + { + free(proxy_ptr->project_notes); + } + free(proxy_ptr->object); free(proxy_ptr->service); free(proxy_ptr); @@ -327,31 +397,66 @@ bool ladish_room_proxy_unload_project(ladish_room_proxy_handle proxy) return true; } -bool ladish_room_proxy_get_project_properties(ladish_room_proxy_handle proxy, char ** project_dir, char ** project_name) +void +ladish_room_proxy_get_project_properties( + ladish_room_proxy_handle proxy, + const char ** project_dir, + const char ** project_name, + const char ** project_description, + const char ** project_notes) { - char * name; - char * dir; - ASSERT(proxy_ptr->project_properties_version > 0); - name = strdup(proxy_ptr->project_name); - if (name == NULL) + if (project_dir != NULL) { - log_error("strdup() failed for project name"); + *project_dir = proxy_ptr->project_dir; + } + + if (project_name != NULL) + { + *project_name = proxy_ptr->project_name; + } + + if (project_description != NULL) + { + *project_description = proxy_ptr->project_description; + } + + if (project_notes != NULL) + { + *project_notes = proxy_ptr->project_notes; + } +} + +bool +ladish_room_proxy_set_project_description( + ladish_room_proxy_handle proxy, + const char * description) +{ + uint64_t new_version; + + if (!dbus_call(0, proxy_ptr->service, proxy_ptr->object, IFACE_ROOM, "SetProjectDescription", "s", &description, "t", &new_version)) + { + log_error("SetProjectDescription() failed."); return false; } - dir = strdup(proxy_ptr->project_dir); - if (dir == NULL) + return true; +} + +bool +ladish_room_proxy_set_project_notes( + ladish_room_proxy_handle proxy, + const char * notes) +{ + uint64_t new_version; + + if (!dbus_call(0, proxy_ptr->service, proxy_ptr->object, IFACE_ROOM, "SetProjectNotes", "s", ¬es, "t", &new_version)) { - log_error("strdup() failed for project dir"); - free(name); + log_error("SetProjectNotes(%s) failed.", notes); return false; } - *project_name = name; - *project_dir = dir; - return true; } diff --git a/proxies/room_proxy.h b/proxies/room_proxy.h index edfaf38a..0644c0fd 100644 --- a/proxies/room_proxy.h +++ b/proxies/room_proxy.h @@ -39,7 +39,9 @@ ladish_room_proxy_create( void (* project_properties_changed)( void * project_properties_changed_context, const char * project_dir, - const char * project_name), + const char * project_name, + const char * project_description, + const char * project_notes), ladish_room_proxy_handle * proxy_ptr); void ladish_room_proxy_destroy(ladish_room_proxy_handle proxy); @@ -47,7 +49,24 @@ char * ladish_room_proxy_get_name(ladish_room_proxy_handle proxy); bool ladish_room_proxy_load_project(ladish_room_proxy_handle proxy, const char * project_dir); bool ladish_room_proxy_save_project(ladish_room_proxy_handle proxy, const char * project_dir, const char * project_name); bool ladish_room_proxy_unload_project(ladish_room_proxy_handle proxy); -bool ladish_room_proxy_get_project_properties(ladish_room_proxy_handle proxy, char ** project_dir, char ** project_name); + +void +ladish_room_proxy_get_project_properties( + ladish_room_proxy_handle proxy, + const char ** project_dir, + const char ** project_name, + const char ** project_description, + const char ** project_notes); + +bool +ladish_room_proxy_set_project_description( + ladish_room_proxy_handle proxy, + const char * description); + +bool +ladish_room_proxy_set_project_notes( + ladish_room_proxy_handle proxy, + const char * notes); bool ladish_room_proxy_get_recent_projects( diff --git a/wscript b/wscript index f8e5c34d..d06a9c7f 100644 --- a/wscript +++ b/wscript @@ -500,6 +500,7 @@ def build(bld): 'main.c', 'load_project_dialog.c', 'save_project_dialog.c', + 'project_properties.c', 'world_tree.c', 'graph_view.c', 'canvas.cpp',