mp3splt-gtk
main_win.c
Go to the documentation of this file.
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  * The main window
00035  *
00036  * main file that initialises the menubar, the toolbar, 
00037  * the tabs, about window, status error messages
00038  *
00039  *********************************************************/
00040 
00041 //we include the "config.h" file from the config options
00042 #ifdef HAVE_CONFIG_H
00043 #include "config.h"
00044 #else
00045 #define VERSION "0.7.1"
00046 #define PACKAGE_NAME "mp3splt-gtk"
00047 #endif
00048 
00049 #include <string.h>
00050 #include "export.h"
00051 
00052 #include <gtk/gtk.h>
00053 #include <glib/gi18n.h>
00054 #include <libmp3splt/mp3splt.h>
00055 #include <gdk/gdkkeysyms.h>
00056 
00057 #ifdef __WIN32__
00058 #include <windows.h>
00059 #include <shlwapi.h>
00060 #endif
00061 
00062 
00063 #include "util.h"
00064 #include "main_win.h"
00065 #include "mp3splt-gtk.h"
00066 #include "tree_tab.h"
00067 #include "split_files.h"
00068 #include "utilities.h"
00069 #include "preferences_tab.h"
00070 #include "freedb_tab.h"
00071 #include "special_split.h"
00072 #include "utilities.h"
00073 #include "player_tab.h"
00074 #include "player.h"
00075 #include "messages.h"
00076 #include "import.h"
00077 #include "preferences_manager.h"
00078 #include "player_tab.h"
00079 
00080 #include "ui_manager.h"
00081 
00082 //main window
00083 GtkWidget *window = NULL;
00084 GtkAccelGroup *window_accel_group = NULL;
00085 
00086 //status bar
00087 GtkWidget *status_bar;
00088 
00089 //if we are on the preferences tab, then TRUE
00090 gint preferences_tab = FALSE;
00091 
00092 //player box
00093 GtkWidget *player_box;
00094 
00095 //the split freedb button
00096 GtkWidget *split_freedb_button;
00097 
00098 //new window for the progress bar
00099 GtkWidget *percent_progress_bar;
00100 
00101 //filename and path for the file to split
00102 gchar *filename_to_split;
00103 gchar *filename_path_of_split;
00104 
00105 //if we are currently splitting
00106 gint we_are_splitting = FALSE;
00107 gint we_quit_main_program = FALSE;
00108 
00109 GtkWidget *player_vbox = NULL;
00110 
00111 //stop button to cancel the split
00112 GtkWidget *cancel_button = NULL;
00113 
00114 extern GtkWidget *mess_history_dialog;
00115 
00116 extern GtkWidget *da;
00117 extern GtkWidget *progress_bar;
00118 
00119 extern GArray *splitpoints;
00120 extern gint selected_id;
00121 extern splt_state *the_state;
00122 extern splt_freedb_results *search_results;
00123 extern GList *player_pref_list;
00124 extern GList *text_options_list;
00125 extern gchar **split_files;
00126 extern gint max_split_files;
00127 extern gint selected_player;
00128 extern silence_wave *silence_points;
00129 extern gint number_of_silence_points;
00130 
00131 extern ui_state *ui;
00132 
00133 GtkWidget *playlist_box = NULL;
00134 
00135 //close the window and exit button function
00136 void quit(GtkWidget *widget, gpointer   data)
00137 {
00138   save_preferences(NULL, NULL);
00139 
00140   if (we_are_splitting)
00141   {
00142     gint err = SPLT_OK;
00143     mp3splt_stop_split(the_state,&err);
00144     print_status_bar_confirmation(err);
00145 
00146     we_quit_main_program = TRUE;
00147     put_status_message(_(" info: stopping the split process before exiting"));
00148   }
00149 
00150   //quit the player: currently closes gstreamer
00151   if (player_is_running())
00152   {
00153     player_quit();
00154   }
00155 
00156   g_list_free(player_pref_list);
00157   g_list_free(text_options_list);
00158   g_array_free(splitpoints, TRUE);
00159 
00160   if (silence_points)
00161   {
00162     g_free(silence_points);
00163     silence_points = NULL;
00164     number_of_silence_points = 0;
00165   }
00166 
00167   gtk_main_quit();
00168 }
00169 
00170 void main_window_drag_data_received(GtkWidget *window,
00171     GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint
00172     info, guint time, gpointer user_data)
00173 {
00174   const gchar *received_data = (gchar *) gtk_selection_data_get_text(data);
00175 
00176   if (received_data != NULL)
00177   {
00178     gchar **drop_filenames = NULL;
00179     drop_filenames = g_strsplit(received_data, "\n", 0);
00180 
00181     gint current_index = 0;
00182     gchar *current_filename = drop_filenames[current_index];
00183     while (current_filename != NULL)
00184     {
00185       gchar *filename = NULL;
00186       if (strstr(current_filename, "file:") == current_filename)
00187       {
00188         filename = g_filename_from_uri(current_filename, NULL, NULL);
00189       }
00190       else
00191       {
00192         gint fname_malloc_size = strlen(current_filename) + 1;
00193         filename = g_malloc(sizeof(gchar) * fname_malloc_size);
00194         g_snprintf(filename, fname_malloc_size, "%s", current_filename);
00195       }
00196 
00197       remove_end_slash_n_r_from_filename(filename);
00198 
00199       if (is_filee(filename))
00200       {
00201         handle_import(filename);
00202       }
00203 
00204       if (filename)
00205       {
00206         g_free(filename);
00207         filename = NULL;
00208       }
00209 
00210       g_free(current_filename);
00211       current_index++;
00212       current_filename = drop_filenames[current_index];
00213     }
00214 
00215     if (drop_filenames)
00216     {
00217       g_free(drop_filenames);
00218       drop_filenames = NULL;
00219     }
00220   }
00221 }
00222 
00223 gboolean configure_window_callback(GtkWindow *window, GdkEvent *event, gpointer data)
00224 {
00225   ui_state *ui = (ui_state *)data;
00226 
00227   ui_set_main_win_position(ui, event->configure.x, event->configure.y); 
00228   ui_set_main_win_size(ui, event->configure.width, event->configure.height);
00229 
00230   return FALSE;
00231 }
00232 
00233 void initialize_window()
00234 {
00235   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00236 
00237   g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(configure_window_callback), ui);
00238 
00239   window_accel_group = gtk_accel_group_new();
00240   gtk_window_add_accel_group(GTK_WINDOW(window), window_accel_group);
00241  
00242   gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME" "VERSION);
00243   gtk_container_set_border_width (GTK_CONTAINER (window), 0);
00244 
00245   g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(quit), NULL);
00246   g_signal_connect(G_OBJECT(window), "drag-data-received",
00247       G_CALLBACK(main_window_drag_data_received), NULL);
00248   gtk_drag_dest_set(window, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
00249       drop_types, 3, GDK_ACTION_COPY | GDK_ACTION_MOVE);
00250  
00251   GString *Imagefile = g_string_new(PIXMAP_PATH);
00252   build_svg_path(Imagefile, "mp3splt-gtk_ico"ICON_EXT);
00253   GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(Imagefile->str, NULL);
00254   gtk_window_set_default_icon(pixbuf);
00255   g_string_free(Imagefile, TRUE);
00256 }
00257 
00258 void activate_url(GtkAboutDialog *about, const gchar *link, gpointer data)
00259 {
00260 #ifdef __WIN32__
00261   char default_browser[512] = { '\0' };
00262   DWORD dwType, dwSize = sizeof(default_browser) - 1;
00263 
00264   SHGetValue(HKEY_CURRENT_USER,
00265         TEXT("Software\\Clients\\StartMenuInternet"),
00266         TEXT(""),
00267         &dwType,
00268         default_browser,
00269         &dwSize);
00270 
00271   if (default_browser[0] != '\0')
00272   {
00273     SHGetValue(HKEY_LOCAL_MACHINE,
00274         TEXT("SOFTWARE\\Clients\\StartMenuInternet"),
00275         TEXT(""),
00276         &dwType,
00277         default_browser,
00278         &dwSize);
00279   }
00280 
00281   if (default_browser[0] != '\0')
00282   {
00283     char browser_exe[2048] = { '\0' };
00284     dwSize = sizeof(browser_exe) - 1;
00285 
00286     char browser_exe_registry[1024] = { '\0' };
00287     snprintf(browser_exe_registry, 1024,
00288         "SOFTWARE\\Clients\\StartMenuInternet\\%s\\shell\\open\\command\\",
00289         default_browser);
00290 
00291     SHGetValue(HKEY_LOCAL_MACHINE,
00292         TEXT(browser_exe_registry), TEXT(""),
00293         &dwType, browser_exe, &dwSize);
00294 
00295     if (browser_exe[0] != '\0')
00296     {
00297       gint browser_command_size = strlen(browser_exe) + strlen(link) + 2;
00298       char *browser_command = g_malloc(sizeof(char) * browser_command_size);
00299       if (browser_command)
00300       {
00301         snprintf(browser_command, browser_command_size, "%s %s",
00302             browser_exe, link);
00303 
00304         STARTUPINFO si;
00305         PROCESS_INFORMATION pinf;
00306         ZeroMemory(&si, sizeof(si));
00307         si.cb = sizeof(si);
00308         ZeroMemory(&pinf, sizeof(pinf));
00309 
00310         if (! CreateProcess(NULL, browser_command,
00311               NULL, NULL, FALSE, 0, NULL, NULL, &si, &pinf))
00312         {
00313           put_status_message(_("Error launching external command"));
00314         }
00315 
00316         CloseHandle(pinf.hProcess);
00317         CloseHandle(pinf.hThread);
00318 
00319         g_free(browser_command);
00320         browser_command = NULL;
00321       }
00322     }
00323   }
00324 #endif
00325 }
00326 
00327 void about_window(GtkWidget *widget, gpointer *data)
00328 {
00329   GtkWidget *dialog = gtk_about_dialog_new();
00330 
00331   //for the bitmap
00332   GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (PIXMAP_PATH"mp3splt-gtk.png",
00333       NULL);
00334   gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf);
00335   
00336   gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog), (gchar *)PACKAGE_NAME);
00337   gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), VERSION);
00338   gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
00339                                  PACKAGE_NAME" : Copyright © 2005-2011 Alexandru"
00340                                  " Munteanu \n mp3splt : Copyright © 2002-2005 Matteo Trotta");
00341 
00342   gchar *b1 = NULL;
00343   gchar b3[100] = { '\0' };
00344   b1 = (gchar *)_("using");
00345   gchar library_version[20] = { '\0' };
00346   mp3splt_get_version(library_version);
00347   g_snprintf(b3, 100, "-%s-\n%s libmp3splt %s",
00348              _("release of "MP3SPLT_GTK_DATE), b1, library_version);
00349   
00350   gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), b3);
00351   
00352   gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(dialog),
00353                                 "\n"
00354                                 "This program is free software; you can "
00355                                 "redistribute it and/or \n"
00356                                 "modify it under the terms of the GNU General Public License\n"
00357                                 "as published by the Free Software "
00358                                 "Foundation; either version 2\n"
00359                                 "of the License, or (at your option) "
00360                                 "any later version.\n\n"
00361                                 "This program is distributed in the "
00362                                 "hope that it will be useful,\n"
00363                                 "but WITHOUT ANY WARRANTY; without even "
00364                                 "the implied warranty of\n"
00365                                 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
00366                                 "GNU General Public License for more details.\n\n"
00367                                 "You should have received a copy of the GNU General Public License\n"
00368                                 "along with this program; if not, write "
00369                                 "to the Free Software\n"
00370                                 "Foundation, Inc., 59 Temple Place -"
00371                                 "Suite 330, Boston, MA  02111-1307, "
00372                                 "USA.");
00373 
00374   g_signal_connect(G_OBJECT(dialog), "activate-link", G_CALLBACK(activate_url), NULL);
00375 
00376   gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(dialog),
00377       "http://mp3splt.sourceforge.net");
00378   gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog),
00379       "http://mp3splt.sourceforge.net");
00380 
00381   gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(dialog),
00382       "Mario Blättermann <mariobl@gnome.org>");
00383 
00384   gtk_dialog_run(GTK_DIALOG(dialog));
00385   gtk_widget_destroy(dialog);
00386 }
00387 
00392 void remove_status_message()
00393 {
00394   guint status_id =
00395     gtk_statusbar_get_context_id(GTK_STATUSBAR(status_bar), "mess");
00396   gtk_statusbar_pop(GTK_STATUSBAR(status_bar), status_id);
00397 }
00398 
00406 void put_status_message(const gchar *text)
00407 {
00408   put_status_message_with_type(text, SPLT_MESSAGE_INFO);
00409 }
00410 
00420 void put_status_message_with_type(const gchar *text, splt_message_type mess_type)
00421 {
00422   if (mess_type == SPLT_MESSAGE_INFO)
00423   {
00424     guint status_id =
00425       gtk_statusbar_get_context_id(GTK_STATUSBAR(status_bar), "mess");
00426 
00427     gtk_statusbar_pop(GTK_STATUSBAR(status_bar), status_id);
00428     gtk_statusbar_push(GTK_STATUSBAR(status_bar), status_id, text);
00429   }
00430 
00431   put_message_in_history(text, mess_type);
00432 }
00433 
00435 void cancel_button_event(GtkWidget *widget, gpointer data)
00436 {
00437   gint err = SPLT_OK;
00438   mp3splt_stop_split(the_state,&err);
00439   print_status_bar_confirmation(err);
00440   
00441   if (widget != NULL)
00442   {
00443     gtk_widget_set_sensitive(widget, FALSE);
00444   }
00445   put_status_message(_(" info: stopping the split process.. please wait"));
00446 }
00447 
00449 void split_button_event(GtkWidget *widget, gpointer data)
00450 {
00451   //if we are not splitting
00452   if (!we_are_splitting)
00453   {
00454     mp3splt_set_int_option(the_state, SPLT_OPT_OUTPUT_FILENAMES,
00455         SPLT_OUTPUT_DEFAULT);
00456 
00457     gint err = SPLT_OK;
00458 
00459     put_options_from_preferences();
00460 
00461     //output format
00462     if (mp3splt_get_int_option(the_state, SPLT_OPT_SPLIT_MODE,&err)
00463         != SPLT_OPTION_NORMAL_MODE)
00464     {
00465       if (!get_checked_output_radio_box())
00466       {
00467         mp3splt_set_int_option(the_state, SPLT_OPT_OUTPUT_FILENAMES,
00468             SPLT_OUTPUT_FORMAT);
00469       }
00470     }
00471 
00472     filename_to_split = inputfilename_get();
00473 
00474     filename_path_of_split = outputdirectory_get();
00475 
00476     if (filename_path_of_split != NULL)
00477     {
00478       we_are_splitting = TRUE;
00479       create_thread(split_it, NULL, TRUE, NULL);
00480       gtk_widget_set_sensitive(GTK_WIDGET(cancel_button), TRUE);
00481     }
00482     else
00483     {
00484       put_status_message((gchar *)_(" error: no file selected"));
00485     }
00486   }
00487   else
00488   {
00489     put_status_message((gchar *)_(" error: split in progress..."));
00490   }
00491 }
00492 
00494 GtkWidget *create_toolbar()
00495 {
00496   GtkWidget *box = gtk_hbox_new(FALSE, 0);
00497   gtk_container_set_border_width(GTK_CONTAINER(box), 0);
00498   gtk_box_pack_start(GTK_BOX(box), 
00499       gtk_image_new_from_stock(GTK_STOCK_APPLY, GTK_ICON_SIZE_SMALL_TOOLBAR), 
00500       FALSE, FALSE, 0);
00501   gtk_box_pack_start(GTK_BOX(box), gtk_label_new(_("Split !")), FALSE, FALSE, 0);
00502 
00503   GtkWidget *split_button = gtk_button_new();
00504   gtk_container_add(GTK_CONTAINER(split_button), box);
00505   gtk_widget_set_tooltip_text(split_button,_("Split !"));
00506   gtk_container_set_border_width(GTK_CONTAINER(split_button), 0);
00507   gtk_button_set_relief(GTK_BUTTON(split_button), GTK_RELIEF_HALF);
00508 
00509   g_signal_connect(G_OBJECT(split_button), "clicked",
00510       G_CALLBACK(split_button_event), NULL);
00511 
00512   GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
00513   GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
00514 
00515   gtk_box_pack_start(GTK_BOX(hbox), split_button, TRUE, FALSE, 0);
00516   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
00517 
00518   return vbox;
00519 }
00520 
00522 void show_messages_history_dialog(GtkWidget *widget, gpointer data)
00523 {
00524   gtk_widget_show_all(GTK_WIDGET(mess_history_dialog));
00525 }
00526 
00527 #ifndef NO_GNOME
00528 void ShowHelp()
00529 {
00530   GError* gerror = NULL;
00531   gtk_show_uri(gdk_screen_get_default(), "ghelp:mp3splt-gtk",  gtk_get_current_event_time(), &gerror);
00532 }
00533 #endif
00534 
00535 static gchar *my_dgettext(const gchar *key, const gchar *domain)
00536 {
00537   return dgettext("mp3splt-gtk", key);
00538 }
00539 
00541 GtkWidget *create_menu_bar()
00542 {
00543   GtkWidget *menu_box = gtk_hbox_new(FALSE,0);
00544   
00545   static GtkActionEntry const entries[] = {
00546     //name, stock id,   label
00547     { "FileMenu", NULL, N_("_File") },  
00548     { "HelpMenu", NULL, N_("_Help") },
00549 
00550     //name, stock id, label, accelerator, tooltip
00551     { "Open", GTK_STOCK_OPEN, N_("_Open..."), "<Ctrl>O", N_("Open"),
00552       G_CALLBACK(browse_button_event) },
00553 
00554     { "Import", GTK_STOCK_FILE, N_("_Import splitpoints..."), "<Ctrl>I", N_("Import"),
00555       G_CALLBACK(import_event) },
00556     { "Export", GTK_STOCK_SAVE_AS, N_("_Export splitpoints..."), "<Ctrl>E", N_("Export"),
00557       G_CALLBACK(ChooseCueExportFile) },
00558 
00559     { "Split", GTK_STOCK_APPLY, N_("_Split !"), "<Ctrl>S", N_("Split"),
00560       G_CALLBACK(split_button_event) },
00561     { "Messages history", GTK_STOCK_INFO, N_("Messages _history"), "<Ctrl>H", N_("Messages history"),
00562       G_CALLBACK(show_messages_history_dialog) },
00563 
00564     { "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<Ctrl>Q", N_("Quit"),
00565       G_CALLBACK(quit) },
00566 
00567 #ifndef NO_GNOME
00568     { "Contents", GTK_STOCK_HELP, N_("_Contents"), "F1", N_("Contents"),
00569       G_CALLBACK(ShowHelp)},
00570 #endif
00571 
00572     { "About", GTK_STOCK_ABOUT, N_("_About"), "<Ctrl>A", N_("About"),
00573       G_CALLBACK(about_window)},
00574   };
00575 
00576   static const gchar *ui_info = 
00577     "<ui>"
00578     "  <menubar name='MenuBar'>"
00579     "    <menu action='FileMenu'>"
00580     "      <menuitem action='Open'/>"
00581     "      <separator/>"
00582     "      <menuitem action='Import'/>"
00583     "      <menuitem action='Export'/>"
00584     "      <separator/>"
00585     "      <menuitem action='Split'/>"
00586     "      <menuitem action='Messages history'/>"
00587     "      <separator/>"
00588     "      <menuitem action='Quit'/>"
00589     "    </menu>"
00590     "    <menu action='HelpMenu'>"
00591 #ifndef NO_GNOME
00592     "      <menuitem action='Contents'/>"
00593 #endif
00594     "      <menuitem action='About'/>"
00595     "    </menu>"
00596     "  </menubar>"
00597     "</ui>";
00598 
00599   GtkActionGroup *actions = gtk_action_group_new ("Actions");
00600 
00601   gtk_action_group_set_translation_domain(actions, "mp3splt-gtk");
00602   gtk_action_group_set_translate_func(actions,
00603                   (GtkTranslateFunc)my_dgettext, NULL, NULL);
00604 
00605   //adding the GtkActionEntry to GtkActionGroup
00606   gtk_action_group_add_actions (actions, entries, G_N_ELEMENTS(entries), NULL);
00607   GtkUIManager *ui = gtk_ui_manager_new ();
00608   //set action to the ui
00609   gtk_ui_manager_insert_action_group (ui, actions, 0);
00610   //set the actions to the window
00611   gtk_window_add_accel_group (GTK_WINDOW (window), 
00612                               gtk_ui_manager_get_accel_group (ui));
00613   //add ui from string
00614   gtk_ui_manager_add_ui_from_string(ui, ui_info, -1, NULL);
00615   
00616   //attach the menu
00617   gtk_box_pack_start (GTK_BOX (menu_box), 
00618                       gtk_ui_manager_get_widget(ui, "/MenuBar"),
00619                       FALSE, FALSE, 0);
00620   
00621   GtkWidget *toolbar = (GtkWidget *)create_toolbar();
00622   gtk_box_pack_start(GTK_BOX(menu_box), toolbar, TRUE, TRUE, 0);
00623   
00624   return menu_box;
00625 }
00626 
00634 GtkWidget *create_cool_button(gchar *stock_id, gchar *label_text,
00635     gint toggle_or_not)
00636 {
00637   GtkWidget *box;
00638   GtkWidget *label;
00639   GtkWidget *image;
00640   GtkWidget *button;
00641 
00642   box = gtk_hbox_new(FALSE, 0);
00643   gtk_container_set_border_width(GTK_CONTAINER (box), 2);
00644 
00645   image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_MENU);
00646   gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 3);
00647 
00648   if (label_text != NULL)
00649   {
00650     label = gtk_label_new (label_text);
00651     gtk_label_set_text_with_mnemonic(GTK_LABEL(label),label_text);
00652     gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 3);
00653   }
00654   
00655   if (toggle_or_not)
00656   {
00657     button = gtk_toggle_button_new();
00658   }
00659   else
00660   {
00661     button = gtk_button_new();
00662   }
00663  
00664   gtk_container_add(GTK_CONTAINER(button),box);
00665  
00666   return button;
00667 }
00668 
00670 GtkWidget *create_main_vbox()
00671 {
00672   //big ain box contailning all with statusbar
00673   GtkWidget *main_vbox;
00674   //used for pages
00675   GtkWidget *frame;
00676   //the tree view
00677   GtkTreeView *tree_view;
00678   //the main window tabbed notebook
00679   GtkWidget *notebook;
00680   /* label for the notebook */
00681   GtkWidget *notebook_label;
00682 
00683   /* main vertical box with statusbar */
00684   main_vbox = gtk_vbox_new (FALSE, 0);
00685   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 0);
00686 
00687   frame = (GtkWidget *)create_choose_file_frame();
00688   gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 0);
00689 
00690   /* tabbed notebook */
00691   notebook = gtk_notebook_new();
00692   gtk_box_pack_start (GTK_BOX (main_vbox), notebook, TRUE, TRUE, 0);
00693   gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
00694   gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
00695   gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
00696   gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
00697   
00698   //creating the tree view
00699   GtkWidget *splitpoints_vbox;
00700   splitpoints_vbox = gtk_vbox_new (FALSE, 0);
00701   gtk_container_set_border_width (GTK_CONTAINER (splitpoints_vbox), 0);
00702   tree_view = (GtkTreeView *)create_tree_view();
00703   frame = (GtkWidget *)create_choose_splitpoints_frame(tree_view);
00704   gtk_container_add(GTK_CONTAINER(splitpoints_vbox), frame);
00705   
00706   /* player page */
00707   player_vbox = gtk_vbox_new(FALSE,0);
00708   notebook_label = gtk_label_new((gchar *)_("Player"));
00709       
00710   //player control frame
00711   player_box = (GtkWidget *)create_player_control_frame(tree_view);
00712   gtk_box_pack_start(GTK_BOX(player_vbox), player_box, FALSE, FALSE, 0);
00713 
00714   //playlist control frame
00715   playlist_box = (GtkWidget *)create_player_playlist_frame();
00716 
00717   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), player_vbox,
00718       (GtkWidget *)notebook_label);
00719       
00720   /* splitpoints page */
00721   notebook_label = gtk_label_new((gchar *)_("Splitpoints"));
00722   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 
00723                            splitpoints_vbox,
00724                            (GtkWidget *)notebook_label);
00725 
00726   /* split files frame */
00727   GtkWidget *split_files_vbox;
00728   split_files_vbox = gtk_vbox_new (FALSE, 0);
00729   gtk_container_set_border_width (GTK_CONTAINER (split_files_vbox), 0);
00730   
00731   frame = (GtkWidget *)create_split_files();
00732   gtk_container_add(GTK_CONTAINER(split_files_vbox), frame);
00733 
00734   notebook_label = gtk_label_new((gchar *)_("Split files"));
00735   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 
00736                            split_files_vbox,
00737                            (GtkWidget *)notebook_label);
00738   
00739   /* freedb page */
00740   GtkWidget *freedb_vbox;
00741   freedb_vbox = gtk_vbox_new (FALSE, 0);
00742   gtk_container_set_border_width (GTK_CONTAINER (freedb_vbox), 0);
00743   
00744   frame = (GtkWidget *)create_freedb_frame();
00745   gtk_container_add(GTK_CONTAINER(freedb_vbox), frame);
00746   
00747   notebook_label = gtk_label_new((gchar *)_("FreeDB"));
00748   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 
00749                            freedb_vbox,
00750                            (GtkWidget *)notebook_label);
00751   
00752   /* special split page */
00753   GtkWidget *special_split_vbox;
00754   special_split_vbox = gtk_vbox_new (FALSE, 0);
00755   gtk_container_set_border_width (GTK_CONTAINER (special_split_vbox), 0);
00756   frame = (GtkWidget *)create_special_split_page();
00757   gtk_container_add(GTK_CONTAINER(special_split_vbox), frame);
00758   notebook_label = gtk_label_new(_("Type of split"));
00759   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 
00760                            special_split_vbox,
00761                            (GtkWidget *)notebook_label);
00762  
00763   /* preferences page */
00764   GtkWidget *preferences_vbox;
00765   preferences_vbox = gtk_vbox_new (FALSE, 0);
00766   gtk_container_set_border_width (GTK_CONTAINER (preferences_vbox), 0);
00767 
00768   frame = (GtkWidget *)create_choose_preferences();
00769   gtk_container_add(GTK_CONTAINER(preferences_vbox), frame);
00770 
00771   notebook_label = gtk_label_new((gchar *)_("Preferences"));
00772   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 
00773                            preferences_vbox,
00774                            (GtkWidget *)notebook_label);
00775   
00776   /* progress bar */
00777   percent_progress_bar = gtk_progress_bar_new();
00778   //we begin at 0
00779   gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(percent_progress_bar),
00780                                 0.0);
00781   //we write 0 on the bar
00782   gtk_progress_bar_set_text(GTK_PROGRESS_BAR(percent_progress_bar),
00783                             "");
00784   
00785   //hbox for progress bar and cancel button
00786   GtkWidget *hbox;
00787   hbox = gtk_hbox_new (FALSE,0);
00788   //we put the progress bar in the hbox
00789   gtk_box_pack_start(GTK_BOX(hbox), percent_progress_bar, TRUE, TRUE, 3);
00790   
00791   //stop button
00792   cancel_button = create_cool_button(GTK_STOCK_CANCEL,_("S_top"), FALSE);
00793   //action for the cancel button
00794   g_signal_connect(G_OBJECT(cancel_button), "clicked",
00795                    G_CALLBACK(cancel_button_event), NULL);
00796   
00797   //we put the stop button in the hbox
00798   gtk_box_pack_start(GTK_BOX(hbox), cancel_button, FALSE, TRUE, 3);
00799   gtk_widget_set_sensitive(GTK_WIDGET(cancel_button), FALSE);
00800   
00801   //we put progress bar hbox in the main box
00802   gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 3);  
00803 
00804   /* show messages history dialog */
00805   create_mess_history_dialog();
00806  
00807   /* statusbar */
00808   status_bar = gtk_statusbar_new();
00809 
00810   //TODO: gtk+ >= 3
00811   //gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status_bar), FALSE);
00812 
00813   GtkWidget *mess_history_button =
00814     create_cool_button(GTK_STOCK_INFO, NULL, FALSE);
00815   gtk_button_set_relief(GTK_BUTTON(mess_history_button), GTK_RELIEF_NONE);
00816   gtk_widget_set_tooltip_text(mess_history_button,_("Messages history"));
00817   gtk_box_pack_start(GTK_BOX(status_bar), mess_history_button, FALSE, FALSE, 0);
00818   g_signal_connect(G_OBJECT(mess_history_button), "clicked",
00819       G_CALLBACK(show_messages_history_dialog), NULL);
00820 
00821   gtk_box_pack_start(GTK_BOX(main_vbox), status_bar, FALSE, FALSE, 0);
00822 
00823   return main_vbox;
00824 }
00825 
00826 static void move_and_resize_main_window()
00827 {
00828   const ui_main_window *main_win = ui_get_main_window_infos(ui);
00829 
00830   gint x = main_win->root_x_pos;
00831   gint y = main_win->root_y_pos;
00832 
00833   if (x != 0 && y != 0)
00834   {
00835     gtk_window_move(GTK_WINDOW(window), x, y);
00836   }
00837   else
00838   {
00839     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
00840   }
00841 
00842   gtk_window_resize(GTK_WINDOW(window), main_win->width, main_win->height);
00843 }
00844 
00845 void create_all()
00846 {
00847 #ifdef __WIN32__
00848   set_language();
00849 #endif
00850 
00851   initialize_window();
00852  
00853   GtkWidget *window_vbox = gtk_vbox_new(FALSE, 0);
00854   gtk_container_add(GTK_CONTAINER(window), window_vbox);
00855 
00856   GtkWidget *menu_bar;
00857   menu_bar = (GtkWidget *)create_menu_bar();
00858   gtk_box_pack_start(GTK_BOX(window_vbox), menu_bar, FALSE, FALSE, 0);  
00859  
00860   GtkWidget *main_vbox = (GtkWidget *)create_main_vbox();
00861   gtk_box_pack_start(GTK_BOX(window_vbox), main_vbox, TRUE, TRUE, 0);
00862   
00863   load_preferences();
00864 
00865   if (selected_player == PLAYER_GSTREAMER)
00866   {
00867     hide_connect_button();
00868   }
00869 
00870   hide_disconnect_button();
00871   gtk_widget_hide(playlist_box);
00872 
00873   move_and_resize_main_window();
00874 
00875   gtk_widget_show_all(window);
00876 }
00877 
00882 void print_status_bar_confirmation(gint confirmation)
00883 {
00884   char *error_from_library = mp3splt_get_strerror(the_state, confirmation);
00885   if (error_from_library != NULL)
00886   {
00887     put_status_message(error_from_library);
00888     free(error_from_library);
00889     error_from_library = NULL;
00890   }
00891 }