A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gtk-config-store.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
17  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #include "gtk-config-store.h"
21 #include "raw-text-config.h"
22 #include "display-functions.h"
23 #include "ns3/log.h"
24 #include <fstream>
25 
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("GtkconfigStore");
30 
31 
33 {
34 }
35 
36 void
38 {
39  //this function should be called before running the script to enable the user
40  //to configure the default values for the objects he wants to use
41  GtkWidget *window;
42  GtkWidget *view;
43  GtkWidget *scroll;
44 
45  gtk_init (0, 0);
46  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
47  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Default attributes.");
48  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
49 
50  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
51  GtkTreeStore *model = gtk_tree_store_new (COL_LAST, G_TYPE_POINTER);
52  ModelTypeidCreator creator;
53  creator.Build (model);
54 
55  view = create_view_config_default (model);
56  scroll = gtk_scrolled_window_new (0, 0);
57  gtk_container_add (GTK_CONTAINER (scroll), view);
58 
59  GtkWidget *vbox = gtk_vbox_new (FALSE, 5);
60  gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
61  gtk_box_pack_end (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);
62  GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
63  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
64  GtkWidget *save = gtk_button_new_with_label ("Save");
65  g_signal_connect (save, "clicked", (GCallback) save_clicked_default, window);
66  gtk_box_pack_end (GTK_BOX (hbox), save, FALSE, FALSE, 0);
67  GtkWidget *load = gtk_button_new_with_label ("Load");
68  g_signal_connect (load, "clicked", (GCallback) load_clicked_default, window);
69  gtk_box_pack_end (GTK_BOX (hbox), load, FALSE, FALSE, 0);
70  GtkWidget *exit = gtk_button_new_with_label ("Run Simulation");
71  g_signal_connect (exit, "clicked", (GCallback) exit_clicked_callback, window);
72  gtk_box_pack_end (GTK_BOX (hbox), exit, FALSE, FALSE, 0);
73 
74  gtk_container_add (GTK_CONTAINER (window), vbox);
75 
76  gtk_widget_show_all (window);
77 
78  gtk_main ();
79 
80  gtk_tree_model_foreach (GTK_TREE_MODEL (model),
82  0);
83 
84  gtk_widget_destroy (window);
85 }
86 
87 void
89 {
90  GtkWidget *window;
91  GtkWidget *view;
92  GtkWidget *scroll;
93 
94  gtk_init (0, 0);
95 
96  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
97  gtk_window_set_title (GTK_WINDOW (window), "ns-3 Object attributes.");
98  gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
99 
100  g_signal_connect (window, "delete_event", (GCallback)delete_event_callback, window);
101 
102 
103  GtkTreeStore *model = gtk_tree_store_new (COL_LAST, G_TYPE_POINTER);
104  ModelCreator creator;
105  creator.Build (model);
106 
107  view = create_view (model);
108  scroll = gtk_scrolled_window_new (0, 0);
109  gtk_container_add (GTK_CONTAINER (scroll), view);
110 
111  GtkWidget *vbox = gtk_vbox_new (FALSE, 5);
112  gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
113  gtk_box_pack_end (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);
114  GtkWidget *hbox = gtk_hbox_new (FALSE, 5);
115  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
116  GtkWidget *save = gtk_button_new_with_label ("Save");
117  g_signal_connect (save, "clicked", (GCallback) save_clicked, window);
118  gtk_box_pack_end (GTK_BOX (hbox), save, FALSE, FALSE, 0);
119  GtkWidget *load = gtk_button_new_with_label ("Load");
120  g_signal_connect (load, "clicked", (GCallback) load_clicked, window);
121  gtk_box_pack_end (GTK_BOX (hbox), load, FALSE, FALSE, 0);
122  GtkWidget *exit = gtk_button_new_with_label ("Run Simulation");
123  g_signal_connect (exit, "clicked", (GCallback) exit_clicked_callback, window);
124  gtk_box_pack_end (GTK_BOX (hbox), exit, FALSE, FALSE, 0);
125 
126  gtk_container_add (GTK_CONTAINER (window), vbox);
127 
128  gtk_widget_show_all (window);
129 
130  gtk_main ();
131 
132  gtk_tree_model_foreach (GTK_TREE_MODEL (model),
134  0);
135 
136  gtk_widget_destroy (window);
137 }
138 
139 } // namespace ns3
void ConfigureAttributes(void)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void Build(GtkTreeStore *treestore)
This method will iterate on typeIds having default attributes and create a model for them...
void Build(GtkTreeStore *treestore)
void ConfigureDefaults(void)
void load_clicked(GtkButton *button, gpointer user_data)
If the user presses the button load, it will load the config file into memory.
GtkWidget * create_view_config_default(GtkTreeStore *model)
This is the main view opening the widget, getting tooltips and drawing the tree of attributes...
GtkWidget * create_view(GtkTreeStore *model)
This is the main view opening the widget, getting tooltips and drawing the tree of attributes...
void load_clicked_default(GtkButton *button, gpointer user_data)
If the user presses the button load, it will load the config file into memory.
void exit_clicked_callback(GtkButton *button, gpointer user_data)
Exit the window when exit button is pressed.
gboolean clean_model_callback(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
Delete the tree model contents.
gboolean clean_model_callback_config_default(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
Delete the tree model contents.
void save_clicked_default(GtkButton *button, gpointer user_data)
This is the action done when the user presses on the save button.
gboolean delete_event_callback(GtkWidget *widget, GdkEvent *event, gpointer user_data)
Exit the application.
void save_clicked(GtkButton *button, gpointer user_data)
This is the action done when the user presses on the save button.