mp3splt-gtk
|
00001 /********************************************************** 00002 * 00003 * mp3splt-gtk -- utility based on mp3splt, 00004 * for mp3/ogg splitting without decoding 00005 * 00006 * Copyright: (C) 2005-2011 Alexandru Munteanu 00007 * Contact: io_fx@yahoo.fr 00008 * 00009 * http://mp3splt.sourceforge.net/ 00010 * 00011 *********************************************************/ 00012 00013 /********************************************************** 00014 * 00015 * This program is free software; you can redistribute it and/or 00016 * modify it under the terms of the GNU General Public License 00017 * as published by the Free Software Foundation; either version 2 00018 * of the License, or (at your option) any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program; if not, write to the Free Software 00027 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00028 * USA. 00029 * 00030 *********************************************************/ 00031 00032 /*!******************************************************** 00033 * \file 00034 * 00035 * this file contains the code for the widgets helpers. 00036 ********************************************************/ 00037 00038 #include "widgets_helper.h" 00039 00040 static guint _wh_add_row_to_table(); 00041 static GtkWidget *_wh_put_in_new_hbox_with_margin(GtkWidget *widget, gint margin); 00042 static void _wh_attach_to_table(GtkWidget *table, GtkWidget *widget, 00043 guint start_column, guint end_column, guint row, int expand); 00044 static void _wh_add_in_table_with_label(GtkWidget *table, const gchar *label_text, 00045 GtkWidget *widget, int expand); 00046 00056 GtkWidget *wh_set_title_and_get_vbox(GtkWidget *widget, const gchar *title) 00057 { 00058 GtkWidget *vbox = gtk_vbox_new(FALSE, 0); 00059 00060 GtkWidget *label = gtk_label_new(NULL); 00061 gtk_label_set_markup(GTK_LABEL(label), title); 00062 00063 GtkWidget *label_hbox = gtk_hbox_new(FALSE, 0); 00064 gtk_box_pack_start(GTK_BOX(label_hbox), label, FALSE, FALSE, 0); 00065 gtk_box_pack_start(GTK_BOX(vbox), label_hbox, FALSE, FALSE, 5); 00066 00067 GtkWidget *hbox = gtk_hbox_new(FALSE, 0); 00068 gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 16); 00069 00070 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); 00071 00072 return vbox; 00073 } 00074 00075 GtkWidget *wh_new_table() 00076 { 00077 GtkWidget *table = gtk_table_new(1, 2, FALSE); 00078 gtk_table_set_col_spacing(GTK_TABLE(table), 0, 0); 00079 gtk_table_set_col_spacing(GTK_TABLE(table), 1, 5); 00080 return table; 00081 } 00082 00083 void wh_add_in_table(GtkWidget *table, GtkWidget *widget) 00084 { 00085 guint last_row = _wh_add_row_to_table(table); 00086 00087 _wh_attach_to_table(table, widget, 1, 3, last_row, TRUE); 00088 } 00089 00090 void wh_add_in_table_with_label_expand(GtkWidget *table, const gchar *label_text, GtkWidget *widget) 00091 { 00092 _wh_add_in_table_with_label(table, label_text, widget, TRUE); 00093 } 00094 00095 void wh_add_in_table_with_label(GtkWidget *table, const gchar *label_text, GtkWidget *widget) 00096 { 00097 _wh_add_in_table_with_label(table, label_text, widget, FALSE); 00098 } 00099 00100 GtkWidget *wh_put_in_new_hbox_with_margin_level(GtkWidget *widget, gint margin_level) 00101 { 00102 return _wh_put_in_new_hbox_with_margin(widget, 6 * margin_level); 00103 } 00104 00105 GtkWidget *wh_new_entry(void *callback) 00106 { 00107 GtkWidget *entry = gtk_entry_new(); 00108 gtk_editable_set_editable(GTK_EDITABLE(entry), TRUE); 00109 00110 if (callback) 00111 { 00112 g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(callback), NULL); 00113 } 00114 00115 return entry; 00116 } 00117 00118 GtkWidget *wh_new_button(const gchar *button_label) 00119 { 00120 return gtk_button_new_with_mnemonic(button_label); 00121 } 00122 00123 void wh_get_widget_size(GtkWidget *widget, gint *width, gint *height) 00124 { 00125 #if GTK_MAJOR_VERSION <= 2 00126 GtkAllocation allocation; 00127 gtk_widget_get_allocation(widget, &allocation); 00128 00129 if (width != NULL) 00130 { 00131 *width = allocation.width; 00132 } 00133 00134 if (height != NULL) 00135 { 00136 *height= allocation.height; 00137 } 00138 #else 00139 if (width != NULL) 00140 { 00141 *width = gtk_widget_get_allocated_width(widget); 00142 } 00143 00144 if (height != NULL) 00145 { 00146 *height = gtk_widget_get_allocated_height(widget); 00147 } 00148 #endif 00149 } 00150 00151 static void _wh_folder_changed_event(GtkFileChooser *chooser, gpointer data) 00152 { 00153 ui_state *ui = (ui_state *) data; 00154 ui_set_browser_directory(ui, gtk_file_chooser_get_current_folder(chooser)); 00155 } 00156 00157 void wh_set_browser_directory_handler(ui_state *ui, GtkWidget* dialog) 00158 { 00159 const gchar *browser_dir = ui_get_browser_directory(ui); 00160 if (browser_dir) 00161 { 00162 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), browser_dir); 00163 } 00164 00165 g_signal_connect(GTK_FILE_CHOOSER(dialog), "current-folder-changed", 00166 G_CALLBACK(_wh_folder_changed_event), ui); 00167 } 00168 00169 static guint _wh_add_row_to_table(GtkWidget *table) 00170 { 00171 guint rows; 00172 guint columns; 00173 00174 g_object_get(G_OBJECT(table), 00175 "n-rows", &rows, 00176 "n-columns", &columns, 00177 NULL); 00178 00179 guint new_rows = rows + 1; 00180 00181 gtk_table_resize(GTK_TABLE(table), new_rows, columns); 00182 gtk_table_set_row_spacing(GTK_TABLE(table), new_rows - 1, 4); 00183 00184 return new_rows; 00185 } 00186 00187 static GtkWidget *_wh_put_in_new_hbox_with_margin(GtkWidget *widget, gint margin) 00188 { 00189 GtkWidget *hbox = gtk_hbox_new(FALSE, 0); 00190 gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, margin); 00191 return hbox; 00192 } 00193 00194 static void _wh_add_in_table_with_label(GtkWidget *table, const gchar *label_text, 00195 GtkWidget *widget, int expand) 00196 { 00197 guint last_row = _wh_add_row_to_table(table); 00198 00199 GtkWidget *label = gtk_label_new(label_text); 00200 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); 00201 00202 _wh_attach_to_table(table, label, 1, 2, last_row, FALSE); 00203 _wh_attach_to_table(table, widget, 2, 3, last_row, expand); 00204 } 00205 00206 static void _wh_attach_to_table(GtkWidget *table, GtkWidget *widget, 00207 guint start_column, guint end_column, guint row, int expand) 00208 { 00209 GtkWidget *my_widget = widget; 00210 GtkWidget *hbox; 00211 00212 GtkAttachOptions xoptions = GTK_FILL; 00213 if (expand) 00214 { 00215 xoptions |= GTK_EXPAND; 00216 } 00217 else 00218 { 00219 hbox = gtk_hbox_new(FALSE, 0); 00220 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 0); 00221 my_widget = hbox; 00222 } 00223 00224 gtk_table_attach(GTK_TABLE(table), my_widget, 00225 start_column, end_column, row-1, row, 00226 xoptions, GTK_FILL | GTK_EXPAND, 00227 0, 0); 00228 } 00229