Exemplo n.º 1
0
void ResourceSlox::uploadContacts()
{
  QDomDocument doc;
  QDomElement root = WebdavHandler::addDavElement( doc, doc, "propertyupdate" );
  QDomElement set = WebdavHandler::addDavElement( doc, root, "set" );
  QDomElement prop = WebdavHandler::addDavElement( doc, set, "prop" );

  bool isDelete = false;

  KABC::Addressee::List addedAddr = addedAddressees();
  KABC::Addressee::List changedAddr = changedAddressees();
  KABC::Addressee::List deletedAddr = deletedAddressees();

  if ( !addedAddr.isEmpty() ) {
    mUploadAddressee = addedAddr.first();
    WebdavHandler::addSloxElement( this, doc, prop, fieldName( ClientId ), mUploadAddressee.uid() );
  } else if ( !changedAddr.isEmpty() ) {
    mUploadAddressee = changedAddr.first();
    WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ),
                                   mUploadAddressee.uid().remove( 0, sizeof("kresources_slox_kabc_") - 1) );
  } else if ( !deletedAddr.isEmpty() ) {
    mUploadAddressee = deletedAddr.first();
    isDelete = true;
  } else {
    kdDebug() << k_funcinfo << "Upload finished." << endl;
    emit savingFinished( this );
    return;
  }

  if ( !isDelete ) {
    createAddresseeFields( doc, prop, mUploadAddressee );
  } else {
    QString tmp_uid = mUploadAddressee.uid().remove( 0, sizeof("kresources_slox_kabc_") - 1); // remove prefix from uid
    WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), tmp_uid );
    WebdavHandler::addSloxElement( this, doc, prop, "method", "DELETE" );
  }

  kdDebug() << k_funcinfo << doc.toString() << endl;

  KURL url = mPrefs->url();
  url.setPath( "/servlet/webdav.contacts/" );
  url.setUser( mPrefs->user() );
  url.setPass( mPrefs->password() );

  mUploadJob = KIO::davPropPatch( url, doc, false );
  connect( mUploadJob, SIGNAL( result( KIO::Job * ) ),
           SLOT( slotUploadResult( KIO::Job * ) ) );
  connect( mUploadJob, SIGNAL( percent( KIO::Job *, unsigned long ) ),
           SLOT( slotProgress( KIO::Job *, unsigned long ) ) );

  mUploadProgress = KPIM::ProgressManager::instance()->createProgressItem(
      KPIM::ProgressManager::getUniqueID(), i18n("Uploading contacts") );
  connect( mUploadProgress,
           SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ),
           SLOT( cancelUpload() ) );
}
Exemplo n.º 2
0
void HtmlExport::formatAttendees( QTextStream *ts, Incidence *event )
{
    Attendee::List attendees = event->attendees();
    if (attendees.count()) {
        *ts << "<em>";
#ifndef KORG_NOKABC
        KABC::AddressBook *add_book = KABC::StdAddressBook::self( true );
        KABC::Addressee::List addressList;
        addressList = add_book->findByEmail(event->organizer().email());
        KABC::Addressee o = addressList.first();
        if (!o.isEmpty() && addressList.size()<2) {
            *ts << "<a href=\"mailto:" << event->organizer().email() << "\">";
            *ts << cleanChars(o.formattedName()) << "</a>\n";
        }
        else *ts << event->organizer().fullName();
#else
        *ts << event->organizer().fullName();
#endif
        *ts << "</em><br />";
        Attendee::List::ConstIterator it;
        for( it = attendees.begin(); it != attendees.end(); ++it ) {
            Attendee *a = *it;
            if (!a->email().isEmpty()) {
                *ts << "<a href=\"mailto:" << a->email();
                *ts << "\">" << cleanChars(a->name()) << "</a>";
            }
            else {
                *ts << "    " << cleanChars(a->name());
            }
            *ts << "<br />" << "\n";
        }
    } else {
        *ts << "    &nbsp;\n";
    }
}
Exemplo n.º 3
0
void TestDistrList::testDuplicate()
{
    kDebug() ;
    // This is a special test for the case where we have a contact and a distr list with the same name
    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    KABC::Addressee addr;
    addr.setName( "foo" );
    addr.insertEmail( "*****@*****.**", true );
    ab->insertAddressee( addr );

#if 0 // we need a findByFormattedName
    KABC::Addressee::List addrList = ab->findByName( "foo" );
    assert( addrList.count() == 2 );

    bool a = DistributionList::isDistributionList( addrList.first() );
    bool b = DistributionList::isDistributionList( addrList.last() );
    // one is a distr list, but not both
    assert( a || b );
    //
    assert( ! ( a && b ) );
#endif

    DistributionList dl = DistributionList::findByName( ab, "foo" );
    assert( !dl.isEmpty() );
    assert( DistributionList::isDistributionList( dl ) );
    assert( dl.formattedName() == "foo" );
}
Exemplo n.º 4
0
void TestDistrList::testNewList()
{
    kDebug() ;
    DistributionList dl;
    dl.setName( "foo" );
    assert( !dl.isEmpty() );
    check( "name set", dl.formattedName(), "foo" );
    assert( DistributionList::isDistributionList( dl ) );

    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    ab->insertAddressee( dl );
#if 0 // can't do that until we have KABC::AddressBook::findByFormattedName, or we use setName()
    KABC::Addressee::List addrList = ab->findByName( "foo" );
    assert( addrList.count() == 1 );
    KABC::Addressee addr = addrList.first();
    assert( !addr.isEmpty() );
    check( "correct name", addr.name(), "foo" );
    assert( DistributionList::isDistributionList( addr ) );
#else
    KABC::Addressee addr = dl;
#endif

    DistributionList dl2 = DistributionList::findByName( ab, "foo" );
    assert( !dl2.isEmpty() );
    check( "correct name", dl2.formattedName(), "foo" );
    assert( DistributionList::isDistributionList( dl2 ) );

    // Test the ctor that takes an addressee
    DistributionList dl3( addr );
    assert( !dl3.isEmpty() );
    assert( DistributionList::isDistributionList( dl3 ) );
    check( "correct name", dl3.formattedName(), "foo" );
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
void KAddrBookExternal::openEmail(const QString &addr, QWidget *parent)
{
    QString email;
    QString name;

    KABC::Addressee::parseEmailAddress(addr, name, email);

    KABC::AddressBook *ab = KABC::StdAddressBook::self(true);

    // force a reload of the address book file so that changes that were made
    // by other programs are loaded
    ab->asyncLoad();

    // if we have to reload the address book then we should also wait until
    // it's completely reloaded
#if KDE_IS_VERSION(3,4,89)
    // This ugly hack will be removed in 4.0
    while(!ab->loadingHasFinished())
    {
        QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);

        // use sleep here to reduce cpu usage
        usleep(100);
    }
#endif

    KABC::Addressee::List addressees = ab->findByEmail(email);

    if(addressees.count() > 0)
    {
        if(kapp->dcopClient()->isApplicationRegistered("kaddressbook"))
        {
            //make sure kaddressbook is loaded, otherwise showContactEditor
            //won't work as desired, see bug #87233
            DCOPRef call("kaddressbook", "kaddressbook");
            call.send("newInstance()");
        }
        else
        {
            kapp->startServiceByDesktopName("kaddressbook");
        }

        DCOPRef call("kaddressbook", "KAddressBookIface");
        call.send("showContactEditor(QString)", addressees.first().uid());
    }
    else
    {
        //TODO: Enable the better message at the next string unfreeze
#if 0
        QString text = i18n("<qt>The email address <b>%1</b> cannot be "
                            "found in your addressbook.</qt>").arg(email);
#else
        QString text = email + " " + i18n("is not in address book");
#endif
        KMessageBox::information(parent, text, QString::null, "notInAddressBook");
    }
}
Exemplo n.º 6
0
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
}
Exemplo n.º 7
0
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 );
  }
}
Exemplo n.º 8
0
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;
}