[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    Re: [Kde-pim] Possible unwanted behaviour of the KABC API
From:       Kevin Krammer <kevin.krammer () gmx ! at>
Date:       2005-06-26 17:20:54
Message-ID: 200506261921.00602.kevin.krammer () gmx ! at
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Tuesday 21 June 2005 23:18, Kevin Krammer wrote:

I hope no response doesn't mean I am caught in your spamfilters :(

> I changed to synchronous loading, but I am curious if I misunderstood the
> meaning of the signal and if I should have used a different one.

I did some further investigation using a small test program (attached).
Actually KABC loads the file resource but as the resource says it failed to 
open it doesn get connected and thus no signals are emitted.

-rw-r--r--  1 kdedev kdedev 9957 Jun  2 12:54 std.vcf

kdedev@poseidon:~$ ./kabcloading 2>/dev/null
Received loadingFinished signal
Number of available addressees: 43
Received addressBookChanged signal
Number of available addressees: 43


-r--r--r--  1 kdedev kdedev 10005 Jun 26 19:11 std.vcf

kdedev@poseidon:~$ ./kabcloading 2>/dev/null
Waiting for signals timed out
Number of available addressees: 43

One of the implications is that even kaddressbook fails to list the addressees 
if the only resource is a file resource and its file is not writable!

I don't know enough of the KABC and KResource stuff to actually propose a 
proper fix, but I gathered a couple of ideas:

- connect signal even when open() fails
- let plugins/file/resourcefile open ReadOnly if readOnly() 
|| !QFileInfo::isWritable

- overwrite Resource::readOnly to perform that check

- emit the signal anyway if no resource could be opened

Cheers,
Kevin

-- 
Kevin Krammer <kevin.krammer@gmx.at>
Qt/KDE Developer, Debian User
Moderator: www.mrunix.de (German), www.qtforum.org

["kabcloading.cpp" (text/x-c++src)]

#include <iostream>

#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kabc/stdaddressbook.h>

#include <qtimer.h>

using namespace KABC;

class Receiver : public QObject
{
    Q_OBJECT
public:
    Receiver(KABC::AddressBook* ab) : addressBook(ab)
    {
        QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
        timer.start(5000, true);
        
        QObject::connect(ab, SIGNAL(addressBookChanged(AddressBook*)),
                         this, SLOT(slotAddressBookChanged()));
        QObject::connect(ab, SIGNAL(addressBookLocked(AddressBook*)),
                         this, SLOT(slotAddressBookLocked()));
        QObject::connect(ab, SIGNAL(addressBookUnlocked(AddressBook*)),
                         this, SLOT(slotAddressBookUnlocked()));
        QObject::connect(ab, SIGNAL(loadingFinished(Resource*)),
                         this, SLOT(slotLoadingFinished()));
        QObject::connect(ab, SIGNAL(savingFinished(Resource*)),
                         this, SLOT(slotSavingFinished()));
    }
    
private:
    void printAddresseeCount()
    {
        std::cout << "Number of available addressees: " << \
addressBook->allAddressees().count() << std::endl;  }
    
private slots:
    void slotTimeout()
    {
        std::cout << "Waiting for signals timed out" << std::endl;
        printAddresseeCount();
        KApplication::kApplication()->quit();
    }  
    
    void slotAddressBookChanged()
    {
        std::cout << "Received addressBookChanged signal" << std::endl;
        printAddresseeCount();
        KApplication::kApplication()->quit();
    }
    
    void slotAddressBookLocked()
    {
        std::cout << "Received addressBookLocked signal" << std::endl;
        printAddresseeCount();
    }

    void slotAddressBookUnlocked()
    {
        std::cout << "Received addressBookUnlocked signal" << std::endl;
        printAddresseeCount();
    }

    void slotLoadingFinished()
    {
        std::cout << "Received loadingFinished signal" << std::endl;
        printAddresseeCount();
    }

    void slotSavingFinished()
    {
        std::cout << "Received savingFinished signal" << std::endl;
        printAddresseeCount();
    }
    
private:
    QTimer timer;
    KABC::AddressBook* addressBook;
};

int main(int argc, char** argv)
{
    KAboutData about("kabcloading", "kabcloading", "0.1");
    KCmdLineArgs::init(argc, argv, &about);

    KApplication app(false, false);

    Receiver receiver(StdAddressBook::self(true));

    return app.exec();  
}

#include "kabcloading.moc"

// End of file


[Attachment #8 (application/pgp-signature)]

_______________________________________________
kde-pim mailing list
kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic