Пример #1
0
gint main(gint argc, gchar* argv[]) {
    GtkWidget* login_dialog;
    const char* user_const;
    const char* pass_const;
    gchar username[100];
    gchar password[100];
    gint result;
    gnome_program_init("CdDatabase", "0.1", LIBGNOMEUI_MODULE,
                       argc, argv,
                       GNOME_PARAM_APP_DATADIR, "",
                       NULL);
    GtkWidget* main_window = create_main_window();
    gtk_widget_show_all(main_window);
    /* Must login to database before we start, so create dialog to
       input username and password */
    login_dialog = create_login_dialog();

    while (1) {
        result = gtk_dialog_run(GTK_DIALOG(login_dialog));

        /* If we click cancel, then confirm exit */
        if (result != GTK_RESPONSE_ACCEPT) {
            if (confirm_exit()) {
                return 0;
            } else {
                continue;
            }
        }

        /* Retrieve username and password */
        user_const = gtk_entry_get_text(GTK_ENTRY(username_entry));
        pass_const = gtk_entry_get_text(GTK_ENTRY(password_entry));
        strcpy(username, user_const);
        strcpy(password, pass_const);

        if (database_start(username, password) == TRUE) {
            break;
        }

        /* If we couldn't logon, then display error message and try again */
        GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(main_window),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_ERROR,
                                  GTK_BUTTONS_CLOSE,
                                  "Could not log on! - Check Username and Password");
        gtk_dialog_run(GTK_DIALOG(error_dialog));
        gtk_widget_destroy(error_dialog);
    }

    gtk_widget_destroy(login_dialog);
    gtk_main();
    return 0;
}
Пример #2
0
int main()
{
    struct current_cd_st cd;
    struct cd_search_st cd_res;
    struct current_tracks_st ct;
    int cd_id;
    int res, i;

    /* The first thing your app must always do is initialize a database connection,
       providing a valid user name and password */
    database_start("root", "weiyi");
    
    /* Then you test adding a CD: */
    res = add_cd("Bu Yi", "He Bu Wan De Jiu", "201407301321", &cd_id);
    printf("Result of adding a cd was %d, cd_id is %d\n", res, cd_id);

    memset(&ct, 0, sizeof(ct));
    ct.cd_id = cd_id;
    strcpy(ct.track[0], "San Feng");
    strcpy(ct.track[1], "Yang Rou Mian");
    strcpy(ct.track[2], "Na Me Jiu");
    add_tracks(&ct);

    /* Now search for the CD and retrieve information from the first CD found */
    res = find_cds("Jiu", &cd_res);
    printf("Found %d cds, first has ID %d\n", res, cd_res.cd_id[0]);

    res = get_cd(cd_res.cd_id[0], &cd);
    printf("get_cd returned %d\n", res);

    memset(&ct, 0, sizeof(ct));
    res = get_cd_tracks(cd_res.cd_id[0], &ct);
    printf("get_cd_tracks returned %d\n", res);
    printf("Title: %s\n", cd.title);
    i = 0;
    while (i < res) {
        printf("\ttrack %d is %s\n", i, ct.track[i]);
        i++;
    }

    /* Finally, delete the CD */
    res = delete_cd(cd_res.cd_id[0]);
    printf("delete_cd returned %d\n", res);

    /* Then disconnect and exit */
    database_end();
    return EXIT_SUCCESS;
}
Пример #3
0
int main(void)
{
   struct current_cd_st cd;
   struct cd_search_st cd_res;
   struct current_tracks_st ct;
   int cd_id;
   int res, i;

   database_start(NULL, NULL);
   
   res = add_cd("Mahler", "Symphony No 1", "4596102", &cd_id);
   printf("Result of adding a cd was %d, cd_id is %d\n", res, cd_id);

   memset(&ct, 0, sizeof(ct));
   ct.cd_id = cd_id;
   strcpy(ct.track[0], "Langsam Schleppend");
   strcpy(ct.track[1], "Kraftig bewegt");
   strcpy(ct.track[2], "Feirelich und gemessen");
   strcpy(ct.track[3], "Sturmish bewegt");
   add_tracks(&ct);

   res = find_cds("Symphony", &cd_res);
   printf("Found %d cds, first has ID %d\n", res, cd_res.cd_id[0]);

   res = get_cd(cd_res.cd_id[0], &cd);
   printf("get_cd returned %d\n", res);

   memset(&ct, 0, sizeof(ct));
   res = get_cd_tracks(cd_res.cd_id[0], &ct);
   printf("get_cd tracks returned %d\n", res);
   printf("Title: %s\n", cd.title);
   i = 0;
   
   while(i < res)  {
       printf("\t tracks %d is %s\n", i, ct.track[i]);
       i++;
   }
   
   res = delete_cd(cd_res.cd_id[0]);
   printf("Delete_cd returned %d\n", res);
   
   database_end();
   
   return EXIT_SUCCESS;

}
Пример #4
0
int main( int argc, char **argv )
{
  char username[100];
  char password[100];

  KApplication a( argc, argv, "cdapp" );

  LogonDialog *dialog = new LogonDialog();

  while (1)
  {
    if (dialog->exec() == QDialog::Accepted)
    {
      strcpy(username, dialog->getUsername());
      strcpy(password, dialog->getPassword());
        
      if (database_start(username, password))
        break;
      QMessageBox::information(0, "Title", "Could not Logon: Check username and/or password",
                            QMessageBox::Ok);
        continue;
    }
    else
    {
      if (QMessageBox::information(0, "Title", "Are you sure you want to quit?",
                               QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
      {
        return 0;
      }
    }
  }
  delete dialog;
            
  MainWindow *window = new MainWindow( "Cd App" );
  window->resize( 600, 400 );

  a.setMainWidget( window );
  window->show();

  return a.exec();
}