int main(int argc, char *argv[]) { GtkWidget *app; GnomeAppBar *bar; GtkWidget *frame; //初始化 //setlocale(LC_ALL, ""); gnome_init(PACKAGE, "1.0", argc, argv); bindtextdomain( PACKAGE, "/usr/share/locale"); textdomain( PACKAGE ); //建立主窗口 app = gnome_app_new (PACKAGE, "GNOME Style Programming"); gtk_signal_connect (GTK_OBJECT (app), "delete_event", GTK_SIGNAL_FUNC (quit_cb), NULL); //建立菜单 gnome_app_create_menus (GNOME_APP (app), helper_main_menu); //建立按钮 gnome_app_create_toolbar (GNOME_APP (app), helper_toolbar); //建立状态条 bar = GNOME_APPBAR( gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER)); gnome_app_set_statusbar(GNOME_APP(app), GTK_WIDGET(bar)); //在状态条上显示菜单提示 gnome_app_install_appbar_menu_hints(GNOME_APPBAR(bar), helper_main_menu); //---- 主要工作区域 --------------------------- frame = gtk_frame_new (_("Main Work Area")); gtk_widget_set_usize(frame, 640, 480); gtk_widget_show (frame); //------------------------------- //加入组件 gnome_app_set_contents ( GNOME_APP (app), frame); //显示组件 gtk_widget_show (app); gtk_main (); return 0; }
// remember to use "%%" in the format string to output a literal '%' void mystatus(const char *format, ...) { va_list args; gchar buffer[200]; va_start(args, format); g_vsnprintf(buffer, 200, format, args); gnome_appbar_set_status(GNOME_APPBAR(glade_xml_get_widget(my_glade_xml, "appbar1")), buffer); va_end(args); }
void c2_html_gtkhtml_on_url (GtkHTML *gtkhtml, const gchar *url, gpointer data) { C2Mutex *mutex; if (!GNOME_IS_APPBAR (C2_HTML (gtkhtml)->appbar)) return; mutex = C2_HTML (gtkhtml)->appbar_lock; if (mutex) { if (c2_mutex_trylock (mutex)) return; } gnome_appbar_set_status (GNOME_APPBAR (C2_HTML (gtkhtml)->appbar), url ? url : ""); c2_mutex_unlock (mutex); }
int main (int argc, char *argv []) { GtkWidget *label; GnomeClient *client; gnome_score_init("same-gnome"); bindtextdomain (PACKAGE, GNOMELOCALEDIR); textdomain (PACKAGE); gnome_init_with_popt_table ("same-gnome", VERSION, argc, argv, options, 0, NULL); gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/gnome-gsame.png"); client= gnome_master_client (); gtk_signal_connect (GTK_OBJECT (client), "save_yourself", GTK_SIGNAL_FUNC (save_state), argv[0]); gtk_signal_connect (GTK_OBJECT (client), "die", GTK_SIGNAL_FUNC (client_die), NULL); if (GNOME_CLIENT_RESTARTED (client)){ gnome_config_push_prefix (gnome_client_get_config_prefix (client)); restart (); restarted = 1; gnome_config_pop_prefix (); } srand (time (NULL)); app = gnome_app_new("same-gnome", _("Same Gnome")); gtk_window_set_policy(GTK_WINDOW(app), FALSE, FALSE, TRUE); gtk_signal_connect (GTK_OBJECT(app), "delete_event", (GtkSignalFunc)game_quit_callback, NULL); appbar = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER); gnome_app_set_statusbar(GNOME_APP (app), GTK_WIDGET(appbar)); gnome_appbar_set_status(GNOME_APPBAR (appbar), _("Welcome to Same Gnome!")); gnome_app_create_menus(GNOME_APP(app), mainmenu); gnome_app_install_menu_hints(GNOME_APP (app), mainmenu); vb = gtk_vbox_new (FALSE, 0); gnome_app_set_contents (GNOME_APP (app), vb); if (!fname) { fname = gnome_config_get_string ("/same-gnome/Preferences/Scenario=stones.png"); } create_same_board (fname); label = gtk_label_new (_("Score: ")); scorew = gtk_label_new (""); set_score (score); gtk_box_pack_start(GTK_BOX(appbar), label, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(appbar), scorew, FALSE, TRUE, 0); if (!restarted) new_game (); g_free (fname); gtk_widget_show (vb); gtk_widget_show (GTK_WIDGET(label)); gtk_widget_show (GTK_WIDGET(scorew)); gtk_widget_show (app); gtk_main (); return 0; }
main(int argc, char *argv[]) { int n; int rows, cols; int drawButtons; char *btn_font, *disp_font; /* GtkWidget *main_w; */ GtkWidget *vbox; GtkWidget *menu; GtkWidget *mdisp; GtkWidget *lcd; GtkWidget *btns; GdkFont *new_font; GtkStyle *default_style, *new_style; GdkBitmap *icon_bitmap; #ifdef USE_GNOME GnomeAppBar *appbar; #endif setlocale(LC_ALL, "C"); #ifdef USE_GNOME gnome_init("grpn", "1.0", argc, argv); gnome_app_new("grpn", "grpn"); #else /* initialize gtk */ gtk_init(&argc, &argv); #endif /* initial values */ drawButtons = 1; rows = 8; cols = 30; btn_font = disp_font = NULL; /* process command line args */ n = 1; while(n < argc){ if(0 == strcmp("-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -fn."); exit(0); } btn_font = disp_font = argv[n]; } else if(0 == strcmp("-btn-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -btn-fn."); exit(0); } btn_font = argv[n]; } else if(0 == strcmp("-disp-fn", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -disp-fn."); exit(0); } disp_font = argv[n]; } else if(0 == strcmp("-rows", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -rows."); exit(0); } if(1 != sscanf(argv[n], "%d", &rows)){ usage("Unable to read number or rows."); exit(0); } } else if(0 == strcmp("-cols", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -cols."); exit(0); } if(1 != sscanf(argv[n], "%d", &cols)){ usage("Unable to read number or cols."); exit(0); } } else if(0 == strcmp("-b", argv[n])){ drawButtons = 0; } else if(0 == strcmp("-bm", argv[n])){ n++; if(n >= argc){ usage("Missing required argument for -m."); exit(0); } if (0 == strcmp("dec", argv[n])){ setBaseMode(DECIMAL); } else if (0 == strcmp("eng", argv[n])){ setBaseMode(DECIMAL_ENG); } else if (0 == strcmp("bin", argv[n])){ setBaseMode(BINARY); } else if (0 == strcmp("oct", argv[n])){ setBaseMode(OCTAL); } else if (0 == strcmp("hex", argv[n])){ setBaseMode(HEXADECIMAL); } else { usage("Specify dec, eng, bin, oct or hex for -m."); exit(0); } } else { usage("Unknown Argument."); exit(0); } n++; } /* set up any constants we may use */ setup_constant(); /* initialize the undo system */ initUndoSystem(); /* setup the stack */ if(0 == setup_stack()){ fprintf(stderr, "Error: Could not initalize data structures.\n"); exit(0); } /* set the font if told */ if(btn_font != NULL){ default_style = gtk_widget_get_default_style(); if(NULL == (new_font = gdk_font_load(btn_font))){ fprintf(stderr, "Unable to load font %s.\n", btn_font); exit(0); } new_style = gtk_style_copy(default_style); new_style->font_desc = new_font; /* BDD - No longer in Gtk2.x */ /* gtk_widget_set_default_style(new_style); */ } #ifdef USE_GNOME main_w = gnome_app_new("grpn", "grpn"); setup_menu(main_w); appbar = GNOME_APPBAR(gnome_appbar_new(FALSE, FALSE, FALSE)); gnome_app_set_statusbar(GNOME_APP(main_w), GTK_WIDGET(appbar)); /*create the box that everyone goes in */ vbox = gtk_vbox_new(FALSE, 0); gnome_app_set_contents(GNOME_APP(main_w), vbox); gtk_widget_show(vbox); #else /* the main window contains the work area and the menubar */ main_w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_name(main_w, "grpn"); /*create the box that everyone goes in */ vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(main_w), vbox); gtk_widget_show(vbox); /* set up the menu bar */ menu = setup_menu(vbox); #endif /* handle window manager close */ gtk_signal_connect(GTK_OBJECT(main_w), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL); gtk_signal_connect(GTK_OBJECT(main_w), "destroy", GTK_SIGNAL_FUNC(destroy), NULL); /* create the varrious subsystems */ mdisp = setupModeDisplay(vbox); if(drawButtons) btns = setupButtons(vbox); lcd = setupLCD(vbox, rows, cols, disp_font); /* Create pixmap of depth 1 (bitmap) for icon */ gtk_widget_realize(main_w); icon_bitmap = gdk_bitmap_create_from_data(main_w->window, icon_bitmap_bits, icon_bitmap_width, icon_bitmap_height); gdk_window_set_icon(main_w->window, NULL, icon_bitmap, NULL); gtk_widget_show(main_w); gtk_main(); }
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; }
inline void set_status_text(const gchar *txt) { gnome_appbar_set_status(GNOME_APPBAR(sp->status), txt); }
/* a mailbox was clicked * TODO: this is called twice on keypress... up and down? */ void on_mailboxlist_tree_select_row (GtkCTree * ctree, GList * UNUSED(node), gint UNUSED(column), gpointer UNUSED(user_data)) { GtkWidget *mailbox, *stat; GtkCTreeNode *n; GtkCList *clist; GtkWidget *appbar; gchar *text[3]; synopsis **syn; int x = 0, mboxcount; mboxview *m; n = gtk_ctree_node_nth (ctree, (&(ctree->clist))->focus_row); m = (mboxview *) gtk_ctree_node_get_row_data (ctree, n); if (m == NULL) { printf (_("Bad mbox (null)\n")); exit (-1); } stat = lookup_widget (gems, "appbar1"); mailbox = lookup_widget (gems, "mailbox"); appbar = lookup_widget (gems, "appbar1"); /*** TODO *** clear the mail things */ putmail (NULL); gnome_appbar_push (GNOME_APPBAR (stat), _("Reading synopsis")); while (gtk_events_pending ()) gtk_main_iteration (); syn = (synopsis **) db_read_synopsis (m->mailbox->id, m->status); gnome_appbar_pop (GNOME_APPBAR (stat)); gnome_appbar_push (GNOME_APPBAR (stat), _("Displaying mailbox")); while (gtk_events_pending ()) gtk_main_iteration (); clist = >K_CTREE (mailbox)->clist; gtk_clist_clear (clist); while (gtk_events_pending ()) gtk_main_iteration (); gtk_clist_freeze (clist); if(syn) { mboxcount = 0; while (syn[mboxcount] != NULL) mboxcount++; while (syn[x] != NULL) { GtkCTreeNode *n; text[0] = syn[x]->sender; text[1] = syn[x]->date; text[2] = syn[x]->subject; n = gtk_ctree_insert_node (GTK_CTREE (mailbox), NULL, NULL, text, 5, NULL, NULL, NULL, NULL, TRUE, TRUE); gtk_ctree_node_set_row_data (GTK_CTREE (mailbox), n, syn[x]); gnome_appbar_set_progress (GNOME_APPBAR (appbar), (float)x / (float)mboxcount); /* * pump the status bar */ if (gtk_events_pending ()) gtk_main_iteration (); x++; } free (syn); } gtk_clist_set_sort_column (clist, 1); gtk_clist_set_sort_type (clist, GTK_SORT_ASCENDING); gtk_clist_sort (clist); gtk_clist_thaw (clist); update_mboxlist (NULL); gnome_appbar_set_progress (GNOME_APPBAR (appbar), 0.0); gnome_appbar_pop (GNOME_APPBAR (stat)); /* * gtk_signal_handler_unblock(GTK_OBJECT(ctree), select_row); */ }
static void create_app_helper (GtkWidget *widget, gpointer data) { GtkWidget *app; GtkWidget *vbox; GtkWidget *frame; GtkWidget *vbox2; GtkWidget *w; GtkWidget *popup; GnomeAppBar *bar; GnomeCanvasItem *item; app = gnome_app_new ("testGNOME", "GnomeAppHelper test"); gnome_app_create_menus (GNOME_APP (app), helper_main_menu); gnome_app_create_toolbar (GNOME_APP (app), helper_toolbar); bar = GNOME_APPBAR(gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER)); gnome_app_set_statusbar(GNOME_APP(app), GTK_WIDGET(bar)); gnome_app_install_appbar_menu_hints(GNOME_APPBAR(bar), helper_main_menu); vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL); /* Shared popup menu */ popup = gnome_popup_menu_new (helper_shared_popup); frame = gtk_frame_new ("Shared popup menu"); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); vbox2 = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); gtk_container_set_border_width (GTK_CONTAINER (vbox2), GNOME_PAD_SMALL); gtk_container_add (GTK_CONTAINER (frame), vbox2); gtk_widget_show (vbox2); w = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (vbox2), w, FALSE, FALSE, 0); gtk_widget_show (w); gnome_popup_menu_attach (popup, w, w); w = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (vbox2), w, FALSE, FALSE, 0); gtk_widget_show (w); gnome_popup_menu_attach (popup, w, w); /* Popup menu explicitly popped */ popup = gnome_popup_menu_new (helper_explicit_popup); frame = gtk_frame_new ("Explicit popup menu"); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); gtk_widget_show (frame); w = gnome_canvas_new (); gtk_widget_set_size_request ((w), 200, 100); gnome_canvas_set_scroll_region (GNOME_CANVAS (w), 0.0, 0.0, 200.0, 100.0); gtk_container_add (GTK_CONTAINER (frame), w); gtk_widget_show (w); g_signal_connect (w, "destroy", G_CALLBACK (delete_event), popup); item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (w)), gnome_canvas_ellipse_get_type (), "x1", 5.0, "y1", 5.0, "x2", 95.0, "y2", 95.0, "fill_color", "white", "outline_color", "black", NULL); g_signal_connect (item, "event", G_CALLBACK (item_event), popup); item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (w)), gnome_canvas_ellipse_get_type (), "x1", 105.0, "y1", 0.0, "x2", 195.0, "y2", 95.0, "fill_color", "white", "outline_color", "black", NULL); g_signal_connect (item, "event", G_CALLBACK (item_event), popup); gnome_app_set_contents (GNOME_APP (app), vbox); gtk_widget_show (app); }
/** * @fn GtkWidget* create_mainwin (void) * Crea la ventana principal */ GtkWidget* create_mainwin (void) { GtkWidget *app1; GtkWidget *dock1; GtkWidget *eventbox1; GtkWidget *viewport1; GtkWidget *vbox_main; GtkWidget *vbox_paned; GtkWidget *scrolledwindow; GtkWidget *paned; GtkWidget *text; GtkWidget *inputline; GtkWidget *sw; GtkWidget *ahbox; app1 = gnome_app_new ( PACKAGE, "Tenes Empanadas Graciela"); gtk_object_set_data (GTK_OBJECT (app1), "app1", app1); gtk_window_set_default_size (GTK_WINDOW (app1), 664, 640); gtk_window_set_policy (GTK_WINDOW (app1), TRUE, TRUE, FALSE); dock1 = GNOME_APP (app1)->dock; gtk_widget_ref (dock1); gtk_object_set_data_full (GTK_OBJECT (app1), "dock1", dock1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (dock1); gnome_app_create_menus (GNOME_APP (app1), menubar_uiinfo); gnome_app_create_toolbar(GNOME_APP(app1), toolbar_main); /* TODO: ask in GNOME if this is wanted */ /* gtk_menu_item_right_justify( GTK_MENU_ITEM(menubar_uiinfo[4].widget)); */ gtk_widget_realize (app1); gtk_signal_connect ( GTK_OBJECT(app1), "destroy", GTK_SIGNAL_FUNC( on_exit_activate ), NULL ); gtk_signal_connect ( GTK_OBJECT(app1), "delete_event", GTK_SIGNAL_FUNC( on_exit_activate ), NULL ); SensiData.connect_button = toolbar_main[0].widget; SensiData.start_button = toolbar_main[1].widget; /* 2 is a separator */ SensiData.enviarfichas_button = toolbar_main[3].widget; SensiData.reagrupe_button = toolbar_main[4].widget; SensiData.getcard_button = toolbar_main[5].widget; SensiData.endturn_button = toolbar_main[6].widget; /* 7 is a separator */ SensiData.status_button = toolbar_main[8].widget; eventbox1 = gtk_event_box_new (); gtk_widget_ref (eventbox1); gtk_object_set_data_full (GTK_OBJECT (app1), "eventbox1", eventbox1, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (eventbox1); gnome_app_set_contents (GNOME_APP (app1), eventbox1); viewport1 = gtk_viewport_new (NULL, NULL); gtk_widget_show (viewport1); gtk_container_add (GTK_CONTAINER (eventbox1), viewport1); vbox_main = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox_main); gtk_container_add (GTK_CONTAINER (viewport1), vbox_main); /* status map */ if( mainstatus_create(&window_mainstatus) != TEG_STATUS_SUCCESS ) goto error; gtk_box_pack_start( GTK_BOX(vbox_main), window_mainstatus, FALSE,FALSE,0); /* paned */ paned = gtk_vpaned_new(); gtk_box_pack_start( GTK_BOX( vbox_main ), paned, TRUE, TRUE, 0 ); vbox_paned = gtk_vbox_new (FALSE, 0); gtk_paned_add1(GTK_PANED(paned), vbox_paned); gtk_widget_show (vbox_paned); /* map */ scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_widget_set_usize(scrolledwindow, 640, 394); if( canvas_create_map() != TEG_STATUS_SUCCESS ) goto error; gtk_container_add(GTK_CONTAINER(scrolledwindow), canvas_map); gtk_container_add(GTK_CONTAINER(vbox_paned),scrolledwindow); gtk_widget_show (canvas_map); gtk_widget_show (scrolledwindow); /* text */ ahbox = gtk_hbox_new(FALSE, 2); gtk_paned_pack2(GTK_PANED(paned), ahbox, TRUE, TRUE); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_box_pack_start(GTK_BOX(ahbox), sw, TRUE, TRUE, 0); gtk_widget_set_size_request(sw, 620, 60); text = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); gtk_container_add(GTK_CONTAINER(sw), text); gtk_widget_set_name(text, "chatline"); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD); gtk_widget_realize(text); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5); main_message_area = GTK_TEXT_VIEW(text); /* set_output_window_text(_("Tenes Empanadas Graciela")); */ gtk_widget_show(text); gtk_widget_show(sw); gtk_widget_show(ahbox); gtk_widget_show(paned); /* the chat line */ inputline = gtk_entry_new(); gtk_box_pack_start( GTK_BOX( vbox_main ), inputline, FALSE, FALSE, 0 ); gtk_widget_show(inputline); g_signal_connect(inputline, "activate", G_CALLBACK(inputline_return), NULL); chatline_init(); /* status bar */ statusbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_NEVER); gtk_widget_ref (statusbar); gtk_object_set_data_full (GTK_OBJECT (app1), "statusbar", statusbar, (GtkDestroyNotify) gtk_widget_unref); gtk_widget_show (statusbar); gnome_app_set_statusbar (GNOME_APP (app1), statusbar); gtk_box_pack_start(GTK_BOX(statusbar), ministatus_build(), FALSE, TRUE, 0); gnome_appbar_set_status(GNOME_APPBAR(statusbar), _("Welcome to TEG!")); gnome_app_install_menu_hints( GNOME_APP(app1), menubar_uiinfo ); /* icono */ { GdkBitmap *mask; GdkPixmap *icono; #include "../teg_pix/teg_icono.xpm" gtk_widget_realize (app1); icono = gdk_pixmap_create_from_xpm_d( app1->window, &mask, &app1->style->bg[GTK_STATE_NORMAL],teg_icono_xpm ); gdk_window_set_icon (app1->window, NULL, icono , mask ); } gtk_widget_show(app1); return app1; error: g_error(_("Unable to create map!")); return NULL; }