NSM.C (5718B)
1 2 /*******************************************************************************/ 3 /* Copyright (C) 2012 Jonathan Moore Liles */ 4 /* */ 5 /* This program is free software; you can redistribute it and/or modify it */ 6 /* under the terms of the GNU General Public License as published by the */ 7 /* Free Software Foundation; either version 2 of the License, or (at your */ 8 /* option) any later version. */ 9 /* */ 10 /* This program is distributed in the hope that it will be useful, but WITHOUT */ 11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ 13 /* more details. */ 14 /* */ 15 /* You should have received a copy of the GNU General Public License along */ 16 /* with This program; see the file COPYING. If not,write to the Free Software */ 17 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 /*******************************************************************************/ 19 20 21 #include "NSM.H" 22 23 #include "../Nio/Nio.h" 24 25 #if defined(FLTK_UI) || defined(NTK_UI) 26 #include <FL/Fl.H> 27 #endif 28 #include <cstdio> 29 #include <cstring> 30 #include <sys/stat.h> 31 #include <sys/types.h> 32 #include <unistd.h> 33 #include <stdlib.h> 34 35 extern int Pexitprogram; 36 #if defined(FLTK_UI) || defined(NTK_UI) 37 #include "MasterUI.h" 38 extern MasterUI *ui; 39 #endif 40 41 extern NSM_Client *nsm; 42 extern char *instance_name; 43 44 NSM_Client::NSM_Client(zyn::MiddleWare *m) 45 :project_filename(0), 46 display_name(0), 47 middleware(m) 48 { 49 } 50 51 int command_open(const char *name, 52 const char *display_name, 53 const char *client_id, 54 char **out_msg); 55 int command_save(char **out_msg); 56 57 int 58 NSM_Client::command_save(char **out_msg) 59 { 60 (void) out_msg; 61 int r = ERR_OK; 62 if(!project_filename) 63 return ERR_NO_SESSION_OPEN; 64 65 middleware->transmitMsgGui(0, "/save_xmz", "s", project_filename); 66 67 return r; 68 } 69 70 int 71 NSM_Client::command_open(const char *name, 72 const char *display_name, 73 const char *client_id, 74 char **out_msg) 75 { 76 (void) out_msg; 77 zyn::Nio::stop(); 78 79 if(instance_name) 80 free(instance_name); 81 82 instance_name = strdup(client_id); 83 84 zyn::Nio::start(); 85 86 char *new_filename = (char *)malloc(strlen(name) + 5); 87 88 if (new_filename) { 89 strcpy(new_filename, name); 90 strcat(new_filename, ".xmz"); 91 } else { 92 // TODO, handle error condition... 93 } 94 95 struct stat st; 96 97 int r = ERR_OK; 98 99 if(0 == stat(new_filename, &st)) 100 middleware->transmitMsgGui(0, "/load_xmz", "s", new_filename); 101 else 102 middleware->transmitMsgGui(0, "/reset_master", ""); 103 104 if(project_filename) 105 free(project_filename); 106 107 if(this->display_name) 108 free(this->display_name); 109 110 project_filename = new_filename; 111 112 this->display_name = strdup(display_name); 113 114 return r; 115 } 116 117 #if defined(FLTK_UI) || defined(NTK_UI) 118 static void save_callback(Fl_Widget *, void *v) 119 { 120 MasterUI *ui = static_cast<MasterUI*>(v); 121 ui->do_save_master(); 122 } 123 #endif 124 125 void 126 NSM_Client::command_active(bool active) 127 { 128 #if defined(FLTK_UI) || defined(NTK_UI) 129 if(active) { 130 Fl_Menu_Item *m; 131 //TODO see if there is a cleaner way of doing this without voiding 132 //constness 133 if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item( 134 "&File/&Open Parameters...")))) 135 m->label("&Import Parameters..."); 136 if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item( 137 "&File/&Open Parameters...")))) 138 m->label("&Import Parameters..."); 139 140 //TODO get this menu entry inserted at the right point 141 if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item("&File/&Export Parameters...")))) 142 m->show(); 143 else 144 ui->mastermenu->add("&File/&Export Parameters...",0,save_callback,ui); 145 146 if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item("&File/&Export Parameters...")))) 147 m->show(); 148 else 149 ui->simplemastermenu->add("&File/&Export Parameters...",0,save_callback,ui); 150 151 ui->sm_indicator1->value(1); 152 ui->sm_indicator2->value(1); 153 ui->sm_indicator1->tooltip(session_manager_name()); 154 ui->sm_indicator2->tooltip(session_manager_name()); 155 } 156 else { 157 Fl_Menu_Item *m; 158 if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item( 159 "&File/&Import Parameters...")))) 160 m->label("&Open Parameters..."); 161 if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item( 162 "&File/&Open Parameters...")))) 163 m->label("&Open Parameters..."); 164 165 if((m=const_cast<Fl_Menu_Item *>(ui->mastermenu->find_item("&File/&Export Parameters...")))) 166 m->hide(); 167 if((m=const_cast<Fl_Menu_Item *>(ui->simplemastermenu->find_item("&File/&Export Parameters...")))) 168 m->hide(); 169 170 ui->sm_indicator1->value(0); 171 ui->sm_indicator2->value(0); 172 ui->sm_indicator1->tooltip(NULL); 173 ui->sm_indicator2->tooltip(NULL); 174 } 175 #else 176 (void)active; 177 #endif 178 }