static void imp_ldif_update_row( GtkCList *clist ) { Ldif_FieldRec *rec; gchar *text[ FIELDS_N_COLS ]; gint row; if( impldif_dlg.rowIndSelect < 0 ) return; row = impldif_dlg.rowIndSelect; rec = gtk_clist_get_row_data( clist, row ); text[ FIELD_COL_SELECT ] = ""; text[ FIELD_COL_FIELD ] = rec->tagName; text[ FIELD_COL_ATTRIB ] = rec->userName; gtk_clist_freeze( clist ); gtk_clist_remove( clist, row ); if( row == impldif_dlg.rowCount - 1 ) { gtk_clist_append( clist, text ); } else { gtk_clist_insert( clist, row, text ); } if( rec->selected ) gtk_clist_set_pixmap( clist, row, FIELD_COL_SELECT, markxpm, markxpmmask ); gtk_clist_set_row_data( clist, row, rec ); gtk_clist_thaw( clist ); }
static void clist_append_fname(GtkWidget * list, char *fname, GdkPixmap *pixmap, GdkPixmap *mask) { gint pos; gchar *str[2]; str[0] = NULL; str[1] = fname; pos = gtk_clist_append(GTK_CLIST(list), str); gtk_clist_set_pixmap(GTK_CLIST(list), pos, 0, pixmap, mask); }
static void clist_append_fname(GtkWidget * list, char *fname, GdkPixmap *pixmap, GdkPixmap *mask) { gint pos; gchar *filename, *str[2]; filename = g_filename_to_utf8(fname, -1, NULL, NULL, NULL); str[0] = NULL; str[1] = filename ? filename : fname; pos = gtk_clist_append(GTK_CLIST(list), str); gtk_clist_set_pixmap(GTK_CLIST(list), pos, 0, pixmap, mask); g_free(filename); }
static void addUserInListBox(MAINWIN *ctl, HUSER usr) { gchar *tbl[] = { "A", "*Failed*" }; int pos; tbl[1] = (char *) icqQueryUserNick(usr); pos = gtk_clist_append(GTK_CLIST(ctl->listBox),(gchar **) &tbl); gtk_clist_set_row_data(GTK_CLIST(ctl->listBox),pos,usr); gtk_clist_set_pixmap (GTK_CLIST(ctl->listBox),pos,0,ctl->iPixmap[usr->modeIcon],ctl->iBitmap[usr->modeIcon]); }
/** * Load list with LDIF fields read from file. * \param ldf LDIF control data. */ static void imp_ldif_load_fields( LdifFile *ldf ) { GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field); GList *node, *list; gchar *text[ FIELDS_N_COLS ]; impldif_dlg.rowIndSelect = -1; impldif_dlg.rowCount = 0; if( ! ldf->accessFlag ) return; gtk_clist_clear( clist ); list = ldif_get_fieldlist( ldf ); node = list; while( node ) { Ldif_FieldRec *rec = node->data; gint row; text[ FIELD_COL_RESERVED ] = ""; text[ FIELD_COL_SELECT ] = ""; text[ FIELD_COL_FIELD ] = rec->tagName; text[ FIELD_COL_ATTRIB ] = rec->userName; row = gtk_clist_append( clist, text ); gtk_clist_set_row_data( clist, row, rec ); if( rec->selected ) { gtk_clist_set_pixmap( clist, row, FIELD_COL_SELECT, markxpm, markxpmmask ); } if( rec->reserved ) { gtk_clist_set_pixmap( clist, row, FIELD_COL_RESERVED, markxpm, markxpmmask ); } impldif_dlg.rowCount++; node = g_list_next( node ); } g_list_free( list ); list = NULL; ldif_set_accessed( ldf, FALSE ); }
static void pattern_clist_update_groups (int row, unsigned newstate, unsigned oldstate) { int i; unsigned mask; for (i = 0, mask = 1; i < 3; i++, mask <<= 1) { if ((newstate & mask) != 0) { if ((oldstate & mask) == 0) { gtk_clist_set_pixmap (GTK_CLIST (pattern_clist), row, i, group_pix[i].pix, group_pix[i].mask); } } else { if ((oldstate & mask) != 0) gtk_clist_set_text (GTK_CLIST (pattern_clist), row, i, ""); } } }
static int install_update_clist(void) { FILE *in; char line[1002]; char *Pc; char *new_line[3]; int last_row_selected; int count; int len; int sdcard_install; new_line[0]=""; new_line[1]=line; new_line[2]=NULL; last_row_selected = clist_row_selected; in = jp_open_home_file(EPN".install", "r"); if (!in) { return EXIT_FAILURE; } gtk_signal_disconnect_by_func(GTK_OBJECT(clist), GTK_SIGNAL_FUNC(cb_clist_selection), NULL); gtk_clist_freeze(GTK_CLIST(clist)); gtk_clist_clear(GTK_CLIST(clist)); #ifdef __APPLE__ gtk_clist_thaw(GTK_CLIST(clist)); gtk_widget_hide(clist); gtk_widget_show_all(clist); gtk_clist_freeze(GTK_CLIST(clist)); #endif for (count=0; !feof(in); count++) { line[0]='\0'; Pc = fgets(line, 1000, in); if (!Pc) { break; } /* Strip newline characters from end of string */ len=strlen(line); if ((line[len-1]=='\n') || (line[len-1]=='\r')) line[len-1]='\0'; if ((line[len-2]=='\n') || (line[len-2]=='\r')) line[len-2]='\0'; sdcard_install = (line[0] == '\001'); /* Strip char indicating SDCARD install from start of string */ if (sdcard_install) { new_line[1] = &line[1]; } else { new_line[1] = &line[0]; } gtk_clist_append(GTK_CLIST(clist), new_line); /* Add SDCARD icon for files to be installed on SDCARD */ if (sdcard_install) { GdkPixmap *pixmap; GdkBitmap *mask; get_pixmaps(clist, PIXMAP_SDCARD, &pixmap, &mask); gtk_clist_set_pixmap(GTK_CLIST(clist), count, INST_SDCARD_COLUMN, pixmap, mask); } } fclose(in); gtk_signal_connect(GTK_OBJECT(clist), "select_row", GTK_SIGNAL_FUNC(cb_clist_selection), NULL); if (last_row_selected > count-1) { last_row_selected = count - 1; } if (last_row_selected >= 0) { clist_select_row(GTK_CLIST(clist), last_row_selected, INST_FNAME_COLUMN); } gtk_clist_thaw(GTK_CLIST(clist)); return EXIT_SUCCESS; }
void nsComponentsDlg::ToggleRowSelection(GtkWidget *aWidget, gint aRow, gboolean aToggleState) { int numRows = 0, currRow = 0; GtkStyle *style = NULL; GdkBitmap *ch_mask = NULL; GdkPixmap *checked = NULL; GdkBitmap *un_mask = NULL; GdkPixmap *unchecked = NULL; nsComponent *currComp = sCustomST->GetComponents()->GetHead(); style = gtk_widget_get_style(gCtx->window); checked = gdk_pixmap_create_from_xpm_d(gCtx->window->window, &ch_mask, &style->bg[GTK_STATE_NORMAL], (gchar **)check_on_xpm); unchecked = gdk_pixmap_create_from_xpm_d(gCtx->window->window, &un_mask, &style->bg[GTK_STATE_NORMAL], (gchar **)check_off_xpm); numRows = sCustomST->GetComponents()->GetLengthVisible(); while ((currRow < numRows) && currComp) // paranoia! { if (!currComp->IsInvisible()) { if (aRow == currRow) { // update long desc gtk_label_set_text(GTK_LABEL(sDescLong), currComp->GetDescLong()); gtk_widget_show(sDescLong); if (aToggleState) { if (currComp->IsSelected()) { DUMP("Toggling off..."); currComp->SetUnselected(); } else { DUMP("Toggling on..."); currComp->SetSelected(); } } currComp->ResolveDependees(currComp->IsSelected(), sCustomST->GetComponents()); break; } currRow++; } currComp = currComp->GetNext(); } // after resolving dependees redraw all checkboxes in one fell swoop currRow = 0; currComp = sCustomST->GetComponents()->GetHead(); while ((currRow < numRows) && currComp) // paranoia! { if (!currComp->IsInvisible()) { if (currComp->IsSelected()) { gtk_clist_set_pixmap(GTK_CLIST(aWidget), currRow, 0, checked, ch_mask); } else { gtk_clist_set_pixmap(GTK_CLIST(aWidget), currRow, 0, unchecked, un_mask); } currRow++; } currComp = currComp->GetNext(); } }
int nsComponentsDlg::Show(int aDirection) { int err = OK; int customSTIndex = 0, i; int numRows = 0; int currRow = 0; GtkWidget *hbox = NULL; XI_VERIFY(gCtx); XI_VERIFY(gCtx->notebook); if (mWidgetsInit == FALSE) { customSTIndex = gCtx->sdlg->GetNumSetupTypes(); sCustomST = gCtx->sdlg->GetSetupTypeList(); for (i=1; i<customSTIndex; i++) sCustomST = sCustomST->GetNext(); DUMP(sCustomST->GetDescShort()); // create a new table and add it as a page of the notebook mTable = gtk_table_new(5, 1, FALSE); gtk_notebook_append_page(GTK_NOTEBOOK(gCtx->notebook), mTable, NULL); mPageNum = gtk_notebook_get_current_page(GTK_NOTEBOOK(gCtx->notebook)); gtk_widget_show(mTable); // 1st row: a label (msg0) // insert a static text widget in the first row GtkWidget *msg0 = gtk_label_new(mMsg0); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), msg0, FALSE, FALSE, 0); gtk_widget_show(hbox); gtk_table_attach(GTK_TABLE(mTable), hbox, 0, 1, 1, 2, static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND), GTK_FILL, 20, 20); gtk_widget_show(msg0); // 2nd row: a CList with a check box for each row (short desc) GtkWidget *list = NULL; GtkWidget *scrollwin = NULL; GtkStyle *style = NULL; GdkBitmap *ch_mask = NULL; GdkPixmap *checked = NULL; GdkBitmap *un_mask = NULL; GdkPixmap *unchecked = NULL; gchar *dummy[2] = { " ", " " }; nsComponent *currComp = sCustomST->GetComponents()->GetHead(); GtkWidget *descLongTable = NULL; GtkWidget *frame = NULL; scrollwin = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); list = gtk_clist_new(2); gtk_clist_set_selection_mode(GTK_CLIST(list), GTK_SELECTION_BROWSE); gtk_clist_column_titles_hide(GTK_CLIST(list)); gtk_clist_set_column_auto_resize(GTK_CLIST(list), 0, TRUE); gtk_clist_set_column_auto_resize(GTK_CLIST(list), 1, TRUE); // determine number of rows we'll need numRows = sCustomST->GetComponents()->GetLengthVisible(); for (i = 0; i < numRows; i++) gtk_clist_append(GTK_CLIST(list), dummy); style = gtk_widget_get_style(gCtx->window); checked = gdk_pixmap_create_from_xpm_d(gCtx->window->window, &ch_mask, &style->bg[GTK_STATE_NORMAL], (gchar **)check_on_xpm); unchecked = gdk_pixmap_create_from_xpm_d(gCtx->window->window, &un_mask, &style->bg[GTK_STATE_NORMAL], (gchar **)check_off_xpm); while ((currRow < numRows) && currComp) // paranoia! { if (!currComp->IsInvisible()) { if (currComp->IsSelected()) gtk_clist_set_pixmap(GTK_CLIST(list), currRow, 0, checked, ch_mask); else gtk_clist_set_pixmap(GTK_CLIST(list), currRow, 0, unchecked, un_mask); gtk_clist_set_text(GTK_CLIST(list), currRow, 1, currComp->GetDescShort()); currRow++; } currComp = currComp->GetNext(); } // by default, first row selected upon Show() sCurrRowSelected = 0; gtk_signal_connect(GTK_OBJECT(list), "select_row", GTK_SIGNAL_FUNC(RowSelected), NULL); gtk_signal_connect(GTK_OBJECT(list), "key_press_event", GTK_SIGNAL_FUNC(KeyPressed), NULL); gtk_container_add(GTK_CONTAINER(scrollwin), list); gtk_widget_show(list); gtk_widget_show(scrollwin); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), scrollwin, TRUE, TRUE, 0); gtk_widget_show(hbox); gtk_table_attach(GTK_TABLE(mTable), hbox, 0, 1, 2, 3, static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND), static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 20, 0); // XXX 3rd row: labels for ds avail and ds reqd // 4th row: a frame with a label (long desc) descLongTable = gtk_table_new(1, 1, FALSE); gtk_widget_show(descLongTable); gtk_table_attach(GTK_TABLE(mTable), descLongTable, 0, 1, 4, 5, static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 20, 20); frame = gtk_frame_new(gCtx->Res("DESCRIPTION")); gtk_table_attach_defaults(GTK_TABLE(descLongTable), frame, 0, 1, 0, 1); gtk_widget_show(frame); sDescLong = gtk_label_new( sCustomST->GetComponents()->GetFirstVisible()->GetDescLong()); gtk_label_set_line_wrap(GTK_LABEL(sDescLong), TRUE); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), sDescLong, FALSE, FALSE, 20); gtk_widget_show(hbox); gtk_table_attach_defaults(GTK_TABLE(descLongTable), hbox, 0, 1, 0, 1); gtk_widget_show(sDescLong); mWidgetsInit = TRUE; } else { gtk_notebook_set_page(GTK_NOTEBOOK(gCtx->notebook), mPageNum); gtk_widget_show(mTable); } // signal connect the buttons gCtx->backID = gtk_signal_connect(GTK_OBJECT(gCtx->back), "clicked", GTK_SIGNAL_FUNC(nsComponentsDlg::Back), gCtx->cdlg); gCtx->nextID = gtk_signal_connect(GTK_OBJECT(gCtx->next), "clicked", GTK_SIGNAL_FUNC(nsComponentsDlg::Next), gCtx->cdlg); // show back btn again after setup type dlg where we couldn't go back gtk_widget_set_sensitive(gCtx->back, TRUE); if (aDirection == nsXInstallerDlg::BACKWARD_MOVE) // from install dlg gtk_button_set_label(GTK_BUTTON(gCtx->next), GTK_STOCK_GO_FORWARD); return err; }
void ghack_menu_window_add_menu( GtkWidget *menuWin, gpointer menu_item, gpointer data) { GHackMenuItem* item; GtkWidget *clist; gchar buf[BUFSZ]="", accelBuf[BUFSZ]=""; gchar *pbuf; char *text[4] = { buf, NULL, NULL, NULL }; gint nCurrentRow = -1, numItems = -1; MenuWinType isMenu; GtkStyle *bigStyle = NULL; gboolean item_selectable; GdkImlibImage* image; static gboolean special; g_assert (menu_item != NULL); item = (GHackMenuItem*) menu_item; item_selectable = ( item->identifier->a_int == 0)? FALSE : TRUE; isMenu = (MenuWinType) GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menuWin), "isMenu")); clist = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (menuWin), "clist")); g_assert (clist != NULL); /* This is a special kludge to make the special hidden help menu item work as designed */ if ( special==TRUE ) { special=FALSE; item_selectable=TRUE; } if ( ! strcmp( item->str, "The NetHack license.")) { special=TRUE; } if (item->str) { /* First, make a new blank entry in the clist */ nCurrentRow = gtk_clist_append (GTK_CLIST (clist), text); if (item->glyph != NO_GLYPH) { image = ghack_image_from_glyph( item->glyph, FALSE); if (image==NULL || image->pixmap==NULL) { g_warning("Bummer -- having to force rendering for glyph %d!", item->glyph); /* wierd -- pixmap is NULL so retry rendering it */ image = ghack_image_from_glyph( item->glyph, TRUE); } if (image==NULL || image->pixmap==NULL) { g_error("Aiiee! glyph is still NULL for item\n\"%s\"", item->str); } else gtk_clist_set_pixmap (GTK_CLIST (clist), nCurrentRow, 1, gdk_imlib_move_image( image), gdk_imlib_move_mask( image)); } if (item->accelerator) { /* FIXME: handle accelerator, */ g_snprintf(accelBuf, sizeof(accelBuf), "%c ", item->accelerator); gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 0, accelBuf); g_snprintf(buf, sizeof(buf), "%s", item->str); gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); } else { if (item->group_accel) { /* FIXME: maybe some day I should try to handle * group accelerators... */ } if (( (item->attr == 0) && (item->identifier->a_int != 0)) || (special ==TRUE) ) { numItems = GPOINTER_TO_INT( gtk_object_get_data( GTK_OBJECT(clist), "numItems") )+1; /* Ok, now invent a unique accelerator */ if ( ('a'+numItems) <= 'z' ) { g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'a'+numItems); gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); } else if ( ('A'+numItems-26)<='Z') { g_snprintf(accelBuf, sizeof(accelBuf), "%c ", 'A'+numItems-26); gtk_clist_set_text(GTK_CLIST(clist), nCurrentRow, 0, accelBuf); } else { accelBuf[0] = buf[0] = 0; } g_snprintf(buf, sizeof(buf), "%s", item->str); gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); gtk_object_set_data (GTK_OBJECT (clist), "numItems", GINT_TO_POINTER (numItems)); /* This junk is to specially handle the options menu */ pbuf = strstr( buf, " ["); if (pbuf == NULL) { pbuf = strstr( buf, "\t["); } if (pbuf != NULL) { *pbuf=0; pbuf++; gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf); } } /* FIXME: handle more than 26*2 accelerators (but how? * since I only have so many keys to work with???) else { foo(); } */ else { g_snprintf(buf, sizeof(buf), "%s", item->str); pbuf = strstr( buf, " ["); if (pbuf == NULL) { pbuf = strstr( buf, "\t["); } if (pbuf != NULL) { *pbuf=0; pbuf++; gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 3, pbuf); } gtk_clist_set_text (GTK_CLIST (clist), nCurrentRow, 2, buf); } } if (item->attr) { switch(item->attr) { case ATR_ULINE: case ATR_BOLD: case ATR_BLINK: case ATR_INVERSE: bigStyle = gtk_style_copy (GTK_WIDGET (clist)->style); g_assert (bigStyle != NULL); gdk_font_unref (bigStyle->font); bigStyle->font = gdk_font_load ( "-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*"); bigStyle->fg[GTK_STATE_NORMAL] = color_blue; gtk_clist_set_cell_style (GTK_CLIST (clist), nCurrentRow, 2, bigStyle); item_selectable = FALSE; } } g_assert (nCurrentRow >= 0); gtk_clist_set_selectable (GTK_CLIST (clist), nCurrentRow, item_selectable); if ( item_selectable==TRUE && item->presel== TRUE) { /* pre-select this item */ gtk_clist_select_row( GTK_CLIST (clist), nCurrentRow, 0); } gtk_object_set_data (GTK_OBJECT (clist), "numRows", GINT_TO_POINTER (nCurrentRow)); /* We have to allocate memory here, since the menu_item currently * lives on the stack, and will otherwise go to the great bit bucket * in the sky as soon as this function exits, which would leave a * pointer to crap in the row_data. Use g_memdup to make a private, * persistant copy of the item identifier. * * We need to arrange to blow away this memory somewhere (like * ghack_menu_destroy and ghack_menu_window_clear for example). * * -Erik */ { menuItem newItem; menuItem *pNewItem; newItem.identifier = *item->identifier; newItem.itemNumber=nCurrentRow; newItem.selected=FALSE; newItem.accelerator[0]=0; /* only copy 1 char, since accel keys are by definition 1 char */ if (accelBuf[0]) { strncpy(newItem.accelerator, accelBuf, 1); } newItem.accelerator[1]=0; pNewItem = g_memdup(&newItem, sizeof( menuItem)); gtk_clist_set_row_data (GTK_CLIST (clist), nCurrentRow, (gpointer) pNewItem); } } /* Now adjust the column widths to match the contents */ gtk_clist_columns_autosize (GTK_CLIST (clist)); }
void * check_pop_main (Account *account) { char *buf = NULL, *buf2, *buf3; C2ResolveNode *resolve; int sock; int timedout = FALSE; struct sockaddr_in server; int messages = 0, bytes = 0, downloaded_bytes = 0, i = 0, password_errors = 3; GList *download[DOWNLOAD_LIST_LAST], *uidl_search = NULL, *top_search = NULL; GList *list; gboolean supports_uidl = FALSE; mid_t mid; FILE *index; FILE *mail; Message message; char *mailbox; Mailbox *mbox; GString *strmsg; char *header[HEADER_LAST]; gboolean reading_header = TRUE; gboolean with_attachs = FALSE; char *content_type; char *row[8]; GtkStyle *style, *style2; gboolean clisted = FALSE; g_return_val_if_fail (account, NULL); g_return_val_if_fail (account->type == C2_ACCOUNT_POP, NULL); download[DOWNLOAD_LIST_TOTAL] = NULL; download[DOWNLOAD_LIST_UIDL] = NULL; download[DOWNLOAD_LIST_TOP] = NULL; resolve = c2_resolve (account->protocol.pop.host, &buf); if (buf) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); return NULL; } sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, _("Failed to create socket")); gdk_threads_leave (); return NULL; } server.sin_family = AF_INET; server.sin_port = htons (account->protocol.pop.host_port); server.sin_addr.s_addr= inet_addr (resolve->ip); if (connect (sock, (struct sockaddr *)&server, sizeof (server)) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); return NULL; } /* Guten Morgen, Herr Server! */ buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } c2_free (buf); /* Log In */ gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("Logging in...")); gdk_threads_leave (); retry_login: if (sock_printf (sock, "USER %s\r\n", account->protocol.pop.usr_name) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } c2_free (buf); if (sock_printf (sock, "PASS %s\r\n", account->protocol.pop.pass) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (strnne (buf, "+OK", 3)) { if (--password_errors < 0) { if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } } gdk_threads_enter (); if (!gui_ask_password (account)) { gdk_threads_leave (); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } } else { gdk_threads_leave (); goto retry_login; } } c2_free (buf); /* STAT */ gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("Checking for number of mails in server...")); gdk_threads_leave (); if (sock_printf (sock, "STAT\r\n") < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } sscanf (buf, "+OK %d ", &messages); c2_free (buf); if (!messages) { gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("No messages in server")); window_checking_report (C2_CHECK_OK, account->acc_name, _("No messages to download")); gdk_threads_leave (); clisted = TRUE; goto bye_bye_server; } else if (messages != 1) buf = g_strdup_printf (_("%d messages in server"), messages); else buf = g_strdup_printf (_("1 message in server")); gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), buf); gdk_threads_leave (); c2_free (buf); /* UIDL */ if (!account->keep_copy) { dont_use_uidl: /* Without UIDL*/ for (i = 1; i <= messages; i++) { buf = g_strdup_printf ("%d", i); download[DOWNLOAD_LIST_UIDL] = g_list_append (download[DOWNLOAD_LIST_UIDL], (gpointer) buf); } } else { /* With UIDL */ if (sock_printf (sock, "UIDL\r\n") < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } for (i = 0;; i++) { buf = sock_read (sock, &timedout); if (!i && strnne (buf, "+OK", 3)) { /* UIDL is optional for POP servers, * so I won't complain if server doesn't like it */ buf2 = g_strdup_printf (_("The POP server of the account %s doesn't support UIDL."), account->acc_name); gdk_threads_enter (); gnome_appbar_set_status (GNOME_APPBAR (WMain->appbar), buf2); gdk_threads_leave (); supports_uidl = FALSE; goto dont_use_uidl; } supports_uidl = TRUE; if (!i) continue; if (streq (buf, ".\r\n")) break; buf2 = str_get_word (1, buf, ' '); buf3 = str_strip (buf2, '\r'); buf2 = str_strip (buf3, '\n'); if (!uidl_check (buf2, account->acc_name)) { download[DOWNLOAD_LIST_UIDL] = g_list_append (download[DOWNLOAD_LIST_UIDL], buf); } } } /* TOP */ if (!config->message_bigger) { /* Without TOP */ dont_use_list: dont_use_top: for (i = 1; i <= messages; i++) download[DOWNLOAD_LIST_TOP] = g_list_append (download[DOWNLOAD_LIST_TOP], (gpointer) i); } else { /* With TOP */ char *subject, *from, *date, *kbytes; if (sock_printf (sock, "LIST\r\n") < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } for (i = 0;; i++) { buf = sock_read (sock, &timedout); if (!i && strnne (buf, "+OK", 3)) { buf2 = g_strdup_printf (_("The POP server of the account %s doesn't support LIST."), account->acc_name); gdk_threads_enter (); gnome_appbar_set_status (GNOME_APPBAR (WMain->appbar), buf2); gdk_threads_leave (); goto dont_use_list; } if (!i) continue; if (streq (buf, ".\r\n")) break; buf2 = str_get_word (1, buf, ' '); str_strip (buf2, '\r'); str_strip (buf2, '\n'); download[DOWNLOAD_LIST_TOP] = g_list_append (download[DOWNLOAD_LIST_TOP], buf); c2_free (buf2); } for (list = download[DOWNLOAD_LIST_TOP]; list; list = list->next) { if (sock_printf (sock, "TOP %d 0\r\n", atoi (CHAR (list->data))) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } strmsg = g_string_new (NULL); for (i = 0;; i++) { buf = sock_read (sock, &timedout); if (!i && strnne (buf, "+OK", 3)) { buf2 = g_strdup_printf (_("The POP server of the account %s doesn't support TOP."), account->acc_name); gdk_threads_enter (); gnome_appbar_set_status (GNOME_APPBAR (WMain->appbar), buf2); gdk_threads_leave (); goto dont_use_top; } if (!i) continue; if (streq (buf, ".\r\n")) break; g_string_append (strmsg, buf); c2_free (buf); } subject = message_get_header_field (NULL, strmsg->str, "\nSubject:"); from = message_get_header_field (NULL, strmsg->str, "From:"); date = message_get_header_field (NULL, strmsg->str, "\nDate:"); kbytes = str_get_word (1, CHAR (list->data), ' '); str_strip (kbytes, '\r');str_strip (kbytes, '\n'); gdk_threads_enter (); if ((atoi (kbytes) >= config->message_bigger*1024) && (!gui_message_big_new (from, subject, date, account->acc_name, kbytes))) { gdk_threads_leave (); c2_free (list->data); list->data = NULL; download[DOWNLOAD_LIST_TOP] = g_list_remove_link (download[DOWNLOAD_LIST_TOP], list); } else gdk_threads_leave (); } } /* Learn messages to download */ if (!account->keep_copy && !config->message_bigger) { /* !UIDL AND !TOP */ download[DOWNLOAD_LIST_TOTAL] = download[DOWNLOAD_LIST_UIDL]; } else if (account->keep_copy && !config->message_bigger) { /* UIDL AND !TOP */ for (list = download[DOWNLOAD_LIST_UIDL]; list; list = list->next) { download[DOWNLOAD_LIST_TOTAL] = g_list_append (download[DOWNLOAD_LIST_TOTAL], str_get_word (0, CHAR (list->data), ' ')); } } else if (!account->keep_copy && config->message_bigger) { /* !UIDL AND TOP */ download[DOWNLOAD_LIST_TOTAL] = download[DOWNLOAD_LIST_TOP]; } else if (account->keep_copy && config->message_bigger) { /* UIDL AND TOP */ for (uidl_search = download[DOWNLOAD_LIST_UIDL]; !uidl_search; uidl_search = uidl_search->next) { for (top_search = download[DOWNLOAD_LIST_TOP]; !top_search; top_search = top_search->next) { printf ("%d %d\n", (int) uidl_search->data, (int) top_search->data); /* TODO */ } } } messages = g_list_length (download[DOWNLOAD_LIST_TOTAL]); gdk_threads_enter (); gtk_progress_configure (GTK_PROGRESS (window_checking->mail_progress), 0, 0, messages); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("%p%% downloaded (%v of %u messages)")); gdk_threads_leave (); strmsg = g_string_new (NULL); message.message = message.header = NULL; for (list = download[DOWNLOAD_LIST_TOTAL]; list; list = list->next) { buf = str_get_word (0, CHAR (list->data), ' '); i = atoi (buf); c2_free (buf); /* Ask for the mail */ if (sock_printf (sock, "RETR %d\r\n", i) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } /* Read the first line */ buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } /* Learn bytes in the messages */ sscanf (buf, "+OK %d octets\r\n", &bytes); if (bytes) { gdk_threads_enter (); gtk_progress_configure (GTK_PROGRESS (window_checking->bytes_progress), 0, 0, bytes); gtk_widget_show (window_checking->bytes_progress); gdk_threads_leave (); } else { gdk_threads_enter (); gtk_widget_hide (window_checking->bytes_progress); gdk_threads_leave (); } c2_free (buf); /* Get the mail */ reading_header = TRUE; for (;;) { buf = sock_read (sock, &timedout); if (bytes) { downloaded_bytes += strlen (buf); gdk_threads_enter (); gtk_progress_set_value (GTK_PROGRESS (window_checking->bytes_progress), downloaded_bytes); gdk_threads_leave (); } if (streq (buf, ".\r\n")) { message.message = g_strdup (strmsg->str); g_string_assign (strmsg, ""); str_strip (message.message, '\r'); break; } if (reading_header && strlen (buf) > 2) { char *buf2; buf2 = decode_8bit (buf); c2_free (buf); buf = buf2; } if (reading_header && strlen (buf) == 2) { /* Still reading header and is an empty line */ buf2 = g_strdup_printf ("X-CronosII-Account: %s\r\n", account->acc_name); g_string_append (strmsg, buf2); c2_free (buf2); reading_header = FALSE; } g_string_append (strmsg, buf); } gtk_progress_set_percentage (GTK_PROGRESS (window_checking->bytes_progress), 1); /* Write to the mail file */ mailbox = account->mailbox->name; #if USE_PLUGINS c2_dynamic_module_signal_emit (C2_DYNAMIC_MODULE_MESSAGE_DOWNLOAD_POP, &message, &mailbox, NULL, NULL, NULL); #endif mbox = search_mailbox_name (config->mailbox_head, mailbox); if (!mbox) { /* Mailbox couldn't be found, going with the default */ mbox = account->mailbox; } mid = c2_mailbox_get_next_mid (mbox); buf = c2_mailbox_mail_path (mailbox, mid); if ((mail = fopen (buf, "w")) == NULL) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, _("Error opening the file where to store the new mail")); cronos_error (errno, _("Opening the mail file"), ERROR_WARNING); gdk_threads_leave (); c2_free (buf); continue; } c2_free (buf); fprintf (mail, "%s", message.message); fclose (mail); /* Write to the index file */ buf = c2_mailbox_index_path (mailbox); if ((index = fopen (buf, "a")) == NULL) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, _("Error opening the main DB file to store the new mail")); cronos_error (errno, _("Opening the main DB file"), ERROR_WARNING); gdk_threads_leave (); c2_free (buf); goto bye_bye_server; } header[HEADER_SUBJECT] = message_get_header_field (&message, NULL, "\nSubject:"); header[HEADER_FROM] = message_get_header_field (&message, NULL, "\nFrom:"); header[HEADER_DATE] = message_get_header_field (&message, NULL, "\nDate:"); content_type = message_get_header_field (&message, NULL, "\nContent-Type:"); with_attachs = FALSE; /* if (content_type) { message_mime_parse_content_type (content_type, &type, &subtype, ¶meter); if (streq (type, "multipart")) { GList *s; MimeHash *mime; message_mime_parse (&message, NULL); for (s = message.mime; s != NULL; s = s->next) { mime = MIMEHASH (s->data); if (!mime) continue; if (strneq (mime->disposition, "attachment", 10)) with_attachs = TRUE; } } }*/ if (!header[HEADER_SUBJECT]) header[HEADER_SUBJECT] = ""; if (!header[HEADER_FROM]) header[HEADER_FROM] = ""; if (!header[HEADER_DATE]) header[HEADER_DATE] = ""; fprintf (index, "N\r\r%s\r%s\r%s\r%s\r%s\r%d\n", with_attachs ? "1" : "", header[HEADER_SUBJECT], header[HEADER_FROM], header[HEADER_DATE], account->acc_name, mid); fclose (index); c2_free (message.message); c2_free (message.header); message.message = message.header = NULL; if (!account->keep_copy) { /* Delete the message */ if (sock_printf (sock, "DELE %d\r\n", i) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } } if (streq (selected_mbox, mailbox)) { row[0] = ""; row[1] = ""; row[2] = ""; row[3] = header[HEADER_SUBJECT]; row[4] = header[HEADER_FROM]; row[5] = header[HEADER_DATE]; row[6] = account->acc_name; row[7] = g_strdup_printf ("%d", mid); gdk_threads_enter (); gtk_clist_freeze (GTK_CLIST (WMain->clist)); gtk_clist_append (GTK_CLIST (WMain->clist), row); style = gtk_widget_get_style (WMain->clist); style2 = gtk_style_copy (style); style2->font = font_unread; gtk_clist_set_row_style (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, style2); gtk_clist_set_pixmap (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, 0, pixmap_unread, mask_unread); if (with_attachs) gtk_clist_set_pixmap (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, 2, pixmap_attach, mask_attach); new_messages++; gtk_clist_thaw (GTK_CLIST (WMain->clist)); gtk_clist_set_row_data (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, (gpointer) "N"); update_wm_title (); gtk_progress_set_value (GTK_PROGRESS (window_checking->mail_progress), i); gdk_threads_leave (); clisted = TRUE; } gdk_threads_enter (); gtk_progress_set_value (GTK_PROGRESS (window_checking->mail_progress), gtk_progress_get_value (GTK_PROGRESS (window_checking->mail_progress))+1); gdk_threads_leave (); } if (supports_uidl) { GList *llist; for (llist = download[DOWNLOAD_LIST_UIDL]; llist != NULL; llist = llist->next) { char *uidl; uidl = CHAR (llist->data); buf2 = str_get_word (1, uidl, ' '); buf3 = str_strip (buf2, '\r'); buf2 = str_strip (buf3, '\n'); if (buf2) { uidl_register (buf2, account->acc_name); } } } if (messages != 1) buf = g_strdup_printf (_("%d messages downloaded."), messages); else buf = g_strdup_printf (_("1 message downloaded.")); gdk_threads_enter (); gtk_progress_configure (GTK_PROGRESS (window_checking->mail_progress), messages, 0, messages); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), buf); window_checking_report (C2_CHECK_OK, account->acc_name, buf); gdk_threads_leave (); bye_bye_server: if (sock_printf (sock, "QUIT\r\n") < 0) { buf = g_strerror (errno); } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; } run_for_your_life: close (sock); return NULL; }