📄 passface.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 <sys/stat.h>#include "passface.h"#include "misc.h"#include "edit.h"#include "../addr.h"#include "../ntlocale.h"#include "../var.h"#include "../main.h"#include "list.h"#include <gdk/gdkkeysyms.h>enum { UM_COL_REGEX, UM_COL_LIMIT, UM_COL_CON, UM_COL_DATA, UM_COL_LAST};tFacePass *FaceForPasswords=(tFacePass *)NULL;/* */static void face_pass_ok(GtkWidget *widget, tFacePass *parent) { parent->close();};static void face_pass_add(GtkWidget *widget, tFacePass *parent) { parent->open_dialog();};static gint face_pass_delete(GtkWidget *widget,GdkEvent *event, tFacePass *parent) { parent->close(); return TRUE;};static void face_pass_del(GtkWidget *widget, tFacePass *parent) { parent->delete_rows();};static gboolean face_pass_clist_handler(GtkTreeView *view, GdkEventButton *event, tFacePass *parent) { if (event && event->type==GDK_2BUTTON_PRESS && event->button==1){ GtkTreeSelection *sel=gtk_tree_view_get_selection(view); GtkTreeIter iter; GtkTreePath *path; if (gtk_tree_view_get_path_at_pos(view,gint(event->x),gint(event->y),&path,NULL,NULL,NULL)){ gtk_tree_selection_unselect_all(sel); gtk_tree_selection_select_path(sel,path); GtkTreeIter iter; GtkTreeModel *model=gtk_tree_view_get_model(view); gtk_tree_model_get_iter(model,&iter,path); gtk_tree_path_free(path); parent->edit_row(&iter); return TRUE; }; }; if (event->type == GDK_KEY_PRESS) { GdkEventKey *kevent=(GdkEventKey *)event; switch(kevent->keyval) { case GDK_Delete: case GDK_KP_Delete: { parent->delete_rows(); return TRUE; }; }; }; return FALSE;};static void face_pass_dialog_ok(GtkWidget *widget,tFacePass *parent) { parent->apply_dialog();};static void add_url_cancel(GtkWidget *widget, tDownload *dwn){ FaceForPasswords->addlist_del(dwn);};static void add_url_ok(GtkWidget *widget, tLimitDownload *dwn){ FaceForPasswords->addlist_add(dwn);};static void add_url_delete(GtkWidget *widget,GdkEvent *event, tDownload *dwn){ FaceForPasswords->addlist_del(dwn);};static void edit_url_cancel(GtkWidget *widget, tDownload *dwn){ dwn->delete_editor();};static void edit_url_ok(GtkWidget *widget, tLimitDownload *dwn){ if (dwn->editor->apply_changes()) return; dwn->Name2Save.set(dwn->editor->get_url()); FaceForPasswords->recalc_run(dwn); dwn->delete_editor(); FaceForPasswords->redraw_url(dwn);};static void edit_url_delete(GtkWidget *widget,GdkEvent *event, tDownload *dwn){ dwn->delete_editor();};tFacePass::tFacePass(){ do_not_run=0; window=NULL;};tFacePass::~tFacePass(){ do_not_run=1; tDownload *dwn=dlist.first(); while(dwn){ free_matched((tLimitDownload*)dwn); dwn=dlist.prev(); }; close();};void tFacePass::set_do_not_run(int a){do_not_run=1;};void tFacePass::addlist_del(tDownload *dwn){ addlist.del(dwn); delete(dwn);};void tFacePass::show_url(tLimitDownload *dwn){ GtkTreeIter iter; gtk_list_store_append(list_store, &iter); gtk_list_store_set(list_store, &iter, UM_COL_REGEX,dwn->Name2Save.get(), UM_COL_LIMIT,dwn->config->con_limit, UM_COL_CON,dwn->cur_limit, UM_COL_DATA,dwn, -1); if (dwn->list_iter) gtk_tree_iter_free(dwn->list_iter); dwn->list_iter=gtk_tree_iter_copy(&iter);};void tFacePass::redraw_url(tLimitDownload *dwn){ if (!window) return; gtk_list_store_set(list_store, dwn->list_iter, UM_COL_REGEX,dwn->Name2Save.get(), UM_COL_LIMIT,dwn->config->con_limit, UM_COL_CON,dwn->cur_limit, -1);};void tFacePass::calc_matched_run_rec(tQueue *q,tLimitDownload *dwn,regex_t *reg){ d4xDownloadQueue *dq=(d4xDownloadQueue*)(q->first()); while (dq){ tDownload *what=dq->first(DL_RUN); while (what){ if (what->regex_match==NULL){ char *url=what->info->url(); if (regexec(reg,url,0,NULL,0)==0){ what->regex_match=new d4xDwnLink(what,dwn); //awful lists for fast access what->regex_match->q=&(dwn->lim_run); dwn->lim_run.insert(what->regex_match); //on REAL LARGE queues :-) if (what->split){ dwn->cur_limit+=what->split->runcount - what->split->stopcount; }else dwn->cur_limit+=1; }; delete[] url; }; what=(tDownload *)(what->prev); }; calc_matched_run_rec(&(dq->child),dwn,reg); dq=(d4xDownloadQueue *)(dq->prev); };};void tFacePass::calc_matched_run(tLimitDownload *dwn){ // walk over all run queues to match limit regex_t reg; if (regcomp(®,dwn->Name2Save.get(),REG_NOSUB)==0){ calc_matched_run_rec(&D4X_QTREE,dwn,®); regfree(®); };};void tFacePass::free_matched(tLimitDownload *dwn){ d4xDwnLink *lnk=(d4xDwnLink *)dwn->lim_run.first(); while(lnk){ lnk->dwn->regex_match=NULL; dwn->lim_run.dispose(); lnk=(d4xDwnLink *)dwn->lim_run.first(); }; lnk=(d4xDwnLink *)dwn->limited.first(); while(lnk){ lnk->dwn->regex_match=NULL; d4xDownloadQueue *dq=lnk->dwn->myowner->PAPA; dq->del(lnk->dwn); aa.insert_into_wait_list(lnk->dwn,dq); if (!do_not_run) aa.try_to_run_wait(dq); dwn->limited.dispose(); lnk=(d4xDwnLink *)dwn->limited.first(); };};void tFacePass::rerun_wait_queues(tQueue *q){ d4xDownloadQueue *dq=(d4xDownloadQueue*)(q->first()); while (dq){ aa.try_to_run_wait(dq); rerun_wait_queues(&(dq->child)); dq=(d4xDownloadQueue *)(dq->prev); };};void tFacePass::recalc_run(tLimitDownload *dwn){ int need2rw=dwn->limited.first()?1:0; do_not_run=1; free_matched(dwn); do_not_run=0; dwn->cur_limit=0; if (dwn->config->con_limit>0) calc_matched_run(dwn); if (need2rw) rerun_wait_queues(&D4X_QTREE);};void tFacePass::stop_matched(tDownload *dwn){ if (dwn->regex_match==NULL) return; dwn->regex_match->q->del(dwn->regex_match); delete(dwn->regex_match); dwn->regex_match=NULL;};void tFacePass::limit_dec(tDownload *what){ if (what->regex_match==NULL) return; tLimitDownload *dwn=(tLimitDownload *)(what->regex_match->papa); dwn->cur_limit--; redraw_url(dwn); if (dwn->cur_limit<dwn->config->con_limit){ d4xDwnLink *lnk=(d4xDwnLink *)dwn->limited.first(); if (lnk){ lnk->dwn->regex_match=NULL; d4xDownloadQueue *dq=lnk->dwn->myowner->PAPA; dq->del(lnk->dwn); aa.insert_into_wait_list(lnk->dwn,dq); if (!do_not_run) aa.try_to_run_wait(dq); dwn->limited.dispose(); }; };};void tFacePass::limit_inc(tDownload *what){ if (what->regex_match==NULL) return; tLimitDownload *dwn=(tLimitDownload *)(what->regex_match->papa); dwn->cur_limit++; redraw_url(dwn);};void tFacePass::limit_to_run(tDownload *what){ if (what->regex_match==NULL) return; tLimitDownload *dwn=(tLimitDownload *)(what->regex_match->papa); dwn->limited.del(what->regex_match); dwn->lim_run.insert(what->regex_match); what->regex_match->q=&(dwn->lim_run); dwn->cur_limit++; redraw_url(dwn);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -