📄 buttons.cc
字号:
gint buttons_save_release(GtkButton *button,GdkEventButton *event,gint code){ if (event->button==3){ button->button_down=FALSE; GtkStateType new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL); if (GTK_WIDGET_STATE(button)!=new_state){ gtk_widget_set_state(GTK_WIDGET(button),new_state); gtk_widget_queue_draw(GTK_WIDGET(button)); }; switch (code){ case BUTTON_SAVE: save_list(); break; case BUTTON_OPTIONS: open_edit_for_selected(); break; }; return TRUE; }; return FALSE;};void buttons_progress_set_text(){ char data[10]; *data=0; sprintf(data,"%i ",CFG.PROGRESS_MODE>=2?1:CFG.PROGRESS_MODE+2); char *text=sum_strings(_(BUTTONS_TEXT[BUTTON_PROGRESS])," ",data,NULL); gtk_tooltips_set_tip(GTK_TOOLBAR(ButtonsBar)->tooltips, buttons_array[BUTTON_PROGRESS], text,(char*) NULL); gtk_image_set_from_pixmap(GTK_IMAGE(pixmaps_array[BUTTON_PROGRESS]), progress_pixmap[CFG.PROGRESS_MODE], progress_bitmap[CFG.PROGRESS_MODE]); delete[] text;};void buttons_progress_toggle(){ CFG.PROGRESS_MODE+=1; if (CFG.PROGRESS_MODE>2) CFG.PROGRESS_MODE=0; gtk_widget_queue_draw(D4X_QUEUE->qv.ListOfDownloads); buttons_progress_set_text();};static void bb_move_up(){ D4X_QUEUE->qv.move_up();};static void bb_move_down(){ D4X_QUEUE->qv.move_down();};static void bb_open_logs(){ D4X_QUEUE->qv.open_logs();};static void bb_reinit_progress_pixs(){#include "pixmaps/percent1.xpm"#include "pixmaps/percent2.xpm"#include "pixmaps/percent3.xpm" for (int i=0;i<3;i++){ if (progress_pixmap[i]) gdk_pixmap_unref(progress_pixmap[i]); if (progress_bitmap[i]) gdk_bitmap_unref(progress_bitmap[i]); }; if (bb_new_pixmap_from_theme("progress1",&progress_pixmap[0],&progress_bitmap[0])) progress_pixmap[0]=make_pixmap_from_xpm(&progress_bitmap[0],percent1_xpm,MainWindow); if (bb_new_pixmap_from_theme("progress2",&progress_pixmap[1],&progress_bitmap[1])) progress_pixmap[1]=make_pixmap_from_xpm(&progress_bitmap[1],percent2_xpm,MainWindow); if (bb_new_pixmap_from_theme("progress3",&progress_pixmap[2],&progress_bitmap[2])) progress_pixmap[2]=make_pixmap_from_xpm(&progress_bitmap[2],percent3_xpm,MainWindow);};static void bb_button_change_pix(GtkWidget *pix,char *themename,char **xpm){ GdkBitmap *mask; GdkPixmap *pixmap; if (bb_new_pixmap_from_theme(themename,&pixmap,&mask)==0){ gtk_image_set_from_pixmap(GTK_IMAGE(pix),pixmap,mask); }else{ pixmap=make_pixmap_from_xpm(&mask,xpm,MainWindow); gtk_image_set_from_pixmap(GTK_IMAGE(pix),pixmap,mask); }; gdk_pixmap_unref(pixmap); gdk_bitmap_unref(mask);};void bb_theme_changed(){#include "pixmaps/add.xpm"#include "pixmaps/add_clipboard.xpm"#include "pixmaps/del.xpm"#include "pixmaps/stop_bar.xpm"#include "pixmaps/continue.xpm"#include "pixmaps/del_com.xpm"#include "pixmaps/prefs.xpm"#include "pixmaps/openlog.xpm"#include "pixmaps/del_all.xpm"#include "pixmaps/up_bar.xpm"#include "pixmaps/down_bar.xpm"#include "pixmaps/speed1.xpm"#include "pixmaps/speed2.xpm"#include "pixmaps/speed3.xpm"#include "pixmaps/save.xpm"#include "pixmaps/dndtrash_bar.xpm"#include "pixmaps/load.xpm" bb_button_change_pix(pixmaps_array[BUTTON_ADD],"add",add_xpm); bb_button_change_pix(pixmaps_array[BUTTON_ADD_CLIPBOARD],"clipboardadd",add_clipboard_xpm); bb_button_change_pix(pixmaps_array[BUTTON_DEL],"del",del_xpm); bb_button_change_pix(pixmaps_array[BUTTON_STOP],"stop",stop_bar_xpm); bb_button_change_pix(pixmaps_array[BUTTON_CONTINUE],"continue",continue_xpm); bb_button_change_pix(pixmaps_array[BUTTON_DEL_COMPLETED],"delcompleted",del_com_xpm); bb_button_change_pix(pixmaps_array[BUTTON_UP],"moveup",up_bar_xpm); bb_button_change_pix(pixmaps_array[BUTTON_DOWN],"movedown",down_bar_xpm); bb_button_change_pix(pixmaps_array[BUTTON_LOG],"openlog",openlog_xpm); bb_button_change_pix(pixmaps_array[BUTTON_SPEED1],"speedlow",speed1_xpm); bb_button_change_pix(pixmaps_array[BUTTON_SPEED2],"speedmedium",speed2_xpm); bb_button_change_pix(pixmaps_array[BUTTON_SPEED3],"speedhigh",speed3_xpm); bb_button_change_pix(pixmaps_array[BUTTON_OPTIONS],"preferences",prefs_xpm); bb_button_change_pix(pixmaps_array[BUTTON_LOAD],"load",load_xpm); bb_button_change_pix(pixmaps_array[BUTTON_SAVE],"save",save_xpm); bb_button_change_pix(pixmaps_array[BUTTON_DND_TRASH],"dnd",dndtrash_bar_xpm); bb_button_change_pix(pixmaps_array[BUTTON_DEL_ALL],"clearlist",del_all_xpm); bb_reinit_progress_pixs(); buttons_progress_set_text();};void init_buttons_bar() {#include "pixmaps/add.xpm"#include "pixmaps/add_clipboard.xpm"#include "pixmaps/del.xpm"#include "pixmaps/stop_bar.xpm"#include "pixmaps/continue.xpm"#include "pixmaps/del_com.xpm"#include "pixmaps/prefs.xpm"#include "pixmaps/openlog.xpm"#include "pixmaps/del_all.xpm"#include "pixmaps/up_bar.xpm"#include "pixmaps/down_bar.xpm"#include "pixmaps/speed1.xpm"#include "pixmaps/speed2.xpm"#include "pixmaps/speed3.xpm"#include "pixmaps/save.xpm"#include "pixmaps/dndtrash_bar.xpm"#include "pixmaps/cfgbt.xpm"#include "pixmaps/load.xpm" bb_reinit_progress_pixs(); ButtonsBar=gtk_toolbar_new (); gtk_toolbar_set_orientation(GTK_TOOLBAR(ButtonsBar),GTK_ORIENTATION_HORIZONTAL); gtk_toolbar_set_style(GTK_TOOLBAR(ButtonsBar),GTK_TOOLBAR_ICONS); gtk_container_set_border_width(GTK_CONTAINER(ButtonsBar),0);// gtk_toolbar_set_space_style(GTK_TOOLBAR(ButtonsBar), GTK_TOOLBAR_SPACE_LINE);// gtk_toolbar_set_button_relief(GTK_TOOLBAR(ButtonsBar), GTK_RELIEF_NONE); pixmaps_array[BUTTON_ADD]=new_pixmap(add_xpm,"add"); buttons_array[BUTTON_ADD]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "", _(BUTTONS_TEXT[BUTTON_ADD]),"",pixmaps_array[BUTTON_ADD], G_CALLBACK (init_add_window), NULL); pixmaps_array[BUTTON_ADD_CLIPBOARD]=new_pixmap(add_clipboard_xpm,"clipboardadd"); buttons_array[BUTTON_ADD_CLIPBOARD]=gtk_toolbar_append_item(GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_ADD_CLIPBOARD]),"",pixmaps_array[BUTTON_ADD_CLIPBOARD], G_CALLBACK (init_add_clipboard_window), NULL); pixmaps_array[BUTTON_DEL]=new_pixmap(del_xpm,"del"); buttons_array[BUTTON_DEL]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_DEL]), "",pixmaps_array[BUTTON_DEL], G_CALLBACK (ask_delete_download), NULL); gtk_toolbar_append_space (GTK_TOOLBAR (ButtonsBar)); pixmaps_array[BUTTON_CONTINUE]=new_pixmap(continue_xpm,"continue"); buttons_array[BUTTON_CONTINUE]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_CONTINUE]), "", pixmaps_array[BUTTON_CONTINUE], G_CALLBACK (continue_downloads), NULL); pixmaps_array[BUTTON_STOP]=new_pixmap(stop_bar_xpm,"stop"); buttons_array[BUTTON_STOP]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_STOP]) , "", pixmaps_array[BUTTON_STOP], G_CALLBACK (stop_downloads), NULL); pixmaps_array[BUTTON_DEL_COMPLETED]=new_pixmap(del_com_xpm,"delcompleted"); buttons_array[BUTTON_DEL_COMPLETED]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_DEL_COMPLETED]) , "", pixmaps_array[BUTTON_DEL_COMPLETED], G_CALLBACK (ask_delete_completed_downloads), NULL); pixmaps_array[BUTTON_UP]=new_pixmap(up_bar_xpm,"moveup"); buttons_array[BUTTON_UP]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_UP]),"",pixmaps_array[BUTTON_UP], G_CALLBACK (bb_move_up), NULL); pixmaps_array[BUTTON_DOWN]=new_pixmap(down_bar_xpm,"movedown"); buttons_array[BUTTON_DOWN]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_DOWN]) , "", pixmaps_array[BUTTON_DOWN], G_CALLBACK (bb_move_down), NULL); pixmaps_array[BUTTON_LOG]=new_pixmap(openlog_xpm,"openlog"); buttons_array[BUTTON_LOG]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_LOG]) , "", pixmaps_array[BUTTON_LOG], G_CALLBACK (bb_open_logs), NULL); gtk_toolbar_append_space (GTK_TOOLBAR (ButtonsBar)); pixmaps_array[BUTTON_OPTIONS]=new_pixmap(prefs_xpm,"preferences"); buttons_array[BUTTON_OPTIONS]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_OPTIONS]),"",pixmaps_array[BUTTON_OPTIONS], G_CALLBACK (d4x_prefs_init), NULL); gtk_toolbar_append_space (GTK_TOOLBAR (ButtonsBar)); pixmaps_array[BUTTON_SPEED1]=new_pixmap(speed1_xpm,"speedlow"); buttons_array[BUTTON_SPEED1]=gtk_toolbar_append_element (GTK_TOOLBAR (ButtonsBar), GTK_TOOLBAR_CHILD_RADIOBUTTON, (GtkWidget *)NULL, "", _(BUTTONS_TEXT[BUTTON_SPEED1]), "", pixmaps_array[BUTTON_SPEED1], G_CALLBACK (set_speed_limit), (GtkWidget *)NULL); pixmaps_array[BUTTON_SPEED2]=new_pixmap(speed2_xpm,"speedmedium"); buttons_array[BUTTON_SPEED2]=gtk_toolbar_append_element (GTK_TOOLBAR (ButtonsBar), GTK_TOOLBAR_CHILD_RADIOBUTTON, buttons_array[BUTTON_SPEED1], "", _(BUTTONS_TEXT[BUTTON_SPEED2]), "", pixmaps_array[BUTTON_SPEED2], G_CALLBACK (set_speed_limit), (GtkWidget *)NULL); pixmaps_array[BUTTON_SPEED3]=new_pixmap(speed3_xpm,"speedhigh"); buttons_array[BUTTON_SPEED3]=gtk_toolbar_append_element (GTK_TOOLBAR (ButtonsBar), GTK_TOOLBAR_CHILD_RADIOBUTTON, buttons_array[BUTTON_SPEED2], "", _(BUTTONS_TEXT[BUTTON_SPEED3]), "", pixmaps_array[BUTTON_SPEED3], G_CALLBACK (set_speed_limit), (GtkWidget *)NULL); gtk_toolbar_append_space (GTK_TOOLBAR (ButtonsBar)); pixmaps_array[BUTTON_DEL_ALL]=new_pixmap(del_all_xpm,"clearlist"); buttons_array[BUTTON_DEL_ALL]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_DEL_ALL]),"",pixmaps_array[BUTTON_DEL_ALL], G_CALLBACK (ask_delete_all), NULL); pixmaps_array[BUTTON_SAVE]=new_pixmap(save_xpm,"save"); buttons_array[BUTTON_SAVE]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_SAVE]) , "", pixmaps_array[BUTTON_SAVE], G_CALLBACK (init_save_list), NULL); pixmaps_array[BUTTON_LOAD]=new_pixmap(load_xpm,"load"); buttons_array[BUTTON_LOAD]=gtk_toolbar_append_item(GTK_TOOLBAR (ButtonsBar), "",_(BUTTONS_TEXT[BUTTON_LOAD]) , "",pixmaps_array[BUTTON_LOAD], G_CALLBACK (init_load_list),NULL); pixmaps_array[BUTTON_PROGRESS]=gtk_image_new_from_pixmap(progress_pixmap[0],progress_bitmap[0]); buttons_array[BUTTON_PROGRESS]=gtk_toolbar_append_item (GTK_TOOLBAR (ButtonsBar), "", _(BUTTONS_TEXT[BUTTON_PROGRESS]), "", pixmaps_array[BUTTON_PROGRESS], G_CALLBACK (buttons_progress_toggle), NULL); pixmaps_array[BUTTON_DND_TRASH]=new_pixmap (dndtrash_bar_xpm,"dnd"); buttons_array[BUTTON_DND_TRASH]=gtk_toolbar_append_element (GTK_TOOLBAR (ButtonsBar), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, (GtkWidget *)NULL, "", _(BUTTONS_TEXT[BUTTON_DND_TRASH]), "", pixmaps_array[BUTTON_DND_TRASH], G_CALLBACK (dnd_trash_toggle), (GtkWidget *)NULL); buttons_array[BUTTON_CONFIGURE] = gtk_button_new (); gtk_button_set_relief (GTK_BUTTON (buttons_array[BUTTON_CONFIGURE]), GTK_RELIEF_NONE); GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(buttons_array[BUTTON_CONFIGURE]), GTK_CAN_FOCUS); gtk_container_add(GTK_CONTAINER(buttons_array[BUTTON_CONFIGURE]),new_pixmap (cfgbt_xpm,NULL)); gtk_widget_show_all(buttons_array[BUTTON_CONFIGURE]); gtk_toolbar_append_widget(GTK_TOOLBAR (ButtonsBar), buttons_array[BUTTON_CONFIGURE], _(BUTTONS_TEXT[BUTTON_CONFIGURE]), ""); g_signal_connect(G_OBJECT(buttons_array[BUTTON_CONFIGURE]), "clicked",G_CALLBACK(buttons_configure), NULL); g_signal_connect(G_OBJECT (buttons_array[BUTTON_SAVE]), "button_press_event", G_CALLBACK (buttons_save_press), GINT_TO_POINTER(BUTTON_SAVE)); g_signal_connect(G_OBJECT (buttons_array[BUTTON_SAVE]), "button_release_event", G_CALLBACK (buttons_save_release),GINT_TO_POINTER(BUTTON_SAVE)); g_signal_connect(G_OBJECT (buttons_array[BUTTON_OPTIONS]), "button_press_event", G_CALLBACK (buttons_save_press), GINT_TO_POINTER(BUTTON_OPTIONS)); g_signal_connect(G_OBJECT (buttons_array[BUTTON_OPTIONS]), "button_release_event", G_CALLBACK (buttons_save_release),GINT_TO_POINTER(BUTTON_OPTIONS)); set_speed_buttons(); set_dndtrash_button(); GtkTooltips *tooltips=((GtkToolbar *)(ButtonsBar))->tooltips; gtk_tooltips_force_window(tooltips); GtkStyle *current_style =gtk_style_copy(gtk_widget_get_style(tooltips->tip_window)); char *tcolor=d4x_xml_find_obj_value(D4X_THEME_DATA,"buttonsbar tipcolor"); if (tcolor){ gdk_color_parse(tcolor,&(current_style->bg[GTK_STATE_NORMAL])); }else{ current_style->bg[GTK_STATE_NORMAL] = LYELLOW; }; gtk_widget_set_style(tooltips->tip_window, current_style); gtk_widget_show(ButtonsBar); buttons_speed_set_text(); buttons_progress_set_text(); buttons_cfg_init();};void buttons_theme_changed(){ GtkTooltips *tooltips=((GtkToolbar *)(ButtonsBar))->tooltips; GtkStyle *current_style =gtk_style_copy(gtk_widget_get_style(tooltips->tip_window)); char *tcolor=d4x_xml_find_obj_value(D4X_THEME_DATA,"buttonsbar tipcolor"); if (tcolor){ gdk_color_parse(tcolor,&(current_style->bg[GTK_STATE_NORMAL])); }else{ current_style->bg[GTK_STATE_NORMAL] = LYELLOW; }; gtk_widget_set_style(tooltips->tip_window, current_style);};void buttons_cfg_init(){ buttons_flags_init();};void prepare_buttons() { if (!D4X_QUEUE) return; if (D4X_QUEUE->count()) gtk_widget_set_sensitive(buttons_array[BUTTON_DEL_ALL],TRUE); else gtk_widget_set_sensitive(buttons_array[BUTTON_DEL_ALL],FALSE); if (D4X_QUEUE->qv.last_selected==NULL) { gtk_widget_set_sensitive(buttons_array[BUTTON_DEL],FALSE); gtk_widget_set_sensitive(buttons_array[BUTTON_STOP],FALSE); gtk_widget_set_sensitive(buttons_array[BUTTON_CONTINUE],FALSE); gtk_widget_set_sensitive(buttons_array[BUTTON_LOG],FALSE); gtk_widget_set_sensitive(buttons_array[BUTTON_UP],FALSE); gtk_widget_set_sensitive(buttons_array[BUTTON_DOWN],FALSE); } else { gtk_widget_set_sensitive(buttons_array[BUTTON_DEL],TRUE); gtk_widget_set_sensitive(buttons_array[BUTTON_STOP],TRUE); gtk_widget_set_sensitive(buttons_array[BUTTON_CONTINUE],TRUE); gtk_widget_set_sensitive(buttons_array[BUTTON_LOG],TRUE); gtk_widget_set_sensitive(buttons_array[BUTTON_UP],TRUE); gtk_widget_set_sensitive(buttons_array[BUTTON_DOWN],TRUE); };};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -