📄 fsched.cc
字号:
/*********************/ d4xSchedAction *action=(d4xSchedAction *)NULL; switch(editor->last_action){ case SACT_SET_SPEED:{ d4xSASpeed *act=new d4xSASpeed; action=act; if (GTK_TOGGLE_BUTTON(editor->sb_low)->active) act->speed=1; else{ act->speed=GTK_TOGGLE_BUTTON(editor->sb_middle)->active?2:3; }; break; }; case SACT_POPUP_WINDOW:{ d4xSAPopup *act=new d4xSAPopup; action=act; break; }; case SACT_EXIT:{ d4xSAExit *act=new d4xSAExit; action=act; break; }; case SACT_DEL_COMPLETED:{ d4xSADelCompleted *act=new d4xSADelCompleted; action=act; break; }; case SACT_DEL_FAILED:{ d4xSADelFailed *act=new d4xSADelFailed; action=act; break; }; case SACT_RUN_DOWNLOAD:{ d4xSARunDownload *act=new d4xSARunDownload; act->url=new tAddr(text_from_combo(editor->url_entry)); action=act; break; }; case SACT_PAUSE_DOWNLOAD:{ d4xSAStopDownload *act=new d4xSAStopDownload; act->url=new tAddr(text_from_combo(editor->url_entry)); action=act; break; }; case SACT_DELETE_DOWNLOAD:{ d4xSADelDownload *act=new d4xSADelDownload; act->url=new tAddr(text_from_combo(editor->url_entry)); action=act; break; }; case SACT_SAVE_LIST:{ d4xSASaveList *act=new d4xSASaveList; act->path.set(text_from_combo(editor->path_entry)); action=act; break; }; case SACT_EXECUTE:{ d4xSAExecute *act=new d4xSAExecute; act->command.set(text_from_combo(editor->path_entry)); action=act; break; }; case SACT_ADD_DOWNLOAD:{ d4xSAAddDownload *act=new d4xSAAddDownload; if (act->dwn) delete(act->dwn); if (editor->dwn==NULL){ editor->dwn=new tDownload; editor->dwn->config=new tCfg; editor->dwn->set_default_cfg(); editor->dwn->config->save_path.set(CFG.GLOBAL_SAVE_PATH); editor->dwn->info=new tAddr(text_from_combo(editor->url_entry)); }; act->dwn=editor->dwn; editor->dwn=(tDownload*)NULL; action=act; break; }; case SACT_DEL_IF_COMPLETED:{ d4xSADelIfCompleted *act=new d4xSADelIfCompleted; act->url=new tAddr(text_from_combo(editor->url_entry)); action=act; break; }; }; if (action){ action->start_time=start_time; action->period=period; action->retries=retries; MainScheduler->add_action(action); }; gtk_widget_destroy(GTK_WIDGET(editor));};static void my_gtk_aeditor_cancel(GtkWidget *widget,GtkWidget *editor){ gtk_widget_destroy(editor);};static void my_gtk_aeditor_close(GtkWidget *widget,GdkEvent *event,GtkWidget *editor){ gtk_widget_destroy(editor);};static void my_gtk_aeditor_retry_cb(GtkWidget *widget,MyGtkAEditor *editor){ gtk_widget_set_sensitive(editor->retry_times,GTK_TOGGLE_BUTTON(widget)->active); gtk_widget_set_sensitive(editor->period_days,GTK_TOGGLE_BUTTON(widget)->active); gtk_widget_set_sensitive(editor->period_hours,GTK_TOGGLE_BUTTON(widget)->active); gtk_widget_set_sensitive(editor->period_mins,GTK_TOGGLE_BUTTON(widget)->active);// gtk_widget_set_sensitive(editor->,GTK_TOGGLE_BUTTON(widget)->active);};static void my_gtk_aeditor_init(MyGtkAEditor *editor){ GtkWidget *vbox=gtk_vbox_new(FALSE,0); editor->last_action=-1; //no last actions editor->dwn=(tDownload *)NULL; editor->action=(d4xSchedAction *)NULL; editor->frame_child=(GtkWidget *)NULL; editor->hbox=gtk_hbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(editor->hbox),5); gtk_box_set_spacing(GTK_BOX(vbox),5); editor->omenu = my_option_menu (action_names, sizeof(action_names)/sizeof(char*), 0, editor); GtkWidget *hbox=gtk_hbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(hbox),1); GtkWidget *label=gtk_label_new(_("Start time(hour:min:sec)")); editor->hour=my_gtk_entry_new_with_max_length(2,0); editor->min=my_gtk_entry_new_with_max_length(2,0); editor->sec=my_gtk_entry_new_with_max_length(2,0); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(hbox),editor->hour,FALSE,FALSE,0); label=gtk_label_new(":"); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(hbox),editor->min,FALSE,FALSE,0); label=gtk_label_new(":"); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(hbox),editor->sec,FALSE,FALSE,0); GtkWidget *tmpvbox=gtk_vbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(tmpvbox),5); editor->calendar=gtk_calendar_new(); gtk_calendar_display_options(GTK_CALENDAR(editor->calendar), GtkCalendarDisplayOptions( GTK_CALENDAR_WEEK_START_MONDAY | GTK_CALENDAR_SHOW_DAY_NAMES| GTK_CALENDAR_SHOW_HEADING)); gtk_box_pack_start(GTK_BOX(tmpvbox),hbox,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(tmpvbox),editor->calendar,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(editor->hbox),tmpvbox,FALSE,FALSE,0); tmpvbox=gtk_vbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(tmpvbox),5); editor->retry=gtk_check_button_new_with_label(_("Retry this action")); g_signal_connect(G_OBJECT(editor->retry),"clicked", G_CALLBACK(my_gtk_aeditor_retry_cb),editor); gtk_box_pack_start (GTK_BOX (tmpvbox),editor->retry,FALSE, FALSE, 0); hbox=gtk_hbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(hbox),5); editor->retry_times=my_gtk_entry_new_with_max_length(2,1); gtk_box_pack_start (GTK_BOX (hbox),editor->retry_times,FALSE, FALSE, 0); label=gtk_label_new(_("times to repeat (-1 unlimited)")); gtk_box_pack_start (GTK_BOX (hbox),label,FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (tmpvbox),hbox,FALSE, FALSE, 0); label=gtk_label_new(_("period (day/hour:min)")); hbox=gtk_hbox_new(FALSE,0); gtk_box_set_spacing(GTK_BOX(hbox),1); editor->period_hours=my_gtk_entry_new_with_max_length(2,0); editor->period_mins=my_gtk_entry_new_with_max_length(2,0); editor->period_days=my_gtk_entry_new_with_max_length(2,0); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(hbox),editor->period_days,FALSE,FALSE,0); label=gtk_label_new("/"); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(hbox),editor->period_hours,FALSE,FALSE,0); label=gtk_label_new(":"); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(hbox),editor->period_mins,FALSE,FALSE,0); gtk_box_pack_start (GTK_BOX (tmpvbox),hbox,FALSE, FALSE, 0); GtkWidget *frame=gtk_frame_new(_("Action")); gtk_container_set_border_width(GTK_CONTAINER(frame),5); gtk_container_add(GTK_CONTAINER(frame),editor->omenu); gtk_box_pack_end(GTK_BOX (tmpvbox),frame,FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(editor->hbox),tmpvbox,FALSE,TRUE,0); gtk_box_pack_start(GTK_BOX(vbox),editor->hbox,FALSE,TRUE,0); editor->frame=gtk_frame_new(_("Properties")); gtk_container_set_border_width(GTK_CONTAINER(editor->frame),5); gtk_box_pack_start(GTK_BOX(vbox),editor->frame,FALSE,TRUE,0); hbox=gtk_hbutton_box_new(); gtk_box_set_spacing(GTK_BOX(hbox),5); GtkWidget *ok_button=gtk_button_new_with_label(_("Ok")); GtkWidget *cancel_button=gtk_button_new_with_label(_("Cancel")); gtk_box_pack_end(GTK_BOX(hbox),ok_button,FALSE,FALSE,0); gtk_box_pack_end(GTK_BOX(hbox),cancel_button,FALSE,FALSE,0); g_signal_connect(G_OBJECT(ok_button),"clicked", G_CALLBACK(my_gtk_aeditor_ok),editor); g_signal_connect(G_OBJECT(cancel_button),"clicked", G_CALLBACK(my_gtk_aeditor_cancel),editor); g_signal_connect(G_OBJECT(editor),"delete_event", G_CALLBACK(my_gtk_aeditor_close), editor); d4x_eschandler_init(GTK_WIDGET(editor),editor); gtk_box_pack_start (GTK_BOX (vbox),hbox, FALSE, TRUE, 0); gtk_window_set_title(GTK_WINDOW(editor),_("Edit scheduled action")); gtk_window_set_position(GTK_WINDOW(editor),GTK_WIN_POS_CENTER); gtk_container_set_border_width(GTK_CONTAINER(editor),5); gtk_container_add(GTK_CONTAINER(editor),vbox);};guint my_gtk_aeditor_get_type(){ static guint my_aeditor_type=0; if (!my_aeditor_type){ GTypeInfo my_aeditor_info={ sizeof(MyGtkAEditorClass), NULL, NULL, (GClassInitFunc)my_gtk_aeditor_class_init, NULL, NULL, sizeof(MyGtkAEditor), 0, (GInstanceInitFunc)my_gtk_aeditor_init }; my_aeditor_type =g_type_register_static (GTK_TYPE_WINDOW,"MyGtkAEditor",&my_aeditor_info,(GTypeFlags)0); }; return my_aeditor_type;};GtkWidget *my_gtk_aeditor_new(d4xSchedAction *action){ MyGtkAEditor *editor=(MyGtkAEditor *)g_object_new(my_gtk_aeditor_get_type(),NULL); char data[MAX_LEN]; if (action){ struct tm date; localtime_r(&(action->start_time),&date); sprintf(data,"%i",date.tm_hour); text_to_combo(editor->hour,data); sprintf(data,"%i",date.tm_min); text_to_combo(editor->min,data); sprintf(data,"%i",date.tm_sec); text_to_combo(editor->sec,data); gtk_calendar_select_month(GTK_CALENDAR(editor->calendar),date.tm_mon,date.tm_year+1900); gtk_calendar_select_day(GTK_CALENDAR(editor->calendar),date.tm_mday); if (action->retries){ sprintf(data,"%i",action->retries); text_to_combo(editor->retry_times,data); int mins,days,hours; GTK_TOGGLE_BUTTON(editor->retry)->active=TRUE; mins=(action->period%3600)/60; days=action->period/(3600*24); hours=(action->period%(3600*24))/3600; sprintf(data,"%i",mins); text_to_combo(editor->period_mins,data); sprintf(data,"%i",hours); text_to_combo(editor->period_hours,data); sprintf(data,"%i",days); text_to_combo(editor->period_days,data); }; editor->action=action; gtk_option_menu_set_history (GTK_OPTION_MENU (editor->omenu),action->type()); aeditor_select_mode_int(editor,action->type()); }else{ time_t now=time((time_t*)NULL); struct tm date; localtime_r(&now,&date); sprintf(data,"%i",date.tm_hour); text_to_combo(editor->hour,data); sprintf(data,"%i",date.tm_min); text_to_combo(editor->min,data); sprintf(data,"%i",date.tm_sec); text_to_combo(editor->sec,data); gtk_calendar_select_month(GTK_CALENDAR(editor->calendar),date.tm_mon,date.tm_year+1900); gtk_calendar_select_day(GTK_CALENDAR(editor->calendar),date.tm_mday); aeditor_select_mode_int(editor,0); if (editor->action && editor->action->type()==SACT_SET_SPEED){ d4xSASpeed *act=(d4xSASpeed *)(editor->action); if (act->speed==1) g_signal_emit_by_name(G_OBJECT(editor->sb_low),"clicked"); else g_signal_emit_by_name(act->speed==2?G_OBJECT(editor->sb_middle):G_OBJECT(editor->sb_high), "clicked"); }; }; if (!GTK_TOGGLE_BUTTON(editor->retry)->active){ gtk_widget_set_sensitive(editor->retry_times,FALSE); gtk_widget_set_sensitive(editor->period_days,FALSE); gtk_widget_set_sensitive(editor->period_hours,FALSE); gtk_widget_set_sensitive(editor->period_mins,FALSE); }; return GTK_WIDGET(editor);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -