mp3splt-gtk
ui_manager.c
1 /**********************************************************
2  *
3  * mp3splt-gtk -- utility based on mp3splt,
4  * for mp3/ogg splitting without decoding
5  *
6  * Copyright (c) 2005-2012 Alexandru Munteanu - io_fx@yahoo.fr
7  *
8  * http://mp3splt.sourceforge.net/
9  *
10  *********************************************************/
11 
12 /**********************************************************
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27  * USA.
28  *
29  *********************************************************/
30 
31 #include <gtk/gtk.h>
32 
33 #include "ui_manager.h"
34 
35 void ui_set_browser_directory(ui_state *ui, const gchar *directory)
36 {
37  ui_infos *infos = ui->infos;
38 
39  if (infos->browser_directory)
40  {
41  g_free(infos->browser_directory);
42  infos->browser_directory = NULL;
43  }
44 
45  if (directory == NULL)
46  {
47  infos->browser_directory = NULL;
48  return;
49  }
50 
51  infos->browser_directory = g_strdup(directory);
52 }
53 
54 const gchar *ui_get_browser_directory(ui_state *ui)
55 {
56  return ui->infos->browser_directory;
57 }
58 
59 void ui_set_main_win_position(ui_state *ui, gint x, gint y)
60 {
61  if (x == 0 && y == 0)
62  {
63  return;
64  }
65 
66  ui_main_window *main_win = ui->infos->main_win;
67  main_win->root_x_pos = x;
68  main_win->root_y_pos = y;
69 }
70 
71 void ui_set_main_win_size(ui_state *ui, gint width, gint height)
72 {
73  ui_main_window *main_win = ui->infos->main_win;
74  main_win->width = width;
75  main_win->height = height;
76 }
77 
78 const ui_main_window *ui_get_main_window_infos(ui_state *ui)
79 {
80  return ui->infos->main_win;
81 }
82 
83 static void ui_main_window_new(ui_infos *infos)
84 {
85  ui_main_window *main_win = g_malloc0(sizeof(ui_main_window));
86 
87  main_win->root_x_pos = 0;
88  main_win->root_y_pos = 0;
89 
90  main_win->width = UI_DEFAULT_WIDTH;
91  main_win->height = UI_DEFAULT_HEIGHT;
92 
93  infos->main_win = main_win;
94 }
95 
96 static void ui_infos_new(ui_state *ui)
97 {
98  ui_infos *infos = g_malloc0(sizeof(ui_infos));
99 
100  ui_main_window_new(infos);
101 
102  infos->browser_directory = NULL;
103 
104  ui->infos = infos;
105 }
106 
107 ui_state *ui_state_new()
108 {
109  ui_state *ui = g_malloc0(sizeof(ui_state));
110 
111  ui_infos_new(ui);
112 
113  return ui;
114 }
115 
116 static void ui_main_window_free(ui_main_window **main_win)
117 {
118  if (!main_win || !*main_win)
119  {
120  return;
121  }
122 
123  g_free(*main_win);
124  *main_win = NULL;
125 }
126 
127 static void ui_infos_free(ui_infos **infos)
128 {
129  if (!infos || !*infos)
130  {
131  return;
132  }
133 
134  ui_main_window_free(&(*infos)->main_win);
135 
136  g_free(*infos);
137  *infos = NULL;
138 }
139 
140 void ui_state_free(ui_state *ui)
141 {
142  if (ui)
143  {
144  ui_infos_free(&ui->infos);
145 
146  g_free(ui);
147  }
148 }
149