/* main */ int main(void) { int ret = 0; Mime * mime; struct { char const * filename; char const * type; } tests[] = { { "Makefile", "text/x-makefile" }, { "../include/Desktop/mime.h", "text/x-chdr" }, { "mime.c", "text/x-csrc" } }; size_t i; char const * p; if((mime = mime_new(NULL)) == NULL) return 2; for(i = 0; i < sizeof(tests) / sizeof(*tests); i++) if((p = mime_type(mime, tests[i].filename)) == NULL) /* XXX ignore this as shared-mime-info may be missing */ printf("%s: %s (expected: %s)\n", tests[i].filename, "Unknown type", tests[i].type); else if(strcmp(tests[i].type, p) != 0) { printf("%s: %s (expected: %s)\n", tests[i].filename, p, tests[i].type); ret = 3; } else printf("%s: %s\n", tests[i].filename, p); mime_delete(mime); return ret; }
/* vfs */ static int _vfs(void) { int ret = 0; Mime * mime; char const downloads[] = "/home/user/Downloads"; char const * type; GdkPixbuf * icon; if((mime = mime_new(NULL)) == NULL) return -1; if((type = browser_vfs_mime_type(mime, downloads, S_IFDIR)) == NULL || strcmp(type, "inode/directory") != 0) ret = -1; else printf("%s\n", type); if((icon = browser_vfs_mime_icon(mime, downloads, type, NULL, NULL, 48)) != NULL) g_object_unref(icon); mime_delete(mime); return ret; }
Compose * compose_new(Config * config) { Compose * compose; GtkAccelGroup * group; GtkWidget * vbox; GtkWidget * toolbar; GtkToolItem * toolitem; GtkSizeGroup * sizegroup; GtkWidget * vpaned; GtkWidget * vbox2; GtkWidget * widget; GtkCellRenderer * renderer; GtkTreeViewColumn * column; GtkTreeIter iter; char const * headers[] = { "To:", "Cc:", "Bcc:", "Reply-To:", "Newsgroup:", "Followup-To:" }; size_t i; if((compose = malloc(sizeof(*compose))) == NULL) { compose_error(NULL, strerror(errno), 0); return NULL; } compose->mime = mime_new(NULL); /* check errors */ if(compose->mime == NULL) { free(compose); return NULL; } compose->config = config; compose->standalone = FALSE; /* window */ group = gtk_accel_group_new(); compose->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_add_accel_group(GTK_WINDOW(compose->window), group); #ifndef EMBEDDED gtk_window_set_default_size(GTK_WINDOW(compose->window), 512, 384); #else gtk_window_set_default_size(GTK_WINDOW(compose->window), 200, 300); #endif gtk_window_set_title(GTK_WINDOW(compose->window), _("Compose")); #if GTK_CHECK_VERSION(2, 6, 0) gtk_window_set_icon_name(GTK_WINDOW(compose->window), "mailer"); #endif g_signal_connect_swapped(G_OBJECT(compose->window), "delete-event", G_CALLBACK(_compose_on_closex), compose); vbox = gtk_vbox_new(FALSE, 0); /* menubar */ #ifndef EMBEDDED widget = desktop_menubar_create(_compose_menubar, compose, group); gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, FALSE, 0); #endif /* toolbar */ toolbar = desktop_toolbar_create(_compose_toolbar, compose, group); gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, TRUE, 0); /* from */ sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); toolbar = gtk_toolbar_new(); widget = gtk_label_new(_("From: ")); gtk_misc_set_alignment(GTK_MISC(widget), 0.1, 0.5); gtk_widget_set_size_request(widget, 80, -1); gtk_size_group_add_widget(sizegroup, widget); toolitem = gtk_tool_item_new(); gtk_container_add(GTK_CONTAINER(toolitem), widget); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1); #if GTK_CHECK_VERSION(2, 24, 0) compose->from = gtk_combo_box_text_new_with_entry(); #else compose->from = gtk_combo_box_entry_new_text(); #endif toolitem = gtk_tool_item_new(); gtk_tool_item_set_expand(toolitem, TRUE); gtk_container_add(GTK_CONTAINER(toolitem), compose->from); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1); gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); /* paned */ vpaned = gtk_vpaned_new(); /* headers */ widget = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); compose->h_store = gtk_list_store_new(CHC_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); compose->h_store_filter = gtk_tree_model_filter_new(GTK_TREE_MODEL( compose->h_store), NULL); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER( compose->h_store_filter), _compose_on_headers_filter, compose, NULL); compose->h_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL( compose->h_store_filter)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(compose->h_view), FALSE); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(compose->h_view), TRUE); compose->h_headers = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); for(i = 0; i < sizeof(headers) / sizeof(*headers); i++) { gtk_list_store_append(compose->h_headers, &iter); gtk_list_store_set(compose->h_headers, &iter, 0, headers[i], 1, headers[i], -1); } renderer = gtk_cell_renderer_combo_new(); g_object_set(renderer, "editable", TRUE, "model", compose->h_headers, "text-column", 1, NULL); g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK( _on_header_field_edited), compose); column = gtk_tree_view_column_new_with_attributes("", renderer, "text", CHC_HEADER, NULL); gtk_tree_view_column_set_min_width(column, 80); gtk_tree_view_append_column(GTK_TREE_VIEW(compose->h_view), column); renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL); g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK( _on_header_edited), compose); column = gtk_tree_view_column_new_with_attributes("", renderer, "text", CHC_VALUE, NULL); #if GTK_CHECK_VERSION(2, 4, 0) gtk_tree_view_column_set_expand(column, TRUE); #endif gtk_tree_view_append_column(GTK_TREE_VIEW(compose->h_view), column); /* default to 8-bits transfers with UTF-8 encoding */ compose_set_header(compose, "Content-Transfer-Encoding:", "8bit", FALSE); compose_set_header(compose, "Content-Type:", "text/plain; charset=UTF-8", FALSE); compose_add_field(compose, "To:", NULL); gtk_container_add(GTK_CONTAINER(widget), compose->h_view); gtk_paned_add1(GTK_PANED(vpaned), widget); /* paned */ vbox2 = gtk_vbox_new(FALSE, 0); /* subject */ toolbar = gtk_toolbar_new(); widget = gtk_label_new(_("Subject: ")); gtk_misc_set_alignment(GTK_MISC(widget), 0.1, 0.5); gtk_size_group_add_widget(sizegroup, widget); toolitem = gtk_tool_item_new(); gtk_container_add(GTK_CONTAINER(toolitem), widget); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1); compose->subject = gtk_entry_new(); toolitem = gtk_tool_item_new(); gtk_tool_item_set_expand(toolitem, TRUE); gtk_container_add(GTK_CONTAINER(toolitem), compose->subject); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), toolitem, -1); gtk_box_pack_start(GTK_BOX(vbox2), toolbar, FALSE, TRUE, 0); /* view */ widget = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); compose->view = _new_text_view(compose); compose_set_font(compose, _compose_get_font(compose)); gtk_container_add(GTK_CONTAINER(widget), compose->view); gtk_box_pack_start(GTK_BOX(vbox2), widget, TRUE, TRUE, 0); gtk_paned_add2(GTK_PANED(vpaned), vbox2); gtk_box_pack_start(GTK_BOX(vbox), vpaned, TRUE, TRUE, 0); /* attachments */ compose->a_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(compose->a_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); compose->a_store = gtk_list_store_new(CAC_COUNT, G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF); compose->a_view = gtk_icon_view_new_with_model(GTK_TREE_MODEL( compose->a_store)); gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(compose->a_view), CAC_ICON); gtk_icon_view_set_selection_mode(GTK_ICON_VIEW(compose->a_view), GTK_SELECTION_MULTIPLE); gtk_icon_view_set_text_column(GTK_ICON_VIEW(compose->a_view), CAC_BASENAME); gtk_container_add(GTK_CONTAINER(compose->a_window), compose->a_view); gtk_widget_show_all(compose->a_view); gtk_widget_set_no_show_all(compose->a_window, TRUE); gtk_box_pack_start(GTK_BOX(vbox), compose->a_window, FALSE, TRUE, 0); /* statusbar */ compose->statusbar = gtk_statusbar_new(); compose->statusbar_id = 0; gtk_box_pack_start(GTK_BOX(vbox), compose->statusbar, FALSE, TRUE, 0); gtk_container_add(GTK_CONTAINER(compose->window), vbox); /* about dialog */ compose->ab_window = NULL; /* signature */ compose_append_signature(compose); compose_set_modified(compose, FALSE); compose_scroll_to_offset(compose, 0); /* display */ gtk_widget_grab_focus(compose->view); gtk_widget_show_all(vbox); gtk_widget_show(compose->window); return compose; }