📄 msearch.c
字号:
return menu;}voidtreeitem_button_event (GtkWidget * widget, GdkEventButton * event, gpointer user_data){ GtkWidget *menu = treeitem_popup (); GtkWidget *tree = lookup_widget (widget, "search_tree"); gtk_signal_connect (GTK_OBJECT (lookup_widget (menu, "add")), "activate", GTK_SIGNAL_FUNC (on_add_button_clicked), (gpointer) tree); gtk_signal_connect (GTK_OBJECT (lookup_widget (menu, "delete")), "activate", GTK_SIGNAL_FUNC (treeitem_delete), widget); if ((event->button == 1) || (event->button == 3)) gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 1, 0);}voidtreeitem_delete (GtkWidget * widget, gpointer user_data){ GtkWidget *treeitem = user_data; GtkWidget *tree = lookup_widget (treeitem, "search_tree"); GtkWidget *text = lookup_widget (treeitem, "search_english"); GList *seek; int total = -1; for (seek = GTK_TREE (tree)->children; seek; seek = seek->next) total++; // we're not going to delete the last item from the tree if (total) gtk_container_remove (GTK_CONTAINER (tree), treeitem); search_english_update (text);}voidmsearch_search (GtkWidget * widget, gpointer user_data){ char *match = NULL; int i, total, trtotal, mfound; unsigned long pcount, ptotal; float prog = 0; Folder *fl; GList *flseek, *trseek, *msg; Message *mseek; char *whole = NULL, *message = NULL; Header_Info *header = NULL; char *folder = gtk_entry_get_text (GTK_ENTRY (lookup_widget (widget, "search_folder"))); GtkWidget *progress = lookup_widget (widget, "progressbar"); GtkWidget *include = lookup_widget (widget, "child_button"); GtkWidget *ignorecase = lookup_widget (widget, "case_button"); GtkWidget *anyall = lookup_widget (widget, "all_button"); GtkWidget *tree = lookup_widget (widget, "search_tree"); Attachment *att = (Attachment *) calloc (1, sizeof (Attachment)); GtkWidget *msearch_clist = lookup_widget (widget, "message_clist"); char *cl_data[6]; char date[255]; msg_info *info; int row; int ignore = 0; if (searching) return; searching = 1; msearch_cancel_flag = 0; gtk_progress_set_show_text (GTK_PROGRESS (progress), TRUE); if (GTK_TOGGLE_BUTTON (ignorecase)->active) ignore = 1; att->mtype = strdup ("dummyatt"); // if the GList *found has items, we're going to go ahead and destroy it#if 1 if (found) msearch_destroy_clist_contents (GTK_CLIST (msearch_clist));#endif // make sure there are items in the tree, to be safe trtotal = 0; for (trseek = GTK_TREE (tree)->children; trseek; trseek = trseek->next) trtotal++; if (!trtotal) return; // progress bar counting totals gtk_progress_bar_update (GTK_PROGRESS_BAR (progress), 0.0); pcount = 0; ptotal = 0; for (flseek = folder_create_glist (); flseek; flseek = flseek->next) { fl = folder_seek (folder_seek_by_name (flseek->data)); for (mseek = fl->msglst; mseek; mseek = mseek->next) { ptotal = ptotal + mseek->size; } } // for each folder for (flseek = folder_create_glist (); flseek; flseek = flseek->next) { fl = folder_seek (folder_seek_by_name (flseek->data)); // for each message in the current folder for (mseek = fl->msglst; mseek; mseek = mseek->next) { if (msearch_cancel_flag) break; // do progressbar updates pcount = pcount + mseek->size; if (ptotal != 0) prog = (float) pcount / (float) ptotal; if (pcount > ptotal) pcount = ptotal; if (prog > 0 && prog < 1) gtk_progress_bar_update (GTK_PROGRESS_BAR (progress), prog); while (gtk_events_pending ()) gtk_main_iteration (); // if all folders is selected, or the current folder is selected, // or the parent of the current folder is selected, if that // checkbutton is active... if ((strcasecmp (folder, "* All Folders") == 0) || (strcasecmp (mseek->folder, folder) == 0) || ((GTK_TOGGLE_BUTTON (include)->active) && (strcasecmp (folder_seek (folder_seek_by_name (mseek->folder))->parent, folder) == 0))) { // this is going to be like a truth table or something match = (char *) malloc ((trtotal + 1) * sizeof (char)); mfound = 0; i = 0; // for each tree item in the tree for (trseek = GTK_TREE (tree)->children; trseek; trseek = trseek->next) { GtkWidget *trtarget = trseek->data; int equal = 0; int sim = 0; // similar char *where = gtk_entry_get_text (GTK_ENTRY (gtk_object_get_data (GTK_OBJECT (trtarget), "search_attribute"))); char *is = gtk_entry_get_text (GTK_ENTRY (gtk_object_get_data (GTK_OBJECT (trtarget), "search_criteria"))); char *to = gtk_entry_get_text (GTK_ENTRY (gtk_object_get_data (GTK_OBJECT (trtarget), "search_text"))); gtk_editable_select_region (GTK_EDITABLE (gtk_object_get_data (GTK_OBJECT (trtarget), "search_text")), 0, -1); if (!strlen (to)) break; mfound = 0; if ((strcmp (is, "Equal")) == 0) equal = 1; if ((strcmp (is, "Similar")) == 0) sim = 1; whole = NULL; message = NULL; header = NULL; switch (*where) { case 'S': // Subject { if (mseek->subject) mfound = msearch_check (mseek->subject, to, equal, sim, ignore); break; } case 'F': // From { if (mseek->from) mfound = msearch_check (mseek->from, to, equal, sim, ignore); break; } case 'R': // Reply-To { if (mseek->replyto) mfound = msearch_check (mseek->replyto, to, equal, sim, ignore); break; } case 'T': // To { whole = message_load (folder_seek (folder_seek_by_name (mseek->rfolder)), mseek); header = parse_header (whole); if (header->to) mfound = msearch_check (header->to, to, equal, sim, ignore); break; } case 'C': // Cc { whole = message_load (folder_seek (folder_seek_by_name (mseek->rfolder)), mseek); header = parse_header (whole); if (header->cc) mfound = msearch_check (header->cc, to, equal, sim, ignore); break; } case 'B': // Bcc { whole = message_load (folder_seek (folder_seek_by_name (mseek->rfolder)), mseek); header = parse_header (whole); if (header->bcc) mfound = msearch_check (header->bcc, to, equal, sim, ignore); break; } case 'M': // Message { whole = message_load (folder_seek (folder_seek_by_name (mseek->rfolder)), mseek); message = mime_process (whole, att, 0); if (message) mfound = msearch_check (message, to, equal, sim, ignore); break; } case 'K': // Keywords { if (mseek->keywords) mfound = msearch_check (mseek->keywords, to, equal, sim, ignore); break; } case 'P': // Priority { if (mseek->priority) mfound = msearch_check (mseek->priority, to, equal, sim, ignore); break; } default: mfound = 0; break; } if (whole) free (whole); if (message) free (message); if (header) destroy_hinfo (header); if (mfound) *(match + i) = '1'; else *(match + i) = '0'; i++; } } gtk_progress_bar_update (GTK_PROGRESS_BAR (progress), 1.0); if (match) *(match + (trtotal)) = '\0'; total = 0; if (match) { for (i = 0; i < strlen (match); i++) if ((*(match + i)) == '1') total++; if (total) { int gotit = 1; if ((GTK_TOGGLE_BUTTON (anyall)->active) && (total != strlen (match))) gotit = 0; if (gotit) { found = g_list_append (found, mseek); } } free (match); match = NULL; } } } gtk_clist_freeze (GTK_CLIST (msearch_clist)); gtk_clist_clear (GTK_CLIST (msearch_clist)); // time to update the message clist if we have anything found if (found) { for (msg = found; msg; msg = msg->next) { mseek = msg->data; cl_data[0] = NULL; cl_data[1] = mseek->priority; cl_data[2] = mseek->subject; cl_data[3] = mseek->from; cl_data[4] = mseek->date; strftime (date, sizeof (date), "%a, %d %b %Y %H:%M:%S %z", localtime (&mseek->time)); cl_data[5] = strdup (date); //cl_data[5] = ctime (&mseek->time); info = (msg_info *) calloc (1, sizeof (msg_info)); info->msg = mseek; info->fl = folder_seek (folder_seek_by_name (mseek->rfolder)); row = gtk_clist_prepend (GTK_CLIST (msearch_clist), cl_data); info->row = row; gtk_clist_set_row_data_full (GTK_CLIST (msearch_clist), row, (gpointer) info, NULL); } } message_clist_reset_shading (msearch_clist); //message_clist_clicked_column (message_clist, 5, NULL); gtk_clist_thaw (GTK_CLIST (msearch_clist)); searching = 0; free (att->mtype); free (att); gtk_progress_set_show_text (GTK_PROGRESS (progress), FALSE);}voidmsearch_destroy_clist_contents (GtkCList * clist){ gpointer *row; gtk_clist_freeze (clist); while ((row = gtk_clist_get_row_data (clist, 0))) { free (row); gtk_clist_remove (clist, 0); } g_list_free (found); found = NULL; gtk_clist_clear (clist); gtk_clist_thaw (clist);}voidon_message_clist_button_press_event (GtkWidget * widget, GdkEventButton * event, gpointer user_data){ int row, column; msg_info *info; if (event->type != GDK_2BUTTON_PRESS) return; gtk_clist_get_selection_info (GTK_CLIST (widget), event->x, event->y, &row, &column); info = gtk_clist_get_row_data (GTK_CLIST (widget), row); if (!info) return; gtk_widget_show (message_window_new (info));}intmsearch_check (char *this, char *that, int equal, int sim, int ignore){ if (ignore) { char *lthis = msearch_lower (this); char *lthat = msearch_lower (that); if (((strcasecmp (this, that) == 0) && (equal)) || ((strcasecmp (this, that) != 0) && (!equal) && (!sim)) || ((strstr (lthis, lthat) != NULL) && (sim))) { if (lthis) free (lthis); if (lthat) free (lthat); return 1; } } else { if (((strcmp (this, that) == 0) && (equal)) || ((strcmp (this, that) != 0) && (!equal) && (!sim)) || ((strstr (this, that) != NULL) && (sim))) return 1; } return 0;}char *msearch_lower (char *string){ char *newstring = strdup (string); int i; for (i = 0; i < strlen (string); i++) { *(newstring + i) = tolower (*(string + i)); } return newstring;}voidmsearch_cancel (void){ msearch_cancel_flag = 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -