/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
- // Copyright (C) 1999 Jean-Marc Valin
- //
- // This program 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, or (at your option)
- // any later version.
- //
- // This program 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 this file. If not, write to the Free Software Foundation,
- // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- #include "VisixProject.h"
- #include <iostream>
- #include "VisixFileSource.h"
- #include "VisixApp.h"
- /*static gboolean project_click (GtkWidget *widget, GdkEvent *event, VisixProject *project)
- {
- if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton*)event)->button == 3)
- {
- project->popup(event);
- return true;
- }
- return false;
- }*/
- static void file_open_ok_sel(GtkWidget *w, VisixProject *project)
- {
- GtkWidget *ssel = GTK_WIDGET(gtk_object_get_user_data(GTK_OBJECT(w)));
- gchar *fname = g_strdup(gtk_file_selection_get_filename (GTK_FILE_SELECTION(ssel)));
-
- if (fname) {
- string name(fname);
- project->addFile(name);
- }
-
- g_free (fname);
- gtk_widget_destroy (GTK_WIDGET (ssel));
- ssel = NULL;
- }
- static gint
- file_open_destroy(GtkWidget *w, GtkWidget *sel)
- {
- gtk_widget_destroy(sel);
- return TRUE;
- }
- static void add_file(GtkMenuItem *menuitem,
- VisixProject *project)
- {
- GtkWidget *ssel = gtk_file_selection_new("Open file...");
-
- gtk_object_set_user_data(GTK_OBJECT(GTK_FILE_SELECTION(ssel)->ok_button),ssel);
- gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(ssel)->ok_button),
- "clicked", (GtkSignalFunc)file_open_ok_sel,
- project);
-
- gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(ssel)->cancel_button),
- "clicked", (GtkSignalFunc)file_open_destroy,
- ssel);
-
-
- gtk_widget_show(ssel);
- //project->addFile();
- }
- static void show_properties(GtkMenuItem *menuitem,
- VisixProject *project)
- {
- //cerr << "properties\n";
- project->showProperties();
- }
- VisixProject::VisixProject(GtkWidget *_parent, VisixApp *_app, xmlNodePtr proj)
- : parent(_parent)
- , app(_app)
- //, properties(new AudioProperties())
- {
- name = string((char *)xmlGetProp(proj, (CHAR *)"name"));
-
- xmlNodePtr prop = proj->childs;
- bool found = false;
- //cerr << "searching for properties\n";
- while (prop != NULL)
- {
- if (string((char*)prop->name) == "Properties")
- {
- found = true;
- properties = new AudioProperties(prop);
- break;
- }
- prop = prop->next;
- }
- if (!found)
- {
- properties = new AudioProperties();
- }
-
- setup();
- xmlNodePtr src = proj->childs;
- while (src != NULL)
- {
- if (string((char*)src->name) == "FileSource")
- {
- sources.insert(sources.end(),new VisixFileSource(tree, this, src));
- }
- src = src->next;
- }
- }
- VisixProject::VisixProject(GtkWidget *_parent, VisixApp *_app, const string &_name)
- : parent(_parent)
- , name(_name)
- , properties(new AudioProperties())
- , app(_app)
- {
- setup();
- }
- void VisixProject::setup()
- {
- item = gtk_tree_item_new_with_label((gchar *)name.c_str());
-
- gtk_widget_show(item);
- gtk_tree_append(GTK_TREE(parent),item);
- tree = gtk_tree_new();
- gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
- /*gtk_signal_connect (GTK_OBJECT (item), "button-press-event",
- GTK_SIGNAL_FUNC (project_click),
- this);*/
- menu = gtk_menu_new();
- gtk_widget_show(menu);
- GtkWidget *label = gtk_menu_item_new_with_label("Add File");
- gtk_object_ref(GTK_OBJECT(label));
- gtk_object_set_data_full (GTK_OBJECT (menu), "label1",
- label,
- (GtkDestroyNotify) gtk_widget_unref);
- gtk_widget_show(label);
- gtk_menu_append(GTK_MENU(menu),label);
- gtk_signal_connect (GTK_OBJECT (label), "activate",
- GTK_SIGNAL_FUNC (add_file),
- this);
- label = gtk_menu_item_new_with_label("Properties");
- gtk_object_ref(GTK_OBJECT(label));
- gtk_object_set_data_full (GTK_OBJECT (menu), "label2",
- label,
- (GtkDestroyNotify) gtk_widget_unref);
- gtk_widget_show(label);
- gtk_menu_append(GTK_MENU(menu),label);
- gtk_signal_connect (GTK_OBJECT (label), "activate",
- GTK_SIGNAL_FUNC (show_properties),
- this);
-
- gnome_popup_menu_attach(menu, item, this);
- }
- void VisixProject::popup(GdkEvent *event)
- {
- gnome_popup_menu_do_popup_modal (menu,NULL,NULL,&(event->button),NULL);
- }
- void VisixProject::addFile(const string &fullpath)
- {
- string filename, path;
- int slashpos = fullpath.rfind("/");
- path="";
- path.append(fullpath,0,slashpos+1);
- filename=fullpath;
- filename.erase(0,slashpos+1);
- sources.insert(sources.end(),new VisixFileSource(tree, this, filename, path));
- }
- void VisixProject::save (xmlNode *root)
- {
- xmlNodePtr tree;
- tree = xmlNewChild(root, NULL, (CHAR *)"Project", NULL);
- xmlSetProp(tree, (CHAR *)"name", (CHAR *)name.c_str());
- for (int i=0;i<sources.size();i++)
- {
- sources[i]->save(tree);
- }
- properties->save(tree);
- }
- void VisixProject::showProperties()
- {
- properties->show();
- }
- void VisixProject::removeSource(VisixSource *src)
- {
- //ANSI C++ fix
- vector<VisixSource *>::iterator i=sources.begin();
- while (i != sources.end())
- {
- if (*i == src)
- {
- sources.erase(i);
- delete src;
- break;
- }
- ++i;
- }
- /*for (int i=0;i<sources.size();i++)
- {
- if (sources[i] == src)
- {
- sources.erase(&sources[i]);
- delete src;
- }
- }*/
- }