Exemplo n.º 1
0
int main(int argc, char **argv) {

    char line[MAX_MESSAGE_LEN+1];

    if (argc < 5) {
        printUsage();
    }

    host = argv[1];
    sport = argv[2];
    user = argv[3];
    password = argv[4];

    printf("\nStarting talk-client %s %s %s %s\n", host, sport, user, password);

    // Convert port to number
    sscanf(sport, "%d", &port);

    //create gui
    //
    //entry.c - text fields, messages, password
    //panned.c - split pane
    //radio.c - radio buttons
    //timer.c - time and countdown






    add_user();

    // Enter room
    enter_room();

    printf("\nEntered room and starting message thread\n");

    // Start message thread
    startGetMessageThread();

    while (1) {
        printPrompt();

        char * s = fgets(line,MAX_MESSAGE_LEN, stdin);
        if (s==NULL) {
            leave_room();
            printf("talk-client exiting...\n");
            exit(1);
        }

        if (!isatty(0)) {
            // If it is not a terminal, echo command as well
            printf("%s\n", line);
        }

        if (line[0]=='-') {
            // This is a command process it
            if (!strcmp(line,"-help")) {
                printHelp();
            }
            else if (!strcmp(line,"-quit")) {
                printf("talk-client exiting...\n");
                exit(1);
            }
            // Put other commands here
            else if (!strcmp(line,"-users")) {
                print_users();
            }
            else if (!strcmp(line,"-who")) {
                print_users_in_room();
            }
            else {
                printf("Wrong command\n");
            }
        }
        else if (line[0]==0) {
            // Empty line. Print help
            printf("Type -help to print the available commands\n");
        }
        else {
            // Send message
            char response[MAX_RESPONSE];
            sendCommand(host,port,"SEND-MESSAGE", user, password, line, response);
        }
    }

    printf("TEST ENDS\n");
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv) {

    char line[MAX_MESSAGE_LEN+1];

    if (argc < 5) {
        printUsage();
    }

    host = argv[1];
    sport = argv[2];
    user = argv[3];
    password = argv[4];

    printf("\nStarting talk-client %s %s %s %s\n", host, sport, user, password);

    int i;
    for (i = 0; i < 100; i++) {
        messages[i] = (char*) malloc(100*sizeof(char));
    }
    
    // Convert port to number
    sscanf(sport, "%d", &port);

    add_user();
    create_room();

    // Enter room
    enter_room();

    // Start message thread
    startGetMessageThread();

    //TODO

    GtkWidget *window;
    GtkWidget *table;

    GtkWidget *title;
    GtkWidget *title1;
    GtkWidget *title2;
    GtkWidget *title3;

    GtkWidget *activate;
    GtkWidget *halign;
    GtkWidget *halign1;
    GtkWidget *halign2;
    GtkWidget *halign3;
    GtkWidget *halign4;
    GtkWidget *halign5;

    GtkWidget *valign;
    GtkWidget *close;
    GtkWidget *wins;
    GtkWidget *list;
    GtkWidget *wins1;
    GtkWidget *messages;
    GtkWidget *type;

    GtkWidget *send;
    GtkWidget *createAccount;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_set_size_request (window, 800, 700);
    gtk_window_set_resizable(GTK_WINDOW(window), TRUE);

    gtk_container_set_border_width(GTK_CONTAINER(window), 15);

    table = gtk_table_new(8, 8, FALSE);
    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
    gtk_table_set_row_spacings(GTK_TABLE(table), 10);

    title = gtk_label_new("Rooms");
    halign = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign), title);
    gtk_table_attach(GTK_TABLE(table), halign, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);

    title1 = gtk_label_new("Users");
    halign1 = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign1), title1);
    gtk_table_attach(GTK_TABLE(table), halign1, 4, 5, 0, 1, GTK_FILL, GTK_FILL, 0, 0);

    //wins = gtk_text_view_new();
    //gtk_text_view_set_editable(GTK_TEXT_VIEW(wins), TRUE);
    //gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(wins), TRUE);
    wins = create_list("Rooms");
    gtk_table_attach(GTK_TABLE(table), wins, 0, 4, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    //wins1 = gtk_text_view_new();
    //gtk_text_view_set_editable(GTK_TEXT_VIEW(wins1), TRUE);
    //gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(wins1), TRUE);
    wins1 = create_list("Users");
    gtk_table_attach(GTK_TABLE(table), wins1, 4, 8, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    title2 = gtk_label_new("Messages");
    halign4 = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign4), title2);
    gtk_table_attach(GTK_TABLE(table), halign4, 0, 1, 2, 3, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    messages = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(messages), FALSE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(messages), FALSE);
    gtk_table_attach(GTK_TABLE(table), messages, 0, 8, 3, 5, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    title3 = gtk_label_new("Type a message:");
    halign5 = gtk_alignment_new(0, 0, 0, 0);
    gtk_container_add(GTK_CONTAINER(halign5), title3);
    gtk_table_attach(GTK_TABLE(table), halign5, 0, 1, 5, 6, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    type = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(type), TRUE);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(type), TRUE);
    gtk_table_attach(GTK_TABLE(table), type, 0, 8, 6, 7, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 1, 1);

    halign2 = gtk_alignment_new(0, 1, 0, 0);
    send = gtk_button_new_with_label("Send");
    g_signal_connect (send, "clicked", G_CALLBACK (send_message), NULL);
    gtk_container_add(GTK_CONTAINER(halign2), send);
    gtk_table_attach(GTK_TABLE(table), halign2, 0, 1, 7, 8, GTK_FILL, GTK_FILL, 0, 0);

    createAccount = gtk_button_new_with_label("Create Account");
    g_signal_connect (createAccount, "clicked", G_CALLBACK (add_user), NULL);
    gtk_table_attach(GTK_TABLE(table), createAccount, 5, 8, 7, 8, GTK_FILL, GTK_FILL, 0, 0);


    gtk_container_add(GTK_CONTAINER(window), table);

    g_signal_connect_swapped(G_OBJECT(window), "destroy",
            G_CALLBACK(gtk_main_quit), G_OBJECT(window));

    gtk_widget_show_all(window);
    gtk_main();
    //TODO
    while (1) {
        printPrompt();
        //gtk_main();
        //gtk_main_quit();
        char * s = fgets(line,MAX_MESSAGE_LEN, stdin);
        if (s==NULL) {
            leave_room();
            printf("talk-client exiting...\n");
            exit(1);
        }

        if (!isatty(0)) {
            // If it is not a terminal, echo command as well
            printf("%s\n", line);
        }

        if (line[0]=='-') {
            // This is a command process it
            if (!strcmp(line,"-help")) {
                printHelp();
            }
            else if (!strcmp(line,"-quit")) {
                printf("talk-client exiting...\n");
                exit(1);
            }
            // Put other commands here
        }
        else if (line[0]==0) {
            // Empty line. Print help
            printf("Type -help to print the available commands\n");
        }
        else {
            // Send message
        }
    }

    printf("TEST ENDS\n");
    return 0;

}