QString Nick::calculateLabel1() { NickInfoPtr nickinfo = getChannelNick()->getNickInfo(); KABC::Addressee addressee = nickinfo->getAddressee(); if(!addressee.realName().isEmpty()) //if no addressee, realName will be empty { return nickinfo->getNickname() + " (" + addressee.realName() + ')'; } else if(Preferences::showRealNames() && !nickinfo->getRealName().isEmpty()) { return nickinfo->getNickname() + " (" + nickinfo->getRealName() + ')'; } return nickinfo->getNickname(); }
void KOAttendeeEditor::openAddressBook() { #ifndef KORG_NOKABC KPIM::AddressesDialog *dia = new KPIM::AddressesDialog( this, "adddialog" ); dia->setShowCC( false ); dia->setShowBCC( false ); if ( dia->exec() ) { KABC::Addressee::List aList = dia->allToAddressesNoDuplicates(); for ( KABC::Addressee::List::iterator itr = aList.begin(); itr != aList.end(); ++itr ) { insertAttendeeFromAddressee( (*itr) ); } } delete dia; return; #if 0 // old code KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this); if (!a.isEmpty()) { // If this is myself, I don't want to get a response but instead // assume I will be available bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() ); KCal::Attendee::PartStat partStat = myself ? KCal::Attendee::Accepted : KCal::Attendee::NeedsAction; insertAttendee( new Attendee( a.realName(), a.preferredEmail(), !myself, partStat, KCal::Attendee::ReqParticipant, a.uid() ) ); } #endif #endif }
void ReportGenerator::contactToTemplate( TextTemplate *tmpl, const QString& prefix, const KABC::Addressee& contact ) { if( contact.isEmpty() ) return; tmpl->setValue( ADDRESS_TAG( prefix, "NAME" ), escapeTrml2pdfXML( contact.realName() ) ); QString co = contact.organization(); if( co.isEmpty() ) { co = contact.realName(); } tmpl->setValue( ADDRESS_TAG( prefix, "ORGANISATION" ), escapeTrml2pdfXML( co ) ); tmpl->setValue( ADDRESS_TAG( prefix, "URL" ), escapeTrml2pdfXML( contact.url().prettyUrl() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "EMAIL" ), escapeTrml2pdfXML( contact.preferredEmail() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "PHONE" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Work ).number() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "FAX" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Fax ).number() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "CELL" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Cell ).number() ) ); KABC::Address address; address = contact.address( KABC::Address::Pref ); if( address.isEmpty() ) address = contact.address(KABC::Address::Work ); if( address.isEmpty() ) address = contact.address(KABC::Address::Home ); if( address.isEmpty() ) address = contact.address(KABC::Address::Postal ); tmpl->setValue( ADDRESS_TAG( prefix, "POSTBOX" ), escapeTrml2pdfXML( address.postOfficeBox() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "EXTENDED" ), escapeTrml2pdfXML( address.extended() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "STREET" ), escapeTrml2pdfXML( address.street() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "LOCALITY" ), escapeTrml2pdfXML( address.locality() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ), escapeTrml2pdfXML( address.region() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "POSTCODE" ), escapeTrml2pdfXML( address.postalCode() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "COUNTRY" ), escapeTrml2pdfXML( address.country() ) ); tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ), escapeTrml2pdfXML( address.region() ) ); tmpl->setValue( ADDRESS_TAG( prefix,"LABEL" ), escapeTrml2pdfXML( address.label() ) ); }
void KoRdfFoaF::fromKABC(KABC::Addressee addr) { m_name = addr.realName(); m_nick = addr.nickName(); KABC::PhoneNumber ph = addr.phoneNumber(KABC::PhoneNumber::Work); m_phone = ph.number(); m_homePage = addr.url().url(); }
void KraftView::slotAddresseeFound( const QString& uid, const KABC::Addressee& contact ) { if( !contact.isEmpty() ) { kDebug() << "Addressee Found with uid " << uid; slotNewAddress( contact, false ); kDebug() << "The loaded Contact has this realname: " << contact.realName() << endl; } else { kDebug() << "No contact found for uid " << uid; } }
AddresseeCardViewItem(const KABC::Field::List &fields, bool showEmptyFields, KABC::AddressBook *doc, const KABC::Addressee &addr, CardView *parent) : CardViewItem(parent, addr.realName()), mFields(fields), mShowEmptyFields(showEmptyFields), mDocument(doc), mAddressee(addr) { if(mFields.isEmpty()) mFields = KABC::Field::defaultFields(); refresh(); }
void KCalResourceSlox::parseMembersAttribute( const QDomElement &e, Incidence *incidence ) { incidence->clearAttendees(); QDomNode n; for( n = e.firstChild(); !n.isNull(); n = n.nextSibling() ) { QDomElement memberElement = n.toElement(); if ( memberElement.tagName() == fieldName( Participant ) ) { QString member = memberElement.text(); KABC::Addressee account; if ( mAccounts ) account = mAccounts->lookupUser( member ); else kError() << "KCalResourceSlox: no accounts set"; QString name; QString email; Attendee *a = incidence->attendeeByUid( member ); if ( account.isEmpty() ) { if ( a ) continue; name = member; email = member + '@' + KUrl( mPrefs->url() ).host(); } else { name = account.realName(); email = account.preferredEmail(); } if ( a ) { a->setName( name ); a->setEmail( email ); } else { a = new Attendee( name, email ); a->setUid( member ); incidence->addAttendee( a ); } QString status = memberElement.attribute( "confirm" ); if ( !status.isEmpty() ) { if ( status == "accept" ) { a->setStatus( Attendee::Accepted ); } else if ( status == "decline" ) { a->setStatus( Attendee::Declined ); } else { a->setStatus( Attendee::NeedsAction ); } } } else { kDebug() << "Unknown tag in members attribute:" << memberElement.tagName(); } } }
void AddressEditWidget::loadContact( const KABC::Addressee &contact ) { mName = contact.realName(); mAddressList = contact.addresses(); mAddressSelectionWidget->setAddresses( mAddressList ); // set the preferred address as the visible one for ( int i = 0; i < mAddressList.count(); ++i ) { if ( mAddressList.at( i ).type() & KABC::Address::Pref ) { mAddressSelectionWidget->setCurrentAddress( mAddressList.at( i ) ); break; } } updateAddressView(); updateButtons(); }
void KOAttendeeEditor::insertAttendeeFromAddressee( const KABC::Addressee &a, const Attendee *at ) { bool myself = KOPrefs::instance()->thatIsMe( a.preferredEmail() ); bool sameAsOrganizer = mOrganizerCombo && KPIMUtils::compareEmail( a.preferredEmail(), mOrganizerCombo->currentText(), false ); KCal::Attendee::PartStat partStat = at ? at->status() : KCal::Attendee::NeedsAction; bool rsvp = at? at->RSVP() : true; if ( myself && sameAsOrganizer ) { partStat = KCal::Attendee::Accepted; rsvp = false; } Attendee *newAt = new Attendee( a.realName(), a.preferredEmail(), !myself, partStat, at ? at->role() : Attendee::ReqParticipant, a.uid() ); newAt->setRSVP( rsvp ); insertAttendee( newAt, true ); }
AddresseeItem::AddresseeItem( QTreeWidget *parent, const KABC::Addressee &addressee) : QTreeWidgetItem( parent ), mAddressee( addressee ) { //We can't save showphoto because we don't have a d pointer KABC::Picture pic = mAddressee.photo(); if(!pic.isIntern()) pic = mAddressee.logo(); if(pic.isIntern()) { //60 pixels seems okay.. kmail uses 60 btw QIcon icon( QPixmap::fromImage( pic.data().scaledToWidth(60) ) ); setIcon( Photo, icon ); } setText( Name, addressee.realName() ); setText( Email, addressee.preferredEmail() ); }
void PublishDialog::openAddressbook() { #ifndef KORG_NOKABC KABC::Addressee::List addressList; addressList = KABC::AddresseeDialog::getAddressees( this ); //KABC::Addressee a = KABC::AddresseeDialog::getAddressee(this); KABC::Addressee a = addressList.first(); if ( !a.isEmpty() ) { uint i; for ( i=0; i<addressList.size(); i++ ) { a = addressList[i]; mWidget->mNameLineEdit->setEnabled( true ); mWidget->mEmailLineEdit->setEnabled( true ); QListViewItem *item = new QListViewItem( mWidget->mAddressListView ); mWidget->mAddressListView->setSelected( item, true ); mWidget->mNameLineEdit->setText( a.realName() ); mWidget->mEmailLineEdit->setText( a.preferredEmail() ); mWidget->mAddressListView->insertItem( item ); } } #endif }
void PublishDialog::openAddressbook() { KABC::Addressee::List addressList = KABC::AddresseeDialog::getAddressees( this ); if( addressList.isEmpty() ) { return; } KABC::Addressee a = addressList.first(); if ( !a.isEmpty() ) { int i; for ( i=0; i<addressList.size(); i++ ) { a = addressList[i]; mUI.mNameLineEdit->setEnabled( true ); mUI.mEmailLineEdit->setEnabled( true ); QListWidgetItem *item = new QListWidgetItem( mUI.mListWidget ); mUI.mListWidget->setItemSelected( item, true ); mUI.mNameLineEdit->setText( a.realName() ); mUI.mEmailLineEdit->setText( a.preferredEmail() ); mUI.mListWidget->addItem( item ); } mUI.mRemove->setEnabled( true ); } }
/** * Return a string containing formatted additional information about a nick. * @param nickInfo A pointer to NickInfo structure for the nick. May be Null. * @param addressee Addressbook entry for the nick. May be empty. * @return A string formatted for display containing the information * about the nick. * @return needWhois True if a WHOIS needs to be performed on the nick * to get additional information. */ QString NicksOnline::getNickAdditionalInfo(NickInfoPtr nickInfo, KABC::Addressee addressee, bool& needWhois) { QString info; if (!addressee.isEmpty()) { if (addressee.fullEmail().isEmpty()) info += addressee.realName(); else info += addressee.fullEmail(); } QString niInfo; if (nickInfo) { if (nickInfo->isAway()) { niInfo += i18n("Away"); if (!nickInfo->getAwayMessage().isEmpty()) niInfo += '(' + nickInfo->getAwayMessage() + ')'; } if (!nickInfo->getHostmask().isEmpty()) niInfo += ' ' + nickInfo->getHostmask(); if (!nickInfo->getRealName().isEmpty()) niInfo += " (" + nickInfo->getRealName() + ')'; if (!nickInfo->getNetServer().isEmpty()) { niInfo += i18n( " online via %1" ).arg( nickInfo->getNetServer() ); if (!nickInfo->getNetServerInfo().isEmpty()) niInfo += " (" + nickInfo->getNetServerInfo() + ')'; } if (!nickInfo->getOnlineSince().isNull()) niInfo += i18n( " since %1" ).arg( nickInfo->getPrettyOnlineSince() ); } needWhois = niInfo.isEmpty(); if (!info.isEmpty() && !needWhois) info += ' '; return info + niInfo; }
QVariant ContactsTreeModel::entityData( const Item &item, int column, int role ) const { if ( item.mimeType() == KABC::Addressee::mimeType() ) { if ( !item.hasPayload<KABC::Addressee>() ) { // Pass modeltest if ( role == Qt::DisplayRole ) return item.remoteId(); return QVariant(); } const KABC::Addressee contact = item.payload<KABC::Addressee>(); if ( role == Qt::DecorationRole ) { if ( column == 0 ) { const KABC::Picture picture = contact.photo(); if ( picture.isIntern() ) { return picture.data().scaled( QSize( 16, 16 ), Qt::KeepAspectRatio ); } else { return KIcon( QLatin1String( "x-office-contact" ) ); } } return QVariant(); } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) { switch ( mColumns.at( column ) ) { case FullName: return contact.realName(); break; case Birthday: if ( contact.birthday().isValid() ) return KGlobal::locale()->formatDate( contact.birthday().date() ); break; case HomeAddress: { const KABC::Address address = contact.address( KABC::Address::Home ); if ( !address.isEmpty() ) return address.formattedAddress(); } break; case BusinessAddress: { const KABC::Address address = contact.address( KABC::Address::Work ); if ( !address.isEmpty() ) return address.formattedAddress(); } break; case PhoneNumbers: { QStringList values; const KABC::PhoneNumber::List numbers = contact.phoneNumbers(); foreach ( const KABC::PhoneNumber &number, numbers ) values += number.number(); return values.join( "\n" ); } break; case PreferredEmail: return contact.preferredEmail(); break; case AllEmails: return contact.emails().join( "\n" ); break; case Organization: return contact.organization(); break; case Homepage: return contact.url().url(); break; case Note: return contact.note(); break; } } } else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
int create(KCmdLineArgs *args) { KODE::Printer p; if(args->isSet("warning")) p.setCreationWarning(true); bool createKioslave = args->isSet("create-kioslave"); bool createMain = args->isSet("create-main"); QString filename = args->getOption("filename"); if(createMain) { if(filename.isEmpty()) { kdError() << "Error: No file name given." << endl; return 1; } if(filename.endsWith(".cpp")) { filename = filename.left(filename.length() - 4); } } else { if(!args->isSet("classname")) { kdError() << "Error: No class name given." << endl; return 1; } } QString className = args->getOption("classname"); QString protocol; if(createKioslave) { if(!args->isSet("protocol")) { protocol = className.lower(); kdWarning() << "Warning: No protocol for kioslave given. Assuming '" << protocol << "'" << endl; } else { protocol = args->getOption("protocol"); } } KODE::File file; file.setProject(args->getOption("project")); QString authorEmail = args->getOption("author-email"); QString authorName; KABC::Addressee a; if(authorEmail.isEmpty()) { a = KABC::StdAddressBook::self()->whoAmI(); authorEmail = a.preferredEmail(); } else { KABC::Addressee::List as = KABC::StdAddressBook::self()->findByEmail(authorEmail); if(as.isEmpty()) { kdDebug() << "Unable to find '" << authorEmail << "' in address book." << endl; } else { a = as.first(); } } if(!a.isEmpty()) { authorName = a.realName(); } if(!authorEmail.isEmpty()) { file.addCopyright(QDate::currentDate().year(), authorName, authorEmail); } KODE::License l; if(args->isSet("gpl")) l = KODE::License(KODE::License::GPL); if(args->isSet("lgpl")) l = KODE::License(KODE::License::LGPL); l.setQtException(args->isSet("qt-exception")); file.setLicense(l); file.setNameSpace(args->getOption("namespace")); if(createMain) { file.addInclude("kaboutdata.h"); file.addInclude("kapplication.h"); file.addInclude("kdebug"); file.addInclude("klocale"); file.addInclude("kcmdlineargs"); KODE::Code code; code += "static const KCmdLineOptions options[] ="; code += "{"; code += " { \"verbose\", \"Verbose output\", 0 },"; code += " KCmdLineLastOption"; code += "};"; file.addFileCode(code); KODE::Function main("main", "int"); main.addArgument("int argc"); main.addArgument("char **argv"); code.clear(); code += "KAboutData aboutData(\"test\",\"Test\",\"0.1\");"; code += "KCmdLineArgs::init(argc,argv,&aboutData);"; code += "KCmdLineArgs::addCmdLineOptions( options );"; code += ""; code += "KApplication app;"; code += ""; code += "KCmdLineArgs *args = KCmdLineArgs::parsedArgs();"; code += ""; code += "Q_UNUSED( args );"; main.setBody(code); file.addFileFunction(main); file.setFilename(filename); p.printImplementation(file, false); return 0; } KODE::Class c(className); if(args->isSet("create-dialog")) { c.addBaseClass(KODE::Class("KDialogBase")); c.addInclude("kdialogbase.h"); } else if(createKioslave) { c.setDocs("This class implements a kioslave for ..."); c.addBaseClass(KODE::Class("SlaveBase", "KIO")); c.addHeaderInclude("kio/slavebase.h"); KODE::Function get("get", "void"); get.addArgument("const KURL &url"); KODE::Code code; code += "kdDebug(7000) << \"" + className + "::get()\" << endl;"; code += "kdDebug(7000) << \" URL: \" << url.url() << endl;"; code += "#if 1"; code += "kdDebug(7000) << \" Path: \" << url.path() << endl;"; code += "kdDebug(7000) << \" Query: \" << url.query() << endl;"; code += "kdDebug(7000) << \" Protocol: \" << url.protocol() << endl;"; code += "kdDebug(7000) << \" Filename: \" << url.filename() << endl;"; code += "#endif"; code.newLine(); code += "mimeType( \"text/plain\" );"; code.newLine(); code += "QCString str( \"Hello!\" );"; code += "data( str );"; code.newLine(); code += "finished();"; code.newLine(); code += "kdDebug(7000) << \"" + className + "CgiProtocol::get() done\" << endl;"; get.setBody(code); c.addFunction(get); c.addInclude("kinstance.h"); c.addInclude("kdebug.h"); c.addInclude("sys/types.h"); c.addInclude("unistd.h"); c.addInclude("stdlib.h"); KODE::Function main("kdemain", "int"); main.addArgument("int argc"); main.addArgument("char **argv"); code.clear(); code += "KInstance instance( \"kio_" + protocol + "\" );"; code += ""; code += "kdDebug(7000) << \"Starting kio_" + protocol + "(pid: \" << getpid() << \")\" << endl;"; code += ""; code += "if (argc != 4) {"; code.indent(); code += "fprintf( stderr, \"Usage: kio_" + protocol + " protocol domain-socket1 domain-socket2\\n\");"; code += "exit( -1 );"; code.unindent(); code += "}"; code += ""; code += className + " slave( argv[2], argv[3] );"; code += "slave.dispatchLoop();"; code += ""; code += "return 0;"; main.setBody(code); file.addFileFunction(main); file.addExternCDeclaration(p.functionSignature(main)); } KODE::Function constructor(className); if(args->isSet("singleton")) { constructor.setAccess(KODE::Function::Private); KODE::Function self("self", className + " *"); self.setStatic(true); KODE::Code code; code += "if ( !mSelf ) {"; code += " selfDeleter.setObject( mSelf, new " + className + "() );"; code += "}"; code += "return mSelf;"; self.setBody(code); c.addFunction(self); KODE::MemberVariable selfVar("mSelf", className + " *", true); selfVar.setInitializer("0"); c.addMemberVariable(selfVar); KODE::Variable staticDeleter("selfDeleter", "KStaticDeleter<" + className + ">", true); file.addFileVariable(staticDeleter); file.addInclude("kstaticdeleter.h"); } if(createKioslave) { constructor.addArgument("const QCString &pool"); constructor.addArgument("const QCString &app"); constructor.addInitializer("SlaveBase( \"" + protocol + "\", pool, app )"); } c.addFunction(constructor); file.insertClass(c); p.printHeader(file); p.printImplementation(file); if(createKioslave) { // Write automake Makefile KODE::AutoMakefile am; am.addEntry("INCLUDES", "$(all_includes)"); am.newLine(); am.addEntry("noinst_HEADERS", className.lower() + ".h"); am.newLine(); am.addEntry("METASOURCES", "AUTO"); am.newLine(); am.addEntry("kdelnkdir", "$(kde_servicesdir)"); am.addEntry("kdelnk_DATA", protocol + ".protocol"); KODE::AutoMakefile::Target t("kde_module_LTLIBRARIES", "kio_" + protocol + ".la"); t.setSources(className.lower() + ".cpp"); t.setLibAdd("$(LIB_KIO)"); t.setLdFlags("$(all_libraries) -module $(KDE_PLUGIN)"); am.addTarget(t); p.printAutoMakefile(am); // Write protocol file QString protocolFilename = protocol + ".protocol"; QFileInfo fi(protocolFilename); protocolFilename = fi.absFilePath(); KSaveFile::backupFile(protocolFilename, QString::null, ".backup"); QFile::remove(protocolFilename); KSimpleConfig protocolFile(protocolFilename); protocolFile.setGroup("Protocol"); protocolFile.writeEntry("exec", "kio_" + protocol); protocolFile.writeEntry("protocol", protocol); protocolFile.writeEntry("input", "none"); protocolFile.writeEntry("output", "filesystem"); protocolFile.writeEntry("reading", "true"); protocolFile.writeEntry("DocPath", "kioslave/" + protocol + ".html"); protocolFile.sync(); } return 0; }
/** * Perform an addressbook command (edit contact, create new contact, * change/delete association.) * @param id The command id. @ref CommandIDs. * * The operation is performed on the nickname at the currently-selected item in * the nicklistview. * * Also refreshes the nicklistview display to reflect the new addressbook state * for the nick. */ void NicksOnline::doCommand(int id) { if(id < 0) { return; } QString serverName; QString nickname; QListViewItem* item = m_nickListView->selectedItem(); if(!getItemServerAndNick(item, serverName, nickname)) { return; } // Get the server object corresponding to the server name. Server* server = KonversationApplication::instance()->getConnectionManager()->getServerByName(serverName); if (!server) return; // Get NickInfo object corresponding to the nickname. NickInfoPtr nickInfo = server->getNickInfo(nickname); // Get addressbook entry for the nick. KABC::Addressee addressee; if(nickInfo) { addressee = nickInfo->getAddressee(); } else { addressee = server->getOfflineNickAddressee(nickname); } switch(id) { case ciSendEmail: Konversation::Addressbook::self()->sendEmail(addressee); return; //no need to refresh item case ciAddressbookEdit: Konversation::Addressbook::self()->editAddressee(addressee.uid()); return; //no need to refresh item - nickinfo changed will be called anyway. case ciAddressbookChange: if(nickInfo) { nickInfo->showLinkAddressbookUI(); } else { LinkAddressbookUI *linkaddressbookui = new LinkAddressbookUI(server->getViewContainer()->getWindow(), NULL, nickname, server->getServerName(), server->getDisplayName(), addressee.realName()); linkaddressbookui->show(); } break; case ciAddressbookNew: case ciAddressbookDelete: { Konversation::Addressbook *addressbook = Konversation::Addressbook::self(); if(addressbook && addressbook->getAndCheckTicket()) { if(id == ciAddressbookDelete) { if (addressee.isEmpty()) { return; } addressbook->unassociateNick(addressee, nickname, server->getServerName(), server->getDisplayName()); } else { addressee.setGivenName(nickname); addressee.setNickName(nickname); addressbook->associateNickAndUnassociateFromEveryoneElse(addressee, nickname, server->getServerName(), server->getDisplayName()); } if(addressbook->saveTicket()) { //saveTicket will refresh the addressees for us. if(id == ciAddressbookNew) { Konversation::Addressbook::self()->editAddressee(addressee.uid()); } } } break; } case ciJoinChannel: { // only join real channels if (static_cast<NicksOnlineItem*>(m_nickListView->selectedItem())->type() == NicksOnlineItem::ChannelItem) { QString contactChannel = m_nickListView->selectedItem()->text(nlvcChannel); server->queue( "JOIN "+contactChannel ); } break; } case ciWhois: server->queue("WHOIS "+nickname); return; case ciOpenQuery: NickInfoPtr nickInfo = server->obtainNickInfo(nickname); class Query* query = server->addQuery(nickInfo, true /*we initiated*/); emit showView(query); return; } refreshItem(item); }
void readKMailEntry(const QString &kmailEntry, KABC::AddressBook *ab) { kdDebug() << "KMAILENTRY: " << kmailEntry << endl; QString entry = kmailEntry.simplifyWhiteSpace(); if(entry.isEmpty()) return; QString email; QString name; QString comment; if(entry.at(entry.length() - 1) == ')') { int br = entry.findRev('('); if(br >= 0) { comment = entry.mid(br + 1, entry.length() - br - 2); entry.truncate(br); if(entry.at(entry.length() - 1).isSpace()) { entry.truncate(br - 1); } } } int posSpace = entry.findRev(' '); if(posSpace < 0) { email = entry; if(!comment.isEmpty()) { name = comment; comment = ""; } } else { email = entry.mid(posSpace + 1); name = entry.left(posSpace); } if(email.at(0) == '<' && email.at(email.length() - 1) == '>') { email = email.mid(1, email.length() - 2); } if(name.at(0) == '"' && name.at(name.length() - 1) == '"') { name = name.mid(1, name.length() - 2); } if(name.at(0) == '\'' && name.at(name.length() - 1) == '\'') { name = name.mid(1, name.length() - 2); } if(name.at(name.length() - 1) == ')') { int br = name.findRev('('); if(br >= 0) { comment = name.mid(br + 1, name.length() - br - 2) + " " + comment; name.truncate(br); if(name.at(name.length() - 1).isSpace()) { name.truncate(br - 1); } } } kdDebug() << " EMAIL : " << email << endl; kdDebug() << " NAME : " << name << endl; kdDebug() << " COMMENT : " << comment << endl; KABC::Addressee::List al = ab->findByEmail(email); if(al.isEmpty()) { KABC::Addressee a; a.setNameFromString(name); a.insertEmail(email); a.setNote(comment); ab->insertAddressee(a); kdDebug() << "--INSERTED: " << a.realName() << endl; } }
void AddresseeEditorDialog::setTitle( const KABC::Addressee &addr ) { if ( !addr.realName().isEmpty() ) setCaption( i18n( "Edit Contact '%1'" ).arg( addr.realName() ) ); }
KABC::AddresseeList GMXXXPort::importContacts( const QString& ) const { KABC::AddresseeList addrList; QString fileName = KFileDialog::getOpenFileName( ":xxport_gmx", GMX_FILESELECTION_STRING, 0 ); if ( fileName.isEmpty() ) return addrList; QFile file( fileName ); if ( !file.open( IO_ReadOnly ) ) { QString msg = i18n( "<qt>Unable to open <b>%1</b> for reading.</qt>" ); KMessageBox::error( parentWidget(), msg.arg( fileName ) ); return addrList; } QDateTime dt; QTextStream gmxStream( &file ); gmxStream.setEncoding( QTextStream::Latin1 ); QString line, line2; line = gmxStream.readLine(); line2 = gmxStream.readLine(); if (!line.startsWith("AB_ADDRESSES:") || !line2.startsWith("Address_id")) { KMessageBox::error( parentWidget(), i18n("%1 is not a GMX address book file.").arg(fileName) ); return addrList; } QStringList strList; typedef QMap<QString, KABC::Addressee *> AddressMap; AddressMap addrMap; // "Address_id,Nickname,Firstname,Lastname,Title,Birthday,Comments,Change_date,Status,Address_link_id,Categories" line = gmxStream.readLine(); while (!line.startsWith("####") && !gmxStream.atEnd()) { while (1) { strList = QStringList::split('#', line, true); if (strList.count() >= 11) break; line.append('\n'); line.append(gmxStream.readLine()); }; KABC::Addressee *addr = new KABC::Addressee; addr->setNickName(strList[1]); addr->setGivenName(strList[2]); addr->setFamilyName(strList[3]); addr->setTitle(strList[4]); if (addr->formattedName().isEmpty()) addr->setFormattedName(addr->realName()); if (checkDateTime(strList[5],dt)) addr->setBirthday(dt); addr->setNote(strList[6]); if (checkDateTime(strList[7],dt)) addr->setRevision(dt); // addr->setStatus(strList[8]); Status // addr->xxx(strList[9]); Address_link_id // addr->setCategory(strList[10]); Categories addrMap[strList[0]] = addr; line = gmxStream.readLine(); } // now read the address records line = gmxStream.readLine(); if (!line.startsWith("AB_ADDRESS_RECORDS:")) { kdWarning() << "Could not find address records!\n"; return addrList; } // Address_id,Record_id,Street,Country,Zipcode,City,Phone,Fax,Mobile,Mobile_type,Email, // Homepage,Position,Comments,Record_type_id,Record_type,Company,Department,Change_date,Preferred,Status line = gmxStream.readLine(); line = gmxStream.readLine(); while (!line.startsWith("####") && !gmxStream.atEnd()) { while (1) { strList = QStringList::split('#', line, true); if (strList.count() >= 21) break; line.append('\n'); line.append(gmxStream.readLine()); }; KABC::Addressee *addr = addrMap[strList[0]]; if (addr) { for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it ) *it = (*it).simplifyWhiteSpace(); // strList[1] = Record_id (numbered item, ignore here) int id = strList[14].toInt(); // Record_type_id (0=work,1=home,2=other) int type = (id==0) ? KABC::Address::Work : KABC::Address::Home; if (!strList[19].isEmpty() && strList[19].toInt()!=0) type |= KABC::Address::Pref; // Preferred address (seems to be bitfield for telephone Prefs) KABC::Address adr = addr->address(type); adr.setStreet(strList[2]); adr.setCountry(strList[3]); adr.setPostalCode(strList[4]); adr.setLocality(strList[5]); addr->insertPhoneNumber( KABC::PhoneNumber(strList[6], KABC::PhoneNumber::Home) ); addr->insertPhoneNumber( KABC::PhoneNumber(strList[7], KABC::PhoneNumber::Fax) ); int celltype = KABC::PhoneNumber::Cell; // strList[9]=Mobile_type // always 0 or -1(default phone). if (strList[9].toInt()) celltype |= KABC::PhoneNumber::Pref; addr->insertPhoneNumber( KABC::PhoneNumber(strList[8], celltype) ); addr->insertEmail(strList[10]); if (!strList[11].isEmpty()) addr->setUrl(strList[11]); if (!strList[12].isEmpty()) addr->setRole(strList[12]); // strList[13]=Comments // strList[14]=Record_type_id (0,1,2) - see above // strList[15]=Record_type (name of this additional record entry) if (!strList[16].isEmpty()) addr->setOrganization(strList[16]); // Company if (!strList[17].isEmpty()) addr->insertCustom( "KADDRESSBOOK", "X-Department", strList[17]); // Department if (checkDateTime(strList[18],dt)) addr->setRevision(dt); // Change_date // strList[19]=Preferred (see above) // strList[20]=Status (should always be "1") addr->insertAddress(adr); } else { kdWarning() << "unresolved line: " << line << endl; } line = gmxStream.readLine(); } // now add the addresses to to addrList for ( AddressMap::Iterator it = addrMap.begin(); it != addrMap.end(); ++it ) { KABC::Addressee *addr = it.data(); addrList.append(*addr); delete addr; } file.close(); return addrList; }