diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index 0d7768f21..b8132ae0c 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -70,6 +70,7 @@ tr_prefs_init_global( void ) pref_int_set_default ( PREF_KEY_MAIN_WINDOW_WIDTH, 300 ); pref_int_set_default ( PREF_KEY_MAIN_WINDOW_X, 50 ); pref_int_set_default ( PREF_KEY_MAIN_WINDOW_Y, 50 ); + pref_string_set_default ( PREF_KEY_MAIN_WINDOW_LAYOUT_ORDER, "menu,toolbar,filter,list,statusbar" ); str = NULL; #if GLIB_CHECK_VERSION( 2, 14, 0 ) diff --git a/gtk/tr-prefs.h b/gtk/tr-prefs.h index 1496d5009..b3b2a0d11 100644 --- a/gtk/tr-prefs.h +++ b/gtk/tr-prefs.h @@ -21,33 +21,33 @@ GtkWidget * tr_prefs_dialog_new( GObject * core, /* if you add a key here, you /must/ add its * default in tr_prefs_init_global( void ) */ -#define PREF_KEY_SCHED_LIMIT_ENABLED "sched-limit-enabled" -#define PREF_KEY_SCHED_BEGIN "sched-begin" -#define PREF_KEY_SCHED_END "sched-end" -#define PREF_KEY_SCHED_DL_LIMIT "sched-download-limit" -#define PREF_KEY_SCHED_UL_LIMIT "sched-upload-limit" -#define PREF_KEY_OPTIONS_PROMPT "show-options-window" -#define PREF_KEY_OPEN_DIALOG_FOLDER "open-dialog-dir" -#define PREF_KEY_INHIBIT_HIBERNATION "inhibit-desktop-hibernation" -#define PREF_KEY_DIR_WATCH "watch-dir" -#define PREF_KEY_DIR_WATCH_ENABLED "watch-dir-enabled" -#define PREF_KEY_SHOW_TRAY_ICON "show-notification-area-icon" -#define PREF_KEY_START "start-added-torrents" -#define PREF_KEY_TRASH_ORIGINAL "trash-original-torrent-files" -#define PREF_KEY_ASKQUIT "prompt-before-exit" -#define PREF_KEY_SORT_MODE "sort-mode" -#define PREF_KEY_SORT_REVERSED "sort-reversed" -#define PREF_KEY_MINIMAL_VIEW "minimal-view" -#define PREF_KEY_FILTERBAR "show-filterbar" -#define PREF_KEY_STATUSBAR "show-statusbar" -#define PREF_KEY_STATUSBAR_STATS "statusbar-stats" -#define PREF_KEY_TOOLBAR "show-toolbar" +#define PREF_KEY_SCHED_LIMIT_ENABLED "sched-limit-enabled" +#define PREF_KEY_SCHED_BEGIN "sched-begin" +#define PREF_KEY_SCHED_END "sched-end" +#define PREF_KEY_SCHED_DL_LIMIT "sched-download-limit" +#define PREF_KEY_SCHED_UL_LIMIT "sched-upload-limit" +#define PREF_KEY_OPTIONS_PROMPT "show-options-window" +#define PREF_KEY_OPEN_DIALOG_FOLDER "open-dialog-dir" +#define PREF_KEY_INHIBIT_HIBERNATION "inhibit-desktop-hibernation" +#define PREF_KEY_DIR_WATCH "watch-dir" +#define PREF_KEY_DIR_WATCH_ENABLED "watch-dir-enabled" +#define PREF_KEY_SHOW_TRAY_ICON "show-notification-area-icon" +#define PREF_KEY_START "start-added-torrents" +#define PREF_KEY_TRASH_ORIGINAL "trash-original-torrent-files" +#define PREF_KEY_ASKQUIT "prompt-before-exit" +#define PREF_KEY_SORT_MODE "sort-mode" +#define PREF_KEY_SORT_REVERSED "sort-reversed" +#define PREF_KEY_MINIMAL_VIEW "minimal-view" +#define PREF_KEY_FILTERBAR "show-filterbar" +#define PREF_KEY_STATUSBAR "show-statusbar" +#define PREF_KEY_STATUSBAR_STATS "statusbar-stats" +#define PREF_KEY_TOOLBAR "show-toolbar" #define PREF_KEY_BLOCKLIST_UPDATES_ENABLED "blocklist-updates-enabled" -#define PREF_KEY_MAIN_WINDOW_HEIGHT "main-window-height" -#define PREF_KEY_MAIN_WINDOW_WIDTH "main-window-width" -#define PREF_KEY_MAIN_WINDOW_X "main-window-x" -#define PREF_KEY_MAIN_WINDOW_Y "main-window-y" - +#define PREF_KEY_MAIN_WINDOW_LAYOUT_ORDER "main-window-layout-order" +#define PREF_KEY_MAIN_WINDOW_HEIGHT "main-window-height" +#define PREF_KEY_MAIN_WINDOW_WIDTH "main-window-width" +#define PREF_KEY_MAIN_WINDOW_X "main-window-x" +#define PREF_KEY_MAIN_WINDOW_Y "main-window-y" void tr_prefs_init_global( void ); diff --git a/gtk/tr-window.c b/gtk/tr-window.c index b8e05b506..be69f2bf5 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -498,16 +498,17 @@ onAskTrackerQueryTooltip( GtkWidget * widget UNUSED, ***/ GtkWidget * -tr_window_new( GtkUIManager * ui_manager, - TrCore * core ) +tr_window_new( GtkUIManager * ui_mgr, TrCore * core ) { int i, n; const char * pch; PrivateData * p; + GtkWidget *mainmenu, *toolbar, *filter, *list, *status; GtkWidget * vbox, *w, *self, *h, *c, *s, *image, *menu; GtkWindow * win; GSList * l; GSList * toggles; + const char * filter_names[FILTER_MODE_QTY] = { /* show all torrents */ N_( "A_ll" ), @@ -537,20 +538,18 @@ tr_window_new( GtkUIManager * ui_manager, gtk_window_set_title( win, g_get_application_name( ) ); gtk_window_set_role( win, "tr-main" ); gtk_window_set_default_size( win, - pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ), - pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) ); + pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ), + pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) ); gtk_window_move( win, pref_int_get( PREF_KEY_MAIN_WINDOW_X ), - pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) ); - gtk_window_add_accel_group( win, - gtk_ui_manager_get_accel_group( ui_manager ) ); + pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) ); + gtk_window_add_accel_group( win, gtk_ui_manager_get_accel_group( ui_mgr ) ); /* window's main container */ vbox = gtk_vbox_new ( FALSE, 0 ); gtk_container_add ( GTK_CONTAINER( self ), vbox ); /* main menu */ - w = action_get_widget( "/main-window-menu" ); - gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 ); + w = mainmenu = action_get_widget( "/main-window-menu" ); w = action_get_widget( "/main-window-menu/torrent-menu/update-tracker" ); #if GTK_CHECK_VERSION( 2, 12, 0 ) g_signal_connect( w, "query-tooltip", @@ -558,12 +557,11 @@ tr_window_new( GtkUIManager * ui_manager, #endif /* toolbar */ - w = p->toolbar = action_get_widget( "/main-window-toolbar" ); - gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 ); + w = toolbar = p->toolbar = action_get_widget( "/main-window-toolbar" ); /* filter */ toggles = NULL; - h = p->filter = gtk_hbox_new( FALSE, 0 ); + h = filter = p->filter = gtk_hbox_new( FALSE, 0 ); gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL ); for( i = 0; i < FILTER_MODE_QTY; ++i ) { @@ -590,7 +588,6 @@ tr_window_new( GtkUIManager * ui_manager, s ), SEXY_ICON_ENTRY_PRIMARY, TRUE ); gtk_box_pack_end( GTK_BOX( h ), s, FALSE, FALSE, 0 ); - gtk_box_pack_start( GTK_BOX( vbox ), h, FALSE, FALSE, 0 ); g_signal_connect( s, "changed", G_CALLBACK( filter_entry_changed ), p ); /* status menu */ @@ -614,7 +611,7 @@ tr_window_new( GtkUIManager * ui_manager, } /* status */ - h = p->status = gtk_hbox_new( FALSE, GUI_PAD ); + h = status = p->status = gtk_hbox_new( FALSE, GUI_PAD ); gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD ); w = p->gutter_lb = gtk_label_new( "N Torrents" ); gtk_box_pack_start( GTK_BOX( h ), w, 0, 0, 0 ); @@ -641,7 +638,6 @@ tr_window_new( GtkUIManager * ui_manager, gtk_box_pack_end( GTK_BOX( h ), w, FALSE, FALSE, 0 ); g_signal_connect( w, "button-release-event", G_CALLBACK( onYinYangReleased ), p ); - gtk_box_pack_start( GTK_BOX( vbox ), h, FALSE, FALSE, 0 ); menu = gtk_menu_new( ); l = NULL; @@ -650,27 +646,46 @@ tr_window_new( GtkUIManager * ui_manager, const char * name = _( filter_text_names[i] ); GtkWidget * w = gtk_radio_menu_item_new_with_label ( l, name ); l = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM( w ) ); - g_object_set_data( G_OBJECT( - w ), FILTER_TEXT_MODE_KEY, GINT_TO_POINTER( i ) ); - g_signal_connect( w, "toggled", G_CALLBACK( - filter_text_toggled_cb ), p ); + g_object_set_data( G_OBJECT( w ), FILTER_TEXT_MODE_KEY, + GINT_TO_POINTER( i ) ); + g_signal_connect( w, "toggled", + G_CALLBACK( filter_text_toggled_cb ), p ); gtk_menu_shell_append( GTK_MENU_SHELL( menu ), w ); gtk_widget_show( w ); } - g_signal_connect( s, "icon-released", G_CALLBACK( - entry_icon_released ), menu ); + g_signal_connect( s, "icon-released", + G_CALLBACK( entry_icon_released ), menu ); /* workarea */ p->view = makeview( p, core ); - w = p->scroll = gtk_scrolled_window_new( NULL, NULL ); + w = list = p->scroll = gtk_scrolled_window_new( NULL, NULL ); gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( w ), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC ); + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC ); gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( w ), GTK_SHADOW_IN ); gtk_container_add( GTK_CONTAINER( w ), p->view ); - gtk_box_pack_start( GTK_BOX( vbox ), w, TRUE, TRUE, 0 ); - gtk_container_set_focus_child( GTK_CONTAINER( vbox ), w ); + + /* layout the widgets */ + { + const char * str = pref_string_get( PREF_KEY_MAIN_WINDOW_LAYOUT_ORDER ); + char ** tokens = g_strsplit( str, ",", -1 ); + for( i=0; tokens && tokens[i]; ++i ) + { + const char * key = tokens[i]; + + if( !strcmp( key, "menu" ) ) + gtk_box_pack_start( GTK_BOX( vbox ), mainmenu, FALSE, FALSE, 0 ); + else if( !strcmp( key, "toolbar" ) ) + gtk_box_pack_start( GTK_BOX( vbox ), toolbar, FALSE, FALSE, 0 ); + else if( !strcmp( key, "filter" ) ) + gtk_box_pack_start( GTK_BOX( vbox ), filter, FALSE, FALSE, 0 ); + else if( !strcmp( key, "list" ) ) + gtk_box_pack_start( GTK_BOX( vbox ), list, TRUE, TRUE, 0 ); + else if( !strcmp( key, "statusbar" ) ) + gtk_box_pack_start( GTK_BOX( vbox ), status, FALSE, FALSE, 0 ); + } + g_strfreev( tokens ); + } /* show all but the window */ gtk_widget_show_all( vbox );