📄 list.cc
字号:
/* WebDownloader for X-Window * Copyright (C) 1999-2002 Koshelev Maxim * This Program is free but not GPL!!! You can't modify it * without agreement with author. You can't distribute modified * program but you can distribute unmodified program. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */#include <stdio.h>#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include <pthread.h>#include <string.h>#include <strings.h>#include <sys/stat.h>#include <unistd.h>#include "../dlist.h"#include "../main.h"#include "../var.h"#include "../savelog.h"#include "../config.h"#include "../locstr.h"#include "../ntlocale.h"#include "../sndserv.h"#include "log.h"#include "addd.h"#include "list.h"#include "prefs.h"#include "buttons.h"#include "about.h"#include "graph.h"#include "edit.h"#include "lmenu.h"#include "saveload.h"#include "misc.h"#include "dndtrash.h"#include "passface.h"#include "colors.h"#include "fsface.h"#include "fsched.h"#include "filtrgui.h"#include "../xml.h"#undef FLT_ROUNDS#define FLT_ROUNDS 3GtkWidget *MainMenu;GtkAdjustment *ProgressBarValues;GtkWidget *ProgressOfDownload;GtkWidget *MainStatusBar,*ReadedBytesStatusBar;GtkWidget *MainWindow=(GtkWidget *)NULL;GtkWidget *MainHBox;GtkWidget *ContainerForCList=(GtkWidget *)NULL;GdkGC *MainWindowGC=(GdkGC *)NULL;GtkTreeView *FSearchView;GtkWidget *BoxForGraph;GtkItemFactory *main_menu_item_factory=NULL;GtkWidget *MainLogList,*MAIN_PANED=(GtkWidget *)NULL,*MAIN_PANED2=(GtkWidget *)NULL;GtkWidget *MAIN_PANED1=(GtkWidget *)NULL;d4xQsTree *D4X_QVT;int main_log_mask;unsigned int ScrollShift[2];int mainwin_title_state;gfloat main_log_value;GtkAdjustment *main_log_adj;GtkItemFactory *list_menu_itemfact;tConfirmedDialog *AskDelete=(tConfirmedDialog *)NULL;tConfirmedDialog *AskDeleteCompleted=(tConfirmedDialog *)NULL;tConfirmedDialog *AskDeleteFataled=(tConfirmedDialog *)NULL;tConfirmedDialog *AskExit=(tConfirmedDialog *)NULL;gint StatusBarContext,RBStatusBarContext;int LogsTimer,GraphTimer,ListTimer;int SAVE_LIST_INTERVAL,EXIT_COMPLETE_INTERVAL;//pthread_mutex_t MAIN_GTK_MUTEX=(pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;int FirstConfigureEvent;int UpdateTitleCycle=0;int MAIN_PANED_HEIGHT=0;char *OLD_CLIPBOARD_CONTENT=NULL;char *LOAD_ACCELERATORS[6]={(char *)NULL,(char *)NULL,(char *)NULL,(char*)NULL,(char *)NULL};enum{ ROLL_STAT=0, ROLL_INFO, ROLL_LAST};enum MAIN_MENU_ENUM{ MM_FILE, MM_FILE_SAVE, MM_FILE_LOAD, MM_FILE_TXT, MM_FILE_NEW, MM_FILE_PASTE, MM_FILE_AUTO, MM_FILE_EXIT, MM_FILE_SEP, MM_DOWNLOAD, MM_DOWNLOAD_LOG, MM_DOWNLOAD_STOP, MM_DOWNLOAD_EDIT, MM_DOWNLOAD_DEL, MM_DOWNLOAD_RUN, MM_DOWNLOAD_DEL_C, MM_DOWNLOAD_DEL_F,MM_DOWNLOAD_RERUN, MM_DOWNLOAD_PROTECT,MM_DOWNLOAD_UNSELECT_ALL,MM_DOWNLOAD_SELECT_ALL ,MM_DOWNLOAD_INVERT, MM_DOWNLOAD_SEP, MM_QUEUE,MM_QUEUE_NQ,MM_QUEUE_NSQ,MM_QUEUE_REMOVE,MM_QUEUE_PROP, MM_OPTIONS, MM_OPTIONS_SCHEDULER, MM_OPTIONS_PASSWORDS, MM_OPTIONS_COMMON, MM_OPTIONS_FILTERS, MM_OPTIONS_SPEED, MM_OPTIONS_SPEED_1, MM_OPTIONS_SPEED_2, MM_OPTIONS_SPEED_3, MM_OPTIONS_BUTTONS, MM_OPTIONS_BUTTONS_ADD, MM_OPTIONS_BUTTONS_MAN, MM_OPTIONS_BUTTONS_SPEED, MM_OPTIONS_BUTTONS_MISC, MM_HELP, MM_HELP_ABOUT};char *main_menu_kb[MM_HELP_ABOUT+1];char *main_menu_kbnames[]={ "file", "save", "load", "findlinks", "new", "paste", "auto", "exit", "", "download", "log", "stop", "edit", "delete", "continue", "delcompleted", "delfailed", "rerunfailed", "protect", "unselect", "select", "invert", "", "queue", "newqueue", "newsubqueue", "removequeue", "queueproperties", "options", "scheduler", "urlmanager", "general", "filters", "speed", "low", "medium", "unlimited", "buttons", "", "", "", "", "help", "about"};char *main_menu_inames[]={ N_("/_File"), N_("/File/_Save List"), N_("/File/_Load List"), N_("/File/Find links in file"), N_("/File/_New Download"), N_("/File/_Paste Download"), N_("/File/_Automated adding"), N_("/File/Exit"), N_("/File/sep1"), N_("/_Download"), N_("/Download/View _Log"), N_("/Download/_Stop downloads"), N_("/Download/Edit download"), N_("/Download/_Delete downloads"), N_("/Download/Continue downloads"), N_("/Download/Delete completed"), N_("/Download/Delete failed"), N_("/Download/Rerun failed"), N_("/Download/(Un)Protect"), N_("/Download/Unselect all"), N_("/Download/Select all"), N_("/Download/Invert selection"), N_("/Download/-"), N_("/_Queue"), N_("/Queue/Create new queue"), N_("/Queue/Create new subqueue"), N_("/Queue/Remove this queue"), N_("/Queue/Properties"), N_("/_Options"), N_("/Options/Scheduler"), N_("/Options/URL-manager"), N_("/Options/General"), N_("/Options/Filters"), N_("/Options/Speed"), N_("/Options/Speed/Low"), N_("/Options/Speed/Medium"), N_("/Options/Speed/Unlimited"), N_("/Options/Buttons"), N_("/Options/Buttons/Add buttons"), N_("/Options/Buttons/Manipulating"), N_("/Options/Buttons/Speed buttons"), N_("/Options/Buttons/Misc buttons"), N_("/_Help"), N_("/_Help/About")};void d4x_load_accelerators();char *old_clipboard_content(){ if (CFG.CLIPBOARD_MONITOR) return(OLD_CLIPBOARD_CONTENT); return(NULL);};static void open_passwords_window(...) { FaceForPasswords->init();};void util_item_factory_popup(GtkItemFactory *ifactory,guint x, guint y,guint mouse_button,guint32 time) { static GQuark quark_user_menu_pos=0; struct Pos { gint x; gint y; } *pos; if(!quark_user_menu_pos) quark_user_menu_pos=g_quark_from_static_string("user_menu_pos"); pos=(Pos *)g_object_get_qdata(G_OBJECT(ifactory),quark_user_menu_pos); if(!pos) { pos=(Pos *)g_malloc0(sizeof(struct Pos)); g_object_set_qdata_full(G_OBJECT(ifactory->widget),quark_user_menu_pos,pos,g_free); } pos->x=x; pos->y=y; gtk_menu_popup(GTK_MENU(ifactory->widget), (GtkWidget *)NULL, (GtkWidget *)NULL, (GtkMenuPositionFunc)NULL, pos, mouse_button,time);};void _rerun_failed_downloads(){ aa.rerun_failed();};void main_menu_speed_calback(gpointer data,guint action,GtkWidget *widget){ if (action>0 && action<4){ CFG.SPEED_LIMIT=action; set_speed_buttons(); };};void main_menu_speed_prepare(){ GtkWidget *menu_item=gtk_item_factory_get_widget(main_menu_item_factory,_(main_menu_inames[MM_OPTIONS_SPEED_1])); if (menu_item){ GTK_CHECK_MENU_ITEM(menu_item)->active=CFG.SPEED_LIMIT==1?TRUE:FALSE; if (GTK_WIDGET_VISIBLE(menu_item)) gtk_widget_queue_draw(menu_item); }; menu_item=gtk_item_factory_get_widget(main_menu_item_factory,_(main_menu_inames[MM_OPTIONS_SPEED_2])); if (menu_item){ GTK_CHECK_MENU_ITEM(menu_item)->active=CFG.SPEED_LIMIT==2?TRUE:FALSE; if (GTK_WIDGET_VISIBLE(menu_item)) gtk_widget_queue_draw(menu_item); }; menu_item=gtk_item_factory_get_widget(main_menu_item_factory,_(main_menu_inames[MM_OPTIONS_SPEED_3])); if (menu_item){ GTK_CHECK_MENU_ITEM(menu_item)->active=CFG.SPEED_LIMIT==3?TRUE:FALSE; if (GTK_WIDGET_VISIBLE(menu_item)) gtk_widget_queue_draw(menu_item); };};void load_accelerated(gpointer *p,gint realnum){ tString *str=ALL_HISTORIES[SAVE_HISTORY]->last(); int num=realnum-128; for (int i=0;i<=num;i++){ if (str==NULL) return; if (i==num) read_list_from_file_current(str->body); str=ALL_HISTORIES[SAVE_HISTORY]->next(); };};static void _remove_underscore(char *where){ char *p,*q; p=q=where; while (*p){ if (*p!='_') *q++ = *p; p++; }; *q=0;};static char *copy_without_underscore(char *what){ char *d=copy_string(what); _remove_underscore(d); return(d);};void init_load_accelerators(){ tString *str=ALL_HISTORIES[SAVE_HISTORY]->last(); char *path=copy_string(_(main_menu_inames[MM_FILE_SEP])); char *sep=index(path+1,'/'); if (LOAD_ACCELERATORS[5]==NULL){ LOAD_ACCELERATORS[5]=copy_string(_(main_menu_inames[MM_FILE_EXIT])); _remove_underscore(LOAD_ACCELERATORS[5]); }; gtk_item_factory_delete_item(main_menu_item_factory,LOAD_ACCELERATORS[5]); if (LOAD_ACCELERATORS[4]==NULL){ LOAD_ACCELERATORS[4]=sum_strings(_(main_menu_inames[MM_FILE_SEP]),"1",NULL); }else{ gtk_item_factory_delete_item(main_menu_item_factory, LOAD_ACCELERATORS[4]); }; for (int j=0;j<3;j++) if (LOAD_ACCELERATORS[j]){ gtk_item_factory_delete_item(main_menu_item_factory, LOAD_ACCELERATORS[j]); delete[] LOAD_ACCELERATORS[j]; }; if (sep){ *sep=0; for (int i=0;i<3;i++){ if (str==NULL) break; GtkItemFactoryEntry tmp; sep=rindex(str->body,'/'); char data[MAX_LEN]; g_snprintf(data,MAX_LEN,"%i",i+1); if (sep) tmp.path=sum_strings(path,"/",data,". ",sep+1,NULL); else tmp.path=sum_strings(path,"/",data,". ",str->body,NULL); tmp.accelerator=sum_strings("<control>",data,NULL); tmp.callback=(GtkItemFactoryCallback)load_accelerated; tmp.callback_action=i+128; tmp.item_type="<Item>"; LOAD_ACCELERATORS[i]=tmp.path; tmp.path=escape_char(tmp.path,'_','_'); gtk_item_factory_create_item(main_menu_item_factory, &tmp, NULL,1); delete[] tmp.path; delete[] tmp.accelerator; /*adding tooltip*/ GtkWidget *menu_item=gtk_item_factory_get_widget_by_action(main_menu_item_factory, tmp.callback_action); if (menu_item){ GtkTooltips *tooltip=gtk_tooltips_new(); gtk_tooltips_force_window(tooltip); GtkStyle *current_style=gtk_style_copy(gtk_widget_get_style(tooltip->tip_window)); current_style->bg[GTK_STATE_NORMAL] = LYELLOW; gtk_widget_set_style(tooltip->tip_window, current_style); gtk_tooltips_set_tip(tooltip,menu_item,str->body,(const gchar *)NULL); gtk_tooltips_enable(tooltip); }; /* modify path for deleting it successfully */ _remove_underscore(LOAD_ACCELERATORS[i]); str=ALL_HISTORIES[SAVE_HISTORY]->next(); }; }; delete[] path; GtkItemFactoryEntry sep_item={LOAD_ACCELERATORS[4], (gchar *)NULL, (GtkItemFactoryCallback)NULL, 0, "<Separator>"}; GtkItemFactoryEntry exit_item={_(main_menu_inames[MM_FILE_EXIT]), "<alt>X", (GtkItemFactoryCallback)ask_exit, 0, (gchar *)NULL}; gtk_item_factory_create_item(main_menu_item_factory, &sep_item,NULL,1); gtk_item_factory_create_item(main_menu_item_factory, &exit_item,NULL,1);};static gint main_menu_enable_all(){ GtkWidget *menu_item; for (int i=MM_DOWNLOAD_LOG;i<=MM_DOWNLOAD_RUN;i++){ menu_item=gtk_item_factory_get_item_by_action(main_menu_item_factory, i+100); if (menu_item) gtk_widget_set_sensitive(menu_item,TRUE); }; for (int i=MM_DOWNLOAD_UNSELECT_ALL;i<=MM_DOWNLOAD_INVERT;i++){ menu_item=gtk_item_factory_get_item_by_action(main_menu_item_factory, i+100); if (menu_item) gtk_widget_set_sensitive(menu_item,TRUE); }; return FALSE;};void mmenu_open_logs(){ D4X_QUEUE->qv.open_logs();};void mmenu_unselect_all(){ D4X_QUEUE->qv.unselect_all();};void mmenu_select_all(){ D4X_QUEUE->qv.select_all();};void mmenu_invert_selection(){ D4X_QUEUE->qv.invert_selection();};static void _mm_queue_menu_(gpointer *a,gint act){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -