/tags/rel-0-4-3/FreeSpeech/visix/src/VisixProject.cc

# · C++ · 238 lines · 154 code · 44 blank · 40 comment · 15 complexity · 37fd2fc112e14e03a90509e6e9a58d6e MD5 · raw file

  1. // Copyright (C) 1999 Jean-Marc Valin
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but
  9. // WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this file. If not, write to the Free Software Foundation,
  15. // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. #include "VisixProject.h"
  17. #include <iostream>
  18. #include "VisixFileSource.h"
  19. #include "VisixApp.h"
  20. /*static gboolean project_click (GtkWidget *widget, GdkEvent *event, VisixProject *project)
  21. {
  22. if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton*)event)->button == 3)
  23. {
  24. project->popup(event);
  25. return true;
  26. }
  27. return false;
  28. }*/
  29. static void file_open_ok_sel(GtkWidget *w, VisixProject *project)
  30. {
  31. GtkWidget *ssel = GTK_WIDGET(gtk_object_get_user_data(GTK_OBJECT(w)));
  32. gchar *fname = g_strdup(gtk_file_selection_get_filename (GTK_FILE_SELECTION(ssel)));
  33. if (fname) {
  34. string name(fname);
  35. project->addFile(name);
  36. }
  37. g_free (fname);
  38. gtk_widget_destroy (GTK_WIDGET (ssel));
  39. ssel = NULL;
  40. }
  41. static gint
  42. file_open_destroy(GtkWidget *w, GtkWidget *sel)
  43. {
  44. gtk_widget_destroy(sel);
  45. return TRUE;
  46. }
  47. static void add_file(GtkMenuItem *menuitem,
  48. VisixProject *project)
  49. {
  50. GtkWidget *ssel = gtk_file_selection_new("Open file...");
  51. gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(ssel)->ok_button),ssel);
  52. gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(ssel)->ok_button),
  53. "clicked", (GtkSignalFunc)file_open_ok_sel,
  54. project);
  55. gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(ssel)->cancel_button),
  56. "clicked", (GtkSignalFunc)file_open_destroy,
  57. ssel);
  58. gtk_widget_show(ssel);
  59. //project->addFile();
  60. }
  61. static void show_properties(GtkMenuItem *menuitem,
  62. VisixProject *project)
  63. {
  64. //cerr << "properties\n";
  65. project->showProperties();
  66. }
  67. VisixProject::VisixProject(GtkWidget *_parent, VisixApp *_app, xmlNodePtr proj)
  68. : parent(_parent)
  69. , app(_app)
  70. //, properties(new AudioProperties())
  71. {
  72. name = string((char *)xmlGetProp(proj, (CHAR *)"name"));
  73. xmlNodePtr prop = proj->childs;
  74. bool found = false;
  75. //cerr << "searching for properties\n";
  76. while (prop != NULL)
  77. {
  78. if (string((char*)prop->name) == "Properties")
  79. {
  80. found = true;
  81. properties = new AudioProperties(prop);
  82. break;
  83. }
  84. prop = prop->next;
  85. }
  86. if (!found)
  87. {
  88. properties = new AudioProperties();
  89. }
  90. setup();
  91. xmlNodePtr src = proj->childs;
  92. while (src != NULL)
  93. {
  94. if (string((char*)src->name) == "FileSource")
  95. {
  96. sources.insert(sources.end(),new VisixFileSource(tree, this, src));
  97. }
  98. src = src->next;
  99. }
  100. }
  101. VisixProject::VisixProject(GtkWidget *_parent, VisixApp *_app, const string &_name)
  102. : parent(_parent)
  103. , name(_name)
  104. , properties(new AudioProperties())
  105. , app(_app)
  106. {
  107. setup();
  108. }
  109. void VisixProject::setup()
  110. {
  111. item = gtk_tree_item_new_with_label((gchar *)name.c_str());
  112. gtk_widget_show(item);
  113. gtk_tree_append(GTK_TREE(parent),item);
  114. tree = gtk_tree_new();
  115. gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
  116. /*gtk_signal_connect (GTK_OBJECT (item), "button-press-event",
  117. GTK_SIGNAL_FUNC (project_click),
  118. this);*/
  119. menu = gtk_menu_new();
  120. gtk_widget_show(menu);
  121. GtkWidget *label = gtk_menu_item_new_with_label("Add File");
  122. gtk_object_ref(GTK_OBJECT(label));
  123. gtk_object_set_data_full (GTK_OBJECT (menu), "label1",
  124. label,
  125. (GtkDestroyNotify) gtk_widget_unref);
  126. gtk_widget_show(label);
  127. gtk_menu_append(GTK_MENU(menu),label);
  128. gtk_signal_connect (GTK_OBJECT (label), "activate",
  129. GTK_SIGNAL_FUNC (add_file),
  130. this);
  131. label = gtk_menu_item_new_with_label("Properties");
  132. gtk_object_ref(GTK_OBJECT(label));
  133. gtk_object_set_data_full (GTK_OBJECT (menu), "label2",
  134. label,
  135. (GtkDestroyNotify) gtk_widget_unref);
  136. gtk_widget_show(label);
  137. gtk_menu_append(GTK_MENU(menu),label);
  138. gtk_signal_connect (GTK_OBJECT (label), "activate",
  139. GTK_SIGNAL_FUNC (show_properties),
  140. this);
  141. gnome_popup_menu_attach(menu, item, this);
  142. }
  143. void VisixProject::popup(GdkEvent *event)
  144. {
  145. gnome_popup_menu_do_popup_modal (menu,NULL,NULL,&(event->button),NULL);
  146. }
  147. void VisixProject::addFile(const string &fullpath)
  148. {
  149. string filename, path;
  150. int slashpos = fullpath.rfind("/");
  151. path="";
  152. path.append(fullpath,0,slashpos+1);
  153. filename=fullpath;
  154. filename.erase(0,slashpos+1);
  155. sources.insert(sources.end(),new VisixFileSource(tree, this, filename, path));
  156. }
  157. void VisixProject::save (xmlNode *root)
  158. {
  159. xmlNodePtr tree;
  160. tree = xmlNewChild(root, NULL, (CHAR *)"Project", NULL);
  161. xmlSetProp(tree, (CHAR *)"name", (CHAR *)name.c_str());
  162. for (int i=0;i<sources.size();i++)
  163. {
  164. sources[i]->save(tree);
  165. }
  166. properties->save(tree);
  167. }
  168. void VisixProject::showProperties()
  169. {
  170. properties->show();
  171. }
  172. void VisixProject::removeSource(VisixSource *src)
  173. {
  174. //ANSI C++ fix
  175. vector<VisixSource *>::iterator i=sources.begin();
  176. while (i != sources.end())
  177. {
  178. if (*i == src)
  179. {
  180. sources.erase(i);
  181. delete src;
  182. break;
  183. }
  184. ++i;
  185. }
  186. /*for (int i=0;i<sources.size();i++)
  187. {
  188. if (sources[i] == src)
  189. {
  190. sources.erase(&sources[i]);
  191. delete src;
  192. }
  193. }*/
  194. }