Akonadi: fixed compile and runtime issues

Due to bitrot the Akonadi backend and KWallet support code no longer
worked. Moved the common code for KApplication initialization into
libsyncevolution's SyncContext::initMain() and fixed autotools rules.

The old code always tried to contact an X server (default constructor
of KApplication). That doesn't seem to be necessary and is avoided now.
Even better might be to skip KApplication entirely and instead use
QCoreApplication and KComponentData, as suggested by
http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKApplication.html

KAboutData was incorrectly passed the address of a string pointer, not
the pointer itself.

Testing the Akonadi backend in client-test failed because client-test
always overwrites the "backend" value with
"Test_kde_[contact/event/..]._[1/2]". Now this special case is
detected. The backend then uses the first resp. second resource that
it finds.
This commit is contained in:
Patrick Ohly 2012-01-27 15:05:06 +00:00
parent 72eed2087f
commit 4928d51eca
11 changed files with 94 additions and 146 deletions

View File

@ -498,7 +498,7 @@ then
then
KDEKWALLETFOUND=yes
if ! test "$KDE_KWALLET_CFLAGS"; then
KDE_KWALLET_CFLAGS="-I`$KDE4_CONFIG --path include` -I`$KDE4_CONFIG --path include`/KDE -I`$QMAKE -query QT_INSTALL_HEADERS`"
KDE_KWALLET_CFLAGS="-I`$KDE4_CONFIG --path include` -I`$KDE4_CONFIG --path include`/KDE -I`$QMAKE -query QT_INSTALL_HEADERS` `pkg-config --cflags QtDBus`"
fi
if ! test "$KDE_KWALLET_LIBS"; then
KDE_KWALLET_LIBS="-lkdeui -lkdecore `pkg-config --libs QtDBus`"

View File

