bool StandardContactList::save() { if(!ProfileManager::instance()->profilePath().isEmpty()) { QString cfgName = ProfileManager::instance()->profilePath() + QDir::separator() + "contacts.xml"; ProfileManager::instance()->sync(); QDomDocument doc; doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"")); QDomElement root = doc.createElement("contactlist"); QDomElement global = doc.createElement("global"); m_userData->serialize(global); root.appendChild(global); QDomElement owner = doc.createElement("owner"); save_owner(owner); root.appendChild(owner); QDomElement groups = doc.createElement("groups"); if(save_groups(groups)) root.appendChild(groups); QDomElement contacts = doc.createElement("contacts"); if(save_contacts(contacts)) root.appendChild(contacts); doc.appendChild(root); QFile f(cfgName); f.open(QIODevice::WriteOnly | QIODevice::Truncate); f.write(doc.toByteArray()); f.close(); } return true; }
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; }