⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cpp

📁 这个是LINUX下的HFTP测试版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************类Chftp_Local部分**************************************/Chftp_Filedata *Chftp_Local::hftp_Localdata;Chftp_Filelist *Chftp_Local::Local_Filelist; Chftp_Local::Chftp_Local(GtkWidget *hpanel,gint begin,gint end){  try{    GtkWidget *notebox=NULL,*label=NULL;    hftp_Init_members();    notebox=gtk_notebook_new();    gtk_widget_show(notebox);    gtk_paned_pack1(GTK_PANED (hpanel),notebox,FALSE,TRUE);    if(!(Local_Filelist=new Chftp_Filelist(notebox,0,4,0)))      throw Chftp_error("界面初始化失败,程序即将被关闭!");    label=gtk_label_new(" 本地文件 ");    gtk_notebook_set_tab_label(GTK_NOTEBOOK(notebox),			       gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebox),0),label);    label=gtk_label_new(" 快速连接 ");    GtkWidget *scrollwindow;    scrollwindow=gtk_scrolled_window_new(NULL,NULL);    gtk_widget_show(scrollwindow);    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW				   (scrollwindow),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);    gchar *titles[1]={"常用ftp站点列表:"};    marklist=gtk_clist_new_with_titles(1,titles);    gtk_widget_show(marklist);    gtk_container_add(GTK_CONTAINER(scrollwindow),marklist);    gtk_notebook_insert_page(GTK_NOTEBOOK(notebox),scrollwindow,label,1);    hftp_Set_LocalFile();    get_chdir(NULL);    gtk_signal_connect(GTK_OBJECT(Local_Filelist->hftp_GetClist()),"button_press_event",		       GTK_SIGNAL_FUNC(hftp_list_dbclick),(gpointer)this);    gtk_signal_connect(GTK_OBJECT(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry),"changed",		       GTK_SIGNAL_FUNC(get_chdir),(gpointer)this);  }  catch(Chftp_error& UIerror){    UIerror.messagebox();  }}void Chftp_Local::hftp_list_dbclick(GtkWidget *widget,					     GdkEventButton *event,gpointer data){  gint row,column,i;  gchar *text,text2[300];  guint8 for_pix;  if(GDK_2BUTTON_PRESS==event->type && 1==event->button){    gtk_clist_get_selection_info(GTK_CLIST(widget),(int)event->x,(int)event->y,&row,&column);    if(0==gtk_clist_get_text(GTK_CLIST(widget),row,1,&text)) return;    if(0==strcmp(text,"目录")){      gtk_clist_get_pixtext(GTK_CLIST(widget),row,0,&text,&for_pix,NULL,NULL);      if(0==strcmp(text,".")) return;      else if(0==strcmp(text,"..")){   //返回上一层目录.	strcpy(text2,gtk_entry_get_text(GTK_ENTRY					(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry)));	if((i=strlen(text2))<=1) return;	while(*(text2+i)!='/') i--;	if(0==i) strcpy(text2,"/");	else *(text2+i)='\0';}      else{	strcpy(text2,gtk_entry_get_text(GTK_ENTRY					(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry)));	if('/'!=*(text2+strlen(text2)-1)) strcat(text2,"/");	strcat(text2,text);}      gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry),text2);      hftp_Localdata->hftp_GetFiles(gtk_entry_get_text				    (GTK_ENTRY(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry)),				    Local_Filelist->hftp_GetClist()); }  }}void Chftp_Local::get_chdir(gpointer data){  hftp_Localdata->hftp_GetFiles(gtk_entry_get_text				(GTK_ENTRY(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry)),				Local_Filelist->hftp_GetClist()); }void Chftp_Local:: hftp_Init_members(){  try{    if(!(hftp_Localdata=new Chftp_Filedata))      throw Chftp_error("界面初始化失败,程序即将被关闭!");    if(!(bookmark=new Chftp_bookmark))      throw Chftp_error("初始化失败,程序即将被关闭!");    directorys=NULL;    Local_Filelist=NULL;     }catch(Chftp_error& UIerror){    UIerror.messagebox();  }}void Chftp_Local::hftp_Set_LocalFile(){  directorys=g_list_append(directorys,(gpointer)"/mnt");  directorys=g_list_append(directorys,(gpointer)"/home");  directorys=g_list_append(directorys,(gpointer)"/");  directorys=g_list_append(directorys,(gpointer)"/root");  gtk_combo_set_popdown_strings(GTK_COMBO(Local_Filelist->hftp_GetCombo()),directorys);  gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Local_Filelist->hftp_GetCombo())->entry),		     hftp_Localdata->hftp_GetCurrent_dir());  Shftp_Address *temp;  gint i;  temp=bookmark->address;  while(temp){    i=gtk_clist_append(GTK_CLIST(marklist),&(temp->title));    gtk_clist_set_pixtext(GTK_CLIST(marklist),i,0,temp->title,				10,filestyle[2].pixmap,filestyle[2].mask);    temp=temp->next;  }}    Chftp_Local::~Chftp_Local(){  if(Local_Filelist) delete Local_Filelist;  if(hftp_Localdata) delete hftp_Localdata;}/**********************************************类Chftp_Remote部分**********************************/Chftp_Remote::Chftp_Remote(GtkWidget *hpanel,gint begin,gint end){  try{    GtkWidget *label=NULL,*scrollwindow;    scrollwindow=gtk_scrolled_window_new(NULL,NULL);    gtk_widget_show(scrollwindow);    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW				   (scrollwindow),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);    gtk_paned_pack2 (GTK_PANED (hpanel), scrollwindow, TRUE, TRUE);    notebox=gtk_notebook_new();    gtk_widget_show(notebox);    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollwindow),notebox);    }  catch(Chftp_error& UIerror){    UIerror.messagebox();  }}Chftp_Remote::~Chftp_Remote(){  if(Remote_Filelist) delete Remote_Filelist;}/*********************************************类Chftp_State部分************************************/Chftp_State::Chftp_State(GtkWidget *table){  GtkWidget *scrollwindow;  scrollwindow=gtk_scrolled_window_new(NULL,NULL);  gtk_widget_show(scrollwindow);  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW				 (scrollwindow),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);  gchar *titles[7]={"文件名","大小","进度","已用时","剩余时间","速度","状态"};  StateBox=gtk_clist_new_with_titles(7,titles);  gtk_clist_set_column_width(GTK_CLIST(StateBox),0,270);         //设定各列的宽度.  gtk_clist_set_column_width(GTK_CLIST(StateBox),1,85);  gtk_clist_set_column_width(GTK_CLIST(StateBox),2,80);  gtk_clist_set_column_justification(GTK_CLIST(StateBox),2,GTK_JUSTIFY_CENTER);  gtk_clist_set_column_width(GTK_CLIST(StateBox),3,120);  gtk_clist_set_column_justification(GTK_CLIST(StateBox),3,GTK_JUSTIFY_CENTER);  gtk_clist_set_column_width(GTK_CLIST(StateBox),4,120);  gtk_clist_set_column_justification(GTK_CLIST(StateBox),4,GTK_JUSTIFY_CENTER);  gtk_clist_set_column_width(GTK_CLIST(StateBox),5,140);  gtk_clist_set_column_justification(GTK_CLIST(StateBox),5,GTK_JUSTIFY_CENTER);  gtk_clist_set_column_width(GTK_CLIST(StateBox),6,50);  gtk_clist_set_column_justification(GTK_CLIST(StateBox),6,GTK_JUSTIFY_CENTER);  gtk_container_add(GTK_CONTAINER(scrollwindow),StateBox);       //给列表框配上滚动条.  gtk_table_attach_defaults(GTK_TABLE(table),scrollwindow,0,280,4,5);}void Chftp_State::State_append(char **files){  gint i;  i=gtk_clist_append(GTK_CLIST(StateBox),files);  gtk_clist_set_pixtext(GTK_CLIST(StateBox),i,0,files[0],			1,filestyle[3].pixmap,filestyle[3].mask);}void Chftp_State::State_updata(char **files,int position){  gtk_clist_remove(GTK_CLIST(StateBox),position);  gtk_clist_insert(GTK_CLIST(StateBox),position,files);  gtk_clist_set_pixtext(GTK_CLIST(StateBox),position,0,files[0],			1,filestyle[3].pixmap,filestyle[3].mask);}/***********************************************类Chftp_Filelist部分*******************************/Chftp_Filelist::Chftp_Filelist(GtkWidget *notebox,gint begin,gint end,gint index){  GtkWidget *Frame=NULL,*Filebox=NULL,*pixmapwid,    *scrollwindow=NULL,*table=NULL,*StateBox=NULL;  GdkBitmap *mask;  GtkStyle *style;  GdkPixmap *pixmap;  GtkWidget *label=gtk_label_new("  ");  const GtkTargetEntry possible_types[]={{"STRING", 0, 0},					 {"text/plain", 0, 0},					 {"application/x-rootwin-drop", 0, 1}};  Frame=gtk_frame_new(NULL);  gtk_widget_show(Frame);  table=gtk_table_new(4,2,TRUE);  gtk_widget_show(table);  gtk_notebook_insert_page(GTK_NOTEBOOK(notebox),table,label,index);  gtk_table_attach_defaults(GTK_TABLE(table),Frame,0,2,begin,end);  Filebox=gtk_vbox_new(FALSE,5);  gtk_widget_show(Filebox);  gtk_container_add(GTK_CONTAINER(Frame),Filebox);  StateBox=gtk_hbox_new(FALSE,1);  gtk_widget_show(StateBox);  gtk_box_pack_start(GTK_BOX(Filebox),StateBox,FALSE,FALSE,0);  FilepathComo=gtk_combo_new();                        //用于显示文件路径的一个组合框.  gtk_widget_show(FilepathComo);  gtk_box_pack_start(GTK_BOX(StateBox),FilepathComo,TRUE,TRUE,0);  if(3==end){    style=gtk_widget_get_style(notebox);	    pixmap=gdk_pixmap_create_from_xpm(notebox->window,				      &mask,&style->bg[GTK_STATE_NORMAL],"/usr/local/share/pixmaps/dotdot.xpm");    pixmapwid=gtk_pixmap_new(pixmap,mask);    gtk_widget_show(pixmapwid);    up_button=gtk_button_new();    gtk_container_add(GTK_CONTAINER(up_button),pixmapwid);    gtk_widget_show(up_button);    gtk_box_pack_start(GTK_BOX(StateBox),up_button,FALSE,FALSE,0);    pixmap=gdk_pixmap_create_from_xpm(notebox->window,				      &mask,&style->bg[GTK_STATE_NORMAL],"/usr/local/share/pixmaps/refresh.xpm");    pixmapwid=gtk_pixmap_new(pixmap,mask);    gtk_widget_show(pixmapwid);    fresh_button=gtk_button_new();    gtk_container_add(GTK_CONTAINER(fresh_button),pixmapwid);    gtk_widget_show(fresh_button);    gtk_box_pack_start(GTK_BOX(StateBox),fresh_button,FALSE,FALSE,0);    pixmap=gdk_pixmap_create_from_xpm(notebox->window,				      &mask,&style->bg[GTK_STATE_NORMAL],"/usr/local/share/pixmaps/close.xpm");    pixmapwid=gtk_pixmap_new(pixmap,mask);    gtk_widget_show(pixmapwid);    shut_button=gtk_button_new();    gtk_container_add(GTK_CONTAINER(shut_button),pixmapwid);    gtk_widget_show(shut_button);    gtk_box_pack_start(GTK_BOX(StateBox),shut_button,FALSE,FALSE,0);  }  gtk_combo_disable_activate(GTK_COMBO(FilepathComo));  scrollwindow=gtk_scrolled_window_new(NULL,NULL);  gtk_widget_show(scrollwindow);  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrollwindow),				 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);  gchar *titles[6]={"文件名","类型","大小","用户","日期","属性"};  FileList=gtk_clist_new_with_titles(6,titles);  gtk_widget_show(FileList);    gtk_drag_source_set(FileList,GDK_BUTTON1_MASK,possible_types,3,		      (GdkDragAction)(GDK_ACTION_COPY|GDK_ACTION_MOVE));  gtk_drag_dest_set(FileList, GTK_DEST_DEFAULT_ALL,possible_types,2,		    (GdkDragAction)(GDK_ACTION_COPY|GDK_ACTION_MOVE));  gtk_clist_set_selection_mode (GTK_CLIST(FileList),				GTK_SELECTION_SINGLE);  gtk_clist_set_column_width(GTK_CLIST(FileList),0,270);         //设定各列的宽度.  gtk_clist_set_column_width(GTK_CLIST(FileList),1,45);  gtk_clist_set_column_width(GTK_CLIST(FileList),2,75);  gtk_clist_set_column_justification(GTK_CLIST(FileList),2,GTK_JUSTIFY_RIGHT);  gtk_clist_set_column_width(GTK_CLIST(FileList),3,60);  gtk_clist_set_column_justification(GTK_CLIST(FileList),3,GTK_JUSTIFY_CENTER);  gtk_clist_set_column_width(GTK_CLIST(FileList),4,140);  gtk_clist_set_column_justification(GTK_CLIST(FileList),4,GTK_JUSTIFY_CENTER);  gtk_clist_set_column_width(GTK_CLIST(FileList),5,100);  gtk_clist_set_column_justification(GTK_CLIST(FileList),5,GTK_JUSTIFY_CENTER);  gtk_container_add(GTK_CONTAINER(scrollwindow),FileList);       //给列表框配上滚动条.  gtk_box_pack_start(GTK_BOX(Filebox),scrollwindow,TRUE,TRUE,0);  if(3==end) hftp_Create_Message_Box(table,0,2);}void Chftp_Filelist::hftp_Create_Message_Box(GtkWidget *table,gint begin,gint end){  GtkWidget *Frame=gtk_frame_new(NULL);  gtk_widget_show(Frame);  GtkObject *mess_vadj=GTK_OBJECT(gtk_adjustment_new(10000,1,10000,1,200,200));  gtk_frame_set_shadow_type(GTK_FRAME(Frame),GTK_SHADOW_IN);  gtk_table_attach_defaults(GTK_TABLE(table),Frame,begin,end,3,4);  GtkWidget *scrollwindow;  scrollwindow=gtk_scrolled_window_new(NULL,GTK_ADJUSTMENT(mess_vadj));  gtk_widget_show(scrollwindow);  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW				 (scrollwindow),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);  gtk_container_add(GTK_CONTAINER(Frame),scrollwindow);  MessageBox=gtk_list_new();  gtk_widget_show(MessageBox);  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollwindow),MessageBox);     for(gint i=0;i<195;i++)    hftp_AddStringToList("");  hftp_AddStringToList("ftp客户端软件hFTP测试版.");  hftp_AddStringToList("作者: 何林强.");  hftp_AddStringToList("浙江大学计算机学院99级");  hftp_AddStringToList("Email:helinqiang@163.net.");  hftp_AddStringToList("QQ: 7219408.");}void Chftp_Filelist::hftp_AddStringToList(gchar *textstring){  GtkWidget *listitem=NULL;  listitem=gtk_list_item_new_with_label(textstring);   gtk_container_add(GTK_CONTAINER(MessageBox),listitem);  if(gtk_list_child_position(GTK_LIST(MessageBox),listitem)>200)    gtk_list_clear_items(GTK_LIST(MessageBox),0,1);   gtk_widget_show(listitem);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -