bool StandardContactList::load_new() { QString cfgName = ProfileManager::instance()->profilePath() + QDir::separator() + "contacts.xml"; QFile f(cfgName); if(!f.open(QIODevice::ReadOnly)) return false; QDomDocument doc; doc.setContent(f.readAll()); QDomElement el = doc.elementsByTagName("global").at(0).toElement(); if(!m_userData->deserialize(el)) return false; QDomElement owner = doc.elementsByTagName("owner").at(0).toElement(); load_owner(owner); QDomElement groups = doc.elementsByTagName("groups").at(0).toElement(); if(!load_groups(groups)) return false; QDomElement contacts = doc.elementsByTagName("contacts").at(0).toElement(); if(!load_contacts(contacts)) return false; return true; }
int ab_init(void) { /* Do nothing if the database handle has been set. */ if (conn) { return 0; } if (sqlite3_open(dbname, &conn) != SQLITE_OK) { fprintf(stderr, "error opening SQLite database %s: %s\n", dbname, sqlite3_errmsg(conn)); sqlite3_close(conn); return -1; } if (_create_tables()) { _ab_sqlite_disconnect(conn); return -1; } if (sqlite3_prepare(conn, insert_sql, -1, &insert_stmt, NULL) != SQLITE_OK) { fprintf(stderr, "error preparing insert statement: %s\n", sqlite3_errmsg(conn)); _ab_sqlite_disconnect(conn); return -1; } if (sqlite3_prepare(conn, update_sql, -1, &update_stmt, NULL) != SQLITE_OK) { fprintf(stderr, "error preparing update statement: %s\n", sqlite3_errmsg(conn)); return -1; } if (sqlite3_prepare(conn, delete_sql, -1, &delete_stmt, NULL) != SQLITE_OK) { fprintf(stderr, "error preparing delete statement: %s\n", sqlite3_errmsg(conn)); return -1; } if (sqlite3_prepare(conn, select_sql, -1, &select_stmt, NULL) != SQLITE_OK) { fprintf(stderr, "error preparing select statement: %s\n", sqlite3_errmsg(conn)); return -1; } load_contacts(); return 0; }
int main(int argc, char** argv) { cvector_void contacts; char choice; int quit = 0; cvec_void(&contacts, 0, 10, sizeof(contact), free_contact, NULL); saved = 1; print_menu(); while (!quit) { puts("What action would you like to perform?"); choice = read_char(stdin, SPACE_SET, 0, 1); switch (choice) { case 'A': case 'a': add_contact(&contacts); break; case 'D': case 'd': display_contacts(&contacts); break; case 'E': case 'e': edit_contacts(&contacts); break; case 'V': case 'v': save_contacts(&contacts); break; case 'L': case 'l': load_contacts(&contacts); break; case 'R': case 'r': remove_contact(&contacts); break; case 'S': case 's': sort_contacts(&contacts); break; case 'F': case 'f': find_contacts(&contacts, NULL, 1); break; case 'Q': case 'q': //TODO if (!saved) { puts("You have unsaved changes! Are you sure you want to quit? (y/N)"); choice = read_char(stdin, SPACE_SET_NO_NEWLINE, 0, 1); if (choice == 'y' || choice == 'y') quit = 1; else quit = 0; } else { quit = 1; } break; case '?': print_menu(); break; } putchar('\n'); } cvec_free_void(&contacts); return 0; }
/* Entry point for this file, here we take care of * creating the addressbook if it doesnt exist, * getting an EBookClient, and creating our EBookClientCursor. */ EBookClient * cursor_load_data (const gchar *vcard_path, EBookClientCursor **ret_cursor) { ESourceRegistry *registry; ESource *scratch; ESourceBackend *backend = NULL; GMainLoop *loop; GError *error = NULL; EBookClient *ret_book; g_return_val_if_fail (vcard_path != NULL, NULL); g_return_val_if_fail (ret_cursor != NULL, NULL); g_print ("Cursor loading data from %s\n", vcard_path); loop = g_main_loop_new (NULL, FALSE); registry = e_source_registry_new_sync (NULL, &error); if (!registry) g_error ("Unable to create the registry: %s", error->message); /* Listen to the registry for our added source */ g_signal_connect ( registry, "source-added", G_CALLBACK (cursor_data_source_added), loop); /* Now create a scratch source for our addressbook */ scratch = e_source_new_with_uid (CURSOR_DATA_SOURCE_ID, NULL, &error); /* Ensure the new ESource will be a local addressbook source */ backend = e_source_get_extension (scratch, E_SOURCE_EXTENSION_ADDRESS_BOOK); e_source_backend_set_backend_name (backend, "local"); /* Now is the right time to use the ESourceBackendSummarySetup to configure * your newly created addressbook. This configuration should happen on the * scratch source before calling e_source_registry_commit_source_sync(). */ /* Commit the source to the registry */ if (!e_source_registry_commit_source_sync (registry, scratch, NULL, &error)) { /* It's possible the source already exists if we already ran the example with this data server */ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { /* If so... then just call our callback early */ ESource *source = e_source_registry_ref_source (registry, CURSOR_DATA_SOURCE_ID); g_clear_error (&error); g_return_val_if_fail (E_IS_SOURCE (source), NULL); /* Run the callback which creates the addressbook client connection */ cursor_data_source_added (registry, source, NULL); g_object_unref (source); } else g_error ("Unable to add new addressbook source to the registry: %s", error->message); } g_object_unref (scratch); /* Give EDS a little time to actually create the ESource remotely and * also have a copy if it cached locally, wait for the "source-added" * signal. */ if (address_book == NULL) { g_timeout_add_seconds (20, cursor_data_source_timeout, NULL); g_main_loop_run (loop); /* By now we aborted or we have an addressbook created */ g_return_val_if_fail (address_book != NULL, NULL); } /********************************************************** * Ok, done with creating an addressbook, let's add data * **********************************************************/ load_contacts (address_book, vcard_path); /* Addressbook should have contacts now, let's create the cursor */ *ret_cursor = get_cursor (address_book); /* Cleanup some resources we used to populate the addressbook */ g_main_loop_unref (loop); g_object_unref (address_book_source); g_object_unref (registry); /* Give the ref through the return value*/ ret_book = address_book; address_book_source = NULL; address_book = NULL; /* Return the addressbook */ return ret_book; }