@ -25,16 +25,6 @@ extern "C" {
#endif
#ifdef USE_KDE_KWALLET
#include <QtCore/QCoreApplication>
#include <QtCore/QString>
#include <QtCore/QLatin1String>
#include <QtCore/QDebug>
#include <QtDBus/QDBusConnection>
#include <KApplication>
#include <KAboutData>
#include <KCmdLineArgs>
#include <kwallet.h>
#endif
@ -49,45 +39,6 @@ CmdlineSyncClient::CmdlineSyncClient(const string &server,
SyncContext(server, doLogging),
m_keyring(useKeyring)
{
#ifdef USE_KDE_KWALLET
//QCoreApplication *app;
int argc = 1;
static const char *prog = "syncevolution";
static char *argv[] = { (char *)&prog, NULL };
//if (!qApp) {
//new QCoreApplication(argc, argv);
//}
KAboutData aboutData(// The program name used internally.
"syncevolution",
// The message catalog name
// If null, program name is used instead.
0,
// A displayable program name string.
ki18n("Syncevolution"),
// The program version string.
"1.0",
// Short description of what the app does.
ki18n("Lets Akonadi synchronize with a SyncML Peer"),
// The license this code is released under
KAboutData::License_GPL,
// Copyright Statement
ki18n("(c) 2010"),
// Optional text shown in the About box.
// Can contain any information desired.
ki18n(""),
// The program homepage string.
"http://www.syncevolution.org/",
// The bug report email address
"syncevolution@syncevolution.org");
KCmdLineArgs::init(argc, argv, &aboutData);
if (!kapp) {
new KApplication;
//To stop KApplication from spawning it's own DBus Service ... Will have to patch KApplication about this
QDBusConnection::sessionBus().unregisterService("org.syncevolution.syncevolution-"+QString::number(getpid()));
}
#endif
}
/**
* GNOME keyring distinguishes between empty and unset
@ -187,7 +138,7 @@ bool CmdlineSyncClient::savePassword(const string &passwordName,
#ifdef USE_GNOME_KEYRING
// When both GNOME KEYRING and KWALLET are available, check if
// this is a KDE Session and call
if (getenv("KDE_FULL_SESSION")) {
if (!getenv("KDE_FULL_SESSION")) {
isKde = false;
}
#endif

View File

@ -342,6 +342,16 @@ namespace {
}
#endif
static class vCard30Test : public RegisterSyncSourceTest {
public:
vCard30Test() : RegisterSyncSourceTest("kde_contact", "eds_contact") {}
virtual void updateConfig(ClientTestConfig &config) const
{
config.m_type = "kde-contacts";
}
} vCard30Test;
static class iCal20Test : public RegisterSyncSourceTest {
public:
iCal20Test() : RegisterSyncSourceTest("kde_event", "eds_event") {}

View File

@ -1,13 +1,14 @@
Getting started with Akonadi on Debian testing:
aptitude install libakonadi-dev akonadi-server \
libqt4-dev kdepim-runtime \
akonadiconsole \
kdepimlibs5-dev
Controlling Akonadi server:
akonadictl start/stop/restart
Debugging Akonadi:
akonadiconsole (from kdepim-runtime)
akonadiconsole
Configuring without Evolution and with Akonadi:
<path>/syncevolution/configure --with-synthesis-src=<path>/libsynthesis \

View File

@ -17,5 +17,5 @@ src_backends_akonadi_syncakonadi_la_SOURCES = \
src_backends_akonadi_syncakonadi_la_LIBADD = $(KDEPIM_LIBS) $(SYNCEVOLUTION_LIBS)
src_backends_akonadi_syncakonadi_la_LDFLAGS = -module -avoid-version
src_backends_akonadi_syncakonadi_la_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(SYNCEVO_WFLAGS)
src_backends_akonadi_syncakonadi_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/test $(BACKEND_CPPFLAGS)
src_backends_akonadi_syncakonadi_la_CPPFLAGS = $(SYNCEVOLUTION_CFLAGS) -I$(top_srcdir)/test $(BACKEND_CPPFLAGS)
src_backends_akonadi_syncakonadi_la_DEPENDENCIES = $(SYNCEVOLUTION_LIBS)

View File

@ -35,15 +35,8 @@
#include <Akonadi/ServerManager>
#include <Akonadi/Control>
#include <KApplication>
#include <KAboutData>
#include <KCmdLineArgs>
#include <kurl.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QStringList>
#include <QtDBus/QDBusConnection>
#include <QtCore/QDebug>
SE_BEGIN_CXX
@ -72,46 +65,11 @@ bool AkonadiSyncSource::isEmpty()
void AkonadiSyncSource::start()
{
int argc = 1;
static const char *prog = "syncevolution";
static char *argv[] = { (char *)&prog, NULL };
//if (!qApp) {
//new QCoreApplication(argc, argv);
//}
KAboutData aboutData(// The program name used internally.
"syncevolution",
// The message catalog name
// If null, program name is used instead.
0,
// A displayable program name string.
ki18n("Syncevolution"),
// The program version string.
"1.0",
// Short description of what the app does.
ki18n("Lets Akonadi synchronize with a SyncML Peer"),
// The license this code is released under
KAboutData::License_GPL,
// Copyright Statement
ki18n("(c) 2010"),
// Optional text shown in the About box.
// Can contain any information desired.
ki18n(""),
// The program homepage string.
"http://www.syncevolution.org/",
// The bug report email address
"syncevolution@syncevolution.org");
KCmdLineArgs::init(argc, argv, &aboutData);
if (!kapp) {
new KApplication;
//To stop KApplication from spawning it's own DBus Service ... Will have to patch KApplication about this
QDBusConnection::sessionBus().unregisterService("org.syncevolution.syncevolution-"+QString::number(getpid()));
}
// Start The Akonadi Server if not already Running.
if (!Akonadi::ServerManager::isRunning()) {
qDebug() << "Akonadi Server isn't running, and hence starting it.";
SE_LOG_DEBUG(NULL, NULL, "Akonadi Server isn't running, and hence starting it.");
if (!Akonadi::Control::start()) {
qDebug() << "Couldn't Start Akonadi Server: hence the akonadi backend of syncevolution wont work ..";
SE_THROW("Couldn't Start Akonadi Server: hence the akonadi backend of syncevolution wont work ..");
}
}
}
@ -159,9 +117,29 @@ void AkonadiSyncSource::open()
// otherwise the collection URL or a name
string id = getDatabaseID();
// support selection by name and empty ID for default by using
// evolutionsource = akonadi:?collection=<number>
// invalid url=>invalid collection Error at runtime.
// hack for testing: use first resp. second database
if (boost::starts_with(id, "Test_")) {
Databases databases = getDatabases();
ssize_t index = -1;
if (boost::ends_with(id, "_1")) {
index = 0;
} else if (boost::ends_with(id, "_2")) {
index = 1;
}
if (index >= 0) {
if (databases.size() <= (size_t)index) {
SE_THROW("need two Akonadi resources for testing");
}
id = databases[index].m_uri;
SE_LOG_DEBUG(NULL, NULL, "testing Akonadi with %s", id.c_str());
}
}
if (!boost::starts_with(id, "akonadi:")) {
// TODO: support selection by name and empty ID for default
SE_THROW("database must be selected via database = akonadi:?collection=<number>");
}
m_collection = Collection::fromUrl(KUrl(id.c_str()));
}

View File

@ -29,49 +29,6 @@ DBusSync::DBusSync(const std::string &config,
DBusUserInterface(config),
m_session(session)
{
#ifdef USE_KDE_KWALLET
//QCoreApplication *app;
//if (!qApp) {
//int argc = 1;
//app = new QCoreApplication(argc, (char *[1]){ (char*) "syncevolution"});
//}
int argc = 1;
static const char *prog = "syncevolution";
static char *argv[] = { (char *)&prog, NULL };
//if (!qApp) {
//new QCoreApplication(argc, argv);
//}
KAboutData aboutData(// The program name used internally.
"syncevolution",
// The message catalog name
// If null, program name is used instead.
0,
// A displayable program name string.
ki18n("Syncevolution"),
// The program version string.
"1.0",
// Short description of what the app does.
ki18n("Lets Akonadi synchronize with a SyncML Peer"),
// The license this code is released under
KAboutData::License_GPL,
// Copyright Statement
ki18n("(c) 2010"),
// Optional text shown in the About box.
// Can contain any information desired.
ki18n(""),
// The program homepage string.
"http://www.syncevolution.org/",
// The bug report email address
"syncevolution@syncevolution.org");
KCmdLineArgs::init(argc, argv, &aboutData);
if (!kapp) {
new KApplication;
//To stop KApplication from spawning it's own DBus Service ... Will have to patch KApplication about this
QDBusConnection::sessionBus().unregisterService("org.syncevolution.syncevolution-"+QString::number(getpid()));
}
#endif
}
boost::shared_ptr<TransportAgent> DBusSync::createTransportAgent()

View File

@ -73,7 +73,7 @@ string DBusUserInterface::askPassword(const string &passwordName,
#ifdef USE_GNOME_KEYRING
//When Both GNOME KEYRING and KWALLET are available, Check if this is a KDE Session
//and Call
if(getenv("KDE_FULL_SESSION"))
if(!getenv("KDE_FULL_SESSION"))
isKde=false;
#endif
if (isKde){
@ -149,7 +149,7 @@ bool DBusUserInterface::savePassword(const string &passwordName,
#ifdef USE_GNOME_KEYRING
//When Both GNOME KEYRING and KWALLET are available, Check if this is a KDE Session
//and Call
if(getenv("KDE_FULL_SESSION"))
if(!getenv("KDE_FULL_SESSION"))
isKde=false;
#endif
if(isKde){

View File

@ -255,7 +255,7 @@ CLIENT_LIB_TEST_FILES += $(TEST_FILES_GENERATED)
src_client_test_CPPFLAGS = -DHAVE_CONFIG_H -DENABLE_INTEGRATION_TESTS -DENABLE_UNIT_TESTS $(src_cppflags) $(BUTEOSYNCPROFILE_CFLAGS) $(BUTEOSYNCCOMMON_CFLAGS) $(QT_CPPFLAGS)
src_client_test_CXXFLAGS = @CPPUNIT_CXXFLAGS@ $(PCRECPP_CFLAGS) $(SYNCEVOLUTION_CXXFLAGS) $(CORE_CXXFLAGS) $(KEYRING_CFLAGS) $(BUTEOSYNCPROFILE_CFLAGS) $(BUTEOSYNCCOMMON_CFLAGS) $(filter-out -O2 -g -W -Wall, $(QT_CXXFLAGS)) $(SYNCEVO_WFLAGS)
src_client_test_LDFLAGS = @CPPUNIT_LDFLAGS@ `nm src/syncevo/.libs/libsyncevolution.a | grep funambolAutoRegisterRegistry | sed -e 's/.* /-Wl,-u/'` $(PCRECPP_LIBS) $(CORE_LD_FLAGS) $(KEYRING_LIBS) $(BUTEOSYNCPROFILE_LIBS) $(BUTEOSYNCCOMMON_LIBS) $(QT_LDFLAGS)
src_client_test_LDFLAGS = @CPPUNIT_LDFLAGS@ `nm src/syncevo/.libs/libsyncevolution.a | grep funambolAutoRegisterRegistry | sed -e 's/.* /-Wl,-u/'` $(PCRECPP_LIBS) $(CORE_LD_FLAGS) $(KEYRING_LIBS) $(KDE_KWALLET_LIBS) $(BUTEOSYNCPROFILE_LIBS) $(BUTEOSYNCCOMMON_LIBS) $(QT_LDFLAGS)
src_client_test_LDADD = $(CORE_LDADD) $(SYNTHESIS_ENGINE) $(BUTEOSYNCPROFILE_LIBS) $(BUTEOSYNCCOMMON_LIBS) $(QT_LIBS)
# These dependencies are intentionally a bit too broad:
# they ensure that all files are in place to *run* client-test.

View File

@ -71,6 +71,18 @@ using namespace std;
#include <synthesis/SDK_util.h>
#include <synthesis/san.h>
#ifdef USE_KDE_KWALLET
#include <QtCore/QCoreApplication>
#include <QtCore/QString>
#include <QtCore/QLatin1String>
#include <QtCore/QDebug>
#include <QtDBus/QDBusConnection>
#include <KApplication>
#include <KAboutData>
#include <KCmdLineArgs>
#endif
#include "test.h"
#include <syncevo/declarations.h>
@ -2782,6 +2794,44 @@ void SyncContext::initMain(const char *appname)
g_log_set_default_handler(Logger::glogFunc, NULL);
#endif
#ifdef USE_KDE_KWALLET
//QCoreApplication *app;
int argc = 1;
static char *argv[] = { const_cast<char *>(appname), NULL };
KAboutData aboutData(// The program name used internally.
"syncevolution",
// The message catalog name
// If null, program name is used instead.
0,
// A displayable program name string.
ki18n("SyncEvolution"),
// The program version string.
"1.0",
// Short description of what the app does.
ki18n("Lets Akonadi synchronize with a SyncML Peer"),
// The license this code is released under
KAboutData::License_GPL,
// Copyright Statement
ki18n("(c) 2010-12"),
// Optional text shown in the About box.
// Can contain any information desired.
ki18n(""),
// The program homepage string.
"http://www.syncevolution.org/",
// The bug report email address
"syncevolution@syncevolution.org");
KCmdLineArgs::init(argc, argv, &aboutData);
if (!kapp) {
// Explicitly disable GUI mode in the KApplication. Otherwise
// the whole binary will fail to run when there is no X11
// display.
new KApplication(false);
//To stop KApplication from spawning it's own DBus Service ... Will have to patch KApplication about this
QDBusConnection::sessionBus().unregisterService("org.syncevolution.syncevolution-"+QString::number(getpid()));
}
#endif
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;

View File

@ -182,6 +182,7 @@ src_syncevo_libsyncevolution_la_LIBADD = \
@GIO_LIBS@ \
@GTHREAD_LIBS@ \
@GLIB_LIBS@ \
$(KDE_KWALLET_LIBS) \
$(SYNTHESIS_LIBS) \
$(PCRECPP_LIBS) \
$(TRANSPORT_LIBS) \