From 997208c0df5f282e80476da9b1eccd39d83fb243 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 22 Aug 2010 06:49:44 +0300 Subject: [PATCH] gui: basic save/unload/load project functionality --- gui/gladish.ui | 171 ++++++++++++- gui/graph_view.c | 34 ++- gui/graph_view.h | 3 + gui/gtk_builder.h | 2 + gui/load_project_dialog.c | 182 ++++++++++++++ ...jects_dialog.hpp => load_project_dialog.h} | 13 +- gui/load_projects_dialog.cpp | 236 ------------------ gui/main.c | 28 +++ gui/menu.c | 15 +- gui/menu.h | 4 + gui/save_project_dialog.c | 55 ++++ gui/save_project_dialog.h | 34 +++ proxies/room_proxy.c | 147 +++++++++++ proxies/room_proxy.h | 41 +++ wscript | 9 +- 15 files changed, 712 insertions(+), 262 deletions(-) create mode 100644 gui/load_project_dialog.c rename gui/{load_projects_dialog.hpp => load_project_dialog.h} (72%) delete mode 100644 gui/load_projects_dialog.cpp create mode 100644 gui/save_project_dialog.c create mode 100644 gui/save_project_dialog.h create mode 100644 proxies/room_proxy.c create mode 100644 proxies/room_proxy.h diff --git a/gui/gladish.ui b/gui/gladish.ui index 05a496ff..240df247 100644 --- a/gui/gladish.ui +++ b/gui/gladish.ui @@ -628,22 +628,21 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, main_win False - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK vertical 2 - + 400 400 - True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK automatic automatic - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -654,8 +653,53 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, 1 + + + True + 2 + + + True + 0.52999997138977051 + 2 + Path + + + False + 0 + + + + + True + True + + + + 1 + + + + + Browse... + True + False + True + True + + + False + 2 + + + + + False + 2 + + - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK end @@ -699,8 +743,8 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, - load_project_cancel_button - load_project_ok_button + load_project_cancel_button + load_project_ok_button @@ -1458,4 +1502,117 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, True gtk-save-as + + 5 + normal + main_win + False + + + True + vertical + 2 + + + True + 2 + 2 + 2 + 2 + + + True + Path + + + GTK_FILL + + + + + True + Name + + + 1 + 2 + GTK_FILL + + + + + True + True + + + + 1 + 2 + + + + + True + True + + + + 1 + 2 + 1 + 2 + + + + + False + 1 + + + + + True + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + project_save_as_cancel_button + project_save_as_ok_button + + diff --git a/gui/graph_view.c b/gui/graph_view.c index 04335028..52cf8b21 100644 --- a/gui/graph_view.c +++ b/gui/graph_view.c @@ -29,6 +29,7 @@ #include "gtk_builder.h" #include "world_tree.h" #include "menu.h" +#include "../proxies/room_proxy.h" struct graph_view { @@ -38,6 +39,7 @@ struct graph_view graph_proxy_handle graph; GtkWidget * canvas_widget; ladish_app_supervisor_proxy_handle app_supervisor; + ladish_room_proxy_handle room; }; struct list_head g_views; @@ -113,6 +115,7 @@ create_view( } view_ptr->app_supervisor = NULL; + view_ptr->room = NULL; if (!graph_proxy_create(service, object, graph_dict_supported, &view_ptr->graph)) { @@ -145,15 +148,28 @@ create_view( } } + if (strcmp(object, STUDIO_OBJECT_PATH) != 0 && strcmp(object, JACKDBUS_OBJECT_PATH) != 0) /* TODO: this is a quite lame way to detect room views */ + { + if (!ladish_room_proxy_create(service, object, &view_ptr->room)) + { + goto free_app_supervisor; + } + } + if (!graph_proxy_activate(view_ptr->graph)) { - goto free_app_supervisor; + goto free_room_proxy; } *handle_ptr = (graph_view_handle)view_ptr; return true; +free_room_proxy: + if (view_ptr->room != NULL) + { + ladish_room_proxy_destroy(view_ptr->room); + } free_app_supervisor: if (view_ptr->app_supervisor != NULL) { @@ -237,6 +253,11 @@ void destroy_view(graph_view_handle view) ladish_app_supervisor_proxy_destroy(view_ptr->app_supervisor); } + if (view_ptr->room != NULL) + { + ladish_room_proxy_destroy(view_ptr->room); + } + free(view_ptr->name); free(view_ptr); } @@ -309,11 +330,7 @@ graph_view_handle get_current_view(void) bool is_room_view(graph_view_handle view) { - const char * opath; - - opath = graph_proxy_get_object(view_ptr->graph); - - return strcmp(opath, STUDIO_OBJECT_PATH) != 0 && strcmp(opath, JACKDBUS_OBJECT_PATH) != 0; + return view_ptr->room != NULL; } bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal, uint8_t level) @@ -325,3 +342,8 @@ ladish_app_supervisor_proxy_handle graph_view_get_app_supervisor(graph_view_hand { return view_ptr->app_supervisor; } + +ladish_room_proxy_handle graph_view_get_room(graph_view_handle view) +{ + return view_ptr->room; +} diff --git a/gui/graph_view.h b/gui/graph_view.h index 9c812dca..3ba4b9aa 100644 --- a/gui/graph_view.h +++ b/gui/graph_view.h @@ -29,6 +29,7 @@ #include "graph_canvas.h" #include "../proxies/app_supervisor_proxy.h" +#include "../proxies/room_proxy.h" typedef struct graph_view_tag { int unused; } * graph_view_handle; @@ -57,6 +58,8 @@ bool is_room_view(graph_view_handle view); ladish_app_supervisor_proxy_handle graph_view_get_app_supervisor(graph_view_handle view); bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal, uint8_t level); +ladish_room_proxy_handle graph_view_get_room(graph_view_handle view); + /* not very good place for this prototype, because it is not implemented in graph_view.c */ void set_main_window_title(graph_view_handle view); diff --git a/gui/gtk_builder.h b/gui/gtk_builder.h index ccafafcf..1236aebe 100644 --- a/gui/gtk_builder.h +++ b/gui/gtk_builder.h @@ -27,6 +27,8 @@ #ifndef GTK_BUILDER_H__E2BF7CFC_1B04_4160_9165_A1B433C6B3C2__INCLUDED #define GTK_BUILDER_H__E2BF7CFC_1B04_4160_9165_A1B433C6B3C2__INCLUDED +#include "common.h" + bool init_gtk_builder(void); void uninit_gtk_builder(void); GtkWidget * get_gtk_builder_widget(const char * name); diff --git a/gui/load_project_dialog.c b/gui/load_project_dialog.c new file mode 100644 index 00000000..f69c96b7 --- /dev/null +++ b/gui/load_project_dialog.c @@ -0,0 +1,182 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains implementation of the load project dialog + ************************************************************************** + * + * 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 "load_project_dialog.h" +#include "gtk_builder.h" + +enum +{ + COL_NAME = 0, + COL_MODIFIED, + COL_DESCRIPTION, + COL_MTIME, + NUM_COLS +}; + +#if 0 +static +void +convert_timestamp_to_string( + const time_t timestamp, + std::string& timestamp_string) +{ + GDate mtime, now; + gint days_diff; + struct tm tm_mtime; + time_t time_now; + const gchar *format; + gchar buf[256]; + + if (timestamp == 0) + { + timestamp_string = "Unknown"; + return; + } + + localtime_r(×tamp, &tm_mtime); + + g_date_set_time_t(&mtime, timestamp); + time_now = time(NULL); + g_date_set_time_t(&now, time_now); + + days_diff = g_date_get_julian(&now) - g_date_get_julian(&mtime); + + if (days_diff == 0) + { + format = "Today at %H:%M"; + } + else if (days_diff == 1) + { + format = "Yesterday at %H:%M"; + } + else + { + if (days_diff > 1 && days_diff < 7) + { + format = "%A"; /* Days from last week */ + } + else + { + format = "%x"; /* Any other date */ + } + } + + if (strftime(buf, sizeof(buf), format, &tm_mtime) != 0) + { + timestamp_string = buf; + } + else + { + timestamp_string = "Unknown"; + } +} +#endif + +static int mtime_sorter(GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data) +{ + uint64_t ta; + uint64_t tb; + + gtk_tree_model_get(GTK_TREE_MODEL(user_data), a, COL_MTIME, &ta, -1); + gtk_tree_model_get(GTK_TREE_MODEL(user_data), b, COL_MTIME, &tb, -1); + + return ta > tb ? -1 : (ta == tb ? 0 : 1); +} + +void ladish_run_load_project_dialog(ladish_room_proxy_handle room) +{ + GtkWidget * dialog; + GtkTreeView * view; + GtkResponseType response; + GtkListStore * store; + GtkCellRenderer * renderer; + GtkTreeSortable * sortable; + gint colno; + GtkTreeViewColumn * column; + GtkEntry * path; + + dialog = get_gtk_builder_widget("load_project_dialog"); + path = GTK_ENTRY(get_gtk_builder_widget("load_project_path_entry")); + view = GTK_TREE_VIEW(get_gtk_builder_widget("loadable_project_list")); + + store = GTK_LIST_STORE(gtk_tree_view_get_model(view)); + if (store == NULL) + { + store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64); + sortable = GTK_TREE_SORTABLE(store); + gtk_tree_view_set_model(view, GTK_TREE_MODEL(store)); + + renderer = gtk_cell_renderer_text_new(); + + colno = gtk_tree_view_insert_column_with_attributes(view, -1, "Project Name", renderer, NULL) - 1; + column = gtk_tree_view_get_column(view, colno); + gtk_tree_view_column_set_sort_column_id(column, COL_NAME); + + colno = gtk_tree_view_insert_column_with_attributes(view, -1, "Modified", renderer, NULL) - 1; + column = gtk_tree_view_get_column(view, colno); + gtk_tree_view_column_set_sort_column_id(column, COL_MODIFIED); + gtk_tree_sortable_set_sort_func(sortable, colno, mtime_sorter, store, NULL); + gtk_tree_sortable_set_sort_column_id(sortable, colno, GTK_SORT_ASCENDING); + + colno = gtk_tree_view_insert_column_with_attributes(view, -1, "Description", renderer, NULL) - 1; + column = gtk_tree_view_get_column(view, colno); + gtk_tree_view_column_set_sort_column_id(column, COL_DESCRIPTION); + } + + //log_info("store = %p", store); + + /* Gtk::TreeModel::Row row; */ + /* int result; */ + + /* for (std::list::iterator iter = projects.begin(); iter != projects.end(); iter++) */ + /* { */ + /* std::string str; */ + /* row = *(_model->append()); */ + /* row[_columns.name] = iter->name; */ + /* convert_timestamp_to_string(iter->modification_time, str); */ + /* row[_columns.modified] = str; */ + /* row[_columns.description] = iter->description; */ + /* row[_columns.mtime] = iter->modification_time; */ + /* } */ + + /* _widget->signal_button_press_event().connect(sigc::mem_fun(*this, &LoadProjectDialog::on_button_press_event), false); */ + /* _widget->signal_key_press_event().connect(sigc::mem_fun(*this, &LoadProjectDialog::on_key_press_event), false); */ + + + gtk_entry_set_text(path, ""); + + gtk_widget_show(dialog); + response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + if (response == GTK_RESPONSE_OK) + { + log_info("Loading project from '%s'", gtk_entry_get_text(path)); + if (!ladish_room_proxy_load_project(room, gtk_entry_get_text(path))) + { + log_error("ladish_room_proxy_load_project() failed."); + } + } +} diff --git a/gui/load_projects_dialog.hpp b/gui/load_project_dialog.h similarity index 72% rename from gui/load_projects_dialog.hpp rename to gui/load_project_dialog.h index 10686ebb..c9b95a7f 100644 --- a/gui/load_projects_dialog.hpp +++ b/gui/load_project_dialog.h @@ -2,8 +2,7 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2008 Dave Robillard - * Copyright (C) 2008 Nedko Arnaudov + * Copyright (C) 2010 Nedko Arnaudov * ************************************************************************** * This file contains interface to the load project dialog code @@ -25,9 +24,11 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef PATCHAGE_LOAD_PROJECT_DIALOG_H -#define PATCHAGE_LOAD_PROJECT_DIALOG_H +#ifndef LOAD_PROJECT_DIALOG_H__CD70F7DD_6871_4D72_8087_DB26ABB8FC1F__INCLUDED +#define LOAD_PROJECT_DIALOG_H__CD70F7DD_6871_4D72_8087_DB26ABB8FC1F__INCLUDED -void run_load_project_dialog(std::list& projects); +#include "../proxies/room_proxy.h" -#endif // PATCHAGE_LOAD_PROJECT_DIALOG_H +void ladish_run_load_project_dialog(ladish_room_proxy_handle room); + +#endif /* #ifndef LOAD_PROJECT_DIALOG_H__CD70F7DD_6871_4D72_8087_DB26ABB8FC1F__INCLUDED */ diff --git a/gui/load_projects_dialog.cpp b/gui/load_projects_dialog.cpp deleted file mode 100644 index d93a817c..00000000 --- a/gui/load_projects_dialog.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C ; c-basic-offset: 2 -*- */ -/* - * LADI Session Handler (ladish) - * - * Copyright (C) 2008 Dave Robillard - * Copyright (C) 2008 Nedko Arnaudov - * - ************************************************************************** - * This file contains implementation of the load project dialog - ************************************************************************** - * - * 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 "lash_proxy.hpp" -#include "load_projects_dialog.hpp" -#include "Patchage.hpp" -#include "globals.hpp" - -struct LoadProjectDialog -{ - LoadProjectDialog(); - - void run(std::list& projects); - - void load_selected_project(); - bool on_button_press_event(GdkEventButton* event_ptr); - bool on_key_press_event(GdkEventKey* event_ptr); - - int mtime_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b); - - struct Record : public Gtk::TreeModel::ColumnRecord - { - Gtk::TreeModelColumn name; - Gtk::TreeModelColumn modified; - Gtk::TreeModelColumn description; - Gtk::TreeModelColumn mtime; - }; - - Widget _dialog; - Widget _widget; - Record _columns; - Glib::RefPtr _model; -}; - -static -void -convert_timestamp_to_string( - const time_t timestamp, - std::string& timestamp_string) -{ - GDate mtime, now; - gint days_diff; - struct tm tm_mtime; - time_t time_now; - const gchar *format; - gchar buf[256]; - - if (timestamp == 0) - { - timestamp_string = "Unknown"; - return; - } - - localtime_r(×tamp, &tm_mtime); - - g_date_set_time_t(&mtime, timestamp); - time_now = time(NULL); - g_date_set_time_t(&now, time_now); - - days_diff = g_date_get_julian(&now) - g_date_get_julian(&mtime); - - if (days_diff == 0) - { - format = "Today at %H:%M"; - } - else if (days_diff == 1) - { - format = "Yesterday at %H:%M"; - } - else - { - if (days_diff > 1 && days_diff < 7) - { - format = "%A"; /* Days from last week */ - } - else - { - format = "%x"; /* Any other date */ - } - } - - if (strftime(buf, sizeof(buf), format, &tm_mtime) != 0) - { - timestamp_string = buf; - } - else - { - timestamp_string = "Unknown"; - } -} - - -LoadProjectDialog::LoadProjectDialog() - : _dialog(g_xml, "load_project_dialog") - , _widget(g_xml, "loadable_projects_list") -{ - _dialog.init(g_xml, "load_project_dialog"); - _widget.init(g_xml, "loadable_projects_list"); - - _columns.add(_columns.name); - _columns.add(_columns.modified); - _columns.add(_columns.description); - _columns.add(_columns.mtime); - - _model = Gtk::ListStore::create(_columns); - _widget->set_model(_model); - - _widget->remove_all_columns(); - - _widget->append_column("Project Name", _columns.name); - _widget->get_column(0)->set_sort_column(_columns.name); - - _widget->append_column("Modified", _columns.modified); - _model->set_sort_func(_columns.modified, sigc::mem_fun(this, &LoadProjectDialog::mtime_sorter)); - _widget->get_column(1)->set_sort_column(_columns.modified); - _model->set_sort_column(_columns.modified, Gtk::SORT_ASCENDING); - - _widget->append_column("Description", _columns.description); - _widget->get_column(2)->set_sort_column(_columns.description); -} - -int -LoadProjectDialog::mtime_sorter(Gtk::TreeModel::iterator a, Gtk::TreeModel::iterator b) -{ - time_t ta = (*a)[_columns.mtime]; - time_t tb = (*b)[_columns.mtime]; - - return ta > tb ? -1 : (ta == tb ? 0 : 1); -} - -void -LoadProjectDialog::run(std::list& projects) -{ - Gtk::TreeModel::Row row; - int result; - - for (std::list::iterator iter = projects.begin(); iter != projects.end(); iter++) - { - std::string str; - row = *(_model->append()); - row[_columns.name] = iter->name; - convert_timestamp_to_string(iter->modification_time, str); - row[_columns.modified] = str; - row[_columns.description] = iter->description; - row[_columns.mtime] = iter->modification_time; - } - - _widget->signal_button_press_event().connect(sigc::mem_fun(*this, &LoadProjectDialog::on_button_press_event), false); - _widget->signal_key_press_event().connect(sigc::mem_fun(*this, &LoadProjectDialog::on_key_press_event), false); - -loop: - result = _dialog->run(); - - if (result == 2) - { - Glib::RefPtr selection = _widget->get_selection(); - Gtk::TreeIter iter = selection->get_selected(); - if (!iter) - { - goto loop; - } - - Glib::ustring project_name = (*iter)[_columns.name]; - g_app->load_project(project_name); - } - - _dialog->hide(); -} - - -void -LoadProjectDialog::load_selected_project() -{ - Glib::RefPtr selection = _widget->get_selection(); - Glib::ustring name = (*selection->get_selected())[_columns.name]; - g_app->load_project(name); - _dialog->hide(); -} - - -bool -LoadProjectDialog::on_button_press_event(GdkEventButton * event_ptr) -{ - if (event_ptr->type == GDK_2BUTTON_PRESS && event_ptr->button == 1) - { - load_selected_project(); - return true; - } - return false; -} - - -bool -LoadProjectDialog::on_key_press_event(GdkEventKey * event_ptr) -{ - if (event_ptr->type == GDK_KEY_PRESS && - (event_ptr->keyval == GDK_Return || - event_ptr->keyval == GDK_KP_Enter)) - { - load_selected_project(); - return true; - } - - return false; -} - -void run_load_project_dialog(std::list& projects) -{ - LoadProjectDialog dialog; - dialog.run(projects); -} diff --git a/gui/main.c b/gui/main.c index 48d72464..374fb413 100644 --- a/gui/main.c +++ b/gui/main.c @@ -50,6 +50,8 @@ #include "ask_dialog.h" #include "../proxies/app_supervisor_proxy.h" #include "create_room_dialog.h" +#include "load_project_dialog.h" +#include "save_project_dialog.h" #include "menu.h" GtkWidget * g_main_win; @@ -817,6 +819,32 @@ void menu_request_destroy_room(void) } } +void menu_request_load_project(void) +{ + ladish_run_load_project_dialog(graph_view_get_room(get_current_view())); +} + +void menu_request_unload_project(void) +{ + if (!ladish_room_proxy_unload_project(graph_view_get_room(get_current_view()))) + { + log_error("ladish_room_proxy_unload_project() failed"); + } +} + +void menu_request_save_project(void) +{ + if (!ladish_room_proxy_save_project(graph_view_get_room(get_current_view()), "", "")) + { + log_error("ladish_room_proxy_unload_project() failed"); + } +} + +void menu_request_save_as_project(void) +{ + ladish_run_save_project_dialog(graph_view_get_room(get_current_view())); +} + static gboolean poll_jack(gpointer data) { update_load(); diff --git a/gui/menu.c b/gui/menu.c index 646cc8f0..2819e4b3 100644 --- a/gui/menu.c +++ b/gui/menu.c @@ -38,6 +38,9 @@ static GtkWidget * g_menu_item_rename_studio; static GtkWidget * g_menu_item_create_room; static GtkWidget * g_menu_item_destroy_room; static GtkWidget * g_menu_item_load_project; +static GtkWidget * g_menu_item_unload_project; +static GtkWidget * g_menu_item_save_project; +static GtkWidget * g_menu_item_save_as_project; static GtkWidget * g_menu_item_daemon_exit; static GtkWidget * g_menu_item_jack_configure; static GtkCheckMenuItem * g_menu_item_jack_latency_32; @@ -90,6 +93,9 @@ void menu_init(void) g_menu_item_create_room = get_gtk_builder_widget("menu_item_create_room"); g_menu_item_destroy_room = get_gtk_builder_widget("menu_item_destroy_room"); g_menu_item_load_project = get_gtk_builder_widget("menu_item_load_project"); + g_menu_item_unload_project = get_gtk_builder_widget("menu_item_unload_project"); + g_menu_item_save_project = get_gtk_builder_widget("menu_item_save_project"); + g_menu_item_save_as_project = get_gtk_builder_widget("menu_item_save_as_project"); g_menu_item_daemon_exit = get_gtk_builder_widget("menu_item_daemon_exit"); g_menu_item_jack_configure = get_gtk_builder_widget("menu_item_jack_configure"); g_menu_item_view_toolbar = get_gtk_builder_widget("menu_item_view_toolbar"); @@ -120,6 +126,10 @@ void menu_init(void) g_signal_connect(G_OBJECT(g_menu_item_start_app), "activate", G_CALLBACK(menu_request_start_app), NULL); g_signal_connect(G_OBJECT(g_menu_item_create_room), "activate", G_CALLBACK(menu_request_create_room), NULL); g_signal_connect(G_OBJECT(g_menu_item_destroy_room), "activate", G_CALLBACK(menu_request_destroy_room), NULL); + g_signal_connect(G_OBJECT(g_menu_item_load_project), "activate", G_CALLBACK(menu_request_load_project), NULL); + g_signal_connect(G_OBJECT(g_menu_item_unload_project), "activate", G_CALLBACK(menu_request_unload_project), NULL); + g_signal_connect(G_OBJECT(g_menu_item_save_project), "activate", G_CALLBACK(menu_request_save_project), NULL); + g_signal_connect(G_OBJECT(g_menu_item_save_as_project), "activate", G_CALLBACK(menu_request_save_as_project), NULL); g_signal_connect(G_OBJECT(g_menu_item_jack_latency_32), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)32); g_signal_connect(G_OBJECT(g_menu_item_jack_latency_64), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)64); @@ -209,5 +219,8 @@ bool menu_set_jack_latency(uint32_t buffer_size, bool force, bool * changed_ptr) void menu_view_activated(bool room) { gtk_widget_set_sensitive(g_menu_item_destroy_room, room); - //gtk_widget_set_sensitive(g_menu_item_load_project, room); + gtk_widget_set_sensitive(g_menu_item_load_project, room); + gtk_widget_set_sensitive(g_menu_item_unload_project, room); + gtk_widget_set_sensitive(g_menu_item_save_project, room); + gtk_widget_set_sensitive(g_menu_item_save_as_project, room); } diff --git a/gui/menu.h b/gui/menu.h index fbb28d44..9ba58cff 100644 --- a/gui/menu.h +++ b/gui/menu.h @@ -45,6 +45,10 @@ void menu_request_unload_studio(void); void menu_request_rename_studio(void); void menu_request_create_room(void); void menu_request_destroy_room(void); +void menu_request_load_project(void); +void menu_request_unload_project(void); +void menu_request_save_project(void); +void menu_request_save_as_project(void); void menu_request_jack_latency_change(uint32_t buffer_size); void menu_request_toggle_toolbar(bool visible); diff --git a/gui/save_project_dialog.c b/gui/save_project_dialog.c new file mode 100644 index 00000000..b5ceced5 --- /dev/null +++ b/gui/save_project_dialog.c @@ -0,0 +1,55 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains implementation of the save project dialog + ************************************************************************** + * + * 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 "save_project_dialog.h" +#include "gtk_builder.h" + +void ladish_run_save_project_dialog(ladish_room_proxy_handle room) +{ + GtkWidget * dialog; + GtkEntry * path; + GtkEntry * name; + GtkResponseType response; + + dialog = get_gtk_builder_widget("project_save_as_dialog"); + path = GTK_ENTRY(get_gtk_builder_widget("project_save_as_path_entry")); + name = GTK_ENTRY(get_gtk_builder_widget("project_save_as_name_entry")); + + gtk_entry_set_text(path, ""); + gtk_entry_set_text(name, ""); + + gtk_widget_show(dialog); + response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + if (response == GTK_RESPONSE_OK) + { + log_info("Saving project to '%s' (%s)", gtk_entry_get_text(path), gtk_entry_get_text(name)); + if (!ladish_room_proxy_save_project(room, gtk_entry_get_text(path), gtk_entry_get_text(name))) + { + log_error("ladish_room_proxy_save_project() failed."); + } + } +} diff --git a/gui/save_project_dialog.h b/gui/save_project_dialog.h new file mode 100644 index 00000000..8fb39620 --- /dev/null +++ b/gui/save_project_dialog.h @@ -0,0 +1,34 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains interface to the save project dialog code + ************************************************************************** + * + * 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. + */ + +#ifndef SAVE_PROJECT_DIALOG_H__7C9FB1FB_8582_451E_8959_1CD688E50A20__INCLUDED +#define SAVE_PROJECT_DIALOG_H__7C9FB1FB_8582_451E_8959_1CD688E50A20__INCLUDED + +#include "../proxies/room_proxy.h" + +void ladish_run_save_project_dialog(ladish_room_proxy_handle room); + +#endif /* #ifndef SAVE_PROJECT_DIALOG_H__7C9FB1FB_8582_451E_8959_1CD688E50A20__INCLUDED */ diff --git a/proxies/room_proxy.c b/proxies/room_proxy.c new file mode 100644 index 00000000..90751eb7 --- /dev/null +++ b/proxies/room_proxy.c @@ -0,0 +1,147 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains implementation of code that interfaces + * ladishd room objects through D-Bus + ************************************************************************** + * + * 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 "room_proxy.h" + +struct ladish_room_proxy +{ + char * service; + char * object; +}; + +bool ladish_room_proxy_create(const char * service, const char * object, ladish_room_proxy_handle * handle_ptr) +{ + struct ladish_room_proxy * proxy_ptr; + + proxy_ptr = malloc(sizeof(struct ladish_room_proxy)); + if (proxy_ptr == NULL) + { + log_error("malloc() failed to allocate room proxy struct"); + goto fail; + } + + proxy_ptr->service = strdup(service); + if (proxy_ptr->service == NULL) + { + log_error("strdup() failed too duplicate service name '%s'", service); + goto free_proxy; + } + + proxy_ptr->object = strdup(object); + if (proxy_ptr->object == NULL) + { + log_error("strdup() failed too duplicate object name '%s'", object); + goto free_service; + } + + *handle_ptr = (ladish_room_proxy_handle)proxy_ptr; + return true; + +free_service: + free(proxy_ptr->service); +free_proxy: + free(proxy_ptr); +fail: + return false; +} + +#define proxy_ptr ((struct ladish_room_proxy *)proxy) + +void ladish_room_proxy_destroy(ladish_room_proxy_handle proxy) +{ + free(proxy_ptr->object); + free(proxy_ptr->service); + free(proxy_ptr); +} + +char * ladish_room_proxy_get_name(ladish_room_proxy_handle proxy) +{ + DBusMessage * reply_ptr; + const char * name; + char * name_buffer; + + if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_ROOM, "GetName", "", NULL, &reply_ptr)) + { + log_error("GetName() failed."); + return NULL; + } + + if (!dbus_message_get_args( + reply_ptr, + &g_dbus_error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + { + dbus_message_unref(reply_ptr); + dbus_error_free(&g_dbus_error); + log_error("decoding reply of GetName failed."); + return NULL; + } + + name_buffer = strdup(name); + dbus_message_unref(reply_ptr); + if (name_buffer == NULL) + { + log_error("strdup() for app name failed."); + } + return name_buffer; +} + +bool ladish_room_proxy_load_project(ladish_room_proxy_handle proxy, const char * project_dir) +{ + if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_ROOM, "LoadProject", "s", &project_dir, "")) + { + log_error("LoadProject() failed."); + return false; + } + + return true; +} + +bool ladish_room_proxy_save_project(ladish_room_proxy_handle proxy, const char * project_dir, const char * project_name) +{ + if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_ROOM, "SaveProject", "ss", &project_dir, &project_name, "")) + { + log_error("SaveProject() failed."); + return false; + } + + return true; +} + +bool ladish_room_proxy_unload_project(ladish_room_proxy_handle proxy) +{ + if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_ROOM, "UnloadProject", "", "")) + { + log_error("UnloadProject() failed."); + return false; + } + + return true; +} + +#undef proxy_ptr diff --git a/proxies/room_proxy.h b/proxies/room_proxy.h new file mode 100644 index 00000000..c3561ca4 --- /dev/null +++ b/proxies/room_proxy.h @@ -0,0 +1,41 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains interface to room object that is backed through D-Bus + ************************************************************************** + * + * 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. + */ + +#ifndef ROOM_PROXY_H__0FDD1790_EF07_4C6C_8C95_0F75E29A3E81__INCLUDED +#define ROOM_PROXY_H__0FDD1790_EF07_4C6C_8C95_0F75E29A3E81__INCLUDED + +#include "common.h" + +typedef struct ladish_room_proxy_tag { int unused; } * ladish_room_proxy_handle; + +bool ladish_room_proxy_create(const char * service, const char * object, ladish_room_proxy_handle * proxy_ptr); +void ladish_room_proxy_destroy(ladish_room_proxy_handle proxy); +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); + +#endif /* #ifndef ROOM_PROXY_H__0FDD1790_EF07_4C6C_8C95_0F75E29A3E81__INCLUDED */ diff --git a/wscript b/wscript index c32d7f87..b7f08a54 100644 --- a/wscript +++ b/wscript @@ -393,14 +393,10 @@ def build(bld): for source in [ 'main.c', - #'lash_client.cpp', - #'lash_proxy.cpp', - #'load_projects_dialog.cpp', - #'project.cpp', + 'load_project_dialog.c', + 'save_project_dialog.c', 'world_tree.c', 'graph_view.c', - #'project_properties.cpp', - #'session.cpp', 'canvas.cpp', 'graph_canvas.c', 'gtk_builder.c', @@ -416,6 +412,7 @@ def build(bld): 'studio_proxy.c', 'control_proxy.c', 'app_supervisor_proxy.c', + "room_proxy.c", ]: gladish.source.append(os.path.join("proxies", source))